Search in sources :

Example 1 with FenceOperationResult

use of org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult in project ovirt-engine by oVirt.

the class RestartVdsCommand method wasSkippedDueToPolicy.

/**
 * Determines according to the return status from the Ovirt command whether the fence-operation has been skipped due
 * to policy.
 */
protected boolean wasSkippedDueToPolicy(ActionReturnValue result) {
    boolean skipped = false;
    if (result.getActionReturnValue() instanceof FenceOperationResult) {
        FenceOperationResult fenceResult = result.getActionReturnValue();
        skipped = fenceResult.getStatus() == Status.SKIPPED_DUE_TO_POLICY;
    }
    return skipped;
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Example 2 with FenceOperationResult

use of org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult in project ovirt-engine by oVirt.

the class SingleAgentFenceActionExecutor method changeStatus.

/**
 * Executes start or stop fence operation using specified agent
 */
protected FenceOperationResult changeStatus(FenceActionType fenceAction) {
    FenceAgentExecutor agentExecutor = createAgentExecutor();
    FenceOperationResult statusResult = null;
    // start at -1 because 1st fence attempt is regular and not a retry
    int fenceRetries = -1;
    do {
        FenceOperationResult result = agentExecutor.fence(fenceAction, fenceAgent);
        if (result.getStatus() == Status.SKIPPED_ALREADY_IN_STATUS) {
            // action skipped already in status, so report it as success with correct power status
            return new FenceOperationResult(Status.SUCCESS, fenceAction == FenceActionType.START ? PowerStatus.ON : PowerStatus.OFF);
        } else if (result.getStatus() == Status.SKIPPED_DUE_TO_POLICY) {
            // skipped due to policy is handled in caller
            return result;
        }
        if (result.getStatus() == Status.SUCCESS) {
            // fence operation was successful, verify if host power status changed
            statusResult = waitForStatus(fenceAction);
            if (isRequestedStatusAchieved(statusResult)) {
                // requested host power status reached, end with success
                return statusResult;
            }
        }
        fenceRetries++;
    } while (fenceRetries < allowedFenceActionRetries);
    return new FenceOperationResult(Status.ERROR, // fail safe, at least one fence attempt should always be executed, so statusResult shouldn't be null
    statusResult == null ? PowerStatus.UNKNOWN : statusResult.getPowerStatus(), "Allowed retries to verify host power status exceeded");
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Example 3 with FenceOperationResult

use of org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult in project ovirt-engine by oVirt.

the class BackendHostResourceTest method testFenceStatus.

@Test
public void testFenceStatus() throws Exception {
    FenceOperationResult retVal = new FenceOperationResult(FenceOperationResult.Status.SUCCESS, PowerStatus.ON);
    setUpEntityQueryExpectations(QueryType.GetVdsFenceStatus, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, retVal);
    Action action = new Action();
    action.setFenceType(FenceType.STATUS.value());
    verifyActionResponse(resource.fence(action));
    PowerManagementStatus status = action.getPowerManagement().getStatus();
    assertEquals(PowerManagementStatus.ON, status);
}
Also used : Action(org.ovirt.engine.api.model.Action) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) PowerManagementStatus(org.ovirt.engine.api.model.PowerManagementStatus) Test(org.junit.Test)

Example 4 with FenceOperationResult

use of org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult in project ovirt-engine by oVirt.

the class FenceAgentModel method test.

/**
 * Execute the fence agent test.
 */
public void test() {
    validatePmModels();
    if (!isValid()) {
        return;
    }
    setMessage(ConstantsManager.getInstance().getConstants().testingInProgressItWillTakeFewSecondsPleaseWaitMsg());
    getTestCommand().setIsExecutionAllowed(false);
    Cluster cluster = getHost().getCluster().getSelectedItem();
    GetFenceAgentStatusParameters param = new GetFenceAgentStatusParameters();
    FenceAgent agent = new FenceAgent();
    if (getHost().getHostId() != null) {
        param.setVdsId(getHost().getHostId());
    }
    agent.setOrder(getOrder().getEntity());
    agent.setIp(getManagementIp().getEntity());
    agent.setType(getPmType().getSelectedItem());
    agent.setUser(getPmUserName().getEntity());
    agent.setPassword(getPmPassword().getEntity());
    agent.setPort(getPmPort().getEntity());
    agent.setOptionsMap(getPmOptionsMap());
    param.setAgent(agent);
    param.setStoragePoolId(cluster.getStoragePoolId() != null ? cluster.getStoragePoolId() : Guid.Empty);
    param.setFenceProxySources(FenceProxySourceTypeHelper.parseFromString(getHost().getPmProxyPreferences()));
    param.setVdsName(getHost().getName().getEntity());
    param.setHostName(getHost().getHost().getEntity());
    param.setClusterId(cluster.getId());
    Frontend.getInstance().runQuery(QueryType.GetFenceAgentStatus, param, new AsyncQuery<QueryReturnValue>(returnValue -> {
        String msg;
        if (returnValue == null) {
            msg = ConstantsManager.getInstance().getConstants().testFailedUnknownErrorMsg();
        } else {
            FenceOperationResult result = returnValue.getReturnValue();
            if (result.getStatus() == FenceOperationResult.Status.SUCCESS) {
                msg = ConstantsManager.getInstance().getMessages().testSuccessfulWithPowerStatus(result.getPowerStatus() == PowerStatus.ON ? ConstantsManager.getInstance().getConstants().powerOn() : ConstantsManager.getInstance().getConstants().powerOff());
            } else {
                msg = ConstantsManager.getInstance().getMessages().testFailedWithErrorMsg(result.getMessage());
            }
        }
        setMessage(msg);
        getTestCommand().setIsExecutionAllowed(true);
    }, true));
}
Also used : NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) QueryType(org.ovirt.engine.core.common.queries.QueryType) PowerStatus(org.ovirt.engine.core.common.businessentities.pm.PowerStatus) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) GetFenceAgentStatusParameters(org.ovirt.engine.core.common.queries.GetFenceAgentStatusParameters) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Frontend(org.ovirt.engine.ui.frontend.Frontend) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) ICommandTarget(org.ovirt.engine.ui.uicommonweb.ICommandTarget) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) IntegerValidation(org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) StringHelper(org.ovirt.engine.core.compat.StringHelper) Objects(java.util.Objects) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) FenceProxySourceTypeHelper(org.ovirt.engine.core.common.utils.pm.FenceProxySourceTypeHelper) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) FenceAgent(org.ovirt.engine.core.common.businessentities.pm.FenceAgent) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) Comparator(java.util.Comparator) HostAddressValidation(org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) FenceAgent(org.ovirt.engine.core.common.businessentities.pm.FenceAgent) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) GetFenceAgentStatusParameters(org.ovirt.engine.core.common.queries.GetFenceAgentStatusParameters)

