You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/12/12 22:01:24 UTC

[24/48] All Checkstyle problems corrected

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
index d1fd2a7..01508a4 100755
--- a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
@@ -94,7 +94,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.nio.Link;
 import com.cloud.utils.nio.Task;
 
-@Local(value = { AgentManager.class, ClusteredAgentRebalanceService.class })
+@Local(value = {AgentManager.class, ClusteredAgentRebalanceService.class})
 public class ClusteredAgentManagerImpl extends AgentManagerImpl implements ClusterManagerListener, ClusteredAgentRebalanceService {
     final static Logger s_logger = Logger.getLogger(ClusteredAgentManagerImpl.class);
     private static final ScheduledExecutorService s_transferExecutor = Executors.newScheduledThreadPool(2, new NamedThreadFactory("Cluster-AgentRebalancingExecutor"));
@@ -128,13 +128,13 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
     }
 
     protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false",
-            "Enable agent load balancing between management server nodes", true);
+        "Enable agent load balancing between management server nodes", true);
     protected final ConfigKey<Double> ConnectedAgentThreshold = new ConfigKey<Double>(Double.class, "agent.load.threshold", "Advanced", "0.7",
-            "What percentage of the agents can be held by one management server before load balancing happens", true);
+        "What percentage of the agents can be held by one management server before load balancing happens", true);
     protected final ConfigKey<Integer> LoadSize = new ConfigKey<Integer>(Integer.class, "direct.agent.load.size", "Advanced", "16",
-            "How many agents to connect to in each round", true);
+        "How many agents to connect to in each round", true);
     protected final ConfigKey<Integer> ScanInterval = new ConfigKey<Integer>(Integer.class, "direct.agent.scan.interval", "Advanced", "90",
-            "Interval between scans to load agents", false, ConfigKey.Scope.Global, 1000);
+        "Interval between scans to load agents", false, ConfigKey.Scope.Global, 1000);
 
     @Override
     public boolean configure(String name, Map<String, Object> xmlParams) throws ConfigurationException {
@@ -334,7 +334,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                     if (transferVO != null) {
                         if (transferVO.getFutureOwner() == _nodeId && transferVO.getState() == HostTransferState.TransferStarted) {
                             s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " +
-                                    _nodeId);
+                                _nodeId);
                             return true;
                         }
                     }
@@ -344,7 +344,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                 // but the host has already reconnected to the current management server
                 if (!attache.forForward()) {
                     s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId +
-                            " as the host is directly connected to the current management server " + _nodeId);
+                        " as the host is directly connected to the current management server " + _nodeId);
                     return true;
                 }
 
@@ -375,7 +375,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
 
     public void notifyNodesInCluster(AgentAttache attache) {
         s_logger.debug("Notifying other nodes of to disconnect");
-        Command[] cmds = new Command[] { new ChangeAgentCommand(attache.getId(), Event.AgentDisconnected) };
+        Command[] cmds = new Command[] {new ChangeAgentCommand(attache.getId(), Event.AgentDisconnected)};
         _clusterMgr.broadcast(attache.getId(), _gson.toJson(cmds));
     }
 
@@ -384,23 +384,23 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Notifying other MS nodes to run host scan task");
         }
