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);
}
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));
}
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);
}
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");
}
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);
}
Aggregations