查找某个文件在HDFS集群中的位置
来源:互联网 发布:tasty大龙小龙知乎 编辑:程序博客网 时间:2024/05/21 09:14
通过"FileSystem.getFileBlockLocation(FileStatus file,long start,long len)"可查找指定文件在HDFS集群上的位置,其中file为文件的完整路径,start和len来标识查找文件的路径。
以下是java代码的实现:
package com.njupt.hadoop;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
public class FindFileOnHDFS {
public static void main(String[] args) throws Exception{
getHDFSNodes();
getFileLocal();
}
public static void getFileLocal() throws Exception {
Configuration conf = new Configuration();
FileSystem hdfs = FileSystem.get(conf);
Path fpath = new Path("/user/root/20120722/word.txt");
FileStatus fileStatus = hdfs.getFileStatus(fpath);
BlockLocation[] blkLocations = hdfs.getFileBlockLocations(fileStatus, 0, fileStatus.getLen());
int blockLen = blkLocations.length;
for(int i = 0 ; i < blockLen ; ++i ){
String[] hosts = blkLocations[i].getHosts();
System.out.println("block_"+i + "_location:" + hosts[i]);
}
}
public static void getHDFSNodes() throws Exception{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
DistributedFileSystem hdfs = (DistributedFileSystem)fs;
DatanodeInfo[] dataNodeStats = hdfs.getDataNodeStats();
for( int i = 0 ; i < dataNodeStats.length ; ++i ){
System.out.println("DataNode_" + i + "_Node:" + dataNodeStats[i].getHostName());
}
}
}
- 查找某个文件在HDFS集群中的位置
- 查找某个文件在HDFS集群的位置
- Hadoop——查找摸个文件在HDFS集群中的位置
- 查找某个元素在数组中的位置
- 在Linux中查找某个文件的位置
- Hadoop-No.6之文件在HDFS中的位置
- hadoop中查找某个字符串所在的hdfs位置
- linux下查找某个文件的位置
- 用gawk遍历目录查找字符串在文件中的位置
- 查找某个字符在一个字符串中的位置,假设字符串中的字符是有序的,如“adfgikmnprs”中查找g的位置。(折半查找)
- 获取某个字符在字符串中的位置
- linux下查找某个文件位置的方法
- linux下查找某个文件位置的方法
- linux下查找某个文件位置的方法
- linux下查找某个文件位置的方法
- linux下查找某个文件位置的方法
- 嵌入式 linux下查找某个文件位置的方法
- linux下查找某个文件位置的方法
- C++实现贪心算法-找零钱
- CodeForces-April Fools Day Contest 2013 - A
- 新一代大智慧文件夹结构
- 一道阿里巴巴笔试题
- c++类的实例化,有没有new的区别
- 查找某个文件在HDFS集群中的位置
- tar.xz格式文件的解压方法(转)
- 将本地文件拷到HDFS中
- map遍历
- POJ2352:Stars
- # museum(Gauss-Jordan/Gauss对比-4倍常数)
- 心动C++情牵队列
- 使用java实现在HDFS中创建文件夹
- Openstack Folsom Centos6.3 常用命令总结