Search in sources :

Example 41 with ServerConfigImpl

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

the class KubernetesServerExposerTest method assertThatInternalServerIsExposed.

@SuppressWarnings("SameParameterValue")
private void assertThatInternalServerIsExposed(String machineName, String serverNameRegex, String portProtocol, Integer port, ServerConfigImpl expected) {
    assertThatContainerPortIsExposed(portProtocol, port);
    // ensure that service is created
    Service service = findContainerRelatedService();
    assertNotNull(service);
    // ensure that required service port is exposed
    assertThatServicePortIsExposed(port, service);
    Annotations.Deserializer serviceAnnotations = Annotations.newDeserializer(service.getMetadata().getAnnotations());
    assertEquals(serviceAnnotations.machineName(), machineName);
    Map<String, ServerConfigImpl> servers = serviceAnnotations.servers();
    ServerConfig serverConfig = servers.get(serverNameRegex);
    assertEquals(serverConfig, expected);
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) Service(io.fabric8.kubernetes.api.model.Service) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 42 with ServerConfigImpl

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

the class MultiHostExternalServiceExposureStrategyTest method shouldCreateIngressForServer.

@Test
public void shouldCreateIngressForServer() {
    // given
    ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
    IntOrString targetPort = new IntOrString(8080);
    ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(targetPort).build();
    Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig);
    // when
    externalServerExposer.expose(kubernetesEnvironment, MACHINE_NAME, SERVICE_NAME, null, servicePort, serversToExpose);
    // then
    assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "http-server", "tcp", 8080, servicePort, new ServerConfigImpl(httpServerConfig).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)

Example 43 with ServerConfigImpl

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

the class TraefikGatewayRouteConfigGeneratorTest method testGenerateGatewayConfigWithNonDefaultDomain.

@Test
public void testGenerateGatewayConfigWithNonDefaultDomain() throws InfrastructureException {
    String expectedConfig = "http:\n" + "  routers:\n" + "    external-server-1:\n" + "      rule: \"PathPrefix(`/blabol-cesta`)\"\n" + "      service: \"external-server-1\"\n" + "      middlewares:\n" + "      - \"external-server-1\"\n" + "      priority: 100\n" + "  services:\n" + "    external-server-1:\n" + "      loadBalancer:\n" + "        servers:\n" + "        - url: \"http://service-url.che-namespace.svc.myorg.internal:1234\"\n" + "  middlewares:\n" + "    external-server-1:\n" + "      stripPrefix:\n" + "        prefixes:\n" + "        - \"/blabol-cesta\"";
    ServerConfigImpl serverConfig = new ServerConfigImpl("123", "https", "/", ImmutableMap.of(SERVICE_NAME_ATTRIBUTE, "service-url", SERVICE_PORT_ATTRIBUTE, "1234", ServerConfig.ENDPOINT_ORIGIN, "/blabol-cesta"));
    Map<String, String> annotations = new Annotations.Serializer().server("s1", serverConfig).annotations();
    ConfigMap routeConfig = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotations).endMetadata().build();
    gatewayConfigGeneratorNonDefaultDomain.addRouteConfig("external-server-1", routeConfig);
    Map<String, String> generatedConfig = gatewayConfigGeneratorNonDefaultDomain.generate("che-namespace");
    assertTrue(generatedConfig.containsKey("external-server-1.yml"));
    assertEquals(generatedConfig.get("external-server-1.yml"), expectedConfig);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 44 with ServerConfigImpl

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

the class TraefikGatewayRouteConfigGeneratorTest method failWhenMultipleServersInConfigmapAnnotations.

@Test(expectedExceptions = InfrastructureException.class)
public void failWhenMultipleServersInConfigmapAnnotations() throws InfrastructureException {
    ServerConfigImpl serverConfig = new ServerConfigImpl("123", "https", "/", ImmutableMap.of(SERVICE_NAME_ATTRIBUTE, "service-url", SERVICE_PORT_ATTRIBUTE, "1234", ServerConfig.ENDPOINT_ORIGIN, "/blabol-cesta"));
    Map<String, String> annotations = new Annotations.Serializer().server("s1", serverConfig).server("s2", serverConfig).annotations();
    ConfigMap routeConfig = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotations).endMetadata().build();
    gatewayConfigGenerator.addRouteConfig("c1", routeConfig);
    gatewayConfigGenerator.generate("che-namespace");
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 45 with ServerConfigImpl

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

the class GatewayRouterProvisionerTest method testProvision.

@Test
public void testProvision() throws InfrastructureException {
    // given
    Map<String, String> annotationsWith2Servers = new Annotations.Serializer().server("s1", serverConfig).annotations();
    ConfigMap gatewayRouteConfigMap = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotationsWith2Servers).endMetadata().build();
    when(env.getConfigMaps()).thenReturn(Collections.singletonMap("route", gatewayRouteConfigMap));
    Map<String, String> expectedData = Collections.singletonMap("data.yml", "this is for sure generated configuration");
    when(gatewayRouteConfigGenerator.generate(NAMESPACE)).thenReturn(expectedData);
    // when
    gatewayRouterProvisioner.provision(env, identity);
    // then
    verify(configGeneratorFactory).create();
    verify(gatewayRouteConfigGenerator).addRouteConfig("route", gatewayRouteConfigMap);
    verify(gatewayRouteConfigGenerator).generate(NAMESPACE);
    Map<String, ServerConfigImpl> serverConfigsAfterProvisioning = new Annotations.Deserializer(gatewayRouteConfigMap.getMetadata().getAnnotations()).servers();
    assertEquals(serverConfigsAfterProvisioning.size(), 1);
    ServerConfigImpl server = serverConfigsAfterProvisioning.get(serverConfigsAfterProvisioning.keySet().iterator().next());
    // verify that provisioner removes the internal attributes
    assertFalse(server.getAttributes().containsKey(SERVICE_NAME_ATTRIBUTE));
    assertFalse(server.getAttributes().containsKey(SERVICE_PORT_ATTRIBUTE));
    // verify that provisioner included the data info configmap
    Map<String, String> actualData = gatewayRouteConfigMap.getData();
    assertEquals(actualData, expectedData);
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) 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