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);
}
}
Aggregations