Search in sources :

Example 1 with KeyMetadata

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

the class TestContainerEndpoint method testGetKeysForContainerWithPrevKey.

@Test
public void testGetKeysForContainerWithPrevKey() {
    // test if prev-key param works as expected
    Response response = containerEndpoint.getKeysForContainer(1L, -1, "/sampleVol/bucketOne/key_one");
    KeysResponse data = (KeysResponse) response.getEntity();
    assertEquals(3, data.getTotalCount());
    Collection<KeyMetadata> keyMetadataList = data.getKeys();
    assertEquals(1, keyMetadataList.size());
    Iterator<KeyMetadata> iterator = keyMetadataList.iterator();
    KeyMetadata keyMetadata = iterator.next();
    assertEquals("key_two", keyMetadata.getKey());
    assertEquals(2, keyMetadata.getVersions().size());
    assertEquals(2, keyMetadata.getBlockIds().size());
    response = containerEndpoint.getKeysForContainer(1L, -1, StringUtils.EMPTY);
    data = (KeysResponse) response.getEntity();
    keyMetadataList = data.getKeys();
    assertEquals(3, data.getTotalCount());
    assertEquals(2, keyMetadataList.size());
    iterator = keyMetadataList.iterator();
    keyMetadata = iterator.next();
    assertEquals("key_one", keyMetadata.getKey());
    // test for negative cases
    response = containerEndpoint.getKeysForContainer(1L, -1, "/sampleVol/bucketOne/invalid_key");
    data = (KeysResponse) response.getEntity();
    keyMetadataList = data.getKeys();
    assertEquals(3, data.getTotalCount());
    assertEquals(0, keyMetadataList.size());
    response = containerEndpoint.getKeysForContainer(5L, -1, "");
    data = (KeysResponse) response.getEntity();
    keyMetadataList = data.getKeys();
    assertEquals(0, keyMetadataList.size());
    assertEquals(0, 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) KeyMetadata(org.apache.hadoop.ozone.recon.api.types.KeyMetadata) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) Test(org.junit.Test)

Example 2 with KeyMetadata

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

the class ContainerEndpoint method getKeysForContainer.

/**
 * Return @{@link org.apache.hadoop.ozone.recon.api.types.KeyMetadata} for
 * all keys that belong to the container identified by the id param
 * starting from the given "prev-key" query param for the given "limit".
 * The given prevKeyPrefix is skipped from the results returned.
 *
 * @param containerID the given containerID.
 * @param limit max no. of keys to get.
 * @param prevKeyPrefix the key prefix after which results are returned.
 * @return {@link Response}
 */
@GET
@Path("/{id}/keys")
public Response getKeysForContainer(@PathParam("id") Long containerID, @DefaultValue(DEFAULT_FETCH_COUNT) @QueryParam(RECON_QUERY_LIMIT) int limit, @DefaultValue(StringUtils.EMPTY) @QueryParam(RECON_QUERY_PREVKEY) String prevKeyPrefix) {
    Map<String, KeyMetadata> keyMetadataMap = new LinkedHashMap<>();
    long totalCount;
    try {
        Map<ContainerKeyPrefix, Integer> containerKeyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(containerID, prevKeyPrefix);
        // Get set of Container-Key mappings for given containerId.
        for (ContainerKeyPrefix containerKeyPrefix : containerKeyPrefixMap.keySet()) {
            // Directly calling get() on the Key table instead of iterating since
            // only full keys are supported now. When we change to using a prefix
            // of the key, this needs to change to prefix seek.
            OmKeyInfo omKeyInfo = omMetadataManager.getKeyTable(getBucketLayout()).getSkipCache(containerKeyPrefix.getKeyPrefix());
            if (null != omKeyInfo) {
                // Filter keys by version.
                List<OmKeyLocationInfoGroup> matchedKeys = omKeyInfo.getKeyLocationVersions().stream().filter(k -> (k.getVersion() == containerKeyPrefix.getKeyVersion())).collect(Collectors.toList());
                List<ContainerBlockMetadata> blockIds = getBlocks(matchedKeys, containerID);
                String ozoneKey = omMetadataManager.getOzoneKey(omKeyInfo.getVolumeName(), omKeyInfo.getBucketName(), omKeyInfo.getKeyName());
                if (keyMetadataMap.containsKey(ozoneKey)) {
                    keyMetadataMap.get(ozoneKey).getVersions().add(containerKeyPrefix.getKeyVersion());
                    keyMetadataMap.get(ozoneKey).getBlockIds().put(containerKeyPrefix.getKeyVersion(), blockIds);
                } else {
                    // break the for loop if limit has been reached
                    if (keyMetadataMap.size() == limit) {
                        break;
                    }
                    KeyMetadata keyMetadata = new KeyMetadata();
                    keyMetadata.setBucket(omKeyInfo.getBucketName());
                    keyMetadata.setVolume(omKeyInfo.getVolumeName());
                    keyMetadata.setKey(omKeyInfo.getKeyName());
                    keyMetadata.setCreationTime(Instant.ofEpochMilli(omKeyInfo.getCreationTime()));
                    keyMetadata.setModificationTime(Instant.ofEpochMilli(omKeyInfo.getModificationTime()));
                    keyMetadata.setDataSize(omKeyInfo.getDataSize());
                    keyMetadata.getVersions().add(containerKeyPrefix.getKeyVersion());
                    keyMetadataMap.put(ozoneKey, keyMetadata);
                    keyMetadata.getBlockIds().put(containerKeyPrefix.getKeyVersion(), blockIds);
                }
            }
        }
        totalCount = reconContainerMetadataManager.getKeyCountForContainer(containerID);
    } catch (IOException ioEx) {
        throw new WebApplicationException(ioEx, Response.Status.INTERNAL_SERVER_ERROR);
    }
    KeysResponse keysResponse = new KeysResponse(totalCount, keyMetadataMap.values());
    return Response.ok(keysResponse).build();
}
Also used : DEFAULT_BATCH_NUMBER(org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_BATCH_NUMBER) Produces(javax.ws.rs.Produces) MissingContainersResponse(org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse) Path(javax.ws.rs.Path) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) StringUtils(org.apache.commons.lang3.StringUtils) ContainerBlockMetadata(org.apache.hadoop.ozone.recon.api.types.KeyMetadata.ContainerBlockMetadata) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) ReconContainerMetadataManager(org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) ContainersResponse(org.apache.hadoop.ozone.recon.api.types.ContainersResponse) UnHealthyContainerStates(org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates) UnhealthyContainers(org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers) ReconContainerManager(org.apache.hadoop.ozone.recon.scm.ReconContainerManager) ContainerHealthSchemaManager(org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager) UUID(java.util.UUID) Instant(java.time.Instant) RECON_QUERY_BATCH_PARAM(org.apache.hadoop.ozone.recon.ReconConstants.RECON_QUERY_BATCH_PARAM) Collectors(java.util.stream.Collectors) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) List(java.util.List) UnhealthyContainersSummary(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersSummary) Response(javax.ws.rs.core.Response) UnhealthyContainerMetadata(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainerMetadata) WebApplicationException(javax.ws.rs.WebApplicationException) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) KeyMetadata(org.apache.hadoop.ozone.recon.api.types.KeyMetadata) ArrayList(java.util.ArrayList) OzoneStorageContainerManager(org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) ContainerHistory(org.apache.hadoop.ozone.recon.persistence.ContainerHistory) RECON_QUERY_PREVKEY(org.apache.hadoop.ozone.recon.ReconConstants.RECON_QUERY_PREVKEY) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) MissingContainerMetadata(org.apache.hadoop.ozone.recon.api.types.MissingContainerMetadata) RECON_QUERY_LIMIT(org.apache.hadoop.ozone.recon.ReconConstants.RECON_QUERY_LIMIT) PREV_CONTAINER_ID_DEFAULT_VALUE(org.apache.hadoop.ozone.recon.ReconConstants.PREV_CONTAINER_ID_DEFAULT_VALUE) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) IOException(java.io.IOException) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) ContainerMetadata(org.apache.hadoop.ozone.recon.api.types.ContainerMetadata) UnhealthyContainersResponse(org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse) DEFAULT_FETCH_COUNT(org.apache.hadoop.ozone.recon.ReconConstants.DEFAULT_FETCH_COUNT) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) WebApplicationException(javax.ws.rs.WebApplicationException) ContainerBlockMetadata(org.apache.hadoop.ozone.recon.api.types.KeyMetadata.ContainerBlockMetadata) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) KeyMetadata(org.apache.hadoop.ozone.recon.api.types.KeyMetadata) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with KeyMetadata

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

