Search in sources :

Example 6 with ServerImpl

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

the class RouteServerResolverTest method testResolvingServersWhenThereIsMatchedRouteForMachineAndServerPathIsEmpty.

@Test
public void testResolvingServersWhenThereIsMatchedRouteForMachineAndServerPathIsEmpty() {
    Route route = createRoute("matched", "machine", singletonMap("http-server", new ServerConfigImpl("3054", "http", "", ATTRIBUTES_MAP)));
    RouteServerResolver serverResolver = new RouteServerResolver(emptyList(), singletonList(route));
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    assertEquals(resolved.size(), 1);
    assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://localhost").withStatus(UNKNOWN).withAttributes(defaultAttributeAnd(Constants.SERVER_PORT_ATTRIBUTE, "3054", ServerConfig.ENDPOINT_ORIGIN, "/")));
}
Also used : ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RouteServerResolver(org.eclipse.che.workspace.infrastructure.openshift.server.RouteServerResolver) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 7 with ServerImpl

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

the class RouteServerResolverTest method shouldSetEndpointOrigin.

@Test
public void shouldSetEndpointOrigin() {
    // given
    Route route = new RouteBuilder().withNewMetadata().addToAnnotations(Annotations.newSerializer().machineName("m1").server("svr", new ServerConfigImpl().withPort("8080").withProtocol("http").withPath("/kachny")).annotations()).endMetadata().withNewSpec().withHost("che.host").endSpec().build();
    RouteServerResolver serverResolver = new RouteServerResolver(emptyList(), singletonList(route));
    // when
    Map<String, ServerImpl> resolvedServers = serverResolver.resolve("m1");
    // then
    ServerImpl svr = resolvedServers.get("svr");
    assertNotNull(svr);
    assertEquals("/", ServerConfig.getEndpointOrigin(svr.getAttributes()));
    assertEquals("http://che.host/kachny", svr.getUrl());
}
Also used : RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RouteServerResolver(org.eclipse.che.workspace.infrastructure.openshift.server.RouteServerResolver) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 8 with ServerImpl

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

the class RuntimeServerBuilder method build.

public ServerImpl build() {
    if (endpointOrigin == null) {
        endpointOrigin = "/";
    }
    StringBuilder ub = new StringBuilder();
    if (protocol != null) {
        ub.append(protocol).append("://");
    } else {
        ub.append("tcp://");
    }
    ub.append(host);
    if (port != null) {
        ub.append(':').append(removeSuffix(port));
    }
    if (path != null) {
        if (!path.isEmpty() && !path.startsWith("/")) {
            ub.append("/");
        }
        ub.append(path);
    }
    Map<String, String> completeAttributes = new HashMap<>(attributes);
    completeAttributes.put(Constants.SERVER_PORT_ATTRIBUTE, targetPort);
    ServerConfig.setEndpointOrigin(completeAttributes, endpointOrigin);
    return new ServerImpl().withUrl(ub.toString()).withStatus(ServerStatus.UNKNOWN).withAttributes(completeAttributes);
}
Also used : ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) HashMap(java.util.HashMap)

Example 9 with ServerImpl

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

the class WorkspaceServiceTest method shouldGetWorkspaceWithExternalServersByDefault.

@Test
public void shouldGetWorkspaceWithExternalServersByDefault() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    ServerImpl externalServer = createExternalServer();
    Map<String, Server> servers = ImmutableMap.of("server1", 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(singletonMap(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).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 10 with ServerImpl

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

the class WorkspaceServiceTest method shouldTreatServerWithInternalServerAttributeNotEqualToTrueExternal.

@Test
public void shouldTreatServerWithInternalServerAttributeNotEqualToTrueExternal() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    ServerImpl externalServer = createInternalServer().withAttributes(singletonMap(ServerConfig.INTERNAL_SERVER_ATTRIBUTE, ""));
    Map<String, Server> servers = ImmutableMap.of("server1", 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(singletonMap(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).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)

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