Search in sources :

Example 1 with ResourceDto

use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.

the class OrganizationResourcesDistributionService method capResources.

@POST
@Path("/{suborganizationId}/cap")
@Consumes(APPLICATION_JSON)
@Operation(summary = "Cap usage of shared resources.. By default suborganization is able to use all parent organization resources." + "Cap allow to limit usage of shared resources by suborganization.", responses = { @ApiResponse(responseCode = "204", description = "Resources successfully capped"), @ApiResponse(responseCode = "400", description = "Missed required parameters, parameters are not valid"), @ApiResponse(responseCode = "404", description = "Specified organization was not found"), @ApiResponse(responseCode = "409", description = "Specified organization is root organization"), @ApiResponse(responseCode = "409", description = "Suborganization is using shared resources"), @ApiResponse(responseCode = "500", description = "Internal server error occurred") })
public void capResources(@Parameter(description = "Suborganization id") @PathParam("suborganizationId") String suborganizationId, @Parameter(description = "Resources to cap") List<ResourceDto> resourcesCap) throws BadRequestException, NotFoundException, ConflictException, ServerException {
    checkArgument(resourcesCap != null, "Missed resources caps.");
    Set<String> resourcesToSet = new HashSet<>();
    for (ResourceDto resource : resourcesCap) {
        if (!resourcesToSet.add(resource.getType())) {
            throw new BadRequestException(format("Resources to cap must contain only one resource with type '%s'.", resource.getType()));
        }
        resourceValidator.validate(resource);
    }
    resourcesDistributor.capResources(suborganizationId, resourcesCap);
}
Also used : BadRequestException(org.eclipse.che.api.core.BadRequestException) HashSet(java.util.HashSet) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with ResourceDto

use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.

the class ResourceServiceTest method shouldReturnTotalResourcesForGivenAccount.

@Test
public void shouldReturnTotalResourcesForGivenAccount() throws Exception {
    doReturn(singletonList(resource)).when(resourceManager).getTotalResources(any());
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123");
    assertEquals(response.statusCode(), 200);
    verify(resourceManager).getTotalResources(eq("account123"));
    final List<ResourceDto> resources = unwrapDtoList(response, ResourceDto.class);
    assertEquals(resources.size(), 1);
    final ResourceDto fetchedResource = resources.get(0);
    assertEquals(fetchedResource.getType(), RESOURCE_TYPE);
    assertEquals(new Long(fetchedResource.getAmount()), RESOURCE_AMOUNT);
    assertEquals(fetchedResource.getUnit(), RESOURCE_UNIT);
}
Also used : Response(io.restassured.response.Response) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 3 with ResourceDto

use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.

the class ResourceServiceTest method shouldReturnAvailableResourcesForGivenAccount.

@Test
public void shouldReturnAvailableResourcesForGivenAccount() throws Exception {
    doReturn(singletonList(resource)).when(resourceManager).getAvailableResources(any());
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/available");
    assertEquals(response.statusCode(), 200);
    verify(resourceManager).getAvailableResources(eq("account123"));
    final List<ResourceDto> resources = unwrapDtoList(response, ResourceDto.class);
    assertEquals(resources.size(), 1);
    final ResourceDto fetchedResource = resources.get(0);
    assertEquals(fetchedResource.getType(), RESOURCE_TYPE);
    assertEquals(new Long(fetchedResource.getAmount()), RESOURCE_AMOUNT);
    assertEquals(fetchedResource.getUnit(), RESOURCE_UNIT);
}
Also used : Response(io.restassured.response.Response) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 4 with ResourceDto

use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto in project che-server by eclipse-che.

the class ResourceServiceTest method testGetsResourceDetails.

@Test
public void testGetsResourceDetails() throws Exception {
    // given
    final ResourceDto testResource = DtoFactory.newDto(ResourceDto.class).withType("test").withAmount(1234).withUnit("mb");
    final ResourcesDetailsDto toFetch = DtoFactory.newDto(ResourcesDetailsDto.class).withAccountId("account123").withProvidedResources(singletonList(DtoFactory.newDto(ProvidedResourcesDto.class).withId("resource123").withProviderId("provider").withOwner("account123").withStartTime(123L).withEndTime(321L).withResources(singletonList(testResource)))).withTotalResources(singletonList(testResource));
    // when
    when(resourceManager.getResourceDetails(eq("account123"))).thenReturn(new ResourcesDetailsImpl(toFetch));
    // then
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/account123/details");
    assertEquals(response.statusCode(), 200);
    final ResourcesDetailsDto resourceDetailsDto = DtoFactory.getInstance().createDtoFromJson(response.body().print(), ResourcesDetailsDto.class);
    assertEquals(resourceDetailsDto, toFetch);
    verify(resourceManager).getResourceDetails("account123");
}
Also used : Response(io.restassured.response.Response) ResourcesDetailsDto(org.eclipse.che.multiuser.resource.shared.dto.ResourcesDetailsDto) ProvidedResourcesDto(org.eclipse.che.multiuser.resource.shared.dto.ProvidedResourcesDto) ResourcesDetailsImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 5 with ResourceDto

use of org.eclipse.che.multiuser.resource.shared.dto.ResourceDto 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)

Aggregations

ResourceDto (org.eclipse.che.multiuser.resource.shared.dto.ResourceDto)20 Test (org.testng.annotations.Test)18 Response (io.restassured.response.Response)12 Operation (io.swagger.v3.oas.annotations.Operation)2 Consumes (jakarta.ws.rs.Consumes)2 POST (jakarta.ws.rs.POST)2 Path (jakarta.ws.rs.Path)2 HashSet (java.util.HashSet)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 ServiceError (org.eclipse.che.api.core.rest.shared.dto.ServiceError)2 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)2 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)2 ProvidedResourcesDto (org.eclipse.che.multiuser.resource.shared.dto.ProvidedResourcesDto)2 ResourcesDetailsDto (org.eclipse.che.multiuser.resource.shared.dto.ResourcesDetailsDto)2 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)2 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)2 ResourcesDetailsImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourcesDetailsImpl)2