Skip to content

Commit

Permalink
Final cleanup of generic tick-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jwolski committed Jul 29, 2015
1 parent 82c2f5b commit ce5429f
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions scripts/tick-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
// THE SOFTWARE.
'use strict';

var TChannel = require('tchannel');
var childProc = require('child_process');
var color = require('cli-color');
var farmhash = require('farmhash').hash32;
var generateHosts = require('./generate-hosts');
var program = require('commander');
var TChannel = require('tchannel');
var fs = require('fs');

var programInterpreter, programPath, procsToStart = 5;
Expand Down Expand Up @@ -350,14 +351,23 @@ function findLocalIP() {

function ClusterProc(port) {
var newProc;
var hostport = localIP + ':' + port;

this.port = port;
this.hostPort = localIP + ':' + port;

if (programInterpreter) {
newProc = require('child_process').spawn(programInterpreter, [programPath, '--listen=' + hostport, '--hosts=./hosts.json']);
newProc = childProc.spawn(programInterpreter,
[programPath, '--listen=' + this.hostPort, '--hosts=./hosts.json']);
} else {
newProc = require('child_process').spawn(programPath, ['--listen=' + hostport, '--hosts=./hosts.json']);
newProc = childProc.spawn(programPath,
['--listen=' + this.hostPort, '--hosts=./hosts.json']);
}

var self = this;

newProc.on('error', function(err) {
console.log('Error: ' + err.message + ', failed to spawn ' + programPath + ' on ' + hostport);
console.log('Error: ' + err.message + ', failed to spawn ' +
programPath + ' on ' + self.hostPort);
});

newProc.on('exit', function(code) {
Expand Down Expand Up @@ -398,8 +408,6 @@ function ClusterProc(port) {
newProc.stdout.on('data', logOutput);
newProc.stderr.on('data', logOutput);

this.port = port;
this.hostPort = localIP + ':' + port;
this.proc = newProc;
this.pid = newProc.pid;
this.killed = null;
Expand Down Expand Up @@ -544,16 +552,16 @@ function send(host, arg1, arg2, arg3, callback) {

program
.version(require('../package.json').version)
.option('-n <size>')
.option('-i, --interpreter <interpreter>')
.option('-n <size>', 'Size of cluster. Default is ' + procsToStart + '.')
.option('-i, --interpreter <interpreter>', 'Interpreter that runs program.')
.arguments('<program>')
.description('tick-cluster is a tool that launches a ringpop cluster of arbitrary size')
.action(function onAction(path, options) {
programPath = path;
if (programPath[0] !== '/') {
programPath = './' + programPath;
}

if (options.N) {
procsToStart = parseInt(options.N);
}
Expand All @@ -568,6 +576,10 @@ program.on('--help', function onHelp() {

program.parse(process.argv);

if (!programPath) {
console.log('Error: program is required');
process.exit(1);
}

if(!fs.existsSync(programPath)) {
console.log('Error: program ' + programPath + ' does not exist. Check path');
Expand Down

0 comments on commit ce5429f

Please sign in to comment.