@@ -2042,7 +2042,6 @@ protected StartAnswer execute(StartCommand cmd) {
2042
2042
VirtualMachineDefinedProfileSpec diskProfileSpec = null ;
2043
2043
VirtualMachineDefinedProfileSpec vmProfileSpec = null ;
2044
2044
2045
-
2046
2045
DeployAsIsInfoTO deployAsIsInfo = vmSpec .getDeployAsIsInfo ();
2047
2046
boolean deployAsIs = deployAsIsInfo != null ;
2048
2047
@@ -2086,7 +2085,6 @@ protected StartAnswer execute(StartCommand cmd) {
2086
2085
}
2087
2086
2088
2087
VirtualMachineDiskInfoBuilder diskInfoBuilder = null ;
2089
- VirtualDevice [] nicDevices = null ;
2090
2088
VirtualMachineMO vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2091
2089
DiskControllerType systemVmScsiControllerType = DiskControllerType .lsilogic ;
2092
2090
int firstScsiControllerBusNum = 0 ;
@@ -2103,7 +2101,6 @@ protected StartAnswer execute(StartCommand cmd) {
2103
2101
diskDatastores = vmMo .getAllDiskDatastores ();
2104
2102
diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2105
2103
hasSnapshot = vmMo .hasSnapshot ();
2106
- nicDevices = vmMo .getNicDevices ();
2107
2104
2108
2105
tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2109
2106
ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
@@ -2119,17 +2116,20 @@ protected StartAnswer execute(StartCommand cmd) {
2119
2116
}
2120
2117
2121
2118
takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2119
+ vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2122
2120
2123
- if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2124
- vmMo .safePowerOff (_shutdownWaitMs );
2121
+ if (vmMo != null ) {
2122
+ if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2123
+ vmMo .safePowerOff (_shutdownWaitMs );
2125
2124
2126
- diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2127
- hasSnapshot = vmMo .hasSnapshot ();
2128
- diskDatastores = vmMo .getAllDiskDatastores ();
2125
+ diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2126
+ hasSnapshot = vmMo .hasSnapshot ();
2127
+ diskDatastores = vmMo .getAllDiskDatastores ();
2129
2128
2130
- tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2131
- ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2132
- numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2129
+ tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2130
+ ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2131
+ numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2132
+ }
2133
2133
} else {
2134
2134
// If a VM with the same name is found in a different cluster in the DC, unregister the old VM and configure a new VM (cold-migration).
2135
2135
VirtualMachineMO existingVmInDc = dcMo .findVm (vmInternalCSName );
@@ -2146,7 +2146,7 @@ protected StartAnswer execute(StartCommand cmd) {
2146
2146
vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2147
2147
if (vmMo == null ) {
2148
2148
logger .info ("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it" );
2149
- vmMo = takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2149
+ takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2150
2150
}
2151
2151
} else {
2152
2152
DiskTO rootDisk = null ;
@@ -2256,11 +2256,11 @@ protected StartAnswer execute(StartCommand cmd) {
2256
2256
vmConfigSpec .setCpuHotAddEnabled (vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ());
2257
2257
}
2258
2258
2259
- if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2259
+ if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
2260
2260
logger .warn ("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
2261
2261
}
2262
2262
2263
- if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2263
+ if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
2264
2264
logger .warn ("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
2265
2265
}
2266
2266
@@ -2593,7 +2593,7 @@ protected StartAnswer execute(StartCommand cmd) {
2593
2593
2594
2594
Map <String , Map <String , String >> iqnToData = new HashMap <>();
2595
2595
2596
- postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , ideControllerKey , scsiControllerKey , iqnToData , hyperHost , context );
2596
+ postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , iqnToData , hyperHost , context );
2597
2597
2598
2598
//
2599
2599
// Power-on VM
@@ -2731,14 +2731,24 @@ private void syncVolumeDatastoreAndPathForDatastoreCluster(DiskTO vol, VirtualMa
2731
2731
}
2732
2732
2733
2733
private boolean powerOnVM (final VirtualMachineMO vmMo , final String vmInternalCSName , final String vmNameOnVcenter ) throws Exception {
2734
- int retry = 20 ;
2735
- while (retry -- > 0 ) {
2734
+ final int retry = 20 ;
2735
+ int retryAttempt = 0 ;
2736
+ while (++retryAttempt <= retry ) {
2736
2737
try {
2738
+ logger .debug (String .format ("VM %s, powerOn attempt #%d" , vmInternalCSName , retryAttempt ));
2737
2739
return vmMo .powerOn ();
2738
2740
} catch (Exception e ) {
2739
2741
logger .info (String .format ("Got exception while power on VM %s with hostname %s" , vmInternalCSName , vmNameOnVcenter ), e );
2740
- if (e .getMessage () != null && e .getMessage ().contains ("File system specific implementation of Ioctl[file] failed" )) {
2742
+ if (e .getMessage () != null &&
2743
+ (e .getMessage ().contains ("File system specific implementation of Ioctl[file] failed" ) ||
2744
+ e .getMessage ().contains ("Unable to access file" ) ||
2745
+ e .getMessage ().contains ("it is locked" ))) {
2741
2746
logger .debug (String .format ("Failed to power on VM %s with hostname %s. Retrying" , vmInternalCSName , vmNameOnVcenter ));
2747
+ try {
2748
+ Thread .sleep (1000 );
2749
+ } catch (InterruptedException ie ) {
2750
+ logger .debug (String .format ("Waiting to power on VM %s been interrupted: " , vmInternalCSName ));
2751
+ }
2742
2752
} else {
2743
2753
throw e ;
2744
2754
}
@@ -3292,7 +3302,7 @@ private void tearDownVm(VirtualMachineMO vmMo) throws Exception {
3292
3302
3293
3303
int getReservedMemoryMb (VirtualMachineTO vmSpec ) {
3294
3304
if (vmSpec .getDetails ().get (VMwareGuru .VmwareReserveMemory .key ()).equalsIgnoreCase ("true" )) {
3295
- if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ){
3305
+ if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ) {
3296
3306
float reservedMemory = (vmSpec .getMaxRam () * Float .parseFloat (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION )));
3297
3307
return (int ) (reservedMemory / ResourceType .bytesToMiB );
3298
3308
}
@@ -3630,18 +3640,18 @@ private Pair<String, String> getVMDiskInfo(String volumePath, boolean isManaged,
3630
3640
3631
3641
private VirtualMachineDiskInfo getMatchingExistingDisk (VirtualMachineDiskInfoBuilder diskInfoBuilder , DiskTO vol , VmwareHypervisorHost hyperHost , VmwareContext context )
3632
3642
throws Exception {
3633
- if (diskInfoBuilder != null ) {
3634
- VolumeObjectTO volume = (VolumeObjectTO ) vol .getData ();
3635
- String chainInfo = volume .getChainInfo ();
3636
- Map <String , String > details = vol .getDetails ();
3637
- boolean isManaged = details != null && Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3638
- String iScsiName = details .get (DiskTO .IQN );
3639
- String datastoreUUID = volume .getDataStore ().getUuid ();
3640
-
3641
- return getMatchingExistingDiskWithVolumeDetails (diskInfoBuilder , volume .getPath (), chainInfo , isManaged , iScsiName , datastoreUUID , hyperHost , context );
3642
- } else {
3643
+ if (diskInfoBuilder == null ) {
3643
3644
return null ;
3644
3645
}
3646
+
3647
+ VolumeObjectTO volume = (VolumeObjectTO ) vol .getData ();
3648
+ String chainInfo = volume .getChainInfo ();
3649
+ Map <String , String > details = vol .getDetails ();
3650
+ boolean isManaged = details != null && Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3651
+ String iScsiName = details .get (DiskTO .IQN );
3652
+ String datastoreUUID = volume .getDataStore ().getUuid ();
3653
+
3654
+ return getMatchingExistingDiskWithVolumeDetails (diskInfoBuilder , volume .getPath (), chainInfo , isManaged , iScsiName , datastoreUUID , hyperHost , context );
3645
3655
}
3646
3656
3647
3657
private String getDiskController (VirtualMachineMO vmMo , VirtualMachineDiskInfo matchingExistingDisk , DiskTO vol , Pair <String , String > controllerInfo , boolean deployAsIs ) throws Exception {
@@ -3666,34 +3676,36 @@ private String getDiskController(VirtualMachineMO vmMo, VirtualMachineDiskInfo m
3666
3676
return VmwareHelper .getControllerBasedOnDiskType (controllerInfo , vol );
3667
3677
}
3668
3678
3669
- private void postDiskConfigBeforeStart (VirtualMachineMO vmMo , VirtualMachineTO vmSpec , DiskTO [] sortedDisks , int ideControllerKey ,
3670
- int scsiControllerKey , Map <String , Map <String , String >> iqnToData , VmwareHypervisorHost hyperHost , VmwareContext context ) throws Exception {
3679
+ private void postDiskConfigBeforeStart (VirtualMachineMO vmMo , VirtualMachineTO vmSpec , DiskTO [] sortedDisks ,
3680
+ Map <String , Map <String , String >> iqnToData , VmwareHypervisorHost hyperHost , VmwareContext context ) throws Exception {
3671
3681
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo .getDiskInfoBuilder ();
3672
3682
3673
3683
for (DiskTO vol : sortedDisks ) {
3674
3684
if (vol .getType () == Volume .Type .ISO )
3675
3685
continue ;
3676
3686
3677
- VolumeObjectTO volumeTO = (VolumeObjectTO ) vol .getData ();
3678
-
3679
3687
VirtualMachineDiskInfo diskInfo = getMatchingExistingDisk (diskInfoBuilder , vol , hyperHost , context );
3680
- assert (diskInfo != null );
3688
+ if (diskInfo == null ) {
3689
+ continue ;
3690
+ }
3681
3691
3682
3692
String [] diskChain = diskInfo .getDiskChain ();
3683
- assert (diskChain .length > 0 );
3693
+ if (diskChain .length <= 0 ) {
3694
+ continue ;
3695
+ }
3684
3696
3685
- Map <String , String > details = vol .getDetails ();
3686
- boolean managed = false ;
3697
+ DatastoreFile file = new DatastoreFile (diskChain [0 ]);
3687
3698
3699
+ boolean managed = false ;
3700
+ Map <String , String > details = vol .getDetails ();
3688
3701
if (details != null ) {
3689
3702
managed = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3690
3703
}
3691
3704
3692
- DatastoreFile file = new DatastoreFile ( diskChain [ 0 ] );
3705
+ VolumeObjectTO volumeTO = ( VolumeObjectTO ) vol . getData ( );
3693
3706
3694
3707
if (managed ) {
3695
3708
DatastoreFile originalFile = new DatastoreFile (volumeTO .getPath ());
3696
-
3697
3709
if (!file .getFileBaseName ().equalsIgnoreCase (originalFile .getFileBaseName ())) {
3698
3710
if (logger .isInfoEnabled ())
3699
3711
logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + diskChain [0 ]);
@@ -3706,7 +3718,6 @@ private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO v
3706
3718
}
3707
3719
3708
3720
VolumeObjectTO volInSpec = getVolumeInSpec (vmSpec , volumeTO );
3709
-
3710
3721
if (volInSpec != null ) {
3711
3722
if (managed ) {
3712
3723
Map <String , String > data = new HashMap <>();
@@ -3871,20 +3882,20 @@ private DatastoreMO getDataStoreWhereDiskExists(VmwareHypervisorHost hyperHost,
3871
3882
if (diskInfo != null ) {
3872
3883
logger .info ("Found existing disk info from volume path: " + volume .getPath ());
3873
3884
return dsMo ;
3874
- } else {
3875
- String chainInfo = volume . getChainInfo ();
3876
- if ( chainInfo != null ) {
3877
- VirtualMachineDiskInfo infoInChain = _gson . fromJson (chainInfo , VirtualMachineDiskInfo . class );
3878
- if ( infoInChain != null ) {
3879
- String [] disks = infoInChain . getDiskChain ();
3880
- if ( disks . length > 0 ) {
3881
- for ( String diskPath : disks ) {
3882
- DatastoreFile file = new DatastoreFile ( diskPath );
3883
- diskInfo = diskInfoBuilder . getDiskInfoByBackingFileBaseName ( file . getFileBaseName (), dsName );
3884
- if ( diskInfo != null ) {
3885
- logger . info ( "Found existing disk from chain info: " + diskPath );
3886
- return dsMo ;
3887
- }
3885
+ }
3886
+
3887
+ String chainInfo = volume . getChainInfo ();
3888
+ if (chainInfo != null ) {
3889
+ VirtualMachineDiskInfo infoInChain = _gson . fromJson ( chainInfo , VirtualMachineDiskInfo . class );
3890
+ if ( infoInChain != null ) {
3891
+ String [] disks = infoInChain . getDiskChain ();
3892
+ if ( disks . length > 0 ) {
3893
+ for ( String diskPath : disks ) {
3894
+ DatastoreFile file = new DatastoreFile ( diskPath );
3895
+ diskInfo = diskInfoBuilder . getDiskInfoByBackingFileBaseName ( file . getFileBaseName (), dsName );
3896
+ if ( diskInfo != null ) {
3897
+ logger . info ( "Found existing disk from chain info: " + diskPath ) ;
3898
+ return dsMo ;
3888
3899
}
3889
3900
}
3890
3901
}
@@ -4747,7 +4758,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
4747
4758
Map <Integer , Long > volumeDeviceKey = new HashMap <>();
4748
4759
if (cmd instanceof MigrateVolumeCommand ) { // Else device keys will be found in relocateVirtualMachine
4749
4760
MigrateVolumeCommand mcmd = (MigrateVolumeCommand ) cmd ;
4750
- addVolumeDiskmapping (vmMo , volumeDeviceKey , mcmd .getVolumePath (), mcmd .getVolumeId ());
4761
+ addVolumeDiskMapping (vmMo , volumeDeviceKey , mcmd .getVolumePath (), mcmd .getVolumeId ());
4751
4762
if (logger .isTraceEnabled ()) {
4752
4763
for (Integer diskId : volumeDeviceKey .keySet ()) {
4753
4764
logger .trace (String .format ("Disk to migrate has disk id %d and volumeId %d" , diskId , volumeDeviceKey .get (diskId )));
@@ -4765,9 +4776,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
4765
4776
4766
4777
Answer createAnswerForCmd (VirtualMachineMO vmMo , List <VolumeObjectTO > volumeObjectToList , Command cmd , Map <Integer , Long > volumeDeviceKey ) throws Exception {
4767
4778
List <VolumeObjectTO > volumeToList ;
4768
- VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo .getDiskInfoBuilder ();
4769
4779
VirtualDisk [] disks = vmMo .getAllDiskDevice ();
4770
- Answer answer ;
4771
4780
if (logger .isTraceEnabled ()) {
4772
4781
logger .trace (String .format ("creating answer for %s" , cmd .getClass ().getSimpleName ()));
4773
4782
}
@@ -4784,7 +4793,7 @@ Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObje
4784
4793
return new Answer (cmd , false , null );
4785
4794
}
4786
4795
4787
- private void addVolumeDiskmapping (VirtualMachineMO vmMo , Map <Integer , Long > volumeDeviceKey , String volumePath , long volumeId ) throws Exception {
4796
+ private void addVolumeDiskMapping (VirtualMachineMO vmMo , Map <Integer , Long > volumeDeviceKey , String volumePath , long volumeId ) throws Exception {
4788
4797
if (logger .isDebugEnabled ()) {
4789
4798
logger .debug (String .format ("locating disk for volume (%d) using path %s" , volumeId , volumePath ));
4790
4799
}
@@ -4919,7 +4928,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
4919
4928
VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster ;
4920
4929
String targetDsName = cmd .getTargetPool ().getUuid ();
4921
4930
morDestinationDS = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (dsHost , targetDsName );
4922
- if (morDestinationDS == null ) {
4931
+ if (morDestinationDS == null ) {
4923
4932
String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
4924
4933
logger .error (msg );
4925
4934
throw new CloudRuntimeException (msg );
@@ -5886,6 +5895,11 @@ protected Answer execute(CleanupVMCommand cmd) {
5886
5895
logger .debug (msg );
5887
5896
return new Answer (cmd , true , msg );
5888
5897
} catch (Exception e ) {
5898
+ if (e .getMessage ().contains ("was not found" )) {
5899
+ String msg = String .format ("%s - VM [%s] file(s) not found, cleanup not needed ." , e .getMessage (), cmd .getVmName ());
5900
+ logger .debug (msg );
5901
+ return new Answer (cmd , true , msg );
5902
+ }
5889
5903
return new Answer (cmd , false , createLogMessageException (e , cmd ));
5890
5904
}
5891
5905
}
0 commit comments