ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject ambari git commit: AMBARI-14511. Hive View: No output/feedback when you create or drop databases. (Dipayan Bhowmick va yusaku)
Date Wed, 06 Jan 2016 20:21:19 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk d5c29f9d4 -> 9b99d4982


AMBARI-14511. Hive View: No output/feedback when you create or drop databases. (Dipayan Bhowmick
va yusaku)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9b99d498
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9b99d498
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9b99d498

Branch: refs/heads/trunk
Commit: 9b99d4982710faab64a39ab93a30e7fe0fdefe46
Parents: d5c29f9
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Wed Jan 6 12:16:58 2016 -0800
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Wed Jan 6 12:16:58 2016 -0800

----------------------------------------------------------------------
 .../ui/hive-web/app/controllers/databases.js    | 54 +++++++++++++++-
 .../ui/hive-web/app/services/database.js        | 14 ++++
 .../tests/unit/controllers/databases-test.js    | 68 +++++++++++++++++++-
 3 files changed, 134 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9b99d498/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js
b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js
index 8dff5a8..f0378cd 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js
@@ -18,6 +18,7 @@
 
 import Ember from 'ember';
 import constants from 'hive/utils/constants';
+import ENV from '../config/environment';
 
 export default Ember.Controller.extend({
   databaseService: Ember.inject.service(constants.namingConventions.database),
@@ -92,6 +93,8 @@ export default Ember.Controller.extend({
   selectedDatabaseChanged: function () {
     var self = this;
 
+    this.resetSearch();
+
     this.set('isLoading', true);
 
     this.get('databaseService').getAllTables().then(function () {
@@ -147,12 +150,13 @@ export default Ember.Controller.extend({
 
   getDatabases: function () {
     var self = this;
-    var selectedDatabase = this.get('selectedDatabase');
+    var selectedDatabase = this.get('selectedDatabase.name');
 
     this.set('isLoading', true);
 
     this.get('databaseService').getDatabases().then(function (databases) {
       self.set('isLoading');
+      self.get('databaseService').setDatabaseByName(selectedDatabase);
     }).catch(function (error) {
       self._handleError(error);
 
@@ -164,9 +168,57 @@ export default Ember.Controller.extend({
     });
   }.on('init'),
 
+  syncDatabases: function() {
+    var oldDatabaseNames = this.store.all('database').mapBy('name');
+    var self = this;
+    return this.get('databaseService').getDatabasesFromServer().then(function(data) {
+      // Remove the databases from store which are not in server
+      data.forEach(function(dbName) {
+        if(!oldDatabaseNames.contains(dbName)) {
+          self.store.createRecord('database', {
+            id: dbName,
+            name: dbName
+          });
+        }
+      });
+      // Add the databases in store which are new in server
+      oldDatabaseNames.forEach(function(dbName) {
+        if(!data.contains(dbName)) {
+          self.store.find('database', dbName).then(function(db) {
+            self.store.unloadRecord(db);
+          });
+        }
+      });
+    });
+  },
+
+  initiateDatabaseSync: function() {
+    // This was required so that the unit test would not stall
+    if(ENV.environment !== "test") {
+      Ember.run.later(this, function() {
+        this.syncDatabases();
+        this.initiateDatabaseSync();
+      }, 15000);
+    }
+  }.on('init'),
+
+  resetSearch: function() {
+    var resultsTab = this.get('tabs').findBy('view', constants.namingConventions.databaseSearch);
+    var databaseExplorerTab = this.get('tabs').findBy('view', constants.namingConventions.databaseTree);
+    var tableSearchResults = this.get('tableSearchResults');
+    resultsTab.set('visible', false);
+    this.set('selectedTab', databaseExplorerTab);
+    this.set('tableSearchTerm', '');
+    this.set('columnSearchTerm', '');
+    tableSearchResults.set('tables', undefined);
+    tableSearchResults.set('hasNext', undefined);
+  },
+
+
   actions: {
     refreshDatabaseExplorer: function () {
       this.getDatabases();
+      this.resetSearch();
     },
 
     passwordLDAPDB: function(){

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b99d498/contrib/views/hive/src/main/resources/ui/hive-web/app/services/database.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/services/database.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/services/database.js
index 97f5134..2a6f5d4 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/app/services/database.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/services/database.js
@@ -52,6 +52,20 @@ export default Ember.Service.extend({
     return defer.promise;
   },
 
+  // This will do a ajax call to fetch the current database by by-passing the store.
+  // As we want to retain the current state of databases in store and just want to
+  // find the current databases in the server
+  getDatabasesFromServer: function() {
+    var defer = Ember.RSVP.defer();
+    var url = this.get('baseUrl');
+    Ember.$.getJSON(url).then(function(data) {
+      defer.resolve(data.databases);
+    }, function(err) {
+      defer.reject(err);
+    });
+    return defer.promise;
+  },
+
   setDatabaseByName: function (name) {
     var database = this.databases.findBy('name', name);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b99d498/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/databases-test.js
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/databases-test.js
b/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/databases-test.js
index 10d0bc5..c3ac272 100644
--- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/databases-test.js
+++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/databases-test.js
@@ -20,6 +20,7 @@ import Ember from 'ember';
 import { moduleFor, test } from 'ember-qunit';
 
 var controller;
+var store;
 
 moduleFor('controller:databases', 'DatabasesController', {
   needs: [ 'adapter:database',
@@ -35,9 +36,22 @@ moduleFor('controller:databases', 'DatabasesController', {
       defer.resolve();
 
       return defer.promise;
-    }
+    };
 
+    //mock getDatabasesFromServer which is called by the poller
+    this.container.lookup('service:database').getDatabasesFromServer = function () {
+     var defer = Ember.RSVP.defer();
+
+     var databases = [ "database_a", "database_b"];
+
+     defer.resolve(databases);
+     return defer.promise;
+     };
+
+    store = this.container.lookup('store:main');
     controller = this.subject();
+    controller.store = store;
+
   },
 
   teardown: function () {
@@ -208,3 +222,55 @@ test('showMoreColumns pushes more columns to visibleColumns if there
are still h
   equal(table.get('visibleColumns.length'), controller.get('pageCount') * 2, 'there are 2
visible columns out of 3.');
   equal(table.get('canGetNextPage'), true, 'user can get next columns page.');
 });
+
+test('syncDatabases pushed more databases when new databases are added in the backend', function()
{
+  expect(3);
+
+  var databaseA = {
+    id: "database_a",
+    name: "database_a"
+  };
+
+  Ember.run(function() {
+    store.createRecord('database', databaseA);
+    controller.syncDatabases();
+  });
+
+  var latestDbNames = store.all('database').mapBy('name');
+  equal(latestDbNames.length, 2, "There is 1 additional database added to hive");
+  equal(latestDbNames.contains("database_a"), true, "New database list should contain the
old database name.");
+  equal(latestDbNames.contains("database_b"), true, "New database list should contain the
new database name.");
+});
+
+test('syncDatabases removed database when old databases are removed in the backend', function()
{
+  expect(4);
+
+  var latestDbNames;
+
+  var databaseA = {
+    id: "database_a",
+    name: "database_a"
+  };
+  var databaseB = {
+    id: "database_b",
+    name: "database_b"
+  };
+  var databaseC = {
+    id: "database_c",
+    name: "database_c"
+  };
+
+  Ember.run(function() {
+    store.createRecord('database', databaseA);
+    store.createRecord('database', databaseB);
+    store.createRecord('database', databaseC);
+    controller.syncDatabases();
+  });
+
+  latestDbNames = store.all('database').mapBy('name');
+  equal(latestDbNames.length, 2, "One database is removed from hive");
+  equal(latestDbNames.contains("database_a"), true, "New database list should contain the
old database name.");
+  equal(latestDbNames.contains("database_b"), true, "New database list should contain the
old database name.");
+  equal(latestDbNames.contains("database_c"), false, "New database list should not contain
the database name removed in the backend.");
+
+});


Mime
View raw message