Skip to content

Commit

Permalink
Add all master/slave nodes when a node is added to console
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjlee committed Oct 15, 2010
1 parent 8f08c66 commit 3361da1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
52 changes: 33 additions & 19 deletions console/js/console.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ function initShortcuts() {
next.find('input').button().click();
optNodes.buttonset('refresh');
});
doc.bind('keydown', 'p', function() {
doc.bind('keydown', 'h', function() {
if (!selectedNode) return;
var selected = selectedNode.tabs.tabs('option', 'selected');
selectedNode.tabs.tabs('select', selected-1);
});
doc.bind('keydown', 'n', function() {
doc.bind('keydown', 'l', function() {
if (!selectedNode) return;
var selected = selectedNode.tabs.tabs('option', 'selected');
selectedNode.tabs.tabs('select', selected+1);
Expand Down Expand Up @@ -125,14 +125,22 @@ function hideAddNodeDialog() {
function addNode(name) {
var node = getNodeObject(name);

node.button = addNodeButton(node);
node.tabs = addNodeTabs(node);
node.graphs = {};
node.selectNode = function() {
node.button.click();
}
node.selectReportGraph = function(index) {
node.tabs.tabs('select', index);
if (!node.uiloaded) {
node.uiloaded = true;
node.button = addNodeButton(node);
node.tabs = addNodeTabs(node);
node.graphs = {};
node.selectNode = function() {
node.button.click();
optNodes.buttonset('refresh');
}
node.selectReportGraph = function(index) {
node.tabs.tabs('select', index);
}

$.getJSON('http://' + node.name + '/remote/hosts', function(hosts, status) {
if (hosts) hosts.forEach(function(name) { addNode(name) });
});
}

refreshReportsData(node);
Expand All @@ -154,6 +162,14 @@ function removeNode(node) {
node.tabs.remove();
deleteNodeObject(node);
}
function selectNode(node) {
if (selectedNode === node) return;
if (selectedNode) selectedNode.tabs.hide();
selectedNode = node;
selectedNode.tabs.show();
refreshReportGraphs(node);
resizeReportGraphs();
}
function addNodeButton(node) {
optNodes.append(
'<span id="cmd-' + node.id + '">\
Expand All @@ -163,11 +179,7 @@ function addNodeButton(node) {
$('#' + node.id ).button({
icons: { secondary: 'ui-icon-squaresmall-close' }
}).click(function() {
if (selectedNode === node) return;
if (selectedNode) selectedNode.tabs.hide();
selectedNode = node;
selectedNode.tabs.show();
refreshReportGraphs(node);
selectNode(node);
});
$('#cmd-' + node.id + ' span.ui-icon-squaresmall-close').click(function(){
removeNode(node);
Expand All @@ -177,14 +189,11 @@ function addNodeButton(node) {
}
function addNodeTabs(node) {
var tabs = $('<div id="tab-charts-' + node.id + '">\
<div class="clsShortcutKeys">&lt; p &nbsp;&nbsp; n &gt;</div>\
<div class="clsShortcutKeys">&lt; h &nbsp;&nbsp; l &gt;</div>\
<ul></ul>\
</div>');
tabs.appendTo(pnlCharts).tabs();
tabs.tabs('add', '#tab-console-' + node.id, 'Console: ' + node.name);
tabs.bind('tabsselect', function(event, ui) {
refreshReportGraphs(node);
});
tabs.hide();
return tabs;
}
Expand Down Expand Up @@ -247,6 +256,11 @@ function refreshReportGraphs(node) {
}

pnlSummary.html(jsonToTable(summary));

if (!node.graphsloaded && node.tabs.tabs('length') > 1) {
node.graphsloaded = true;
node.tabs.tabs('select', 0);
}
}

// ---------------
Expand Down
10 changes: 6 additions & 4 deletions lib/nodeloadlib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions src/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ function RemoteSlave(id, master) {
this.tests = [];
if (master) {
master = master.split(':');
this.masterhost = master[0];
this.master = http.createClient(master[1], master[0]);
this.master = {
host: master[0],
port: master[1],
client: http.createClient(master[1], master[0])
};
}
}
RemoteSlave.prototype = {
Expand Down Expand Up @@ -176,9 +179,9 @@ RemoteSlave.prototype = {
this.sendReport_('/remote/progress', {slaveId: this.id, data: reports});
},
sendReport_: function(url, object) {
if (this.master) {
if (this.master.client) {
var s = JSON.stringify(object);
var req = this.master.request('POST', url, {'host': this.masterhost, 'content-length': s.length});
var req = this.master.client.request('POST', url, {'host': this.master.host, 'content-length': s.length});
req.write(s);
req.end();
}
Expand All @@ -204,6 +207,7 @@ function RemoteWorkerPool(master, slaves, fun) {
id: slaves[i],
state: "notstarted",
host: slave[0],
port: slave[1],
client: http.createClient(slave[1], slave[0])
};
}
Expand Down Expand Up @@ -315,6 +319,21 @@ function serveRemote(url, req, res) {
eval(remoteFun);
sendStatus(200);
});
} else if (req.method == "GET" && req.url == "/remote/hosts") {
var hosts = [];
if (SLAVE_CONFIG) {
hosts.push(SLAVE_CONFIG.master.host + ':' + SLAVE_CONFIG.master.port);
}
if (WORKER_POOL) {
hosts.push(WORKER_POOL.master);
for (var i in WORKER_POOL.slaves) {
hosts.push(i);
}
}
var body = JSON.stringify(hosts);
res.writeHead(200, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*", "Content-Length": body.length});
res.write(body);
res.end();
} else if (req.method == "GET" && req.url == "/remote/state") {
if (SCHEDULER.running == true) {
sendStatus(200);
Expand Down

0 comments on commit 3361da1

Please sign in to comment.