Search in sources :

Example 1 with AgentKey

use of org.eclipse.che.api.agent.shared.model.AgentKey in project che by eclipse.

the class WorkspaceRuntimes method launchAgents.

protected void launchAgents(Instance instance, List<String> agents) throws ServerException {
    try {
        for (AgentKey agentKey : agentSorter.sort(agents)) {
            if (!Thread.currentThread().isInterrupted()) {
                LOG.info("Launching '{}' agent at workspace {}", agentKey.getId(), instance.getWorkspaceId());
                Agent agent = agentRegistry.getAgent(agentKey);
                AgentLauncher launcher = launcherFactory.find(agentKey.getId(), instance.getConfig().getType());
                launcher.launch(instance, agent);
            }
        }
    } catch (AgentException e) {
        throw new MachineException(e.getMessage(), e);
    }
}
Also used : AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) Agent(org.eclipse.che.api.agent.shared.model.Agent) AgentLauncher(org.eclipse.che.api.agent.server.launcher.AgentLauncher) AgentException(org.eclipse.che.api.agent.server.exception.AgentException) MachineException(org.eclipse.che.api.machine.server.exception.MachineException)

Example 2 with AgentKey

use of org.eclipse.che.api.agent.shared.model.AgentKey in project che by eclipse.

the class AgentSorter method doSort.

private void doSort(AgentKey agentKey, List<AgentKey> sorted, Set<String> pending) throws AgentException {
    String agentId = agentKey.getId();
    Optional<AgentKey> alreadySorted = sorted.stream().filter(k -> k.getId().equals(agentId)).findFirst();
    if (alreadySorted.isPresent()) {
        return;
    }
    pending.add(agentId);
    Agent agent = agentRegistry.getAgent(agentKey);
    for (String dependency : agent.getDependencies()) {
        if (pending.contains(dependency)) {
            throw new AgentException(String.format("Agents circular dependency found between '%s' and '%s'", dependency, agentId));
        }
        doSort(AgentKeyImpl.parse(dependency), sorted, pending);
    }
    sorted.add(agentKey);
    pending.remove(agentId);
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) AgentKeyImpl(org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl) Inject(com.google.inject.Inject) Set(java.util.Set) AgentException(org.eclipse.che.api.agent.server.exception.AgentException) Nullable(org.eclipse.che.commons.annotation.Nullable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Optional(java.util.Optional) AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) Singleton(com.google.inject.Singleton) AgentRegistry(org.eclipse.che.api.agent.server.AgentRegistry) AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) Agent(org.eclipse.che.api.agent.shared.model.Agent) AgentException(org.eclipse.che.api.agent.server.exception.AgentException)

Example 3 with AgentKey

use of org.eclipse.che.api.agent.shared.model.AgentKey in project che by eclipse.

the class AgentConfigApplier method apply.

/**
     * Applies docker specific properties to a machine.
     *
     * @param machineConf
     *         machine config with the list of agents that should be injected into machine
     * @param machine
     *         affected machine
     * @throws AgentException
     *         if any error occurs
     */
public void apply(@Nullable ExtendedMachine machineConf, CheServiceImpl machine) throws AgentException {
    if (machineConf != null) {
        for (AgentKey agentKey : sorter.sort(machineConf.getAgents())) {
            Agent agent = agentRegistry.getAgent(agentKey);
            addEnv(machine, agent.getProperties());
            addExposedPorts(machine, agent.getServers());
            addLabels(machine, agent.getServers());
        }
    }
}
Also used : AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) Agent(org.eclipse.che.api.agent.shared.model.Agent)

Aggregations

Agent (org.eclipse.che.api.agent.shared.model.Agent)3 AgentKey (org.eclipse.che.api.agent.shared.model.AgentKey)3 AgentException (org.eclipse.che.api.agent.server.exception.AgentException)2 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AgentRegistry (org.eclipse.che.api.agent.server.AgentRegistry)1 AgentLauncher (org.eclipse.che.api.agent.server.launcher.AgentLauncher)1 AgentKeyImpl (org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl)1 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)1 Nullable (org.eclipse.che.commons.annotation.Nullable)1