diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 08e89684ef3..c239b937a2e 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -777,8 +777,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateStart(vmUuid, params, planToDeploy, planner); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = startVmThroughJobQueue(vmUuid, params, planToDeploy, planner); @@ -1354,8 +1355,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateStop(vmUuid, cleanUpEvenIfUnableToStop); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { @@ -1453,7 +1455,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to transition the state but we're moving on because it's forced stop"); } - if (state == State.Starting || state == State.Migrating) { + if ((state == State.Starting) || (state == State.Migrating) || (state == State.Stopping)) { if (work != null) { doCleanup = true; } else { @@ -1462,8 +1464,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } throw new CloudRuntimeException("Work item not found, We cannot stop " + vm + " when it is in state " + vm.getState()); } - } else if (state == State.Stopping) { - doCleanup = true; } if (doCleanup) { @@ -1683,8 +1683,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateStorageMigration(vmUuid, destPool); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = migrateVmStorageThroughJobQueue(vmUuid, destPool); @@ -1777,8 +1778,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateMigrate(vmUuid, srcHostId, dest); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = migrateVmThroughJobQueue(vmUuid, srcHostId, dest); @@ -2082,8 +2084,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateMigrateWithStorage(vmUuid, srcHostId, destHostId, volumeToPool); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { @@ -2428,8 +2431,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateReboot(vmUuid, params); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = rebootVmThroughJobQueue(vmUuid, params); @@ -3292,12 +3296,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public String hostUuid; public VMInstanceVO vm; - @SuppressWarnings("unchecked") public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) { this.name = name; this.state = state; this.vm = vm; - hostUuid = host; + this.hostUuid = host; } public AgentVmInfo(String name, VMInstanceVO vm, State state) { @@ -3402,8 +3405,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { return orchestrateAddVmToNetwork(vm, network, requested); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = addVmToNetworkThroughJobQueue(vm, network, requested); @@ -3413,7 +3417,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (InterruptedException e) { throw new RuntimeException("Operation is interrupted", e); } catch (java.util.concurrent.ExecutionException e) { - throw new RuntimeException("Execution excetion", e); + throw new RuntimeException("Execution exception", e); } Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob()); @@ -3516,8 +3520,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { return orchestrateRemoveNicFromVm(vm, nic); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { @@ -3768,8 +3773,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateMigrateForScale(vmUuid, srcHostId, dest, oldSvcOfferingId); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = migrateVmForScaleThroughJobQueue(vmUuid, srcHostId, dest, oldSvcOfferingId); @@ -4031,8 +4037,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { return orchestrateReConfigureVm(vmUuid, oldServiceOffering, reconfiguringOnExistingHost); } finally { - if (VmJobEnabled.value()) + if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); + } } } else { Outcome outcome = reconfigureVmThroughJobQueue(vmUuid, oldServiceOffering, reconfiguringOnExistingHost); @@ -4084,7 +4091,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac work.setStep(Step.Prepare); work.setResourceType(ItWorkVO.ResourceType.Host); work.setResourceId(vm.getHostId()); - work = _workDao.persist(work); + _workDao.persist(work); boolean success = false; try { if (reconfiguringOnExistingHost) { @@ -4106,8 +4113,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (AgentUnavailableException e) { throw e; } finally { - // work.setStep(Step.Done); - //_workDao.update(work.getId(), work); if (!success) { _capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId()); // release the new capacity vm.setServiceOfferingId(oldServiceOffering.getId());