use of org.eclipse.che.multiuser.resource.model.ResourcesDetails 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.ResourcesDetails in project devspaces-images by redhat-developer.
the class ResourceManagerTest method testReturnsResourceDetailsForGivenAccount.
@Test
public void testReturnsResourceDetailsForGivenAccount() throws Exception {
final ResourceImpl testResource = new ResourceImpl("RAM", 1000, "mb");
final ResourceImpl reducedResource = new ResourceImpl("timeout", 2000, "m");
final ProvidedResourcesImpl providedResource = new ProvidedResourcesImpl("test", null, ACCOUNT_ID, 123L, 321L, singletonList(testResource));
when(resourcesProvider.getResources(eq(ACCOUNT_ID))).thenReturn(singletonList(providedResource));
when(resourceAggregator.aggregateByType(any())).thenReturn(ImmutableMap.of(reducedResource.getType(), reducedResource));
final ResourcesDetails resourcesDetails = resourceManager.getResourceDetails(ACCOUNT_ID);
verify(resourcesProvider).getResources(eq(ACCOUNT_ID));
verify(resourceAggregator).aggregateByType(eq(singletonList(testResource)));
assertEquals(resourcesDetails.getAccountId(), ACCOUNT_ID);
assertEquals(resourcesDetails.getProvidedResources().size(), 1);
assertEquals(resourcesDetails.getProvidedResources().get(0), providedResource);
assertEquals(resourcesDetails.getTotalResources().size(), 1);
assertEquals(resourcesDetails.getTotalResources().get(0), reducedResource);
}
use of org.eclipse.che.multiuser.resource.model.ResourcesDetails 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.multiuser.resource.model.ResourcesDetails in project che-server by eclipse-che.
the class ResourceManagerTest method testReturnsResourceDetailsForGivenAccount.
@Test
public void testReturnsResourceDetailsForGivenAccount() throws Exception {
final ResourceImpl testResource = new ResourceImpl("RAM", 1000, "mb");
final ResourceImpl reducedResource = new ResourceImpl("timeout", 2000, "m");
final ProvidedResourcesImpl providedResource = new ProvidedResourcesImpl("test", null, ACCOUNT_ID, 123L, 321L, singletonList(testResource));
when(resourcesProvider.getResources(eq(ACCOUNT_ID))).thenReturn(singletonList(providedResource));
when(resourceAggregator.aggregateByType(any())).thenReturn(ImmutableMap.of(reducedResource.getType(), reducedResource));
final ResourcesDetails resourcesDetails = resourceManager.getResourceDetails(ACCOUNT_ID);
verify(resourcesProvider).getResources(eq(ACCOUNT_ID));
verify(resourceAggregator).aggregateByType(eq(singletonList(testResource)));
assertEquals(resourcesDetails.getAccountId(), ACCOUNT_ID);
assertEquals(resourcesDetails.getProvidedResources().size(), 1);
assertEquals(resourcesDetails.getProvidedResources().get(0), providedResource);
assertEquals(resourcesDetails.getTotalResources().size(), 1);
assertEquals(resourcesDetails.getTotalResources().get(0), reducedResource);
}
Aggregations