diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 08fa4b438f6..a6bd95ee897 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -5104,9 +5104,9 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes answer.setVolumeChainInfo(chainInfo); return answer; } catch (Exception e) { - String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString(); + String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.getMessage(); logger.error(msg, e); - return new MigrateVolumeAnswer(cmd, false, msg, null); + return new MigrateVolumeAnswer(cmd, false, e.getMessage(), null); } } diff --git a/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java b/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java index 5b389e0d9df..b0cacf60a17 100644 --- a/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java +++ b/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java @@ -260,7 +260,7 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy { } else { answer = agentMgr.sendTo(sourcePool.getDataCenterId(), HypervisorType.VMware, cmd); } - updateVolumeAfterMigration(answer, srcData, destData); + handleAnswerAndUpdateVolumeAfterMigration(answer, srcData, destData); CopyCommandResult result = new CopyCommandResult(null, answer); callback.complete(result); } @@ -286,21 +286,19 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy { return hostId; } - private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataObject destData) { + private void handleAnswerAndUpdateVolumeAfterMigration(Answer answer, DataObject srcData, DataObject destData) { VolumeVO destinationVO = volDao.findById(destData.getId()); if (!(answer instanceof MigrateVolumeAnswer)) { // OfflineVmwareMigration: reset states and such - VolumeVO sourceVO = volDao.findById(srcData.getId()); - sourceVO.setState(Volume.State.Ready); - volDao.update(sourceVO.getId(), sourceVO); - if (destinationVO.getId() != sourceVO.getId()) { - destinationVO.setState(Volume.State.Expunged); - destinationVO.setRemoved(new Date()); - volDao.update(destinationVO.getId(), destinationVO); - } + resetVolumeState(srcData, destinationVO); throw new CloudRuntimeException("unexpected answer from hypervisor agent: " + answer.getDetails()); } MigrateVolumeAnswer ans = (MigrateVolumeAnswer) answer; + if (!answer.getResult()) { + String msg = "Unable to migrate volume: " + srcData.getName() + " due to " + answer.getDetails(); + resetVolumeState(srcData, destinationVO); + throw new CloudRuntimeException(msg); + } if (logger.isDebugEnabled()) { String format = "retrieved '%s' as new path for volume(%d)"; logger.debug(String.format(format, ans.getVolumePath(), destData.getId())); @@ -311,6 +309,17 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy { volDao.update(destinationVO.getId(), destinationVO); } + private void resetVolumeState(DataObject srcData, VolumeVO destinationVO) { + VolumeVO sourceVO = volDao.findById(srcData.getId()); + sourceVO.setState(Volume.State.Ready); + volDao.update(sourceVO.getId(), sourceVO); + if (destinationVO.getId() != sourceVO.getId()) { + destinationVO.setState(Volume.State.Expunged); + destinationVO.setRemoved(new Date()); + volDao.update(destinationVO.getId(), destinationVO); + } + } + @Override public void copyAsync(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback callback) { Answer answer = null; diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index 4719d2c9194..6a2aa09c38a 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -3738,7 +3738,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic VolumeApiResult result = future.get(); if (result.isFailed()) { logger.debug("migrate volume failed:" + result.getResult()); - throw new StorageUnavailableException("Migrate volume failed: " + result.getResult(), destPool.getId()); + throw new CloudRuntimeException("Migrate volume failed: " + result.getResult()); } return result.getVolume(); } catch (InterruptedException e) {