Search in sources :

Example 1 with RollingMaintenanceCommand

use of com.cloud.agent.api.RollingMaintenanceCommand in project cloudstack by apache.

the class RollingMaintenanceManagerImpl method sendRollingMaintenanceCommandToHost.

/**
 * Send rolling maintenance command to a host to perform a certain stage specified in cmd
 * @return tuple: (SUCCESS, DETAILS, AVOID_MAINTENANCE) where:
 *                  - SUCCESS: True if stage is successfull
 *                  - DETAILS: Information retrieved by the host after executing the stage
 *                  - AVOID_MAINTENANCE: True if maintenance stage must be avoided
 */
private Ternary<Boolean, String, Boolean> sendRollingMaintenanceCommandToHost(Host host, Stage stage, int timeout, String payload) throws InterruptedException {
    boolean completed = false;
    Answer answer = null;
    long timeSpent = 0L;
    long pingInterval = KvmRollingMaintenancePingInterval.value() * 1000L;
    boolean avoidMaintenance = false;
    RollingMaintenanceCommand cmd = new RollingMaintenanceCommand(stage.toString());
    cmd.setWait(timeout);
    cmd.setPayload(payload);
    while (!completed && timeSpent < timeout * 1000L) {
        try {
            answer = agentManager.send(host.getId(), cmd);
        } catch (AgentUnavailableException | OperationTimedoutException e) {
            // Agent may be restarted on the scripts - continue polling until it is up
            String msg = String.format("Cannot send command to %s, waiting %sms - %s", host, pingInterval, e.getMessage());
            s_logger.warn(msg, e);
            cmd.setStarted(true);
            Thread.sleep(pingInterval);
            timeSpent += pingInterval;
            continue;
        }
        cmd.setStarted(true);
        RollingMaintenanceAnswer rollingMaintenanceAnswer = (RollingMaintenanceAnswer) answer;
        completed = rollingMaintenanceAnswer.isFinished();
        if (!completed) {
            Thread.sleep(pingInterval);
            timeSpent += pingInterval;
        } else {
            avoidMaintenance = rollingMaintenanceAnswer.isAvoidMaintenance();
        }
    }
    if (timeSpent >= timeout * 1000L) {
        return new Ternary<>(false, "Timeout exceeded for rolling maintenance on host " + host.getUuid() + " and stage " + stage.toString(), avoidMaintenance);
    }
    return new Ternary<>(answer.getResult(), answer.getDetails(), avoidMaintenance);
}
Also used : Answer(com.cloud.agent.api.Answer) RollingMaintenanceAnswer(com.cloud.agent.api.RollingMaintenanceAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) Ternary(com.cloud.utils.Ternary) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) RollingMaintenanceCommand(com.cloud.agent.api.RollingMaintenanceCommand) RollingMaintenanceAnswer(com.cloud.agent.api.RollingMaintenanceAnswer)

Aggregations

Answer (com.cloud.agent.api.Answer)1 RollingMaintenanceAnswer (com.cloud.agent.api.RollingMaintenanceAnswer)1 RollingMaintenanceCommand (com.cloud.agent.api.RollingMaintenanceCommand)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 Ternary (com.cloud.utils.Ternary)1