public void test() throws IOException { Configuration conf = new Configuration(); conf.addResource("conf/hdfs/test-hdfs-client-conf.xml"); System.setProperty("HADOOP_USER_NAME", "hdfs"); DistributedFileSystem fs = (DistributedFileSystem) FileSystem.get(conf); DatanodeInfo[] dataNodeStatus = fs.getDataNodeStats(); for (DatanodeInfo dninfo : dataNodeStatus) { System.out.println(dninfo.getHostName() + ", Is Decommission:" + dninfo.isDecommissioned()); System.out.println(dninfo.getHostName() + ", Dump Data node:" + dninfo.dumpDatanode()); } System.out.println("Default block size:" + fs.getDefaultBlockSize()); ContentSummary contentSummary = fs.getContentSummary(new Path("/")); System.out.println("Content Summary:" + contentSummary); FsStatus fsstatus = fs.getStatus(); System.out.println(fsstatus.getCapacity()); }
@Override protected void processPath(PathData item) throws IOException { FsStatus fsStats = item.fs.getStatus(item.path); long size = fsStats.getCapacity(); long used = fsStats.getUsed(); long free = fsStats.getRemaining(); usagesTable.addRow( item.fs.getUri(), formatSize(size), formatSize(used), formatSize(free), StringUtils.formatPercent((double)used/(double)size, 0) ); }
/** * 此方法用于获取文件的FsStatus * * @param fileSystemInfo * 文件系统信息 * @param path * 文件路径 * @return FsStatus */ public static FsStatus getStatus(FileSystemInfo fileSystemInfo, String path) { FileSystem fs = getFileSystem(fileSystemInfo); Path uri = new Path(path); try { pathNotExistCheck(path, fs, uri); return fs.getStatus(uri); } catch (IOException e) { e.printStackTrace(); } finally { closeFileSystem(fs); } return null; }
@Override public FsStatus getStatus() throws IOException { try { return underlyingFs.getStatus(); } catch(FSError e) { throw propagateFSError(e); } }
@Override public FsStatus getStatus(Path p) throws IOException { try { return underlyingFs.getStatus(p); } catch(FSError e) { throw propagateFSError(e); } }
/** @throws Exception If failed. */ public void testStatus() throws Exception { Path file1 = new Path("/file1"); try (FSDataOutputStream file = fs.create(file1, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()))) { file.write(new byte[1024 * 1024]); } FsStatus status = fs.getFsStatus(); assertEquals(getClientFsUser(), fs.getFileStatus(file1).getOwner()); assertEquals(4, grid(0).cluster().nodes().size()); long used = 0, max = 0; for (int i = 0; i < 4; i++) { IgniteFileSystem igfs = grid(i).fileSystem("igfs"); IgfsMetrics metrics = igfs.metrics(); used += metrics.localSpaceSize(); max += metrics.maxSpaceSize(); } assertEquals(used, status.getUsed()); assertEquals(max, status.getCapacity()); }
/** * @see ClientProtocol#getStats() */ public FsStatus getDiskStatus() throws IOException { ClientActionHandler handler = new ClientActionHandler() { @Override public Object doAction(ClientProtocol namenode) throws RemoteException, IOException { return namenode.getStats(); } }; long rawNums[] = (long[]) doClientActionWithRetry(handler, "getDiskStatus"); return new FsStatus(rawNums[0], rawNums[1], rawNums[2]); }
@Override public FsStatus getStatus(Path p) throws IOException { CephStatVFS stat = new CephStatVFS(); ceph.statfs(p, stat); FsStatus status = new FsStatus(stat.bsize * stat.blocks, stat.bsize * (stat.blocks - stat.bavail), stat.bsize * stat.bavail); return status; }
@Override public FsStatus getStatus(Path p) throws IOException { return super.getStatus(fullPath(p)); }
@Override public FsStatus getFsStatus() throws IOException { return myFs.getFsStatus(); }
@Override public FsStatus getFsStatus() throws AccessControlException, FileNotFoundException, IOException { return new FsStatus(0, 0, 0); }
@Override public FsStatus getFsStatus() { return new FsStatus(0, 0, 0); }
@Override public FsStatus getStatus() throws IOException { return underlyingFs.getStatus(); }
@Override public FsStatus getStatus(Path p) throws IOException { return underlyingFs.getStatus(p); }
/** * @see ClientProtocol#getStats() */ public FsStatus getDiskStatus() throws IOException { long rawNums[] = callGetStats(); return new FsStatus(rawNums[0], rawNums[1], rawNums[2]); }
public DiskStatus(FsStatus stats) { super(stats.getCapacity(), stats.getUsed(), stats.getRemaining()); }
@Override public FsStatus getStatus(Path p) throws IOException { statistics.incrementReadOps(1); return dfs.getDiskStatus(); }