mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-04-08 20:55:02 +02:00
Various updates.
This commit is contained in:
parent
9a813adf0e
commit
e105ce8c65
30
src/xapi.js
30
src/xapi.js
@ -19,7 +19,7 @@ require('util').inherits(Xapi, require('events').EventEmitter);
|
||||
|
||||
Xapi.prototype.call = function (method) {
|
||||
var args = arguments;
|
||||
var tries = 0;
|
||||
var current; // Error code.
|
||||
|
||||
var self = this;
|
||||
return function helper() {
|
||||
@ -45,21 +45,37 @@ Xapi.prototype.call = function (method) {
|
||||
return value.Value;
|
||||
}).fail(function (error) {
|
||||
|
||||
// Gets the error code for transport errors and XAPI errors.
|
||||
var previous = current;
|
||||
current = error.code || error[0];
|
||||
|
||||
// XAPI sommetimes close the connection when the server is
|
||||
// no longer pool master (`event.next`), so we have to
|
||||
// retry at least once to know who is the new pool master.
|
||||
if ((0 === tries) && ('ECONNRESET' === error.code))
|
||||
if (('ECONNRESET' === current) && (previous !== current))
|
||||
{
|
||||
// @todo Does not work because it seems to reuse the
|
||||
// broken socket.
|
||||
|
||||
++tries;
|
||||
return Q.delay(2000).then(helper);
|
||||
}
|
||||
|
||||
//
|
||||
if ('HOST_STILL_BOOTING' === current)
|
||||
{
|
||||
return Q.delay(2000).then(helper);
|
||||
}
|
||||
|
||||
// XAPI is sometimes reinitialized and sessions are lost.
|
||||
// We try log in again if necessary.
|
||||
if ('SESSION_INVALID' === current)
|
||||
{
|
||||
self.logIn();
|
||||
return helper();
|
||||
}
|
||||
|
||||
if ('HOST_IS_SLAVE' === error[0])
|
||||
if ('HOST_IS_SLAVE' === current)
|
||||
{
|
||||
tries = 0;
|
||||
self.changeHost(error[1]);
|
||||
return helper();
|
||||
}
|
||||
@ -82,6 +98,10 @@ Xapi.prototype.changeHost = function (host) {
|
||||
rejectUnauthorized: false,
|
||||
}); // @todo Handle connection success/error.
|
||||
|
||||
this.logIn();
|
||||
};
|
||||
|
||||
Xapi.prototype.logIn = function () {
|
||||
var self = this;
|
||||
self.sessionId = undefined;
|
||||
self.sessionId = self.call(
|
||||
|
14
src/xo.js
14
src/xo.js
@ -311,10 +311,9 @@ Xo.prototype.start = function (cfg) {
|
||||
'replace': true,
|
||||
});
|
||||
});
|
||||
})).then(function () {
|
||||
xo.computeStats();
|
||||
return xapi.call('event.register', ['*']);
|
||||
}).then(function () {
|
||||
xo.computeStats();
|
||||
|
||||
return function loop() {
|
||||
return xapi.call('event.next').then(function (event) {
|
||||
event = event[0]; // @todo Handle multiple events.
|
||||
@ -333,6 +332,15 @@ Xo.prototype.start = function (cfg) {
|
||||
}
|
||||
|
||||
return loop();
|
||||
}).fail(function (error) {
|
||||
if ('SESSION_NOT_REGISTERED' === error[0])
|
||||
{
|
||||
// We are registering for events here to
|
||||
// properly handle reconnections.
|
||||
return xapi.call('event.register', ['*']).then(loop);
|
||||
}
|
||||
|
||||
throw error;
|
||||
});
|
||||
}();
|
||||
}).fail(function (error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user