cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: updated refs/heads/4.3 to 96678bb
Date Sat, 14 Dec 2013 01:26:33 GMT
Updated Branches:
  refs/heads/4.3 bfb65aa5a -> 96678bbbf


CLOUDSTACK-669: refactor VM work job dispatcher to allow volume/snapshot manager to participate serialized job handling


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

Branch: refs/heads/4.3
Commit: 96678bbbfbe567f60ae3114b759e8ed1823d0cb7
Parents: bfb65aa
Author: Kelven Yang <kelveny@gmail.com>
Authored: Fri Dec 13 17:25:56 2013 -0800
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Fri Dec 13 17:26:13 2013 -0800

----------------------------------------------------------------------
 .../src/com/cloud/vm/VirtualMachineManager.java |  26 ---
 .../components-api/src/com/cloud/vm/VmWork.java |   9 +-
 ...spring-engine-orchestration-core-context.xml |   7 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java | 130 ++++++++++----
 .../src/com/cloud/vm/VmWorkAddVmToNetwork.java  |  10 +-
 .../src/com/cloud/vm/VmWorkJobDispatcher.java   | 177 +++++++++++--------
 .../src/com/cloud/vm/VmWorkJobHandler.java      |  26 +++
 .../src/com/cloud/vm/VmWorkMigrate.java         |   5 +-
 .../src/com/cloud/vm/VmWorkMigrateForScale.java |  10 +-
 .../com/cloud/vm/VmWorkMigrateWithStorage.java  |  10 +-
 .../src/com/cloud/vm/VmWorkReboot.java          |   4 +-
 .../src/com/cloud/vm/VmWorkReconfigure.java     |   8 +-
 .../src/com/cloud/vm/VmWorkRemoveNicFromVm.java |   6 +-
 .../com/cloud/vm/VmWorkRemoveVmFromNetwork.java |   8 +-
 .../src/com/cloud/vm/VmWorkStart.java           |   8 +-
 .../src/com/cloud/vm/VmWorkStop.java            |   4 +-
 .../com/cloud/vm/VmWorkStorageMigration.java    |   6 +-
 .../spring-server-core-managers-context.xml     |  10 +-
 18 files changed, 290 insertions(+), 174 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/api/src/com/cloud/vm/VirtualMachineManager.java
