Search in sources :

Example 81 with WorkspaceImpl

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

the class WorkspaceManager method doCreateWorkspace.

private WorkspaceImpl doCreateWorkspace(WorkspaceConfig config, Account account, Map<String, String> attributes, boolean isTemporary) throws NotFoundException, ServerException, ConflictException {
    final WorkspaceImpl workspace = WorkspaceImpl.builder().generateId().setConfig(config).setAccount(account).setAttributes(attributes).setTemporary(isTemporary).build();
    workspace.getAttributes().put(CREATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
    workspaceDao.create(workspace);
    LOG.info("Workspace '{}/{}' with id '{}' created by user '{}'", account.getName(), workspace.getConfig().getName(), workspace.getId(), sessionUserNameOr("undefined"));
    eventService.publish(new WorkspaceCreatedEvent(workspace));
    return workspace;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceCreatedEvent(org.eclipse.che.api.workspace.server.event.WorkspaceCreatedEvent)

Example 82 with WorkspaceImpl

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

the class WorkspaceManager method createWorkspace.

/**
     * Creates a new {@link WorkspaceImpl} instance based on the given configuration.
     *
     * @param config
     *         the workspace config to create the new workspace instance
     * @param namespace
     *         workspace name is unique in this namespace
     * @return new workspace instance
     * @throws NullPointerException
     *         when either {@code config} or {@code owner} is null
     * @throws NotFoundException
     *         when account with given id was not found
     * @throws ConflictException
     *         when any conflict occurs (e.g Workspace with such name already exists for {@code owner})
     * @throws ServerException
     *         when any other error occurs
     */
public WorkspaceImpl createWorkspace(WorkspaceConfig config, String namespace) throws ServerException, ConflictException, NotFoundException {
    requireNonNull(config, "Required non-null config");
    requireNonNull(namespace, "Required non-null namespace");
    WorkspaceImpl workspace = doCreateWorkspace(config, accountManager.getByName(namespace), emptyMap(), false);
    workspace.setStatus(WorkspaceStatus.STOPPED);
    return workspace;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)

Example 83 with WorkspaceImpl

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

the class FactoryServiceTest method shouldNotGenerateFactoryIfNoProjectsWithSourceStorage.

@Test
public void shouldNotGenerateFactoryIfNoProjectsWithSourceStorage() throws Exception {
    // given
    final String wsId = "workspace123234";
    WorkspaceImpl.WorkspaceImplBuilder ws = WorkspaceImpl.builder();
    WorkspaceConfigImpl.WorkspaceConfigImplBuilder wsConfig = WorkspaceConfigImpl.builder();
    ws.setId(wsId);
    wsConfig.setProjects(Arrays.asList(DTO.createDto(ProjectConfigDto.class).withPath("/proj1"), DTO.createDto(ProjectConfigDto.class).withPath("/proj2")));
    wsConfig.setName("wsname");
    wsConfig.setEnvironments(singletonMap("env1", DTO.createDto(EnvironmentDto.class)));
    wsConfig.setDefaultEnv("env1");
    ws.setStatus(WorkspaceStatus.RUNNING);
    wsConfig.setCommands(singletonList(DTO.createDto(CommandDto.class).withName("MCI").withType("mvn").withCommandLine("clean install")));
    ws.setConfig(wsConfig.build());
    WorkspaceImpl usersWorkspace = ws.build();
    when(workspaceManager.getWorkspace(eq(wsId))).thenReturn(usersWorkspace);
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SERVICE_PATH + "/workspace/" + wsId);
    // then
    assertEquals(response.getStatusCode(), BAD_REQUEST.getStatusCode());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 84 with WorkspaceImpl

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

the class WorkspaceDaoTest method shouldGetWorkspaceByNameAndNamespace.

@Test
public void shouldGetWorkspaceByNameAndNamespace() throws Exception {
    final WorkspaceImpl workspace = workspaces[0];
    assertEquals(workspaceDao.get(workspace.getConfig().getName(), workspace.getNamespace()), new WorkspaceImpl(workspace));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 85 with WorkspaceImpl

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

the class WorkspaceDaoTest method shouldThrowNotFoundExceptionWhenWorkspaceWithSuchNameDoesNotExistInGiveWorkspace.

@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowNotFoundExceptionWhenWorkspaceWithSuchNameDoesNotExistInGiveWorkspace() throws Exception {
    final WorkspaceImpl workspace1 = workspaces[0];
    final WorkspaceImpl workspace2 = workspaces[2];
    workspaceDao.get(workspace1.getConfig().getName(), workspace2.getNamespace());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Aggregations

WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)165 Test (org.testng.annotations.Test)130 Response (com.jayway.restassured.response.Response)34 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)15 ServerException (org.eclipse.che.api.core.ServerException)14 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)12 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 AccountImpl (org.eclipse.che.account.spi.AccountImpl)11 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)10 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)9 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)9 NotFoundException (org.eclipse.che.api.core.NotFoundException)8 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)8 Consumes (javax.ws.rs.Consumes)7 ConflictException (org.eclipse.che.api.core.ConflictException)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)7 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)7