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