Search in sources :

Example 6 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class FCStatisticsBaseTest method testStatistics.

@Test
public void testStatistics() throws IOException, URISyntaxException {
    URI fsUri = getFsUri();
    Statistics stats = FileContext.getStatistics(fsUri);
    Assert.assertEquals(0, stats.getBytesRead());
    Path filePath = fileContextTestHelper.getTestRootPath(fc, "file1");
    createFile(fc, filePath, numBlocks, blockSize);
    Assert.assertEquals(0, stats.getBytesRead());
    verifyWrittenBytes(stats);
    FSDataInputStream fstr = fc.open(filePath);
    byte[] buf = new byte[blockSize];
    int bytesRead = fstr.read(buf, 0, blockSize);
    fstr.read(0, buf, 0, blockSize);
    Assert.assertEquals(blockSize, bytesRead);
    verifyReadBytes(stats);
    verifyWrittenBytes(stats);
    verifyReadBytes(FileContext.getStatistics(getFsUri()));
    Map<URI, Statistics> statsMap = FileContext.getAllStatistics();
    URI exactUri = getSchemeAuthorityUri();
    verifyWrittenBytes(statsMap.get(exactUri));
    fc.delete(filePath, true);
}
Also used : URI(java.net.URI) Statistics(org.apache.hadoop.fs.FileSystem.Statistics) Test(org.junit.Test)

Example 7 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class AbstractFileSystem method getStatistics.

/**
   * Get the statistics for a particular file system.
   * 
   * @param uri
   *          used as key to lookup STATISTICS_TABLE. Only scheme and authority
   *          part of the uri are used.
   * @return a statistics object
   */
protected static synchronized Statistics getStatistics(URI uri) {
    String scheme = uri.getScheme();
    if (scheme == null) {
        throw new IllegalArgumentException("Scheme not defined in the uri: " + uri);
    }
    URI baseUri = getBaseUri(uri);
    Statistics result = STATISTICS_TABLE.get(baseUri);
    if (result == null) {
        result = new Statistics(scheme);
        STATISTICS_TABLE.put(baseUri, result);
    }
    return result;
}
Also used : URI(java.net.URI) Statistics(org.apache.hadoop.fs.FileSystem.Statistics) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException)

Example 8 with Statistics

use of org.apache.hadoop.fs.FileSystem.Statistics in project hadoop by apache.

the class Task method getFsStatistics.

/**
   * Gets a handle to the Statistics instance based on the scheme associated
   * with path.
   * 
   * @param path the path.
   * @param conf the configuration to extract the scheme from if not part of 
   *   the path.
   * @return a Statistics instance, or null if none is found for the scheme.
   */
protected static List<Statistics> getFsStatistics(Path path, Configuration conf) throws IOException {
    List<Statistics> matchedStats = new ArrayList<FileSystem.Statistics>();
    path = path.getFileSystem(conf).makeQualified(path);
    String scheme = path.toUri().getScheme();
    for (Statistics stats : FileSystem.getAllStatistics()) {
        if (stats.getScheme().equals(scheme)) {
            matchedStats.add(stats);
        }
    }
    return matchedStats;
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) ArrayList(java.util.ArrayList) Statistics(org.apache.hadoop.fs.FileSystem.Statistics)

Aggregations

Statistics (org.apache.hadoop.fs.FileSystem.Statistics)8 Test (org.junit.Test)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)2 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)1