Search in sources :

Example 6 with FenceOperationResult

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

the class FenceVdsVDSCommand method executeVdsBrokerCommand.

@Override
protected void executeVdsBrokerCommand() {
    // ignore starting already started host or stopping already stopped host.
    if (getParameters().getAction() == FenceActionType.STATUS || !isAlreadyInRequestedStatus()) {
        FenceStatusReturn result = fenceNode(getParameters().getAction());
        FenceOperationResult actionResult = new FenceOperationResult(getParameters().getAction(), result.getStatus().code, result.getStatus().message, result.power, result.operationStatus);
        setReturnValue(actionResult);
        getVDSReturnValue().setSucceeded(actionResult.getStatus() != FenceOperationResult.Status.ERROR);
        if (getParameters().getAction() == FenceActionType.STATUS && actionResult.getPowerStatus() == PowerStatus.UNKNOWN && !getParameters().getTargetVdsID().equals(Guid.Empty)) {
            alertPowerManagementStatusFailed(actionResult.getMessage());
        }
    } else {
        // start/stop action was skipped, host is already turned on/off
        alertActionSkippedAlreadyInStatus();
        getVDSReturnValue().setSucceeded(true);
        setReturnValue(new FenceOperationResult(FenceOperationResult.Status.SKIPPED_ALREADY_IN_STATUS, PowerStatus.UNKNOWN));
    }
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult)

Example 7 with FenceOperationResult

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

the class FenceVdsVDSCommandTest method stopHostWhichIsPoweredDown.

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

Example 8 with FenceOperationResult

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

the class FenceVdsVDSCommandTest method stopHostSkippedDueToFencingPolicy.

/**
 * Test execution of stop action when fencing policy forbids stopping host still connected to storage, so stopping
 * the host is skipped
 */
@Test
public void stopHostSkippedDueToFencingPolicy() {
    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", "skipped"));
    command.execute();
    FenceOperationResult result = (FenceOperationResult) command.getVDSReturnValue().getReturnValue();
    assertEquals(Status.SKIPPED_DUE_TO_POLICY, result.getStatus());
    assertEquals(PowerStatus.UNKNOWN, result.getPowerStatus());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) Test(org.junit.Test)

Example 9 with FenceOperationResult

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

the class FenceVdsVDSCommandTest method failedGetStatus.

/**
 * Tests result of failed get power status of host
 */
@Test
public void failedGetStatus() {
    String agentMessage = "Test failed, status unknown";
    setupCommand(setupCommandParams(FenceActionType.STATUS));
    setupBrokerResult(createBrokerResultMap(1, agentMessage, "unknown", null));
    command.execute();
    FenceOperationResult result = (FenceOperationResult) command.getVDSReturnValue().getReturnValue();
    assertEquals(Status.ERROR, result.getStatus());
    assertEquals(PowerStatus.UNKNOWN, result.getPowerStatus());
    assertEquals(agentMessage, result.getMessage());
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) Test(org.junit.Test)

Example 10 with FenceOperationResult

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

the class ConcurrentAgentsFenceActionExecutor method fenceConcurrently.

/**
 * Executes specified fence action on all fence agents concurrently
 */
protected FenceOperationResult fenceConcurrently(FenceActionType fenceAction) {
    List<FenceOperationResult> results = new ArrayList<>(fenceAgents.size());
    FenceOperationResult taskResult;
    ExecutorCompletionService<FenceOperationResult> tasksExecutor = ThreadPoolUtil.createCompletionService();
    List<Future<FenceOperationResult>> futures = ThreadPoolUtil.submitTasks(tasksExecutor, createTasks(fenceAction));
    for (int i = 0; i < fenceAgents.size(); ++i) {
        try {
            taskResult = tasksExecutor.take().get();
        } catch (ExecutionException | InterruptedException e) {
            taskResult = new FenceOperationResult(Status.ERROR, PowerStatus.UNKNOWN, e.getMessage());
            log.error("Error getting task result: {}", e.getMessage());
            log.debug("Exception", e);
        }
        results.add(taskResult);
        if (tasksProcessor.isGoalReached(taskResult)) {
            // action goal is reach, cancel all remaining tasks
            for (Future<FenceOperationResult> future : futures) {
                future.cancel(true);
            }
            break;
        }
    }
    return tasksProcessor.createActionResult(results);
}
Also used : FenceOperationResult(org.ovirt.engine.core.common.businessentities.pm.FenceOperationResult) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

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