Search in sources :

Example 1 with RollingMaintenanceExecutor

use of com.cloud.hypervisor.kvm.resource.rolling.maintenance.RollingMaintenanceExecutor in project cloudstack by apache.

the class LibvirtRollingMaintenanceCommandWrapper method execute.

@Override
public RollingMaintenanceAnswer execute(RollingMaintenanceCommand command, LibvirtComputingResource resource) {
    RollingMaintenanceExecutor executor = resource.getRollingMaintenanceExecutor();
    String stage = command.isCheckMaintenanceScript() ? RollingMaintenanceManager.Stage.Maintenance.toString() : command.getStage();
    int timeout = command.getWait();
    String payload = command.getPayload();
    try {
        File scriptFile = executor.getStageScriptFile(stage);
        if (command.isCheckMaintenanceScript()) {
            return new RollingMaintenanceAnswer(command, scriptFile != null);
        } else if (scriptFile == null) {
            s_logger.info("No script file defined for stage " + stage + ". Skipping stage...");
            return new RollingMaintenanceAnswer(command, true, "Skipped stage " + stage, true);
        }
        if (command.isStarted() && executor instanceof RollingMaintenanceAgentExecutor) {
            String msg = "Stage has been started previously and the agent restarted, setting stage as finished";
            s_logger.info(msg);
            return new RollingMaintenanceAnswer(command, true, msg, true);
        }
        s_logger.info("Processing stage " + stage);
        if (!command.isStarted()) {
            executor.startStageExecution(stage, scriptFile, timeout, payload);
        }
        if (executor.isStageRunning(stage, scriptFile, payload)) {
            return new RollingMaintenanceAnswer(command, true, "Stage " + stage + " still running", false);
        }
        boolean success = executor.getStageExecutionSuccess(stage, scriptFile);
        String output = executor.getStageExecutionOutput(stage, scriptFile);
        RollingMaintenanceAnswer answer = new RollingMaintenanceAnswer(command, success, output, true);
        if (executor.getStageAvoidMaintenance(stage, scriptFile)) {
            s_logger.info("Avoid maintenance flag added to the answer for the stage " + stage);
            answer.setAvoidMaintenance(true);
        }
        s_logger.info("Finished processing stage " + stage);
        return answer;
    } catch (CloudRuntimeException e) {
        return new RollingMaintenanceAnswer(command, false, e.getMessage(), false);
    }
}
Also used : RollingMaintenanceExecutor(com.cloud.hypervisor.kvm.resource.rolling.maintenance.RollingMaintenanceExecutor) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) File(java.io.File) RollingMaintenanceAnswer(com.cloud.agent.api.RollingMaintenanceAnswer) RollingMaintenanceAgentExecutor(com.cloud.hypervisor.kvm.resource.rolling.maintenance.RollingMaintenanceAgentExecutor)

Aggregations

RollingMaintenanceAnswer (com.cloud.agent.api.RollingMaintenanceAnswer)1 RollingMaintenanceAgentExecutor (com.cloud.hypervisor.kvm.resource.rolling.maintenance.RollingMaintenanceAgentExecutor)1 RollingMaintenanceExecutor (com.cloud.hypervisor.kvm.resource.rolling.maintenance.RollingMaintenanceExecutor)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 File (java.io.File)1