Search in sources :

Example 6 with ProvidedResources

use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project devspaces-images by redhat-developer.

the class FreeResourcesProviderTest method shouldNotProvideDefaultResourcesForAccountThatDoesNotHaveDefaultResourcesProvider.

@Test
public void shouldNotProvideDefaultResourcesForAccountThatDoesNotHaveDefaultResourcesProvider() throws Exception {
    // given
    when(account.getType()).thenReturn("anotherTestType");
    when(accountManager.getById(any())).thenReturn(account);
    doThrow(new NotFoundException("not found")).when(freeResourcesLimitManager).get(any());
    // when
    List<ProvidedResources> result = provider.getResources("account123");
    // then
    assertTrue(result.isEmpty());
}
Also used : ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 7 with ProvidedResources

use of org.eclipse.che.multiuser.resource.model.ProvidedResources 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 8 with ProvidedResources

use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.

the class FreeResourcesProviderTest method shouldNotProvideDefaultResourcesForAccountThatDoesNotHaveDefaultResourcesProvider.

@Test
public void shouldNotProvideDefaultResourcesForAccountThatDoesNotHaveDefaultResourcesProvider() throws Exception {
    // given
    when(account.getType()).thenReturn("anotherTestType");
    when(accountManager.getById(any())).thenReturn(account);
    doThrow(new NotFoundException("not found")).when(freeResourcesLimitManager).get(any());
    // when
    List<ProvidedResources> result = provider.getResources("account123");
    // then
    assertTrue(result.isEmpty());
}
Also used : ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 9 with ProvidedResources

use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.

the class SuborganizationResourcesProviderTest method shouldProvideResourcesForSuborganizationalAccount.

@Test
public void shouldProvideResourcesForSuborganizationalAccount() throws Exception {
    // given
    when(account.getType()).thenReturn(OrganizationImpl.ORGANIZATIONAL_ACCOUNT);
    when(organization.getParent()).thenReturn("parentOrg");
    final ResourceImpl parentNotCapedResource = new ResourceImpl("test", 1234, "unit");
    final ResourceImpl parentCapedResource = new ResourceImpl("caped", 20, "unit");
    final ResourceImpl parentUnlimitedCapedResource = new ResourceImpl("unlimited", -1, "unit");
    doReturn(asList(parentNotCapedResource, parentCapedResource, parentUnlimitedCapedResource)).when(resourceManager).getTotalResources(anyString());
    final ResourceImpl capedResourceCap = new ResourceImpl("caped", 10, "unit");
    final ResourceImpl unlimitedCapedResourceCap = new ResourceImpl("unlimited", 40, "unit");
    doReturn(asList(capedResourceCap, unlimitedCapedResourceCap)).when(resourcesDistributor).getResourcesCaps(any());
    // when
    final List<ProvidedResources> providedResources = suborganizationResourcesProvider.getResources("organization123");
    // then
    assertEquals(providedResources.size(), 1);
    assertEquals(providedResources.get(0), new ProvidedResourcesImpl(SuborganizationResourcesProvider.PARENT_RESOURCES_PROVIDER, null, "organization123", -1L, -1L, asList(parentNotCapedResource, capedResourceCap, unlimitedCapedResourceCap)));
    verify(accountManager).getById("organization123");
    verify(organizationManager).getById("organization123");
    verify(resourcesDistributor).getResourcesCaps("organization123");
    verify(resourceManager).getTotalResources("parentOrg");
}
Also used : ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) Test(org.testng.annotations.Test)

Example 10 with ProvidedResources

use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project devspaces-images by redhat-developer.

the class FreeResourcesProviderTest method shouldProvideDefaultResourcesIfThereAreProviderForThisAccountType.

@Test
public void shouldProvideDefaultResourcesIfThereAreProviderForThisAccountType() throws Exception {
    // given
    when(accountManager.getById(any())).thenReturn(account);
    when(freeResourcesLimitManager.get(any())).thenThrow(new NotFoundException("not found"));
    when(defaultResourcesProvider.getResources(any())).thenReturn(singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1020, TEST_RESOURCE_UNIT)));
    // when
    List<ProvidedResources> result = provider.getResources("user123");
    // then
    assertEquals(result.size(), 1);
    ProvidedResources providedResources = result.get(0);
    assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, null, "user123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1020, TEST_RESOURCE_UNIT))));
    verify(freeResourcesLimitManager).get("user123");
}
Also used : ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Aggregations

ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)14 Test (org.testng.annotations.Test)12 NotFoundException (org.eclipse.che.api.core.NotFoundException)8 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)8 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)8 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)4 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 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