/**
* 获取hadoop相关配置信息
* @param hadoopConfPath 目前用户需要提供hadoop的配置文件路径
* @return
*/
public static Configuration getHadoopConfig(String hadoopConfPath){
Configuration conf=new Configuration();
conf.addResource(new Path(hadoopConfPath+"/core-site.xml"));
conf.addResource(new Path(hadoopConfPath+"/hdfs-site.xml"));
return conf;
} /**
* 获取hdfs文件系统连接
* @param hadoopConfPath 目前用户需要提供hadoop的配置文件路径
* @return
*/
public static FileSystem getFileSystem(String hadoopConfPath) {
Configuration conf=new Configuration();
conf.addResource(new Path(hadoopConfPath+"/core-site.xml"));
conf.addResource(new Path(hadoopConfPath+"/hdfs-site.xml"));
FileSystem fs = null;
try {
fs=FileSystem.get(conf);
} catch (IOException e) { LOGGER.error("从path={}路径获取hadoop配置信息错误:{}", hadoopConfPath, e.getMessage()); } return fs;
}

正则匹配路径的方法:

 /**
* 通过正则获取该目录下满足条件的所有目录
* @param luceneFilePathRegular 正则目录,如/user/solrindex/正则表达式
* @return 满足正则表达式的目录集合 list
*/
public static List<String> fetchDirByRegularLinux(String luceneFilePathRegular){
List<String> list=new ArrayList<>();
//分割获取主目录
int len= luceneFilePathRegular.lastIndexOf(EtlConstants.LINUX_ROUTE_SEGMENT)+1;
String mainDir=luceneFilePathRegular.substring(0, len);
String regular=luceneFilePathRegular.substring(len,luceneFilePathRegular.length());
File dir=new File(mainDir);
if(dir.exists() && dir.isDirectory()){
File [] arr= dir.listFiles();
for (File file : arr) {
if (file.exists() && file.isDirectory()) {
String fileName = file.getName();
if (matchStr(fileName, regular)) {
list.add(file.getAbsolutePath()+SolrUtil.INDEX_DIR_SUFFIX);
}
}
}
}
if(list.size()>0){
LOGGER.info("通过正则匹配到的Solr目录有:");
for (String s : list) {
LOGGER.info(s);
}
}else{
LOGGER.error("路径{}下,不存在满足正则:{}条件的目录", dir, regular);
}
return list;
} /**
* 通过正则获取该目录下满足条件的所有目录
* @param luceneFilePathRegular 正则目录,如hdfs:/user/solrindex/正则表达式
* @param nameNodeConfigPath //获取name配置信息目录
* @return 满足正则表达式的目录集合 list
*/
public static List<String> fetchDirByRegularHdfs(String luceneFilePathRegular,String nameNodeConfigPath){
List<String> list=new ArrayList<>();
FileSystem fs=HdfsUtil.getFileSystem(nameNodeConfigPath);
String prefixHdfs=luceneFilePathRegular.split(":")[0];
String hdfsPath=luceneFilePathRegular.split(":")[1];
//分割获取主目录
int len= hdfsPath.lastIndexOf(EtlConstants.LINUX_ROUTE_SEGMENT)+1;
String mainDir=hdfsPath.substring(0, len);
String regular=hdfsPath.substring(len, hdfsPath.length());
try {
FileStatus[] fileStatuses = fs.globStatus(new Path(mainDir+"*"));
for (FileStatus fileStatus : fileStatuses){
if (fileStatus.isDirectory() && matchStr(fileStatus.getPath().getName(), regular)) {
list.add(prefixHdfs+":"+mainDir+fileStatus.getPath().getName()+SolrUtil.INDEX_DIR_SUFFIX);
}
} } catch (IOException e) {
LOGGER.error("获取hdfs目录信息异常,路径:{},异常信息:{}",luceneFilePathRegular,e.getMessage());
e.printStackTrace();
}
if(list.size()>0){
LOGGER.info("通过正则匹配到的Solr目录有:");
for (String s : list) {
LOGGER.info(s);
}
}else{
LOGGER.error("路径{}下,不存在满足正则:{}条件的目录", luceneFilePathRegular, regular);
}
return list;
} /**
* @Method Description:按正则表示是匹配字符串
* @param str
* @param regular
* @return
* @author: libingjie
*/
public static Boolean matchStr(String str, String regular) {
Pattern pattern = Pattern.compile(regular);
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}

