hadoop-ui界面
properties配置
#HDFS相关配置
hdfs.defaultfs = fs.defaultFS
hdfs.user = hadoop
# 新版 默认8020 具体看core-site.xml 里面的defaultFS 配置,
# 但是 telnet 172.27.96.212 8020 拒绝访问,
# telnet 172.27.96.214 9000(以前的默认端口) 可以
# !所以这个 ip:port 可以看 hadoop-ui界面的 显示active的那个节点 !
hdfs.host = hdfs://172.27.96.214:9000
hdfs.model = /model_manager_customer/models
hdfs.model.up = /model_manager_customer/socr_models
pom.xml
<!--hadoop hdfs-->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.8.2</version>
</dependency>
hdfsUtils
package com.example.modelmanager.utils;
import com.example.modelmanager.enums.CommonEnum;
import com.example.modelmanager.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.io.IOUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
@Component
@Slf4j
public class HdfsUtils {
private Configuration getHdfsConfig(String defaultFS, String hdfsServer) {
Configuration conf = new Configuration();
conf.set(defaultFS, hdfsServer);
return conf;
}
private FileSystem getFileSystem(String defaultFS,String hdfsServer, String user) {
try {
return FileSystem.get(new URI(hdfsServer), getHdfsConfig(defaultFS, hdfsServer), user);
} catch (IOException | InterruptedException | URISyntaxException e) {
log.error(e.getMessage());
throw new BizException("500",e.getMessage());
}
}
public void getListNode(String defaultFS,String hdfsServer, String user) {
try {
FileSystem fs = getFileSystem(defaultFS,hdfsServer, user);
DistributedFileSystem hdfs = (DistributedFileSystem) fs