----------------------------------------------------------------------
diff --git a/engine/api/src/com/cloud/vm/VirtualMachineManager.java b/engine/api/src/com/cloud/vm/VirtualMachineManager.java
index c982c2e..f9bb935 100644
--- a/engine/api/src/com/cloud/vm/VirtualMachineManager.java
+++ b/engine/api/src/com/cloud/vm/VirtualMachineManager.java
@@ -103,13 +103,8 @@ public interface VirtualMachineManager extends Manager {
     void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
             ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
 
-    void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
-    	ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
-    
     void advanceStop(String vmUuid, boolean cleanupEvenIfUnableToStop) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
 
-    void orchestrateStop(String vmUuid, boolean cleanupEvenIfUnableToStop) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
-
     void advanceExpunge(String vmUuid) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
 
     void destroy(String vmUuid) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
@@ -118,16 +113,10 @@ public interface VirtualMachineManager extends Manager {
 
     void migrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException;
     
-    void orchestrateMigrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException;
-
     void migrateWithStorage(String vmUuid, long srcId, long destId, Map<Volume, StoragePool> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException;
     
-    void orchestrateMigrateWithStorage(String vmUuid, long srcId, long destId, Map<Volume, StoragePool> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException;
-    
     void reboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException;
 
-    void orchestrateReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException;
-
     void advanceReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException,
             ConcurrentOperationException, OperationTimedoutException;
 
@@ -143,8 +132,6 @@ public interface VirtualMachineManager extends Manager {
     VirtualMachine findById(long vmId);
 
     void storageMigration(String vmUuid, StoragePool storagePoolId);
-    
-    void orchestrateStorageMigration(String vmUuid, StoragePool storagePoolId);
 
     /**
      * @param vmInstance
@@ -171,10 +158,6 @@ public interface VirtualMachineManager extends Manager {
     NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
         ResourceUnavailableException, InsufficientCapacityException;
     
-    NicProfile orchestrateAddVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
-    	ResourceUnavailableException, InsufficientCapacityException;
-    
-
     /**
      * @param vm
      * @param nic
@@ -184,8 +167,6 @@ public interface VirtualMachineManager extends Manager {
      */
     boolean removeNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException;
 
-    boolean orchestrateRemoveNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException;
-
     /**
      * @param vm
      * @param network
@@ -196,8 +177,6 @@ public interface VirtualMachineManager extends Manager {
      */
     boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException;
     
-    boolean orchestrateRemoveVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException;
-
     /**
      * @param nic
      * @param hypervisorType
@@ -214,13 +193,8 @@ public interface VirtualMachineManager extends Manager {
 
     VirtualMachine reConfigureVm(String vmUuid, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException;
     
-    VirtualMachine orchestrateReConfigureVm(String vmUuid, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException;
-
     void findHostAndMigrate(String vmUuid, Long newSvcOfferingId, DeploymentPlanner.ExcludeList excludeHostList) throws InsufficientCapacityException,
             ConcurrentOperationException, ResourceUnavailableException;
 
     void migrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long newSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException;
-    
-    void orchestrateMigrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long newSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException;
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/components-api/src/com/cloud/vm/VmWork.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VmWork.java b/engine/components-api/src/com/cloud/vm/VmWork.java
index 3f9e71d..8a19cd6 100644
--- a/engine/components-api/src/com/cloud/vm/VmWork.java
+++ b/engine/components-api/src/com/cloud/vm/VmWork.java
@@ -25,10 +25,13 @@ public class VmWork implements Serializable {
 	long accountId;
 	long vmId;
 
-    public VmWork(long userId, long accountId, long vmId) {
+    String handlerName;
+
+    public VmWork(long userId, long accountId, long vmId, String handlerName) {
         this.userId = userId;
         this.accountId = accountId;
         this.vmId = vmId;
+        this.handlerName = handlerName;
 	}
 
 	public long getUserId() {
@@ -42,4 +45,8 @@ public class VmWork implements Serializable {
 	public long getVmId() {
 		return vmId;
 	}
+
+    public String getHandlerName() {
+        return handlerName;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
----------------------------------------------------------------------
diff --git a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
index fc3bae3..49cb9cd 100644
--- a/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
+++ b/engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml
@@ -60,7 +60,6 @@
 
     <bean id="clusteredAgentManagerImpl" class="com.cloud.agent.manager.ClusteredAgentManagerImpl" />
 
-
     <bean id="cloudOrchestrator"
         class="org.apache.cloudstack.engine.orchestration.CloudOrchestrator" />
     <bean id="dataCenterResourceManagerImpl"
@@ -73,10 +72,16 @@
     <bean id="virtualMachineEntityImpl" class="org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl" />
     
     <bean id="virtualMachinePowerStateSyncImpl" class="com.cloud.vm.VirtualMachinePowerStateSyncImpl" />
+      
     <bean id= "vmWorkJobDispatcher" class="com.cloud.vm.VmWorkJobDispatcher">
         <property name="name">
             <util:constant static-field="com.cloud.vm.VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER"/>
         </property>
+        <property name="handlers">
+            <map>
+                <entry key="VirtualMachineManagerImpl" value-ref="clusteredVirtualMachineManagerImpl" />
+            </map>
+        </property>
     </bean>
     <bean id= "vmWorkJobWakeupDispatcher" class="com.cloud.vm.VmWorkJobWakeupDispatcher">
         <property name="name">

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 849ebcf..bc6a32f 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -205,9 +205,11 @@ import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
 
 @Local(value = VirtualMachineManager.class)
-public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager, Listener, Configurable {
+public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager, VmWorkJobHandler, Listener, Configurable {
     private static final Logger s_logger = Logger.getLogger(VirtualMachineManagerImpl.class);
 
+    public static final String VM_WORK_JOB_HANDLER = VirtualMachineManagerImpl.class.getSimpleName();
+
     private static final String VM_SYNC_ALERT_SUBJECT = "VM state sync alert";
     
     @Inject
@@ -270,6 +272,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
     @Inject
     protected EntityManager _entityMgr;
+
     @Inject
     ConfigDepot _configDepot;
 
@@ -726,8 +729,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
     
-    @Override
-    public void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
+    private void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
     	ConcurrentOperationException, ResourceUnavailableException {
         
     	CallContext cctxt = CallContext.current();
@@ -1250,8 +1252,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
 
-    @Override
-    public void orchestrateStop(String vmUuid, boolean cleanUpEvenIfUnableToStop) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
+    private void orchestrateStop(String vmUuid, boolean cleanUpEvenIfUnableToStop) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
         advanceStop(vm, cleanUpEvenIfUnableToStop);
@@ -1537,8 +1538,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
 
-    @Override
-    public void orchestrateStorageMigration(String vmUuid, StoragePool destPool) {
+    private void orchestrateStorageMigration(String vmUuid, StoragePool destPool) {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
         try {
@@ -1624,8 +1624,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
     
-    @Override
-    public void orchestrateMigrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException {
+    private void orchestrateMigrate(String vmUuid, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
         if (vm == null) {
             if (s_logger.isDebugEnabled()) {
@@ -1894,8 +1893,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
     
-    @Override
-    public void orchestrateMigrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map<Volume, StoragePool> volumeToPool) throws ResourceUnavailableException,
+    private void orchestrateMigrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map<Volume, StoragePool> volumeToPool) throws ResourceUnavailableException,
     	ConcurrentOperationException {
     	
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
@@ -2176,8 +2174,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
     
-    @Override
-    public void orchestrateReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException,
+    private void orchestrateReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException,
     ResourceUnavailableException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
@@ -3110,8 +3107,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
     
-    @Override
-    public NicProfile orchestrateAddVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException,
+    private NicProfile orchestrateAddVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException,
     InsufficientCapacityException {
         CallContext cctx = CallContext.current();
 
@@ -3217,8 +3213,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
 
-    @Override
-    public boolean orchestrateRemoveNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
+    private boolean orchestrateRemoveNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
         CallContext cctx = CallContext.current();
         VMInstanceVO vmVO = _vmDao.findById(vm.getId());
         NetworkVO network = _networkDao.findById(nic.getNetworkId());
@@ -3282,9 +3277,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	return orchestrateRemoveVmFromNetwork(vm, network, broadcastUri);
     }
     
-    @Override
     @DB
-    public boolean orchestrateRemoveVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
+    private boolean orchestrateRemoveVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
         CallContext cctx = CallContext.current();
         VMInstanceVO vmVO = _vmDao.findById(vm.getId());
         ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount());
@@ -3449,8 +3443,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
 
-    @Override
-    public void orchestrateMigrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long oldSvcOfferingId)
+    private void orchestrateMigrateForScale(String vmUuid, long srcHostId, DeployDestination dest, Long oldSvcOfferingId)
     	throws ResourceUnavailableException, ConcurrentOperationException {
         
     	VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
@@ -3707,8 +3700,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	}
     }
     
-    @Override
-    public VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, boolean reconfiguringOnExistingHost) throws ResourceUnavailableException,
+    private VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, boolean reconfiguringOnExistingHost) throws ResourceUnavailableException,
     ConcurrentOperationException {
         VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
@@ -4166,7 +4158,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     	            workJob.setVmInstanceId(vm.getId());
 
     	            // save work context info (there are some duplications)
-    	            VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId());
+                    VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER);
     	            workInfo.setPlan(planToDeploy);
     	            workInfo.setParams(params);
     	            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
@@ -4220,7 +4212,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		            workJob.setVmInstanceId(vm.getId());
 		
 		            // save work context info (there are some duplications)
-		            VmWorkStop workInfo = new VmWorkStop(user.getId(), account.getId(), vm.getId(), cleanup);
+                    VmWorkStop workInfo = new VmWorkStop(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, cleanup);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4273,7 +4265,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		            workJob.setVmInstanceId(vm.getId());
 		
 		            // save work context info (there are some duplications)
-		            VmWorkReboot workInfo = new VmWorkReboot(user.getId(), account.getId(), vm.getId(), params);
+                    VmWorkReboot workInfo = new VmWorkReboot(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, params);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4325,7 +4317,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		            workJob.setVmInstanceId(vm.getId());
 		
 		            // save work context info (there are some duplications)
-		            VmWorkMigrate workInfo = new VmWorkMigrate(user.getId(), account.getId(), vm.getId(), srcHostId, dest);
+                    VmWorkMigrate workInfo = new VmWorkMigrate(user.getId(), account.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, dest);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4380,7 +4372,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkMigrateWithStorage workInfo = new VmWorkMigrateWithStorage(user.getId(), account.getId(), vm.getId(),
-		            	srcHostId, destHostId, volumeToPool);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, destHostId, volumeToPool);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4434,7 +4426,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkMigrateForScale workInfo = new VmWorkMigrateForScale(user.getId(), account.getId(), vm.getId(),
-		            	srcHostId, dest, newSvcOfferingId);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, srcHostId, dest, newSvcOfferingId);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4487,7 +4479,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkStorageMigration workInfo = new VmWorkStorageMigration(user.getId(), account.getId(), vm.getId(),
-		            	destPool);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, destPool);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4538,7 +4530,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(),
-		            	network, requested);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, requested);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4589,7 +4581,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(),
-		            	nic);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4640,7 +4632,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkRemoveVmFromNetwork workInfo = new VmWorkRemoveVmFromNetwork(user.getId(), account.getId(), vm.getId(),
-		            	network, broadcastUri);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, broadcastUri);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4693,7 +4685,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 		
 		            // save work context info (there are some duplications)
 		            VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(),
-		            		oldServiceOffering, reconfiguringOnExistingHost);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, oldServiceOffering, reconfiguringOnExistingHost);
 		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 		
 		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
@@ -4709,4 +4701,74 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
    
+    @Override
+    public Pair<JobInfo.Status, String> handleVmWorkJob(AsyncJob job, VmWork work) throws Exception {
+
+        VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, work.getVmId());
+        if (vm == null) {
+            s_logger.info("Unable to find vm " + work.getVmId());
+        }
+        assert (vm != null);
+        if (work instanceof VmWorkStart) {
+            VmWorkStart workStart = (VmWorkStart)work;
+            orchestrateStart(vm.getUuid(), workStart.getParams(), workStart.getPlan());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkStop) {
+            VmWorkStop workStop = (VmWorkStop)work;
+            orchestrateStop(vm.getUuid(), workStop.isCleanup());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkMigrate) {
+            VmWorkMigrate workMigrate = (VmWorkMigrate)work;
+            orchestrateMigrate(vm.getUuid(), workMigrate.getSrcHostId(), workMigrate.getDeployDestination());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkMigrateWithStorage) {
+            VmWorkMigrateWithStorage workMigrateWithStorage = (VmWorkMigrateWithStorage)work;
+            orchestrateMigrateWithStorage(vm.getUuid(),
+                    workMigrateWithStorage.getSrcHostId(),
+                    workMigrateWithStorage.getDestHostId(),
+                    workMigrateWithStorage.getVolumeToPool());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkMigrateForScale) {
+            VmWorkMigrateForScale workMigrateForScale = (VmWorkMigrateForScale)work;
+            orchestrateMigrateForScale(vm.getUuid(),
+                    workMigrateForScale.getSrcHostId(),
+                    workMigrateForScale.getDeployDestination(),
+                    workMigrateForScale.getNewServiceOfferringId());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkReboot) {
+            VmWorkReboot workReboot = (VmWorkReboot)work;
+            orchestrateReboot(vm.getUuid(), workReboot.getParams());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkAddVmToNetwork) {
+            VmWorkAddVmToNetwork workAddVmToNetwork = (VmWorkAddVmToNetwork)work;
+            NicProfile nic = orchestrateAddVmToNetwork(vm, workAddVmToNetwork.getNetwork(),
+                    workAddVmToNetwork.getRequestedNicProfile());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, JobSerializerHelper.toObjectSerializedString(nic));
+        } else if (work instanceof VmWorkRemoveNicFromVm) {
+            VmWorkRemoveNicFromVm workRemoveNicFromVm = (VmWorkRemoveNicFromVm)work;
+            boolean result = orchestrateRemoveNicFromVm(vm, workRemoveNicFromVm.getNic());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED,
+                    JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
+        } else if (work instanceof VmWorkRemoveVmFromNetwork) {
+            VmWorkRemoveVmFromNetwork workRemoveVmFromNetwork = (VmWorkRemoveVmFromNetwork)work;
+            boolean result = orchestrateRemoveVmFromNetwork(vm,
+                    workRemoveVmFromNetwork.getNetwork(), workRemoveVmFromNetwork.getBroadcastUri());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED,
+                    JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
+        } else if (work instanceof VmWorkReconfigure) {
+            VmWorkReconfigure workReconfigure = (VmWorkReconfigure)work;
+            reConfigureVm(vm.getUuid(), workReconfigure.getNewServiceOffering(),
+                    workReconfigure.isSameHost());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else if (work instanceof VmWorkStorageMigration) {
+            VmWorkStorageMigration workStorageMigration = (VmWorkStorageMigration)work;
+            orchestrateStorageMigration(vm.getUuid(), workStorageMigration.getDestStoragePool());
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
+        } else {
+            RuntimeException e = new RuntimeException("Unsupported VM work command: " + job.getCmd());
+            String exceptionJson = JobSerializerHelper.toSerializedString(e);
+            s_logger.error("Serialize exception object into json: " + exceptionJson);
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.FAILED, exceptionJson);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java b/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
index 3590c0d..25858e4 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
@@ -24,19 +24,19 @@ public class VmWorkAddVmToNetwork extends VmWork {
 	Network network;
 	NicProfile requstedNicProfile;
 	
-	public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, 
+    public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, String handlerName,
 		Network network, NicProfile requested) {
-		super(userId, accountId, vmId);
+        super(userId, accountId, vmId, handlerName);
 	
 		this.network = network;
-		this.requstedNicProfile = requested;
+		requstedNicProfile = requested;
 	}
 	
 	public Network getNetwork() {
-		return this.network;
+		return network;
 	}
 	
 	public NicProfile getRequestedNicProfile() {
-		return this.requstedNicProfile;
+		return requstedNicProfile;
 	}
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java b/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
index 7c36d8c..00eb1ed 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java
@@ -16,9 +16,12 @@
 // under the License.
 package com.cloud.vm;
 
+import java.util.Map;
+
 import javax.inject.Inject;
 
 import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.jobs.AsyncJob;
 import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
@@ -26,6 +29,7 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
 import org.apache.cloudstack.jobs.JobInfo;
 
+import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.vm.dao.VMInstanceDao;
 
@@ -40,6 +44,19 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch
 	@Inject private AsyncJobManager _asyncJobMgr;
     @Inject private VMInstanceDao _instanceDao;
     
+    private Map<String, VmWorkJobHandler> _handlers;
+
+    public VmWorkJobDispatcher() {
+    }
+
+    public Map<String, VmWorkJobHandler> getHandlers() {
+        return _handlers;
+    }
+
+    public void setHandlers(Map<String, VmWorkJobHandler> handlers) {
+        _handlers = handlers;
+    }
+
 	@Override
     public void runJob(AsyncJob job) {
         VmWork work = null;
@@ -67,78 +84,98 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch
         		return;
             }
             
-            CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());
-
-            VMInstanceVO vm = _instanceDao.findById(work.getVmId());
-            if (vm == null) {
-                s_logger.info("Unable to find vm " + work.getVmId());
+            if (_handlers == null || _handlers.isEmpty()) {
+                s_logger.error("Invalid startup configuration, no work job handler is found. cmd: " + job.getCmd() + ", job info: " + job.getCmdInfo());
+                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, "Invalid startup configuration. no job handler is found");
+                return;
             }
-            assert(vm != null);
-            if(work instanceof VmWorkStart) {
-            	VmWorkStart workStart = (VmWorkStart)work;
-            	_vmMgr.orchestrateStart(vm.getUuid(), workStart.getParams(), workStart.getPlan());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkStop) {
-            	VmWorkStop workStop = (VmWorkStop)work;
-            	_vmMgr.orchestrateStop(vm.getUuid(), workStop.isCleanup());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkMigrate) {
-            	VmWorkMigrate workMigrate = (VmWorkMigrate)work;
-            	_vmMgr.orchestrateMigrate(vm.getUuid(), workMigrate.getSrcHostId(), workMigrate.getDeployDestination());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkMigrateWithStorage) {
-            	VmWorkMigrateWithStorage workMigrateWithStorage = (VmWorkMigrateWithStorage)work;
-            	_vmMgr.orchestrateMigrateWithStorage(vm.getUuid(), 
-            		workMigrateWithStorage.getSrcHostId(), 
-            		workMigrateWithStorage.getDestHostId(), 
-            		workMigrateWithStorage.getVolumeToPool());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkMigrateForScale) { 
-            	VmWorkMigrateForScale workMigrateForScale = (VmWorkMigrateForScale)work;
-            	_vmMgr.orchestrateMigrateForScale(vm.getUuid(), 
-            		workMigrateForScale.getSrcHostId(), 
-            		workMigrateForScale.getDeployDestination(), 
-            		workMigrateForScale.getNewServiceOfferringId());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkReboot) { 
-                VmWorkReboot workReboot = (VmWorkReboot)work;
-                _vmMgr.orchestrateReboot(vm.getUuid(), workReboot.getParams());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkAddVmToNetwork) { 
-                VmWorkAddVmToNetwork workAddVmToNetwork = (VmWorkAddVmToNetwork)work;
-                NicProfile nic = _vmMgr.orchestrateAddVmToNetwork(vm, workAddVmToNetwork.getNetwork(), 
-                	workAddVmToNetwork.getRequestedNicProfile());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, 
-                    JobSerializerHelper.toObjectSerializedString(nic));
-            } else if(work instanceof VmWorkRemoveNicFromVm) { 
-                VmWorkRemoveNicFromVm workRemoveNicFromVm = (VmWorkRemoveNicFromVm)work;
-                boolean result = _vmMgr.orchestrateRemoveNicFromVm(vm, workRemoveNicFromVm.getNic());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, 
-                	JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
-            } else if(work instanceof VmWorkRemoveVmFromNetwork) { 
-                VmWorkRemoveVmFromNetwork workRemoveVmFromNetwork = (VmWorkRemoveVmFromNetwork)work;
-                boolean result = _vmMgr.orchestrateRemoveVmFromNetwork(vm, 
-                	workRemoveVmFromNetwork.getNetwork(), workRemoveVmFromNetwork.getBroadcastUri());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, 
-                    	JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
-            } else if(work instanceof VmWorkReconfigure) { 
-                VmWorkReconfigure workReconfigure = (VmWorkReconfigure)work;
-                _vmMgr.reConfigureVm(vm.getUuid(), workReconfigure.getNewServiceOffering(), 
-                	workReconfigure.isSameHost());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else if(work instanceof VmWorkStorageMigration) { 
-                VmWorkStorageMigration workStorageMigration = (VmWorkStorageMigration)work;
-                _vmMgr.orchestrateStorageMigration(vm.getUuid(), workStorageMigration.getDestStoragePool());
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
-            } else {
-            	assert(false);
-                s_logger.error("Unhandled VM work command: " + job.getCmd());
-            	
-            	RuntimeException e = new RuntimeException("Unsupported VM work command: " + job.getCmd());
-                String exceptionJson = JobSerializerHelper.toSerializedString(e);
-                s_logger.error("Serialize exception object into json: " + exceptionJson);
-                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, exceptionJson);
+
+            VmWorkJobHandler handler = _handlers.get(work.getHandlerName());
+            
+            if (handler == null) {
+                s_logger.error("Unable to find work job handler. handler name: " + work.getHandlerName() + ", job cmd: " + job.getCmd() + ", job info: " + job.getCmdInfo());
+                _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, "Unable to find work job handler");
+                return;
             }
+
+            CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());
+            
+            Pair<JobInfo.Status, String> result = handler.handleVmWorkJob(job, work);
+            _asyncJobMgr.completeAsyncJob(job.getId(), result.first(), 0, result.second());
+            
+/*
+                        VMInstanceVO vm = _instanceDao.findById(work.getVmId());
+                        if (vm == null) {
+                            s_logger.info("Unable to find vm " + work.getVmId());
+                        }
+                        assert(vm != null);
+                        if(work instanceof VmWorkStart) {
+                        	VmWorkStart workStart = (VmWorkStart)work;
+                        	_vmMgr.orchestrateStart(vm.getUuid(), workStart.getParams(), workStart.getPlan());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkStop) {
+                        	VmWorkStop workStop = (VmWorkStop)work;
+                        	_vmMgr.orchestrateStop(vm.getUuid(), workStop.isCleanup());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkMigrate) {
+                        	VmWorkMigrate workMigrate = (VmWorkMigrate)work;
+                        	_vmMgr.orchestrateMigrate(vm.getUuid(), workMigrate.getSrcHostId(), workMigrate.getDeployDestination());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkMigrateWithStorage) {
+                        	VmWorkMigrateWithStorage workMigrateWithStorage = (VmWorkMigrateWithStorage)work;
+                        	_vmMgr.orchestrateMigrateWithStorage(vm.getUuid(),
+                        		workMigrateWithStorage.getSrcHostId(),
+                        		workMigrateWithStorage.getDestHostId(),
+                        		workMigrateWithStorage.getVolumeToPool());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkMigrateForScale) {
+                        	VmWorkMigrateForScale workMigrateForScale = (VmWorkMigrateForScale)work;
+                        	_vmMgr.orchestrateMigrateForScale(vm.getUuid(),
+                        		workMigrateForScale.getSrcHostId(),
+                        		workMigrateForScale.getDeployDestination(),
+                        		workMigrateForScale.getNewServiceOfferringId());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkReboot) {
+                            VmWorkReboot workReboot = (VmWorkReboot)work;
+                            _vmMgr.orchestrateReboot(vm.getUuid(), workReboot.getParams());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkAddVmToNetwork) {
+                            VmWorkAddVmToNetwork workAddVmToNetwork = (VmWorkAddVmToNetwork)work;
+                            NicProfile nic = _vmMgr.orchestrateAddVmToNetwork(vm, workAddVmToNetwork.getNetwork(),
+                            	workAddVmToNetwork.getRequestedNicProfile());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
+                                JobSerializerHelper.toObjectSerializedString(nic));
+                        } else if(work instanceof VmWorkRemoveNicFromVm) {
+                            VmWorkRemoveNicFromVm workRemoveNicFromVm = (VmWorkRemoveNicFromVm)work;
+                            boolean result = _vmMgr.orchestrateRemoveNicFromVm(vm, workRemoveNicFromVm.getNic());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
+                            	JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
+                        } else if(work instanceof VmWorkRemoveVmFromNetwork) {
+                            VmWorkRemoveVmFromNetwork workRemoveVmFromNetwork = (VmWorkRemoveVmFromNetwork)work;
+                            boolean result = _vmMgr.orchestrateRemoveVmFromNetwork(vm,
+                            	workRemoveVmFromNetwork.getNetwork(), workRemoveVmFromNetwork.getBroadcastUri());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
+                                	JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
+                        } else if(work instanceof VmWorkReconfigure) {
+                            VmWorkReconfigure workReconfigure = (VmWorkReconfigure)work;
+                            _vmMgr.reConfigureVm(vm.getUuid(), workReconfigure.getNewServiceOffering(),
+                            	workReconfigure.isSameHost());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else if(work instanceof VmWorkStorageMigration) {
+                            VmWorkStorageMigration workStorageMigration = (VmWorkStorageMigration)work;
+                            _vmMgr.orchestrateStorageMigration(vm.getUuid(), workStorageMigration.getDestStoragePool());
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
+                        } else {
+                        	assert(false);
+                            s_logger.error("Unhandled VM work command: " + job.getCmd());
+                        	
+                        	RuntimeException e = new RuntimeException("Unsupported VM work command: " + job.getCmd());
+                            String exceptionJson = JobSerializerHelper.toSerializedString(e);
+                            s_logger.error("Serialize exception object into json: " + exceptionJson);
+                            _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, exceptionJson);
+                        }
+            */
+
         } catch(Throwable e) {
             s_logger.error("Unable to complete " + job, e);
             

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java b/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java
new file mode 100644
index 0000000..6ab1bbc
--- /dev/null
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+import org.apache.cloudstack.framework.jobs.AsyncJob;
+import org.apache.cloudstack.jobs.JobInfo;
+
+import com.cloud.utils.Pair;
+
+public interface VmWorkJobHandler {
+    Pair<JobInfo.Status, String> handleVmWorkJob(AsyncJob job, VmWork work) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkMigrate.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkMigrate.java b/engine/orchestration/src/com/cloud/vm/VmWorkMigrate.java
index c313876..51ee52c 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkMigrate.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkMigrate.java
@@ -38,8 +38,9 @@ public class VmWorkMigrate extends VmWork {
     private Map<String, String> storage;
     long srcHostId;
 
-    public VmWorkMigrate(long userId, long accountId, long vmId, long srcHostId, DeployDestination dst) {
-        super(userId, accountId, vmId);
+    public VmWorkMigrate(long userId, long accountId, long vmId, String handlerName,
+            long srcHostId, DeployDestination dst) {
+        super(userId, accountId, vmId, handlerName);
         this.srcHostId = srcHostId;
         zoneId = dst.getDataCenter() != null ? dst.getDataCenter().getId() : null;
         podId = dst.getPod() != null ? dst.getPod().getId() : null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkMigrateForScale.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkMigrateForScale.java b/engine/orchestration/src/com/cloud/vm/VmWorkMigrateForScale.java
index 8e71aa8..9b59f67 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkMigrateForScale.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkMigrateForScale.java
@@ -25,12 +25,12 @@ public class VmWorkMigrateForScale extends VmWork {
 	DeployDestination deployDestination;
 	Long newSvcOfferingId;
 	
-    public VmWorkMigrateForScale(long userId, long accountId, long vmId, long srcHostId, 
+    public VmWorkMigrateForScale(long userId, long accountId, long vmId, String handlerName, long srcHostId,
     	DeployDestination dest, Long newSvcOfferingId) {
     	
-    	super(userId, accountId, vmId);
+        super(userId, accountId, vmId, handlerName);
     	this.srcHostId = srcHostId;
-    	this.deployDestination = dest;
+    	deployDestination = dest;
     	this.newSvcOfferingId = newSvcOfferingId;
     }
 	
@@ -39,10 +39,10 @@ public class VmWorkMigrateForScale extends VmWork {
     }
     
     public DeployDestination getDeployDestination() {
-    	return this.deployDestination;
+    	return deployDestination;
     }
     
     public Long getNewServiceOfferringId() {
-    	return this.newSvcOfferingId;
+    	return newSvcOfferingId;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java b/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java
index ae91231..37a6ba4 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkMigrateWithStorage.java
@@ -28,10 +28,10 @@ public class VmWorkMigrateWithStorage extends VmWork {
 	long destHostId;
 	Map<Volume, StoragePool> volumeToPool;
 	
-    public VmWorkMigrateWithStorage(long userId, long accountId, long vmId, long srcHostId, 
+    public VmWorkMigrateWithStorage(long userId, long accountId, long vmId, String handlerName, long srcHostId,
     	long destHostId, Map<Volume, StoragePool> volumeToPool) {
     	
-    	super(userId, accountId, vmId);
+        super(userId, accountId, vmId, handlerName);
     
     	this.srcHostId = srcHostId;
     	this.destHostId = destHostId;
@@ -39,14 +39,14 @@ public class VmWorkMigrateWithStorage extends VmWork {
     }
     
     public long getSrcHostId() {
-    	return this.srcHostId;
+    	return srcHostId;
     }
     
     public long getDestHostId() {
-    	return this.destHostId;
+    	return destHostId;
     }
     
     public Map<Volume, StoragePool> getVolumeToPool() {
-    	return this.volumeToPool;
+    	return volumeToPool;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkReboot.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkReboot.java b/engine/orchestration/src/com/cloud/vm/VmWorkReboot.java
index 8f50702..8e69f89 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkReboot.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkReboot.java
@@ -28,8 +28,8 @@ public class VmWorkReboot extends VmWork {
 	// use serialization friendly map
 	private Map<String, String> rawParams;
 	
-    public VmWorkReboot(long userId, long accountId, long vmId, Map<VirtualMachineProfile.Param, Object> params) {
-    	super(userId, accountId, vmId);
+    public VmWorkReboot(long userId, long accountId, long vmId, String handlerName, Map<VirtualMachineProfile.Param, Object> params) {
+        super(userId, accountId, vmId, handlerName);
     	
     	setParams(params);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkReconfigure.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkReconfigure.java b/engine/orchestration/src/com/cloud/vm/VmWorkReconfigure.java
index 48a9df3..bfc5735 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkReconfigure.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkReconfigure.java
@@ -24,20 +24,20 @@ public class VmWorkReconfigure extends VmWork {
 	ServiceOffering newServiceOffering;
 	boolean sameHost;
 	
-    public VmWorkReconfigure(long userId, long accountId, long vmId, 
+    public VmWorkReconfigure(long userId, long accountId, long vmId, String handlerName,
     	ServiceOffering newServiceOffering, boolean sameHost) {
     	
-    	super(userId, accountId, vmId);
+        super(userId, accountId, vmId, handlerName);
     	
     	this.newServiceOffering = newServiceOffering;
     	this.sameHost = sameHost;
     }
     
     public ServiceOffering getNewServiceOffering() {
-    	return this.newServiceOffering;
+    	return newServiceOffering;
     }
     
     public boolean isSameHost() {
-    	return this.sameHost;
+    	return sameHost;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java b/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
index b756ac3..3dfbf27 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
@@ -21,13 +21,13 @@ public class VmWorkRemoveNicFromVm extends VmWork {
 
 	Nic nic;
     
-	public VmWorkRemoveNicFromVm(long userId, long accountId, long vmId, Nic nic) {
-    	super(userId, accountId, vmId);
+    public VmWorkRemoveNicFromVm(long userId, long accountId, long vmId, String handlerName, Nic nic) {
+        super(userId, accountId, vmId, handlerName);
     	
     	this.nic = nic;
     }
     
     public Nic getNic() {
-    	return this.nic;
+    	return nic;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkRemoveVmFromNetwork.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkRemoveVmFromNetwork.java b/engine/orchestration/src/com/cloud/vm/VmWorkRemoveVmFromNetwork.java
index d4e0ae4..0cb02b2 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkRemoveVmFromNetwork.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkRemoveVmFromNetwork.java
@@ -26,18 +26,18 @@ public class VmWorkRemoveVmFromNetwork extends VmWork {
 	Network network;
 	URI broadcastUri;
 	
-	public VmWorkRemoveVmFromNetwork(long userId, long accountId, long vmId, Network network, URI broadcastUri) {
-    	super(userId, accountId, vmId);
+    public VmWorkRemoveVmFromNetwork(long userId, long accountId, long vmId, String handlerName, Network network, URI broadcastUri) {
+        super(userId, accountId, vmId, handlerName);
     	
     	this.network = network;
     	this.broadcastUri = broadcastUri;
 	}
 	
 	public Network getNetwork() {
-		return this.network;
+		return network;
 	}
 	
 	public URI getBroadcastUri() {
-		return this.broadcastUri;
+		return broadcastUri;
 	}
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkStart.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkStart.java b/engine/orchestration/src/com/cloud/vm/VmWorkStart.java
index 7a7447f..caa4cfb 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkStart.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkStart.java
@@ -50,8 +50,8 @@ public class VmWorkStart extends VmWork {
 	// use serialization friendly map
 	private Map<String, String> rawParams;
 
-    public VmWorkStart(long userId, long accountId, long vmId) {
-        super(userId, accountId, vmId);
+    public VmWorkStart(long userId, long accountId, long vmId, String handlerName) {
+        super(userId, accountId, vmId, handlerName);
 	}
 
 	public DeploymentPlan getPlan() {
@@ -62,8 +62,8 @@ public class VmWorkStart extends VmWork {
 			ReservationContext context = null;
 			if(reservationId != null) {
 		        Journal journal = new Journal.LogJournal("VmWorkStart", s_logger);
-				context = new ReservationContextImpl(reservationId, journal, 
-						CallContext.current().getCallingUser(), 
+				context = new ReservationContextImpl(reservationId, journal,
+						CallContext.current().getCallingUser(),
 						CallContext.current().getCallingAccount());
 			}
 			

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkStop.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkStop.java b/engine/orchestration/src/com/cloud/vm/VmWorkStop.java
index 0a27057..4b2c00c 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkStop.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkStop.java
@@ -21,8 +21,8 @@ public class VmWorkStop extends VmWork {
 	
 	private final boolean cleanup;
 	
-    public VmWorkStop(long userId, long accountId, long vmId, boolean cleanup) {
-        super(userId, accountId, vmId);
+    public VmWorkStop(long userId, long accountId, long vmId, String handlerName, boolean cleanup) {
+        super(userId, accountId, vmId, handlerName);
         this.cleanup = cleanup;
 	}
 	

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/engine/orchestration/src/com/cloud/vm/VmWorkStorageMigration.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkStorageMigration.java b/engine/orchestration/src/com/cloud/vm/VmWorkStorageMigration.java
index ba8330c..c8df5a9 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkStorageMigration.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkStorageMigration.java
@@ -23,13 +23,13 @@ public class VmWorkStorageMigration extends VmWork {
 
 	StoragePool destPool;
 	
-    public VmWorkStorageMigration(long userId, long accountId, long vmId, StoragePool destPool) {
-    	super(userId, accountId, vmId);
+    public VmWorkStorageMigration(long userId, long accountId, long vmId, String handlerName, StoragePool destPool) {
+        super(userId, accountId, vmId, handlerName);
     	
     	this.destPool = destPool;
     }
     
     public StoragePool getDestStoragePool() {
-    	return this.destPool;
+    	return destPool;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96678bbb/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
----------------------------------------------------------------------
diff --git a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
index bcb218a..2fe76ba 100644
--- a/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
+++ b/server/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml
@@ -20,11 +20,16 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
+       xmlns:util="http://www.springframework.org/schema/util"
+       
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                      http://www.springframework.org/schema/aop 
+                      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                       http://www.springframework.org/schema/context
-                      http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+                      http://www.springframework.org/schema/context/spring-context-3.0.xsd
+                      http://www.springframework.org/schema/util
+                      http://www.springframework.org/schema/util/spring-util-3.0.xsd"
                       >
 
     <bean id="accountManagerImpl" class="com.cloud.user.AccountManagerImpl">
@@ -228,5 +233,4 @@
         class="org.apache.cloudstack.region.gslb.GlobalLoadBalancingRulesServiceImpl" />
 
     <bean id="certServiceImpl" class="org.apache.cloudstack.network.lb.CertServiceImpl" />
-
 </beans>


Mime
View raw message