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;
}
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;
}
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());
}
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));
}
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());
}
Aggregations