Search in sources :

Example 1 with FileExecutor

use of de.cinovo.cloudconductor.agent.executors.FileExecutor in project cloudconductor-agent-redhat by cinovo.

the class ConfigFileHandler method run.

/**
 * @throws ExecutionError an error occurred during execution
 */
public void run() throws ExecutionError {
    ConfigFileHandler.LOGGER.debug("Start Config File Handler");
    Set<ConfigFile> configFiles;
    try {
        configFiles = ServerCom.getFiles();
        ConfigFileHandler.LOGGER.debug("Received " + configFiles.size() + " configuration files.");
    } catch (CloudConductorException e) {
        ConfigFileHandler.LOGGER.error("Error getting configuration files from server: ", e);
        throw new ExecutionError(e);
    }
    // handle files
    ConfigFileHandler.LOGGER.debug("Handle files");
    IExecutor<Set<String>> files = new FileExecutor(configFiles);
    try {
        files.execute();
    } catch (ExecutionError e) {
        // just log the error but go on with execution
        ConfigFileHandler.LOGGER.error("Error handling files: " + e.getMessage(), e);
    }
    Set<String> servicesToRestart = files.getResult();
    if ((servicesToRestart != null) && !servicesToRestart.isEmpty()) {
        // handle restart of services
        ConfigFileHandler.LOGGER.debug("Restart services");
        ScriptExecutor serviceHandler = ScriptExecutor.generateServiceStateHandler(servicesToRestart, null, null);
        try {
            serviceHandler.execute();
        } catch (ExecutionError e) {
            // just log the error but go on with execution
            ConfigFileHandler.LOGGER.error(e.getMessage());
        }
    }
    ConfigFileHandler.LOGGER.debug("Finished Config File Handler");
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) Set(java.util.Set) FileExecutor(de.cinovo.cloudconductor.agent.executors.FileExecutor) ConfigFile(de.cinovo.cloudconductor.api.model.ConfigFile) ScriptExecutor(de.cinovo.cloudconductor.agent.executors.ScriptExecutor)

Aggregations

ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)1 FileExecutor (de.cinovo.cloudconductor.agent.executors.FileExecutor)1 ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)1 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)1 ConfigFile (de.cinovo.cloudconductor.api.model.ConfigFile)1 Set (java.util.Set)1