Search in sources :

Example 66 with ServerConfig

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

the class KubernetesServerExposer method provisionServicesForDiscoverableServers.

// TODO: this creates discoverable services as an extra services. Service for same {@link
// ServerConfig} is also created later in in {@link #exposeNonSecureServers(Map, Map, Map)} or
// {@link #exposeSecureServers(Map, Map)} as a non-discoverable one. This was added during
// working on adding endpoints for kubernetes/openshift components, to keep behavior consistent.
// However, this logic is probably broken and should be changed.
/**
 * Creates services with defined names for discoverable {@link ServerConfig}s. The name is taken
 * from {@link ServerConfig}'s attributes under {@link ServerConfig#SERVER_NAME_ATTRIBUTE} and
 * must be set, otherwise service won't be created.
 */
private void provisionServicesForDiscoverableServers(Map<String, ? extends ServerConfig> servers) {
    for (String serverName : servers.keySet()) {
        ServerConfig server = servers.get(serverName);
        if (server.getAttributes().containsKey(SERVER_NAME_ATTRIBUTE)) {
            // remove the name from attributes so we don't send it to the client
            String endpointName = server.getAttributes().remove(SERVER_NAME_ATTRIBUTE);
            if (server.isDiscoverable()) {
                Service service = new ServerServiceBuilder().withName(endpointName).withMachineName(machineName).withSelectorEntry(CHE_ORIGINAL_NAME_LABEL, pod.getMetadata().getName()).withPorts(Collections.singletonList(getServicePort(server))).withServers(Collections.singletonMap(serverName, server)).build();
                k8sEnv.getServices().put(service.getMetadata().getName(), service);
            }
        }
    }
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Service(io.fabric8.kubernetes.api.model.Service)

Example 67 with ServerConfig

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

the class OpenShiftExternalServerExposerTest method shouldAddRouteToEnvForExposingSpecifiedServer.

@Test
public void shouldAddRouteToEnvForExposingSpecifiedServer() {
    // given
    OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().build();
    Map<String, ServerConfig> servers = new HashMap<>();
    servers.put("server", new ServerConfigImpl());
    // when
    osExternalServerExposer.expose(osEnv, "machine123", "service123", null, new ServicePort(null, "servicePort", null, null, "TCP", null), servers);
    // then
    assertEquals(1, osEnv.getRoutes().size());
    Route route = osEnv.getRoutes().values().iterator().next();
    assertNotNull(route);
    assertEquals(route.getSpec().getTo().getName(), "service123");
    assertEquals(route.getSpec().getPort().getTargetPort().getStrVal(), "servicePort");
    Deserializer annotations = Annotations.newDeserializer(route.getMetadata().getAnnotations());
    assertEquals(annotations.machineName(), "machine123");
    assertEquals(annotations.servers(), servers);
    assertEquals(route.getMetadata().getLabels().get("foo"), "bar");
    assertNull(route.getSpec().getHost());
}
Also used : OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) Deserializer(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.Deserializer) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 68 with ServerConfig

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

the class OpenShiftExternalServerExposerTest method shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost.

@Test
public void shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost() {
    // given
    RouteServerExposer osExternalServerExposer = new RouteServerExposer(LABELS, "open.che.org");
    OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().build();
    Map<String, ServerConfig> servers = new HashMap<>();
    servers.put("server", new ServerConfigImpl());
    // when
    osExternalServerExposer.expose(osEnv, "machine123", "service123", null, new ServicePort(null, "servicePort", null, null, "TCP", null), servers);
    // then
    assertEquals(1, osEnv.getRoutes().size());
    Route route = osEnv.getRoutes().values().iterator().next();
    assertNotNull(route);
    assertEquals(route.getSpec().getTo().getName(), "service123");
    assertEquals(route.getSpec().getPort().getTargetPort().getStrVal(), "servicePort");
    assertTrue(route.getSpec().getHost().endsWith(".open.che.org"));
    assertTrue(route.getSpec().getHost().startsWith("route"));
}
Also used : OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 69 with ServerConfig

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

the class ServerConfigImplTest method testCreateFromEndpointTranslatePublicFalse.

@Test
public void testCreateFromEndpointTranslatePublicFalse() {
    ServerConfig serverConfig = ServerConfigImpl.createFromEndpoint(new EndpointImpl("name", 123, singletonMap("public", "false")));
    assertFalse(serverConfig.getAttributes().isEmpty());
    assertEquals(serverConfig.getAttributes().get(INTERNAL_SERVER_ATTRIBUTE), Boolean.TRUE.toString());
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) Test(org.testng.annotations.Test)

Example 70 with ServerConfig

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

the class ServerConfigImplTest method testCreateFromEndpointTranslatePublicTrue.

@Test
public void testCreateFromEndpointTranslatePublicTrue() {
    ServerConfig serverConfig = ServerConfigImpl.createFromEndpoint(new EndpointImpl("name", 123, singletonMap("public", "true")));
    assertFalse(serverConfig.isInternal());
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) 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