-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (71 loc) · 1.89 KB
/
index.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
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
#!/usr/bin/env node
"use strict";
const Master = require("./master/master").Master;
const Worker = require("./worker/worker").Worker;
const argv = require('yargs')
.usage(`Usage: $0 <command> [options]`)
.example('master', 'node index.js master -f input.txt -a localhost:5050')
.example('worker', 'node index.js worker -m localhost:5050 -a localhost:5051')
.command('master', 'run MapReduce master service', {
address: {
alias: 'a',
description: 'master host ipaddress:port',
default: 'localhost:5000',
type: 'string',
},
num_map: {
alias: 'm',
description: 'number of mappers',
default: 1,
type: 'number',
},
num_red: {
alias: 'r',
description: 'number of reducers',
default: 1,
type: 'number',
},
file: {
alias: 'f',
description: 'input file name',
demandOption: '!Provide an input file name',
},
})
.command('worker', 'run MapReduce worker service', {
address: {
alias: 'a',
description: 'worker host ipaddress:port',
default: 'localhost:6000',
type: 'string',
},
master: {
alias: 'm',
description: 'master host ipaddress:port',
demandOption: '!Provide master node address',
type: 'string',
}
})
.demandCommand(1, 1, 'Enter a command')
.recommendCommands()
.epilogue('for more information, check out https://github.com/mutaphore/mr-node')
.help('h')
.argv;
function main() {
const command = argv._[0];
let service;
if (command === 'master') {
service = new Master(argv.address, argv.num_map, argv.num_red, argv.file);
} else if (command === 'worker') {
service = new Worker(argv.address, argv.master);
} else {
console.error(`Invalid command "${command}"`);
process.exit(1);
}
service.start((err) => {
if (err) {
console.error(err);
process.exit(1);
}
});
}
main();