Search in sources :

Example 1 with ServerImpl

use of org.eclipse.che.api.machine.server.model.impl.ServerImpl in project che by eclipse.

the class ServerEvaluationStrategyTest method shouldAddRefUrlProtocolPathToServerFromMachineConfig.

@Test
public void shouldAddRefUrlProtocolPathToServerFromMachineConfig() throws Exception {
    // given
    prepareStrategyAndContainerInfoMocks();
    serverConfs.put("8080/tcp", new ServerConfImpl("myserv1", "8080/tcp", "http", null));
    serverConfs.put("9090/udp", new ServerConfImpl("myserv2", "9090/udp", "dhcp", "/some/path"));
    final HashMap<String, ServerImpl> expectedServers = new HashMap<>();
    expectedServers.put("8080/tcp", new ServerImpl("myserv1", "http", DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100")));
    expectedServers.put("9090/udp", new ServerImpl("myserv2", "dhcp", DEFAULT_HOSTNAME + ":32101", "dhcp://" + DEFAULT_HOSTNAME + ":32101/some/path", new ServerPropertiesImpl("/some/path", DEFAULT_HOSTNAME + ":32101", "dhcp://" + DEFAULT_HOSTNAME + ":32101/some/path")));
    // when
    final Map<String, ServerImpl> servers = strategy.getServers(containerInfo, DEFAULT_HOSTNAME, serverConfs);
    // then
    assertEquals(servers, expectedServers);
}
Also used : ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) HashMap(java.util.HashMap) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) Test(org.testng.annotations.Test)

Example 2 with ServerImpl

use of org.eclipse.che.api.machine.server.model.impl.ServerImpl in project che by eclipse.

the class ServerEvaluationStrategyTest method shouldAllowToUsePortFromDockerLabelsWithoutTransportProtocol.

@Test
public void shouldAllowToUsePortFromDockerLabelsWithoutTransportProtocol() throws Exception {
    // given
    prepareStrategyAndContainerInfoMocks();
    labels.put(String.format(SERVER_CONF_LABEL_REF_KEY, "8080"), "myserv1");
    labels.put(String.format(SERVER_CONF_LABEL_PROTOCOL_KEY, "8080"), "http");
    labels.put(String.format(SERVER_CONF_LABEL_REF_KEY, "9090/udp"), "myserv1-tftp");
    labels.put(String.format(SERVER_CONF_LABEL_PROTOCOL_KEY, "9090/udp"), "tftp");
    final HashMap<String, ServerImpl> expectedServers = new HashMap<>();
    expectedServers.put("8080/tcp", new ServerImpl("myserv1", "http", DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100")));
    expectedServers.put("9090/udp", new ServerImpl("myserv1-tftp", "tftp", DEFAULT_HOSTNAME + ":32101", "tftp://" + DEFAULT_HOSTNAME + ":32101", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32101", "tftp://" + DEFAULT_HOSTNAME + ":32101")));
    // when
    final Map<String, ServerImpl> servers = strategy.getServers(containerInfo, DEFAULT_HOSTNAME, serverConfs);
    // then
    assertEquals(servers, expectedServers);
}
Also used : ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) HashMap(java.util.HashMap) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl) Test(org.testng.annotations.Test)

Example 3 with ServerImpl

use of org.eclipse.che.api.machine.server.model.impl.ServerImpl 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 ServerImpl

use of org.eclipse.che.api.machine.server.model.impl.ServerImpl in project che by eclipse.

the class SshMachineInstance method serverConfToServer.

private ServerImpl serverConfToServer(ServerConf serverConf, UriBuilder uriBuilder) {
    String port = serverConf.getPort().split("/")[0];
    uriBuilder.port(Integer.parseInt(port));
    if (serverConf.getPath() != null) {
        uriBuilder.path(serverConf.getPath());
    }
    URI serverUri = uriBuilder.build();
    return new ServerImpl(serverConf.getRef(), serverConf.getProtocol(), serverUri.getHost() + ":" + serverUri.getPort(), serverConf.getProtocol() != null ? serverUri.toString() : null, null);
}
Also used : ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) URI(java.net.URI)

Example 5 with ServerImpl

use of org.eclipse.che.api.machine.server.model.impl.ServerImpl in project che by eclipse.

the class LocalDockerServerEvaluationStrategyTest method getExpectedServers.

private Map<String, ServerImpl> getExpectedServers(String externalAddress, String internalAddress, boolean useExposedPorts) {
    String port1;
    String port2;
    if (useExposedPorts) {
        port1 = ":4301";
        port2 = ":4305";
    } else {
        port1 = ":32100";
        port2 = ":32103";
    }
    Map<String, ServerImpl> expectedServers = new HashMap<>();
    expectedServers.put("4301/tcp", new ServerImpl("sysServer1-tcp", "http", externalAddress + ":32100", "http://" + externalAddress + ":32100/some/path1", new ServerPropertiesImpl("/some/path1", internalAddress + port1, "http://" + internalAddress + port1 + "/some/path1")));
    expectedServers.put("4305/udp", new ServerImpl("devSysServer1-udp", null, externalAddress + ":32103", null, new ServerPropertiesImpl("some/path4", internalAddress + port2, null)));
    return expectedServers;
}
Also used : ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) HashMap(java.util.HashMap) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl)

Aggregations

ServerImpl (org.eclipse.che.api.machine.server.model.impl.ServerImpl)15 ServerPropertiesImpl (org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl)11 HashMap (java.util.HashMap)10 Test (org.testng.annotations.Test)10 ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)7 HashSet (java.util.HashSet)3 ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)3 Matchers.anyString (org.mockito.Matchers.anyString)3 List (java.util.List)2 MachineRuntimeInfoImpl (org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl)2 Response (com.jayway.restassured.response.Response)1 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 ServerProperties (org.eclipse.che.api.core.model.machine.ServerProperties)1 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)1 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)1 MachineLimitsImpl (org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)1 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)1