-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgossip.js
43 lines (38 loc) · 1.21 KB
/
gossip.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
var nodeIp;
var timeout;
getNodeData = function () {
$.getJSON(nodeIp + "/networkState", function (networkState) {
updateNetworkStateTable(networkState)
});
}
connectToNode = function () {
nodeIp = $('#nodeIp').val();
getNodeData(nodeIp);
timeout = setTimeout(connectToNode, 10000, nodeIp);
};
updateNetworkStateTable = function (networkState) {
let action;
for (ip in networkState) {
if ($('#'+ip)[0] === undefined) {
action = addNewTableEntry
}
else {
action = updateExistingEntry
}
action(ip, networkState[ip]);
}
}
updateExistingEntry = function (ip, nodeData) {
$currentRow = $('#' + ip);
$currentRow.children()[0].text(ip);
$currentRow.children()[1].text(revision);
$currentRow.children()[2].text(nodeData.heartbeat);
$currentRow.children()[3].text(nodeData.state);
}
addNewTableEntry = function (ip, nodeData) {
$currentRow = $("#networkStateTable").append($('<tr>').attr('id', ip));
$currentRow.append($('<td>').text(ip));
$currentRow.append($('<td>').text(nodeData.revision));
$currentRow.append($('<td>').text(nodeData.heartbeat));
$currentRow.append($('<td>').text(nodeData.state));
}