4、记录1----获取hdfs上FileSystem的方法 记录2:正则匹配路径:linux、hdfs的更多相关文章

  1. php程序无法记录log情况下可尝试下面方法记录log

    error_reporting(E_ERROR | E_PARSE); function shutdownCallback(){    $arrError = error_get_last(); // ...

  2. python获取文件扩展名的方法(转)

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...

  3. python获取文件扩展名的方法

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...

  4. Linux记录-shell获取hdfs used使用

    #!/bin/bash export JAVA_HOME=/app/jdk/jdk1.8.0_92 export HADOOP_HOME=/app/hadoop export HADOOP_CONF_ ...

  5. Eclipse 上传 删除 下载 分析 hdfs 上的文件

    本篇讲解如何通过Eclipse 编写代码去操作分析hdfs 上的文件. 1.在eclipse 下新建Map/Reduce Project项目.如图:  项目建好后,会默认加载一系列相应的jar包. 下 ...

  6. 用流的方式来操作hdfs上的文件

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...

  7. HBase 在HDFS 上的目录树

         总所周知,HBase 是天生就是架设在 HDFS 上,在这个分布式文件系统中,HBase 是怎么去构建自己的目录树的呢? 这里只介绍系统级别的目录树. 一.0.94-cdh4.2.1版本 系 ...

  8. hadoop的API对HDFS上的文件访问

    这篇文章主要介绍了使用hadoop的API对HDFS上的文件访问,其中包括上传文件到HDFS上.从HDFS上下载文件和删除HDFS上的文件,需要的朋友可以参考下hdfs文件操作操作示例,包括上传文件到 ...

  9. iOS获取UIView上某点的颜色值

    项目需求中遇到获取UIView上某个坐标点的RGB颜色值的需求,现在把自己找到的解决方案简单总结记录一下,遇到了下面的情况: 不可移动的UIView 旋转式的UIView 滑条式的UIView 不可移 ...

随机推荐

  1. KM算法专题

    原文:http://972169909-qq-com.iteye.com/blog/1184514 题目地址:这里. 1)求图中所有环的总长度(环的长度不唯一)的最小值.当无法得到完备匹配时说明环不存 ...

  2. MySQL学习笔记(3) - 查询服务器版本,当前时间,当前用户

    SELECT VERSION(); --显示当前服务器版本 SELECT NOW(); --显示当前日期时间 SELECT USER(); --显示当前用户 MySQL中语句规范: 1.关键字和函数名 ...

  3. web标准(复习)--1

    XHTML CSS基础知识 一.xhtml css基础知识首先说一下我们这节课的知识点 1.文档类型 2.语言编码 3.html标签 4.css样式 5.css优先级 6.css盒模型组成 1)文档类 ...

  4. 分享一个js生成二维码的库

    二维码用js生成会比用服务器生成方便很多,只要把window.location.href的值传入,即可生成对应的二维码..最主要是,这个库可以兼容ie6~ie9哦... 具体使用,请看官网:http: ...

  5. Android热补丁动态修复

    1.前言 由于公司项目中使用到热修复技术,之前对这块技术知之甚少,所以有时间去学习了解了一下. 2.学习资源 2.1 热修复介绍 还是鸿洋老师的精彩讲解,中间引用了Andorid dex分包方案和QQ ...

  6. javascript 事件触发

    http://www.zhangxinxu.com/wordpress/2012/04/js-dom%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BA%8B%E4%BB%B6/ htt ...

  7. SVN莫名出错,网上找遍无果,递归删除当前目录下所有.svn文件名

    哎,太深刻的教训. 原来以前其它目录里有.SVN目录 ,而此SVN目录COPY到真正的SVN工作目录之后,会将有用的.SVN目录覆盖. 那么一样,显然,CI,UPDATE,CO之间的命令全部异常... ...

  8. XJOI网上同步训练DAY6 T1

    思路:考试的时候直接想出来了,又有点担心复杂度,不过还是打了,居然是直接A掉,开心啊. 我们发现,Ai<=7,这一定是很重要的条件,我们考虑状态压缩,去枚举路径中出现了哪些数字,然后我们把原来n ...

  9. 勾选checkbox之后,button按钮可用

    js:function chkClick() {    if (document.getElementById("chkBox").checked == true) {       ...

  10. BAT线下战争:巨额投资或培养出自己最大对手(包括美团、58、饿了么在内的公司都在计划推出自己的支付工具和金融产品,腾讯只做2不做O)

    BAT线下战争:巨额投资或培养出自己最大对手 2015年10月12日09:49   <财经>杂志    我有话说(18人参与) 收藏本文        BAT大举投资线下公司,看似咄咄逼人 ...