-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJobClient.java
73 lines (63 loc) · 2.44 KB
/
JobClient.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
import java.io.*;
import java.util.*;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import MapReduceProto.MapReduce.*;
import Utils.*;
import IJobTracker.*;
public class JobClient {
public static void main(String args[]) {
if(args.length < 5){
System.out.println("JobClient should be invoked as 'JobClient <mapName> <reducerName> <inputFile in HDFS> <outputFile in HDFS> <numReducers>'");
}
try {
JobSubmitRequest.Builder request = JobSubmitRequest.newBuilder();
request.setMapName(args[0]);
request.setReducerName(args[1]);
request.setInputFile(args[2]);
request.setOutputFile(args[3]);
request.setNumReduceTasks(Integer.parseInt(args[4]));
Registry registry = LocateRegistry.getRegistry();
IJobTracker stub = (IJobTracker) registry.lookup("jobtracker");
byte[] responseByte = stub.jobSubmit(Utils.serialize(request.build()));
JobSubmitResponse response = (JobSubmitResponse) Utils.deserialize(responseByte);
if (response.getStatus() == 1){
int jobId = response.getJobId();
System.out.println(jobId);
trackJob(jobId);
} else {
System.out.println("TRY AGAIN!! SOME ERROR OCCURED!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void trackJob(int jobId) {
try {
JobStatusRequest.Builder request = JobStatusRequest.newBuilder();
request.setJobId(jobId);
Registry registry = LocateRegistry.getRegistry();
IJobTracker stub = (IJobTracker) registry.lookup("jobtracker");
while(true) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
if (line.equals("track")) {
byte[] responseByte = stub.getJobStatus(Utils.serialize(request.build()));
JobStatusResponse response = (JobStatusResponse) Utils.deserialize(responseByte);
if (response.getStatus() == 1){
if(response.getJobDone()){
System.out.println("JOB DONE!!");
return;
}
System.out.println("Total Map Tasks : "+response.getTotalMapTasks());
System.out.println("Total Map Tasks Started: "+response.getNumMapTasksStarted());
System.out.println("Total Reduce Tasks : "+response.getTotalReduceTasks());
System.out.println("Total Reduce Tasks Started : "+response.getNumReduceTasksStarted());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}