mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel
This commit is contained in:
commit
b7654658bd
|
@ -34,6 +34,7 @@
|
|||
var FoxxController = require("org/arangodb/foxx").Controller,
|
||||
controller = new FoxxController(applicationContext),
|
||||
cluster = require("org/arangodb/cluster"),
|
||||
load = require("internal").download,
|
||||
_ = require("underscore");
|
||||
|
||||
/** Plan and start a new cluster
|
||||
|
@ -49,7 +50,7 @@
|
|||
res.json(!cluster.dispatcherDisabled());
|
||||
});
|
||||
|
||||
if (! cluster.dispatcherDisabled()) {
|
||||
if (!cluster.dispatcherDisabled()) {
|
||||
var Plans = require("./repositories/plans.js"),
|
||||
plans = new Plans.Repository(
|
||||
require("internal").db._collection(
|
||||
|
@ -78,7 +79,7 @@
|
|||
return {
|
||||
username: "root",
|
||||
passwd: ""
|
||||
}
|
||||
};
|
||||
},
|
||||
startUp = function(req, res) {
|
||||
cleanUp();
|
||||
|
@ -170,6 +171,32 @@
|
|||
res.json("ok");
|
||||
});
|
||||
|
||||
controller.post("/communicationCheck", function(req, res) {
|
||||
var list = req.body();
|
||||
var options = {};
|
||||
var result = [];
|
||||
var base64Encode = require("internal").base64Encode;
|
||||
_.each(list, function(info) {
|
||||
var host = info.host;
|
||||
var port = info.port;
|
||||
if (info.user) {
|
||||
options.headers = {
|
||||
"Authorization": "Basic " + base64Encode(info.user + ":" +
|
||||
info.passwd)
|
||||
};
|
||||
}
|
||||
var url = "http://" + host + ":" + port + "/_api/version";
|
||||
var resi = load(url, "", options);
|
||||
if (resi.code !== 200) {
|
||||
result.push(false);
|
||||
} else {
|
||||
result.push(true);
|
||||
}
|
||||
delete options.headers;
|
||||
});
|
||||
res.json(result);
|
||||
});
|
||||
|
||||
controller.del("/plan", function(req, res) {
|
||||
plans.clear();
|
||||
res.json("ok");
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
"click .delete" : "removeEntry",
|
||||
"click #cancel" : "cancel",
|
||||
"click #test-all-connections" : "checkAllConnections",
|
||||
"focusout .host" : "autoCheckConnections",
|
||||
"focusout .port" : "autoCheckConnections",
|
||||
"focusout .user" : "autoCheckConnections",
|
||||
"focusout .passwd" : "autoCheckConnections"
|
||||
"focusout .host" : "checkAllConnections",
|
||||
"focusout .port" : "checkAllConnections",
|
||||
"focusout .user" : "checkAllConnections",
|
||||
"focusout .passwd" : "checkAllConnections"
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
|
@ -191,70 +191,65 @@
|
|||
|
||||
},
|
||||
|
||||
autoCheckConnections: function (e) {
|
||||
var host,
|
||||
port,
|
||||
user,
|
||||
passwd,
|
||||
parentElement = $(e.currentTarget).parent();
|
||||
host = $(parentElement).children('.host').val();
|
||||
port = $(parentElement).children('.port').val();
|
||||
user = $(parentElement).children('.user').val();
|
||||
passwd = $(parentElement).children('.passwd').val();
|
||||
|
||||
if (host !== '' && port !== '') {
|
||||
this.checkAllConnections();
|
||||
readAllConnections: function() {
|
||||
var res = [];
|
||||
$(".dispatcher").each(function(key, row) {
|
||||
var obj = {
|
||||
host: $('.host', row).val(),
|
||||
port: $('.port', row).val(),
|
||||
user: $('.user', row).val(),
|
||||
passwd: $('.passwd', row).val()
|
||||
};
|
||||
if (obj.host && obj.port) {
|
||||
res.push(obj);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
},
|
||||
|
||||
checkConnection: function(
|
||||
host,
|
||||
port,
|
||||
user,
|
||||
passwd,
|
||||
target,
|
||||
i,
|
||||
dispatcherArray,
|
||||
connectionValidationKey
|
||||
) {
|
||||
checkAllConnections: function() {
|
||||
var self = this;
|
||||
$(target).find('.cluster-connection-check-success').remove();
|
||||
$(target).find('.cluster-connection-check-fail').remove();
|
||||
var connectionValidationKey = Math.random();
|
||||
this.connectionValidationKey = connectionValidationKey;
|
||||
$('.cluster-connection-check-success').remove();
|
||||
$('.cluster-connection-check-fail').remove();
|
||||
var list = this.readAllConnections();
|
||||
if (list.length) {
|
||||
try {
|
||||
$.ajax({
|
||||
async: true,
|
||||
cache: false,
|
||||
type: "GET",
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
},
|
||||
url: "http://" + host + ":" + port + "/_api/version",
|
||||
success: function() {
|
||||
type: "POST",
|
||||
url: "/_admin/aardvark/cluster/communicationCheck",
|
||||
data: JSON.stringify(list),
|
||||
success: function(checkList) {
|
||||
if (connectionValidationKey === self.connectionValidationKey) {
|
||||
$(target).append(
|
||||
var dispatcher = $(".dispatcher");
|
||||
var i = 0;
|
||||
dispatcher.each(function(key, row) {
|
||||
var host = $(".host", row).val();
|
||||
var port = $(".port", row).val();
|
||||
if (host && port) {
|
||||
if (checkList[i]) {
|
||||
$(".controls:first", row).append(
|
||||
'<span class="cluster-connection-check-success">Connection: ok</span>'
|
||||
);
|
||||
dispatcherArray[i] = true;
|
||||
self.checkDispatcherArray(dispatcherArray, connectionValidationKey);
|
||||
}
|
||||
},
|
||||
error: function(p) {
|
||||
if (connectionValidationKey === self.connectionValidationKey) {
|
||||
$(target).append(
|
||||
} else {
|
||||
$(".controls:first", row).append(
|
||||
'<span class="cluster-connection-check-fail">Connection: fail</span>'
|
||||
);
|
||||
dispatcherArray[i] = false;
|
||||
}
|
||||
},
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + passwd));
|
||||
//send this header to prevent the login box
|
||||
xhr.setRequestHeader("X-Omit-Www-Authenticate", "content");
|
||||
i++;
|
||||
}
|
||||
});
|
||||
self.checkDispatcherArray(checkList, connectionValidationKey);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
this.disableLaunchButton();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
checkDispatcherArray: function(dispatcherArray, connectionValidationKey) {
|
||||
|
@ -266,39 +261,6 @@
|
|||
}
|
||||
},
|
||||
|
||||
checkAllConnections: function() {
|
||||
this.connectionValidationKey = Math.random();
|
||||
this.disableLaunchButton();
|
||||
var numOfDispatcher = $('.dispatcher').length,
|
||||
dispatcherArray = [],
|
||||
idx;
|
||||
for (idx = 0; idx < numOfDispatcher; idx++) {
|
||||
dispatcherArray.push(false);
|
||||
}
|
||||
|
||||
//Object mit #dispatcher + random key
|
||||
var self = this;
|
||||
$('.dispatcher').each(
|
||||
function(i, dispatcher) {
|
||||
var target = $('.controls', dispatcher)[0];
|
||||
var host = $('.host', dispatcher).val();
|
||||
var port = $('.port', dispatcher).val();
|
||||
var user = $('.user', dispatcher).val();
|
||||
var passwd = $('.passwd', dispatcher).val();
|
||||
self.checkConnection(
|
||||
host,
|
||||
port,
|
||||
user,
|
||||
passwd,
|
||||
target,
|
||||
i,
|
||||
dispatcherArray,
|
||||
self.connectionValidationKey
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
disableLaunchButton: function() {
|
||||
$('#startSymmetricPlan').attr('disabled', 'disabled');
|
||||
$('#startSymmetricPlan').removeClass('button-success');
|
||||
|
|
Loading…
Reference in New Issue