jiapeng лет назад: 6
Родитель
Сommit
937b38401f

+ 2 - 2
pom.xml

@ -10,8 +10,8 @@
10 10
    <packaging>war</packaging>
11 11
    <properties>
12 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 15
        <maven.war.filteringDeploymentDescriptors>true</maven.war.filteringDeploymentDescriptors>
16 16
        <maven.tomcat.path>/</maven.tomcat.path>
17 17
    </properties>

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

@ -26,6 +26,7 @@ public class HdfsService {
26 26

27 27

28 28
	public void setRemoteUrl(String remoteUrl) {
29
		System.setProperty("HADOOP_USER_NAME", "hadoop");
29 30
		this.remoteUrl = remoteUrl;
30 31
		configuration.set("fs.default.name", this.remoteUrl);
31 32
		try {
@ -36,17 +37,24 @@ public class HdfsService {
36 37
	}
37 38
	
38 39
	public void upload(String path,File src) throws IOException{
40
		Path dstPath = new Path(root,path);
39 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,7 +63,9 @@ public class HdfsService {
55 63
	public static void main(String args[]) throws Exception{
56 64
		HdfsService service = new HdfsService();
57 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,7 +32,7 @@ public class AiCleanTask implements Runnable{
32 32
		File file = new File(aiTaskService.getDstPath(), taskId);
33 33
		file = new File(file,"data");
34 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 36
				HttpURLConnection httpURLConnection = (HttpURLConnection) u.openConnection();
37 37
				if (httpURLConnection.getResponseCode() == 200) {
38 38
					InputStream in = httpURLConnection.getInputStream();