Search in sources :

Example 6 with Account

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

the class JpaUserDevfileDao method create.

@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
    requireNonNull(userDevfile);
    try {
        Account account = accountDao.getByName(userDevfile.getNamespace());
        UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
        doCreate(userDevfileImpl);
        return userDevfileImpl;
    } catch (DuplicateKeyException ex) {
        throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
    } catch (IntegrityConstraintViolationException ex) {
        throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getMessage(), ex);
    } catch (NotFoundException e) {
        throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) DuplicateKeyException(org.eclipse.che.core.db.jpa.DuplicateKeyException)

Example 7 with Account

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

the class JpaUserDevfileDao method create.

@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
    requireNonNull(userDevfile);
    try {
        Account account = accountDao.getByName(userDevfile.getNamespace());
        UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
        doCreate(userDevfileImpl);
        return userDevfileImpl;
    } catch (DuplicateKeyException ex) {
        throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
    } catch (IntegrityConstraintViolationException ex) {
        throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getMessage(), ex);
    } catch (NotFoundException e) {
        throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) DuplicateKeyException(org.eclipse.che.core.db.jpa.DuplicateKeyException)

Example 8 with Account

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

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 9 with Account

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

the class ResourceManager method getResourceDetails.

/**
 * Returns detailed information about resources which given account can use.
 *
 * @param accountId account id
 * @return detailed information about resources which can be used by given account
 * @throws NotFoundException when account with specified id was not found
 * @throws ServerException when some exception occurs
 */
public ResourcesDetails getResourceDetails(String accountId) throws NotFoundException, ServerException {
    final List<ProvidedResources> resources = new ArrayList<>();
    for (ResourcesProvider resourcesProvider : resourcesProviders) {
        resources.addAll(resourcesProvider.getResources(accountId));
    }
    final List<Resource> allResources = resources.stream().flatMap(providedResources -> providedResources.getResources().stream()).collect(Collectors.toList());
    return new ResourcesDetailsImpl(accountId, resources, new ArrayList<>(resourceAggregator.aggregateByType(allResources).values()));
}
Also used : ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) Resource(org.eclipse.che.multiuser.resource.model.Resource) Set(java.util.Set) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) AvailableResourcesProvider(org.eclipse.che.multiuser.resource.api.AvailableResourcesProvider) NoEnoughResourcesException(org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ResourcesDetailsImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) ResourcesProvider(org.eclipse.che.multiuser.resource.api.ResourcesProvider) Map(java.util.Map) Optional(java.util.Optional) ResourcesDetails(org.eclipse.che.multiuser.resource.model.ResourcesDetails) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) ResourceAggregator(org.eclipse.che.multiuser.resource.api.ResourceAggregator) AvailableResourcesProvider(org.eclipse.che.multiuser.resource.api.AvailableResourcesProvider) ResourcesProvider(org.eclipse.che.multiuser.resource.api.ResourcesProvider) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) ArrayList(java.util.ArrayList) Resource(org.eclipse.che.multiuser.resource.model.Resource) ResourcesDetailsImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl)

Example 10 with Account

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

the class RamResourceUsageTracker method getUsedResource.

@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    List<WorkspaceImpl> activeWorkspaces = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), true, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).collect(Collectors.toList());
    long currentlyUsedRamMB = 0;
    for (WorkspaceImpl activeWorkspace : activeWorkspaces) {
        if (WorkspaceStatus.STARTING.equals(activeWorkspace.getStatus())) {
            // starting workspace may not have all machine in runtime
            // it is need to calculate ram from environment config
            WorkspaceConfigImpl config = activeWorkspace.getConfig();
            if (config != null) {
                final EnvironmentImpl startingEnvironment = config.getEnvironments().get(activeWorkspace.getRuntime().getActiveEnv());
                if (startingEnvironment != null) {
                    currentlyUsedRamMB += environmentRamCalculator.calculate(startingEnvironment);
                }
            }
        // Estimation of memory for starting workspace with Devfile is not implemented yet
        // just ignore such
        } else {
            currentlyUsedRamMB += environmentRamCalculator.calculate(activeWorkspace.getRuntime());
        }
    }
    if (currentlyUsedRamMB > 0) {
        return Optional.of(new ResourceImpl(RamResourceType.ID, currentlyUsedRamMB, RamResourceType.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) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) 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) 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) RamResourceType(org.eclipse.che.multiuser.resource.api.type.RamResourceType) STOPPED(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED) 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) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

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