use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class RuntimeResourceUsageTracker method getUsedResource.
@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
final long currentlyUsedRuntimes = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), false, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).count();
if (currentlyUsedRuntimes > 0) {
return Optional.of(new ResourceImpl(RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT));
} else {
return Optional.empty();
}
}
use of org.eclipse.che.account.shared.model.Account in project devspaces-images by redhat-developer.
the class JpaWorkerDaoTest method shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Database exception")
public void shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod() throws Exception {
final Account account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspaceId").setAccount(account).build();
// Persist the account
manager.getTransaction().begin();
manager.persist(account);
manager.getTransaction().commit();
manager.clear();
// Persist the workspace
manager.getTransaction().begin();
manager.persist(workspace);
manager.getTransaction().commit();
manager.clear();
final UserImpl user = new UserImpl("user0", "user0@com.com", "usr0");
// Persist the user
manager.getTransaction().begin();
manager.persist(user);
manager.getTransaction().commit();
manager.clear();
// Persist the worker
WorkerImpl worker = new WorkerImpl("workspaceId", "user0", Collections.singletonList(SET_PERMISSIONS));
manager.getTransaction().begin();
manager.persist(worker);
manager.getTransaction().commit();
manager.clear();
workerDao.exists("user0", "workspaceId", SET_PERMISSIONS);
}
use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
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);
}
use of org.eclipse.che.account.shared.model.Account in project che-server by eclipse-che.
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 che-server by eclipse-che.
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