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());
}
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();
}
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());
}
Aggregations