void checkAccountPermissions(String accountName, AccountOperation operation) throws ForbiddenException, NotFoundException, ServerException { if (accountName == null) { // default namespace will be used return; } final Account account = accountManager.getByName(accountName); AccountPermissionsChecker accountPermissionsChecker = accountTypeToPermissionsChecker.get(account.getType()); if (accountPermissionsChecker == null) { throw new ForbiddenException("User is not authorized to use specified namespace"); } accountPermissionsChecker.checkPermissions(account.getId(), operation); } }
/** * Asynchronously starts workspace from the given configuration. * * @param config workspace configuration from which workspace is created and started * @param namespace workspace name is unique in this namespace * @return starting workspace * @throws NullPointerException when {@code workspaceId} is null * @throws NotFoundException when workspace with given {@code workspaceId} doesn't exist * @throws ServerException when any other error occurs during workspace start */ public WorkspaceImpl startWorkspace( WorkspaceConfig config, String namespace, boolean isTemporary, Map<String, String> options) throws ServerException, NotFoundException, ConflictException, ValidationException { requireNonNull(config, "Required non-null configuration"); requireNonNull(namespace, "Required non-null namespace"); validator.validateConfig(config); final WorkspaceImpl workspace = doCreateWorkspace( config, accountManager.getByName(namespace), Collections.emptyMap(), isTemporary); startAsync(workspace, workspace.getConfig().getDefaultEnv(), options); return normalizeState(workspace, true); }
/** * Creates a new {@link Workspace} instance based on the given configuration and the instance * attributes. * * @param config the workspace config to create the new workspace instance * @param namespace workspace name is unique in this namespace * @param attributes workspace instance attributes * @return new workspace instance * @throws NullPointerException when either {@code config} or {@code namespace} is null * @throws NotFoundException when account with given id was not found * @throws ConflictException when any conflict occurs (e.g Workspace with such name already exists * for {@code owner}) * @throws ServerException when any other error occurs * @throws ValidationException when incoming configuration or attributes are not valid */ @Traced public WorkspaceImpl createWorkspace( WorkspaceConfig config, String namespace, @Nullable Map<String, String> attributes) throws ServerException, NotFoundException, ConflictException, ValidationException { requireNonNull(config, "Required non-null config"); requireNonNull(namespace, "Required non-null namespace"); validator.validateConfig(config); if (attributes != null) { validator.validateAttributes(attributes); } return doCreateWorkspace(config, accountManager.getByName(namespace), attributes, false); }
@Override public WorkspaceImpl createWorkspace( WorkspaceConfig config, String namespace, @Nullable Map<String, String> attributes) throws ServerException, ConflictException, NotFoundException, ValidationException { checkMaxEnvironmentRam(config); String accountId = accountManager.getByName(namespace).getId(); try (@SuppressWarnings("unused") Unlocker u = resourcesLocks.lock(accountId)) { checkWorkspaceResourceAvailability(accountId); return super.createWorkspace(config, namespace, attributes); } }
@Override public WorkspaceImpl startWorkspace( WorkspaceConfig config, String namespace, boolean isTemporary, Map<String, String> options) throws ServerException, NotFoundException, ConflictException, ValidationException { checkMaxEnvironmentRam(config); String accountId = accountManager.getByName(namespace).getId(); try (@SuppressWarnings("unused") Unlocker u = resourcesLocks.lock(accountId)) { checkWorkspaceResourceAvailability(accountId); checkRuntimeResourceAvailability(accountId); checkRamResourcesAvailability(accountId, namespace, config, null); return super.startWorkspace(config, namespace, isTemporary, options); } }