Search in sources :

Example 26 with FenceOperationResult

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

the class StartVdsCommandTest method onSuccessReturnValueOk.

/**
 * This test verifies that when the fence operation is successful, the return value contains all that is should:
 * succeeded=true, the agents used, and the object returned.
 */
@Test
public void onSuccessReturnValueOk() {
    mockExecutor(true);
    doNothing().when(command).teardown();
    command.executeCommand();
    assertTrue(command.getReturnValue().getSucceeded());
    Object commandReturnValue = command.getReturnValue().getActionReturnValue();
    assertNotNull(commandReturnValue);
    assertTrue(commandReturnValue instanceof FenceOperationResult);
    FenceOperationResult commandReturnValueCasted = (FenceOperationResult) commandReturnValue;
    assertEquals(Status.SUCCESS, commandReturnValueCasted.getStatus());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 27 with FenceOperationResult

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

the class StartVdsCommandTest method mockExecutor.

private void mockExecutor(boolean success) {
    FenceOperationResult result;
    if (success) {
        result = new FenceOperationResult(Status.SUCCESS, PowerStatus.ON);
    } else {
        result = new FenceOperationResult(Status.ERROR, PowerStatus.UNKNOWN);
    }
    doReturn(result).when(executor).fence(any());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Example 28 with FenceOperationResult

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

the class FenceAgentExecutor method executeFenceAction.

protected FenceOperationResult executeFenceAction(FenceActionType action, FenceAgent agent, VDS proxyHost) {
    FenceAgent realAgent = createRealAgent(agent, proxyHost);
    auditFenceActionExecution(action, realAgent, proxyHost);
    VDSReturnValue retVal = resourceManager.runVdsCommand(VDSCommandType.FenceVds, new FenceVdsVDSCommandParameters(proxyHost.getId(), fencedHost.getId(), realAgent, action, convertFencingPolicy(proxyHost)));
    FenceOperationResult result = (FenceOperationResult) retVal.getReturnValue();
    log.debug("Result of '{}' fence action: {}", result);
    if (result == null) {
        log.error("FenceVdsVDSCommand finished with null return value: succeeded={}, exceptionString='{}'", retVal.getSucceeded(), retVal.getExceptionString());
        log.debug("Exception", retVal.getExceptionObject());
        result = new FenceOperationResult(Status.ERROR, PowerStatus.UNKNOWN, retVal.getExceptionString());
    }
    if (result.getStatus() == Status.ERROR) {
        auditFenceActionFailure(action, realAgent, proxyHost);
    }
    return result;
}
Also used : FenceVdsVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.FenceVdsVDSCommandParameters) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) FenceAgent(org.ovirt.engine.core.common.businessentities.pm.FenceAgent) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 29 with FenceOperationResult

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

the class FenceVdsBaseCommand method executeCommand.

@Override
protected void executeCommand() {
    log.info("Power-Management: {} of host '{}' initiated.", getAction(), getVdsName());
    audit(AuditLogType.FENCE_OPERATION_STARTED);
    VDSStatus lastStatus = getVds().getStatus();
    FenceOperationResult result = null;
    try {
        setup();
        result = createHostFenceActionExecutor(getVds(), getParameters().getFencingPolicy()).fence(getAction());
        handleResult(result);
        if (getSucceeded()) {
            log.info("Power-Management: {} host '{}' succeeded.", getAction(), getVdsName());
            audit(AuditLogType.FENCE_OPERATION_SUCCEEDED);
        } else {
            log.info("Power-Management: {} host '{}' failed.", getAction(), getVdsName());
            audit(AuditLogType.FENCE_OPERATION_FAILED);
        }
    } finally {
        if (!getSucceeded()) {
            setStatus(lastStatus);
            if (result != null && result.getStatus() != Status.SKIPPED_DUE_TO_POLICY) {
                // show alert only if command was not skipped due to fencing policy
                alertIfPowerManagementOperationFailed();
            }
            throw new EngineException(EngineError.VDS_FENCE_OPERATION_FAILED);
        } else {
            teardown();
        }
    }
}
Also used : VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 30 with FenceOperationResult

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

the class HostFenceActionExecutor method fence.

/**
 * Executes specified fence action using specified fence agents
 */
protected FenceOperationResult fence(FenceActionType fenceAction, List<FenceAgent> fenceAgents) {
    PowerManagementHelper.AgentsIterator iterator = createFenceAgentsIterator(fenceAgents);
    FenceOperationResult result = null;
    while (iterator.hasNext()) {
        result = createFenceActionExecutor(iterator.next()).fence(fenceAction);
        if (result.getStatus() == Status.SUCCESS) {
            break;
        }
    }
    return result;
}
Also used : 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