Search in sources :

Example 11 with MachineDto

use of org.eclipse.che.api.workspace.shared.dto.MachineDto in project devspaces-images by redhat-developer.

the class WorkspaceService method filterServers.

private WorkspaceDto filterServers(WorkspaceDto workspace, boolean includeInternal) {
    // no runtime - nothing to filter
    if (workspace.getRuntime() == null) {
        return workspace;
    }
    // if it is needed to include internal there is nothing to filter
    if (includeInternal) {
        return workspace;
    }
    for (MachineDto machine : workspace.getRuntime().getMachines().values()) {
        Map<String, ServerDto> filteredServers = new HashMap<>();
        machine.getServers().forEach((name, server) -> {
            if (!ServerConfig.isInternal(server.getAttributes())) {
                filteredServers.put(name, server);
            }
        });
        machine.withServers(filteredServers);
    }
    return workspace;
}
Also used : ServerDto(org.eclipse.che.api.workspace.shared.dto.ServerDto) MachineDto(org.eclipse.che.api.workspace.shared.dto.MachineDto) HashMap(java.util.HashMap)

Example 12 with MachineDto

use of org.eclipse.che.api.workspace.shared.dto.MachineDto 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)

Aggregations

MachineDto (org.eclipse.che.api.workspace.shared.dto.MachineDto)12 Response (io.restassured.response.Response)10 Machine (org.eclipse.che.api.core.model.workspace.runtime.Machine)10 Server (org.eclipse.che.api.core.model.workspace.runtime.Server)10 MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)10 RuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl)10 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)10 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)10 RuntimeDto (org.eclipse.che.api.workspace.shared.dto.RuntimeDto)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)2 ServerDto (org.eclipse.che.api.workspace.shared.dto.ServerDto)2