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