Liron Ar has uploaded a new change for review. Change subject: core: distinguish between spm commands failures ......................................................................
core: distinguish between spm commands failures The engine can distinguish between a failed execution of spm command that was sent to vdsm and a failed spm command that wasn't executed because of a failure to get an spm. With this knowledge, the engine can handle the error better. An example usage is introduced with this change - When activating a domain whose status is maintenance and failing, in case that the command was actually executed it can't move back to maintenance status as it might already be activated in vdsm. If the activate verb was actually executed, the domain can move back to maintenance safely. Change-Id: I043fbaba00d96d93f8af502881043c72d1814343 Signed-off-by: Liron Aravot <lara...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsHandler.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ActivateStorageDomainCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBLLException.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSReturnValue.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VDSCommandBase.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java 6 files changed, 94 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/22347/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsHandler.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsHandler.java index fc6a249..8818c2c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsHandler.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsHandler.java @@ -114,9 +114,10 @@ */ public static VDSReturnValue handleVdsResult(VDSReturnValue result) { if (StringUtils.isNotEmpty(result.getExceptionString())) { - throw new VdcBLLException( - result.getVdsError() != null ? result.getVdsError().getCode() : VdcBllErrors.ENGINE, - result.getExceptionString()); + if (result.getVdsError() == null) { + result.getVdsError().setCode(VdcBllErrors.ENGINE); + } + throw new VdcBLLException(result); } return result; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ActivateStorageDomainCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ActivateStorageDomainCommand.java index 693c40e..7fb80ef 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ActivateStorageDomainCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ActivateStorageDomainCommand.java @@ -22,8 +22,9 @@ import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap; import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId; import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; -import org.ovirt.engine.core.common.locks.LockingGroup; +import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.common.vdscommands.ActivateStorageDomainVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; @@ -70,13 +71,32 @@ .getStoragePoolIsoMapDao() .get(new StoragePoolIsoMapId(getParameters().getStorageDomainId(), getParameters().getStoragePoolId())); + StorageDomainStatus previousStorageDomainStatus = map.getStatus(); + if (previousStorageDomainStatus == StorageDomainStatus.Maintenance) { + map.setStatus(StorageDomainStatus.Unknown); + } changeStorageDomainStatusInTransaction(map, StorageDomainStatus.Locked); freeLock(); log.infoFormat("ActivateStorage Domain. Before Connect all hosts to pool. Time:{0}", new Date()); connectAllHostsToPool(); - runVdsCommand(VDSCommandType.ActivateStorageDomain, - new ActivateStorageDomainVDSCommandParameters(getStoragePool().getId(), getStorageDomain().getId())); + try { + runVdsCommand(VDSCommandType.ActivateStorageDomain, + new ActivateStorageDomainVDSCommandParameters(getStoragePool().getId(), getStorageDomain().getId())); + } catch (VdcBLLException e) { + if (!e.getVdsReturnValue().getCommandExecutionState().isExecuted() + && previousStorageDomainStatus == StorageDomainStatus.Maintenance) { + executeInNewTransaction(new TransactionMethod<Void>() { + public Void runInTransaction() { + getCompensationContext().resetCompensation(); + getStoragePoolIsoMapDAO().updateStatus(map.getId(), StorageDomainStatus.Maintenance); + return null; + } + }); + } + + throw e; + } log.infoFormat("ActivateStorage Domain. After Connect all hosts to pool. Time:{0}", new Date()); refreshAllVdssInPool(); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBLLException.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBLLException.java index 6d38af7..466cbdd 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBLLException.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBLLException.java @@ -1,8 +1,11 @@ package org.ovirt.engine.core.common.errors; +import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; + public class VdcBLLException extends RuntimeException { private static final long serialVersionUID = 9070362191178977106L; + private VDSReturnValue vdsReturnValue; public VdcBLLException(VdcBllErrors errCode, RuntimeException baseException) { super("VdcBLLException:", baseException); @@ -18,6 +21,14 @@ setVdsError(tempVar); } + public VdcBLLException(VDSReturnValue returnValue) { + super("VdcBLLException: " + returnValue.getExceptionString()); + VDSError tempVar = new VDSError(); + tempVar.setCode(returnValue.getVdsError().getCode()); + setVdsError(tempVar); + setVdsReturnValue(returnValue); + } + public VdcBLLException(VdcBllErrors errCode) { super("VdcBLLException: " + errCode.toString()); VDSError tempVar = new VDSError(); @@ -25,6 +36,14 @@ setVdsError(tempVar); } + public VDSReturnValue getVdsReturnValue() { + return vdsReturnValue; + } + + public void setVdsReturnValue(VDSReturnValue vdsReturnValue) { + this.vdsReturnValue = vdsReturnValue; + } + private VDSError privateVdsError; public VDSError getVdsError() { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSReturnValue.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSReturnValue.java index 06c45b9..3bd3952 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSReturnValue.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSReturnValue.java @@ -11,8 +11,11 @@ private RuntimeException exceptionObject; private AsyncTaskCreationInfo creationInfo; private VDSError vdsError; + boolean wasCommandExecuted; + private ExecutionState commandExecutionState; public VDSReturnValue() { + commandExecutionState = ExecutionState.COMMAND_EXECUTION; } public Object getReturnValue() { @@ -62,4 +65,38 @@ public void setVdsError(VDSError value) { vdsError = value; } + + public boolean isWasCommandExecuted() { + return wasCommandExecuted; + } + + public void setWasCommandExecuted(boolean wasCommandExecuted) { + this.wasCommandExecuted = wasCommandExecuted; + } + + public ExecutionState getCommandExecutionState() { + return commandExecutionState; + } + + public void setCommandExecutionState(ExecutionState commandExecutionState) { + this.commandExecutionState = commandExecutionState; + } + + public enum ExecutionState { + COMMAND_EXECUTION(true), SPM_COMMAND_BEFORE_GETTING_SPM(false), SPM_COMMAND_EXECUTION(true); + + boolean isExecuted; + + private ExecutionState (boolean isExecuted) { + this.isExecuted = isExecuted; + } + + public boolean isExecuted() { + return isExecuted; + } + + public void setExecuted(boolean executed) { + isExecuted = executed; + } + } } diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VDSCommandBase.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VDSCommandBase.java index afffcbe..fbc9eb1 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VDSCommandBase.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VDSCommandBase.java @@ -50,9 +50,13 @@ protected void executeCommand() { try { // creating ReturnValue object since execute can be called more than once (failover) - // and we want returnValue clean from last run. - _returnValue = new VDSReturnValue(); - getVDSReturnValue().setSucceeded(true); + // and we want returnValue clean from last run except the CommandExecutionPhase. + VDSReturnValue newReturnValue = new VDSReturnValue(); + newReturnValue.setSucceeded(true); + if (_returnValue != null && _returnValue.getCommandExecutionState() != VDSReturnValue.ExecutionState.COMMAND_EXECUTION) { + getVDSReturnValue().setCommandExecutionState(_returnValue.getCommandExecutionState()); + } + _returnValue = newReturnValue; executeVDSCommand(); } catch (RuntimeException ex) { setVdsRuntimeError(ex); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java index 7bc4b95..28afd53 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java @@ -1497,9 +1497,13 @@ @Override protected void executeVDSCommand() { boolean isStartReconstruct = false; + if (getVDSReturnValue().getCommandExecutionState() == VDSReturnValue.ExecutionState.COMMAND_EXECUTION) { + getVDSReturnValue().setCommandExecutionState(VDSReturnValue.ExecutionState.SPM_COMMAND_BEFORE_GETTING_SPM); + } synchronized (getCurrentIrsProxyData().syncObj) { try { if (getIrsProxy() != null) { + getVDSReturnValue().setCommandExecutionState(VDSReturnValue.ExecutionState.SPM_COMMAND_EXECUTION); executeIrsBrokerCommand(); } else { if (getVDSReturnValue().getVdsError() == null) { -- To view, visit http://gerrit.ovirt.org/22347 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I043fbaba00d96d93f8af502881043c72d1814343 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liron Ar <lara...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches