Search in sources :

Example 1 with ServerConf

use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.

the class CheEnvironmentEngine method machineConfigToService.

private CheServiceImpl machineConfigToService(MachineConfig machineConfig) throws ServerException {
    CheServiceImpl service = new CheServiceImpl();
    service.setMemLimit(machineConfig.getLimits().getRam() * 1024L * 1024L);
    service.setEnvironment(machineConfig.getEnvVariables());
    if ("image".equals(machineConfig.getSource().getType())) {
        service.setImage(machineConfig.getSource().getLocation());
    } else {
        if (machineConfig.getSource().getContent() != null) {
            throw new ServerException("Additional machine creation from dockerfile content is not supported anymore. " + "Please use dockerfile location instead");
        } else {
            service.setBuild(new CheServiceBuildContextImpl(machineConfig.getSource().getLocation(), null, null, null));
        }
    }
    List<? extends ServerConf> servers = machineConfig.getServers();
    if (servers != null) {
        List<String> expose = new ArrayList<>();
        for (ServerConf server : servers) {
            expose.add(server.getPort());
        }
        service.setExpose(expose);
    }
    return service;
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 2 with ServerConf

use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.

the class CheEnvironmentValidator method validateMachine.

public void validateMachine(MachineConfig machineCfg) throws IllegalArgumentException {
    String machineName = machineCfg.getName();
    checkArgument(!isNullOrEmpty(machineName), "Machine name is null or empty");
    checkArgument(MACHINE_NAME_PATTERN.matcher(machineName).matches(), "Machine name '%s' is invalid", machineName);
    checkNotNull(machineCfg.getSource(), "Machine '%s' doesn't have source", machineName);
    checkArgument(machineCfg.getSource().getContent() != null || machineCfg.getSource().getLocation() != null, "Source of machine '%s' must contain location or content", machineName);
    checkArgument(machineCfg.getSource().getContent() == null || machineCfg.getSource().getLocation() == null, "Source of machine '%s' contains mutually exclusive fields location and content", machineName);
    checkArgument(machineInstanceProviders.hasProvider(machineCfg.getType()), "Type '%s' of machine '%s' is not supported. Supported values are: %s.", machineCfg.getType(), machineName, Joiner.on(", ").join(machineInstanceProviders.getProviderTypes()));
    if (machineCfg.getSource().getType().equals("dockerfile") && machineCfg.getSource().getLocation() != null) {
        try {
            final String protocol = new URL(machineCfg.getSource().getLocation()).getProtocol();
            checkArgument(protocol.equals("http") || protocol.equals("https"), "Machine '%s' has invalid source location protocol: %s", machineName, machineCfg.getSource().getLocation());
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException(format("Machine '%s' has invalid source location: '%s'", machineName, machineCfg.getSource().getLocation()));
        }
    }
    for (ServerConf serverConf : machineCfg.getServers()) {
        checkArgument(serverConf.getPort() != null && SERVER_PORT.matcher(serverConf.getPort()).matches(), "Machine '%s' contains server conf with invalid port '%s'", machineName, serverConf.getPort());
        checkArgument(serverConf.getProtocol() == null || SERVER_PROTOCOL.matcher(serverConf.getProtocol()).matches(), "Machine '%s' contains server conf with invalid protocol '%s'", machineName, serverConf.getProtocol());
    }
    for (Map.Entry<String, String> envVariable : machineCfg.getEnvVariables().entrySet()) {
        checkArgument(!isNullOrEmpty(envVariable.getKey()), "Machine '%s' contains environment variable with null or empty name", machineName);
        checkNotNull(envVariable.getValue(), "Machine '%s' contains environment variable '%s' with null value", machineName, envVariable.getKey());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) Map(java.util.Map) URL(java.net.URL)

Example 3 with ServerConf

use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.

the class SshMachineInstance method getRuntime.

public MachineRuntimeInfoImpl getRuntime() {
    // lazy initialization
    if (machineRuntime == null) {
        synchronized (this) {
            if (machineRuntime == null) {
                UriBuilder uriBuilder = UriBuilder.fromUri("http://" + sshClient.getHost());
                final Map<String, ServerImpl> servers = new HashMap<>();
                for (ServerConf serverConf : machinesServers) {
                    servers.put(serverConf.getPort(), serverConfToServer(serverConf, uriBuilder.clone()));
                }
                machineRuntime = new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), servers);
            }
        }
    // todo get env from client
    }
    return machineRuntime;
}
Also used : MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 4 with ServerConf

use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.

the class DockerInstanceRuntimeInfoTest method shouldPassCommonServerConfigsOnGetServersForNonDevMachine.

@Test
public void shouldPassCommonServerConfigsOnGetServersForNonDevMachine() throws Exception {
    // given
    Set<ServerConf> commonSystemServersConfigs = new HashSet<>();
    commonSystemServersConfigs.add(new ServerConfImpl("sysServer1-tcp", "4301/tcp", "http", "/some/path"));
    commonSystemServersConfigs.add(new ServerConfImpl("sysServer2-udp", "4302/udp", "dhcp", null));
    commonSystemServersConfigs.add(new ServerConfImpl("sysServer1-udp", "4301/udp", null, "some/path"));
    Set<ServerConf> devSystemServersConfigs = singleton(new ServerConfImpl("devSysServer1-tcp", "4305/tcp", "http", null));
    List<ServerConf> serversConfFromMachineConf = singletonList(new ServerConfImpl("machineConfServer1-tcp", "4306/tcp", "http", null));
    when(machineConfig.getServers()).thenAnswer(invocation -> serversConfFromMachineConf);
    when(machineConfig.isDev()).thenReturn(false);
    runtimeInfo = new DockerInstanceRuntimeInfo(containerInfo, machineConfig, DEFAULT_HOSTNAME, provider, devSystemServersConfigs, commonSystemServersConfigs);
    // when
    Map<String, ServerImpl> servers = runtimeInfo.getServers();
    // then
    assertEquals(servers, serversMap);
    verify(serverEvaluationStrategy).getServers(eq(containerInfo), eq(DEFAULT_HOSTNAME), serversCaptor.capture());
    assertEquals(serversCaptor.getValue(), serversToMap(commonSystemServersConfigs, serversConfFromMachineConf));
}
Also used : ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) Matchers.anyString(org.mockito.Matchers.anyString) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with ServerConf

use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.

the class DockerInstanceRuntimeInfoTest method shouldPassCommonAndDevServerConfigsOnGetServersForNonDevMachine.

@Test
public void shouldPassCommonAndDevServerConfigsOnGetServersForNonDevMachine() throws Exception {
    Set<ServerConf> commonSystemServersConfigs = new HashSet<>();
    commonSystemServersConfigs.add(new ServerConfImpl("sysServer1-tcp", "4301/tcp", "http", "/some/path1"));
    commonSystemServersConfigs.add(new ServerConfImpl("sysServer2-udp", "4302/udp", "dhcp", "some/path2"));
    Set<ServerConf> devSystemServersConfigs = new HashSet<>();
    devSystemServersConfigs.add(new ServerConfImpl("devSysServer1-tcp", "4305/tcp", "http", "/some/path3"));
    devSystemServersConfigs.add(new ServerConfImpl("devSysServer1-udp", "4305/udp", null, "some/path4"));
    List<ServerConf> serversConfFromMachineConf = singletonList(new ServerConfImpl("machineConfServer1-tcp", "4306/tcp", "http", null));
    when(machineConfig.getServers()).thenAnswer(invocation -> serversConfFromMachineConf);
    when(machineConfig.isDev()).thenReturn(true);
    runtimeInfo = new DockerInstanceRuntimeInfo(containerInfo, machineConfig, DEFAULT_HOSTNAME, provider, devSystemServersConfigs, commonSystemServersConfigs);
    Map<String, ServerImpl> servers = runtimeInfo.getServers();
    assertEquals(servers, serversMap);
    verify(serverEvaluationStrategy).getServers(eq(containerInfo), eq(DEFAULT_HOSTNAME), serversCaptor.capture());
    assertEquals(serversCaptor.getValue(), serversToMap(commonSystemServersConfigs, devSystemServersConfigs, serversConfFromMachineConf));
}
Also used : ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) Matchers.anyString(org.mockito.Matchers.anyString) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)5 ServerImpl (org.eclipse.che.api.machine.server.model.impl.ServerImpl)3 HashSet (java.util.HashSet)2 ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Test (org.testng.annotations.Test)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 ServerException (org.eclipse.che.api.core.ServerException)1 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)1 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)1 MachineRuntimeInfoImpl (org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl)1