Search in sources :

Example 1 with ResourceImpl

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();
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) RuntimeResourceType(org.eclipse.che.multiuser.resource.api.type.RuntimeResourceType) Provider(javax.inject.Provider) Resource(org.eclipse.che.multiuser.resource.model.Resource) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Singleton(javax.inject.Singleton) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Pages(org.eclipse.che.api.core.Pages) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) STOPPED(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED) Account(org.eclipse.che.account.shared.model.Account) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)

Example 2 with ResourceImpl

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);
}
Also used : Response(io.restassured.response.Response) 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) Test(org.testng.annotations.Test)

Example 3 with ResourceImpl

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");
}
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 4 with ResourceImpl

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");
}
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 5 with ResourceImpl

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");
}
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

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