-        Command[] cmds = new Command[] { new ScheduleHostScanTaskCommand() };
+        Command[] cmds = new Command[] {new ScheduleHostScanTaskCommand()};
         _clusterMgr.broadcast(0, _gson.toJson(cmds));
     }
 
     protected static void logT(byte[] bytes, final String msg) {
         s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
-                (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+            (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
     }
 
     protected static void logD(byte[] bytes, final String msg) {
         s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
-                (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+            (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
     }
 
     protected static void logI(byte[] bytes, final String msg) {
         s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
-                (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+            (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
     }
 
     public boolean routeToPeer(String peer, byte[] bytes) {
@@ -425,7 +425,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                 if (s_logger.isDebugEnabled()) {
                     logD(bytes, "Routing to peer");
                 }
-                Link.write(ch, new ByteBuffer[] { ByteBuffer.wrap(bytes) }, sslEngine);
+                Link.write(ch, new ByteBuffer[] {ByteBuffer.wrap(bytes)}, sslEngine);
                 return true;
             } catch (IOException e) {
                 try {
@@ -618,7 +618,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                         }
                         Request req = Request.parse(data);
                         Command[] cmds = req.getCommands();
-                        CancelCommand cancel = (CancelCommand) cmds[0];
+                        CancelCommand cancel = (CancelCommand)cmds[0];
                         if (s_logger.isDebugEnabled()) {
                             logD(data, "Cancel request received");
                         }
@@ -647,7 +647,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                             return;
                         } else {
                             if (agent instanceof Routable) {
-                                Routable cluster = (Routable) agent;
+                                Routable cluster = (Routable)agent;
                                 cluster.routeToAgent(data);
                             } else {
                                 agent.send(Request.parse(data));
@@ -664,7 +664,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                     if (mgmtId != -1 && mgmtId != _nodeId) {
                         routeToPeer(Long.toString(mgmtId), data);
                         if (Request.requiresSequentialExecution(data)) {
-                            AgentAttache attache = (AgentAttache) link.attachment();
+                            AgentAttache attache = (AgentAttache)link.attachment();
                             if (attache != null) {
                                 attache.sendNext(Request.getSequence(data));
                             } else if (s_logger.isDebugEnabled()) {
@@ -726,7 +726,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
 
     @Override
     public boolean executeRebalanceRequest(long agentId, long currentOwnerId, long futureOwnerId, Event event) throws AgentUnavailableException,
-            OperationTimedoutException {
+        OperationTimedoutException {
         boolean result = false;
         if (event == Event.RequestAgentRebalance) {
             return setToWaitForRebalance(agentId, currentOwnerId, futureOwnerId);
@@ -793,7 +793,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
         } else {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() +
-                        "; number of managed agents is " + allManagedAgents.size());
+                    "; number of managed agents is " + allManagedAgents.size());
             }
             return;
         }
@@ -947,7 +947,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                                 // no need to do anything with the real attache as we haven't modified it yet
                                 Date cutTime = DateUtil.currentGMTTime();
                                 HostTransferMapVO transferMap =
-                                        _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
+                                    _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
 
                                 if (transferMap == null) {
                                     s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host");
@@ -966,7 +966,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                                 ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner());
                                 if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
                                     s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms +
-                                            ", skipping rebalance for the host");
+                                        ", skipping rebalance for the host");
                                     iterator.remove();
                                     _hostTransferDao.completeAgentTransfer(hostId);
                                     continue;
@@ -983,7 +983,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
 
                                 } else {
                                     s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() +
-                                            " and listener queue size is " + attache.getNonRecurringListenersSize());
+                                        " and listener queue size is " + attache.getNonRecurringListenersSize());
                                 }
                             }
                         } else {
@@ -1050,7 +1050,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                 if (result) {
                     if (s_logger.isDebugEnabled()) {
                         s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                                " as a part of rebalance process");
+                            " as a part of rebalance process");
                     }
                     result = loadDirectlyConnectedHost(host, true);
                 } else {
@@ -1059,16 +1059,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
 
             } catch (Exception ex) {
                 s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                        " as a part of rebalance process due to:", ex);
+                    " as a part of rebalance process due to:", ex);
                 result = false;
             }
 
             if (result) {
                 s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                        " as a part of rebalance process");
+                    " as a part of rebalance process");
             } else {
                 s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                        " as a part of rebalance process");
+                    " as a part of rebalance process");
             }
         }
 
@@ -1089,7 +1089,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
             return;
         }
 
