Search in sources :

Example 16 with MachineSourceImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.

the class WorkspaceManagerTest method shouldRecoverWorkspaceWhenRecoverParameterIsNullAndAutoRestoreAttributeIsSetAndSnapshotExists.

@Test
public void shouldRecoverWorkspaceWhenRecoverParameterIsNullAndAutoRestoreAttributeIsSetAndSnapshotExists() throws Exception {
    final WorkspaceImpl workspace = createAndMockWorkspace();
    workspace.getAttributes().put(AUTO_RESTORE_FROM_SNAPSHOT, "true");
    mockStart(workspace);
    SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(workspace.getId()).setType("docker").setMachineSource(new MachineSourceImpl("image"));
    SnapshotImpl snapshot1 = snapshotBuilder.build();
    SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
    when(snapshotDao.findSnapshots(workspace.getId())).thenReturn(asList(snapshot1, snapshot2));
    workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), null);
    verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), true);
    assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Test(org.testng.annotations.Test)

Example 17 with MachineSourceImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.

the class WorkspaceManagerTest method mockSnapshots.

private List<SnapshotImpl> mockSnapshots(Workspace workspace, long creation) throws SnapshotException {
    SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setCreationDate(creation).setEnvName(workspace.getConfig().getDefaultEnv()).setWorkspaceId(workspace.getId()).setType("docker").setMachineSource(new MachineSourceImpl("image"));
    SnapshotImpl snapshot1 = snapshotBuilder.build();
    SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
    List<SnapshotImpl> snapshots = asList(snapshot1, snapshot2);
    when(snapshotDao.findSnapshots(workspace.getId())).thenReturn(snapshots);
    return snapshots;
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)

Example 18 with MachineSourceImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.

the class CheEnvironmentEngine method saveSnapshot.

/**
     * Saves machine into snapshot.
     *
     * @param workspaceId
     *         ID of workspace that owns environment
     * @param machineId
     *         ID of machine to save
     * @return snapshot
     * @throws EnvironmentNotRunningException
     *         if environment of machine is not running
     * @throws NotFoundException
     *         if machine is not running
     * @throws ServerException
     *         if another error occurs
     */
public SnapshotImpl saveSnapshot(String workspaceId, String machineId) throws ServerException, NotFoundException {
    EnvironmentHolder environmentHolder;
    SnapshotImpl snapshot = null;
    Instance instance = null;
    try (@SuppressWarnings("unused") Unlocker u = stripedLocks.readLock(workspaceId)) {
        environmentHolder = environments.get(workspaceId);
        if (environmentHolder == null || environmentHolder.status != EnvStatus.RUNNING) {
            throw new EnvironmentNotRunningException(format("Environment '%s' is not running", workspaceId));
        }
        for (Instance machine : environmentHolder.machines) {
            if (machine.getId().equals(machineId)) {
                instance = machine;
                snapshot = SnapshotImpl.builder().generateId().setType(machine.getConfig().getType()).setWorkspaceId(machine.getWorkspaceId()).setDescription(machine.getEnvName()).setDev(machine.getConfig().isDev()).setEnvName(machine.getEnvName()).setMachineName(machine.getConfig().getName()).useCurrentCreationDate().build();
            }
        }
    }
    if (instance == null) {
        throw new NotFoundException(format("Machine with id '%s' is not found in environment of workspace '%s'", machineId, workspaceId));
    }
    try {
        MachineSource machineSource = instance.saveToSnapshot();
        snapshot.setMachineSource(new MachineSourceImpl(machineSource));
        return snapshot;
    } catch (ServerException e) {
        try {
            instance.getLogger().writeLine("Snapshot storing failed. " + e.getLocalizedMessage());
        } catch (IOException ignore) {
        }
        throw e;
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) SourceNotFoundException(org.eclipse.che.api.machine.server.exception.SourceNotFoundException) NotFoundException(org.eclipse.che.api.core.NotFoundException) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) IOException(java.io.IOException) MachineSource(org.eclipse.che.api.core.model.machine.MachineSource)

Example 19 with MachineSourceImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.

the class WorkspaceServiceTest method testWorkspaceLinks.

@Test
public void testWorkspaceLinks() throws Exception {
    // given
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    EnvironmentImpl environment = workspace.getConfig().getEnvironments().get(workspace.getConfig().getDefaultEnv());
    assertNotNull(environment);
    final WorkspaceRuntimeImpl runtime = new WorkspaceRuntimeImpl(workspace.getConfig().getDefaultEnv(), null);
    MachineConfigImpl devMachineConfig = MachineConfigImpl.builder().setDev(true).setEnvVariables(emptyMap()).setServers(emptyList()).setLimits(new MachineLimitsImpl(1024)).setSource(new MachineSourceImpl("type").setContent("content")).setName(environment.getMachines().keySet().iterator().next()).setType("type").build();
    runtime.setDevMachine(new MachineImpl(devMachineConfig, "machine123", workspace.getId(), workspace.getConfig().getDefaultEnv(), USER_ID, MachineStatus.RUNNING, new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), singletonMap("8080/https", new ServerImpl("wsagent", "https", "address", "url", new ServerPropertiesImpl("path", "internaladdress", "internalurl"))))));
    runtime.getMachines().add(runtime.getDevMachine());
    workspace.setStatus(RUNNING);
    workspace.setRuntime(runtime);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    final WorkspaceDto workspaceDto = unwrapDto(response, WorkspaceDto.class);
    final Set<String> actualRels = workspaceDto.getLinks().stream().map(Link::getRel).collect(toSet());
    final Set<String> expectedRels = new HashSet<>(asList(LINK_REL_START_WORKSPACE, LINK_REL_REMOVE_WORKSPACE, GET_ALL_USER_WORKSPACES, LINK_REL_GET_SNAPSHOT, LINK_REL_GET_WORKSPACE_EVENTS_CHANNEL, LINK_REL_IDE_URL, LINK_REL_SELF, LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, LINK_REL_ENVIRONMENT_STATUS_CHANNEL));
    assertTrue(actualRels.equals(expectedRels), format("Links difference: '%s'. \n" + "Returned links: '%s', \n" + "Expected links: '%s'.", Sets.symmetricDifference(actualRels, expectedRels), actualRels.toString(), expectedRels.toString()));
    assertNotNull(workspaceDto.getRuntime().getLink(LINK_REL_STOP_WORKSPACE), "Runtime doesn't contain stop link");
    assertNotNull(workspaceDto.getRuntime().getLink(WSAGENT_REFERENCE), "Runtime doesn't contain wsagent link");
    assertNotNull(workspaceDto.getRuntime().getLink(WSAGENT_WEBSOCKET_REFERENCE), "Runtime doesn't contain wsagent.websocket link");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Matchers.anyString(org.mockito.Matchers.anyString) MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) Response(com.jayway.restassured.response.Response) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)19 Test (org.testng.annotations.Test)13 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)10 Instance (org.eclipse.che.api.machine.server.spi.Instance)7 Matchers.anyString (org.mockito.Matchers.anyString)7 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)5 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)5 IOException (java.io.IOException)4 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)4 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)4 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)4 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ServerException (org.eclipse.che.api.core.ServerException)3 MachineLimitsImpl (org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)3 Response (com.jayway.restassured.response.Response)2 ArrayList (java.util.ArrayList)2 MachineSource (org.eclipse.che.api.core.model.machine.MachineSource)2 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)2 MachineRuntimeInfoImpl (org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl)2