From 06e9a949d5f919a5632a7bd45b7976358d30da09 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Mon, 26 May 2014 17:09:44 +0200 Subject: [PATCH] Cluster Servers and Coordinators are now working async. It is now possible to contact a cluster even if some of the coordinators are down --- .../js/collections/clusterCoordinators.js | 53 +++++++----- .../js/collections/clusterServers.js | 84 +++++++++++-------- .../js/routers/clusterRouter.js | 4 + 3 files changed, 87 insertions(+), 54 deletions(-) diff --git a/js/apps/system/aardvark/clusterFrontend/js/collections/clusterCoordinators.js b/js/apps/system/aardvark/clusterFrontend/js/collections/clusterCoordinators.js index b4988c2d33..bfba2d66db 100644 --- a/js/apps/system/aardvark/clusterFrontend/js/collections/clusterCoordinators.js +++ b/js/apps/system/aardvark/clusterFrontend/js/collections/clusterCoordinators.js @@ -16,6 +16,27 @@ this._retryCount = 0; }, + checkRetries: function() { + this.updateUrl(); + if (this._retryCount > 10) { + window.App.clusterUnreachable(); + } + }, + + successFullTry: function() { + this._retryCount = 0; + }, + + failureTry: function(retry, err) { + if (err.status === 401) { + window.App.requestAuth(); + } else { + window.App.clusterPlan.rotateCoordinator(); + this._retryCount++; + retry(); + } + }, + statusClass: function(s) { switch (s) { case "ok": @@ -30,26 +51,15 @@ return "danger"; } }, - + getStatuses: function(cb, nextStep) { - if (this._retryCount > 10) { - console.log("Cluster unreachable"); - } + this.checkRetries(); var self = this; - this.updateUrl(); this.fetch({ beforeSend: window.App.addAuth.bind(window.App), - error: function() { - self._retryCount++; - console.log(self._retryCount); - self.forEach(function(m) { - cb(self.statusClass("critical"), m.get("address")); - }); - window.App.clusterPlan.rotateCoordinator(); - self.getStatuses(cb, nextStep); - } + error: self.failureTry.bind(self, self.getStatuses.bind(self, cb, nextStep)) }).done(function() { - console.log(self._retryCount); + self.successFullTry(); self._retryCount = 0; self.forEach(function(m) { cb(self.statusClass(m.get("status")), m.get("address")); @@ -59,14 +69,13 @@ }, byAddress: function (res, callback) { + this.checkRetries(); var self = this; - this.updateUrl(); this.fetch({ beforeSend: window.App.addAuth.bind(window.App), - error: function() { - console.log("incord2"); - } + error: self.failureTry.bind(self, self.byAddress.bind(self, res, callback)) }).done(function() { + self.successFullTry(); res = res || {}; self.forEach(function(m) { var addr = m.get("address"); @@ -80,6 +89,8 @@ }, getList: function() { + throw "Do not use coordinator.getList"; + /* this.fetch({ async: false, beforeSend: window.App.addAuth.bind(window.App) @@ -87,9 +98,12 @@ return this.map(function(m) { return m.forList(); }); + */ }, getOverview: function() { + throw "Do not use coordinator.getOverview"; + /* this.fetch({ async: false, beforeSend: window.App.addAuth.bind(window.App) @@ -123,6 +137,7 @@ } }); return res; + */ } }); }()); diff --git a/js/apps/system/aardvark/clusterFrontend/js/collections/clusterServers.js b/js/apps/system/aardvark/clusterFrontend/js/collections/clusterServers.js index 46b0d0f510..74a30351e3 100644 --- a/js/apps/system/aardvark/clusterFrontend/js/collections/clusterServers.js +++ b/js/apps/system/aardvark/clusterFrontend/js/collections/clusterServers.js @@ -16,6 +16,28 @@ initialize: function() { window.App.registerForUpdate(this); + this._retryCount = 0; + }, + + checkRetries: function() { + this.updateUrl(); + if (this._retryCount > 10) { + window.App.clusterUnreachable(); + } + }, + + successFullTry: function() { + this._retryCount = 0; + }, + + failureTry: function(retry, err) { + if (err.status === 401) { + window.App.requestAuth(); + } else { + window.App.clusterPlan.rotateCoordinator(); + this._retryCount++; + retry(); + } }, statusClass: function(s) { @@ -34,45 +56,31 @@ }, getStatuses: function(cb) { + this.checkRetries(); var self = this, completed = function() { + self.successFullTry(); + self._retryCount = 0; self.forEach(function(m) { cb(self.statusClass(m.get("status")), m.get("address")); }); }; - this.updateUrl(); // This is the first function called in // Each update loop this.fetch({ - async: false, beforeSend: window.App.addAuth.bind(window.App), - error: function(d) { - if (d.status === 401) { - window.App.requestAuth(); - } else { - console.log("inDB"); - self.forEach(function(m) { - cb(self.statusClass("critical"), m.get("address")); - }); - } - } + error: self.failureTry.bind(self, self.getStatuses.bind(self, cb)) }).done(completed); }, byAddress: function (res, callback) { + this.checkRetries(); var self = this; - this.updateUrl(); this.fetch({ beforeSend: window.App.addAuth.bind(window.App), - error: function(d) { - if (d.status === 401) { - window.App.requestAuth(); - } else { - console.log(d); - console.log("Hier isse kapuuuhhhttt inDB2"); - } - } + error: self.failureTry.bind(self, self.byAddress.bind(self, res, callback)) }).done(function() { + self.successFullTry(); res = res || {}; self.forEach(function(m) { var addr = m.get("address"); @@ -85,25 +93,30 @@ }); }, - getList: function() { + getList: function(callback) { + throw "Do not use"; + var self = this; this.fetch({ - async: false, - beforeSend: window.App.addAuth.bind(window.App) + beforeSend: window.App.addAuth.bind(window.App), + error: self.failureTry.bind(self, self.getList.bind(self, callback)) + }).done(function() { + self.successFullTry(); + var res = []; + _.each(self.where({role: "primary"}), function(m) { + var e = {}; + e.primary = m.forList(); + if (m.get("secondary")) { + e.secondary = self.get(m.get("secondary")).forList(); + } + res.push(e); + }); + callback(res); }); - var res = [], - self = this; - _.each(this.where({role: "primary"}), function(m) { - var e = {}; - e.primary = m.forList(); - if (m.get("secondary")) { - e.secondary = self.get(m.get("secondary")).forList(); - } - res.push(e); - }); - return res; }, getOverview: function() { + throw "Do not use DbServer.getOverview"; + /* this.fetch({ async: false, beforeSend: window.App.addAuth.bind(window.App) @@ -146,6 +159,7 @@ } }); return res; + */ } }); diff --git a/js/apps/system/aardvark/clusterFrontend/js/routers/clusterRouter.js b/js/apps/system/aardvark/clusterFrontend/js/routers/clusterRouter.js index 55c4c53cc0..e742a4cebe 100644 --- a/js/apps/system/aardvark/clusterFrontend/js/routers/clusterRouter.js +++ b/js/apps/system/aardvark/clusterFrontend/js/routers/clusterRouter.js @@ -174,6 +174,10 @@ arangoDatabase, btoa, _*/ serverToShow : this.serverToShow }); this.dashboardView.render(); + }, + + clusterUnreachable: function() { + alert("Your cluster seems to be unreachable. This is only temp msg"); } });