-        ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache) attache;
+        ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache)attache;
 
         if (success) {
 
@@ -1100,7 +1100,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
             Request requestToTransfer = forwardAttache.getRequestToTransfer();
             while (requestToTransfer != null) {
                 s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " +
-                        _nodeId + " to " + futureOwnerId);
+                    _nodeId + " to " + futureOwnerId);
                 boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes());
                 if (!routeResult) {
                     logD(requestToTransfer.getBytes(), "Failed to route request to peer");
@@ -1138,10 +1138,10 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
         }
 
         synchronized (_agents) {
-            ClusteredDirectAgentAttache attache = (ClusteredDirectAgentAttache) _agents.get(hostId);
+            ClusteredDirectAgentAttache attache = (ClusteredDirectAgentAttache)_agents.get(hostId);
             if (attache != null && attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
                 handleDisconnectWithoutInvestigation(attache, Event.StartAgentRebalance, true, true);
-                ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache) createAttache(hostId);
+                ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache)createAttache(hostId);
                 if (forwardAttache == null) {
                     s_logger.warn("Unable to create a forward attache for the host " + hostId + " as a part of rebalance process");
                     return false;
@@ -1154,7 +1154,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                     s_logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing");
                 } else {
                     s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " +
-                            attache.getNonRecurringListenersSize() + ", can't start host rebalancing");
+                        attache.getNonRecurringListenersSize() + ", can't start host rebalancing");
                 }
                 return false;
             }
@@ -1211,7 +1211,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
             // Scheduling host scan task in peer MS is a best effort operation during host add, regular host scan
             // happens at fixed intervals anyways. So handling any exceptions that may be thrown
             s_logger.warn("Exception happened while trying to schedule host scan task on mgmt server " + _clusterMgr.getSelfPeerName() +
-                    ", ignoring as regular host scan happens at fixed interval anyways", e);
+                ", ignoring as regular host scan happens at fixed interval anyways", e);
             return null;
         }
 
@@ -1250,7 +1250,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
             }
 
             if (cmds.length == 1 && cmds[0] instanceof ChangeAgentCommand) { // intercepted
-                ChangeAgentCommand cmd = (ChangeAgentCommand) cmds[0];
+                ChangeAgentCommand cmd = (ChangeAgentCommand)cmds[0];
 
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Intercepting command for agent change: agent " + cmd.getAgentId() + " event: " + cmd.getEvent());
@@ -1271,7 +1271,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                 answers[0] = new ChangeAgentAnswer(cmd, result);
                 return _gson.toJson(answers);
             } else if (cmds.length == 1 && cmds[0] instanceof TransferAgentCommand) {
-                TransferAgentCommand cmd = (TransferAgentCommand) cmds[0];
+                TransferAgentCommand cmd = (TransferAgentCommand)cmds[0];
 
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Intercepting command for agent rebalancing: agent " + cmd.getAgentId() + " event: " + cmd.getEvent());
@@ -1294,7 +1294,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                 answers[0] = new Answer(cmd, result, null);
                 return _gson.toJson(answers);
             } else if (cmds.length == 1 && cmds[0] instanceof PropagateResourceEventCommand) {
-                PropagateResourceEventCommand cmd = (PropagateResourceEventCommand) cmds[0];
+                PropagateResourceEventCommand cmd = (PropagateResourceEventCommand)cmds[0];
 
                 s_logger.debug("Intercepting command to propagate event " + cmd.getEvent().name() + " for host " + cmd.getHostId());
 
@@ -1311,7 +1311,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                 answers[0] = new Answer(cmd, result, null);
                 return _gson.toJson(answers);
             } else if (cmds.length == 1 && cmds[0] instanceof ScheduleHostScanTaskCommand) {
-                ScheduleHostScanTaskCommand cmd = (ScheduleHostScanTaskCommand) cmds[0];
+                ScheduleHostScanTaskCommand cmd = (ScheduleHostScanTaskCommand)cmds[0];
                 String response = handleScheduleHostScanTaskCommand(cmd);
                 return response;
             }
