-
Notifications
You must be signed in to change notification settings - Fork 1.4k
vmware: fix inter-cluster stopped vm and volume migration #4895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54ef6e7
vmware: fix inter-cluster stopped vm migration
shwstppr 7cc6b6e
fix detached volume inter-cluster migration
shwstppr ee6aacd
cleanup unused method
shwstppr db2363d
review changes
shwstppr e172623
changes
shwstppr 9973e57
find vm clusterid with multiple ROOT volumes
shwstppr 2356894
fix successive storage migration
shwstppr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| // under the License. | ||
| package com.cloud.hypervisor.guru; | ||
|
|
||
| import static com.cloud.utils.NumbersUtil.toHumanReadableSize; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
|
|
@@ -149,8 +151,6 @@ | |
| import com.vmware.vim25.VirtualMachineConfigSummary; | ||
| import com.vmware.vim25.VirtualMachineRuntimeInfo; | ||
|
|
||
| import static com.cloud.utils.NumbersUtil.toHumanReadableSize; | ||
|
|
||
| public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable { | ||
| private static final Logger s_logger = Logger.getLogger(VMwareGuru.class); | ||
|
|
||
|
|
@@ -209,16 +209,35 @@ protected VMwareGuru() { | |
| return vmwareVmImplementer.implement(vm, toVirtualMachineTO(vm), getClusterId(vm.getId())); | ||
| } | ||
|
|
||
| long getClusterId(long vmId) { | ||
| long clusterId; | ||
| Long hostId; | ||
|
|
||
| hostId = _vmDao.findById(vmId).getHostId(); | ||
| if (hostId == null) { | ||
| Long getClusterId(long vmId) { | ||
| Long clusterId = null; | ||
| Long hostId = null; | ||
| VMInstanceVO vm = _vmDao.findById(vmId); | ||
| if (vm != null) { | ||
| hostId = _vmDao.findById(vmId).getHostId(); | ||
| } | ||
| if (vm != null && hostId == null) { | ||
| // If VM is in stopped state then hostId would be undefined. Hence read last host's Id instead. | ||
| hostId = _vmDao.findById(vmId).getLastHostId(); | ||
| } | ||
| clusterId = _hostDao.findById(hostId).getClusterId(); | ||
| HostVO host = null; | ||
| if (hostId != null) { | ||
| host = _hostDao.findById(hostId); | ||
| } | ||
| if (host != null) { | ||
| clusterId = host.getClusterId(); | ||
| } else { | ||
| List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(vmId, Volume.Type.ROOT); | ||
| if (CollectionUtils.isNotEmpty(volumes)) { | ||
| VolumeVO rootVolume = volumes.get(0); | ||
| if (rootVolume.getPoolId() != null) { | ||
| StoragePoolVO pool = _storagePoolDao.findById(rootVolume.getPoolId()); | ||
| if (pool != null && pool.getClusterId() != null) { | ||
| clusterId = pool.getClusterId(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return clusterId; | ||
| } | ||
|
|
@@ -418,9 +437,11 @@ private static String resolveNameInGuid(String guid) { | |
|
|
||
| @Override public Map<String, String> getClusterSettings(long vmId) { | ||
| Map<String, String> details = new HashMap<String, String>(); | ||
| long clusterId = getClusterId(vmId); | ||
| details.put(VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString()); | ||
| details.put(VmwareReserveMemory.key(), VmwareReserveMemory.valueIn(clusterId).toString()); | ||
| Long clusterId = getClusterId(vmId); | ||
| if (clusterId != null) { | ||
| details.put(VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString()); | ||
| details.put(VmwareReserveMemory.key(), VmwareReserveMemory.valueIn(clusterId).toString()); | ||
| } | ||
| return details; | ||
| } | ||
|
|
||
|
|
@@ -1066,14 +1087,29 @@ private VirtualDisk getAttachedDisk(VirtualMachineMO vmMo, String diskPath) thro | |
| VolumeTO vol = new VolumeTO(volume, destination); | ||
| vols.add(vol); | ||
| } | ||
| MigrateVmToPoolCommand migrateVmToPoolCommand = new MigrateVmToPoolCommand(vm.getInstanceName(), vols, destination.getUuid(), true); | ||
| commands.add(migrateVmToPoolCommand); | ||
|
|
||
| // OfflineVmwareMigration: cleanup if needed | ||
| final Long destClusterId = destination.getClusterId(); | ||
| final Long srcClusterId = getClusterId(vm.getId()); | ||
| final boolean isInterClusterMigration = srcClusterId != null && destClusterId != null && ! srcClusterId.equals(destClusterId); | ||
| Host hostInTargetCluster = null; | ||
| if (isInterClusterMigration) { | ||
| // Without host vMotion might fail between non-shared storages with error similar to, | ||
| // https://kb.vmware.com/s/article/1003795 | ||
| // As this is offline migration VM won't be started on this host | ||
| List<HostVO> hosts = _hostDao.findHypervisorHostInCluster(destClusterId); | ||
| if (CollectionUtils.isNotEmpty(hosts)) { | ||
| hostInTargetCluster = hosts.get(0); | ||
| } | ||
| if (hostInTargetCluster == null) { | ||
| throw new CloudRuntimeException("Migration failed, unable to find suitable target host for VM placement while migrating between storage pools of different clusters without shared storages"); | ||
| } | ||
| } | ||
| MigrateVmToPoolCommand migrateVmToPoolCommand = new MigrateVmToPoolCommand(vm.getInstanceName(), | ||
| vols, destination.getUuid(), hostInTargetCluster == null ? null : hostInTargetCluster.getGuid(), true); | ||
| commands.add(migrateVmToPoolCommand); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please restructure this in smaller methods
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DaanHoogland done |
||
|
|
||
| if (srcClusterId != null && destClusterId != null && !srcClusterId.equals(destClusterId)) { | ||
| // OfflineVmwareMigration: cleanup if needed | ||
| if (isInterClusterMigration) { | ||
| final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId); | ||
| final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId); | ||
| if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please extract into a separate method. i.e.
Long getPoolFromRootVolume(...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaanHoogland done