Search in sources :

Example 1 with ServerConf2

use of org.eclipse.che.api.core.model.workspace.ServerConf2 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 ServerConf2

use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.

the class CheEnvironmentValidator method validateExtendedMachine.

private void validateExtendedMachine(ExtendedMachine extendedMachine, String envName, String machineName) {
    if (extendedMachine.getAttributes() != null && extendedMachine.getAttributes().get("memoryLimitBytes") != null) {
        try {
            long memoryLimitBytes = Long.parseLong(extendedMachine.getAttributes().get("memoryLimitBytes"));
            checkArgument(memoryLimitBytes > 0, "Value of attribute 'memoryLimitBytes' of machine '%s' in environment '%s' is illegal", machineName, envName);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment '%s' is illegal", machineName, envName));
        }
    }
    if (extendedMachine.getServers() != null) {
        extendedMachine.getServers().entrySet().forEach(serverEntry -> {
            String serverName = serverEntry.getKey();
            ServerConf2 server = serverEntry.getValue();
            checkArgument(server.getPort() != null && SERVER_PORT.matcher(server.getPort()).matches(), "Machine '%s' in environment '%s' contains server conf '%s' with invalid port '%s'", machineName, envName, serverName, server.getPort());
            checkArgument(server.getProtocol() == null || SERVER_PROTOCOL.matcher(server.getProtocol()).matches(), "Machine '%s' in environment '%s' contains server conf '%s' with invalid protocol '%s'", machineName, envName, serverName, server.getProtocol());
        });
    }
    if (extendedMachine.getAgents() != null) {
        for (String agent : extendedMachine.getAgents()) {
            checkArgument(!isNullOrEmpty(agent), "Machine '%s' in environment '%s' contains invalid agent '%s'", machineName, envName, agent);
        }
    }
}
Also used : ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2)

Example 3 with ServerConf2

use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStartNonDockerMachine.

@Test
public void shouldBeAbleToStartNonDockerMachine() throws Exception {
    // given
    ServerConf2 serverConf2 = mock(ServerConf2.class);
    when(serverConf2.getPort()).thenReturn("1111/tcp");
    when(serverConf2.getProtocol()).thenReturn("http");
    when(serverConf2.getProperties()).thenReturn(singletonMap("path", "some path"));
    when(agent.getServers()).thenAnswer(invocation -> singletonMap("ssh", serverConf2));
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineInstanceProviders.getProvider("anotherType")).thenReturn(instanceProvider);
    doReturn(newMachine).when(instanceProvider).createInstance(any(Machine.class), any(LineConsumer.class));
    MachineConfigImpl config = MachineConfigImpl.builder().fromConfig(createConfig(false)).setType("anotherType").build();
    // when
    Instance actualInstance = engine.startMachine(workspaceId, config, singletonList("agent"));
    // then
    assertEquals(actualInstance, newMachine);
    ArgumentCaptor<Machine> argumentCaptor = ArgumentCaptor.forClass(Machine.class);
    verify(instanceProvider).createInstance(argumentCaptor.capture(), any(LineConsumer.class));
    MachineConfigImpl newConfig = new MachineConfigImpl(config);
    newConfig.setServers(singletonList(new ServerConfImpl("ssh", "1111/tcp", "http", "some path")));
    assertEquals(argumentCaptor.getValue().getConfig(), newConfig);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) Matchers.anyString(org.mockito.Matchers.anyString) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) Test(org.testng.annotations.Test)

Example 4 with ServerConf2

use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.

the class AgentConfigApplierTest method shouldAddExposedPorts.

@Test
public void shouldAddExposedPorts() throws Exception {
    final ServerConf2 serverConf1 = mock(ServerConf2.class);
    final ServerConf2 serverConf2 = mock(ServerConf2.class);
    when(serverConf1.getPort()).thenReturn("1111/udp");
    when(serverConf2.getPort()).thenReturn("2222/tcp");
    when(sorter.sort(any())).thenReturn(asList(AgentKeyImpl.parse("agent1"), AgentKeyImpl.parse("agent2"), AgentKeyImpl.parse("agent3")));
    when(agent1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
    when(agent2.getServers()).thenAnswer(invocation -> singletonMap("b", serverConf2));
    when(agent3.getServers()).thenReturn(emptyMap());
    CheServiceImpl service = new CheServiceImpl();
    agentConfigApplier.apply(new ExtendedMachineImpl(asList("agent1", "agent2", "agent3"), emptyMap(), emptyMap()), service);
    List<String> exposedPorts = service.getExpose();
    assertTrue(exposedPorts.contains("1111/udp"));
    assertTrue(exposedPorts.contains("2222/tcp"));
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) Test(org.testng.annotations.Test)

Example 5 with ServerConf2

use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.

the class AgentConfigApplier method addLabels.

private void addLabels(CheServiceImpl service, Map<String, ? extends ServerConf2> servers) {
    for (Map.Entry<String, ? extends ServerConf2> entry : servers.entrySet()) {
        String ref = entry.getKey();
        ServerConf2 conf = entry.getValue();
        service.getLabels().put("che:server:" + conf.getPort() + ":protocol", conf.getProtocol());
        service.getLabels().put("che:server:" + conf.getPort() + ":ref", ref);
        String path = conf.getProperties().get("path");
        if (!isNullOrEmpty(path)) {
            service.getLabels().put("che:server:" + conf.getPort() + ":path", path);
        }
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2)

Aggregations

ServerConf2 (org.eclipse.che.api.core.model.workspace.ServerConf2)6 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)2 ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)2 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AgentException (org.eclipse.che.api.agent.server.exception.AgentException)1 AgentImpl (org.eclipse.che.api.agent.shared.model.impl.AgentImpl)1 ServerException (org.eclipse.che.api.core.ServerException)1 Machine (org.eclipse.che.api.core.model.machine.Machine)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)1 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)1 Instance (org.eclipse.che.api.machine.server.spi.Instance)1 Matchers.anyString (org.mockito.Matchers.anyString)1