private WorkspaceImpl normalizeState(WorkspaceImpl workspace, boolean includeRuntimes) throws ServerException { if (includeRuntimes) { runtimes.injectRuntime(workspace); } else { workspace.setStatus(runtimes.getStatus(workspace.getId())); } return workspace; }
private void stopRunningAndStartingWorkspacesAsync() { for (String workspaceId : runtimes.getActive()) { WorkspaceStatus status = runtimes.getStatus(workspaceId); if (status == WorkspaceStatus.RUNNING || status == WorkspaceStatus.STARTING) { try { manager.stopWorkspace(workspaceId, Collections.emptyMap()); } catch (ServerException | ConflictException | NotFoundException x) { if (runtimes.hasRuntime(workspaceId)) { LOG.error( "Couldn't get the workspace '{}' while it's running, the occurred error: '{}'", workspaceId, x.getMessage()); } } } } }
@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()); } } } } }