CLOUDSTACK-8119. Propagate error message to UI for attach/detach volume failure operations.

For AttachVolume/DetachVolume API command, improve user error message in case of RuntimeException by throwing the exception instead of 'Unexpected Exception'.
This commit is contained in:
Likitha Shetty 2014-12-02 16:50:20 +05:30
parent 67eff27f54
commit 4d7ede535d
3 changed files with 17 additions and 1 deletions

View File

@ -1367,7 +1367,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
hostService.invalidateServiceContext(null);
}
String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
String msg = "";
if (isAttach)
msg += "Failed to attach volume: " + e.getMessage();
else
msg += "Failed to detach volume: " + e.getMessage();
s_logger.error(msg, e);
return new AttachAnswer(msg);
}

View File

@ -1378,6 +1378,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
throw (ConcurrentOperationException)jobResult;
else if (jobResult instanceof InvalidParameterValueException)
throw (InvalidParameterValueException)jobResult;
else if (jobResult instanceof RuntimeException)
throw (RuntimeException)jobResult;
else if (jobResult instanceof Throwable)
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
else if (jobResult instanceof Long) {
@ -1580,6 +1582,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
if (jobResult != null) {
if (jobResult instanceof ConcurrentOperationException)
throw (ConcurrentOperationException)jobResult;
else if (jobResult instanceof RuntimeException)
throw (RuntimeException)jobResult;
else if (jobResult instanceof Throwable)
throw new RuntimeException("Unexpected exception", (Throwable)jobResult);
else if (jobResult instanceof Long) {

View File

@ -1126,6 +1126,14 @@ public class VirtualMachineMO extends BaseMO {
throw new Exception("No such disk device: " + vmdkDatastorePath);
}
// IDE virtual disk cannot be detached if VM is running
if (deviceInfo.second() != null && deviceInfo.second().contains("ide")) {
if (getPowerState() == VirtualMachinePowerState.POWERED_ON) {
throw new Exception("Removing a virtual disk over IDE controller is not supported while VM is running in VMware hypervisor. " +
"Please re-try when VM is not running.");
}
}
List<Pair<String, ManagedObjectReference>> chain = getDiskDatastorePathChain(deviceInfo.first(), true);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();