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