cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [1/2] Finally finished how to get virtualmachine manager to work correctly
Date Fri, 24 May 2013 00:53:11 GMT
Updated Branches:
  refs/heads/vmsync 3716f1f32 -> 099778e38


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/099778e3/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 4c421e6..5fd6b02 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -344,7 +344,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
 
     @Override
     @DB
-    public VirtualMachine allocate(String vmInstanceName, VMTemplateVO template, ServiceOfferingVO
serviceOffering, Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
+    public boolean allocate(String vmInstanceName, VMTemplateVO template, ServiceOfferingVO
serviceOffering, Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
             List<Pair<DiskOfferingVO, Long>> dataDiskOfferings, List<Pair<NetworkVO,
NicProfile>> networks, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan
plan,
             HypervisorType hyperType, Account owner) {
         assert (plan.getClusterId() == null && plan.getPoolId() == null) : "We currently
don't support cluster and pool preset yet";
@@ -402,19 +402,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             s_logger.debug("Allocation completed for VM: " + vm);
         }
 
-        return vm;
+        return true;
     }
 
     @Override
-    public VirtualMachine allocate(String vmInstanceName, VMTemplateVO template, ServiceOfferingVO
serviceOffering, List<Pair<NetworkVO, NicProfile>> networks,
+    public boolean allocate(String vmInstanceName, VMTemplateVO template, ServiceOfferingVO
serviceOffering, List<Pair<NetworkVO, NicProfile>> networks,
             DeploymentPlan plan, HypervisorType hyperType, Account owner) {
         return allocate(vmInstanceName, template, serviceOffering, new Pair<DiskOfferingVO,
Long>(serviceOffering, null), null, networks, null, plan, hyperType, owner);
     }
 
     @Override
-    public boolean expunge(String vmUuid, User caller, Account account) {
+    public void expunge(String vmUuid, User caller, Account account) {
         try {
-            return advanceExpunge(vmUuid, caller, account);
+            advanceExpunge(vmUuid, caller, account);
         } catch (OperationTimedoutException e) {
             throw new CloudRuntimeException("Operation timed out", e);
         } catch (ConcurrentOperationException e) {
@@ -425,31 +425,25 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public boolean advanceExpunge(String vmUuid, User caller, Account account) throws ResourceUnavailableException,
OperationTimedoutException,
+    public void advanceExpunge(String vmUuid, User caller, Account account) throws ResourceUnavailableException,
OperationTimedoutException,
             ConcurrentOperationException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
         if (vm == null || vm.getRemoved() != null) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Unable to find vm or vm is destroyed: " + vm);
             }
-            return true;
+            return;
         }
 
-        if (!advanceStop(vmUuid, false, caller, account)) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Unable to stop the VM so we can't expunge it.");
-            }
-        }
+        advanceStop(vmUuid, false, caller, account);
 
         vm = _vmDao.findByUuid(vmUuid);
         try {
             if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId()))
{
-                s_logger.debug("Unable to destroy the vm because it is not in the correct
state: " + vm);
-                return false;
+                throw new CloudRuntimeException("Unable to detroy the VM because it is not
in the correct state: " + vm);
             }
         } catch (NoTransitionException e) {
-            s_logger.debug("Unable to destroy the vm because it is not in the correct state:
" + vm);
-            return false;
+            throw new CloudRuntimeException("Unable to destroy the vm because it is not in
the correct state: " + vm);
         }
 
         if (s_logger.isDebugEnabled()) {
@@ -485,7 +479,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                             break;
                         }
                     }
-                    return false;
+                    throw new CloudRuntimeException("Failed the expunge the vm on the hypervisor");
                 }
             }
         }
@@ -495,8 +489,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         }
         
         _vmDao.remove(vm.getId());
-
-        return true;
     }
 
     @Override
