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());
}
}
}
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");
}
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");
}
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);
}
}
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;
}
Aggregations