Search in sources :

Example 26 with ResourceImpl

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

the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenResourcesToDeductListContainsNotSupportedResourceOnResourcesDeduction.

@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWhenResourcesToDeductListContainsNotSupportedResourceOnResourcesDeduction() throws Exception {
    // given
    final ResourceImpl dResource = mock(ResourceImpl.class);
    when(dResource.getType()).thenReturn("resourceD");
    // when
    resourceAggregator.deduct(singletonList(dResource), emptyList());
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 27 with ResourceImpl

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

the class ResourceAggregatorTest method shouldReturnMinResources.

@Test
public void shouldReturnMinResources() throws Exception {
    // given
    final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, 100, "unit");
    final ResourceImpl bResource = new ResourceImpl(B_RESOURCE_TYPE, 1000, "unit");
    final ResourceImpl minBResource = new ResourceImpl(B_RESOURCE_TYPE, 500, "unit");
    final ResourceImpl anotherBResource = new ResourceImpl(B_RESOURCE_TYPE, 2000, "unit");
    // when
    List<? extends Resource> min = resourceAggregator.min(asList(aResource, bResource, minBResource, anotherBResource));
    // then
    assertEquals(min.size(), 2);
    assertTrue(min.contains(aResource));
    assertTrue(min.contains(minBResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 28 with ResourceImpl

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

the class FreeResourceManagerTest method shouldStoreFreeResourcesLimit.

@Test
public void shouldStoreFreeResourcesLimit() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    ResourceDto resourceDto = DtoFactory.newDto(ResourceDto.class).withAmount(1).withType(TEST_RESOURCE_TYPE).withUnit("unit");
    FreeResourcesLimitDto freeResourcesLimitDto = DtoFactory.newDto(FreeResourcesLimitDto.class).withAccountId("account123").withResources(singletonList(resourceDto));
    // when
    FreeResourcesLimit storedLimit = manager.store(freeResourcesLimitDto);
    // then
    assertEquals(storedLimit, resourcesLimitImpl);
    verify(freeResourcesLimitDao).store(resourcesLimitImpl);
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) FreeResourcesLimitDto(org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 29 with ResourceImpl

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

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 30 with ResourceImpl

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

the class FreeResourcesProvider method getDefaultResources.

private List<ResourceImpl> getDefaultResources(String accountId) throws NotFoundException, ServerException {
    List<ResourceImpl> defaultResources = new ArrayList<>();
    final Account account = accountManager.getById(accountId);
    final DefaultResourcesProvider defaultResourcesProvider = defaultResourcesProviders.get(account.getType());
    if (defaultResourcesProvider != null) {
        defaultResources.addAll(defaultResourcesProvider.getResources(accountId));
    }
    return defaultResources;
}
Also used : Account(org.eclipse.che.account.shared.model.Account) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ArrayList(java.util.ArrayList)

Aggregations

ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)138 Test (org.testng.annotations.Test)116 Resource (org.eclipse.che.multiuser.resource.model.Resource)24 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)20 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)20 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)14 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)12 NotFoundException (org.eclipse.che.api.core.NotFoundException)10 AccountManager (org.eclipse.che.account.api.AccountManager)8 Account (org.eclipse.che.account.shared.model.Account)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)8 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)8 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)8 Response (io.restassured.response.Response)6 Optional (java.util.Optional)6 Inject (javax.inject.Inject)6 Provider (javax.inject.Provider)6 Singleton (javax.inject.Singleton)6 Pages (org.eclipse.che.api.core.Pages)6