Search in sources :

Example 1 with ScriptExecutor

use of de.cinovo.cloudconductor.agent.executors.ScriptExecutor 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)

Example 2 with ScriptExecutor

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

the class PackageHandler method run.

/**
 * @throws ExecutionError an error occurred during execution
 */
public void run() throws ExecutionError {
    PackageHandler.LOGGER.debug("Start PackageHandler");
    // report installed packages
    PackageStateChanges packageChanges = this.reportInstalledPackages();
    Set<String> repos = AgentState.info().getRepos();
    if (!repos.isEmpty()) {
        String repoNames = String.join(",", repos);
        PackageHandler.LOGGER.debug("Execute changes on repos {}", repoNames);
        // executed package changes for each repository
        List<PackageVersion> toDelete = packageChanges.getToErase();
        PackageHandler.LOGGER.debug("Delete: {}", toDelete.toString());
        List<PackageVersion> toInstall = packageChanges.getToInstall();
        PackageHandler.LOGGER.debug("Install: {}", toInstall.toString());
        List<PackageVersion> toUpdate = packageChanges.getToUpdate();
        PackageHandler.LOGGER.debug("Update: {}", toUpdate.toString());
        ScriptExecutor pkgHandler = ScriptExecutor.generatePackageHandler(repoNames, toDelete, toInstall, toUpdate);
        pkgHandler.execute();
        // re-report installed packages
        this.reportInstalledPackages();
    } else {
        PackageHandler.LOGGER.info("No repos in template");
    }
    PackageHandler.LOGGER.debug("Finished PackageHandler");
}
Also used : PackageStateChanges(de.cinovo.cloudconductor.api.model.PackageStateChanges) PackageVersion(de.cinovo.cloudconductor.api.model.PackageVersion) ScriptExecutor(de.cinovo.cloudconductor.agent.executors.ScriptExecutor)

Example 3 with ScriptExecutor

use of de.cinovo.cloudconductor.agent.executors.ScriptExecutor 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)

Example 4 with ScriptExecutor

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

the class ServiceHandler method collectRunningServices.

private List<String> collectRunningServices() throws ExecutionError {
    Set<Service> services = null;
    try {
        services = ServerCom.getServices();
    } catch (CloudConductorException e) {
        throw new ExecutionError("Error getting services from server: ", e);
    }
    List<String> runningServices = new ArrayList<String>();
    ScriptExecutor serviceStateHandler = ScriptExecutor.generateCheckServiceState(services);
    serviceStateHandler.execute();
    try (Scanner s = new Scanner(serviceStateHandler.getResult())) {
        while (s.hasNextLine()) {
            String scriptName = s.next().trim();
            for (Service service : services) {
                if (service.getInitScript().equalsIgnoreCase(scriptName) && !runningServices.contains(service.getName())) {
                    runningServices.add(service.getName());
                }
            }
        }
    }
    ServiceHandler.LOGGER.debug(services.size() + " services registered, " + runningServices.size() + " running.");
    return runningServices;
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) Scanner(java.util.Scanner) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) ArrayList(java.util.ArrayList) Service(de.cinovo.cloudconductor.api.model.Service) ScriptExecutor(de.cinovo.cloudconductor.agent.executors.ScriptExecutor)

Aggregations

ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)4 ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)3 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)3 FileExecutor (de.cinovo.cloudconductor.agent.executors.FileExecutor)1 ConfigFile (de.cinovo.cloudconductor.api.model.ConfigFile)1 PackageStateChanges (de.cinovo.cloudconductor.api.model.PackageStateChanges)1 PackageVersion (de.cinovo.cloudconductor.api.model.PackageVersion)1 Service (de.cinovo.cloudconductor.api.model.Service)1 ServiceStates (de.cinovo.cloudconductor.api.model.ServiceStates)1 ServiceStatesChanges (de.cinovo.cloudconductor.api.model.ServiceStatesChanges)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 Set (java.util.Set)1