當前位置: 首頁>>代碼示例>>Java>>正文


Java FileSystem.getContentSummary方法代碼示例

本文整理匯總了Java中org.apache.hadoop.fs.FileSystem.getContentSummary方法的典型用法代碼示例。如果您正苦於以下問題:Java FileSystem.getContentSummary方法的具體用法?Java FileSystem.getContentSummary怎麽用?Java FileSystem.getContentSummary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.fs.FileSystem的用法示例。


在下文中一共展示了FileSystem.getContentSummary方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testContentSummary

import org.apache.hadoop.fs.FileSystem; //導入方法依賴的package包/類
private void testContentSummary() throws Exception {
  FileSystem fs = FileSystem.get(getProxiedFSConf());
  Path path = new Path(getProxiedFSTestDir(), "foo.txt");
  OutputStream os = fs.create(path);
  os.write(1);
  os.close();
  ContentSummary hdfsContentSummary = fs.getContentSummary(path);
  fs.close();
  fs = getHttpFSFileSystem();
  ContentSummary httpContentSummary = fs.getContentSummary(path);
  fs.close();
  Assert.assertEquals(httpContentSummary.getDirectoryCount(), hdfsContentSummary.getDirectoryCount());
  Assert.assertEquals(httpContentSummary.getFileCount(), hdfsContentSummary.getFileCount());
  Assert.assertEquals(httpContentSummary.getLength(), hdfsContentSummary.getLength());
  Assert.assertEquals(httpContentSummary.getQuota(), hdfsContentSummary.getQuota());
  Assert.assertEquals(httpContentSummary.getSpaceConsumed(), hdfsContentSummary.getSpaceConsumed());
  Assert.assertEquals(httpContentSummary.getSpaceQuota(), hdfsContentSummary.getSpaceQuota());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:BaseTestHttpFSWith.java

示例2: getContentSummary

import org.apache.hadoop.fs.FileSystem; //導入方法依賴的package包/類
/**
 * 此方法用於獲取文件的 ContentSummary
 *
 * @param fileSystemInfo
 *            文件係統信息
 * @param path
 *            文件路徑
 * @return ContentSummary
 */
public static ContentSummary getContentSummary(FileSystemInfo fileSystemInfo, String path) {
	FileSystem fs = getFileSystem(fileSystemInfo);
	Path uri = new Path(path);
	try {
		pathNotExistCheck(path, fs, uri);
		return fs.getContentSummary(uri);
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		closeFileSystem(fs);
	}
	return null;
}
 
開發者ID:zhangjunfang,項目名稱:alluxio,代碼行數:23,代碼來源:HdfsAndAlluxioUtils_update.java

示例3: testTargetDir

import org.apache.hadoop.fs.FileSystem; //導入方法依賴的package包/類
/** test target-dir contains imported files. */
public void testTargetDir() throws IOException {

  try {
    String targetDir = getWarehouseDir() + "/tempTargetDir";

    ArrayList args = getOutputArgv(true);
    args.add("--target-dir");
    args.add(targetDir);

    // delete target-dir if exists and recreate it
    FileSystem fs = FileSystem.get(getConf());
    Path outputPath = new Path(targetDir);
    if (fs.exists(outputPath)) {
      fs.delete(outputPath, true);
    }

    String[] argv = (String[]) args.toArray(new String[0]);
    runImport(argv);

    ContentSummary summ = fs.getContentSummary(outputPath);

    assertTrue("There's no new imported files in target-dir",
        summ.getFileCount() > 0);

  } catch (Exception e) {
    LOG.error("Got Exception: " + StringUtils.stringifyException(e));
    fail(e.toString());
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:31,代碼來源:TestTargetDir.java

示例4: testBlockAllocationAdjustsUsageConservatively

import org.apache.hadoop.fs.FileSystem; //導入方法依賴的package包/類
/**
  * Violate a space quota using files of size < 1 block. Test that block
  * allocation conservatively assumes that for quota checking the entire
  * space of the block is used.
  */
 @Test
 public void testBlockAllocationAdjustsUsageConservatively() 
     throws Exception {
   Configuration conf = new HdfsConfiguration();
   final int BLOCK_SIZE = 6 * 1024;
   conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   MiniDFSCluster cluster = 
     new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
   cluster.waitActive();
   FileSystem fs = cluster.getFileSystem();
   DFSAdmin admin = new DFSAdmin(conf);

   final String nnAddr = conf.get(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY);
   final String webhdfsuri = WebHdfsFileSystem.SCHEME  + "://" + nnAddr;
   System.out.println("webhdfsuri=" + webhdfsuri);
   final FileSystem webhdfs = new Path(webhdfsuri).getFileSystem(conf);

   try {
     Path dir = new Path("/test");
     Path file1 = new Path("/test/test1");
     Path file2 = new Path("/test/test2");
     boolean exceededQuota = false;
     final int QUOTA_SIZE = 3 * BLOCK_SIZE; // total space usage including
                                            // repl.
     final int FILE_SIZE = BLOCK_SIZE / 2;
     ContentSummary c;
     
     // Create the directory and set the quota
     assertTrue(fs.mkdirs(dir));
     runCommand(admin, false, "-setSpaceQuota", Integer.toString(QUOTA_SIZE),
         dir.toString());

     // Creating a file should use half the quota
     DFSTestUtil.createFile(fs, file1, FILE_SIZE, (short) 3, 1L);
     DFSTestUtil.waitReplication(fs, file1, (short) 3);
     c = fs.getContentSummary(dir);
     checkContentSummary(c, webhdfs.getContentSummary(dir));
     assertEquals("Quota is half consumed", QUOTA_SIZE / 2,
                  c.getSpaceConsumed());

     // We can not create the 2nd file because even though the total spaced
     // used by two files (2 * 3 * 512/2) would fit within the quota (3 * 512)
     // when a block for a file is created the space used is adjusted
     // conservatively (3 * block size, ie assumes a full block is written)
     // which will violate the quota (3 * block size) since we've already 
     // used half the quota for the first file.
     try {
       DFSTestUtil.createFile(fs, file2, FILE_SIZE, (short) 3, 1L);
     } catch (QuotaExceededException e) {
       exceededQuota = true;
     }
     assertTrue("Quota not exceeded", exceededQuota);
   } finally {
     cluster.shutdown();
   }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:63,代碼來源:TestQuota.java

示例5: execute

import org.apache.hadoop.fs.FileSystem; //導入方法依賴的package包/類
/**
 * Executes the filesystem operation.
 *
 * @param fs filesystem instance to use.
 *
 * @return a Map object (JSON friendly) with the content-summary.
 *
 * @throws IOException thrown if an IO error occured.
 */
@Override
public Map execute(FileSystem fs) throws IOException {
  ContentSummary contentSummary = fs.getContentSummary(path);
  return contentSummaryToJSON(contentSummary);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:15,代碼來源:FSOperations.java


注:本文中的org.apache.hadoop.fs.FileSystem.getContentSummary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。