Search in sources :

Example 6 with QuotaUsage

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

the class TestViewFsDefaultValue method testGetQuotaUsageWithStorageTypes.

/**
   * Test that getQuotaUsage can be retrieved on the client side if
   * storage types are defined.
   */
@Test
public void testGetQuotaUsageWithStorageTypes() throws IOException {
    FileSystem hFs = cluster.getFileSystem(0);
    final DistributedFileSystem dfs = (DistributedFileSystem) hFs;
    dfs.setQuotaByStorageType(testFileDirPath, StorageType.SSD, 500);
    dfs.setQuotaByStorageType(testFileDirPath, StorageType.DISK, 600);
    QuotaUsage qu = vfs.getQuotaUsage(testFileDirPath);
    assertEquals(500, qu.getTypeQuota(StorageType.SSD));
    assertEquals(600, qu.getTypeQuota(StorageType.DISK));
}
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 7 with QuotaUsage

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

the class DistributedFileSystem method getQuotaUsage.

@Override
public QuotaUsage getQuotaUsage(Path f) throws IOException {
    statistics.incrementReadOps(1);
    storageStatistics.incrementOpCounter(OpType.GET_QUOTA_USAGE);
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<QuotaUsage>() {

        @Override
        public QuotaUsage doCall(final Path p) throws IOException, UnresolvedLinkException {
            return dfs.getQuotaUsage(getPathName(p));
        }

        @Override
        public QuotaUsage next(final FileSystem fs, final Path p) throws IOException {
            return fs.getQuotaUsage(p);
        }
    }.resolve(this, absF);
}
Also used : Path(org.apache.hadoop.fs.Path) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) FileSystem(org.apache.hadoop.fs.FileSystem) QuotaUsage(org.apache.hadoop.fs.QuotaUsage) IOException(java.io.IOException)

Example 8 with QuotaUsage

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

the class FSNamesystem method getQuotaUsage.

/**
   * Get the quota usage for a specific file/dir.
   *
   * @param src The string representation of the path to the file
   *
   * @throws AccessControlException if access is denied
   * @throws UnresolvedLinkException if a symlink is encountered.
   * @throws FileNotFoundException if no file exists
   * @throws StandbyException
   * @throws IOException for issues with writing to the audit log
   *
   * @return object containing information regarding the file
   *         or null if file not found
   */
QuotaUsage getQuotaUsage(final String src) throws IOException {
    checkOperation(OperationCategory.READ);
    final String operationName = "quotaUsage";
    QuotaUsage quotaUsage;
    readLock();
    boolean success = true;
    try {
        checkOperation(OperationCategory.READ);
        quotaUsage = FSDirStatAndListingOp.getQuotaUsage(dir, src);
    } catch (AccessControlException ace) {
        success = false;
        logAuditEvent(success, operationName, src);
        throw ace;
    } finally {
        readUnlock(operationName);
    }
    logAuditEvent(success, operationName, src);
    return quotaUsage;
}
Also used : AccessControlException(org.apache.hadoop.security.AccessControlException) SnapshotAccessControlException(org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException) QuotaUsage(org.apache.hadoop.fs.QuotaUsage)

Example 9 with QuotaUsage

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

the class TestQuota method testSetAndClearSpaceQuotaRegularInternal.

private void testSetAndClearSpaceQuotaRegularInternal(final String[] args, final Path dir, final int cmdRet, final int spaceQuota) throws Exception {
    resetStream();
    final DFSAdmin dfsAdmin = new DFSAdmin(conf);
    final List<String> outs = Lists.newArrayList();
    final int ret = ToolRunner.run(dfsAdmin, args);
    assertEquals(cmdRet, ret);
    final QuotaUsage quotaUsage = dfs.getQuotaUsage(dir);
    assertEquals(spaceQuota, quotaUsage.getSpaceQuota());
    scanIntoList(OUT_STREAM, outs);
    assertTrue("There should be no output if it runs successfully.", outs.isEmpty());
}
Also used : DFSAdmin(org.apache.hadoop.hdfs.tools.DFSAdmin) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) QuotaUsage(org.apache.hadoop.fs.QuotaUsage)

Example 10 with QuotaUsage

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

the class TestQuota method testSetAndClearSpaceQuotaByStorageTypeInternal.

private void testSetAndClearSpaceQuotaByStorageTypeInternal(final String[] args, final Path dir, final int cmdRet, final int spaceQuota, final int spaceQuotaByStorageType) throws Exception {
    resetStream();
    final DFSAdmin dfsAdmin = new DFSAdmin(conf);
    final List<String> outs = Lists.newArrayList();
    final int ret = ToolRunner.run(dfsAdmin, args);
    assertEquals(cmdRet, ret);
    final QuotaUsage quotaUsage = dfs.getQuotaUsage(dir);
    assertEquals(spaceQuota, quotaUsage.getSpaceQuota());
    assertEquals(spaceQuotaByStorageType, quotaUsage.getTypeQuota(StorageType.DISK));
    scanIntoList(OUT_STREAM, outs);
    assertTrue("There should be no output if it runs successfully.", outs.isEmpty());
}
Also used : DFSAdmin(org.apache.hadoop.hdfs.tools.DFSAdmin) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) QuotaUsage(org.apache.hadoop.fs.QuotaUsage)

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