@@ -1328,14 +1328,14 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
 
                     if (s_logger.isDebugEnabled()) {
                         s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " +
-                                (System.currentTimeMillis() - startTick) + " ms, return result: " + jsonReturn);
+                            (System.currentTimeMillis() - startTick) + " ms, return result: " + jsonReturn);
                     }
 
                     return jsonReturn;
                 } else {
                     if (s_logger.isDebugEnabled()) {
                         s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " +
-                                (System.currentTimeMillis() - startTick) + " ms, return null result");
+                            (System.currentTimeMillis() - startTick) + " ms, return null result");
                     }
                 }
             } catch (AgentUnavailableException e) {
@@ -1386,12 +1386,12 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
                             double load = managedHostsCount / allHostsCount;
                             if (load >= ConnectedAgentThreshold.value()) {
                                 s_logger.debug("Scheduling agent rebalancing task as the average agent load " + load + " is more than the threshold " +
-                                        ConnectedAgentThreshold.value());
+                                    ConnectedAgentThreshold.value());
                                 scheduleRebalanceAgents();
                                 _agentLbHappened = true;
                             } else {
                                 s_logger.debug("Not scheduling agent rebalancing task as the averages load " + load + " is less than the threshold " +
-                                        ConnectedAgentThreshold.value());
+                                    ConnectedAgentThreshold.value());
                             }
                         }
                     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/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 a200aea..7201569 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -273,14 +273,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     @Inject
     ConfigDepot _configDepot;
 
-    protected List<HostAllocator> _hostAllocators;
+    protected List<HostAllocator> hostAllocators;
 
     public List<HostAllocator> getHostAllocators() {
-        return _hostAllocators;
+        return hostAllocators;
     }
 
-    public void setHostAllocators(List<HostAllocator> _hostAllocators) {
-        this._hostAllocators = _hostAllocators;
+    public void setHostAllocators(List<HostAllocator> hostAllocators) {
+        this.hostAllocators = hostAllocators;
     }
 
     protected List<StoragePoolAllocator> _storagePoolAllocators;
@@ -699,6 +699,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     @Override
     public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params)
         throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
+
         advanceStart(vmUuid, params, null);
     }
 
@@ -964,15 +965,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                                 s_logger.info("The guru did not like the answers so stopping " + vm);
                             }
 
