Search in sources :

Example 1 with NamespaceSummaryResponse

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

the class TestReconWithOzoneManagerFSO method testNamespaceSummaryAPI.

@Test
public void testNamespaceSummaryAPI() throws Exception {
    // add a vol, bucket and key
    addKeys(0, 10, "dir");
    OzoneManagerServiceProviderImpl impl = (OzoneManagerServiceProviderImpl) cluster.getReconServer().getOzoneManagerServiceProvider();
    impl.syncDataFromOM();
    ReconNamespaceSummaryManager namespaceSummaryManager = cluster.getReconServer().getReconNamespaceSummaryManager();
    ReconOMMetadataManager omMetadataManagerInstance = (ReconOMMetadataManager) cluster.getReconServer().getOzoneManagerServiceProvider().getOMMetadataManagerInstance();
    OzoneStorageContainerManager reconSCM = cluster.getReconServer().getReconStorageContainerManager();
    NSSummaryEndpoint endpoint = new NSSummaryEndpoint(namespaceSummaryManager, omMetadataManagerInstance, reconSCM);
    Response basicInfo = endpoint.getBasicInfo("/vol1/bucket1/dir1");
    NamespaceSummaryResponse entity = (NamespaceSummaryResponse) basicInfo.getEntity();
    Assert.assertSame(entity.getEntityType(), EntityType.DIRECTORY);
    Assert.assertEquals(1, entity.getNumTotalKey());
    Assert.assertEquals(0, entity.getNumTotalDir());
    for (int i = 0; i < 10; i++) {
        Assert.assertNotNull(impl.getOMMetadataManagerInstance().getVolumeTable().get("/vol" + i));
    }
    addKeys(10, 12, "dir");
    impl.syncDataFromOM();
    // test Recon is sync'ed with OM.
    for (int i = 10; i < 12; i++) {
        Assert.assertNotNull(impl.getOMMetadataManagerInstance().getVolumeTable().getSkipCache("/vol" + i));
    }
    // test root response
    Response rootBasicRes = endpoint.getBasicInfo("/");
    NamespaceSummaryResponse rootBasicEntity = (NamespaceSummaryResponse) rootBasicRes.getEntity();
    Assert.assertSame(EntityType.ROOT, rootBasicEntity.getEntityType());
    // one additional dummy volume at creation
    Assert.assertEquals(13, rootBasicEntity.getNumVolume());
    Assert.assertEquals(12, rootBasicEntity.getNumBucket());
    Assert.assertEquals(12, rootBasicEntity.getNumTotalDir());
    Assert.assertEquals(12, rootBasicEntity.getNumTotalKey());
}
Also used : NamespaceSummaryResponse(org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse) Response(javax.ws.rs.core.Response) NSSummaryEndpoint(org.apache.hadoop.ozone.recon.api.NSSummaryEndpoint) ReconNamespaceSummaryManager(org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager) OzoneManagerServiceProviderImpl(org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) OzoneStorageContainerManager(org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager) NSSummaryEndpoint(org.apache.hadoop.ozone.recon.api.NSSummaryEndpoint) NamespaceSummaryResponse(org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse) Test(org.junit.Test)

Example 2 with NamespaceSummaryResponse

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

the class TestNSSummaryEndpoint method testBasic.

@Test
public void testBasic() throws Exception {
    // Test volume basics
    Response volResponse = nsSummaryEndpoint.getBasicInfo(VOL_PATH);
    NamespaceSummaryResponse volResponseObj = (NamespaceSummaryResponse) volResponse.getEntity();
    Assert.assertEquals(EntityType.VOLUME, volResponseObj.getEntityType());
    Assert.assertEquals(2, volResponseObj.getNumBucket());
    Assert.assertEquals(4, volResponseObj.getNumTotalDir());
    Assert.assertEquals(6, volResponseObj.getNumTotalKey());
    // Test bucket 1's basics
    Response bucketOneResponse = nsSummaryEndpoint.getBasicInfo(BUCKET_ONE_PATH);
    NamespaceSummaryResponse bucketOneObj = (NamespaceSummaryResponse) bucketOneResponse.getEntity();
    Assert.assertEquals(EntityType.BUCKET, bucketOneObj.getEntityType());
    Assert.assertEquals(4, bucketOneObj.getNumTotalDir());
    Assert.assertEquals(4, bucketOneObj.getNumTotalKey());
    // Test bucket 2's basics
    Response bucketTwoResponse = nsSummaryEndpoint.getBasicInfo(BUCKET_TWO_PATH);
    NamespaceSummaryResponse bucketTwoObj = (NamespaceSummaryResponse) bucketTwoResponse.getEntity();
    Assert.assertEquals(EntityType.BUCKET, bucketTwoObj.getEntityType());
    Assert.assertEquals(0, bucketTwoObj.getNumTotalDir());
    Assert.assertEquals(2, bucketTwoObj.getNumTotalKey());
    // Test intermediate directory basics
    Response dirOneResponse = nsSummaryEndpoint.getBasicInfo(DIR_ONE_PATH);
    NamespaceSummaryResponse dirOneObj = (NamespaceSummaryResponse) dirOneResponse.getEntity();
    Assert.assertEquals(EntityType.DIRECTORY, dirOneObj.getEntityType());
    Assert.assertEquals(3, dirOneObj.getNumTotalDir());
    Assert.assertEquals(3, dirOneObj.getNumTotalKey());
    // Test invalid path
    Response invalidResponse = nsSummaryEndpoint.getBasicInfo(INVALID_PATH);
    NamespaceSummaryResponse invalidObj = (NamespaceSummaryResponse) invalidResponse.getEntity();
    Assert.assertEquals(ResponseStatus.PATH_NOT_FOUND, invalidObj.getStatus());
    // Test key
    Response keyResponse = nsSummaryEndpoint.getBasicInfo(KEY_PATH);
    NamespaceSummaryResponse keyResObj = (NamespaceSummaryResponse) keyResponse.getEntity();
    Assert.assertEquals(EntityType.KEY, keyResObj.getEntityType());
}
Also used : QuotaUsageResponse(org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse) NamespaceSummaryResponse(org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse) Response(javax.ws.rs.core.Response) DUResponse(org.apache.hadoop.ozone.recon.api.types.DUResponse) FileSizeDistributionResponse(org.apache.hadoop.ozone.recon.api.types.FileSizeDistributionResponse) NamespaceSummaryResponse(org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse) Test(org.junit.Test)

