Search in sources :

Example 16 with MachineImpl

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

the class TestObjects method createRuntime.

/**
 * Creates runtime workspace object based on the machines RAM.
 */
public static WorkspaceImpl createRuntime(String... machineRams) throws Exception {
    final WorkspaceImpl workspace = createWorkspace(DEFAULT_USER_NAME, machineRams);
    final String envName = workspace.getConfig().getDefaultEnv();
    final Map<String, MachineImpl> machines = new HashMap<>();
    int i = 0;
    for (String machineRam : machineRams) {
        machines.put("machine" + i++, createMachine(machineRam, Collections.emptyMap(), MachineStatus.RUNNING));
    }
    RuntimeImpl runtime = new RuntimeImpl(envName, machines, DEFAULT_USER_NAME);
    workspace.setStatus(RUNNING);
    workspace.setRuntime(runtime);
    return workspace;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) HashMap(java.util.HashMap) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl)

Example 17 with MachineImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl 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 18 with MachineImpl

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

the class WorkspaceRuntimesTest method shouldInjectRuntime.

@Test
public void shouldInjectRuntime() throws Exception {
    // given
    WorkspaceImpl workspace = new WorkspaceImpl();
    workspace.setId("ws123");
    when(statuses.get("ws123")).thenReturn(WorkspaceStatus.RUNNING);
    ImmutableMap<String, Machine> machines = ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));
    RuntimeIdentity identity = new RuntimeIdentityImpl("ws123", "my-env", "myId", "infraNamespace");
    RuntimeContext context = mockContext(identity);
    ConcurrentHashMap<String, InternalRuntime<?>> runtimesStorage = new ConcurrentHashMap<>();
    TestInternalRuntime testRuntime = new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING);
    runtimesStorage.put("ws123", testRuntime);
    WorkspaceRuntimes localRuntimes = new WorkspaceRuntimes(runtimesStorage, eventService, ImmutableMap.of(TEST_ENVIRONMENT_TYPE, testEnvFactory), infrastructure, sharedPool, workspaceDao, dbInitializer, probeScheduler, statuses, lockService, devfileConverter, false);
    // when
    localRuntimes.injectRuntime(workspace);
    // then
    assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
    assertEquals(workspace.getRuntime(), asRuntime(testRuntime));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InternalRuntime(org.eclipse.che.api.workspace.server.spi.InternalRuntime) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 19 with MachineImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl 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 20 with MachineImpl

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

the class WorkspaceRuntimesTest method shouldRecoverRuntimeWhenThereIsNotCachedOneDuringInjecting.

@Test
public void shouldRecoverRuntimeWhenThereIsNotCachedOneDuringInjecting() throws Exception {
    // given
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
    mockWorkspaceWithConfig(identity);
    when(statuses.get("workspace123")).thenReturn(WorkspaceStatus.STARTING);
    RuntimeContext context = mockContext(identity);
    doReturn(context).when(infrastructure).prepare(eq(identity), any());
    ImmutableMap<String, Machine> machines = ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));
    TestInternalRuntime testRuntime = new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING);
    when(context.getRuntime()).thenReturn(testRuntime);
    doReturn(mock(InternalEnvironment.class)).when(testEnvFactory).create(any());
    doReturn(ImmutableSet.of(identity)).when(infrastructure).getIdentities();
    // when
    WorkspaceImpl workspace = new WorkspaceImpl();
    workspace.setId("workspace123");
    runtimes.injectRuntime(workspace);
    // then
    assertEquals(workspace.getStatus(), WorkspaceStatus.STARTING);
    assertEquals(workspace.getRuntime(), asRuntime(testRuntime));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) Test(org.testng.annotations.Test)

Aggregations

MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)32 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 Test (org.testng.annotations.Test)22 RuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl)18 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)18 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)18 Machine (org.eclipse.che.api.core.model.workspace.runtime.Machine)16 Response (io.restassured.response.Response)12 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)12 HashMap (java.util.HashMap)10 Server (org.eclipse.che.api.core.model.workspace.runtime.Server)10 MachineDto (org.eclipse.che.api.workspace.shared.dto.MachineDto)10 RuntimeDto (org.eclipse.che.api.workspace.shared.dto.RuntimeDto)10 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)6 ArrayList (java.util.ArrayList)4 URLRewriter (org.eclipse.che.api.workspace.server.URLRewriter)4 RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)4 WarningImpl (org.eclipse.che.api.workspace.server.model.impl.WarningImpl)4 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2