-                            StopCommand cmd = new StopCommand(vm,  ExecuteInSequence.value());
-                            StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
-                            if ( answer != null ) {
+                            StopCommand cmd = new StopCommand(vm, ExecuteInSequence.value());
+                            StopAnswer answer = (StopAnswer)_agentMgr.easySend(destHostId, cmd);
+                            if (answer != null) {
                                 if (vm.getType() == VirtualMachine.Type.User) {
                                     String platform = answer.getPlatform();
                                     if (platform != null) {
                                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                                         _userVmDao.loadDetails(userVm);
-                                        userVm.setDetail("platform",  platform);
+                                        userVm.setDetail("platform", platform);
                                         _userVmDao.saveDetails(userVm);
                                     }
                                 }
@@ -1128,14 +1129,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         VirtualMachine vm = profile.getVirtualMachine();
         StopCommand stop = new StopCommand(vm, ExecuteInSequence.value());
         try {
-            StopAnswer answer = (StopAnswer) _agentMgr.send(vm.getHostId(), stop);
-            if ( answer != null ) {
+            StopAnswer answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
+            if (answer != null) {
                 if (vm.getType() == VirtualMachine.Type.User) {
                     String platform = answer.getPlatform();
                     if (platform != null) {
                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                         _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("platform",  platform);
+                        userVm.setDetail("platform", platform);
                         _userVmDao.saveDetails(userVm);
                     }
                 }
@@ -1368,13 +1369,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         StopAnswer answer = null;
         try {
             answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
-            if ( answer != null ) {
+            if (answer != null) {
                 if (vm.getType() == VirtualMachine.Type.User) {
                     String platform = answer.getPlatform();
-                    if ( platform != null) {
+                    if (platform != null) {
                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                         _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("platform",  platform);
+                        userVm.setDetail("platform", platform);
                         _userVmDao.saveDetails(userVm);
                     }
                 }
@@ -1515,7 +1516,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         return true;
     }
-    
+
     @Override
     public void storageMigration(String vmUuid, StoragePool destPool) {
         AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
@@ -2129,7 +2130,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
     @Override
     public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) {
         boolean isMachineUpgradable = true;
-        for (HostAllocator allocator : _hostAllocators) {
+        for (HostAllocator allocator : hostAllocators) {
             isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
             if (isMachineUpgradable)
                 continue;
@@ -2570,11 +2571,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
                 vm.getHostId() + "] stopped due to storage failure.");
         }
         // track platform info
-        if( info.platform != null && !info.platform.isEmpty() ) {
+        if (info.platform != null && !info.platform.isEmpty()) {
             if (vm.getType() == VirtualMachine.Type.User) {
                 UserVmVO userVm = _userVmDao.findById(vm.getId());
                 _userVmDao.loadDetails(userVm);
-                userVm.setDetail("platform",  info.platform);
+                userVm.setDetail("platform", info.platform);
                 _userVmDao.saveDetails(userVm);
             }
         }
@@ -2972,7 +2973,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
             this.vm = vm;
             hostUuid = host;
             this.platform = platform;
-            
+
         }
 
         public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
@@ -2986,7 +2987,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         public String getHostUuid() {
             return hostUuid;
         }
-        
+
         public String getPlatform() {
             return platform;
         }
@@ -3777,8 +3778,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
     @Override
     public ConfigKey<?>[] getConfigKeys() {
-        return new ConfigKey<?>[] {ClusterDeltaSyncInterval, StartRetry, VmDestroyForcestop, VmOpCancelInterval, VmOpCleanupInterval, VmOpCleanupWait, VmOpLockStateRetry,
-                VmOpWaitInterval, ExecuteInSequence, VmJobCheckInterval, VmJobTimeout, VmJobStateReportInterval};
+        return new ConfigKey<?>[] {ClusterDeltaSyncInterval, StartRetry, VmDestroyForcestop, VmOpCancelInterval, VmOpCleanupInterval, VmOpCleanupWait,
+            VmOpLockStateRetry,
+            VmOpWaitInterval, ExecuteInSequence, VmJobCheckInterval, VmJobTimeout, VmJobStateReportInterval};
     }
 
     public List<StoragePoolAllocator> getStoragePoolAllocators() {
@@ -3832,10 +3834,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
     private void handlePowerOnReportWithNoPendingJobsOnVM(VMInstanceVO vm) {
         //
-        // 	1) handle left-over transitional VM states
-        //	2) handle out of band VM live migration
-        //	3) handle out of sync stationary states, marking VM from Stopped to Running with
-        //	   alert messages
+        //  1) handle left-over transitional VM states
+        //  2) handle out of band VM live migration
+        //  3) handle out of sync stationary states, marking VM from Stopped to Running with
+        //     alert messages
         //
         switch (vm.getState()) {
             case Starting:
@@ -3897,8 +3899,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
     private void handlePowerOffReportWithNoPendingJobsOnVM(VMInstanceVO vm) {
 
-        // 	1) handle left-over transitional VM states
-        //	2) handle out of sync stationary states, schedule force-stop to release resources
+        //  1) handle left-over transitional VM states
+        //  2) handle out of sync stationary states, schedule force-stop to release resources
         //
         switch (vm.getState()) {
             case Starting:
@@ -3933,8 +3935,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         // VMs in expunging state (this need to be handled specially)
         //
         // checking condition
-        //	1) no pending VmWork job
-        //	2) on hostId host and host is UP
+        //  1) no pending VmWork job
+        //  2) on hostId host and host is UP
         //
         // When host is UP, soon or later we will get a report from the host about the VM,
         // however, if VM is missing from the host report (it may happen in out of band changes
@@ -4136,65 +4138,65 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         }
         return null;
     }
-    
+
     //
     // TODO build a common pattern to reduce code duplication in following methods
     // no time for this at current iteration
     //
     public Outcome<VirtualMachine> startVmThroughJobQueue(final String vmUuid,
-    	final Map<VirtualMachineProfile.Param, Object> params,
-    	final DeploymentPlan planToDeploy) {
-        
-    	final CallContext context = CallContext.current();
+        final Map<VirtualMachineProfile.Param, Object> params,
+        final DeploymentPlan planToDeploy) {
+
+        final CallContext context = CallContext.current();
         final User callingUser = context.getCallingUser();
         final Account callingAccount = context.getCallingAccount();
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-    	    	VmWorkJobVO workJob = null;
-    	    	
-    	        _vmDao.lockRow(vm.getId(), true);
-    	        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance,
-    	        	vm.getId(), VmWorkStart.class.getName());
-    	        
-    	        if (pendingWorkJobs.size() > 0) {
-    	            assert (pendingWorkJobs.size() == 1);
-    	            workJob = pendingWorkJobs.get(0);
-    	        } else {
-    	            workJob = new VmWorkJobVO(context.getContextId());
-
-    	            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-    	            workJob.setCmd(VmWorkStart.class.getName());
-
-    	            workJob.setAccountId(callingAccount.getId());
-    	            workJob.setUserId(callingUser.getId());
-    	            workJob.setStep(VmWorkJobVO.Step.Starting);
-    	            workJob.setVmType(vm.getType());
-    	            workJob.setVmInstanceId(vm.getId());
-
-    	            // save work context info (there are some duplications)
-    	            VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId());
-    	            workInfo.setPlan(planToDeploy);
-    	            workInfo.setParams(params);
-    	            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-
-    	            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-    	    	}
-    	        
-	            // Transaction syntax sugar has a cost here
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-    		}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+                VmWorkJobVO workJob = null;
+
+                _vmDao.lockRow(vm.getId(), true);
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance,
+                    vm.getId(), VmWorkStart.class.getName());
+
+                if (pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkStart.class.getName());
+
+                    workJob.setAccountId(callingAccount.getId());
+                    workJob.setUserId(callingUser.getId());
+                    workJob.setStep(VmWorkJobVO.Step.Starting);
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId());
+                    workInfo.setPlan(planToDeploy);
+                    workInfo.setParams(params);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+
+                // Transaction syntax sugar has a cost here
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
-        	VirtualMachine.PowerState.PowerOn, vm.getId(), null);
+            VirtualMachine.PowerState.PowerOn, vm.getId(), null);
     }
 
     public Outcome<VirtualMachine> stopVmThroughJobQueue(final String vmUuid, final boolean cleanup) {
@@ -4203,49 +4205,49 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         final User user = context.getCallingUser();
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
-    	
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-	        		VirtualMachine.Type.Instance, vm.getId(),
-	        		VmWorkStop.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkStop.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setStep(VmWorkJobVO.Step.Prepare);
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkStop workInfo = new VmWorkStop(user.getId(), account.getId(), vm.getId(), cleanup);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		    	}
-		        
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-    		}
-		});
-
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkStop.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkStop.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setStep(VmWorkJobVO.Step.Prepare);
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkStop workInfo = new VmWorkStop(user.getId(), account.getId(), vm.getId(), cleanup);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
-        	VirtualMachine.PowerState.PowerOff, vm.getId(), null);
+            VirtualMachine.PowerState.PowerOff, vm.getId(), null);
     }
 
     public Outcome<VirtualMachine> rebootVmThroughJobQueue(final String vmUuid,
@@ -4256,49 +4258,49 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         final User user = context.getCallingUser();
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
-    	
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-	        		VirtualMachine.Type.Instance, vm.getId(),
-	        		VmWorkReboot.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkReboot.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setStep(VmWorkJobVO.Step.Prepare);
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkReboot workInfo = new VmWorkReboot(user.getId(), account.getId(), vm.getId(), params);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		    	}
-		        
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-    		}
-		});
-
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkReboot.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkReboot.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setStep(VmWorkJobVO.Step.Prepare);
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkReboot workInfo = new VmWorkReboot(user.getId(), account.getId(), vm.getId(), params);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
-        	vm.getId());
+            vm.getId());
     }
 
     public Outcome<VirtualMachine> migrateVmThroughJobQueue(final String vmUuid, final long srcHostId, final DeployDestination dest) {
@@ -4308,48 +4310,48 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkMigrate.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkMigrate.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkMigrate workInfo = new VmWorkMigrate(user.getId(), account.getId(), vm.getId(), srcHostId, dest);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkMigrate.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkMigrate.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkMigrate workInfo = new VmWorkMigrate(user.getId(), account.getId(), vm.getId(), srcHostId, dest);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
-        	VirtualMachine.PowerState.PowerOn, vm.getId(), vm.getPowerHostId());
+            VirtualMachine.PowerState.PowerOn, vm.getId(), vm.getPowerHostId());
     }
 
     public Outcome<VirtualMachine> migrateVmWithStorageThroughJobQueue(
@@ -4362,51 +4364,51 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkMigrateWithStorage.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkMigrate.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkMigrateWithStorage workInfo = new VmWorkMigrateWithStorage(user.getId(), account.getId(), vm.getId(),
-		            	srcHostId, destHostId, volumeToPool);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkMigrateWithStorage.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkMigrate.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkMigrateWithStorage workInfo = new VmWorkMigrateWithStorage(user.getId(), account.getId(), vm.getId(),
+                        srcHostId, destHostId, volumeToPool);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmStateSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"),
-        	VirtualMachine.PowerState.PowerOn, vm.getId(), destHostId);
+            VirtualMachine.PowerState.PowerOn, vm.getId(), destHostId);
     }
