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()); } } } } }
/** * Removes workspace with specified identifier. * * <p> * * <p>Does not remove the workspace if it has the runtime, throws {@link ConflictException} in * this case. Won't throw any exception if workspace doesn't exist. * * @param workspaceId workspace id to remove workspace * @throws ConflictException when workspace has runtime * @throws ServerException when any server error occurs * @throws NullPointerException when {@code workspaceId} is null */ @Traced public void removeWorkspace(String workspaceId) throws ConflictException, ServerException { requireNonNull(workspaceId, "Required non-null workspace id"); if (runtimes.hasRuntime(workspaceId)) { throw new ConflictException( format("The workspace '%s' is currently running and cannot be removed.", workspaceId)); } workspaceDao.remove(workspaceId); LOG.info("Workspace '{}' removed by user '{}'", workspaceId, sessionUserNameOrUndefined()); }