Search in sources :

Example 1 with QuotaUsage

use of org.apache.hadoop.fs.QuotaUsage in project hadoop by apache.

the class Count method processPath.

@Override
protected void processPath(PathData src) throws IOException {
    if (showQuotasAndUsageOnly || showQuotabyType) {
        QuotaUsage usage = src.fs.getQuotaUsage(src.path);
        out.println(usage.toString(isHumanReadable(), showQuotabyType, storageTypes) + src);
    } else {
        ContentSummary summary = src.fs.getContentSummary(src.path);
        out.println(summary.toString(showQuotas, isHumanReadable(), excludeSnapshots) + src);
    }
}
Also used : ContentSummary(org.apache.hadoop.fs.ContentSummary) QuotaUsage(org.apache.hadoop.fs.QuotaUsage)

Example 2 with QuotaUsage

use of org.apache.hadoop.fs.QuotaUsage in project hadoop by apache.

the class FSDirStatAndListingOp method getQuotaUsageInt.

private static QuotaUsage getQuotaUsageInt(FSDirectory fsd, INodesInPath iip) throws IOException {
    fsd.readLock();
    try {
        INode targetNode = iip.getLastINode();
        QuotaUsage usage = null;
        if (targetNode.isDirectory()) {
            DirectoryWithQuotaFeature feature = targetNode.asDirectory().getDirectoryWithQuotaFeature();
            if (feature != null) {
                QuotaCounts counts = feature.getSpaceConsumed();
                QuotaCounts quotas = feature.getQuota();
                usage = new QuotaUsage.Builder().fileAndDirectoryCount(counts.getNameSpace()).quota(quotas.getNameSpace()).spaceConsumed(counts.getStorageSpace()).spaceQuota(quotas.getStorageSpace()).typeConsumed(counts.getTypeSpaces().asArray()).typeQuota(quotas.getTypeSpaces().asArray()).build();
            }
        }
        return usage;
    } finally {
        fsd.readUnlock();
    }
}
Also used : QuotaUsage(org.apache.hadoop.fs.QuotaUsage)

Example 3 with QuotaUsage

use of org.apache.hadoop.fs.QuotaUsage in project hadoop by apache.

the class FSDirStatAndListingOp method getQuotaUsage.

static QuotaUsage getQuotaUsage(FSDirectory fsd, String src) throws IOException {
    FSPermissionChecker pc = fsd.getPermissionChecker();
    final INodesInPath iip;
    fsd.readLock();
    try {
        iip = fsd.resolvePath(pc, src, DirOp.READ_LINK);
        if (fsd.isPermissionEnabled()) {
            fsd.checkPermission(pc, iip, false, null, null, null, FsAction.READ_EXECUTE);
        }
    } finally {
        fsd.readUnlock();
    }
    QuotaUsage usage = getQuotaUsageInt(fsd, iip);
    if (usage != null) {
        return usage;
    } else {
        //If quota isn't set, fall back to getContentSummary.
        return getContentSummaryInt(fsd, iip);
    }
}
Also used : QuotaUsage(org.apache.hadoop.fs.QuotaUsage)

Example 4 with QuotaUsage

use of org.apache.hadoop.fs.QuotaUsage in project hadoop by apache.

the class TestViewFsDefaultValue method testGetQuotaUsage.

/**
   * Test that getQuotaUsage can be retrieved on the client side.
   */
@Test
public void testGetQuotaUsage() throws IOException {
    FileSystem hFs = cluster.getFileSystem(0);
    final DistributedFileSystem dfs = (DistributedFileSystem) hFs;
    dfs.setQuota(testFileDirPath, 100, 500);
    QuotaUsage qu = vfs.getQuotaUsage(testFileDirPath);
    assertEquals(100, qu.getQuota());
    assertEquals(500, qu.getSpaceQuota());
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) QuotaUsage(org.apache.hadoop.fs.QuotaUsage) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) Test(org.junit.Test)

Example 5 with QuotaUsage

use of org.apache.hadoop.fs.QuotaUsage in project hadoop by apache.

the class TestViewFsDefaultValue method testGetQuotaUsageWithQuotaDefined.

/**
   * Test that getQuotaUsage can be retrieved on the client side if
   * quota isn't defined.
   */
@Test
public void testGetQuotaUsageWithQuotaDefined() throws IOException {
    FileSystem hFs = cluster.getFileSystem(0);
    final DistributedFileSystem dfs = (DistributedFileSystem) hFs;
    dfs.setQuota(testFileDirPath, -1, -1);
    dfs.setQuotaByStorageType(testFileDirPath, StorageType.SSD, -1);
    dfs.setQuotaByStorageType(testFileDirPath, StorageType.DISK, -1);
    QuotaUsage qu = vfs.getQuotaUsage(testFileDirPath);
    assertEquals(-1, qu.getTypeQuota(StorageType.SSD));
    assertEquals(-1, qu.getQuota());
    assertEquals(-1, qu.getSpaceQuota());
    assertEquals(2, qu.getFileAndDirectoryCount());
    assertEquals(0, qu.getTypeConsumed(StorageType.SSD));
    assertTrue(qu.getSpaceConsumed() > 0);
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) QuotaUsage(org.apache.hadoop.fs.QuotaUsage) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) Test(org.junit.Test)

Aggregations

QuotaUsage (org.apache.hadoop.fs.QuotaUsage)11 FileSystem (org.apache.hadoop.fs.FileSystem)4 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)3 Test (org.junit.Test)3 DFSAdmin (org.apache.hadoop.hdfs.tools.DFSAdmin)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 IOException (java.io.IOException)1 ContentSummary (org.apache.hadoop.fs.ContentSummary)1 Path (org.apache.hadoop.fs.Path)1 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)1 SnapshotAccessControlException (org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1