-    
+
     public Outcome<VirtualMachine> migrateVmForScaleThroughJobQueue(
         final String vmUuid, final long srcHostId, final DeployDestination dest, final Long newSvcOfferingId) {
 
@@ -4416,47 +4418,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkMigrateForScale.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkMigrate.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkMigrateForScale workInfo = new VmWorkMigrateForScale(user.getId(), account.getId(), vm.getId(),
-		            	srcHostId, dest, newSvcOfferingId);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkMigrateForScale.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkMigrate.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkMigrateForScale workInfo = new VmWorkMigrateForScale(user.getId(), account.getId(), vm.getId(),
+                        srcHostId, dest, newSvcOfferingId);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
 
@@ -4469,47 +4471,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkStorageMigration.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkStorageMigration.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkStorageMigration workInfo = new VmWorkStorageMigration(user.getId(), account.getId(), vm.getId(),
-		            	destPool);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkStorageMigration.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkStorageMigration.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkStorageMigration workInfo = new VmWorkStorageMigration(user.getId(), account.getId(), vm.getId(),
+                        destPool);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
 
@@ -4520,47 +4522,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         final User user = context.getCallingUser();
         final Account account = context.getCallingAccount();
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkAddVmToNetwork.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(),
-		            	network, requested);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkAddVmToNetwork.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(), account.getId(), vm.getId(),
+                        network, requested);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
 
