Search in sources :

Example 31 with FenceOperationResult

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

the class BackendHostResourceTest method testFenceStatusFailure.

@Test
public void testFenceStatusFailure() throws Exception {
    FenceOperationResult retVal = new FenceOperationResult(FenceOperationResult.Status.ERROR, PowerStatus.UNKNOWN, "some_error");
    setUpEntityQueryExpectations(QueryType.GetVdsFenceStatus, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, retVal);
    Action action = new Action();
    action.setFenceType(FenceType.STATUS.value());
    Response response = resource.fence(action);
    Action actionReturned = (Action) response.getEntity();
    assertEquals(actionReturned.getStatus(), CreationStatus.FAILED.value());
    assertNotNull(actionReturned.getFault());
    assertEquals("some_error", actionReturned.getFault().getReason());
}
Also used : Response(javax.ws.rs.core.Response) Action(org.ovirt.engine.api.model.Action) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) Test(org.junit.Test)

Example 32 with FenceOperationResult

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

the class SingleAgentFenceActionExecutor method waitForStatus.

/**
 * Executes status operation until requested host power status is reached or allowed number of retries exceeded
 * to determine of start/stop fence operation was successful
 */
protected FenceOperationResult waitForStatus(FenceActionType fenceAction) {
    FenceOperationResult statusResult = null;
    // start at -1, because the 1st iteration is regular and not a retry
    int statusRetries = -1;
    int unknownStatusReceived = 0;
    log.info("Waiting for host '{}' to reach status '{}'", fencedHost.getHostName(), requestedPowerStatus);
    // Waiting before first attempt to check the host status.
    // This is done because if we will attempt to get host status immediately
    // in most cases it will not turn from on/off to off/on and we will need
    // to wait a full cycle for it.
    ThreadUtils.sleep(getSleepBeforeFirstAttempt());
    while (statusRetries < allowedWaitForStatusRetries) {
        log.info("Attempt {} to get host '{}' status", statusRetries + 2, fencedHost.getHostName());
        statusResult = getStatus();
        if (statusResult.getStatus() == Status.SUCCESS) {
            if (statusResult.getPowerStatus() == PowerStatus.UNKNOWN) {
                if (unknownStatusReceived < getUnknownResultLimit() && statusRetries < allowedWaitForStatusRetries) {
                    // unknown power status received, wait a while and retry
                    ThreadUtils.sleep(delayBetweenRetries);
                    statusRetries++;
                    unknownStatusReceived++;
                } else {
                    // No need to retry, agent definitions are corrupted
                    log.error("Host '{}' PM Agent definitions are corrupted, aborting fence operation.", fencedHost.getHostName());
                    return new FenceOperationResult(Status.ERROR, PowerStatus.UNKNOWN, statusResult.getMessage());
                }
            } else if (statusResult.getPowerStatus() == requestedPowerStatus) {
                log.info("Host '{}' status is '{}'", fencedHost.getHostName(), requestedPowerStatus);
                return new FenceOperationResult(Status.SUCCESS, requestedPowerStatus);
            } else {
                // host is still not in requested power status
                statusRetries++;
                if (statusRetries < allowedWaitForStatusRetries) {
                    ThreadUtils.sleep(delayBetweenRetries);
                }
            }
        } else {
            log.error("Failed to get host '{}' status.", fencedHost.getHostName());
            return statusResult;
        }
    }
    auditVerifyStatusRetryLimitExceeded(fenceAction);
    return new FenceOperationResult(Status.ERROR, statusResult == null ? PowerStatus.UNKNOWN : statusResult.getPowerStatus(), statusResult == null ? "" : statusResult.getMessage());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Example 33 with FenceOperationResult

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

the class FenceVdsVDSCommand method isAlreadyInRequestedStatus.

/**
 * Checks if Host is already in the requested status. If Host is Down and a Stop command is issued or if Host is Up
 * and a Start command is issued command should do nothing.
 */
private boolean isAlreadyInRequestedStatus() {
    FenceStatusReturn result = fenceNode(FenceActionType.STATUS);
    FenceOperationResult actionResult = new FenceOperationResult(FenceActionType.STATUS, result.getStatus().code, result.getStatus().message, result.power, result.operationStatus);
    return actionResult.getStatus() == FenceOperationResult.Status.SUCCESS && actionResult.getPowerStatus() == getRequestedPowerStatus(getParameters().getAction());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Example 34 with FenceOperationResult

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

the class FenceVdsVDSCommandTest method stopHostWithUnknownPowerStatus.

/**
 * Test execution of stop action when host power status cannot be determined
 */
@Test
public void stopHostWithUnknownPowerStatus() {
    setupCommand(setupCommandParams(FenceActionType.STOP));
    setupBrokerResult(// result of STATUS action executed prior to STOP action
    createBrokerResultMap(1, "", "unknown", null), // result of actual STOP action
    createBrokerResultMap(0, "", "unknown", "initiated"));
    command.execute();
    FenceOperationResult result = (FenceOperationResult) command.getVDSReturnValue().getReturnValue();
    assertEquals(Status.SUCCESS, result.getStatus());
    assertEquals(PowerStatus.UNKNOWN, result.getPowerStatus());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) Test(org.junit.Test)

Example 35 with FenceOperationResult

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

the class FenceVdsVDSCommandTest method stopHostWhichIsPoweredUp.

/**
 * Test execution of stop action when host is powered up
 */
@Test
public void stopHostWhichIsPoweredUp() {
    setupCommand(setupCommandParams(FenceActionType.STOP));
    setupBrokerResult(// result of STATUS action executed prior to STOP action
    createBrokerResultMap(0, "", "on", null), // result of actual STOP action
    createBrokerResultMap(0, "", "unknown", "initiated"));
    command.execute();
    FenceOperationResult result = (FenceOperationResult) command.getVDSReturnValue().getReturnValue();
    assertEquals(Status.SUCCESS, result.getStatus());
    assertEquals(PowerStatus.UNKNOWN, result.getPowerStatus());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) Test(org.junit.Test)

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