Search in sources :

Example 1 with WorkspaceCreatedEvent

use of org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent in project che-server by eclipse-che.

the class WorkspaceManager method doCreateWorkspace.

private WorkspaceImpl doCreateWorkspace(WorkspaceConfig config, Devfile devfile, Account account, Map<String, String> attributes, boolean isTemporary) throws ConflictException, ServerException {
    WorkspaceImpl workspace = WorkspaceImpl.builder().generateId().setAccount(account).setConfig(config).setDevfile(devfile).setAttributes(attributes).setTemporary(isTemporary).setStatus(STOPPED).build();
    workspace.getAttributes().put(CREATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
    String targetNamespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
    if (isNullOrEmpty(targetNamespace)) {
        try {
            targetNamespace = runtimes.evalInfrastructureNamespace(buildResolutionContext(workspace));
            workspace.getAttributes().put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, targetNamespace);
        } catch (InfrastructureException e) {
            throw new ServerException(e);
        }
    }
    if (targetNamespace == null || !runtimes.isInfrastructureNamespaceValid(targetNamespace)) {
        throw new ServerException(format("The workspace would be started in a namespace/project" + " '%s', which is not a valid namespace/project name.", targetNamespace));
    }
    workspaceDao.create(workspace);
    LOG.info("Workspace '{}/{}' with id '{}' created by user '{}'", account.getName(), workspace.getName(), workspace.getId(), sessionUserNameOrUndefined());
    eventService.publish(new WorkspaceCreatedEvent(workspace));
    return workspace;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) WorkspaceCreatedEvent(org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 2 with WorkspaceCreatedEvent

use of org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent in project devspaces-images by redhat-developer.

the class WorkspaceManager method doCreateWorkspace.

private WorkspaceImpl doCreateWorkspace(WorkspaceConfig config, Devfile devfile, Account account, Map<String, String> attributes, boolean isTemporary) throws ConflictException, ServerException {
    WorkspaceImpl workspace = WorkspaceImpl.builder().generateId().setAccount(account).setConfig(config).setDevfile(devfile).setAttributes(attributes).setTemporary(isTemporary).setStatus(STOPPED).build();
    workspace.getAttributes().put(CREATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
    String targetNamespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
    if (isNullOrEmpty(targetNamespace)) {
        try {
            targetNamespace = runtimes.evalInfrastructureNamespace(buildResolutionContext(workspace));
            workspace.getAttributes().put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, targetNamespace);
        } catch (InfrastructureException e) {
            throw new ServerException(e);
        }
    }
    if (targetNamespace == null || !runtimes.isInfrastructureNamespaceValid(targetNamespace)) {
        throw new ServerException(format("The workspace would be started in a namespace/project" + " '%s', which is not a valid namespace/project name.", targetNamespace));
    }
    workspaceDao.create(workspace);
    LOG.info("Workspace '{}/{}' with id '{}' created by user '{}'", account.getName(), workspace.getName(), workspace.getId(), sessionUserNameOrUndefined());
    eventService.publish(new WorkspaceCreatedEvent(workspace));
    return workspace;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) WorkspaceCreatedEvent(org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 3 with WorkspaceCreatedEvent

use of org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent in project che-server by eclipse-che.

the class WorkspaceActivityManagerTest method shouldRecordWorkspaceCreation.

@Test
public void shouldRecordWorkspaceCreation() throws Exception {
    String wsId = "1";
    EventSubscriber<WorkspaceCreatedEvent> subscriber = subscribeAndGetCreatedSubscriber();
    subscriber.onEvent(new WorkspaceCreatedEvent(DtoFactory.newDto(WorkspaceDto.class).withId(wsId).withAttributes(ImmutableMap.of(Constants.CREATED_ATTRIBUTE_NAME, "15"))));
    verify(workspaceActivityDao, times(1)).setCreatedTime(eq(wsId), eq(15L));
}
Also used : WorkspaceCreatedEvent(org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 4 with WorkspaceCreatedEvent

use of org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent in project devspaces-images by redhat-developer.

the class WorkspaceActivityManagerTest method shouldRecordWorkspaceCreation.

@Test
public void shouldRecordWorkspaceCreation() throws Exception {
    String wsId = "1";
    EventSubscriber<WorkspaceCreatedEvent> subscriber = subscribeAndGetCreatedSubscriber();
    subscriber.onEvent(new WorkspaceCreatedEvent(DtoFactory.newDto(WorkspaceDto.class).withId(wsId).withAttributes(ImmutableMap.of(Constants.CREATED_ATTRIBUTE_NAME, "15"))));
    verify(workspaceActivityDao, times(1)).setCreatedTime(eq(wsId), eq(15L));
}
Also used : WorkspaceCreatedEvent(org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

WorkspaceCreatedEvent (org.eclipse.che.api.workspace.shared.event.WorkspaceCreatedEvent)4 ServerException (org.eclipse.che.api.core.ServerException)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Test (org.testng.annotations.Test)2