Search in sources :

Example 6 with ServerConfImpl

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

the class DefaultServerEvaluationStrategyTest method setUp.

@BeforeMethod
public void setUp() {
    serverConfs = new HashMap<>();
    serverConfs.put("4301/tcp", new ServerConfImpl("sysServer1-tcp", "4301/tcp", "http", "/some/path1"));
    serverConfs.put("4305/udp", new ServerConfImpl("devSysServer1-udp", "4305/udp", null, "some/path4"));
    Map<String, List<PortBinding>> ports = new HashMap<>();
    ports.put("4301/tcp", Collections.singletonList(new PortBinding().withHostIp(ALL_IP_ADDRESS).withHostPort("32100")));
    ports.put("4305/udp", Collections.singletonList(new PortBinding().withHostIp(ALL_IP_ADDRESS).withHostPort("32103")));
    when(containerInfo.getNetworkSettings()).thenReturn(networkSettings);
    when(networkSettings.getPorts()).thenReturn(ports);
    when(containerInfo.getConfig()).thenReturn(containerConfig);
    when(containerConfig.getLabels()).thenReturn(Collections.emptyMap());
}
Also used : PortBinding(org.eclipse.che.plugin.docker.client.json.PortBinding) HashMap(java.util.HashMap) List(java.util.List) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ServerConfImpl

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

Example 8 with ServerConfImpl

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

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

the class LocalDockerServerEvaluationStrategyTest method setUp.

@BeforeMethod
public void setUp() {
    serverConfs = new HashMap<>();
    serverConfs.put("4301/tcp", new ServerConfImpl("sysServer1-tcp", "4301/tcp", "http", "/some/path1"));
    serverConfs.put("4305/udp", new ServerConfImpl("devSysServer1-udp", "4305/udp", null, "some/path4"));
    ports = new HashMap<>();
    ports.put("4301/tcp", Collections.singletonList(new PortBinding().withHostIp(ALL_IP_ADDRESS).withHostPort("32100")));
    ports.put("4305/udp", Collections.singletonList(new PortBinding().withHostIp(ALL_IP_ADDRESS).withHostPort("32103")));
    when(containerInfo.getNetworkSettings()).thenReturn(networkSettings);
    when(networkSettings.getGateway()).thenReturn(CONTAINERINFO_GATEWAY);
    when(networkSettings.getIpAddress()).thenReturn(CONTAINERINFO_IP_ADDRESS);
    when(networkSettings.getPorts()).thenReturn(ports);
    when(containerInfo.getConfig()).thenReturn(containerConfig);
    when(containerConfig.getLabels()).thenReturn(Collections.emptyMap());
}
Also used : PortBinding(org.eclipse.che.plugin.docker.client.json.PortBinding) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with ServerConfImpl

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

the class ServerEvaluationStrategyTest method shouldPreferMachineConfOverDockerLabels.

@Test
public void shouldPreferMachineConfOverDockerLabels() throws Exception {
    // given
    prepareStrategyAndContainerInfoMocks();
    labels.put(String.format(SERVER_CONF_LABEL_REF_KEY, "8080/tcp"), "myserv1label");
    labels.put(String.format(SERVER_CONF_LABEL_PROTOCOL_KEY, "8080/tcp"), "https");
    labels.put(String.format(SERVER_CONF_LABEL_REF_KEY, "9090/udp"), "myserv2label");
    labels.put(String.format(SERVER_CONF_LABEL_PROTOCOL_KEY, "9090/udp"), "dhcp");
    labels.put(String.format(SERVER_CONF_LABEL_PATH_KEY, "9090/udp"), "/path");
    serverConfs.put("8080/tcp", new ServerConfImpl("myserv1conf", "8080/tcp", "http", null));
    final HashMap<String, ServerImpl> expectedServers = new HashMap<>();
    expectedServers.put("8080/tcp", new ServerImpl("myserv1conf", "http", DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100")));
    expectedServers.put("9090/udp", new ServerImpl("myserv2label", "dhcp", DEFAULT_HOSTNAME + ":32101", "dhcp://" + DEFAULT_HOSTNAME + ":32101/path", new ServerPropertiesImpl("/path", DEFAULT_HOSTNAME + ":32101", "dhcp://" + DEFAULT_HOSTNAME + ":32101/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)

Aggregations

ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)12 ServerImpl (org.eclipse.che.api.machine.server.model.impl.ServerImpl)7 Test (org.testng.annotations.Test)7 HashMap (java.util.HashMap)5 ServerPropertiesImpl (org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl)5 Matchers.anyString (org.mockito.Matchers.anyString)3 HashSet (java.util.HashSet)2 List (java.util.List)2 ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)2 ServerConf2 (org.eclipse.che.api.core.model.workspace.ServerConf2)2 PortBinding (org.eclipse.che.plugin.docker.client.json.PortBinding)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)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 ServerProperties (org.eclipse.che.api.core.model.machine.ServerProperties)1