use of de.cinovo.cloudconductor.api.model.Service in project cloudconductor-agent-redhat by cinovo.
the class ScriptExecutor method generateCheckServiceState.
/**
* @param services the services
* @return the executor
*/
public static ScriptExecutor generateCheckServiceState(Collection<Service> services) {
String scriptName = AgentVars.SCRIPT_SERVICE_STATE;
StringBuilder cmd = new StringBuilder();
if ((services != null) && !services.isEmpty()) {
for (Service svc : services) {
cmd.append(svc.getInitScript());
cmd.append(" ");
}
}
return new ScriptExecutor(scriptName, cmd.toString().trim());
}
use of de.cinovo.cloudconductor.api.model.Service 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