Ravi Nori has uploaded a new change for review. Change subject: engine : Call doPolling on parent commands when children have converged ......................................................................
engine : Call doPolling on parent commands when children have converged In complex hierarchy of parent and child commands call doPolling on parent commands only after child commands have converged. Change-Id: Id85b6abd962a7b2e145177ea0fbdf37e8261b553 Signed-off-by: Ravi Nori <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoFuture.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java 3 files changed, 69 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/38356/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java index e991504..4d7e9cb 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java @@ -5,8 +5,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.Future; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.tasks.CoCoFuture; import org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil; import org.ovirt.engine.core.bll.tasks.interfaces.CommandCallBack; import org.ovirt.engine.core.common.action.DestroyImageParameters; @@ -158,7 +160,8 @@ persistCommand(getParameters().getParentCommand(), true); if (nextCommand != null) { - CommandCoordinatorUtil.executeAsyncCommand(nextCommand.getFirst(), nextCommand.getSecond(), cloneContextAndDetachFromParent()); + Future<VdcReturnValueBase> future = CommandCoordinatorUtil.executeAsyncCommand(nextCommand.getFirst(), nextCommand.getSecond(), cloneContextAndDetachFromParent()); + getParameters().getChildCommands().put(getParameters().getCommandStep(), ((CoCoFuture) future).getCmdId()); } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoFuture.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoFuture.java new file mode 100644 index 0000000..1f78e35 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoFuture.java @@ -0,0 +1,49 @@ +package org.ovirt.engine.core.bll.tasks; + +import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.compat.Guid; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CoCoFuture implements Future<VdcReturnValueBase> { + + Future<VdcReturnValueBase> future; + private Guid cmdId; + + public CoCoFuture(Future<VdcReturnValueBase> future, Guid cmdId) { + this.future = future; + this.cmdId = cmdId; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return future.cancel(mayInterruptIfRunning); + } + + @Override + public boolean isCancelled() { + return future.isCancelled(); + } + + @Override + public boolean isDone() { + return future.isDone(); + } + + @Override + public VdcReturnValueBase get() throws InterruptedException, ExecutionException { + return future.get(); + } + + @Override + public VdcReturnValueBase get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return future.get(timeout, unit); + } + + public Guid getCmdId() { + return cmdId; + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java index 6e6239e..310ed75 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CommandExecutor.java @@ -1,6 +1,7 @@ package org.ovirt.engine.core.bll.tasks; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.Callable; @@ -70,8 +71,9 @@ callBack.onSucceeded(cmdId, coco.getChildCommandIds(cmdId)); break; case ACTIVE: - if (coco.getCommandEntity(cmdId).isExecuted()) { - callBack.doPolling(cmdId, coco.getChildCommandIds(cmdId)); + List<Guid> childIds = coco.getChildCommandIds(cmdId); + if (coco.getCommandEntity(cmdId).isExecuted() && childCommandsConverged(childIds)) { + callBack.doPolling(cmdId, childIds); } break; default: @@ -87,6 +89,17 @@ } } } + } + + private boolean childCommandsConverged(List<Guid> childIds) { + boolean converged = true; + for (Guid childId : childIds) { + if (coco.getCommandStatus(childId) == CommandStatus.ACTIVE) { + converged = false; + break; + } + } + return converged; } private void handleError(Exception ex, CommandStatus status, Guid cmdId) { @@ -163,7 +176,7 @@ command.getCommandId()); retVal = new RejectedExecutionFuture(); } - return retVal; + return new CoCoFuture(retVal, command.getCommandId()); } private VdcReturnValueBase executeCommand(final CommandBase<?> command, final CommandContext cmdContext) { -- To view, visit https://gerrit.ovirt.org/38356 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id85b6abd962a7b2e145177ea0fbdf37e8261b553 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
