Search in sources :

Example 16 with Account

use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.

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();
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) Provider(javax.inject.Provider) Resource(org.eclipse.che.multiuser.resource.model.Resource) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Pages(org.eclipse.che.api.core.Pages) WorkspaceResourceType(org.eclipse.che.multiuser.resource.api.type.WorkspaceResourceType) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)

Example 17 with Account

use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.

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();
}
Also used : Account(org.eclipse.che.account.shared.model.Account) ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException)

Example 18 with Account

use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.

the class MultiUserWorkspaceActivityManager method getIdleTimeout.

@Override
protected long getIdleTimeout(String wsId) {
    List<? extends Resource> availableResources;
    try {
        WorkspaceImpl workspace = workspaceManager.getWorkspace(wsId);
        Account account = accountManager.getByName(workspace.getNamespace());
        availableResources = resourceManager.getAvailableResources(account.getId());
    } catch (NotFoundException | ServerException e) {
        LOG.error(e.getLocalizedMessage(), e);
        return defaultTimeout;
    }
    Optional<? extends Resource> timeoutOpt = availableResources.stream().filter(resource -> TimeoutResourceType.ID.equals(resource.getType())).findAny();
    if (timeoutOpt.isPresent()) {
        return timeoutOpt.get().getAmount() * 60 * 1000;
    } else {
        return defaultTimeout;
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) WorkspaceActivityDao(org.eclipse.che.api.workspace.activity.WorkspaceActivityDao) Logger(org.slf4j.Logger) ResourceManager(org.eclipse.che.multiuser.resource.api.usage.ResourceManager) Resource(org.eclipse.che.multiuser.resource.model.Resource) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Named(javax.inject.Named) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) WorkspaceActivityManager(org.eclipse.che.api.workspace.activity.WorkspaceActivityManager) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) TimeoutResourceType(org.eclipse.che.multiuser.resource.api.type.TimeoutResourceType) EventService(org.eclipse.che.api.core.notification.EventService) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 19 with Account

use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.

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);
}
Also used : Account(org.eclipse.che.account.shared.model.Account) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) AccountPermissionsChecker(org.eclipse.che.multiuser.api.permission.server.account.AccountPermissionsChecker)

Example 20 with Account

use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.

the class ResourceManager method getAvailableResources.

/**
 * Returns list of resources which are available for usage by given account.
 *
 * @param accountId id of account
 * @return list of resources which are available for usage by given account
 * @throws NotFoundException when account with specified id was not found
 * @throws ServerException when some exception occurred while resources fetching
 */
public List<? extends Resource> getAvailableResources(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    final AvailableResourcesProvider availableResourcesProvider = accountTypeToAvailableResourcesProvider.get(account.getType());
    if (availableResourcesProvider == null) {
        return defaultAvailableResourcesProvider.getAvailableResources(accountId);
    }
    return availableResourcesProvider.getAvailableResources(accountId);
}
Also used : Account(org.eclipse.che.account.shared.model.Account) AvailableResourcesProvider(org.eclipse.che.multiuser.resource.api.AvailableResourcesProvider)

Aggregations

Account (org.eclipse.che.account.shared.model.Account)26 ServerException (org.eclipse.che.api.core.ServerException)14 NotFoundException (org.eclipse.che.api.core.NotFoundException)12 Optional (java.util.Optional)10 Inject (javax.inject.Inject)10 Singleton (javax.inject.Singleton)10 AccountManager (org.eclipse.che.account.api.AccountManager)10 Resource (org.eclipse.che.multiuser.resource.model.Resource)10 List (java.util.List)8 WorkspaceManager (org.eclipse.che.api.workspace.server.WorkspaceManager)8 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)8 ResourceUsageTracker (org.eclipse.che.multiuser.resource.api.ResourceUsageTracker)8 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)8 Collectors (java.util.stream.Collectors)6 Provider (javax.inject.Provider)6 Pages (org.eclipse.che.api.core.Pages)6 ArrayList (java.util.ArrayList)4 ConflictException (org.eclipse.che.api.core.ConflictException)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)4 STOPPED (org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED)4