Moti Asayag has uploaded a new change for review. Change subject: engine: Add ability for conditional steps execution ......................................................................
engine: Add ability for conditional steps execution In certain actions we'd like to skip few parts of the command. The patch supports marking certain steps to be skipped, based on a given criteria. Change-Id: I05b0b971da7012cff701d5ab2efa28bedd90deca Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java 1 file changed, 61 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/35032/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java index d3a76ac..f05cc0e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java @@ -6,6 +6,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -18,6 +19,7 @@ import javax.transaction.Transaction; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.Validate; import org.ovirt.engine.core.bll.aaa.SessionDataContainer; import org.ovirt.engine.core.bll.context.CommandContext; import org.ovirt.engine.core.bll.context.CompensationContext; @@ -89,10 +91,10 @@ import org.ovirt.engine.core.dao.GenericDao; import org.ovirt.engine.core.dao.StatusAwareDao; import org.ovirt.engine.core.dao.VdsSpmIdMapDAO; +import org.ovirt.engine.core.utils.CorrelationIdTracker; import org.ovirt.engine.core.utils.Deserializer; import org.ovirt.engine.core.utils.ReflectionUtils; import org.ovirt.engine.core.utils.SerializationFactory; -import org.ovirt.engine.core.utils.CorrelationIdTracker; import org.ovirt.engine.core.utils.lock.EngineLock; import org.ovirt.engine.core.utils.lock.LockManager; import org.ovirt.engine.core.utils.lock.LockManagerFactory; @@ -138,6 +140,7 @@ private Map<Guid, CommandBase<?>> childCommandsMap = new HashMap<>(); private Map<Guid, Pair<VdcActionType, VdcActionParametersBase>> childCommandInfoMap = new HashMap<>(); private CommandStatus commandStatus = CommandStatus.NOT_STARTED; + private Conditional conditionalExecution; public void addChildCommandInfo(Guid id, VdcActionType vdcActionType, VdcActionParametersBase parameters) { childCommandInfoMap.put(id, new Pair<>(vdcActionType, parameters)); @@ -745,9 +748,11 @@ try { Transaction transaction = TransactionSupport.suspend(); try { + markCommandStepsToSkip(); + returnValue = isUserAuthorizedToRunAction() && isBackwardsCompatible() && validateInputs() && acquireLock() - && canDoAction() + && (stepSkipped(StepEnum.VALIDATING) || canDoAction()) && internalValidateAndSetQuota(); if (!returnValue && getReturnValue().getCanDoActionMessages().size() > 0) { log.warn("CanDoAction of action '{}' failed. Reasons: {}", getActionType(), @@ -1166,7 +1171,11 @@ if (hasTaskHandlers()) { getCurrentTaskHandler().execute(); } else { - executeCommand(); + if (stepSkipped(StepEnum.EXECUTING)) { + setSucceeded(true); + } else { + executeCommand(); + } } functionReturnValue = getSucceeded(); exceptionOccurred = false; @@ -2305,4 +2314,53 @@ protected MacPoolManagerStrategy getMacPool() { return MacPoolPerDcSingleton.getInstance().poolForDataCenter(getStoragePoolId()); } + + protected final Conditional skip(StepEnum... step) { + if (conditionalExecution == null) { + conditionalExecution = new Conditional(step); + } + + return conditionalExecution; + } + + protected void markCommandStepsToSkip() { + } + + protected final boolean stepSkipped(StepEnum step) { + if (conditionalExecution == null) { + return false; + } + + return conditionalExecution.skippedSteps.contains(step); + } + + protected static class Conditional { + private Set<StepEnum> skippedSteps = new HashSet<>(); + private StepEnum[] examinedSteps; + + public Conditional(StepEnum... step) { + setExaminedSteps(step); + } + + public Conditional skip(StepEnum... step) { + setExaminedSteps(step); + return this; + } + + public Conditional when(boolean condition) { + if (condition) { + for (StepEnum s : examinedSteps) { + skippedSteps.add(s); + } + } + + examinedSteps = null; + return this; + } + + private void setExaminedSteps(StepEnum[] steps) { + Validate.notEmpty(steps); + examinedSteps = steps; + } + } } -- To view, visit http://gerrit.ovirt.org/35032 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I05b0b971da7012cff701d5ab2efa28bedd90deca Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
