Search in sources :

Example 1 with ContainerMetadata

use of org.apache.hadoop.ozone.recon.api.types.ContainerMetadata 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 ContainerMetadata

use of org.apache.hadoop.ozone.recon.api.types.ContainerMetadata 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 ContainerMetadata

use of org.apache.hadoop.ozone.recon.api.types.ContainerMetadata 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)

Example 4 with ContainerMetadata

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

the class ReconContainerMetadataManagerImpl method getContainers.

/**
 * Iterate the DB to construct a Map of containerID -> containerMetadata
 * only for the given limit from the given start key. The start containerID
 * is skipped from the result.
 *
 * Return all the containers if limit < 0.
 *
 * @param limit No of containers to get.
 * @param prevContainer containerID after which the
 *                      list of containers are scanned.
 * @return Map of containerID -> containerMetadata.
 * @throws IOException on failure.
 */
@Override
public Map<Long, ContainerMetadata> getContainers(int limit, long prevContainer) throws IOException {
    Map<Long, ContainerMetadata> containers = new LinkedHashMap<>();
    TableIterator<ContainerKeyPrefix, ? extends KeyValue<ContainerKeyPrefix, Integer>> containerIterator = containerKeyTable.iterator();
    ContainerKeyPrefix seekKey;
    if (prevContainer > 0L) {
        seekKey = new ContainerKeyPrefix(prevContainer);
        KeyValue<ContainerKeyPrefix, Integer> seekKeyValue = containerIterator.seek(seekKey);
        // prevContainer containerId. If not, then return empty result
        if (seekKeyValue != null && seekKeyValue.getKey().getContainerId() != prevContainer) {
            return containers;
        } else {
            // seek to the prevContainer+1 containerID to start scan
            seekKey = new ContainerKeyPrefix(prevContainer + 1);
            containerIterator.seek(seekKey);
        }
    }
    while (containerIterator.hasNext()) {
        KeyValue<ContainerKeyPrefix, Integer> keyValue = containerIterator.next();
        ContainerKeyPrefix containerKeyPrefix = keyValue.getKey();
        Long containerID = containerKeyPrefix.getContainerId();
        Integer numberOfKeys = keyValue.getValue();
        // and one more new entity needs to be added to the containers map
        if (containers.size() == limit && !containers.containsKey(containerID)) {
            break;
        }
        // initialize containerMetadata with 0 as number of keys.
        containers.computeIfAbsent(containerID, ContainerMetadata::new);
        // increment number of keys for the containerID
        ContainerMetadata containerMetadata = containers.get(containerID);
        containerMetadata.setNumberOfKeys(containerMetadata.getNumberOfKeys() + numberOfKeys);
        containers.put(containerID, containerMetadata);
    }
    return containers;
}
Also used : ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) ContainerMetadata(org.apache.hadoop.ozone.recon.api.types.ContainerMetadata) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ContainerMetadata (org.apache.hadoop.ozone.recon.api.types.ContainerMetadata)4 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 LinkedHashMap (java.util.LinkedHashMap)1 GET (javax.ws.rs.GET)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ContainerKeyPrefix (org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix)1