Search in sources :

Example 1 with ExecutionError

use of de.cinovo.cloudconductor.agent.exceptions.ExecutionError in project cloudconductor-agent-redhat by cinovo.

the class DefaultJob method handlePackages.

private void handlePackages() {
    try {
        PackageHandler packageHandler = new PackageHandler();
        packageHandler.run();
    } catch (ExecutionError e) {
        if (e.getCause() instanceof CloudConductorException) {
            DefaultJob.LOGGER.error("Error handling packages: " + e.getMessage(), e);
        } else {
            DefaultJob.LOGGER.error("Error handling packages: " + e.getMessage());
        }
    }
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) PackageHandler(de.cinovo.cloudconductor.agent.jobs.handler.PackageHandler) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError)

Example 2 with ExecutionError

use of de.cinovo.cloudconductor.agent.exceptions.ExecutionError in project cloudconductor-agent-redhat by cinovo.

the class HeartBeatJob method run.

@Override
public void run() {
    HeartBeatJob.LOGGER.debug("Starting HeartBeatJob");
    AgentOption newOptions;
    try {
        newOptions = ServerCom.heartBeat();
    } catch (CloudConductorException e) {
        HeartBeatJob.LOGGER.error("Error getting options from server: ", e);
        return;
    }
    new OptionHandler(newOptions).run();
    try {
        if (AgentState.repoExecutionLock.tryLock()) {
            new RepoHandler().run();
        }
    } catch (ExecutionError e) {
        HeartBeatJob.LOGGER.error("Error updating repos: ", e);
    } finally {
        AgentState.repoExecutionLock.unlock();
    }
    HeartBeatJob.LOGGER.debug("Finished HeartBeatJob");
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) RepoHandler(de.cinovo.cloudconductor.agent.jobs.handler.RepoHandler) AgentOption(de.cinovo.cloudconductor.api.model.AgentOption) OptionHandler(de.cinovo.cloudconductor.agent.jobs.handler.OptionHandler)

Example 3 with ExecutionError

use of de.cinovo.cloudconductor.agent.exceptions.ExecutionError 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 4 with ExecutionError

use of de.cinovo.cloudconductor.agent.exceptions.ExecutionError in project cloudconductor-agent-redhat by cinovo.

the class InstalledPackages method analyzeStream.

@Override
protected void analyzeStream(String[] dev, String[] error) throws ExecutionError {
    if (error.length > 0) {
        this.logger.error("Failed to get installed packages");
        for (String s : error) {
            this.logger.error(s);
        }
        throw new ExecutionError("Error while collecting installed packages");
    }
    this.logger.debug("Found installed packages: " + dev.length);
    String oldString = null;
    for (String str : dev) {
        if (oldString != null && str.startsWith(" ")) {
            // we need this to work around the yum list bullshit of breaking to new lines sometimes
            str = oldString + str;
        }
        str = str.replaceAll("\\s+", delimiter);
        String[] arr = str.split(InstalledPackages.delimiter);
        if (arr.length < 3) {
            oldString = str;
            continue;
        }
        oldString = null;
        String pkg = arr[0].split("\\.")[0];
        String version = arr[1].split(":")[arr[1].split(":").length - 1];
        if (!version.matches(".*\\d.*")) {
            // we don't have a version -> useless information
            continue;
        }
        String repo = arr[2].replace("@", "");
        PackageVersion packageVersion = new PackageVersion(pkg, version, null);
        Set<String> repos = new HashSet<>();
        repos.add(repo);
        packageVersion.setRepos(repos);
        this.logger.debug(pkg + " - " + version + " - " + repo);
        this.result.add(packageVersion);
    }
}
Also used : ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) PackageVersion(de.cinovo.cloudconductor.api.model.PackageVersion) HashSet(java.util.HashSet)

Example 5 with ExecutionError

use of de.cinovo.cloudconductor.agent.exceptions.ExecutionError in project cloudconductor-agent-redhat by cinovo.

the class AbstractExecutor method execute.

/**
 * @return the executor
 * @throws ExecutionError if an error during execution occures
 */
@Override
public IExecutor<T> execute() throws ExecutionError {
    Process p;
    try {
        p = this.genProcess();
    } catch (Exception e) {
        throw new ExecutionError("Error generating a process.", e);
    }
    if (p == null) {
        throw new ExecutionError("Error generating a process.");
    }
    StreamAnalyzer devAnalyzer = this.getAnalyzer(p.getInputStream());
    StreamAnalyzer errorAnalyzer = this.getAnalyzer(p.getErrorStream());
    devAnalyzer.start();
    errorAnalyzer.start();
    while (this.exitValue < 0) {
        try {
            this.exitValue = p.exitValue();
        } catch (IllegalThreadStateException e) {
            // sleep while waiting for process to finish
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {
            // just ignore this one
            }
        }
    }
    this.analyzeStream(devAnalyzer.getValues(), errorAnalyzer.getValues());
    return this;
}
Also used : ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) IOException(java.io.IOException)

Aggregations

ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)13 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)9 ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)3 IOException (java.io.IOException)3 RepoHandler (de.cinovo.cloudconductor.agent.jobs.handler.RepoHandler)2 ConfigFile (de.cinovo.cloudconductor.api.model.ConfigFile)2 HashSet (java.util.HashSet)2 HashCode (com.google.common.hash.HashCode)1 TransformationErrorException (de.cinovo.cloudconductor.agent.exceptions.TransformationErrorException)1 FileExecutor (de.cinovo.cloudconductor.agent.executors.FileExecutor)1 InstalledPackages (de.cinovo.cloudconductor.agent.executors.InstalledPackages)1 AgentJob (de.cinovo.cloudconductor.agent.jobs.AgentJob)1 ConfigFileHandler (de.cinovo.cloudconductor.agent.jobs.handler.ConfigFileHandler)1 OptionHandler (de.cinovo.cloudconductor.agent.jobs.handler.OptionHandler)1 PackageHandler (de.cinovo.cloudconductor.agent.jobs.handler.PackageHandler)1 ServiceHandler (de.cinovo.cloudconductor.agent.jobs.handler.ServiceHandler)1 AgentOption (de.cinovo.cloudconductor.api.model.AgentOption)1 PackageState (de.cinovo.cloudconductor.api.model.PackageState)1 PackageVersion (de.cinovo.cloudconductor.api.model.PackageVersion)1 Repo (de.cinovo.cloudconductor.api.model.Repo)1