forked from forward/timothy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_driver.js
41 lines (37 loc) · 1.48 KB
/
local_driver.js
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
var exec = require('child_process').exec;
var LocalDriver = function(jobDescription) {
this.jobDescription = jobDescription;
};
LocalDriver.prototype.execute = function(i, input, output, cb) {
this.jobDescription.generate(i, function(err,job){
if(err) {
cb(err, "Error generating map reduce scripts");
} else {
var command;
var setup = "";
if(i==0)
setup = " && mkdir ./.npmcfg && npm config set userconfig ./.npmcfg && npm config set cache . && npm install > /dev/null";
if(output === null) {
command = "cd "+job.jobWorkingDirectory+setup+" && cat "+input+" | node "+job.mapperPath+" | node "+ __dirname+"/timothy/local_sorter.js | node "+job.reducerPath;
} else {
command = "cd "+job.jobWorkingDirectory+setup+" && cat "+input+" | node "+job.mapperPath+" | node "+ __dirname+"/timothy/local_sorter.js | node "+job.reducerPath +" > "+output;
}
console.log("** executing test command:\n"+command);
exec(command, function(e, stdout, stderr) {
console.log("*** ERROR:\n");
console.log(stderr);
console.log("\n\n*** OUTPUT:\n");
console.log(stdout);
exec("rm -rf "+job.jobWorkingDirectory, function(error, stdout, stderr) {
if (error !== null) {
console.log('(!!) exec error: ' + error);
cb(error, "error removing tmp directory "+job.jobWorkingDirectory+" : "+error);
} else {
cb(e, (e==null ?"Error executing test command:\n"+command : null));
}
});
});
}
});
};
exports.LocalDriver = LocalDriver;