Search in sources :

Example 86 with BlockLocation

use of org.apache.hadoop.fs.BlockLocation in project ignite by apache.

the class IgniteHadoopFileSystemAbstractSelfTest method testGetFileBlockLocations.

/** @throws Exception If failed. */
public void testGetFileBlockLocations() throws Exception {
    Path igfsHome = new Path(PRIMARY_URI);
    Path file = new Path(igfsHome, "someFile");
    try (OutputStream out = new BufferedOutputStream(fs.create(file, true, 1024 * 1024))) {
        byte[] data = new byte[128 * 1024];
        for (int i = 0; i < 100; i++) out.write(data);
        out.flush();
    }
    try (FSDataInputStream in = fs.open(file, 1024 * 1024)) {
        byte[] data = new byte[128 * 1024];
        int read;
        do {
            read = in.read(data);
        } while (read > 0);
    }
    FileStatus status = fs.getFileStatus(file);
    int grpLen = 128 * 512 * 1024;
    int grpCnt = (int) ((status.getLen() + grpLen - 1) / grpLen);
    BlockLocation[] locations = fs.getFileBlockLocations(status, 0, status.getLen());
    assertEquals(grpCnt, locations.length);
}
Also used : Path(org.apache.hadoop.fs.Path) IgfsPath(org.apache.ignite.igfs.IgfsPath) FileStatus(org.apache.hadoop.fs.FileStatus) BufferedOutputStream(java.io.BufferedOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) BlockLocation(org.apache.hadoop.fs.BlockLocation) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) BufferedOutputStream(java.io.BufferedOutputStream)

Example 87 with BlockLocation

use of org.apache.hadoop.fs.BlockLocation in project ignite by apache.

the class HadoopIgfs20FileSystemAbstractSelfTest method testGetFileBlockLocations.

/** @throws Exception If failed. */
public void testGetFileBlockLocations() throws Exception {
    Path igfsHome = new Path(primaryFsUri);
    Path file = new Path(igfsHome, "someFile");
    try (OutputStream out = new BufferedOutputStream(fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())))) {
        byte[] data = new byte[128 * 1024];
        for (int i = 0; i < 100; i++) out.write(data);
        out.flush();
    }
    try (FSDataInputStream in = fs.open(file, 1024 * 1024)) {
        byte[] data = new byte[128 * 1024];
        int read;
        do {
            read = in.read(data);
        } while (read > 0);
    }
    FileStatus status = fs.getFileStatus(file);
    int grpLen = 128 * 512 * 1024;
    int grpCnt = (int) ((status.getLen() + grpLen - 1) / grpLen);
    BlockLocation[] locations = fs.getFileBlockLocations(file, 0, status.getLen());
    assertEquals(grpCnt, locations.length);
}
Also used : Path(org.apache.hadoop.fs.Path) IgfsPath(org.apache.ignite.igfs.IgfsPath) FileStatus(org.apache.hadoop.fs.FileStatus) BufferedOutputStream(java.io.BufferedOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) BlockLocation(org.apache.hadoop.fs.BlockLocation) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BlockLocation (org.apache.hadoop.fs.BlockLocation)87 Path (org.apache.hadoop.fs.Path)41 FileStatus (org.apache.hadoop.fs.FileStatus)30 Test (org.junit.Test)29 FileSystem (org.apache.hadoop.fs.FileSystem)16 Configuration (org.apache.hadoop.conf.Configuration)14 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)10 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)10 DatanodeInfo (org.apache.hadoop.hdfs.protocol.DatanodeInfo)7 DataNode (org.apache.hadoop.hdfs.server.datanode.DataNode)7 InetSocketAddress (java.net.InetSocketAddress)5 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)5 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)5 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)5 LocatedBlocks (org.apache.hadoop.hdfs.protocol.LocatedBlocks)5 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)5 IgfsPath (org.apache.ignite.igfs.IgfsPath)5 HashMap (java.util.HashMap)4 Random (java.util.Random)4