@@ -4571,47 +4573,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         final User user = context.getCallingUser();
         final Account account = context.getCallingAccount();
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkRemoveNicFromVm.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkRemoveNicFromVm.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(),
-		            	nic);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkRemoveNicFromVm.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkRemoveNicFromVm.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(), account.getId(), vm.getId(),
+                        nic);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
 
@@ -4622,47 +4624,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         final User user = context.getCallingUser();
         final Account account = context.getCallingAccount();
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkRemoveVmFromNetwork.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkRemoveVmFromNetwork.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkRemoveVmFromNetwork workInfo = new VmWorkRemoveVmFromNetwork(user.getId(), account.getId(), vm.getId(),
-		            	network, broadcastUri);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkRemoveVmFromNetwork.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkRemoveVmFromNetwork.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkRemoveVmFromNetwork workInfo = new VmWorkRemoveVmFromNetwork(user.getId(), account.getId(), vm.getId(),
+                        network, broadcastUri);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
 
@@ -4675,47 +4677,47 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
 
         final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
 
-    	Transaction.execute(new TransactionCallbackNoReturn () {
-    		@Override
+        Transaction.execute(new TransactionCallbackNoReturn() {
+            @Override
             public void doInTransactionWithoutResult(TransactionStatus status) {
-	
-		        _vmDao.lockRow(vm.getId(), true);
-		
-		        List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
-		        	VirtualMachine.Type.Instance, vm.getId(),
-		        	VmWorkReconfigure.class.getName());
-		
-		        VmWorkJobVO workJob = null;
-		        if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-		            assert (pendingWorkJobs.size() == 1);
-		            workJob = pendingWorkJobs.get(0);
-		        } else {
-		                    
-		            workJob = new VmWorkJobVO(context.getContextId());
-		
-		            workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
-		            workJob.setCmd(VmWorkReconfigure.class.getName());
-		
-		            workJob.setAccountId(account.getId());
-		            workJob.setUserId(user.getId());
-		            workJob.setVmType(vm.getType());
-		            workJob.setVmInstanceId(vm.getId());
-		
-		            // save work context info (there are some duplications)
-		            VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(),
-		            		oldServiceOffering, reconfiguringOnExistingHost);
-		            workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
-		
-		            _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
-		        }
-	            context.putContextParameter("workJob", workJob);
-	            context.putContextParameter("jobId", new Long(workJob.getId()));
-	    	}
-    	});
-    	
-    	final long jobId = (Long)context.getContextParameter("jobId");
-    	AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
-    	
+
+                _vmDao.lockRow(vm.getId(), true);
+
+                List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
+                    VirtualMachine.Type.Instance, vm.getId(),
+                    VmWorkReconfigure.class.getName());
+
+                VmWorkJobVO workJob = null;
+                if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
+                    assert (pendingWorkJobs.size() == 1);
+                    workJob = pendingWorkJobs.get(0);
+                } else {
+
+                    workJob = new VmWorkJobVO(context.getContextId());
+
+                    workJob.setDispatcher(VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER);
+                    workJob.setCmd(VmWorkReconfigure.class.getName());
+
+                    workJob.setAccountId(account.getId());
+                    workJob.setUserId(user.getId());
+                    workJob.setVmType(vm.getType());
+                    workJob.setVmInstanceId(vm.getId());
+
+                    // save work context info (there are some duplications)
+                    VmWorkReconfigure workInfo = new VmWorkReconfigure(user.getId(), account.getId(), vm.getId(),
+                        oldServiceOffering, reconfiguringOnExistingHost);
+                    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
+
+                    _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, vm.getId());
+                }
+                context.putContextParameter("workJob", workJob);
+                context.putContextParameter("jobId", new Long(workJob.getId()));
+            }
+        });
+
+        final long jobId = (Long)context.getContextParameter("jobId");
+        AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
+
         return new VmJobSyncOutcome((VmWorkJobVO)context.getContextParameter("workJob"), vm.getId());
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSync.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSync.java b/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSync.java
index dacc8d0..f84c7b7 100644
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSync.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachinePowerStateSync.java
@@ -5,7 +5,7 @@
 // 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,
