Example usage for org.apache.hadoop.hdfs DFSClient getDiskStatus

List of usage examples for org.apache.hadoop.hdfs DFSClient getDiskStatus

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSClient getDiskStatus.

Prototype

public FsStatus getDiskStatus() throws IOException 

Source Link

Usage

From source file:org.openflamingo.fs.hdfs.HdfsFileSystemProvider.java

License:Apache License

@Override
public Map<String, Object> getFileSystemStatus(String type) {
    Map<String, Object> map = new HashMap();
    DFSClient dfsClient = null;
    try {/*w ww  .j av a 2  s  . c o  m*/
        dfsClient = new DFSClient(fs.getConf());
        map.put("canonicalServiceName", fs.getCanonicalServiceName());
        map.put("defaultReplication", fs.getDefaultReplication());
        map.put("defaultBlockSize", fs.getDefaultBlockSize());
        map.put("workingDirectory", fs.getWorkingDirectory().toUri().getPath());
        map.put("homeDirectory", fs.getHomeDirectory().toUri().getPath());
        map.put("corruptBlocksCount", dfsClient.getCorruptBlocksCount());
        map.put("missingBlocksCount", dfsClient.getMissingBlocksCount());
        map.put("underReplicatedBlocksCount", dfsClient.getUnderReplicatedBlocksCount());
        map.put("capacity", dfsClient.getDiskStatus().getCapacity());
        map.put("used", dfsClient.getDiskStatus().getDfsUsed());
        map.put("remaining", dfsClient.getDiskStatus().getRemaining());
        map.put("deadNodes", dfsClient.namenode.getDatanodeReport(FSConstants.DatanodeReportType.DEAD).length);
        map.put("liveNodes", dfsClient.namenode.getDatanodeReport(FSConstants.DatanodeReportType.LIVE).length);
        map.put("humanCapacity", byteDesc(dfsClient.getDiskStatus().getCapacity()));
        map.put("humanUsed", byteDesc(dfsClient.getDiskStatus().getDfsUsed()));
        map.put("humanProgressPercent", formatPercent((double) dfsClient.getDiskStatus().getRemaining()
                / (double) dfsClient.getDiskStatus().getCapacity(), 2));
        map.put("humanProgress", (float) dfsClient.getDiskStatus().getRemaining()
                / (float) dfsClient.getDiskStatus().getCapacity());
        map.put("humanRemaining", byteDesc(dfsClient.getDiskStatus().getRemaining()));
        map.put("humanDefaultBlockSize", byteDesc(fs.getDefaultBlockSize()));
        dfsClient.close();
        return map;
    } catch (Exception ex) {
        throw new FileSystemException(bundle.message("S_FS", "CANNOT_ACCESS_FS_STATUS"), ex);
    } finally {
        IOUtils.closeQuietly(dfsClient);
    }
}