Arik Hadas has uploaded a new change for review. Change subject: core: refactor failure to run vm flow - part 1 ......................................................................
core: refactor failure to run vm flow - part 1 In most of the case when we fail to run VM we want to have proper audit message for it to be logged. That's why on almost every call to RunVmCommandBase#failedToRunVm method we log an audit message right before or after the call. One exception though is on the execution phase of RunVm - if the VM fails to run we do not need to log it, because it would be logged automatically by the infrastructure when the execution phase ends. This patch moves the call to log audit message to be within the failedToRunVm method. As for the case where the failedToRunVm method is called within the execution phase of RunVm, we'll also log it inside the failedToRunVm method, but set commandShouldBeLogged to false so the infrastructure will not log it again. This patch contains two additional minor refactoring changes. Change-Id: I74bd39fd5a4dc95694e9a059c40f7797b5e97623 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 3 files changed, 15 insertions(+), 16 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/16/28116/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 b2bf701..863d959 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 @@ -97,7 +97,6 @@ determineMigrationFailureForAuditLog(); _isRerun = false; setSucceeded(false); - log(); failedToRunVm(); } finally { 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 498f2a2..d04ed91 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 @@ -252,9 +252,10 @@ } else { - failedToRunVm(); + setCommandShouldBeLogged(false); setSucceeded(false); _isRerun = false; + failedToRunVm(); } } 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 c34ba90..da57403 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 @@ -94,6 +94,10 @@ _isRerun = true; log(); + // set _isRerun flag to false so that we'll be able to know if + // there is another rerun attempt within the method + _isRerun = false; + /** * Rerun VM only if not exceeded maximum rerun attempts. for example if there are 10 hosts that can run VM and * predefine maximum 3 attempts to rerun VM - on 4th turn vm will stop to run despite there are still available @@ -110,16 +114,12 @@ JobRepositoryFactory.getJobRepository().closeCompletedJobSteps(job.getId(), JobExecutionStatus.FAILED); } } - // set the _isRerun flag to false before calling executeAction so that we'll know if - // there is another rerun attempt within the method - _isRerun = false; insertAsyncTaskPlaceHolders(); executeAction(); // if there was no rerun attempt in the previous executeAction call and the command // wasn't done because canDoAction check returned false.. if (!_isRerun && !getReturnValue().getCanDoAction()) { - log(); failedToRunVm(); } @@ -128,25 +128,24 @@ } else { Backend.getInstance().getResourceManager().RemoveAsyncRunningCommand(getVmId()); failedToRunVm(); - _isRerun = false; - log(); } } protected void failedToRunVm() { - ThreadPoolUtil.execute(new Runnable() { - @Override - public void run() { - processVmPoolOnStopVm(); - } - }); + log(); + processVmPoolOnStopVm(); ExecutionHandler.setAsyncJob(getExecutionContext(), false); ExecutionHandler.endJob(getExecutionContext(), false); } private void processVmPoolOnStopVm() { - VmPoolHandler.processVmPoolOnStopVm(getVm().getId(), - ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); + ThreadPoolUtil.execute(new Runnable() { + @Override + public void run() { + VmPoolHandler.processVmPoolOnStopVm(getVm().getId(), + ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); + } + }); } /** -- To view, visit http://gerrit.ovirt.org/28116 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I74bd39fd5a4dc95694e9a059c40f7797b5e97623 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
