Search in sources :

Example 1 with AgentImpl

use of org.eclipse.che.api.agent.shared.model.impl.AgentImpl 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 AgentImpl

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

the class ExecAgentLauncher method launch.

@Override
public void launch(Instance machine, Agent agent) throws ServerException {
    final AgentImpl agentCopy = new AgentImpl(agent);
    agentCopy.setScript(agent.getScript() + "\n" + runCommand);
    super.launch(machine, agentCopy);
}
Also used : AgentImpl(org.eclipse.che.api.agent.shared.model.impl.AgentImpl)

Example 3 with AgentImpl

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

the class SshMachineExecAgentLauncher method launch.

public void launch(SshMachineInstance machine, Agent agent) throws ServerException {
    if (isNullOrEmpty(agent.getScript())) {
        return;
    }
    try {
        String architecture = detectArchitecture(machine);
        machine.copy(archivePathProvider.getPath(architecture), terminalLocation);
        final AgentImpl agentCopy = new AgentImpl(agent);
        agentCopy.setScript(agent.getScript() + "\n" + terminalRunCommand);
        final SshMachineProcess process = start(machine, agentCopy);
        LOG.debug("Waiting for agent {} is launched. Workspace ID:{}", agentCopy.getId(), machine.getWorkspaceId());
        final long pingStartTimestamp = System.currentTimeMillis();
        SshProcessLaunchedChecker agentLaunchingChecker = new SshProcessLaunchedChecker("che-websocket-terminal");
        while (System.currentTimeMillis() - pingStartTimestamp < agentMaxStartTimeMs) {
            if (agentLaunchingChecker.isLaunched(agentCopy, machine)) {
                return;
            } else {
                Thread.sleep(agentPingDelayMs);
            }
        }
        process.kill();
        final String errMsg = format("Fail launching agent %s. Workspace ID:%s", agent.getName(), machine.getWorkspaceId());
        LOG.error(errMsg);
        throw new ServerException(errMsg);
    } catch (MachineException e) {
        throw new ServerException(e.getServiceError());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ServerException(format("Launching agent %s is interrupted", agent.getName()));
    } catch (ConflictException e) {
        // should never happen
        throw new ServerException("Internal server error occurs on terminal launching.");
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) SshMachineProcess(org.eclipse.che.plugin.machine.ssh.SshMachineProcess) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) AgentImpl(org.eclipse.che.api.agent.shared.model.impl.AgentImpl)

Aggregations

AgentImpl (org.eclipse.che.api.agent.shared.model.impl.AgentImpl)3 ServerException (org.eclipse.che.api.core.ServerException)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AgentException (org.eclipse.che.api.agent.server.exception.AgentException)1 ConflictException (org.eclipse.che.api.core.ConflictException)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 SshMachineProcess (org.eclipse.che.plugin.machine.ssh.SshMachineProcess)1