Search in sources :

Example 31 with ServerConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.

the class JwtProxySecureServerExposerTest method shouldUseMultiHostStrategyForSubdomainRequiringServers.

@Test
public void shouldUseMultiHostStrategyForSubdomainRequiringServers() throws Exception {
    // given
    ServicePort machineServicePort = new ServicePort();
    machineServicePort.setTargetPort(new IntOrString(8080));
    machineServicePort.setProtocol("TCP");
    Map<String, ServerConfig> servers = ImmutableMap.of("server1", new ServerConfigImpl("8080/tcp", "http", "/api", ImmutableMap.of("secure", "true")), "server2", new ServerConfigImpl("8080/tcp", "ws", "/connect", ImmutableMap.of("secure", "true")));
    Map<String, ServerConfig> conformingServers = Collections.singletonMap("server1", servers.get("server1"));
    Map<String, ServerConfig> subdomainServers = Collections.singletonMap("server2", servers.get("server2"));
    ServicePort jwtProxyServicePort = new ServicePort();
    doReturn(jwtProxyServicePort).when(jwtProxyProvisioner).expose(any(), any(), anyString(), anyString(), any(), anyString(), anyBoolean(), any());
    when(jwtProxyProvisioner.getServiceName()).thenReturn(JWT_PROXY_SERVICE_NAME);
    when(externalServerExposer.getStrategyConformingServers(eq(servers))).thenReturn(conformingServers);
    when(externalServerExposer.getServersRequiringSubdomain(eq(servers))).thenReturn(subdomainServers);
    // when
    secureServerExposer.expose(k8sEnv, null, MACHINE_NAME, MACHINE_SERVICE_NAME, null, machineServicePort, servers);
    // then
    verify(jwtProxyProvisioner).expose(eq(k8sEnv), any(), anyString(), eq(MACHINE_SERVICE_NAME), eq(machineServicePort), eq("TCP"), eq(false), any());
    verify(jwtProxyProvisioner).expose(eq(k8sEnv), any(), anyString(), eq(MACHINE_SERVICE_NAME), eq(machineServicePort), eq("TCP"), eq(true), any());
    verify(externalServerExposer).expose(eq(k8sEnv), eq(MACHINE_NAME), eq(JWT_PROXY_SERVICE_NAME), isNull(), eq(jwtProxyServicePort), eq(conformingServers));
    verify(externalServerExposer).expose(eq(k8sEnv), eq(MACHINE_NAME), eq(JWT_PROXY_SERVICE_NAME), isNull(), eq(jwtProxyServicePort), eq(subdomainServers));
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 32 with ServerConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.

the class JwtProxySecureServerExposerTest method shouldExposeSecureServersWithNewJwtProxyServicePort.

@Test
public void shouldExposeSecureServersWithNewJwtProxyServicePort() throws Exception {
    // given
    ServicePort machineServicePort = new ServicePort();
    machineServicePort.setTargetPort(new IntOrString(8080));
    machineServicePort.setProtocol("TCP");
    Map<String, ServerConfig> servers = ImmutableMap.of("server1", new ServerConfigImpl("8080/tcp", "http", "/api", ImmutableMap.of("secure", "true")), "server2", new ServerConfigImpl("8080/tcp", "ws", "/connect", ImmutableMap.of("secure", "true")));
    ServicePort jwtProxyServicePort = new ServicePort();
    doReturn(jwtProxyServicePort).when(jwtProxyProvisioner).expose(any(), any(), anyString(), anyString(), any(), anyString(), anyBoolean(), any());
    when(jwtProxyProvisioner.getServiceName()).thenReturn(JWT_PROXY_SERVICE_NAME);
    when(externalServerExposer.getStrategyConformingServers(eq(servers))).thenReturn(servers);
    // when
    secureServerExposer.expose(k8sEnv, null, MACHINE_NAME, MACHINE_SERVICE_NAME, null, machineServicePort, servers);
    // then
    verify(jwtProxyProvisioner).expose(eq(k8sEnv), any(), anyString(), eq(MACHINE_SERVICE_NAME), eq(machineServicePort), eq("TCP"), eq(false), any());
    verify(externalServerExposer).expose(eq(k8sEnv), eq(MACHINE_NAME), eq(JWT_PROXY_SERVICE_NAME), isNull(), eq(jwtProxyServicePort), eq(servers));
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 33 with ServerConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.

the class KubernetesServerExposerTest method shouldAddAdditionalContainerPortWhenThereIsTheSameButWithDifferentProtocol.

@Test
public void shouldAddAdditionalContainerPortWhenThereIsTheSameButWithDifferentProtocol() throws Exception {
    // given
    ServerConfigImpl udpServerConfig = new ServerConfigImpl("8080/udp", "udp", "/api", ATTRIBUTES_MAP);
    Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("server", udpServerConfig);
    container.setPorts(new ArrayList<>(singletonList(new ContainerPortBuilder().withName("port-8080").withContainerPort(8080).withProtocol("TCP").build())));
    // when
    serverExposer.expose(serversToExpose);
    // then
    assertEquals(container.getPorts().size(), 2);
    assertEquals(container.getPorts().get(1).getContainerPort(), new Integer(8080));
    assertEquals(container.getPorts().get(1).getProtocol(), "UDP");
    assertThatExternalServerIsExposed(MACHINE_NAME, "udp", 8080, "server", new ServerConfigImpl(udpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
Also used : ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Example 34 with ServerConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.

the class KubernetesServerExposerTest method shouldExposeContainerPortAndCreateServiceAndForServerWhenTwoServersHasTheSamePort.

@Test
public void shouldExposeContainerPortAndCreateServiceAndForServerWhenTwoServersHasTheSamePort() throws Exception {
    // given
    ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
    ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
    Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
    // when
    serverExposer.expose(serversToExpose);
    // then
    assertEquals(kubernetesEnvironment.getServices().size(), 1);
    assertThatExternalServersAreExposed(MACHINE_NAME, "tcp", 8080, ImmutableMap.of("http-server", new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP), "ws-server", new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP)));
}
Also used : ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Example 35 with ServerConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.

the class KubernetesServerExposerTest method shouldExposeTcpContainerPortsAndCreateServiceAndForServerWhenProtocolIsMissedInPort.

@Test
public void shouldExposeTcpContainerPortsAndCreateServiceAndForServerWhenProtocolIsMissedInPort() throws Exception {
    // given
    ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080", "http", "/api", ATTRIBUTES_MAP);
    Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("http-server", httpServerConfig);
    // when
    serverExposer.expose(serversToExpose);
    // then
    assertEquals(kubernetesEnvironment.getServices().size(), 1);
    assertThatExternalServerIsExposed(MACHINE_NAME, "TCP", 8080, "http-server", new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
Also used : ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Aggregations

ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)159 Test (org.testng.annotations.Test)130 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)58 ServerConfig (org.eclipse.che.api.core.model.workspace.config.ServerConfig)38 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)34 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)32 Route (io.fabric8.openshift.api.model.Route)22 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)22 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)21 HashMap (java.util.HashMap)21 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)17 Service (io.fabric8.kubernetes.api.model.Service)16 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)16 RouteServerResolver (org.eclipse.che.workspace.infrastructure.openshift.server.RouteServerResolver)16 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)14 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)14 IngressServerResolver (org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver)14 ServerResolver (org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver)14 RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)12 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)10