Search in sources :

Example 21 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.

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 22 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.

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 23 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.

the class KubernetesServerExposerTest method testExposeUniqueSecureServersWithOnlyMatchingServers.

@Test
public void testExposeUniqueSecureServersWithOnlyMatchingServers() throws InfrastructureException {
    // https://github.com/eclipse/che/issues/16330
    // given 2 servers which one of them is unique
    ServerConfigImpl theiaSC = new ServerConfigImpl("3100/tcp", "https", null, ImmutableMap.of("internal", "false", "discoverable", "false", "secure", "true", "type", "ide"));
    ServerConfigImpl webviewsSC = new ServerConfigImpl("3100/tcp", "https", null, ImmutableMap.of("internal", "false", "discoverable", "false", "unique", "true", "secure", "true", "type", "webview"));
    Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("theia", theiaSC, "webviews", webviewsSC);
    // when
    serverExposer.expose(serversToExpose);
    // then expose is called twice with only one server each
    ArgumentCaptor<Map<String, ServerConfig>> serversCaptor = ArgumentCaptor.forClass(Map.class);
    verify(secureServerExposer, times(2)).expose(any(), any(), any(), any(), any(), any(), serversCaptor.capture());
    for (Map<String, ServerConfig> captures : serversCaptor.getAllValues()) {
        assertEquals(captures.size(), 1);
    }
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test)

Example 24 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.

the class CombinedSingleHostServerExposerTest method shouldExposeDevfileServersOnSubdomans.

@Test
public void shouldExposeDevfileServersOnSubdomans() {
    // given
    ServerConfig s1 = new ServerConfigImpl("1", "http", "/", emptyMap());
    ServerConfig s2 = new ServerConfigImpl("2", "http", "/", singletonMap(REQUIRE_SUBDOMAIN, "false"));
    ServerConfig s3 = new ServerConfigImpl("3", "http", "/", singletonMap(REQUIRE_SUBDOMAIN, "true"));
    CombinedSingleHostServerExposer<KubernetesEnvironment> serverExposer = new CombinedSingleHostServerExposer<>(subdomainExposer, subpathExposer);
    // when
    serverExposer.expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s1", s1, "s2", s2, "s3", s3));
    // then
    verify(subdomainExposer).expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s3", s3));
    verify(subpathExposer).expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s1", s1, "s2", s2));
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 25 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.

the class DefaultHostExternalServiceExposureStrategyTest method shouldCreateSingleIngressForTwoNonUniqueServersWithTheSamePort.

@Test
public void shouldCreateSingleIngressForTwoNonUniqueServersWithTheSamePort() {
    // given
    ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
    ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
    ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(new IntOrString(8080)).build();
    Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
    // when
    externalServerExposer.expose(kubernetesEnvironment, MACHINE_NAME, SERVICE_NAME, null, servicePort, serversToExpose);
    // then
    assertEquals(kubernetesEnvironment.getIngresses().size(), 1);
    assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "http-server", servicePort, new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
    assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "ws-server", servicePort, new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP));
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Aggregations

ServerConfig (org.eclipse.che.api.core.model.workspace.config.ServerConfig)74 Test (org.testng.annotations.Test)54 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)42 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)30 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)28 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)20 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)18 HashMap (java.util.HashMap)16 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)16 Service (io.fabric8.kubernetes.api.model.Service)14 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)12 Map (java.util.Map)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)8 Container (io.fabric8.kubernetes.api.model.Container)6 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)6 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)6 ArrayList (java.util.ArrayList)6 Collections.singletonMap (java.util.Collections.singletonMap)6 Optional (java.util.Optional)6