Search in sources :

Example 16 with RuntimeImpl

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

the class RamResourceUsageTrackerTest method createWorkspace.

/**
 * Creates users workspace object based on the status and machines RAM.
 */
private static WorkspaceImpl createWorkspace(WorkspaceStatus status, Integer... machineRams) {
    final Map<String, MachineImpl> machines = new HashMap<>(machineRams.length - 1);
    final Map<String, MachineConfigImpl> machineConfigs = new HashMap<>(machineRams.length - 1);
    byte i = 1;
    for (Integer machineRam : machineRams) {
        final String machineName = "machine_" + i++;
        machines.put(machineName, createMachine(machineRam));
        machineConfigs.put(machineName, createMachineConfig(machineRam));
    }
    return WorkspaceImpl.builder().setConfig(WorkspaceConfigImpl.builder().setEnvironments(ImmutableBiMap.of(ACTIVE_ENV_NAME, new EnvironmentImpl(null, machineConfigs))).build()).setRuntime(new RuntimeImpl(ACTIVE_ENV_NAME, machines, null)).setStatus(status).build();
}
Also used : MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) HashMap(java.util.HashMap) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 17 with RuntimeImpl

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

the class WorkspaceManagerTest method mockRuntime.

private TestRuntime mockRuntime(WorkspaceImpl workspace, WorkspaceStatus status) throws Exception {
    MachineImpl machine1 = createMachine();
    MachineImpl machine2 = createMachine();
    Map<String, Machine> machines = new HashMap<>();
    machines.put("machine1", machine1);
    machines.put("machine2", machine2);
    List<WarningImpl> warnings = new ArrayList<>();
    warnings.add(new WarningImpl(103, "used default value"));
    warnings.add(new WarningImpl(105, "specified configuration parameter is ignored"));
    TestRuntime runtime = new TestRuntime(machines, workspace.getConfig().getCommands(), warnings);
    lenient().doAnswer(inv -> {
        workspace.setStatus(status);
        workspace.setRuntime(new RuntimeImpl(runtime.getActiveEnv(), runtime.getMachines(), runtime.getOwner(), runtime.getCommands(), runtime.getWarnings()));
        return null;
    }).when(runtimes).injectRuntime(workspace);
    lenient().when(runtimes.isAnyActive()).thenReturn(true);
    return runtime;
}
Also used : MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine)

Example 18 with RuntimeImpl

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

the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue.

@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue() 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", "").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 19 with RuntimeImpl

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

the class WorkspaceServiceTest method shouldReturnWorkspaceWithTokenIfRuntimeExists.

@Test
public void shouldReturnWorkspaceWithTokenIfRuntimeExists() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    workspace.setRuntime(new RuntimeImpl("activeEnv", emptyMap(), "user123"));
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(machineTokenProvider.getToken(anyString())).thenReturn("superToken");
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    assertEquals(response.getStatusCode(), 200);
    WorkspaceDto retrievedWorkspace = unwrapDto(response, WorkspaceDto.class);
    assertEquals(retrievedWorkspace.getRuntime().getMachineToken(), "superToken");
    verify(machineTokenProvider).getToken(workspace.getId());
}
Also used : Response(io.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Test(org.testng.annotations.Test)

Example 20 with RuntimeImpl

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

the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasNoValue.

@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasNoValue() 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").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

RuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl)26 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)22 MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)18 Test (org.testng.annotations.Test)18 Response (io.restassured.response.Response)14 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 Machine (org.eclipse.che.api.core.model.workspace.runtime.Machine)12 Server (org.eclipse.che.api.core.model.workspace.runtime.Server)10 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)10 MachineDto (org.eclipse.che.api.workspace.shared.dto.MachineDto)10 RuntimeDto (org.eclipse.che.api.workspace.shared.dto.RuntimeDto)10 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)2 WorkspaceConfig (org.eclipse.che.api.core.model.workspace.WorkspaceConfig)2 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)2 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)2 WarningImpl (org.eclipse.che.api.workspace.server.model.impl.WarningImpl)2