Omer Frenkel has uploaded a new change for review. Change subject: core: Allow skipping vm command execution ......................................................................
core: Allow skipping vm command execution This patch adds an easy way to skip vm command execution, by overriding 'shouldSkipCommandExecution' method, we can mark the command not to run can-do-action and execute code. the command will just finish as succeeded and operation will be logged. in change-id: I75925d528cca52603660d5a7ec6c5c871304f3d0 there is an example of usage for the 'stop down vm' scenario. Change-Id: I290055f759afcc554d1f49fac12455ae18d2d194 Signed-off-by: Omer Frenkel <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java 1 file changed, 26 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/10/35610/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java index 36368fc..c6044fa 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java @@ -59,6 +59,7 @@ protected final static int MAX_NETWORK_INTERFACES_SUPPORTED = 8; protected final OsRepository osRepository = SimpleDependecyInjector.getInstance().get(OsRepository.class); + private Boolean skipCommandExecution; public VmCommand(T parameters, CommandContext cmdContext) { super(parameters, cmdContext); @@ -96,6 +97,10 @@ @Override protected void executeCommand() { + if (shouldSkipCommandExecutionCached()) { + setSucceeded(true); + return; + } executeVmCommand(); } @@ -561,4 +566,25 @@ return new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksList)); } + + /** + * use this method to get the result of shouldSkipCommandExecution + * as it is also allow to cache the result for multiple calls + */ + protected final boolean shouldSkipCommandExecutionCached() { + if (skipCommandExecution == null) { + skipCommandExecution = shouldSkipCommandExecution(); + } + return skipCommandExecution; + } + + /** + * check for special conditions that will cause the command to skip its canDoAction and execution + * this method should be overridden with specific logic for each command + * using the result should be done with shouldSkipCommandExecutionCached method that cache the result in the command + * @return true if the command should not execute any logic and should not return errors to the user + */ + protected boolean shouldSkipCommandExecution() { + return false; + } } -- To view, visit http://gerrit.ovirt.org/35610 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I290055f759afcc554d1f49fac12455ae18d2d194 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Omer Frenkel <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
