Skip to content

Commit 08c138d

Browse files
authored
Merge pull request #2056 from priyankparihar/CLOUDSTACK-8829
CLOUDSTACK-8829 : Consecutive cold migration fails.
2 parents dcc7f4c + 88b0459 commit 08c138d

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,6 @@ public void storageMigration(final String vmUuid, final StoragePool destPool) {
18031803

18041804
private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
18051805
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
1806-
final Long srchostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
1807-
final HostVO srcHost = _hostDao.findById(srchostId);
1808-
final Long srcClusterId = srcHost.getClusterId();
18091806

18101807
if (destPool == null) {
18111808
throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
@@ -1839,19 +1836,26 @@ private void orchestrateStorageMigration(final String vmUuid, final StoragePool
18391836
// If VM was cold migrated between clusters belonging to two different VMware DCs,
18401837
// unregister the VM from the source host and cleanup the associated VM files.
18411838
if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
1839+
Long srcClusterId = null;
1840+
Long srcHostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
1841+
if (srcHostId != null) {
1842+
HostVO srcHost = _hostDao.findById(srcHostId);
1843+
srcClusterId = srcHost.getClusterId();
1844+
}
1845+
18421846
final Long destClusterId = destPool.getClusterId();
18431847
if (srcClusterId != null && destClusterId != null && ! srcClusterId.equals(destClusterId)) {
18441848
final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId);
18451849
final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId);
18461850
if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) {
18471851
s_logger.debug("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm.getInstanceName() +
1848-
" from source host: " + srcHost.getId());
1852+
" from source host: " + srcHostId);
18491853
final UnregisterVMCommand uvc = new UnregisterVMCommand(vm.getInstanceName());
18501854
uvc.setCleanupVmFiles(true);
18511855
try {
1852-
_agentMgr.send(srcHost.getId(), uvc);
1853-
} catch (final Exception e) {
1854-
throw new CloudRuntimeException("Failed to unregister VM: " + vm.getInstanceName() + " from source host: " + srcHost.getId() +
1856+
_agentMgr.send(srcHostId, uvc);
1857+
} catch (final AgentUnavailableException | OperationTimedoutException e) {
1858+
throw new CloudRuntimeException("Failed to unregister VM: " + vm.getInstanceName() + " from source host: " + srcHostId +
18551859
" after successfully migrating VM's storage across VMware Datacenters");
18561860
}
18571861
}

0 commit comments

Comments
 (0)