Search in sources :

Example 1 with ContainersResponse

use of org.apache.hadoop.ozone.recon.api.types.ContainersResponse in project ozone by apache.

the class TestContainerEndpoint method testGetContainers.

@Test
public void testGetContainers() {
    Response response = containerEndpoint.getContainers(-1, 0L);
    ContainersResponse responseObject = (ContainersResponse) response.getEntity();
    ContainersResponse.ContainersResponseData data = responseObject.getContainersResponseData();
    assertEquals(2, data.getTotalCount());
    List<ContainerMetadata> containers = new ArrayList<>(data.getContainers());
    Iterator<ContainerMetadata> iterator = containers.iterator();
    ContainerMetadata containerMetadata = iterator.next();
    assertEquals(1L, containerMetadata.getContainerID());
    // Number of keys for CID:1 should be 3 because of two different versions
    // of key_two stored in CID:1
    assertEquals(3L, containerMetadata.getNumberOfKeys());
    containerMetadata = iterator.next();
    assertEquals(2L, containerMetadata.getContainerID());
    assertEquals(2L, containerMetadata.getNumberOfKeys());
    // test if limit works as expected
    response = containerEndpoint.getContainers(1, 0L);
    responseObject = (ContainersResponse) response.getEntity();
    data = responseObject.getContainersResponseData();
    containers = new ArrayList<>(data.getContainers());
    assertEquals(1, containers.size());
    assertEquals(2, data.getTotalCount());
}
Also used : MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) Response(javax.ws.rs.core.Response) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) ArrayList(java.util.ArrayList) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) UnhealthyContainerMetadata(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata) MissingContainerMetadata(org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata) ContainerMetadata(org.apache.hadoop.ozone.recon.api.types.ContainerMetadata) Test(org.junit.Test)

Example 2 with ContainersResponse

use of org.apache.hadoop.ozone.recon.api.types.ContainersResponse in project ozone by apache.

the class ContainerEndpoint method getContainers.

/**
 * Return @{@link org.apache.hadoop.ozone.recon.api.types.ContainerMetadata}
 * for the containers starting from the given "prev-key" query param for the
 * given "limit". The given "prev-key" is skipped from the results returned.
 *
 * @param limit max no. of containers to get.
 * @param prevKey the containerID after which results are returned.
 * @return {@link Response}
 */
@GET
public Response getContainers(@DefaultValue(DEFAULT_FETCH_COUNT) @QueryParam(RECON_QUERY_LIMIT) int limit, @DefaultValue(PREV_CONTAINER_ID_DEFAULT_VALUE) @QueryParam(RECON_QUERY_PREVKEY) long prevKey) {
    Map<Long, ContainerMetadata> containersMap;
    long containersCount;
    try {
        containersMap = reconContainerMetadataManager.getContainers(limit, prevKey);
        containersCount = reconContainerMetadataManager.getCountForContainers();
    } catch (IOException ioEx) {
        throw new WebApplicationException(ioEx, Response.Status.INTERNAL_SERVER_ERROR);
    }
    ContainersResponse containersResponse = new ContainersResponse(containersCount, containersMap.values());
    return Response.ok(containersResponse).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) IOException(java.io.IOException) UnhealthyContainerMetadata(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata) MissingContainerMetadata(org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata) ContainerMetadata(org.apache.hadoop.ozone.recon.api.types.ContainerMetadata) GET(javax.ws.rs.GET)

Example 3 with ContainersResponse

use of org.apache.hadoop.ozone.recon.api.types.ContainersResponse in project ozone by apache.

the class TestContainerEndpoint method testGetContainersWithPrevKey.

@Test
public void testGetContainersWithPrevKey() {
    Response response = containerEndpoint.getContainers(1, 1L);
    ContainersResponse responseObject = (ContainersResponse) response.getEntity();
    ContainersResponse.ContainersResponseData data = responseObject.getContainersResponseData();
    assertEquals(2, data.getTotalCount());
    List<ContainerMetadata> containers = new ArrayList<>(data.getContainers());
    Iterator<ContainerMetadata> iterator = containers.iterator();
    ContainerMetadata containerMetadata = iterator.next();
    assertEquals(1, containers.size());
    assertEquals(2L, containerMetadata.getContainerID());
    response = containerEndpoint.getContainers(-1, 0L);
    responseObject = (ContainersResponse) response.getEntity();
    data = responseObject.getContainersResponseData();
    containers = new ArrayList<>(data.getContainers());
    assertEquals(2, containers.size());
    assertEquals(2, data.getTotalCount());
    iterator = containers.iterator();
    containerMetadata = iterator.next();
    assertEquals(1L, containerMetadata.getContainerID());
    // test for negative cases
    response = containerEndpoint.getContainers(-1, 5L);
    responseObject = (ContainersResponse) response.getEntity();
    data = responseObject.getContainersResponseData();
    containers = new ArrayList<>(data.getContainers());
    assertEquals(0, containers.size());
    assertEquals(2, data.getTotalCount());
    response = containerEndpoint.getContainers(-1, -1L);
    responseObject = (ContainersResponse) response.getEntity();
    data = responseObject.getContainersResponseData();
    containers = new ArrayList<>(data.getContainers());
    assertEquals(2, containers.size());
    assertEquals(2, data.getTotalCount());
}
Also used : MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) Response(javax.ws.rs.core.Response) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) ArrayList(java.util.ArrayList) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) UnhealthyContainerMetadata(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata) MissingContainerMetadata(org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata) ContainerMetadata(org.apache.hadoop.ozone.recon.api.types.ContainerMetadata) Test(org.junit.Test)

Aggregations

ContainerMetadata (org.apache.hadoop.ozone.recon.api.types.ContainerMetadata)3 ContainersResponse (org.apache.hadoop.ozone.recon.api.types.ContainersResponse)3 MissingContainerMetadata (org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata)3 MissingContainersResponse (org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse)3 UnhealthyContainerMetadata (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata)3 UnhealthyContainersResponse (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse)3 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 KeysResponse (org.apache.hadoop.ozone.recon.api.types.KeysResponse)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 WebApplicationException (javax.ws.rs.WebApplicationException)1