use of org.eclipse.che.multiuser.resource.model.Resource in project che-server by eclipse-che.
the class ResourceManager method getUsedResources.
/**
* Returns list of resources which are used by given account.
*
* @param accountId id of account
* @return list of resources which are used 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> getUsedResources(String accountId) throws NotFoundException, ServerException {
List<Resource> usedResources = new ArrayList<>();
for (ResourceUsageTracker usageTracker : usageTrackers) {
Optional<Resource> usedResource = usageTracker.getUsedResource(accountId);
usedResource.ifPresent(usedResources::add);
}
return usedResources;
}
use of org.eclipse.che.multiuser.resource.model.Resource in project che-server by eclipse-che.
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.multiuser.resource.model.Resource in project che-server by eclipse-che.
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.multiuser.resource.model.Resource in project che-server by eclipse-che.
the class AbstractExhaustibleResourceTest method shouldReturnResourceWithMinusOneAmountWhenTotalResourceHasMinusOneOnResourcesDeduction.
@Test
public void shouldReturnResourceWithMinusOneAmountWhenTotalResourceHasMinusOneOnResourcesDeduction() throws Exception {
final Resource deducted = resourceType.deduct(new ResourceImpl(TestResourceType.ID, -1, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
assertEquals(deducted.getType(), TestResourceType.ID);
assertEquals(deducted.getAmount(), -1);
assertEquals(deducted.getUnit(), TestResourceType.UNIT);
}
use of org.eclipse.che.multiuser.resource.model.Resource in project che-server by eclipse-che.
the class AbstractExhaustibleResourceTest method shouldFindDifferenceResourcesAmountsOnResourcesDeduction.
@Test
public void shouldFindDifferenceResourcesAmountsOnResourcesDeduction() throws Exception {
final Resource deducted = resourceType.deduct(new ResourceImpl(TestResourceType.ID, 1000, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
assertEquals(deducted.getType(), TestResourceType.ID);
assertEquals(deducted.getAmount(), 500);
assertEquals(deducted.getUnit(), TestResourceType.UNIT);
}
Aggregations