2018-03-26 23:07:56 +03:00
|
|
|
var a, selected_node, deadNode, node2;
|
2017-09-08 15:26:55 +03:00
|
|
|
$(function() {
|
2018-03-26 23:06:08 +03:00
|
|
|
var url = "ws://" + location.host + "/socket";
|
|
|
|
var ws = new WebSocket(url);
|
2018-03-26 23:07:56 +03:00
|
|
|
|
2018-03-26 23:06:08 +03:00
|
|
|
ws.onopen = function() {ws.send(""); };
|
|
|
|
ws.onmessage = function (evt) {
|
|
|
|
a = JSON.parse(evt.data);
|
|
|
|
displayData(a);
|
|
|
|
};
|
|
|
|
$('.tablink').css('display', 'block');
|
|
|
|
|
2018-03-26 23:07:56 +03:00
|
|
|
|
2018-03-21 12:56:03 +03:00
|
|
|
$('#mountFormTrigger').click(function(event){
|
2017-09-08 15:26:55 +03:00
|
|
|
var htmlSelect = '';
|
2018-03-21 12:56:03 +03:00
|
|
|
a.quorum.forEach(function(item) {
|
|
|
|
htmlSelect += "<option value=" + item.node + ">" + item.node + "</option>";
|
|
|
|
})
|
2017-09-08 15:26:55 +03:00
|
|
|
$('#selectNode').html(htmlSelect);
|
|
|
|
/*
|
|
|
|
$.ajax({
|
|
|
|
url:"status",
|
|
|
|
success:function(data){
|
|
|
|
var status = JSON.parse(data);
|
|
|
|
var htmlSelect = '';
|
|
|
|
for (n in status["quorum"]) { htmlSelect += "<option value=" + n + ">" + n + "</option>";}
|
|
|
|
$('#selectNode').html(htmlSelect);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
*/
|
2018-03-26 23:06:08 +03:00
|
|
|
|
2018-03-21 12:56:03 +03:00
|
|
|
})
|
2018-03-26 22:52:10 +03:00
|
|
|
|
2018-03-26 22:08:59 +03:00
|
|
|
|
2018-03-26 22:22:35 +03:00
|
|
|
// var ws = new WebSocket('{{escape(ws)}}');
|
2018-03-26 22:25:41 +03:00
|
|
|
// var cluster, selected_node, deadNode, node2;
|
2018-03-26 22:23:45 +03:00
|
|
|
// ws.onopen = function() {ws.send(""); };
|
|
|
|
// ws.onmessage = function (evt) {
|
|
|
|
// cluster = JSON.parse(evt.data);
|
|
|
|
// displayData(cluster);
|
|
|
|
// };
|
2018-03-26 22:21:30 +03:00
|
|
|
|
2018-03-26 22:08:59 +03:00
|
|
|
$('#mountForm').submit(function(event){
|
2018-03-26 23:10:18 +03:00
|
|
|
console.log('submit');
|
2018-03-26 22:08:59 +03:00
|
|
|
event.preventDefault();
|
|
|
|
$.ajax({
|
|
|
|
url:"mount",
|
|
|
|
data:$(this).serialize(),
|
|
|
|
method:'POST',
|
|
|
|
success:function(data){
|
|
|
|
$('#mount').css('display', 'none');
|
|
|
|
$('input[type = "text"]').val('');
|
|
|
|
var res = JSON.parse(data);
|
|
|
|
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
|
|
|
|
$("#rspContainer").css("display", "block");
|
|
|
|
$("#rsp").html(message)
|
|
|
|
if (res["state"] == 'OK'){
|
|
|
|
$("#rspContainer").css("background-color", "#4CAF50" );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#rspContainer").css("background-color", "#f44336" )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2018-03-26 22:21:30 +03:00
|
|
|
|
2017-09-08 15:26:55 +03:00
|
|
|
});
|
|
|
|
|
2018-03-21 12:56:03 +03:00
|
|
|
function resolve() {
|
|
|
|
$.ajax({
|
|
|
|
url:"resolve",
|
|
|
|
data:{"node": deadNode},
|
|
|
|
success:function(data){
|
|
|
|
$('#details').css("display", "none");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-09-08 15:26:55 +03:00
|
|
|
|
2018-03-26 22:08:59 +03:00
|
|
|
function unmount(a, b, c) { //selected_node, mountpoint, block
|
2018-03-21 12:56:03 +03:00
|
|
|
var u = confirm(a + ": confirm unmount of " + b);
|
|
|
|
if (u == true) {
|
2017-09-08 15:26:55 +03:00
|
|
|
$.ajax({
|
2018-03-21 12:56:03 +03:00
|
|
|
url:"unmount",
|
|
|
|
data:{"node":a, "mountpoint":b, "block":c},
|
|
|
|
success:function(data){
|
|
|
|
var res = JSON.parse(data);
|
|
|
|
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
|
|
|
|
$("#rspContainer").css("display", "block");
|
|
|
|
$("#rsp").html(message)
|
|
|
|
if (res["state"] == 'OK'){
|
|
|
|
$("#rspContainer").css("background-color", "#4CAF50" );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#rspContainer").css("background-color", "#f44336" );
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 15:26:55 +03:00
|
|
|
})
|
|
|
|
}
|
2018-03-21 12:56:03 +03:00
|
|
|
}
|
2017-09-08 15:26:55 +03:00
|
|
|
|
2018-03-21 12:56:03 +03:00
|
|
|
function displayData(a){
|
|
|
|
$("#status").html("<p>"+a.health+"</p>");
|
|
|
|
if (a.health == 'deadly.') {
|
2018-03-21 16:41:29 +03:00
|
|
|
deadNode = a.deadlyreason["node"];
|
2018-03-21 12:56:03 +03:00
|
|
|
$('#showDeadlyDetails').css("display","block");
|
|
|
|
$('#resolve').css("display","block");
|
|
|
|
$("#mountFormTrigger").addClass("w3-disabled")
|
|
|
|
} else {
|
|
|
|
$('#showDeadlyDetails').css("display","none");
|
|
|
|
$('#resolve').css("display","none");
|
|
|
|
$("#mountFormTrigger").removeClass("w3-disabled")
|
|
|
|
$('#details').css("border", "0");
|
|
|
|
}
|
2018-03-21 13:46:21 +03:00
|
|
|
$("#statusContainer:contains('alive')").css("background-color", "#4CAF50");
|
|
|
|
$("#statusContainer:contains('resizing')").css("background-color", "#ff9800");
|
|
|
|
$("#statusContainer:contains('deadly')").css("background-color", "#f44336");;
|
2018-03-22 18:12:15 +03:00
|
|
|
if (node2 != undefined) {
|
2018-03-22 18:15:14 +03:00
|
|
|
var one = a.quorum.map(function(item) {return item.node});
|
2018-03-22 17:04:23 +03:00
|
|
|
var two = node2.quorum.map(function(item) {return item.node});
|
2018-03-22 18:12:15 +03:00
|
|
|
if (JSON.stringify(one) != JSON.stringify(two)) {
|
2018-03-22 17:04:23 +03:00
|
|
|
node2 = a;
|
|
|
|
w3DisplayData("id01", node2);
|
|
|
|
}
|
2018-03-22 18:12:15 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
node2 = a;
|
|
|
|
w3DisplayData("id01", node2);
|
|
|
|
}
|
2018-03-22 17:02:45 +03:00
|
|
|
|
2018-03-22 18:15:14 +03:00
|
|
|
// if ($('.tablink').css('display') != 'block') {
|
|
|
|
// $('.tablink').css('display', 'block');
|
|
|
|
// }
|
2018-03-22 18:17:20 +03:00
|
|
|
// if (selected_node != undefined && selected_node != 'dead'){
|
|
|
|
if (selected_node != undefined){
|
2018-03-21 12:56:03 +03:00
|
|
|
//a.quorum.forEach(function(item) {if (item.node == selected_node) { console.log(item.node)}})
|
|
|
|
var selected_node_body = a.quorum.find(function(node) {
|
2018-03-21 13:46:21 +03:00
|
|
|
return node.node == selected_node;
|
2018-03-21 12:56:03 +03:00
|
|
|
});
|
|
|
|
var t = new Date(selected_node_body["updated"] * 1000)
|
|
|
|
var up_formatted = t.getFullYear() + "/"
|
|
|
|
+ (t.getMonth() + 1) + "/"
|
|
|
|
+ t.getDate() + " "
|
|
|
|
+ t.getHours() + ":"
|
|
|
|
+ t.getMinutes() + ":"
|
|
|
|
+ t.getSeconds();
|
|
|
|
$("#name").html(selected_node);
|
|
|
|
$("#ipv4").html(selected_node_body["ip"]["v4"].join("<br>"));
|
|
|
|
$("#ipv6").html(selected_node_body["ip"]["v6"].join("<br>"));
|
|
|
|
$("#updated").html(up_formatted);
|
|
|
|
if (selected_node_body["mounts"] != null) {
|
|
|
|
var mnt_block = "";
|
|
|
|
for (i in selected_node_body.mounts) {
|
|
|
|
var mnt = selected_node_body.mounts[i];
|
|
|
|
mnt_block += '<a href=\'javascript:void(0)\' onClick=\'unmount("'
|
|
|
|
+ selected_node + '", "'
|
|
|
|
+ selected_node_body.mounts[i].mountpoint + '", "'
|
|
|
|
+ selected_node_body.mounts[i].block
|
2018-03-21 16:11:53 +03:00
|
|
|
+ '")\' >unmount</a><br>Mountpoint: ' + mnt.mountpoint
|
2018-03-21 13:46:21 +03:00
|
|
|
+ '<br>Mountopts: ' + mnt.mountopts
|
|
|
|
+ '<br>Fstype: ' + mnt.fstype
|
2018-03-21 12:56:03 +03:00
|
|
|
+ '<br>Pool: ' + mnt.pool
|
|
|
|
+ '<br>Image: ' + mnt.image
|
|
|
|
+ '<br>Block: ' + mnt.block + '<br>';
|
2018-03-21 12:28:27 +03:00
|
|
|
}
|
2018-03-21 12:56:03 +03:00
|
|
|
$("#mon").html(mnt_block);
|
|
|
|
} else {
|
|
|
|
$("#mon").html("");
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 16:44:45 +03:00
|
|
|
// if (selected_node =='dead') {
|
|
|
|
// var t, up_formatted;
|
|
|
|
// if (a.deadlyreason["updated"] != 0) {
|
|
|
|
// t = new Date(a.deadlyreason["updated"] * 1000)
|
|
|
|
// up_formatted = t.getFullYear() + "/"
|
|
|
|
// + (t.getMonth() + 1) + "/"
|
|
|
|
// + t.getDate() + " "
|
|
|
|
// + t.getHours() + ":"
|
|
|
|
// + t.getMinutes() + ":"
|
|
|
|
// + t.getSeconds();
|
|
|
|
// } else {
|
|
|
|
// up_formatted=0;
|
|
|
|
// }
|
|
|
|
// deadNode = a.deadlyreason["node"];
|
|
|
|
// $("#name").html(a.deadlyreason["node"]);
|
|
|
|
// $("#ipv4").html(a.deadlyreason["ip"]["v4"].join("<br>"));
|
|
|
|
// $("#ipv6").html(a.deadlyreason["ip"]["v6"].join("<br>"));
|
|
|
|
// $("#updated").html(up_formatted);
|
|
|
|
// if (a.deadlyreason["mounts"] != null) {
|
|
|
|
// var mnt_block = "";
|
|
|
|
// for (i in a.deadlyreason.mounts) {
|
|
|
|
// var mnt = a.deadlyreason.mounts[i];
|
|
|
|
// mnt_block += mnt.mountpoint + "<br>"
|
|
|
|
// + mnt.mountopts + "<br>"
|
|
|
|
// + mnt.fstype + "<br>"
|
|
|
|
// + mnt.pool + "<br>"
|
|
|
|
// + mnt.image + "<br><br>";
|
|
|
|
// }
|
|
|
|
// $("#mon").html(mnt_block);
|
|
|
|
// } else {
|
|
|
|
// $("#mon").html("");
|
|
|
|
// }
|
|
|
|
// }
|
2018-03-21 12:56:03 +03:00
|
|
|
$("#leader").html(a.leader);
|
|
|
|
}
|
2018-03-21 12:28:27 +03:00
|
|
|
|
2017-09-08 15:26:55 +03:00
|
|
|
function openNode(evt, nodeName) {
|
2018-03-22 18:09:38 +03:00
|
|
|
// console.log(nodeName);
|
2017-09-08 15:26:55 +03:00
|
|
|
var i, x, tablinks;
|
|
|
|
selected_node = nodeName;
|
|
|
|
x = document.getElementsByClassName("node");
|
|
|
|
tablinks = document.getElementsByClassName("tablink");
|
2018-03-21 16:44:45 +03:00
|
|
|
// if (selected_node == 'dead') {
|
|
|
|
// // if (selected_node == deadNode) {
|
|
|
|
// $('#details').css("border", "2px solid #f44336");
|
|
|
|
// if ($('#showDeadlyDetails').html() == "Show details") {
|
|
|
|
// $('#details').css("display", "block");
|
|
|
|
// $('#showDeadlyDetails').text('Hide details');
|
|
|
|
// } else {
|
|
|
|
// $('#details').css("display", "none");
|
|
|
|
// $('#showDeadlyDetails').text('Show details');
|
|
|
|
// }
|
|
|
|
// // displayData(a);
|
|
|
|
// } else {
|
2018-03-21 13:06:52 +03:00
|
|
|
$('#showDeadlyDetails').text('Show details');
|
2018-03-26 22:52:10 +03:00
|
|
|
$('#details').css("border", "").css("display", "block");
|
|
|
|
displayData(a);
|
2018-03-21 16:44:45 +03:00
|
|
|
// }
|
2017-09-08 15:26:55 +03:00
|
|
|
}
|