@@ -541,19 +533,20 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public VirtualMachine start(String vmUuid, Map<VirtualMachineProfile.Param, Object>
params, User caller, Account account) throws InsufficientCapacityException,
-            ResourceUnavailableException {
-        return start(vmUuid, params, caller, account, null);
+    public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params,
User caller, Account account) {
+        start(vmUuid, params, caller, account, null);
     }
 
     @Override
-    public VirtualMachine start(String vmUuid, Map<VirtualMachineProfile.Param, Object>
params, User caller, Account account, DeploymentPlan planToDeploy)
-            throws InsufficientCapacityException,
-    	ResourceUnavailableException {
+    public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params,
User caller, Account account, DeploymentPlan planToDeploy) {
         try {
-            return advanceStart(vmUuid, params, caller, account, planToDeploy);
+            advanceStart(vmUuid, params, caller, account, planToDeploy);
         } catch (ConcurrentOperationException e) {
-            throw new CloudRuntimeException("Unable to start a VM due to concurrent operation",
e);
+            throw new CloudRuntimeException(e).add(VirtualMachine.class, vmUuid);
+        } catch (InsufficientCapacityException e) {
+            throw new CloudRuntimeException(e).add(VirtualMachine.class, vmUuid);
+        } catch (ResourceUnavailableException e) {
+            throw new CloudRuntimeException(e).add(VirtualMachine.class, vmUuid);
         }
     }
 
@@ -720,14 +713,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public VirtualMachine advanceStart(String vmUuid, Map<VirtualMachineProfile.Param,
Object> params, User caller, Account account) throws InsufficientCapacityException,
+    public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object>
params, User caller, Account account) throws InsufficientCapacityException,
     	ConcurrentOperationException, ResourceUnavailableException {
-        return advanceStart(vmUuid, params, caller, account, null);
+        advanceStart(vmUuid, params, caller, account, null);
     }
     
     @Override
     @DB
-    public VirtualMachine advanceStart(String vmUuid, Map<VirtualMachineProfile.Param,
Object> params, User caller, Account account, DeploymentPlan planToDeploy)
+    public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object>
params, User caller, Account account, DeploymentPlan planToDeploy)
         throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException
{
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
     	
@@ -804,7 +797,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     		});
     	AsyncJobExecutionContext.getCurrentExecutionContext().disjoinJob(jobId);
     	
-    	return vm;
+        return;
     }
 
     @Override
@@ -1081,15 +1074,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
     
     @Override
-    public boolean stop(String vmUuid, User user, Account account) {
+    public void stop(String vmUuid, User user, Account account) {
         try {
-            return advanceStop(vmUuid, false, user, account);
+            advanceStop(vmUuid, false, user, account);
         } catch (OperationTimedoutException e) {
-            throw new CloudRuntimeException("Unable to stop vm because the operation to stop
timed out", e);
+            throw new CloudRuntimeException(e).add(VirtualMachine.class, vmUuid);
         } catch (ConcurrentOperationException e) {
-            throw new CloudRuntimeException("Unable to stop vm because of a concurrent operation",
e);
-        } catch (AgentUnavailableException e) {
-            throw new CloudRuntimeException("Unable to reach host to stop vm", e);
+            throw new CloudRuntimeException(e).add(VirtualMachine.class, vmUuid);
+        } catch (ResourceUnavailableException e) {
+            throw new CloudRuntimeException(e).add(VirtualMachine.class, vmUuid);
         }
     }
 
@@ -1182,7 +1175,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
     
     @Override
-    public boolean advanceStop(final String vmUuid, boolean forced, User user, Account account)
throws AgentUnavailableException,
+    public void advanceStop(final String vmUuid, boolean forced, User user, Account account)
throws ResourceUnavailableException,
             OperationTimedoutException, ConcurrentOperationException {
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
     	VmWorkJobVO workJob = null;
@@ -1255,13 +1248,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
 				}
     		});
     	
