private void checkWorkspaceIsRunningOrStarting(WorkspaceImpl workspace) throws ConflictException { if (workspace.getStatus() != RUNNING && workspace.getStatus() != STARTING) { throw new ConflictException( format( "Could not stop the workspace '%s/%s' because its status is '%s'.", workspace.getNamespace(), workspace.getConfig().getName(), workspace.getStatus())); } }
@GET @Path("/namespace/{namespace:.*}") @Produces(APPLICATION_JSON) @ApiOperation( value = "Get workspaces by given namespace", notes = "This operation can be performed only by authorized user", response = WorkspaceDto.class, responseContainer = "List") @ApiResponses({ @ApiResponse(code = 200, message = "The workspaces successfully fetched"), @ApiResponse(code = 500, message = "Internal server error occurred during workspaces fetching") }) public List<WorkspaceDto> getByNamespace( @ApiParam("Workspace status") @QueryParam("status") String status, @ApiParam("The namespace") @PathParam("namespace") String namespace) throws ServerException, BadRequestException { return withLinks( Pages.stream( (maxItems, skipCount) -> workspaceManager.getByNamespace(namespace, false, maxItems, skipCount)) .filter(ws -> status == null || status.equalsIgnoreCase(ws.getStatus().toString())) .map(DtoConverter::asDto) .collect(toList())); }
.getItems() .stream() .filter(ws -> status == null || status.equalsIgnoreCase(ws.getStatus().toString())) .map(DtoConverter::asDto) .collect(toList()))
@Override public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException { final Account account = accountManager.getById(accountId); final long currentlyUsedRuntimes = Pages.stream( (maxItems, skipCount) -> workspaceManagerProvider .get() .getByNamespace(account.getName(), false, maxItems, skipCount)) .filter(ws -> STOPPED != ws.getStatus()) .count(); if (currentlyUsedRuntimes > 0) { return Optional.of( new ResourceImpl( RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT)); } else { return Optional.empty(); } } }