@@ -21,11 +21,11 @@ import java.util.Map;
 import com.cloud.agent.api.HostVmStateReportEntry;
 
 public interface VirtualMachinePowerStateSync {
-	
-	void resetHostSyncState(long hostId);
-	
-	void processHostVmStateReport(long hostId, Map<String, HostVmStateReportEntry> report);
-	
-	// to adapt legacy ping report
-	void processHostVmStatePingReport(long hostId, Map<String, HostVmStateReportEntry> report);
+
+    void resetHostSyncState(long hostId);
+
+    void processHostVmStateReport(long hostId, Map<String, HostVmStateReportEntry> report);
+
+    // to adapt legacy ping report
+    void processHostVmStatePingReport(long hostId, Map<String, HostVmStateReportEntry> report);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be5e5cc6/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..97396f1 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
@@ -19,24 +19,24 @@ package com.cloud.vm;
 import com.cloud.network.Network;
 
 public class VmWorkAddVmToNetwork extends VmWork {
-	private static final long serialVersionUID = 8861516006586736813L;
+    private static final long serialVersionUID = 8861516006586736813L;
 
-	Network network;
-	NicProfile requstedNicProfile;
-	
-	public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, 
-		Network network, NicProfile requested) {
-		super(userId, accountId, vmId);
-	
-		this.network = network;
-		this.requstedNicProfile = requested;
-	}
-	
-	public Network getNetwork() {
-		return this.network;
-	}
-	
-	public NicProfile getRequestedNicProfile() {
-		return this.requstedNicProfile;
-	}
+    Network network;
+    NicProfile requstedNicProfile;
+
+    public VmWorkAddVmToNetwork(long userId, long accountId, long vmId,
+            Network network, NicProfile requested) {
+        super(userId, accountId, vmId);
+
+        this.network = network;
+        this.requstedNicProfile = requested;
+    }
+
+    public Network getNetwork() {
+        return this.network;
+    }
+
+    public NicProfile getRequestedNicProfile() {
+        return this.requstedNicProfile;
+    }
 }