use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class ResourcesLocks method lock.
/**
* Acquire resources lock for specified account.
*
* @param accountId account id to lock resources
* @return lock for unlocking resources when resources operation finishes
* @throws NotFoundException when account with specified {@code account id} was not found
* @throws ServerException when any other error occurs
*/
public Unlocker lock(String accountId) throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
final ResourceLockKeyProvider resourceLockKeyProvider = accountTypeToLockProvider.get(account.getType());
String lockKey;
if (resourceLockKeyProvider == null) {
// this account type doesn't have custom lock provider.
// Lock resources by current account
lockKey = accountId;
} else {
lockKey = resourceLockKeyProvider.getLockKey(accountId);
}
return stripedLocks.writeLock(lockKey);
}
use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class WorkspaceResourceUsageTracker method getUsedResource.
@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
final List<WorkspaceImpl> accountWorkspaces = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), false, maxItems, skipCount)).collect(Collectors.toList());
if (!accountWorkspaces.isEmpty()) {
return Optional.of(new ResourceImpl(WorkspaceResourceType.ID, accountWorkspaces.size(), WorkspaceResourceType.UNIT));
} else {
return Optional.empty();
}
}
use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class FreeResourcesProvider method getDefaultResources.
private List<ResourceImpl> getDefaultResources(String accountId) throws NotFoundException, ServerException {
List<ResourceImpl> defaultResources = new ArrayList<>();
final Account account = accountManager.getById(accountId);
final DefaultResourcesProvider defaultResourcesProvider = defaultResourcesProviders.get(account.getType());
if (defaultResourcesProvider != null) {
defaultResources.addAll(defaultResourcesProvider.getResources(accountId));
}
return defaultResources;
}
use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class WorkspacePermissionsFilter method checkAccountPermissions.
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);
}
use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class SuborganizationResourcesProvider method getResources.
@Override
public List<ProvidedResources> getResources(String accountId) throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
String parent;
if (!OrganizationImpl.ORGANIZATIONAL_ACCOUNT.equals(account.getType()) || (parent = organizationManager.getById(accountId).getParent()) == null) {
return emptyList();
}
// given account is suborganization's account and can have resources provided by parent
List<? extends Resource> parentTotalResources = resourceManagerProvider.get().getTotalResources(parent);
if (!parentTotalResources.isEmpty()) {
try {
List<? extends Resource> resourcesCaps = distributorProvider.get().getResourcesCaps(accountId);
return singletonList(new ProvidedResourcesImpl(PARENT_RESOURCES_PROVIDER, null, accountId, -1L, -1L, cap(parentTotalResources, resourcesCaps)));
} catch (ConflictException e) {
throw new ServerException(e.getLocalizedMessage());
}
}
return emptyList();
}
Aggregations