From 43f7248f44dc2de446f603ea09545aaf7a45d08a Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 21 Jan 2014 14:42:09 +0100 Subject: [PATCH] Wired DBServers -> Databases -> Collections -> Shards to backend --- js/apps/system/aardvark/cluster.js | 127 +++++++++--------- .../js/collections/clusterCollections.js | 9 +- .../frontend/js/collections/clusterShards.js | 13 +- .../js/templates/clusterShardsView.ejs | 2 +- .../js/views/clusterCollectionView.js | 14 +- .../frontend/js/views/clusterDatabaseView.js | 5 +- .../frontend/js/views/clusterServerView.js | 4 +- .../frontend/js/views/clusterShardsView.js | 4 +- 8 files changed, 100 insertions(+), 78 deletions(-) diff --git a/js/apps/system/aardvark/cluster.js b/js/apps/system/aardvark/cluster.js index 5f209fa9fa..739825550a 100644 --- a/js/apps/system/aardvark/cluster.js +++ b/js/apps/system/aardvark/cluster.js @@ -28,70 +28,75 @@ /// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// +(function() { -"use strict"; - -// Initialise a new FoxxController called controller under the urlPrefix: "cluster". -var FoxxController = require("org/arangodb/foxx").Controller, - controller = new FoxxController(applicationContext), - _ = require("underscore"), - Communication = require("org/arangodb/sharding/agency-communication"), - comm = new Communication.Communication(); - -/** Get all DBServers - * - * Get a list of all running and expected DBServers - * within the cluster - */ -controller.get("/DBServers", function(req, res) { - var list = { - Pavel: { - role: "primary", - secondary: "Sally", - address: "tcp://192.168.0.1:1337" - }, - Pancho: { - role: "primary", - secondary: "none", - address: "tcp://192.168.0.2:1337" - }, - Pablo: { - role: "primary", - secondary: "Sandy", - address: "tcp://192.168.0.5:1337" - }, - Sally: { - role: "secondary", - address: "tcp://192.168.1.1:1337" - }, - Sandy: { - role: "secondary", - address: "tcp://192.168.1.5:1337" - } - }, - noBeat = ["Sandy"], - serving = ["Pancho", "Pavel"], + "use strict"; + // Initialise a new FoxxController called controller under the urlPrefix: "cluster". + var FoxxController = require("org/arangodb/foxx").Controller, + controller = new FoxxController(applicationContext), + _ = require("underscore"), + Communication = require("org/arangodb/sharding/agency-communication"), + comm = new Communication.Communication(), beats = comm.sync.Heartbeats(), - resList = []; - - list = comm.current.DBServers().getList(); - noBeat = beats.noBeat(); - serving = beats.getServing(); + servers = comm.current.DBServers(), + dbs = comm.current.Databases(), + coords = comm.current.Coordinators(); + /** Get all DBServers + * + * Get a list of all running and expected DBServers + * within the cluster + */ + controller.get("/DBServers", function(req, res) { + var resList = [], + list = servers.getList(), + noBeat = beats.noBeat(), + serving = beats.getServing(); - _.each(list, function(v, k) { - v.name = k; - resList.push(v); - if (_.contains(noBeat, k)) { - v.status = "critical"; - return; - } - if (v.role === "primary" && !_.contains(serving, k)) { - v.status = "warning"; - return; - } - v.status = "ok"; + _.each(list, function(v, k) { + v.name = k; + resList.push(v); + if (_.contains(noBeat, k)) { + v.status = "critical"; + return; + } + if (v.role === "primary" && !_.contains(serving, k)) { + v.status = "warning"; + return; + } + v.status = "ok"; + }); + res.json(resList); }); - res.json(resList); -}); + + controller.get("/Databases", function(req, res) { + var list = dbs.getList(); + res.json(_.map(list, function(d) { + return {name: d}; + })); + }); + + controller.get("/:dbname/Collections", function(req, res) { + var dbname = req.params("dbname"), + selected = dbs.select(dbname); + res.json(_.map(selected.getCollections(), + function(c) { + return {name: c}; + }) + ); + }); + + controller.get("/:dbname/:colname/Shards/:servername", function(req, res) { + var dbname = req.params("dbname"), + colname = req.params("colname"), + servername = req.params("servername"), + selected = dbs.select(dbname).collection(colname); + res.json(_.map(selected.getShardsForServer(servername), + function(c) { + return {id: c}; + }) + ); + }); + +}()); diff --git a/js/apps/system/aardvark/frontend/js/collections/clusterCollections.js b/js/apps/system/aardvark/frontend/js/collections/clusterCollections.js index d413cf8164..600606a7e9 100644 --- a/js/apps/system/aardvark/frontend/js/collections/clusterCollections.js +++ b/js/apps/system/aardvark/frontend/js/collections/clusterCollections.js @@ -5,9 +5,14 @@ window.ClusterCollections = Backbone.Collection.extend({ model: window.ClusterCollection, - url: "/_admin/aardvark/cluster/Collections", + url: function() { + return "/_admin/aardvark/cluster/" + + this.dbname + "/" + + "Collections"; + }, - getList: function() { + getList: function(db) { + this.dbname = db; this.fetch({ async: false }); diff --git a/js/apps/system/aardvark/frontend/js/collections/clusterShards.js b/js/apps/system/aardvark/frontend/js/collections/clusterShards.js index 94a9cc9e4b..9b69c316cf 100644 --- a/js/apps/system/aardvark/frontend/js/collections/clusterShards.js +++ b/js/apps/system/aardvark/frontend/js/collections/clusterShards.js @@ -8,9 +8,18 @@ model: window.ClusterShard, - url: "/_admin/aardvark/cluster/Shards", + url: function() { + return "/_admin/aardvark/cluster/" + + this.dbname + "/" + + this.colname + "/" + + "Shards/" + + this.server; + }, - getList: function() { + getList: function(dbname, colname, server) { + this.dbname = dbname; + this.colname = colname; + this.server = server; this.fetch({ async: false }); diff --git a/js/apps/system/aardvark/frontend/js/templates/clusterShardsView.ejs b/js/apps/system/aardvark/frontend/js/templates/clusterShardsView.ejs index d7d75e691d..0071475141 100644 --- a/js/apps/system/aardvark/frontend/js/templates/clusterShardsView.ejs +++ b/js/apps/system/aardvark/frontend/js/templates/clusterShardsView.ejs @@ -13,7 +13,7 @@ diff --git a/js/apps/system/aardvark/frontend/js/views/clusterCollectionView.js b/js/apps/system/aardvark/frontend/js/views/clusterCollectionView.js index 891f7d47c4..7404ee220b 100644 --- a/js/apps/system/aardvark/frontend/js/views/clusterCollectionView.js +++ b/js/apps/system/aardvark/frontend/js/views/clusterCollectionView.js @@ -22,9 +22,11 @@ loadCollection: function(e) { var id = e.currentTarget.id; - this.shardsView.render({ - name: id - }); + this.shardsView.render( + this.db, + id, + this.server + ); }, unrender: function() { @@ -32,9 +34,11 @@ this.shardsView.unrender(); }, - render: function() { + render: function(db, server) { + this.db = db; + this.server = server; $(this.el).html(this.template.render({ - collections: this.collection.getList() + collections: this.collection.getList(this.db) })); this.shardsView.unrender(); return this; diff --git a/js/apps/system/aardvark/frontend/js/views/clusterDatabaseView.js b/js/apps/system/aardvark/frontend/js/views/clusterDatabaseView.js index 501b36de65..f8877e6e2d 100644 --- a/js/apps/system/aardvark/frontend/js/views/clusterDatabaseView.js +++ b/js/apps/system/aardvark/frontend/js/views/clusterDatabaseView.js @@ -22,7 +22,7 @@ loadDatabase: function(e) { var id = e.currentTarget.id; - this.colView.render(id); + this.colView.render(id, this.server); }, unrender: function() { @@ -30,7 +30,8 @@ this.colView.unrender(); }, - render: function(){ + render: function(server) { + this.server = server; $(this.el).html(this.template.render({ databases: this.collection.getList() })); diff --git a/js/apps/system/aardvark/frontend/js/views/clusterServerView.js b/js/apps/system/aardvark/frontend/js/views/clusterServerView.js index 7932063b2c..4772c75a03 100644 --- a/js/apps/system/aardvark/frontend/js/views/clusterServerView.js +++ b/js/apps/system/aardvark/frontend/js/views/clusterServerView.js @@ -22,9 +22,7 @@ loadServer: function(e) { var id = e.currentTarget.id; - this.dbView.render({ - name: id - }); + this.dbView.render(id); this.render(true); }, diff --git a/js/apps/system/aardvark/frontend/js/views/clusterShardsView.js b/js/apps/system/aardvark/frontend/js/views/clusterShardsView.js index 6717aa0c00..b48b7f53cc 100644 --- a/js/apps/system/aardvark/frontend/js/views/clusterShardsView.js +++ b/js/apps/system/aardvark/frontend/js/views/clusterShardsView.js @@ -14,9 +14,9 @@ $(this.el).html(""); }, - render: function() { + render: function(db, col, server) { $(this.el).html(this.template.render({ - shards: this.collection.getList() + shards: this.collection.getList(db, col, server) })); return this; }