-    	try {
-    		AsyncJobExecutionContext.getCurrentExecutionContext().disjoinJob(jobId);
-    	} catch(Exception e) {
-    		s_logger.error("Unexpected exception", e);
-    		return false;
-    	}
-    	return true;
+        try {
+            AsyncJobExecutionContext.getCurrentExecutionContext().disjoinJob(jobId);
+        } catch (InsufficientCapacityException e) {
+            throw new CloudRuntimeException("Should never ever happen on a stop.  Who threw
this?", e);
+        }
     }
 
     @Override
@@ -1604,7 +1595,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public boolean destroy(String vmUuid, User user, Account caller) throws AgentUnavailableException,
OperationTimedoutException,
+    public boolean destroy(String vmUuid, User user, Account caller) throws ResourceUnavailableException,
OperationTimedoutException,
             ConcurrentOperationException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
         if (s_logger.isDebugEnabled()) {
@@ -1617,10 +1608,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             return true;
         }
 
-        if (!advanceStop(vmUuid, _forceStop, user, caller)) {
-            s_logger.debug("Unable to stop " + vm);
-            return false;
-        }
+        advanceStop(vmUuid, _forceStop, user, caller);
         
         vm = _vmDao.findById(vm.getId());
 
@@ -2166,8 +2154,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 return true;
             }
             try {
-                boolean result = advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(),
_accountMgr.getSystemAccount());
-                return result;
+                advanceStop(vm.getUuid(), true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
+                return true;
             } catch (ResourceUnavailableException e) {
                 s_logger.debug("Unable to stop VM due to " + e.getMessage());
             } catch (ConcurrentOperationException e) {
@@ -2216,43 +2204,39 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public boolean reboot(String vmUuid, User caller, Account account) {
+    public void reboot(String vmUuid, User caller, Account account) {
         try {
-            return advanceReboot(vmUuid, caller, account);
+            advanceReboot(vmUuid, caller, account);
         } catch (ConcurrentOperationException e) {
-            throw new CloudRuntimeException("Unable to reboot a VM due to concurrent operation",
e);
+            throw new CloudRuntimeException("Unable to reboot a VM due to concurrent operation",
e).add(VirtualMachine.class, vmUuid);
         } catch (InsufficientCapacityException e) {
-            throw new CloudRuntimeException("Unable to reboot a VM due to insufficient capacity",
e);
+            throw new CloudRuntimeException("Unable to reboot a VM due to insufficient capacity",
e).add(VirtualMachine.class, vmUuid);
         } catch (ResourceUnavailableException e) {
-            throw new CloudRuntimeException("Unable to reboot a VM due to resource unavailable",
e);
+            throw new CloudRuntimeException("Unable to reboot a VM due to resource unavailable",
e).add(VirtualMachine.class, vmUuid);
+        } catch (OperationTimedoutException e) {
+            throw new CloudRuntimeException("Unable to reboot a VM due to reboot operation
timed out", e).add(VirtualMachine.class, vmUuid);
         }
     }
 
     @Override
-    public boolean advanceReboot(String vmUuid, User caller, Account account) throws InsufficientCapacityException,
-    ConcurrentOperationException, ResourceUnavailableException {
+    public void advanceReboot(String vmUuid, User caller, Account account) throws InsufficientCapacityException,
+            ConcurrentOperationException, ResourceUnavailableException, OperationTimedoutException
{
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
         if (vm.getHostId() == null) {
             s_logger.debug("No need to reboot " + vm + " when it doesn't have a host id");
-            return false;
+            return;
         }
 
         Host host = _hostDao.findById(vm.getHostId());
 
-        try {
 
-            Commands cmds = new Commands(OnError.Stop);
-            cmds.addCommand(new RebootCommand(vm.getInstanceName()));
-            _agentMgr.send(host.getId(), cmds);
+        Commands cmds = new Commands(OnError.Stop);
+        cmds.addCommand(new RebootCommand(vm.getInstanceName()));
+        _agentMgr.send(host.getId(), cmds);
 
-            Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
-            if (rebootAnswer == null || !rebootAnswer.getResult()) {
-                s_logger.debug("Unable to reboot VM " + vm + " on " + host + " due to " +
(rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails()));
-            }
-            return true;
-        } catch (OperationTimedoutException e) {
-            s_logger.warn("Unable to send the reboot command to host " + host + " for the
vm " + vm + " due to operation timeout", e);
-            return false;
+        Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
+        if (!rebootAnswer.getResult()) {
+            throw new CloudRuntimeException("Unable to reboot " + vm + " on " + host + "
due to " + rebootAnswer.getDetails()).add(VirtualMachine.class, vmUuid);
         }
     }
 
@@ -3399,7 +3383,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     }
 
     @Override
-    public VirtualMachine findHostAndMigrate(String vmUuid, Long newSvcOfferingId)
+    public boolean findHostAndMigrate(String vmUuid, Long newSvcOfferingId)
             throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException,
VirtualMachineMigrationException, ManagementServerException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
@@ -3441,9 +3425,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         }
 
         excludes.addHost(dest.getHost().getId());
-        VirtualMachine vmInstance = null;
         try {
-            vmInstance = migrateForScale(vm.getUuid(), srcHostId, dest, oldSvcOfferingId);
+            return migrateForScale(vm.getUuid(), srcHostId, dest, oldSvcOfferingId);
         } catch (ResourceUnavailableException e) {
             s_logger.debug("Unable to migrate to unavailable " + dest);
             throw e;
@@ -3460,21 +3443,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 throw e;
             } else {
                 s_logger.debug("Unable to migrate VM, VM is not in Running or even Starting
state, current state: " + vm.getState().toString());
+                return false;
             }
         }
-        if (vmInstance != null) {
-            return vmInstance;
-        }else{
-            return null;
-        }
     }
 
         @Override
-    public VirtualMachine migrateForScale(String vmUuid, long srcHostId, DeployDestination
dest, Long oldSvcOfferingId) throws ResourceUnavailableException,
+    public boolean migrateForScale(String vmUuid, long srcHostId, DeployDestination dest,
Long oldSvcOfferingId) throws ResourceUnavailableException,
             ConcurrentOperationException, ManagementServerException,
                 VirtualMachineMigrationException {
 //            s_logger.info("Migrating " + vm + " to " + dest);
-        return null;
+        return false;
         /*
                     Long newSvcOfferingId = vm.getServiceOfferingId();
                     long dstHostId = dest.getHost().getId();
@@ -3627,7 +3606,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         */
         }
     @Override
-    public VirtualMachine reConfigureVm(VirtualMachine vm, ServiceOffering oldServiceOffering,
boolean reconfiguringOnExistingHost) throws ResourceUnavailableException,
+    public boolean reConfigureVm(VirtualMachine vm, ServiceOffering oldServiceOffering, boolean
reconfiguringOnExistingHost) throws ResourceUnavailableException,
             ConcurrentOperationException {
         /*
                 long newServiceofferingId = vm.getServiceOfferingId();
@@ -3671,7 +3650,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                     }
                 }
         */
-        return vm;
+        return false;
 
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/099778e3/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
index 162d87b..3454c94 100644
--- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
+++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
@@ -673,11 +673,10 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana
         // start or stop VM first, if revert from stopped state to running state, or from
running to stopped
         if(userVm.getState() == VirtualMachine.State.Stopped && vmSnapshotVo.getType()
== VMSnapshot.Type.DiskAndMemory){
             try {
-                if (_itMgr.advanceStart(userVm.getUuid(), new HashMap<VirtualMachineProfile.Param,
Object>(), callerUser, owner) != null) {
-                    userVm = _userVMDao.findById(userVm.getId());
-                }
-        	    hostId = vm.getHostId();
-        	} catch (Exception e) {
+                _itMgr.start(userVm.getUuid(), new HashMap<VirtualMachineProfile.Param,
Object>(), callerUser, owner);
+                userVm = _userVMDao.findById(userVm.getId());
+                hostId = userVm.getHostId();
+            } catch (CloudRuntimeException e) {
         	    s_logger.error("Start VM " + userVm.getInstanceName() + " before reverting failed
due to " + e.getMessage());
         	    throw new CloudRuntimeException(e.getMessage());
         	}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/099778e3/server/test/com/cloud/vm/UserVmManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/UserVmManagerTest.java b/server/test/com/cloud/vm/UserVmManagerTest.java
index 16feb98..d47c8e7 100755
--- a/server/test/com/cloud/vm/UserVmManagerTest.java
+++ b/server/test/com/cloud/vm/UserVmManagerTest.java
@@ -178,8 +178,8 @@ public class UserVmManagerTest {
         when(_rootVols.get(eq(0))).thenReturn(_volumeMock);
         doReturn(3L).when(_volumeMock).getTemplateId();
         when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
-        when(_itMgr.stop(null, _userMock, _account)).thenReturn(true);
-        when(_itMgr.start(null, null, _userMock, _account)).thenReturn(_vmMock);
+//        when(_itMgr.stop(null, _userMock, _account)).thenReturn();
+//        when(_itMgr.start(null, null, _userMock, _account)).thenReturn();
         when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
         doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
         when(_volumeMock.getId()).thenReturn(3L);
@@ -203,13 +203,13 @@ public class UserVmManagerTest {
         doReturn(3L).when(_volumeMock).getTemplateId();
         when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
         doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
-        when(_itMgr.stop(null, _userMock, _account)).thenReturn(true);
+//        when(_itMgr.stop(null, _userMock, _account)).thenReturn(true);
         when(_storageMgr.allocateDuplicateVolume(_volumeMock, 14L)).thenReturn(_volumeMock);
         when(_templateMock.getGuestOSId()).thenReturn(5L);
         doNothing().when(_vmMock).setGuestOSId(anyLong());
         doNothing().when(_vmMock).setTemplateId(3L);
         when(_vmDao.update(314L, _vmMock)).thenReturn(true);
-        when(_itMgr.start(null, null, _userMock, _account)).thenReturn(_vmMock);
+//        when(_itMgr.start(null, null, _userMock, _account)).thenReturn(_vmMock);
         when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
         doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
         when(_volumeMock.getId()).thenReturn(3L);
@@ -357,7 +357,7 @@ public class UserVmManagerTest {
 
         //when(ApiDBUtils.getCpuOverprovisioningFactor()).thenReturn(3f);
         when(_capacityMgr.checkIfHostHasCapacity(anyLong(), anyInt(), anyLong(), anyBoolean(),
anyFloat(), anyFloat(),  anyBoolean())).thenReturn(false);
-        when(_itMgr.reConfigureVm(_vmInstance, so1, false)).thenReturn(_vmInstance);
+//        when(_itMgr.reConfigureVm(_vmInstance, so1, false)).thenReturn(_vmInstance);
 
         doReturn(true).when(_itMgr).upgradeVmDb(anyLong(), anyLong());
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/099778e3/server/test/com/cloud/vm/VmWorkMockVirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/VmWorkMockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/VmWorkMockVirtualMachineManagerImpl.java
index ea2c5bb..698fe80 100644
--- a/server/test/com/cloud/vm/VmWorkMockVirtualMachineManagerImpl.java
+++ b/server/test/com/cloud/vm/VmWorkMockVirtualMachineManagerImpl.java
@@ -120,7 +120,7 @@ public class VmWorkMockVirtualMachineManagerImpl implements VirtualMachineManage
 	}
 
 	@Override
-    public VirtualMachine allocate(String vmInstanceName, VMTemplateVO template,
+    public boolean allocate(String vmInstanceName, VMTemplateVO template,
 			ServiceOfferingVO serviceOffering,
 			Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
 			List<Pair<DiskOfferingVO, Long>> dataDiskOfferings,
@@ -128,47 +128,41 @@ public class VmWorkMockVirtualMachineManagerImpl implements VirtualMachineManage
 			Map<Param, Object> params, DeploymentPlan plan,
             HypervisorType hyperType, Account owner) {
 		// TODO Auto-generated method stub
-		return null;
+        return false;
 	}
 
 
 	@Override
-    public VirtualMachine allocate(String vmInstanceName, VMTemplateVO template,
+    public boolean allocate(String vmInstanceName, VMTemplateVO template,
 			ServiceOfferingVO serviceOffering,
 			List<Pair<NetworkVO, NicProfile>> networkProfiles,
             DeploymentPlan plan, HypervisorType hyperType, Account owner) {
 		// TODO Auto-generated method stub
-		return null;
+        return false;
 	}
 
 	@Override
-    public VirtualMachine start(String vmUuid, Map<Param, Object> params,
-			User caller, Account account) throws InsufficientCapacityException,
-			ResourceUnavailableException {
+    public void start(String vmUuid, Map<Param, Object> params,
+            User caller, Account account) {
 		// TODO Auto-generated method stub
-		return null;
 	}
 
 	@Override
-    public VirtualMachine start(String vmUuid, Map<Param, Object> params,
-			User caller, Account account, DeploymentPlan planToDeploy)
-			throws InsufficientCapacityException, ResourceUnavailableException {
+    public void start(String vmUuid, Map<Param, Object> params,
+            User caller, Account account, DeploymentPlan planToDeploy) {
 		// TODO Auto-generated method stub
-		return null;
 	}
 
 	@Override
-    public boolean stop(String vmUuid, User caller,
+    public void stop(String vmUuid, User caller,
             Account account) {
 		// TODO Auto-generated method stub
-		return false;
 	}
 
 	@Override
-    public boolean expunge(String vmUuid, User caller,
-			Account account) throws ResourceUnavailableException {
+    public void expunge(String vmUuid, User caller,
+            Account account) {
 		// TODO Auto-generated method stub
-		return false;
 	}
 
 	@Override
@@ -197,38 +191,34 @@ public class VmWorkMockVirtualMachineManagerImpl implements VirtualMachineManage
 	}
 
 	@Override
-    public VirtualMachine advanceStart(String vmUuid,
+    public void advanceStart(String vmUuid,
 			Map<Param, Object> params, User caller, Account account)
 			throws InsufficientCapacityException, ResourceUnavailableException,
 			ConcurrentOperationException, OperationTimedoutException {
 		// TODO Auto-generated method stub
-		return null;
 	}
 
 	@Override
-    public VirtualMachine advanceStart(String vmUuid,
+    public void advanceStart(String vmUuid,
 			Map<Param, Object> params, User caller, Account account,
 			DeploymentPlan planToDeploy) throws InsufficientCapacityException,
 			ResourceUnavailableException, ConcurrentOperationException,
 			OperationTimedoutException {
 		// TODO Auto-generated method stub
-		return null;
 	}
 
 	@Override
-    public boolean advanceStop(String vmUuid, boolean forced,
+    public void advanceStop(String vmUuid, boolean forced,
 			User caller, Account account) throws ResourceUnavailableException,
 			OperationTimedoutException, ConcurrentOperationException {
 		// TODO Auto-generated method stub
-		return false;
 	}
 
 	@Override
-    public boolean advanceExpunge(String vmUuid, User caller,
+    public void advanceExpunge(String vmUuid, User caller,
 			Account account) throws ResourceUnavailableException,
 			OperationTimedoutException, ConcurrentOperationException {
 		// TODO Auto-generated method stub
-		return false;
 	}
 
 	@Override
@@ -257,18 +247,16 @@ public class VmWorkMockVirtualMachineManagerImpl implements VirtualMachineManage
 	}
 
 	@Override
-    public boolean reboot(String vmUuid,
+    public void reboot(String vmUuid,
             User caller, Account account) {
 		// TODO Auto-generated method stub
-        return false;
 	}
 
 	@Override
-    public boolean advanceReboot(String vmUuid, User caller, Account account)
+    public void advanceReboot(String vmUuid, User caller, Account account)
 			throws InsufficientCapacityException, ResourceUnavailableException,
 			ConcurrentOperationException, OperationTimedoutException {
 		// TODO Auto-generated method stub
-        return false;
 	}
 
 	@Override
@@ -328,29 +316,29 @@ public class VmWorkMockVirtualMachineManagerImpl implements VirtualMachineManage
 	}
 
 	@Override
-    public VMInstanceVO reConfigureVm(VirtualMachine vm,
+    public boolean reConfigureVm(VirtualMachine vm,
 			ServiceOffering newServiceOffering, boolean sameHost)
 			throws ResourceUnavailableException, ConcurrentOperationException {
 		// TODO Auto-generated method stub
-		return null;
+        return false;
 	}
 
 	@Override
-    public VirtualMachine findHostAndMigrate(String vmUUid,
+    public boolean findHostAndMigrate(String vmUUid,
 			Long newSvcOfferingId) throws InsufficientCapacityException,
 			ConcurrentOperationException, ResourceUnavailableException,
 			VirtualMachineMigrationException, ManagementServerException {
 		// TODO Auto-generated method stub
-		return null;
+        return false;
 	}
 
 	@Override
-    public VirtualMachine migrateForScale(String vmUuid, long srcHostId,
+    public boolean migrateForScale(String vmUuid, long srcHostId,
 			DeployDestination dest, Long newSvcOfferingId)
 			throws ResourceUnavailableException, ConcurrentOperationException,
 			ManagementServerException, VirtualMachineMigrationException {
 		// TODO Auto-generated method stub
-		return null;
+        return false;
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/099778e3/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
index 00141f2..30d55b4 100755
--- a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
+++ b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java
@@ -17,20 +17,24 @@
 package com.cloud.utils.exception;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import com.cloud.utils.AnnotationHelper;
+import com.cloud.utils.Pair;
 import com.cloud.utils.SerialVersionUID;
 
 /**
  * wrap exceptions that you know there's no point in dealing with.
  */
-public class CloudRuntimeException extends RuntimeException {
+public class CloudRuntimeException extends RuntimeException implements ErrorContext {
 
     private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException;
 
     // This holds a list of uuids and their names. Add uuid:fieldname pairs
     protected ArrayList<String> idList = new ArrayList<String>();
 
+    protected ArrayList<Pair<Class<?>, String>> uuidList = new ArrayList<Pair<Class<?>,
String>>();
+
     protected int csErrorCode;
 
 
@@ -44,11 +48,11 @@ public class CloudRuntimeException extends RuntimeException {
         setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
     }
 
-    public CloudRuntimeException() {
+    protected CloudRuntimeException() {
         super();
         setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
     }
-
+    
     public void addProxyObject(String uuid) {
         idList.add(uuid);
         return;
@@ -63,19 +67,30 @@ public class CloudRuntimeException extends RuntimeException {
         return;
     }
 
+    @Override
+    public CloudRuntimeException add(Class<?> entity, String uuid) {
+        uuidList.add(new Pair<Class<?>, String>(entity, uuid));
+        return this;
+    }
+
     public ArrayList<String> getIdProxyList() {
         return idList;
     }
 
     public void setCSErrorCode(int cserrcode) {
-        this.csErrorCode = cserrcode;
+        csErrorCode = cserrcode;
     }
 
     public int getCSErrorCode() {
-        return this.csErrorCode;
+        return csErrorCode;
     }
 
     public CloudRuntimeException(Throwable t) {
-        super(t);
+        super(t.getMessage(), t);
+    }
+
+    @Override
+    public List<Pair<Class<?>, String>> getEntitiesInError() {
+        return uuidList;
     }
 }


Mime
View raw message