8080import com .cloud .agent .api .CheckVirtualMachineCommand ;
8181import com .cloud .agent .api .ClusterSyncAnswer ;
8282import com .cloud .agent .api .ClusterSyncCommand ;
83+ import com .cloud .agent .api .ClusterVMMetaDataSyncCommand ;
84+ import com .cloud .agent .api .ClusterVMMetaDataSyncAnswer ;
8385import com .cloud .agent .api .Command ;
8486import com .cloud .agent .api .MigrateAnswer ;
8587import com .cloud .agent .api .MigrateCommand ;
@@ -340,6 +342,8 @@ public void setHostAllocators(List<HostAllocator> hostAllocators) {
340342 static final ConfigKey <Integer > ClusterDeltaSyncInterval = new ConfigKey <Integer >("Advanced" , Integer .class , "sync.interval" , "60" ,
341343 "Cluster Delta sync interval in seconds" ,
342344 false );
345+ static final ConfigKey <Integer > ClusterVMMetaDataSyncInterval = new ConfigKey <Integer >("Advanced" , Integer .class , "vmmetadata.sync.interval" , "180" , "Cluster VM metadata sync interval in seconds" ,
346+ false );
343347
344348 static final ConfigKey <Boolean > VmJobEnabled = new ConfigKey <Boolean >("Advanced" ,
345349 Boolean .class , "vm.job.enabled" , "true" ,
@@ -2521,7 +2525,35 @@ public Commands deltaHostSync(long hostId, Map<String, State> newStates) {
25212525 return commands ;
25222526 }
25232527
2524- public void deltaSync (Map <String , Ternary <String , State , String >> newStates ) {
2528+ // this is XenServer specific
2529+ public void syncVMMetaData (Map <String , String > vmMetadatum ) {
2530+ if (vmMetadatum == null || vmMetadatum .isEmpty ()) {
2531+ return ;
2532+ }
2533+ for (Map .Entry <String , String > entry : vmMetadatum .entrySet ()) {
2534+ String name = entry .getKey ();
2535+ String platform = entry .getValue ();
2536+ if (platform == null || platform .isEmpty ()) {
2537+ continue ;
2538+ }
2539+ VMInstanceVO vm = _vmDao .findVMByInstanceName (name );
2540+ if (vm != null && vm .getType () == VirtualMachine .Type .User ) {
2541+ // track platform info
2542+ UserVmVO userVm = _userVmDao .findById (vm .getId ());
2543+ _userVmDao .loadDetails (userVm );
2544+ userVm .setDetail ("platform" , platform );
2545+ String pvdriver = "xenserver56" ;
2546+ if ( platform .contains ("device_id" )) {
2547+ pvdriver = "xenserver61" ;
2548+ }
2549+ userVm .setDetail ("hypervisortoolsversion" , pvdriver );
2550+ _userVmDao .saveDetails (userVm );
2551+ }
2552+ }
2553+ }
2554+
2555+
2556+ public void deltaSync (Map <String , Pair <String , State >> newStates ) {
25252557 Map <Long , AgentVmInfo > states = convertToInfos (newStates );
25262558
25272559 for (Map .Entry <Long , AgentVmInfo > entry : states .entrySet ()) {
@@ -2556,7 +2588,7 @@ public void deltaSync(Map<String, Ternary<String, State, String>> newStates) {
25562588 }
25572589 }
25582590
2559- public void fullSync (final long clusterId , Map <String , Ternary <String , State , String >> newStates ) {
2591+ public void fullSync (final long clusterId , Map <String , Pair <String , State >> newStates ) {
25602592 if (newStates == null )
25612593 return ;
25622594 Map <Long , AgentVmInfo > infos = convertToInfos (newStates );
@@ -2686,24 +2718,24 @@ public void fullSync(final long clusterId, Map<String, Ternary<String, State, St
26862718
26872719 }
26882720
2689- protected Map <Long , AgentVmInfo > convertToInfos (final Map <String , Ternary <String , State , String >> newStates ) {
2721+ protected Map <Long , AgentVmInfo > convertToInfos (final Map <String , Pair <String , State >> newStates ) {
26902722 final HashMap <Long , AgentVmInfo > map = new HashMap <Long , AgentVmInfo >();
26912723 if (newStates == null ) {
26922724 return map ;
26932725 }
26942726 boolean is_alien_vm = true ;
26952727 long alien_vm_count = -1 ;
2696- for (Map .Entry <String , Ternary <String , State , String >> entry : newStates .entrySet ()) {
2728+ for (Map .Entry <String , Pair <String , State >> entry : newStates .entrySet ()) {
26972729 is_alien_vm = true ;
26982730 String name = entry .getKey ();
26992731 VMInstanceVO vm = _vmDao .findVMByInstanceName (name );
27002732 if (vm != null ) {
2701- map .put (vm .getId (), new AgentVmInfo (entry .getKey (), vm , entry .getValue ().second (), entry .getValue ().first (), entry . getValue (). third () ));
2733+ map .put (vm .getId (), new AgentVmInfo (entry .getKey (), vm , entry .getValue ().second (), entry .getValue ().first ()));
27022734 is_alien_vm = false ;
27032735 }
27042736 // alien VMs
27052737 if (is_alien_vm ) {
2706- map .put (alien_vm_count --, new AgentVmInfo (entry .getKey (), null , entry .getValue ().second (), entry .getValue ().first (), entry . getValue (). third () ));
2738+ map .put (alien_vm_count --, new AgentVmInfo (entry .getKey (), null , entry .getValue ().second (), entry .getValue ().first ()));
27072739 s_logger .warn ("Found an alien VM " + entry .getKey ());
27082740 }
27092741 }
@@ -2784,15 +2816,6 @@ protected Command compareState(long hostId, VMInstanceVO vm, final AgentVmInfo i
27842816 ") stopped on host " + hostDesc + " due to storage failure" , "Virtual Machine " + vm .getInstanceName () + " (id: " + vm .getId () + ") running on host [" +
27852817 vm .getHostId () + "] stopped due to storage failure." );
27862818 }
2787- // track platform info
2788- if (info .platform != null && !info .platform .isEmpty ()) {
2789- if (vm .getType () == VirtualMachine .Type .User ) {
2790- UserVmVO userVm = _userVmDao .findById (vm .getId ());
2791- _userVmDao .loadDetails (userVm );
2792- userVm .setDetail ("platform" , info .platform );
2793- _userVmDao .saveDetails (userVm );
2794- }
2795- }
27962819
27972820 if (trackExternalChange ) {
27982821 if (serverState == State .Starting ) {
@@ -3013,6 +3036,12 @@ public boolean processAnswers(long agentId, long seq, Answer[] answers) {
30133036 hs .setExecuted ();
30143037 }
30153038 }
3039+ } else if ( answer instanceof ClusterVMMetaDataSyncAnswer ) {
3040+ ClusterVMMetaDataSyncAnswer cvms = (ClusterVMMetaDataSyncAnswer )answer ;
3041+ if (!cvms .isExecuted ()) {
3042+ syncVMMetaData (cvms .getVMMetaDatum ());
3043+ cvms .setExecuted ();
3044+ }
30163045 }
30173046 }
30183047 return true ;
@@ -3046,7 +3075,6 @@ public boolean processCommands(long agentId, long seq, Command[] cmds) {
30463075 }
30473076 }
30483077 }
3049-
30503078 if (VmJobEnabled .value ()) {
30513079 if (ping .getHostVmStateReport () != null ) {
30523080 _syncMgr .processHostVmStatePingReport (agentId , ping .getHostVmStateReport ());
@@ -3105,7 +3133,6 @@ public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance)
31053133 if (allStates != null ) {
31063134 fullSync (clusterId , allStates );
31073135 }
3108-
31093136 // initiate the cron job
31103137 ClusterSyncCommand syncCmd = new ClusterSyncCommand (ClusterDeltaSyncInterval .value (), clusterId );
31113138 try {
@@ -3115,6 +3142,14 @@ public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance)
31153142 s_logger .fatal ("The Cluster VM sync process failed for cluster id " + clusterId + " with " , e );
31163143 }
31173144 }
3145+ // initiate the cron job
3146+ ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand (ClusterVMMetaDataSyncInterval .value (), clusterId );
3147+ try {
3148+ long seq_no = _agentMgr .send (agentId , new Commands (syncVMMetaDataCmd ), this );
3149+ s_logger .debug ("Cluster VM metadata sync started with jobid " + seq_no );
3150+ } catch (AgentUnavailableException e ) {
3151+ s_logger .fatal ("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with " , e );
3152+ }
31183153 } else { // for others KVM and VMWare
31193154 if (!VmJobEnabled .value ()) {
31203155 StartupRoutingCommand startup = (StartupRoutingCommand )cmd ;
@@ -3185,33 +3220,22 @@ protected class AgentVmInfo {
31853220 public State state ;
31863221 public String hostUuid ;
31873222 public VMInstanceVO vm ;
3188- public String platform ;
31893223
31903224 @ SuppressWarnings ("unchecked" )
3191- public AgentVmInfo (String name , VMInstanceVO vm , State state , String host , String platform ) {
3225+ public AgentVmInfo (String name , VMInstanceVO vm , State state , String host ) {
31923226 this .name = name ;
31933227 this .state = state ;
31943228 this .vm = vm ;
31953229 hostUuid = host ;
3196- this .platform = platform ;
3197-
3198- }
3199-
3200- public AgentVmInfo (String name , VMInstanceVO vm , State state , String host ) {
3201- this (name , vm , state , host , null );
32023230 }
32033231
32043232 public AgentVmInfo (String name , VMInstanceVO vm , State state ) {
3205- this (name , vm , state , null , null );
3233+ this (name , vm , state , null );
32063234 }
32073235
32083236 public String getHostUuid () {
32093237 return hostUuid ;
32103238 }
3211-
3212- public String getPlatform () {
3213- return platform ;
3214- }
32153239 }
32163240
32173241 @ Override
0 commit comments