Search in sources :

Example 1 with ResourcesDetailsImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl 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()));
}
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 2 with ResourcesDetailsImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl in project che-server by eclipse-che.

the class ResourceServiceTest method testGetsResourceDetails.

@Test
public void testGetsResourceDetails() throws Exception {
    // given
    final ResourceDto testResource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1234).withUnit("mb");
    final ResourcesDetailsDto toFetch = DtoFactory.newDto(ResourcesDetailsDto.class).withAccountId("account123").withProvidedResources(singletonList(DtoFactory.newDto(ProvidedResourcesDto.class).withId("resource123").withProviderId("provider").withOwner("account123").withStartTime(123L).withEndTime(321L).withResources(singletonList(testResource)))).withTotalResources(singletonList(testResource));
    // when
    when(resourceManager.getResourceDetails(eq("account123"))).thenReturn(new ResourcesDetailsImpl(toFetch));
    // then
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/details");
    assertEquals(response.statusCode(), 200);
    final ResourcesDetailsDto resourceDetailsDto = DtoFactory.getInstance().createDtoFromJson(response.body().print(), ResourcesDetailsDto.class);
    assertEquals(resourceDetailsDto, toFetch);
    verify(resourceManager).getResourceDetails("account123");
}
Also used : Response(io.restassured.response.Response) ResourcesDetailsDto(org.eclipse.che.multiuser.resource.shared.dto.ResourcesDetailsDto) ProvidedResourcesDto(org.eclipse.che.multiuser.resource.shared.dto.ProvidedResourcesDto) ResourcesDetailsImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 3 with ResourcesDetailsImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl 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 4 with ResourcesDetailsImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl in project devspaces-images by redhat-developer.

the class ResourceServiceTest method testGetsResourceDetails.

@Test
public void testGetsResourceDetails() throws Exception {
    // given
    final ResourceDto testResource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1234).withUnit("mb");
    final ResourcesDetailsDto toFetch = DtoFactory.newDto(ResourcesDetailsDto.class).withAccountId("account123").withProvidedResources(singletonList(DtoFactory.newDto(ProvidedResourcesDto.class).withId("resource123").withProviderId("provider").withOwner("account123").withStartTime(123L).withEndTime(321L).withResources(singletonList(testResource)))).withTotalResources(singletonList(testResource));
    // when
    when(resourceManager.getResourceDetails(eq("account123"))).thenReturn(new ResourcesDetailsImpl(toFetch));
    // then
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/details");
    assertEquals(response.statusCode(), 200);
    final ResourcesDetailsDto resourceDetailsDto = DtoFactory.getInstance().createDtoFromJson(response.body().print(), ResourcesDetailsDto.class);
    assertEquals(resourceDetailsDto, toFetch);
    verify(resourceManager).getResourceDetails("account123");
}
Also used : Response(io.restassured.response.Response) ResourcesDetailsDto(org.eclipse.che.multiuser.resource.shared.dto.ResourcesDetailsDto) ProvidedResourcesDto(org.eclipse.che.multiuser.resource.shared.dto.ProvidedResourcesDto) ResourcesDetailsImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Aggregations

ResourcesDetailsImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl)4 Response (io.restassured.response.Response)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 AccountManager (org.eclipse.che.account.api.AccountManager)2 Account (org.eclipse.che.account.shared.model.Account)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 AvailableResourcesProvider (org.eclipse.che.multiuser.resource.api.AvailableResourcesProvider)2 ResourceAggregator (org.eclipse.che.multiuser.resource.api.ResourceAggregator)2 ResourceUsageTracker (org.eclipse.che.multiuser.resource.api.ResourceUsageTracker)2 ResourcesProvider (org.eclipse.che.multiuser.resource.api.ResourcesProvider)2 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)2 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)2