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()));
}
}
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()));
}
}
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;
}
}
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()));
}
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();
}
}
Aggregations