Search in sources :

Example 1 with Service

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());
}
Also used : Service(de.cinovo.cloudconductor.api.model.Service)

Example 2 with Service

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;
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) Scanner(java.util.Scanner) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) ArrayList(java.util.ArrayList) Service(de.cinovo.cloudconductor.api.model.Service) ScriptExecutor(de.cinovo.cloudconductor.agent.executors.ScriptExecutor)

Aggregations

Service (de.cinovo.cloudconductor.api.model.Service)2 ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)1 ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)1 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1