Example 5 with FenceOperationResult

use of org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult in project ovirt-engine by oVirt.

the class FenceVdsVDSCommand method getReturnStatus.

@Override
protected Status getReturnStatus() {
    Status status = new Status();
    FenceOperationResult result = (FenceOperationResult) getReturnValue();
    if (result == null) {
        // unexpected error happened
        status.code = 1;
        status.message = "";
    } else {
        // status result from action result
        status.code = result.getStatus() == FenceOperationResult.Status.ERROR ? 1 : 0;
        status.message = result.getMessage();
    }
    return status;
}
Also used : PowerStatus(org.ovirt.engine.core.common.businessentities.pm.PowerStatus) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Aggregations

FenceOperationResult (org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)58 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)2 Action (org.ovirt.engine.api.model.Action)2 FenceAgent (org.ovirt.engine.core.common.businessentities.pm.FenceAgent)2 PowerStatus (org.ovirt.engine.core.common.businessentities.pm.PowerStatus)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Response (javax.ws.rs.core.Response)1 PowerManagement (org.ovirt.engine.api.model.PowerManagement)1 PowerManagementStatus (org.ovirt.engine.api.model.PowerManagementStatus)1 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)1 HostFenceActionExecutor (org.ovirt.engine.core.bll.pm.HostFenceActionExecutor)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1