Arik Hadas has uploaded a new change for review. Change subject: core: refactor failure to run vm flow - part 5 ......................................................................
core: refactor failure to run vm flow - part 5 This patch is a preliminary step before removing MigrateVmCommand#reportCompleted: - Move the call to freeLock to RunVmCommandBase#reportCompleted - Extract the code that actually ends the command's monitoring job/step to separate method. RunVmCommand & RunVmOnceCommand used to override RunVmCommandBase#reportCompleted just to change the way the job/step is ended, so they are now override the new method instead. Change-Id: Ib02c6a37333785845e6e8246b1a8f4c326e9049d Signed-off-by: Arik Hadas <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java 4 files changed, 29 insertions(+), 23 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/62/24162/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java index b863529..3442695 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java @@ -379,8 +379,6 @@ if (getDestinationVdsId() != null) { decreasePendingVms(getDestinationVdsId()); } - - freeLock(); } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java index 0053ba7..3da5c94 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java @@ -953,13 +953,13 @@ } @Override - public void reportCompleted() { + protected void endExecutionMonitoring() { if (getVm().isRunAndPause() && getVmDynamicDao().get(getVmId()).getStatus() == VMStatus.Paused) { final ExecutionContext executionContext = getExecutionContext(); executionContext.setShouldEndJob(true); ExecutionHandler.endJob(executionContext, true); } else { - super.reportCompleted(); + super.endExecutionMonitoring(); } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java index 8d10b59..3b9e0b5 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java @@ -232,18 +232,28 @@ @Override public void reportCompleted() { - ExecutionContext executionContext = getExecutionContext(); - if (executionContext != null && executionContext.isMonitored() - && !executionContext.isCompleted()) { - switch (executionContext.getExecutionMethod()) { - case AsJob: - ExecutionHandler.endJob(executionContext, false); - break; - case AsStep: - ExecutionHandler.endStep(executionContext, executionContext.getStep(), false); - break; - default: + try { + ExecutionContext executionContext = getExecutionContext(); + if (executionContext != null && executionContext.isMonitored() + && !executionContext.isCompleted()) { + endExecutionMonitoring(); } + } + finally { + freeLock(); + } + } + + protected void endExecutionMonitoring() { + ExecutionContext executionContext = getExecutionContext(); + switch (executionContext.getExecutionMethod()) { + case AsJob: + ExecutionHandler.endJob(executionContext, false); + break; + case AsStep: + ExecutionHandler.endStep(executionContext, executionContext.getStep(), false); + break; + default: } } @@ -294,14 +304,12 @@ decreasePendingVms(vdsId, vm.getNumOfCpus(), vm.getMinAllocatedMem(), vm.getName()); } - protected void decreasePendingVms(Guid vdsId, int numOfCpus, int minAllocatedMem, String vmName) { + private void decreasePendingVms(Guid vdsId, int numOfCpus, int minAllocatedMem, String vmName) { getVdsDynamicDao().updatePartialVdsDynamicCalc(vdsId, 0, -numOfCpus, -minAllocatedMem, 0, 0); getBlockingQueue(vdsId).offer(Boolean.TRUE); - if (log.isDebugEnabled()) { - log.debugFormat("Decreasing vds {0} pending vcpu count by {1} and vmem size by {2} (Vm: {3})", - vdsId, numOfCpus, minAllocatedMem, vmName); - } + log.debugFormat("Decreasing vds {0} pending vcpu count by {1} and vmem size by {2} (Vm: {3})", + vdsId, numOfCpus, minAllocatedMem, vmName); } protected VdsDynamicDAO getVdsDynamicDao() { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java index 0d3c32d..e1d2e6a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java @@ -86,13 +86,13 @@ } @Override - public void reportCompleted() { + protected void endExecutionMonitoring() { ExecutionContext executionContext = getExecutionContext(); executionContext.setShouldEndJob(true); - boolean success = + boolean runAndPausedSucceeded = Boolean.TRUE.equals(getParameters().getRunAndPause()) && getVmDynamicDao().get(getVmId()).getStatus() == VMStatus.Paused; - ExecutionHandler.endJob(executionContext, success); + ExecutionHandler.endJob(executionContext, runAndPausedSucceeded); } @Override -- To view, visit http://gerrit.ovirt.org/24162 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib02c6a37333785845e6e8246b1a8f4c326e9049d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
