Search in sources :

Example 21 with ServerConfigImpl

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

the class IngressServerResolverTest method testResolvingServersWhenThereIsMatchedIngressForTheSpecifiedMachine.

@Test
public void testResolvingServersWhenThereIsMatchedIngressForTheSpecifiedMachine() {
    Ingress ingress = createIngress("matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "/api/", ATTRIBUTES_MAP)));
    ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), emptyList(), singletonList(ingress));
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    assertEquals(resolved.size(), 1);
    assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/api/").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, INGRESS_PATH_PREFIX + "/")));
}
Also used : IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) Test(org.testng.annotations.Test)

Example 22 with ServerConfigImpl

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

the class IngressServerResolverTest method testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsRelative.

@Test
public void testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsRelative() {
    Ingress ingress = createIngress("matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "api", ATTRIBUTES_MAP)));
    ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), emptyList(), singletonList(ingress));
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    assertEquals(resolved.size(), 1);
    assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/api/").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, INGRESS_PATH_PREFIX + "/")));
}
Also used : IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) Test(org.testng.annotations.Test)

Example 23 with ServerConfigImpl

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

the class IngressServerResolverTest method testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsEmpty.

@Test
public void testResolvingServersWhenThereIsMatchedIngressForMachineAndServerPathIsEmpty() {
    Ingress ingress = createIngress("matched", "machine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "", ATTRIBUTES_MAP)));
    ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), emptyList(), singletonList(ingress));
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    assertEquals(resolved.size(), 1);
    assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://" + INGRESS_IP + INGRESS_RULE_PATH_PREFIX + "/").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, INGRESS_PATH_PREFIX + "/")));
}
Also used : IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) Test(org.testng.annotations.Test)

Example 24 with ServerConfigImpl

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

the class IngressServerResolverTest method testResolvingInternalServers.

@Test
public void testResolvingInternalServers() {
    Service service = createService("service11", "machine", CONTAINER_PORT, singletonMap("http-server", new ServerConfigImpl("3054", "http", "api", ATTRIBUTES_MAP)));
    ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), singletonList(service), emptyList());
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    assertEquals(resolved.size(), 1);
    assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://service11:3054/api").withStatus(ServerStatus.UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, "/")));
}
Also used : IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Service(io.fabric8.kubernetes.api.model.Service) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) IngressServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver) Test(org.testng.annotations.Test)

Example 25 with ServerConfigImpl

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

the class DefaultHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.

@SuppressWarnings("SameParameterValue")
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, ServicePort servicePort, ServerConfigImpl expected) {
    // ensure that required ingress is created
    for (Ingress ingress : kubernetesEnvironment.getIngresses().values()) {
        IngressRule ingressRule = ingress.getSpec().getRules().get(0);
        IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
        if (serviceName.equals(backend.getService().getName())) {
            assertEquals(backend.getService().getPort().getName(), servicePort.getName());
            Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
            Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
            ServerConfig serverConfig = servers.get(serverNameRegex);
            if (serverConfig == null) {
                // ok, this ingress is not for this particular server
                continue;
            }
            assertEquals(serverConfig, expected);
            assertEquals(ingressAnnotations.machineName(), machineName);
            return;
        }
    }
    Assert.fail(format("Could not find an ingress for machine '%s' and service '%s'", machineName, serviceName));
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

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