Search in sources :

Example 1 with ServiceStatesChanges

use of de.cinovo.cloudconductor.api.model.ServiceStatesChanges in project cloudconductor-agent-redhat by cinovo.

the class ServiceHandler method run.

/**
 * @throws ExecutionError an error occurred during execution
 */
public void run() throws ExecutionError {
    ServiceHandler.LOGGER.debug("Start ServiceHandler");
    ServiceHandler.LOGGER.debug("ServiceHandler : Report running services");
    List<String> runningServices = this.collectRunningServices();
    ServiceStates req = new ServiceStates(runningServices);
    ServiceStatesChanges serviceChanges;
    try {
        serviceChanges = ServerCom.notifyRunningServices(req);
    } catch (CloudConductorException e) {
        throw new ExecutionError(e);
    }
    int nStart = serviceChanges.getToStart().size();
    int nStop = serviceChanges.getToStop().size();
    int nRestart = serviceChanges.getToRestart().size();
    ServiceHandler.LOGGER.debug("Service changes: " + nStart + " to be started, " + nStop + " to be stopped, " + nRestart + " to be restarted");
    // handle service changes
    ServiceHandler.LOGGER.debug("ServiceHandler: Handle service changes");
    ScriptExecutor serviceHandler = ScriptExecutor.generateServiceStateHandler(serviceChanges.getToRestart(), serviceChanges.getToStart(), serviceChanges.getToStop());
    try {
        serviceHandler.execute();
    } catch (ExecutionError e) {
        // just log the error but go on with execution
        ServiceHandler.LOGGER.error("Error executing service handler: ", e);
    }
    // notify server on current state
    ServiceHandler.LOGGER.debug("ServiceHandler : Report running services again");
    runningServices = this.collectRunningServices();
    req = new ServiceStates(runningServices);
    try {
        ServerCom.notifyRunningServices(req);
    } catch (CloudConductorException e) {
        throw new ExecutionError(e);
    }
    ServiceHandler.LOGGER.debug("Finished ServiceHandler");
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) ServiceStates(de.cinovo.cloudconductor.api.model.ServiceStates) ServiceStatesChanges(de.cinovo.cloudconductor.api.model.ServiceStatesChanges) ScriptExecutor(de.cinovo.cloudconductor.agent.executors.ScriptExecutor)

Aggregations

ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)1 ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)1 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)1 ServiceStates (de.cinovo.cloudconductor.api.model.ServiceStates)1 ServiceStatesChanges (de.cinovo.cloudconductor.api.model.ServiceStatesChanges)1