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