@@ -1796,9 +1796,6 @@ public void storageMigration(final String vmUuid, final StoragePool destPool) {
17961796
17971797 private void orchestrateStorageMigration (final String vmUuid , final StoragePool destPool ) {
17981798 final VMInstanceVO vm = _vmDao .findByUuid (vmUuid );
1799- final Long srchostId = vm .getHostId () != null ? vm .getHostId () : vm .getLastHostId ();
1800- final HostVO srcHost = _hostDao .findById (srchostId );
1801- final Long srcClusterId = srcHost .getClusterId ();
18021799
18031800 if (destPool == null ) {
18041801 throw new CloudRuntimeException ("Unable to migrate vm: missing destination storage pool" );
@@ -1832,19 +1829,26 @@ private void orchestrateStorageMigration(final String vmUuid, final StoragePool
18321829 // If VM was cold migrated between clusters belonging to two different VMware DCs,
18331830 // unregister the VM from the source host and cleanup the associated VM files.
18341831 if (vm .getHypervisorType ().equals (HypervisorType .VMware )) {
1832+ Long srcClusterId = null ;
1833+ Long srcHostId = vm .getHostId () != null ? vm .getHostId () : vm .getLastHostId ();
1834+ if (srcHostId != null ) {
1835+ HostVO srcHost = _hostDao .findById (srcHostId );
1836+ srcClusterId = srcHost .getClusterId ();
1837+ }
1838+
18351839 final Long destClusterId = destPool .getClusterId ();
18361840 if (srcClusterId != null && destClusterId != null && ! srcClusterId .equals (destClusterId )) {
18371841 final String srcDcName = _clusterDetailsDao .getVmwareDcName (srcClusterId );
18381842 final String destDcName = _clusterDetailsDao .getVmwareDcName (destClusterId );
18391843 if (srcDcName != null && destDcName != null && !srcDcName .equals (destDcName )) {
18401844 s_logger .debug ("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm .getInstanceName () +
1841- " from source host: " + srcHost . getId () );
1845+ " from source host: " + srcHostId );
18421846 final UnregisterVMCommand uvc = new UnregisterVMCommand (vm .getInstanceName ());
18431847 uvc .setCleanupVmFiles (true );
18441848 try {
1845- _agentMgr .send (srcHost . getId () , uvc );
1846- } catch (final Exception e ) {
1847- throw new CloudRuntimeException ("Failed to unregister VM: " + vm .getInstanceName () + " from source host: " + srcHost . getId () +
1849+ _agentMgr .send (srcHostId , uvc );
1850+ } catch (final AgentUnavailableException | OperationTimedoutException e ) {
1851+ throw new CloudRuntimeException ("Failed to unregister VM: " + vm .getInstanceName () + " from source host: " + srcHostId +
18481852 " after successfully migrating VM's storage across VMware Datacenters" );
18491853 }
18501854 }
0 commit comments