Search in sources :

Example 11 with ServerImpl

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

the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServers.

@Test
public void shouldGetWorkspaceWithInternalServers() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    String internalServerKey = "server1";
    ServerImpl externalServer = createExternalServer();
    ServerImpl internalServer = createInternalServer();
    Map<String, Server> servers = ImmutableMap.of(internalServerKey, createInternalServer(), externalServerKey, externalServer);
    Map<String, Machine> machines = singletonMap("machine1", new MachineImpl(singletonMap("key", "value"), servers, RUNNING));
    workspace.setRuntime(new RuntimeImpl("activeEnv", machines, "user123"));
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    Map<String, MachineDto> expected = singletonMap("machine1", newDto(MachineDto.class).withAttributes(singletonMap("key", "value")).withStatus(RUNNING).withServers(ImmutableMap.of(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()), internalServerKey, newDto(ServerDto.class).withUrl(createInternalServer().getUrl()).withStatus(internalServer.getStatus()).withAttributes(internalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).queryParam("includeInternalServers", Boolean.TRUE.toString()).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    RuntimeDto retrievedRuntime = unwrapDto(response, WorkspaceDto.class).getRuntime();
    assertNotNull(retrievedRuntime);
    assertEquals(expected, retrievedRuntime.getMachines());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) Response(io.restassured.response.Response) MachineDto(org.eclipse.che.api.workspace.shared.dto.MachineDto) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) RuntimeDto(org.eclipse.che.api.workspace.shared.dto.RuntimeDto) Test(org.testng.annotations.Test)

Example 12 with ServerImpl

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

the class InternalRuntime method rewriteExternalServers.

/**
 * Convenient method to rewrite incoming external servers in a loop
 *
 * @param incoming servers
 * @return rewritten Map of Servers (name -> Server)
 */
private Map<String, Server> rewriteExternalServers(String machineName, Map<String, ? extends Server> incoming) {
    Map<String, Server> outgoing = new HashMap<>();
    RuntimeIdentity identity = context.getIdentity();
    for (Map.Entry<String, ? extends Server> entry : incoming.entrySet()) {
        String name = entry.getKey();
        Server incomingServer = entry.getValue();
        if (ServerConfig.isInternal(incomingServer.getAttributes())) {
            outgoing.put(name, incomingServer);
        } else {
            try {
                ServerImpl server = new ServerImpl(incomingServer).withUrl(urlRewriter.rewriteURL(identity, machineName, name, incomingServer.getUrl()));
                outgoing.put(name, server);
            } catch (InfrastructureException e) {
                context.getEnvironment().getWarnings().add(new WarningImpl(MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + name + " : " + e.getMessage()));
            }
        }
    }
    return outgoing;
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Example 13 with ServerImpl

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

the class IngressServerResolverTest method testResolvingInternalServersWithPortWithTransportProtocol.

@Test
public void testResolvingInternalServersWithPortWithTransportProtocol() {
    Service service = createService("service11", "machine", CONTAINER_PORT, singletonMap("http-server", new ServerConfigImpl("3054/udp", "xxx", "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("xxx://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 14 with ServerImpl

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

the class IngressServerResolverTest method testResolvingServersWhenThereIsNoTheCorrespondingServiceAndIngressForTheSpecifiedMachine.

@Test
public void testResolvingServersWhenThereIsNoTheCorrespondingServiceAndIngressForTheSpecifiedMachine() {
    // given
    Service nonMatchedByPodService = createService("nonMatched", "foreignMachine", CONTAINER_PORT, null);
    Ingress ingress = createIngress("nonMatched", "foreignMachine", Pair.of("http-server", new ServerConfigImpl("3054", "http", "/api", ATTRIBUTES_MAP)));
    ServerResolver serverResolver = new IngressServerResolver(new NoopPathTransformInverter(), singletonList(nonMatchedByPodService), singletonList(ingress));
    // when
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    // then
    assertTrue(resolved.isEmpty());
}
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) 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 15 with ServerImpl

use of org.eclipse.che.api.workspace.server.model.impl.ServerImpl 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)

Aggregations

ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)68 Test (org.testng.annotations.Test)54 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)32 MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 Route (io.fabric8.openshift.api.model.Route)16 RouteServerResolver (org.eclipse.che.workspace.infrastructure.openshift.server.RouteServerResolver)16 Service (io.fabric8.kubernetes.api.model.Service)14 IngressServerResolver (org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.IngressServerResolver)14 ServerResolver (org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver)14 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)12 Machine (org.eclipse.che.api.core.model.workspace.runtime.Machine)12 Server (org.eclipse.che.api.core.model.workspace.runtime.Server)12 Response (io.restassured.response.Response)10 RuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl)10 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)10 MachineDto (org.eclipse.che.api.workspace.shared.dto.MachineDto)10 RuntimeDto (org.eclipse.che.api.workspace.shared.dto.RuntimeDto)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)10 HashMap (java.util.HashMap)8