the class TestContainerEndpoint method testGetKeysForContainer.

@Test
public void testGetKeysForContainer() {
    Response response = containerEndpoint.getKeysForContainer(1L, -1, "");
    KeysResponse data = (KeysResponse) response.getEntity();
    Collection<KeyMetadata> keyMetadataList = data.getKeys();
    assertEquals(3, data.getTotalCount());
    assertEquals(2, keyMetadataList.size());
    Iterator<KeyMetadata> iterator = keyMetadataList.iterator();
    KeyMetadata keyMetadata = iterator.next();
    assertEquals("key_one", keyMetadata.getKey());
    assertEquals(1, keyMetadata.getVersions().size());
    assertEquals(1, keyMetadata.getBlockIds().size());
    Map<Long, List<KeyMetadata.ContainerBlockMetadata>> blockIds = keyMetadata.getBlockIds();
    assertEquals(101, blockIds.get(0L).iterator().next().getLocalID());
    keyMetadata = iterator.next();
    assertEquals("key_two", keyMetadata.getKey());
    assertEquals(2, keyMetadata.getVersions().size());
    assertTrue(keyMetadata.getVersions().contains(0L) && keyMetadata.getVersions().contains(1L));
    assertEquals(2, keyMetadata.getBlockIds().size());
    blockIds = keyMetadata.getBlockIds();
    assertEquals(103, blockIds.get(0L).iterator().next().getLocalID());
    assertEquals(104, blockIds.get(1L).iterator().next().getLocalID());
    response = containerEndpoint.getKeysForContainer(3L, -1, "");
    data = (KeysResponse) response.getEntity();
    keyMetadataList = data.getKeys();
    assertTrue(keyMetadataList.isEmpty());
    assertEquals(0, data.getTotalCount());
    // test if limit works as expected
    response = containerEndpoint.getKeysForContainer(1L, 1, "");
    data = (KeysResponse) response.getEntity();
    keyMetadataList = data.getKeys();
    assertEquals(1, keyMetadataList.size());
    assertEquals(3, 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) KeyMetadata(org.apache.hadoop.ozone.recon.api.types.KeyMetadata) List(java.util.List) ArrayList(java.util.ArrayList) KeysResponse(org.apache.hadoop.ozone.recon.api.types.KeysResponse) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)3 ContainersResponse (org.apache.hadoop.ozone.recon.api.types.ContainersResponse)3 KeyMetadata (org.apache.hadoop.ozone.recon.api.types.KeyMetadata)3 KeysResponse (org.apache.hadoop.ozone.recon.api.types.KeysResponse)3 MissingContainersResponse (org.apache.hadoop.ozone.recon.api.types.MissingContainersResponse)3 UnhealthyContainersResponse (org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersResponse)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 DefaultValue (javax.ws.rs.DefaultValue)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1