Example 3 with NamespaceSummaryResponse

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

the class NSSummaryEndpoint method getBasicInfo.

/**
 * This endpoint will return the entity type and aggregate count of objects.
 * @param path the request path.
 * @return HTTP response with basic info: entity type, num of objects
 * @throws IOException IOE
 */
@GET
@Path("/summary")
public Response getBasicInfo(@QueryParam("path") String path) throws IOException {
    if (path == null || path.length() == 0) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    NamespaceSummaryResponse namespaceSummaryResponse = null;
    if (!isInitializationComplete()) {
        namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.UNKNOWN);
        namespaceSummaryResponse.setStatus(ResponseStatus.INITIALIZING);
        return Response.ok(namespaceSummaryResponse).build();
    }
    String normalizedPath = normalizePath(path);
    String[] names = parseRequestPath(normalizedPath);
    EntityType type = getEntityType(normalizedPath, names);
    switch(type) {
        case ROOT:
            namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.ROOT);
            List<OmVolumeArgs> volumes = listVolumes();
            namespaceSummaryResponse.setNumVolume(volumes.size());
            List<OmBucketInfo> allBuckets = listBucketsUnderVolume(null);
            namespaceSummaryResponse.setNumBucket(allBuckets.size());
            int totalNumDir = 0;
            long totalNumKey = 0L;
            for (OmBucketInfo bucket : allBuckets) {
                long bucketObjectId = bucket.getObjectID();
                totalNumDir += getTotalDirCount(bucketObjectId);
                totalNumKey += getTotalKeyCount(bucketObjectId);
            }
            namespaceSummaryResponse.setNumTotalDir(totalNumDir);
            namespaceSummaryResponse.setNumTotalKey(totalNumKey);
            break;
        case VOLUME:
            namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.VOLUME);
            List<OmBucketInfo> buckets = listBucketsUnderVolume(names[0]);
            namespaceSummaryResponse.setNumBucket(buckets.size());
            int totalDir = 0;
            long totalKey = 0L;
            // iterate all buckets to collect the total object count.
            for (OmBucketInfo bucket : buckets) {
                long bucketObjectId = bucket.getObjectID();
                totalDir += getTotalDirCount(bucketObjectId);
                totalKey += getTotalKeyCount(bucketObjectId);
            }
            namespaceSummaryResponse.setNumTotalDir(totalDir);
            namespaceSummaryResponse.setNumTotalKey(totalKey);
            break;
        case BUCKET:
            namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.BUCKET);
            assert (names.length == 2);
            long bucketObjectId = getBucketObjectId(names);
            namespaceSummaryResponse.setNumTotalDir(getTotalDirCount(bucketObjectId));
            namespaceSummaryResponse.setNumTotalKey(getTotalKeyCount(bucketObjectId));
            break;
        case DIRECTORY:
            // path should exist so we don't need any extra verification/null check
            long dirObjectId = getDirObjectId(names);
            namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.DIRECTORY);
            namespaceSummaryResponse.setNumTotalDir(getTotalDirCount(dirObjectId));
            namespaceSummaryResponse.setNumTotalKey(getTotalKeyCount(dirObjectId));
            break;
        case KEY:
            namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.KEY);
            break;
        case UNKNOWN:
            namespaceSummaryResponse = new NamespaceSummaryResponse(EntityType.UNKNOWN);
            namespaceSummaryResponse.setStatus(ResponseStatus.PATH_NOT_FOUND);
            break;
        default:
            break;
    }
    return Response.ok(namespaceSummaryResponse).build();
}
Also used : EntityType(org.apache.hadoop.ozone.recon.api.types.EntityType) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) NamespaceSummaryResponse(org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

NamespaceSummaryResponse (org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 OzoneStorageContainerManager (org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager)1 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)1 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)1 NSSummaryEndpoint (org.apache.hadoop.ozone.recon.api.NSSummaryEndpoint)1 DUResponse (org.apache.hadoop.ozone.recon.api.types.DUResponse)1 EntityType (org.apache.hadoop.ozone.recon.api.types.EntityType)1 FileSizeDistributionResponse (org.apache.hadoop.ozone.recon.api.types.FileSizeDistributionResponse)1 QuotaUsageResponse (org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse)1 ReconOMMetadataManager (org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager)1 ReconNamespaceSummaryManager (org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager)1 OzoneManagerServiceProviderImpl (org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl)1