use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class RuntimeResourceUsageTracker method getUsedResource.
@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
final Account account = accountManager.getById(accountId);
final long currentlyUsedRuntimes = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), false, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).count();
if (currentlyUsedRuntimes > 0) {
return Optional.of(new ResourceImpl(RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT));
} else {
return Optional.empty();
}
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class FreeResourcesLimitServiceTest method shouldReturnResourcesLimits.
@Test
public void shouldReturnResourcesLimits() throws Exception {
FreeResourcesLimit resourcesLimit1 = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
FreeResourcesLimit resourcesLimit2 = new FreeResourcesLimitImpl("account321", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 2000, "unit")));
doReturn(new Page<>(Arrays.asList(resourcesLimit1, resourcesLimit2), 1, 2, 2)).when(freeResourcesLimitManager).getAll(anyInt(), anyInt());
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/free?skipCount=1&maxItems=5");
assertEquals(response.statusCode(), 200);
final List<FreeResourcesLimitDto> freeResourcesLimits = unwrapDtoList(response, FreeResourcesLimitDto.class);
assertEquals(freeResourcesLimits.size(), 2);
assertTrue(freeResourcesLimits.contains(DtoConverter.asDto(resourcesLimit1)));
assertTrue(freeResourcesLimits.contains(DtoConverter.asDto(resourcesLimit2)));
verify(freeResourcesLimitManager).getAll(5, 1);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
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");
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
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");
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
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");
}
Aggregations