-
Notifications
You must be signed in to change notification settings - Fork 23
/
TestExternalHadoopCall.java
151 lines (126 loc) · 6.48 KB
/
TestExternalHadoopCall.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package dk.netarkivet.harvester.heritrix3.report;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/** Experiment class to implement wrapper around the following hadoop command:
* /home/svc/hadoop-1.2.1/bin/hadoop jar /home/svc/jbs/jbs-fatjar.jar org.archive.jbs.Parse /tmp/ /home/svc/webdanica-hadoop-test-data/431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz
*
* Results in the file /tmp/431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz
*
* There is problems running hadoop using the ProcessBuilder. The process fails with error:
*
*
* Ready to write hadoop-data to /tmp/1462292109062
cmd: /home/svc/hadoop-1.2.1/bin/hadoop jar /home/svc/jbs/jbs-fatjar.jar org.archive.jbs.Parse /tmp/1462292109062 /data1/svc/webdanica-hadoop-test-data/431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz
command: . jar /home/svc/jbs/jbs-fatjar.jar org.archive.jbs.Parse /tmp/1462292109062 /data1/svc/webdanica-hadoop-test-data/431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz
Using java: /usr/java/jdk1.8.0_20_x64/bin/java
Error: Could not find or load main class .home.svc.jbs.jbs-fatjar.jar
When running the full command in the bash shell, the command as seen by hadoop script is only 'jar', not 'jar ... 431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz'
*
*
* */
public class TestExternalHadoopCall {
public static void main(String[] args) throws InterruptedException {
File testWarc = new File("/home/svc/webdanica-hadoop-test-data/431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz");
File hadoopPath = new File("/home/svc/hadoop-1.2.1/bin/hadoop");
File pathToJarfile = new File("/home/svc/jbs/jbs-fatjar.jar");
File tmpDir = new File("/tmp/" + System.currentTimeMillis());
tmpDir.mkdirs();
if (tmpDir.canWrite()){
System.out.println("Ready to write hadoop-data to " + tmpDir.getAbsolutePath());
}
//runHadoopParsedText(testWarc, hadoopPath, pathToJarfile, tmpDir);
runHadoopParsedTextAlternate(testWarc, hadoopPath, pathToJarfile, tmpDir);
// ./bin/hadoop jar ../jbs/jbs-fatjar.jar org.archive.jbs.Parse /tmp/ ../jwat-tools-0.6.2/431-35-20160317083714655-00000-sb-test-har-001.statsbiblioteket.dk.warc.gz
}
public static void runHadoopParsedText(File testWarc, File hadoopPath, File pathToJarfile, File outputdir) {
try {
String cmdString = hadoopPath.getAbsolutePath() + " jar " + pathToJarfile.getAbsolutePath() + " org.archive.jbs.Parse " + outputdir.getAbsolutePath() + " " + testWarc.getAbsolutePath();
System.out.println("cmd: " + cmdString);
List<String> commandList = makeCommandlist( testWarc, hadoopPath, pathToJarfile, outputdir);
//commandList.add(cmdString);
ProcessBuilder pb = new ProcessBuilder(commandList);
pb.redirectErrorStream(true);
Process p = pb.start();
/*
Runtime rt = Runtime.getRuntime();
Process p = rt.exec( cmdString );
p.waitFor();
*/
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
boolean f = false;
String location = null;
while ((s = r.readLine())!=null) {
System.out.println(s);
/*
/if (s.contains("Location")){
foundLocation = true;
location = s.split("Location:")[1];
} */
}
r.close();
} catch ( IOException ioe ) {
ioe.printStackTrace();
}
}
private static List<String> makeCommandlist(File testWarc, File hadoopPath,
File pathToJarfile, File outputdir) {
List<String> commandList = new ArrayList<String>();
commandList.add(hadoopPath.getAbsolutePath());
commandList.add("jar " + pathToJarfile.getAbsolutePath() + " org.archive.jbs.Parse "
+ outputdir.getAbsolutePath() + " " + testWarc.getAbsolutePath());
//commandList.add("org.archive.jbs.Parse");
//commandList.add(outputdir.getAbsolutePath());
//commandList.add(testWarc.getAbsolutePath());
return commandList;
}
public static void runHadoopParsedTextAlternate(File testWarc, File hadoopPath, File pathToJarfile, File outputdir) throws InterruptedException {
//try {
String cmdString = hadoopPath.getAbsolutePath() + " jar " + pathToJarfile.getAbsolutePath() + " org.archive.jbs.Parse " + outputdir.getAbsolutePath() + " " + testWarc.getAbsolutePath();
System.out.println("cmd: " + cmdString);
/*
List<String> commandList = makeCommandlist( testWarc, hadoopPath, pathToJarfile, outputdir);
//commandList.add(cmdString);
ProcessBuilder pb = new ProcessBuilder(commandList);
pb.directory(directory); // Set the working directory of this projects
pb.redirectErrorStream(true);
Process p = pb.start();
*/
Runtime rt = Runtime.getRuntime();
rt.traceInstructions(true);
rt.traceMethodCalls(true);
Process p = null;
try {
p = rt.exec( cmdString );
while (p.isAlive()) {
Thread.sleep(4000L);
System.out.println("Still alive");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//p.waitFor();
/*
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while ((s = r.readLine())!=null) {
System.out.println(s);
/*
/if (s.contains("Location")){
foundLocation = true;
location = s.split("Location:")[1];
} */
// }
//r.close();
/*
} catch ( IOException ioe ) {
ioe.printStackTrace();
}
*/
}
}