Search in sources :

Example 11 with ProvidedResourcesImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl 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)

Example 12 with ProvidedResourcesImpl

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

the class FreeResourcesProviderTest method shouldRewriteDefaultResourcesWithFreeResourcesLimitIfItExists.

@Test
public void shouldRewriteDefaultResourcesWithFreeResourcesLimitIfItExists() throws Exception {
    // given
    when(accountManager.getById(any())).thenReturn(account);
    when(freeResourcesLimitManager.get(any())).thenReturn(new FreeResourcesLimitImpl("user123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, 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, "user123", "user123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
    verify(freeResourcesLimitManager).get("user123");
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) 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 13 with ProvidedResourcesImpl

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

the class FreeResourcesProviderTest method shouldProvideResourcesFromFreeResourcesLimitIfItExists.

@Test
public void shouldProvideResourcesFromFreeResourcesLimitIfItExists() throws Exception {
    // given
    when(account.getType()).thenReturn("anotherTestType");
    when(accountManager.getById(any())).thenReturn(account);
    when(freeResourcesLimitManager.get(any())).thenReturn(new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
    // when
    List<ProvidedResources> result = provider.getResources("account123");
    // then
    assertEquals(result.size(), 1);
    ProvidedResources providedResources = result.get(0);
    assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, "account123", "account123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
    verify(freeResourcesLimitManager).get("account123");
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) 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 14 with ProvidedResourcesImpl

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

the class FreeResourcesProvider method getResources.

@Override
public List<ProvidedResources> getResources(String accountId) throws ServerException, NotFoundException {
    Map<String, ResourceImpl> freeResources = new HashMap<>();
    String limitId = null;
    try {
        FreeResourcesLimit resourcesLimit = freeResourcesLimitManager.get(accountId);
        for (Resource resource : resourcesLimit.getResources()) {
            freeResources.put(resource.getType(), new ResourceImpl(resource));
        }
        limitId = resourcesLimit.getAccountId();
    } catch (NotFoundException ignored) {
    // there is no resources limit for given account
    }
    // add default resources which are not specified by limit
    for (ResourceImpl resource : getDefaultResources(accountId)) {
        freeResources.putIfAbsent(resource.getType(), resource);
    }
    if (!freeResources.isEmpty()) {
        return singletonList(new ProvidedResourcesImpl(FREE_RESOURCES_PROVIDER, limitId, accountId, -1L, -1L, freeResources.values()));
    } else {
        return emptyList();
    }
}
Also used : ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) HashMap(java.util.HashMap) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) Resource(org.eclipse.che.multiuser.resource.model.Resource) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 15 with ProvidedResourcesImpl

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

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)

Aggregations

ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)16 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)14 Test (org.testng.annotations.Test)10 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)8 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 AbstractModule (com.google.inject.AbstractModule)2 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)2 PostConstruct (jakarta.annotation.PostConstruct)2 AccountManager (org.eclipse.che.account.api.AccountManager)2 AccountModule (org.eclipse.che.account.api.AccountModule)2 Account (org.eclipse.che.account.shared.model.Account)2 AccountDao (org.eclipse.che.account.spi.AccountDao)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ServerException (org.eclipse.che.api.core.ServerException)2 EventService (org.eclipse.che.api.core.notification.EventService)2 UserDevfileDao (org.eclipse.che.api.devfile.server.spi.UserDevfileDao)2 FactoryJpaModule (org.eclipse.che.api.factory.server.jpa.FactoryJpaModule)2 FactoryDao (org.eclipse.che.api.factory.server.spi.FactoryDao)2 SshJpaModule (org.eclipse.che.api.ssh.server.jpa.SshJpaModule)2 SshDao (org.eclipse.che.api.ssh.server.spi.SshDao)2