Search in sources :

Example 1 with AgentException

use of org.eclipse.che.api.agent.server.exception.AgentException in project che by eclipse.

the class CheEnvironmentEngine method addAgentsProvidedServers.

private void addAgentsProvidedServers(MachineImpl machine, List<String> agentKeys) throws ServerException {
    for (String agentKey : agentKeys) {
        try {
            AgentImpl agent = new AgentImpl(agentRegistry.getAgent(AgentKeyImpl.parse(agentKey)));
            for (Map.Entry<String, ? extends ServerConf2> entry : agent.getServers().entrySet()) {
                String ref = entry.getKey();
                ServerConf2 conf2 = entry.getValue();
                ServerConfImpl conf = new ServerConfImpl(ref, conf2.getPort(), conf2.getProtocol(), conf2.getProperties().get("path"));
                machine.getConfig().getServers().add(conf);
            }
        } catch (AgentException e) {
            throw new ServerException(e);
        }
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) AgentException(org.eclipse.che.api.agent.server.exception.AgentException) AgentImpl(org.eclipse.che.api.agent.shared.model.impl.AgentImpl) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2)

Example 2 with AgentException

use of org.eclipse.che.api.agent.server.exception.AgentException 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 3 with AgentException

use of org.eclipse.che.api.agent.server.exception.AgentException 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)

Aggregations

AgentException (org.eclipse.che.api.agent.server.exception.AgentException)3 Agent (org.eclipse.che.api.agent.shared.model.Agent)2 AgentKey (org.eclipse.che.api.agent.shared.model.AgentKey)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 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AgentRegistry (org.eclipse.che.api.agent.server.AgentRegistry)1 AgentLauncher (org.eclipse.che.api.agent.server.launcher.AgentLauncher)1 AgentImpl (org.eclipse.che.api.agent.shared.model.impl.AgentImpl)1 AgentKeyImpl (org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl)1 ServerException (org.eclipse.che.api.core.ServerException)1 ServerConf2 (org.eclipse.che.api.core.model.workspace.ServerConf2)1 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)1 ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)1