Skip to content

Commit

Permalink
Added executor function.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Jul 15, 2011
1 parent 082803b commit e33d2d7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/nestor
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nomnom.scriptName('nestor');
nomnom.globalOpts(opts);
nomnom.command('dashboard').callback(function (args) { nestor.dashboard(); });
nomnom.command('build').callback(function (args) { nestor.build(args._[1], args._[2]); });
nomnom.command('executor').callback(function (args) { nestor.executor(); });
nomnom.command('queue').callback(function (args) { nestor.queue(); });
nomnom.command('version').callback(function (args) { nestor.version(); });
nomnom.parseArgs();
22 changes: 22 additions & 0 deletions lib/nestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ Nestor.prototype.queue = function () {
};
this.service.send('/queue/api/json', 'GET', successCb, this.errorCb);
};
Nestor.prototype.executor = function () {
var that = this,
successCb = function (statusCode, headers, result) {
var actions = {
'ok': function () {
var computers = JSON.parse(result).computer;
computers.forEach(function (computer) {
that.console.log('* ' + computer.displayName);
computer.executors.forEach(function (executor) {
if (executor.idle) {
that.console.log('idle');
} else {
that.console.log(executor.progress + '%\t' + executor.currentExecutable.url.replace(/.*\/job\//, '').replace(/\/.*/, ''));
}
});
});
}
};
that._handle(statusCode, actions);
};
this.service.send('/computer/api/json?depth=1', 'GET', successCb, this.errorCb);
};
Nestor.prototype.version = function () {
var that = this,
successCb = function (statusCode, headers, result) {
Expand Down
62 changes: 62 additions & 0 deletions test/unit/nestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,68 @@ vows.describe('Nestor').addBatch({
assert.equal(messages[0], 'Unexpected status code 400');
}
},
'executor': {
'should log progress and job name when it is not idle': function (topic) {
var _path, _method,
messages = [],
console = {
log: function (message) {
messages.push(message);
}
},
service = {
send: function (path, method, successCb, errorCb) {
_path = path;
_method = method;
var result = '{"busyExecutors":2,"computer":[{"actions":[],"displayName":"master",' +
'"executors":[{"currentExecutable":{"number":39,"url":"http://localhost:8080/job/red-rackham/39/"},"currentWorkUnit":{},"idle":false,"likelyStuck":false,"number":0,"progress":31},{"currentExecutable":{"number":12,"url":"http://localhost:8080/job/golden-claw/12/"},' +
'"currentWorkUnit":{},"idle":false,"likelyStuck":false,"number":1,"progress":28}],"icon":"computer.png","idle":false,"jnlpAgent":false,"launchSupported":true,"loadStatistics":{"busyExecutors":{},"queueLength":{},"totalExecutors":{}},"manualLaunchAllowed":true,' +
'"monitorData":{"hudson.node_monitors.SwapSpaceMonitor":{"availablePhysicalMemory":169869312,"availableSwapSpace":124780544,"totalPhysicalMemory":2146435072,"totalSwapSpace":133726208},"hudson.node_monitors.ArchitectureMonitor":"Mac OS X (x86_64)",' +
'"hudson.node_monitors.TemporarySpaceMonitor":{"size":98938888192},"hudson.node_monitors.ResponseTimeMonitor":{"average":145},"hudson.node_monitors.DiskSpaceMonitor":{"size":98938888192},"hudson.node_monitors.ClockMonitor":{"diff":0}},"numExecutors":2,' +
'"offline":false,"offlineCause":null,"oneOffExecutors":[],"temporarilyOffline":false}],"displayName":"nodes","totalExecutors":2}';
successCb(200, null, result);
}
},
nestor = new Nestor(service, console);
nestor.executor();
assert.equal(_path, '/computer/api/json?depth=1');
assert.equal(_method, 'GET');
assert.equal(messages.length, 3);
assert.equal(messages[0], '* master');
assert.equal(messages[1], '31%\tred-rackham');
assert.equal(messages[2], '28%\tgolden-claw');
},
'should log idle when job is not idle': function (topic) {
var _path, _method,
messages = [],
console = {
log: function (message) {
messages.push(message);
}
},
service = {
send: function (path, method, successCb, errorCb) {
_path = path;
_method = method;
var result = '{"busyExecutors":0,"computer":[{"actions":[],"displayName":"master",' +
'"executors":[{"currentExecutable":null,"currentWorkUnit":null,"idle":true,"likelyStuck":false,"number":0,"progress":-1},{"currentExecutable":null,"currentWorkUnit":null,"idle":true,"likelyStuck":false,"number":1,"progress":-1}],' +
'"icon":"computer.png","idle":true,"jnlpAgent":false,"launchSupported":true,"loadStatistics":{"busyExecutors":{},"queueLength":{},"totalExecutors":{}},"manualLaunchAllowed":true,' +
'"monitorData":{"hudson.node_monitors.SwapSpaceMonitor":{"availablePhysicalMemory":83886080,"availableSwapSpace":239075328,"totalPhysicalMemory":2146435072,"totalSwapSpace":268435456},"hudson.node_monitors.ArchitectureMonitor":"Mac OS X (x86_64)",' +
'"hudson.node_monitors.TemporarySpaceMonitor":{"size":98799357952},"hudson.node_monitors.ResponseTimeMonitor":{"average":72},"hudson.node_monitors.DiskSpaceMonitor":{"size":98799357952},"hudson.node_monitors.ClockMonitor":{"diff":0}},"numExecutors":2,' +
'"offline":false,"offlineCause":null,"oneOffExecutors":[],"temporarilyOffline":false}],"displayName":"nodes","totalExecutors":2}';
successCb(200, null, result);
}
},
nestor = new Nestor(service, console);
nestor.executor();
assert.equal(_path, '/computer/api/json?depth=1');
assert.equal(_method, 'GET');
assert.equal(messages.length, 3);
assert.equal(messages[0], '* master');
assert.equal(messages[1], 'idle');
assert.equal(messages[2], 'idle');
}
},
'version': {
'should log header x-jenkins when it exists': function (topic) {
var _path, _method,
Expand Down

0 comments on commit e33d2d7

Please sign in to comment.