拉取hadoop集群上的hdfs檔案

2021-07-26 16:33:45 字數 2023 閱讀 9503

從hadoop集群拉取hdfs檔案是乙個常見的需求,基於org.apache.hadoop即可做到。

但是hadoop包有個明顯的缺點是引用太多,經常需要排包,包括但不限於httpclient,servlet,slf4j,tomcat等等

@service

public class hdfsclient

this.filesystem = filesystem.get(conf);

logger.info("init hdfs client success,proxy=" + proxy + ",username=" + username + ",useproxy=" + useproxy);

}/**

* 拉取無分割槽資料

* @param remotepath

* @param localpath

*/public void pullhdfs(string remotepath, string localpath) throws exception

if (!localpath.endswith(file.separator))

stopwatch time = new stopwatch();

time.start();

file file = new file(localpath);

deletefile(file);

pulldata(remotepath,localpath);

logger.info("pull {} to {} success! size={} time={}", remotepath, localpath, getdirsize(file), time.gettime());

time.stop();

}/**

* 計算資料夾大小

* @param file

* @return

*/private long getdirsize(final file file)

/*** 刪除老資料整個檔案路徑

** @param file

*/private void deletefile(file file) else if (file.isdirectory())

}file.delete();}}

/*** 拉取遠端資料到本地

* @param remotepath

* @param localpath

* @throws exception

*/private void pulldata(string remotepath, string localpath) throws exception

do }

catch (exception e) ", e);

trynum++;

}} while (trynum >1 && trynum <4);

if(trynum == 4)

}/**

* 刪除crc和success檔案

* @param file

*/private void deletecrcchecksum(file file)

} else if (file.isdirectory()) }}

}/**

* 判斷遠端檔案是否存在

* @param dfspath

* @return

* @throws ioexception

*/private boolean hdf***ist(final string dfspath) throws ioexception

/*** 拉取遠端檔案

* @param dfspath

* @param localpath

* @throws ioexception

*/private void hdfspull(final string dfspath, final string localpath) throws ioexception catch (exception e)

}}

使用git拉取github上的專案

使用git免密上傳和拉取和github上的專案 首先你要去github上註冊你的使用者名稱密碼!git config global user.name 這裡換上你的使用者名稱 git config global user.email 這裡換上你的郵箱 git config global listss...

使用git拉取github上的專案

1.在任意地方,新建資料夾,為防止出錯,最好保證該資料夾目錄都是英文。3.配置本地倉庫的賬號和郵箱 git config global user.name your name git config global user.email email example.com ssh keygen t rs...

通過公網IP訪問雲上的Hadoop集群

背景 從公司內部網路中的hadoop集群訪問部署在亞馬遜雲的hadoop集群 1.ip 網域名稱設定 1.1 給雲上每個例項設定乙個內網ip 如上圖10.0.0.5 1.2 給雲上每個例項繫結乙個elastic ip 彈性ip,如上圖x.x.x.1 並且與內網ip一一對應 1.3 給雲上每個例項配置...