@Transactional protected WorkspaceImpl doUpdate(WorkspaceImpl update) throws NotFoundException { EntityManager manager = managerProvider.get(); if (manager.find(WorkspaceImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getConfig() != null) { update.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } WorkspaceImpl merged = manager.merge(update); manager.flush(); return merged; }
@Transactional protected WorkspaceImpl doUpdate(WorkspaceImpl update) throws NotFoundException { EntityManager manager = managerProvider.get(); if (manager.find(WorkspaceImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getConfig() != null) { update.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } WorkspaceImpl merged = manager.merge(update); manager.flush(); return merged; }
@Override public void onCascadeEvent(BeforeWorkspaceRemovedEvent event) throws Exception { signatureKeyDao.remove(event.getWorkspace().getId()); } }
@VisibleForTesting void removeTemporaryWs() throws ServerException { for (WorkspaceImpl workspace : Pages.iterate( (maxItems, skipCount) -> workspaceDao.getWorkspaces(true, maxItems, skipCount))) { WorkspaceStatus status = runtimes.getStatus(workspace.getId()); if (status == WorkspaceStatus.STOPPED) { try { workspaceDao.remove(workspace.getId()); } catch (ServerException e) { LOG.error( "Unable to cleanup temporary workspace {}. Reason is {}", workspace.getId(), e.getMessage()); } } } } }
@Override public void onCascadeEvent(BeforeWorkspaceRemovedEvent event) throws Exception { removeWorkers(event.getWorkspace().getId(), PAGE_SIZE); }
private WorkspaceImpl normalizeState(WorkspaceImpl workspace, boolean includeRuntimes) throws ServerException { if (includeRuntimes) { runtimes.injectRuntime(workspace); } else { workspace.setStatus(runtimes.getStatus(workspace.getId())); } return workspace; }
/** * Injects runtime information such as status and {@link * org.eclipse.che.api.core.model.workspace.Runtime} into the workspace object, if the workspace * doesn't have runtime sets the status to {@link WorkspaceStatus#STOPPED}. * * @param workspace the workspace to inject runtime into */ public void injectRuntime(WorkspaceImpl workspace) throws ServerException { try (Unlocker ignored = lockService.writeLock(workspace.getId())) { WorkspaceStatus workspaceStatus = statuses.get(workspace.getId()); if (workspaceStatus == null) { workspace.setStatus(STOPPED); return; } InternalRuntime<?> internalRuntime; try { internalRuntime = getInternalRuntime(workspace.getId()); } catch (ServerException | InfrastructureException e) { workspace.setStatus(STOPPED); return; } workspace.setRuntime(asRuntime(internalRuntime)); workspace.setStatus(workspaceStatus); } }
@Override public WorkspaceImpl create(WorkspaceImpl workspace) throws ConflictException, ServerException { requireNonNull(workspace, "Required non-null workspace"); try { doCreate(workspace); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with id '%s' or name '%s' in namespace '%s' already exists", workspace.getId(), workspace.getConfig().getName(), workspace.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } return new WorkspaceImpl(workspace); }
@Override public WorkspaceImpl create(WorkspaceImpl workspace) throws ConflictException, ServerException { requireNonNull(workspace, "Required non-null workspace"); try { doCreate(workspace); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with id '%s' or name '%s' in namespace '%s' already exists", workspace.getId(), workspace.getConfig().getName(), workspace.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } return new WorkspaceImpl(workspace); }
workspaceManager.startWorkspace(workspace.getId(), null, new HashMap<>());
@Override public void onCascadeEvent(BeforeAccountRemovedEvent event) throws Exception { for (WorkspaceImpl workspace : iterate( (maxItems, skipCount) -> workspaceManager.getByNamespace( event.getAccount().getName(), false, maxItems, skipCount))) { workspaceManager.removeWorkspace(workspace.getId()); } } }
@Override public void onCascadeEvent(BeforeAccountRemovedEvent event) throws Exception { for (WorkspaceImpl workspace : iterate( (maxItems, skipCount) -> workspaceManager.getByNamespace( event.getAccount().getName(), false, maxItems, skipCount))) { workspaceManager.removeWorkspace(workspace.getId()); } } }
private WorkspaceImpl doCreateWorkspace( WorkspaceConfig config, Account account, Map<String, String> attributes, boolean isTemporary) throws NotFoundException, ServerException, ConflictException { WorkspaceImpl workspace = WorkspaceImpl.builder() .generateId() .setConfig(config) .setAccount(account) .setAttributes(attributes) .setTemporary(isTemporary) .setStatus(STOPPED) .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(), sessionUserNameOrUndefined()); eventService.publish(new WorkspaceCreatedEvent(workspace)); return workspace; }