Search in sources :

Example 61 with ServerImpl

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

the class RouteServerResolverTest method testResolvingInternalServers.

@Test
public void testResolvingInternalServers() {
    Service service = createService("service11", "machine", CONTAINER_PORT, singletonMap("http-server", new ServerConfigImpl("3054", "http", "api", ATTRIBUTES_MAP)));
    Route route = createRoute("matched", "machine", null);
    RouteServerResolver serverResolver = new RouteServerResolver(singletonList(service), singletonList(route));
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    assertEquals(resolved.size(), 1);
    assertEquals(resolved.get("http-server"), new ServerImpl().withUrl("http://service11:3054/api").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) Service(io.fabric8.kubernetes.api.model.Service) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 62 with ServerImpl

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

the class RouteServerResolverTest method testResolvingServersWhenThereIsNoTheCorrespondingServiceAndRouteForTheSpecifiedMachine.

@Test
public void testResolvingServersWhenThereIsNoTheCorrespondingServiceAndRouteForTheSpecifiedMachine() {
    // given
    Service nonMatchedByPodService = createService("nonMatched", "foreignMachine", CONTAINER_PORT, null);
    Route route = createRoute("nonMatched", "foreignMachine", ImmutableMap.of("http-server", new ServerConfigImpl("3054", "http", "/api", ATTRIBUTES_MAP)));
    RouteServerResolver serverResolver = new RouteServerResolver(singletonList(nonMatchedByPodService), singletonList(route));
    // when
    Map<String, ServerImpl> resolved = serverResolver.resolve("machine");
    // then
    assertTrue(resolved.isEmpty());
}
Also used : ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RouteServerResolver(org.eclipse.che.workspace.infrastructure.openshift.server.RouteServerResolver) Service(io.fabric8.kubernetes.api.model.Service) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 63 with ServerImpl

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

the class RouteServerResolverTest method testResolvingServersWhenThereIsMatchedRouteForMachineAndServerPathIsRelative.

@Test
public void testResolvingServersWhenThereIsMatchedRouteForMachineAndServerPathIsRelative() {
    Route route = createRoute("matched", "machine", singletonMap("http-server", new ServerConfigImpl("3054", "http", "api", 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/api").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 64 with ServerImpl

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

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 65 with ServerImpl

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

the class ServersCheckerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    servers = new HashMap<>();
    servers.putAll(ImmutableMap.of(WSAGENT_HTTP_SERVER, new ServerImpl().withUrl("http://localhost/api"), EXEC_AGENT_HTTP_SERVER, new ServerImpl().withUrl("http://localhost/exec-agent/process"), TERMINAL_SERVER, new ServerImpl().withUrl("http://localhost/terminal/pty")));
    CompletableFuture<String> compFuture = new CompletableFuture<>();
    when(connectionChecker.getReportCompFuture()).thenReturn(compFuture);
    when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(runtimeIdentity.getOwnerId()).thenReturn(USER_ID);
    checker = spy(new ServersChecker(runtimeIdentity, MACHINE_NAME, servers, machineTokenProvider, SERVER_PING_SUCCESS_THRESHOLD, SERVER_PING_INTERVAL_MILLIS, CONFIGURED_SERVERS));
    when(checker.doCreateChecker(any(URL.class), anyString(), anyString())).thenReturn(connectionChecker);
    when(machineTokenProvider.getToken(anyString(), anyString())).thenReturn(MACHINE_TOKEN);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

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