-
Notifications
You must be signed in to change notification settings - Fork 15
/
local_driver.js
50 lines (44 loc) · 1.71 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
42
43
44
45
46
47
48
49
50
var fs = require('fs');
var exec = require('child_process').exec;
var LocalDriver = function(jobDescription) {
this.jobDescription = jobDescription;
};
LocalDriver.prototype.execute = function(i, input, output, cb) {
var cmdenv = (this.jobDescription.configuration.cmdenv || '').split(',').join(' ');
this.jobDescription.generate(i, function(err,job){
if(err) {
cb(err, "Error generating map reduce scripts");
} else {
var command;
var setup = "";
var inputPostfix = "";
try {
if(fs.statSync(input).isDirectory())
inputPostfix = "/*";
} catch (x) { }
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+inputPostfix+" | "+ cmdenv +" node "+job.mapperPath+" | sort | "+ cmdenv +" node "+job.reducerPath;
} else {
command = "cd "+job.jobWorkingDirectory+setup+" && cat "+input+inputPostfix+" | "+ cmdenv +" node "+job.mapperPath+" | sort | "+ cmdenv +" 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;