-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes.html
631 lines (525 loc) · 24.6 KB
/
nodes.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Node Settings</title>
<!-- link to JQuery javascript libraries -->
<script src="js/jquery-1.11.1.min.js"></script>
<!-- link to JQuery CSS definitions -->
<link rel="stylesheet" href="css/jquery-ui.css"/>
<!-- define an internal style -->
<style type="text/css">
.right {
float:right;
}
.loading {
color:CornflowerBlue;
}
</style>
<script type="text/javascript">
var websocket_port = "6464";
var service_port = "6467";
var node_get_service_name = "/cloudi/api/rpc/nodes_get.erl";
var node_set_service_name = "/cloudi/api/rpc/nodes_set.erl";
var node_add_service_name = "/cloudi/api/rpc/nodes_add.erl";
var node_remove_service_name = "/cloudi/api/rpc/nodes_remove.erl";
var node_alive_service_name = "/cloudi/api/rpc/nodes_alive.erl";
var node_dead_service_name = "/cloudi/api/rpc/nodes_dead.erl";
var request_type = "get";
var node_get_web_socket = undefined;
var live_nodes_web_socket = undefined;
var dead_nodes_web_socket = undefined;
var websocket_url = "";
function is(type, obj) {
if (obj === undefined)
return type === 'undefined';
else if (obj === null)
return type === 'null';
else
return type === Object.prototype.toString.call(obj).slice(8, - 1);
};
String.prototype.startsWith = function (str) {
return this.slice(0, str.length) == str;
};
// This function uses a web socket to retrieve the current node settings
function sendNodeGet() {
// if the web socket is undefined then display an error
if (node_get_web_socket == undefined) {
$('#connectionStatus').text("Not connected");
openNodeGet();
}
// clear the current configuration value
$("#current_configuration").val("");
// if the web socket is in an open status then send the request
if (node_get_web_socket.readyState == node_get_web_socket.OPEN) {
node_get_web_socket.send(request_type);
//console.log("Request (out): " + request_type);
}
};
// This function uses a web socket to retrieve the current live nodes
function sendLiveNodes() {
// if the web socket is undefined then display an error
if (live_nodes_web_socket == undefined) {
$("#connectionStatus").text("Not connected");
openLiveNodes();
}
// if the web socket is in an open status then send the request
if (live_nodes_web_socket.readyState == live_nodes_web_socket.OPEN) {
live_nodes_web_socket.send(request_type);
//console.log("Request (out): " + request_type);
}
};
// This function uses a web socket to retrieve the current dead nodes
function sendDeadNodes() {
// if the web socket is undefined then display an error
if (dead_nodes_web_socket == undefined) {
$("#connectionStatus").text("Not connected");
openDeadNodes();
}
// if the web socket is in an open status then send the request
if (dead_nodes_web_socket.readyState == dead_nodes_web_socket.OPEN) {
dead_nodes_web_socket.send(request_type);
//console.log("Request (out): " + request_type);
}
};
// This function opens a web socket used to retrieve the current node settings
function openNodeGet() {
if (!("WebSocket" in window)) {
$('#connectionStatus').text("Not connected");
alert("This browser does not support WebSockets");
return;
}
$('#connectionStatus').text("Connecting");
websocket_url = "ws://" + $("#hostname").val() + ":" + websocket_port + node_get_service_name;
node_get_web_socket = new WebSocket(websocket_url);
console.log("Connecting to " + websocket_url);
// define function that is called when the web socket is opened
node_get_web_socket.onopen = function () {
$('#connectionStatus').text("Connected");
console.log("Connected");
sendNodeGet();
};
// define function that is called when an error occurs with the websocket
node_get_web_socket.onerror = function () {
$('#connectionStatus').text("Error");
console.log("Websocket error");
// hide the loading message
$('#loadingMessage').hide();
alert("Error connecting to websocket " + websocket_url);
};
// define function that is called when data is available on the websocket
handle_message_node_get = function (data) {
if (data.startsWith("notification:")) {
// client state check to determine this is an incoming
// service request, not an incoming response
console.log("Request (in): " + data);
var response = "ok";
node_get_web_socket.send(response);
console.log("Response (in): " + response);
}
else {
console.log("Response (out): " + data);
if (data != "got connect! yay!") {
// update the current configuration
$("#current_configuration").val(data);
// hide the loading message
$("#loadingMessage").hide();
// close web socket
closeNodeGet();
}
}
};
// define function that is called when a message is received on the web socket
node_get_web_socket.onmessage = function (evt) {
var data = evt.data;
if (is("Blob", data)) {
// for the example, treat binary as text
var reader = new FileReader();
reader.readAsText(data, "text/plain");
reader.onload = function (reader_evt) {
data = reader_evt.target.result;
handle_message_node_get(data);
};
}
else {
handle_message_node_get(data);
}
};
// define function that is called when the websocket is closed
node_get_web_socket.onclose = function () {
node_get_web_socket = undefined;
console.log("Connection closed");
};
}
// This function opens a web socket used to retrieve the live nodes
function openLiveNodes() {
if (!("WebSocket" in window)) {
$('#connectionStatus').text("Not connected");
alert("This browser does not support WebSockets");
return;
}
$('#connectionStatus').text("Connecting");
websocket_url = "ws://" + $("#hostname").val() + ":" + websocket_port + node_alive_service_name;
live_nodes_web_socket = new WebSocket(websocket_url);
console.log("Connecting to " + websocket_url);
// define function that is called when the web socket is opened
live_nodes_web_socket.onopen = function () {
$('#connectionStatus').text("Connected");
console.log("Connected");
sendLiveNodes();
};
// define function that is called when an error occurs with the websocket
live_nodes_web_socket.onerror = function () {
$('#connectionStatus').text("Error");
console.log("Websocket error");
// hide the loading message
$('#loadingMessage').hide();
alert("Error connecting to websocket " + websocket_url);
};
// define function that is called when data is available on the websocket
handle_message_live_nodes = function (data) {
if (data.startsWith("notification:")) {
// client state check to determine this is an incoming
// service request, not an incoming response
console.log("Request (in): " + data);
var response = "ok";
live_nodes_web_socket.send(response);
console.log("Response (in): " + response);
}
else {
console.log("Response (out): " + data);
if (data != "got connect! yay!") {
// clear the list of live node values
$("#live_node_list").empty();
// parse the list of nodes
var tempString = data.substring(1,data.length-1);
var nodeArray = tempString.split(",");
for (var i=0; i < nodeArray.length; i++) {
var nodeValue = nodeArray[i];
if (nodeValue == "" || nodeValue.length == 0) {
var optionString = "<option value='NA'>No additional nodes found</option>";
} else {
var optionString = "<option value='" + nodeArray[i]+ "'>" + nodeArray[i] + "</option>";
}
$("#live_node_list").append(optionString);
};
// hide the loading message
$('#loadingMessage').hide();
// close the web socket
closeLiveNodes();
}
}
};
// define function that is called when a message is received on the web socket
live_nodes_web_socket.onmessage = function (evt) {
var data = evt.data;
if (is("Blob", data)) {
// for the example, treat binary as text
var reader = new FileReader();
reader.readAsText(data, "text/plain");
reader.onload = function (reader_evt) {
data = reader_evt.target.result;
handle_message_live_nodes(data);
};
}
else {
handle_message_live_nodes(data);
}
};
// define function that is called when the websocket is closed
live_nodes_web_socket.onclose = function () {
live_nodes_web_socket = undefined;
console.log("Connection closed");
};
};
// This function opens a web socket used to retrieve the dead nodes
function openDeadNodes() {
if (!("WebSocket" in window)) {
$('#connectionStatus').text("Not connected");
alert("This browser does not support WebSockets");
return;
}
$('#connectionStatus').text("Connecting");
websocket_url = "ws://" + $("#hostname").val() + ":" + websocket_port + node_dead_service_name;
dead_nodes_web_socket = new WebSocket(websocket_url);
console.log("Connecting to " + websocket_url);
// define function that is called when the web socket is opened
dead_nodes_web_socket.onopen = function () {
$('#connectionStatus').text("Connected");
console.log("Connected");
sendDeadNodes();
};
// define function that is called when an error occurs with the websocket
dead_nodes_web_socket.onerror = function () {
$('#connectionStatus').text("Error");
console.log("Websocket error");
// hide the loading message
$('#loadingMessage').hide();
alert("Error connecting to websocket " + websocket_url);
};
// define function that is called when data is available on the websocket
handle_message_dead_nodes = function (data) {
if (data.startsWith("notification:")) {
// client state check to determine this is an incoming
// service request, not an incoming response
console.log("Request (in): " + data);
var response = "ok";
dead_nodes_web_socket.send(response);
console.log("Response (in): " + response);
}
else {
console.log("Response (out): " + data);
if (data != "got connect! yay!") {
// clear the list of live node values
$("#dead_node_list").empty();
// parse the list of nodes
var tempString = data.substring(1,data.length-1);
var nodeArray = tempString.split(",");
for (var i=0; i < nodeArray.length; i++) {
var nodeValue = nodeArray[i];
if (nodeValue == "" || nodeValue.length == 0) {
var optionString = "<option value='NA'>No additional nodes found</option>";
} else {
var optionString = "<option value='" + nodeArray[i]+ "'>" + nodeArray[i] + "</option>";
}
$("#dead_node_list").append(optionString);
};
// hide the loading message
$('#loadingMessage').hide();
// close the web socket
closeDeadNodes();
}
}
};
// define function that is called when a message is received on the web socket
dead_nodes_web_socket.onmessage = function (evt) {
var data = evt.data;
if (is("Blob", data)) {
// for the example, treat binary as text
var reader = new FileReader();
reader.readAsText(data, "text/plain");
reader.onload = function (reader_evt) {
data = reader_evt.target.result;
handle_message_dead_nodes(data);
};
}
else {
handle_message_dead_nodes(data);
}
};
// define function that is called when the websocket is closed
dead_nodes_web_socket.onclose = function () {
dead_nodes_web_socket = undefined;
console.log("Connection closed");
};
};
// This function closes the web socket used to retrieve the current node settings
function closeNodeGet() {
$('#connectionStatus').text("");
if (node_get_web_socket == undefined) {
return;
}
node_get_web_socket.close();
};
// This function closes the web socket used to retrieve the live nodes
function closeLiveNodes() {
$('#connectionStatus').text("");
if (live_nodes_web_socket == undefined) {
return;
}
live_nodes_web_socket.close();
};
// This function closes the web socket used to retrieve the dead nodes
function closeDeadNodes() {
$('#connectionStatus').text("");
if (dead_nodes_web_socket == undefined) {
return;
}
dead_nodes_web_socket.close();
};
function createCORSRequest(method, url) {
console.log("Creating CORS Request " + method + " " + url);
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
}
else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
}
else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
console.log("XHR not supported by this browser");
}
return xhr;
};
// This function submits an HTTP request to set the node configuration
function setNodeConfiguration() {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + node_set_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
// refresh the information shown on the screen
sendNodeGet();
};
var value_to_send = $("#set_current_configuration").val();
console.log("Sending value " + value_to_send);
xhr.send(value_to_send);
};
// This function submits an HTTP request to add a node
function addNode(nodeValue) {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + node_add_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
};
var tempString = "['" + nodeValue + "']";
console.log("Sending value " + tempString);
xhr.send(tempString);
};
// This function submits an HTTP request to remove a node
function removeNode(nodeValue) {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + node_remove_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
};
var tempString = "['" + nodeValue + "']";
console.log("Sending value " + tempString);
xhr.send(tempString);
};
</script>
</head>
<body>
<div id="logo">
<img class="right" src="powered_by_cloudi.png"></img>
<h1>Node Settings</h1>
<label class="right" id="connectionStatus"></label>
</div>
<div id="loadingMessage">
<h2 class="loading">Waiting for data...</h2>
</div>
<div>
<input id="hostname" type="text" value="localhost"
title="Host name or address to be monitored"></input>
</div>
<hr></hr>
<table>
<tr>
<td>
<button onclick="sendLiveNodes();"
title="List all the CloudI nodes known to be connected">Display
Connected
Nodes</button>
</td>
<td>
<select id="live_node_list" size="3"></select>
</td>
</tr>
<tr>
<td>
<button onclick="sendDeadNodes();"
title="List all the CloudI nodes that are disconnected but expected to reconnect">Display
Disconnected
Nodes</button>
</td>
<td>
<select id="dead_node_list" size="3"></select>
</td>
</tr>
<tr>
<td>
<button id="add_node_button"
title="Explicitly add a CloudI node name, so that services between all other CloudI nodes and the added nodes can send each other service requests">Add
Node</button>
</td>
</tr>
<tr>
<td>
<button id="remove_node_button"
title="Explicitly remove a CloudI node name. The CloudI node must have been added explicitly to be removed explicitly (not added by an auto-discovery method)">Remove
Node</button>
</td>
</tr>
</table>
<table>
<tr>
<td>
<button onclick="sendNodeGet();"
title="Get the distributed Erlang node configuration for this CloudI node and any CloudI nodes it is currently connected to">Get
Node
Configuration</button>
</td>
<td>
<textarea readonly="readonly" id="current_configuration" rows="3"
cols="100"></textarea>
</td>
<td></td>
</tr>
<tr>
<td>
<button onclick="setNodeConfiguration();"
title="Set the distributed Erlang node configuration for this CloudI node and any CloudI nodes it is currently connected to">Set
Node
Configuration</button>
</td>
<td>
<textarea id="set_current_configuration" rows="3" cols="100"></textarea>
</td>
</tr>
</table>
<script type="text/javascript">
$(document).ready(function () {
// assign default hostname
$("#hostname").val(location.host);
// hide the loading message
$('#loadingMessage').hide();
// define a function to add a new node
$('#add_node_button').click(function () {
var nodeValue = prompt("Enter new node", "cloudi@host");
if (nodeValue != null && nodeValue.length > 0) {
console.log("New node " + nodeValue);
addNode(nodeValue);
}
});
// define a function to remove a node
$('#remove_node_button').click(function () {
var nodeValue = prompt("Enter node to remove", "cloudi@host");
if (nodeValue != null && nodeValue.length > 0) {
console.log("Remove node " + nodeValue);
removeNode(nodeValue);
}
});
});
</script>
</body>
</html>