Example usage for org.apache.hadoop.hdfs.protocol ClientProtocol getBlockLocations

List of usage examples for org.apache.hadoop.hdfs.protocol ClientProtocol getBlockLocations

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.protocol ClientProtocol getBlockLocations.

Prototype

@Idempotent
LocatedBlocks getBlockLocations(String src, long offset, long length) throws IOException;

Source Link

Document

Get locations of the blocks of the specified file within the specified range.

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

/**
 * @see ClientProtocol#getBlockLocations(String, long, long)
 *///from w ww.  j  av a 2s .  c  om
static LocatedBlocks callGetBlockLocations(ClientProtocol namenode, String src, long start, long length)
        throws IOException {
    try {
        return namenode.getBlockLocations(src, start, length);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException(AccessControlException.class, FileNotFoundException.class,
                UnresolvedPathException.class);
    }
}

From source file:com.splunk.shuttl.prototype.symlink.BucketBlockSymlinkPrototypeTest.java

License:Apache License

private void createSymlinkToPathInDir(Path path, File dir) throws IOException {
    File fileInDir = new File(dir, path.getName());

    DistributedFileSystem dfs = (DistributedFileSystem) hadoopFileSystem;
    ClientProtocol namenode = dfs.getClient().namenode;
    String pathOnHadoop = path.toUri().getPath();
    LocatedBlocks blockLocations = namenode.getBlockLocations(pathOnHadoop, 0, Long.MAX_VALUE);
    List<LocatedBlock> locatedBlocks = blockLocations.getLocatedBlocks();
    if (!locatedBlocks.isEmpty()) {
        doSymlinkPathInDir(fileInDir, blockLocations, locatedBlocks);
    } else {//from w  w  w .  java  2  s  . c o m
        // Means that they don't have a block and that they are empty files. Just
        // create them.
        assertTrue(fileInDir.createNewFile());
    }
}

From source file:fm.last.hadoop.tools.BlockFinder.java

License:Apache License

@Override
public int run(String[] argv) throws IOException {
    StringBuilder b = new StringBuilder();

    ClientProtocol namenode = DFSClient.createNamenode(getConf());
    for (String fileName : argv) {
        FileStatus[] fileStatuses = fs.globStatus(new Path(fileName));
        for (FileStatus fileStatus : fileStatuses) {
            if (!fileStatus.isDir()) {
                out.println("FILE: " + fileStatus.getPath().toString());

                String path = fileStatus.getPath().toUri().getPath();
                LocatedBlocks blocks = namenode.getBlockLocations(path, 0, fileStatus.getLen());

                for (LocatedBlock block : blocks.getLocatedBlocks()) {
                    b.setLength(0);/*www  . j av a  2 s  .c om*/
                    b.append(block.getBlock());
                    b.append(" - ");

                    List<String> nodes = newArrayList();
                    for (DatanodeInfo datanodeInfo : block.getLocations()) {
                        nodes.add(datanodeInfo.name);
                    }
                    b.append(Joiner.on(", ").join(nodes));
                    out.println(b.toString());
                }

            }
            out.println();
        }
    }
    return 0;
}