jiapeng 6 years ago
parent
commit
937b38401f

+ 2 - 2
pom.xml

10
    <packaging>war</packaging>
10
    <packaging>war</packaging>
11
    <properties>
11
    <properties>
12
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13
        <maven.compiler.source>1.7</maven.compiler.source>
14
        <maven.compiler.target>1.7</maven.compiler.target>
13
        <maven.compiler.source>1.8</maven.compiler.source>
14
        <maven.compiler.target>1.8</maven.compiler.target>
15
        <maven.war.filteringDeploymentDescriptors>true</maven.war.filteringDeploymentDescriptors>
15
        <maven.war.filteringDeploymentDescriptors>true</maven.war.filteringDeploymentDescriptors>
16
        <maven.tomcat.path>/</maven.tomcat.path>
16
        <maven.tomcat.path>/</maven.tomcat.path>
17
    </properties>
17
    </properties>

+ 18 - 8
src/main/java/com/ekexiu/project/hdfs/HdfsService.java

26

26

27

27

28
	public void setRemoteUrl(String remoteUrl) {
28
	public void setRemoteUrl(String remoteUrl) {
29
		System.setProperty("HADOOP_USER_NAME", "hadoop");
29
		this.remoteUrl = remoteUrl;
30
		this.remoteUrl = remoteUrl;
30
		configuration.set("fs.default.name", this.remoteUrl);
31
		configuration.set("fs.default.name", this.remoteUrl);
31
		try {
32
		try {
36
	}
37
	}
37
	
38
	
38
	public void upload(String path,File src) throws IOException{
39
	public void upload(String path,File src) throws IOException{
40
		Path dstPath = new Path(root,path);
39
		if(src.exists() && src.isDirectory()){
41
		if(src.exists() && src.isDirectory()){
40
			Path dst  =  new Path(root,path);
41
			if(this.dfs.exists(dst)){
42
				if(!this.dfs.delete(dst,true)){
43
					throw new IOException("delete "+configuration.get("fs.default.name")+path.toString()+" error");
42
			if(!this.dfs.exists(dstPath)){
43
				if(!this.dfs.mkdirs(dstPath)){
44
					throw new IOException("mkdir "+configuration.get("fs.default.name")+"/"+path+" error");
44
				}
45
				}
45
			}
46
			}
46
			if(!this.dfs.mkdirs(dst)){
47
				throw new IOException("mkdir "+configuration.get("fs.default.name")+path.toString()+" error");
47
			
48
			
49
			for(File file:src.listFiles()){
50
				Path dst = new Path(dstPath,file.getName());
51
				if(this.dfs.exists(dst)){
52
					if(!this.dfs.delete(dst,true)){
53
						throw new IOException("delete "+configuration.get("fs.default.name")+"/"+path+"/"+file.getName()+" error");
54
					}
55
				}
56
				this.dfs.copyFromLocalFile(new Path(src.getAbsolutePath()), dst);
48
			}
57
			}
49
			this.dfs.copyFromLocalFile(new Path(src.getAbsolutePath()), dst);
50
		}
58
		}
51
		
59
		
52
	}
60
	}
55
	public static void main(String args[]) throws Exception{
63
	public static void main(String args[]) throws Exception{
56
		HdfsService service = new HdfsService();
64
		HdfsService service = new HdfsService();
57
		service.setRemoteUrl("hdfs://39.97.161.48:9000");
65
		service.setRemoteUrl("hdfs://39.97.161.48:9000");
58
		service.upload("11",new File("/ekexiu/storage_asd/dst/a"));
66
		service.upload("25",new File("/ekexiu/storage_asd/task/result/test/data_desen"));
67
		
68
		System.out.println("11111111111111111111111111111111");
59
	}
69
	}
60

70

61
}
71
}

+ 1 - 1
src/main/java/com/ekexiu/project/storage/diacrisis/AiCleanTask.java

32
		File file = new File(aiTaskService.getDstPath(), taskId);
32
		File file = new File(aiTaskService.getDstPath(), taskId);
33
		file = new File(file,"data");
33
		file = new File(file,"data");
34
			try {
34
			try {
35
				URL u = new URL("http://127.0.0.1:5001//desensitize?pi=" + file.getAbsolutePath());
35
				URL u = new URL("http://127.0.0.1:5001/desensitize?pi=" + file.getAbsolutePath());
36
				HttpURLConnection httpURLConnection = (HttpURLConnection) u.openConnection();
36
				HttpURLConnection httpURLConnection = (HttpURLConnection) u.openConnection();
37
				if (httpURLConnection.getResponseCode() == 200) {
37
				if (httpURLConnection.getResponseCode() == 200) {
38
					InputStream in = httpURLConnection.getInputStream();
38
					InputStream in = httpURLConnection.getInputStream();