diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js index 4c6dc1d7e0..74a3b74d80 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js @@ -302,6 +302,7 @@ return; } this.shardsView = new window.ShardsView({ + dbServers: this.dbServers }); this.shardsView.render(); }, diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/templates/shardsView.ejs b/js/apps/system/_admin/aardvark/APP/frontend/js/templates/shardsView.ejs index af5179f44e..b187825e06 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/templates/shardsView.ejs +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/templates/shardsView.ejs @@ -3,11 +3,20 @@
<% var genClass = 'pure-u-1-3'; %> <% var disabled = ' '; %> + <% var collectionName; %> + <% var first = 0; %> <% _.each(collections, function(collection, name) { %> <% if (name.substring(0,1) !== '_') { %> + <% collectionName = name%> + + <% if (first === 0) { %> +
+ <% first++; %> + <% } else { %> +
+ <% } %> -
<%= name %> @@ -26,19 +35,43 @@ <% var counter = 0; %> <% _.each(collection.Plan, function(shard, name) { %>
-
+
<%= name %>
+ <% if (name === Object.keys(collection.Current)[counter]) { %>
<%= shard.leader %>
<% } else { %>
<%= shard.leader %>
<% } %> - <% if (shard.followers.length === 0) { %> -
no followers
+ + <% var found = null; %> + <% _.each(shard.followers, function(db) { %> + <% if (db === shard.leader) { %> + <% found = true; %> + <% } %> + <% }); %> + + <% if (found) { %> +
<% } else { %> -
<%= shard.follower %>
+ <% if (shard.followers.length === 0) { %> +
no followers
+ <% } else { %> + + <% var string = ''; %> + <% _.each(shard.followers, function(db) { %> + <% if (shard.followers.length === 1) { %> + <% string += db + " "; %> + <% } else { %> + <% string += db + ", "; %> + <% } %> + <% }); %> + +
<%= string %>
+ <% } %> <% } %> +
@@ -48,6 +81,7 @@ <% } %> <% }); %> +
diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/databaseView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/databaseView.js index a7b6e172d2..744e8e8392 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/databaseView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/databaseView.js @@ -361,7 +361,6 @@ label: user.get("user") }); }); - console.log(users); tableContent.push( window.modalView.createSelectEntry( diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/shardsView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/shardsView.js index 9ec35e70ed..7ec95bf630 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/shardsView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/shardsView.js @@ -12,10 +12,14 @@ knownServers: [], events: { + "click #shardsContent .pure-table-row" : "moveShard", + "click #rebalanceShards" : "rebalanceShards" }, - initialize: function () { + initialize: function (options) { var self = this; + + self.dbServers = options.dbServers; clearInterval(this.intervalFunction); if (window.App.isCluster) { @@ -24,7 +28,7 @@ //start polling with interval this.intervalFunction = window.setInterval(function() { if (window.location.hash === '#shards') { - self.render(); + self.render(false); } }, this.interval); } @@ -54,6 +58,117 @@ } }, + moveShard: function(e) { + var dbName = window.App.currentDB.get("name"); + var collectionName = $(e.currentTarget).attr("collection"); + var shardName = $(e.currentTarget).attr("shard"); + var fromServer = $(e.currentTarget).attr("leader"); + + var buttons = [], + tableContent = []; + + var array = []; + this.dbServers[0].each(function(db) { + if (db.get("name") !== fromServer) { + array.push({ + value: db.get("name"), + label: db.get("name") + }); + } + }); + array = array.reverse(); + + tableContent.push( + window.modalView.createSelectEntry( + "toDBServer", + "Destination", + undefined, + //this.users !== null ? this.users.whoAmI() : 'root', + "Please select the target databse server. The selected database " + + "server will be the new leader of the shard.", + array + ) + ); + + buttons.push( + window.modalView.createSuccessButton( + "Move", + this.confirmMoveShards.bind(this, dbName, collectionName, shardName, fromServer) + ) + ); + + window.modalView.show( + "modalTable.ejs", + "Move shard: " + shardName, + buttons, + tableContent + ); + + }, + + confirmMoveShards: function(dbName, collectionName, shardName, fromServer) { + var self = this; + var toServer = $('#toDBServer').val(); + + var data = { + database: dbName, + collection: collectionName, + shard: shardName, + fromServer: fromServer, + toServer: toServer + }; + + $.ajax({ + type: "POST", + cache: false, + url: arangoHelper.databaseUrl("/_admin/cluster/moveShard"), + contentType: "application/json", + processData: false, + data: JSON.stringify(data), + async: true, + success: function(data) { + if (data === true) { + window.setTimeout(function() { + self.render(false); + }, 1500); + arangoHelper.arangoNotification("Shard " + shardName + " will be moved to " + toServer + "."); + } + }, + error: function() { + arangoHelper.arangoNotification("Shard " + shardName + " could not be moved to " + toServer + "."); + } + }); + + window.modalView.hide(); + }, + + rebalanceShards: function() { + var self = this; + + $.ajax({ + type: "POST", + cache: false, + url: arangoHelper.databaseUrl("/_admin/cluster/rebalanceShards"), + contentType: "application/json", + processData: false, + data: JSON.stringify({}), + async: true, + success: function(data) { + if (data === true) { + window.setTimeout(function() { + self.render(false); + }, 1500); + arangoHelper.arangoNotification("Started rebalance process."); + } + }, + error: function() { + arangoHelper.arangoNotification("Could not start rebalance process."); + } + }); + + window.modalView.hide(); + }, + continueRender: function(collections) { delete collections.code; delete collections.error;