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'.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4d7ede53
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4d7ede53
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4d7ede53

Branch: refs/heads/reporter
Commit: 4d7ede535df568c6aab4a228ac794ec11d433e1e
Parents: 67eff27
Author: Likitha Shetty <[email protected]>
Authored: Tue Dec 2 16:50:20 2014 +0530
Committer: Likitha Shetty <[email protected]>
Committed: Wed Dec 24 11:29:03 2014 +0530

----------------------------------------------------------------------
 .../com/cloud/storage/resource/VmwareStorageProcessor.java   | 6 +++++-
 server/src/com/cloud/storage/VolumeApiServiceImpl.java       | 4 ++++
 .../src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java | 8 ++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d7ede53/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
index cb7b23a..ba2255b 100644
--- 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
@@ -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);
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d7ede53/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index 5af0d2d..c1652ed 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4d7ede53/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git 
a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 8f05021..cd96105 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -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();

Reply via email to