Search in sources :

Example 1 with CloudConductorException

use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException 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 CloudConductorException

use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException 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 CloudConductorException

use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException 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 CloudConductorException

use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.

the class ServerCom method getConfig.

/**
 * @return the config for this agent
 * @throws CloudConductorException error if retrieval fails
 */
public static Map<String, String> getConfig() throws CloudConductorException {
    Map<String, String> configMap = new HashMap<>();
    try {
        for (ConfigValue c : ServerCom.config.getConfig(AgentState.info().getTemplate(), AgentVars.SERVICE_NAME)) {
            if ((c.getService() != null) && c.getService().equals(AgentVars.SERVICE_NAME)) {
                ServerCom.LOGGER.debug("Add config: " + c.getKey() + ": " + c.getValue());
                configMap.put(c.getKey(), (String) c.getValue());
            }
        }
    } catch (RuntimeException e) {
        ServerCom.LOGGER.error("Error getting config from server: ", e);
        throw new CloudConductorException(e.getMessage());
    }
    return configMap;
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) ConfigValue(de.cinovo.cloudconductor.api.model.ConfigValue) HashMap(java.util.HashMap)

Example 5 with CloudConductorException

use of de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException in project cloudconductor-agent-redhat by cinovo.

the class ServerCom method heartBeat.

/**
 * @return the response
 * @throws CloudConductorException thrown if communication with cloudconductor failed
 */
public static AgentOption heartBeat() throws CloudConductorException {
    try {
        String template = AgentState.info().getTemplate();
        String host = AgentState.info().getHost();
        String uuid = AgentState.info().getUuid();
        String agentName = AgentState.info().getAgent();
        return ServerCom.agent.heartBeat(template, host, agentName, uuid);
    } catch (RuntimeException e) {
        ServerCom.LOGGER.error("Error sending heart beat: ", e);
        throw new CloudConductorException(e.getMessage());
    }
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)

Aggregations

CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)16 ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)9 ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)3 IOException (java.io.IOException)3 TransformationErrorException (de.cinovo.cloudconductor.agent.exceptions.TransformationErrorException)2 ConfigFile (de.cinovo.cloudconductor.api.model.ConfigFile)2 HashCode (com.google.common.hash.HashCode)1 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 ServerConnectionException (de.cinovo.cloudconductor.agent.exceptions.ServerConnectionException)1 FileExecutor (de.cinovo.cloudconductor.agent.executors.FileExecutor)1 InstalledPackages (de.cinovo.cloudconductor.agent.executors.InstalledPackages)1 RefreshJWTJob (de.cinovo.cloudconductor.agent.jobs.RefreshJWTJob)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 RepoHandler (de.cinovo.cloudconductor.agent.jobs.handler.RepoHandler)1 AgentOption (de.cinovo.cloudconductor.api.model.AgentOption)1 ConfigValue (de.cinovo.cloudconductor.api.model.ConfigValue)1 PackageState (de.cinovo.cloudconductor.api.model.PackageState)1 Repo (de.cinovo.cloudconductor.api.model.Repo)1