Search in sources :

Example 6 with Agent

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

the class AbstractAgentLauncherTest method shouldStartMachineProcessWithAgentScriptExecution.

@Test
public void shouldStartMachineProcessWithAgentScriptExecution() throws Exception {
    // given
    String agentId = "testAgentId";
    String agentScript = "testAgentScript";
    when(agent.getId()).thenReturn(agentId);
    when(agent.getScript()).thenReturn(agentScript);
    when(launcher.start(any(Instance.class), any(Agent.class), any(LineConsumer.class))).thenCallRealMethod();
    // when
    launcher.launch(machine, agent);
    // then
    verify(machine).createProcess(eq(new CommandImpl(agentId, agentScript, "agent")), eq(null));
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) Agent(org.eclipse.che.api.agent.shared.model.Agent) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Instance(org.eclipse.che.api.machine.server.spi.Instance) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 7 with Agent

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

the class AbstractAgentLauncherTest method shouldLogAgentStartLogsIfMachineExceptionOccurs.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "An error on agent start")
public void shouldLogAgentStartLogsIfMachineExceptionOccurs() throws Exception {
    // given
    doThrow(new MachineException("An error on agent start")).when(launcher).start(any(Instance.class), any(Agent.class), any(LineConsumer.class));
    // when
    launcher.launch(machine, agent);
    // then
    verify(launcher).logAsErrorAgentStartLogs(anyString(), anyString());
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) Test(org.testng.annotations.Test)

Example 8 with Agent

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

the class AbstractAgentLauncherTest method shouldLogAgentStartLogsIfMachineExceptionOccursAfterAgentStartTimeoutHadReached.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "An error on process kill")
public void shouldLogAgentStartLogsIfMachineExceptionOccursAfterAgentStartTimeoutHadReached() throws Exception {
    // given
    launcher = spy(new TestAgentLauncher(-1, 100, agentChecker));
    when(agentChecker.isLaunched(any(Agent.class), any(InstanceProcess.class), any(Instance.class))).thenReturn(false);
    doReturn(process).when(launcher).start(any(Instance.class), any(Agent.class), any(LineConsumer.class));
    doThrow(new MachineException("An error on process kill")).when(process).kill();
    // when
    launcher.launch(machine, agent);
    // then
    verify(launcher).logAsErrorAgentStartLogs(anyString(), anyString());
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) InstanceProcess(org.eclipse.che.api.machine.server.spi.InstanceProcess) Test(org.testng.annotations.Test)

Example 9 with Agent

use of org.eclipse.che.api.agent.shared.model.Agent 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)9 Test (org.testng.annotations.Test)5 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)4 Instance (org.eclipse.che.api.machine.server.spi.Instance)4 AgentKey (org.eclipse.che.api.agent.shared.model.AgentKey)3 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)3 AgentException (org.eclipse.che.api.agent.server.exception.AgentException)2 AgentLauncher (org.eclipse.che.api.agent.server.launcher.AgentLauncher)2 AgentKeyImpl (org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl)2 InstanceProcess (org.eclipse.che.api.machine.server.spi.InstanceProcess)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 DataSource (javax.sql.DataSource)1 ExecAgent (org.eclipse.che.api.agent.ExecAgent)1 ExecAgentLauncher (org.eclipse.che.api.agent.ExecAgentLauncher)1