use of org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse in project ozone by apache.
the class TestNSSummaryEndpoint method testQuotaUsage.
@Test
public void testQuotaUsage() throws Exception {
// volume level quota usage
Response volResponse = nsSummaryEndpoint.getQuotaUsage(VOL_PATH);
QuotaUsageResponse quVolRes = (QuotaUsageResponse) volResponse.getEntity();
Assert.assertEquals(VOL_QUOTA, quVolRes.getQuota());
Assert.assertEquals(TOTAL_DATA_SIZE, quVolRes.getQuotaUsed());
// bucket level quota usage
Response bucketRes = nsSummaryEndpoint.getQuotaUsage(BUCKET_ONE_PATH);
QuotaUsageResponse quBucketRes = (QuotaUsageResponse) bucketRes.getEntity();
Assert.assertEquals(BUCKET_ONE_QUOTA, quBucketRes.getQuota());
Assert.assertEquals(BUCKET_ONE_DATA_SIZE, quBucketRes.getQuotaUsed());
Response bucketRes2 = nsSummaryEndpoint.getQuotaUsage(BUCKET_TWO_PATH);
QuotaUsageResponse quBucketRes2 = (QuotaUsageResponse) bucketRes2.getEntity();
Assert.assertEquals(BUCKET_TWO_QUOTA, quBucketRes2.getQuota());
Assert.assertEquals(BUCKET_TWO_DATA_SIZE, quBucketRes2.getQuotaUsed());
// other level not applicable
Response naResponse1 = nsSummaryEndpoint.getQuotaUsage(DIR_ONE_PATH);
QuotaUsageResponse quotaUsageResponse1 = (QuotaUsageResponse) naResponse1.getEntity();
Assert.assertEquals(ResponseStatus.TYPE_NOT_APPLICABLE, quotaUsageResponse1.getResponseCode());
Response naResponse2 = nsSummaryEndpoint.getQuotaUsage(KEY_PATH);
QuotaUsageResponse quotaUsageResponse2 = (QuotaUsageResponse) naResponse2.getEntity();
Assert.assertEquals(ResponseStatus.TYPE_NOT_APPLICABLE, quotaUsageResponse2.getResponseCode());
// invalid path request
Response invalidRes = nsSummaryEndpoint.getQuotaUsage(INVALID_PATH);
QuotaUsageResponse invalidResObj = (QuotaUsageResponse) invalidRes.getEntity();
Assert.assertEquals(ResponseStatus.PATH_NOT_FOUND, invalidResObj.getResponseCode());
}
use of org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse in project ozone by apache.
the class NSSummaryEndpoint method getQuotaUsage.
/**
* Quota usage endpoint that summarize the quota allowed and quota used in
* bytes.
* @param path request path
* @return Quota Usage response
* @throws IOException
*/
@GET
@Path("/quota")
public Response getQuotaUsage(@QueryParam("path") String path) throws IOException {
if (path == null || path.length() == 0) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
QuotaUsageResponse quotaUsageResponse = new QuotaUsageResponse();
if (!isInitializationComplete()) {
quotaUsageResponse.setResponseCode(ResponseStatus.INITIALIZING);
return Response.ok(quotaUsageResponse).build();
}
String normalizedPath = normalizePath(path);
String[] names = parseRequestPath(normalizedPath);
EntityType type = getEntityType(normalizedPath, names);
if (type == EntityType.ROOT) {
List<OmVolumeArgs> volumes = listVolumes();
List<OmBucketInfo> buckets = listBucketsUnderVolume(null);
long quotaInBytes = 0L;
long quotaUsedInBytes = 0L;
for (OmVolumeArgs volume : volumes) {
final long quota = volume.getQuotaInBytes();
assert (quota >= -1L);
if (quota == -1L) {
// If one volume has unlimited quota, the "root" quota is unlimited.
quotaInBytes = -1L;
break;
}
quotaInBytes += quota;
}
for (OmBucketInfo bucket : buckets) {
long bucketObjectId = bucket.getObjectID();
quotaUsedInBytes += getTotalSize(bucketObjectId);
}
quotaUsageResponse.setQuota(quotaInBytes);
quotaUsageResponse.setQuotaUsed(quotaUsedInBytes);
} else if (type == EntityType.VOLUME) {
List<OmBucketInfo> buckets = listBucketsUnderVolume(names[0]);
String volKey = omMetadataManager.getVolumeKey(names[0]);
OmVolumeArgs volumeArgs = omMetadataManager.getVolumeTable().getSkipCache(volKey);
long quotaInBytes = volumeArgs.getQuotaInBytes();
long quotaUsedInBytes = 0L;
// Get the total data size used by all buckets
for (OmBucketInfo bucketInfo : buckets) {
long bucketObjectId = bucketInfo.getObjectID();
quotaUsedInBytes += getTotalSize(bucketObjectId);
}
quotaUsageResponse.setQuota(quotaInBytes);
quotaUsageResponse.setQuotaUsed(quotaUsedInBytes);
} else if (type == EntityType.BUCKET) {
String bucketKey = omMetadataManager.getBucketKey(names[0], names[1]);
OmBucketInfo bucketInfo = omMetadataManager.getBucketTable().getSkipCache(bucketKey);
long bucketObjectId = bucketInfo.getObjectID();
long quotaInBytes = bucketInfo.getQuotaInBytes();
long quotaUsedInBytes = getTotalSize(bucketObjectId);
quotaUsageResponse.setQuota(quotaInBytes);
quotaUsageResponse.setQuotaUsed(quotaUsedInBytes);
} else if (type == EntityType.UNKNOWN) {
quotaUsageResponse.setResponseCode(ResponseStatus.PATH_NOT_FOUND);
} else {
// directory and key are not applicable for this request
quotaUsageResponse.setResponseCode(ResponseStatus.TYPE_NOT_APPLICABLE);
}
return Response.ok(quotaUsageResponse).build();
}
Aggregations