ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-9701. User may navigate to dashboard on the not installed cluster (onechiporenko)
Date Thu, 19 Feb 2015 13:54:29 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 01aff40b9 -> 9fd4a0ccc


AMBARI-9701. User may navigate to dashboard on the not installed cluster (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 9fd4a0ccc2744ab989e15029096e1e2e4f59f635
Parents: 01aff40
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Thu Feb 19 15:40:58 2015 +0200
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Thu Feb 19 15:40:58 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   1 +
 ambari-web/app/mixins.js                        |   1 +
 ambari-web/app/mixins/routers/redirections.js   |  87 +++++++++++++
 ambari-web/app/routes/installer.js              |  49 ++------
 ambari-web/app/routes/main.js                   |  13 +-
 .../test/mixins/routers/redirections_test.js    | 125 +++++++++++++++++++
 6 files changed, 234 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9fd4a0cc/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index f9b3f18..048f2e5 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -132,6 +132,7 @@ var files = ['test/init_model_test',
   'test/mixins/common/serverValidator_test',
   'test/mixins/common/table_server_view_mixin_test',
   'test/mixins/main/host/details/host_components/decommissionable_test',
+  'test/mixins/routers/redirections_test',
   'test/mixins/wizard/addSeccurityConfigs_test',
   'test/mixins/wizard/wizard_menu_view_test',
   'test/mixins/wizard/wizardProgressPageController_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fd4a0cc/ambari-web/app/mixins.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins.js b/ambari-web/app/mixins.js
index 4ac2dce..c17e58c 100644
--- a/ambari-web/app/mixins.js
+++ b/ambari-web/app/mixins.js
@@ -26,6 +26,7 @@ require('mixins/common/serverValidator');
 require('mixins/common/table_server_view_mixin');
 require('mixins/common/table_server_mixin');
 require('mixins/main/host/details/host_components/decommissionable');
+require('mixins/routers/redirections');
 require('mixins/wizard/wizardProgressPageController');
 require('mixins/wizard/wizardDeployProgressController');
 require('mixins/wizard/wizardProgressPageView');

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fd4a0cc/ambari-web/app/mixins/routers/redirections.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/routers/redirections.js b/ambari-web/app/mixins/routers/redirections.js
new file mode 100644
index 0000000..574cc5c
--- /dev/null
+++ b/ambari-web/app/mixins/routers/redirections.js
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+/**
+ * Mixin for routers which may redirect user to the some cluster installer steps
+ * Based on cluster state
+ * @type {Em.Mixin}
+ */
+App.RouterRedirections = Em.Mixin.create({
+
+  /**
+   * List of cluster statuses when it's not installed
+   * @type {string[]}
+   */
+  installerStatuses: ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3',
'SERVICE_STARTING_3', 'CLUSTER_INSTALLED_4'],
+
+  /**
+   * Redirect user to the proper installer step if needed
+   * Based on cluster state:
+   *  1. CLUSTER_NOT_CREATED_1 - to current step
+   *  2. CLUSTER_DEPLOY_PREP_2 - to step 8
+   *  3. CLUSTER_INSTALLING_3/SERVICE_STARTING_3 - to step 9
+   *  4. CLUSTER_INSTALLED_4 - to step 10
+   * @param {Em.Router} router
+   * @param {Object} currentClusterStatus
+   * @param {Boolean} isOnInstaller true - user is on the cluster installer, false - something
else
+   * @method redirectToInstaller
+   */
+  redirectToInstaller: function (router, currentClusterStatus, isOnInstaller) {
+
+    var installerController = router.get('installerController');
+    var path = isOnInstaller ? '' : 'installer.';
+    switch (currentClusterStatus.clusterState) {
+      case 'CLUSTER_NOT_CREATED_1' :
+        var localDb = currentClusterStatus.localdb;
+        if (localDb && localDb.Installer && localDb.Installer.currentStep)
{
+          App.db.data = currentClusterStatus.localdb;
+          App.get('router').setAuthenticated(true);
+          var controllerName = installerController.get('name');
+          var suffixLength = 10;
+          var currentStep = App.get('router').getWizardCurrentStep(controllerName.substr(0,
controllerName.length - suffixLength));
+          installerController.setCurrentStep(currentStep);
+        }
+        router.transitionTo(path + 'step' + installerController.get('currentStep'));
+        break;
+      case 'CLUSTER_DEPLOY_PREP_2' :
+        installerController.setCurrentStep('8');
+        App.db.data = currentClusterStatus.localdb;
+        App.get('router').setAuthenticated(true);
+        router.transitionTo(path + 'step' + installerController.get('currentStep'));
+        break;
+      case 'CLUSTER_INSTALLING_3' :
+      case 'SERVICE_STARTING_3' :
+        if (!installerController.get('isStep9')) {
+          installerController.setCurrentStep('9');
+        }
+        router.transitionTo(path + 'step' + installerController.get('currentStep'));
+        break;
+      case 'CLUSTER_INSTALLED_4' :
+        if (!installerController.get('isStep10')) {
+          installerController.setCurrentStep('10');
+        }
+        App.db.data = currentClusterStatus.localdb;
+        App.get('router').setAuthenticated(true);
+        router.transitionTo(path + 'step' + installerController.get('currentStep'));
+        break;
+    }
+  }
+
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fd4a0cc/ambari-web/app/routes/installer.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/installer.js b/ambari-web/app/routes/installer.js
index 57fe93a..7c24e38 100644
--- a/ambari-web/app/routes/installer.js
+++ b/ambari-web/app/routes/installer.js
@@ -18,12 +18,13 @@
 
 var App = require('app');
 
-module.exports = Em.Route.extend({
+module.exports = Em.Route.extend(App.RouterRedirections, {
   route: '/installer',
   App: require('app'),
 
   enter: function (router) {
     console.log('in /installer:enter');
+    var self = this;
 
     App.clusterStatus.set('wizardControllerName', App.router.get('installerController.name'));
 
@@ -42,51 +43,17 @@ module.exports = Em.Route.extend({
             router.get('mainController').stopPolling();
             console.log('In installer with successful authenticated');
             console.log('current step=' + router.get('installerController.currentStep'));
-            Ember.run.next(function () {
-              var installerController = router.get('installerController');
+            Em.run.next(function () {
               App.clusterStatus.updateFromServer().complete(function () {
                 var currentClusterStatus = App.clusterStatus.get('value');
                 //@TODO: Clean up  following states. Navigation should be done solely via
currentStep stored in the localDb and API persist endpoint.
                 //       Actual currentStep value for the installer controller should always
remain in sync with localdb and at persist store in the server.
                 if (currentClusterStatus) {
-                  switch (currentClusterStatus.clusterState) {
-                    case 'CLUSTER_NOT_CREATED_1' :
-                      var localDb = currentClusterStatus.localdb;
-                      if (localDb && localDb.Installer && localDb.Installer.currentStep)
{
-                        App.db.data = currentClusterStatus.localdb;
-                        App.router.setAuthenticated(true);
-                        var controllerName = installerController.get('name');
-                        var suffixLength = 10;
-                        var currentStep = App.get('router').getWizardCurrentStep(controllerName.substr(0,
controllerName.length - suffixLength));
-                        installerController.setCurrentStep(currentStep);
-                      }
-                      router.transitionTo('step' + installerController.get('currentStep'));
-                      break;
-                    case 'CLUSTER_DEPLOY_PREP_2' :
-                      installerController.setCurrentStep('8');
-                      App.db.data = currentClusterStatus.localdb;
-                      App.router.setAuthenticated(true);
-                      router.transitionTo('step' + installerController.get('currentStep'));
-                      break;
-                    case 'CLUSTER_INSTALLING_3' :
-                    case 'SERVICE_STARTING_3' :
-                      if (!installerController.get('isStep9')) {
-                        installerController.setCurrentStep('9');
-                      }
-                      router.transitionTo('step' + installerController.get('currentStep'));
-                      break;
-                    case 'CLUSTER_INSTALLED_4' :
-                      if (!installerController.get('isStep10')) {
-                        installerController.setCurrentStep('10');
-                      }
-                      App.db.data = currentClusterStatus.localdb;
-                      App.router.setAuthenticated(true);
-                      router.transitionTo('step' + installerController.get('currentStep'));
-                      break;
-                    case 'DEFAULT' :
-                    default:
-                      router.transitionTo('main.dashboard.index');
-                      break;
+                  if (self.get('installerStatuses').contains(currentClusterStatus.clusterState))
{
+                    self.redirectToInstaller(router, currentClusterStatus, true);
+                  }
+                  else {
+                    router.transitionTo('main.dashboard.index');
                   }
                 }
               });

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fd4a0cc/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 8175370..6ad614d 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -19,11 +19,12 @@
 var App = require('app');
 var stringUtils = require('utils/string_utils');
 
-module.exports = Em.Route.extend({
+module.exports = Em.Route.extend(App.RouterRedirections, {
   route: '/main',
   enter: function (router) {
     App.db.updateStorage();
     console.log('in /main:enter');
+    var self = this;
     router.getAuthenticated().done(function (loggedIn) {
       if (loggedIn) {
         var applicationController = App.router.get('applicationController');
@@ -42,6 +43,16 @@ module.exports = Em.Route.extend({
                 });
               }
               else {
+                Em.run.next(function () {
+                  App.clusterStatus.updateFromServer().complete(function () {
+                    var currentClusterStatus = App.clusterStatus.get('value');
+                    if (currentClusterStatus) {
+                      if (self.get('installerStatuses').contains(currentClusterStatus.clusterState))
{
+                        self.redirectToInstaller(router, currentClusterStatus, false);
+                      }
+                    }
+                  });
+                });
                 App.router.get('clusterController').set('isLoaded', true);
               }
             }

http://git-wip-us.apache.org/repos/asf/ambari/blob/9fd4a0cc/ambari-web/test/mixins/routers/redirections_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/routers/redirections_test.js b/ambari-web/test/mixins/routers/redirections_test.js
new file mode 100644
index 0000000..7b3eed7
--- /dev/null
+++ b/ambari-web/test/mixins/routers/redirections_test.js
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+var route, installerController, currentClusterStatus;
+
+describe('App.Redirections', function () {
+
+  beforeEach(function () {
+
+    installerController = Em.Object.create({
+      currentStep: '',
+      setCurrentStep: function (k) {
+        this.set('currentStep', k);
+      }
+    });
+
+    router = Em.Object.create(App.RouterRedirections, {
+      transitionTo: Em.K,
+      setAuthenticated: Em.K,
+      installerController: installerController
+    });
+
+    currentClusterStatus = {};
+
+    sinon.spy(router, 'transitionTo');
+    sinon.spy(router, 'setAuthenticated');
+    sinon.stub(App, 'get').withArgs('router').returns(router);
+
+  });
+
+  afterEach(function () {
+    router.transitionTo.restore();
+    router.setAuthenticated.restore();
+    App.get.restore();
+    currentClusterStatus = {};
+  });
+
+  describe('#redirectToInstaller', function () {
+
+    it('CLUSTER_NOT_CREATED_1. user is on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_NOT_CREATED_1';
+      installerController.set('currentStep', '4');
+      router.redirectToInstaller(router, currentClusterStatus, true);
+      expect(router.transitionTo.calledWith('step4')).to.be.true;
+    });
+
+    it('CLUSTER_NOT_CREATED_1. user is not on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_NOT_CREATED_1';
+      installerController.set('currentStep', '4');
+      router.redirectToInstaller(router, currentClusterStatus, false);
+      expect(router.transitionTo.calledWith('installer.step4')).to.be.true;
+    });
+
+    it('CLUSTER_DEPLOY_PREP_2. user is on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_DEPLOY_PREP_2';
+      router.redirectToInstaller(router, currentClusterStatus, true);
+      expect(router.transitionTo.calledWith('step8')).to.be.true;
+      expect(router.setAuthenticated.calledWith(true)).to.be.true;
+    });
+
+    it('CLUSTER_DEPLOY_PREP_2. user is not on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_DEPLOY_PREP_2';
+      router.redirectToInstaller(router, currentClusterStatus, false);
+      expect(router.transitionTo.calledWith('installer.step8')).to.be.true;
+      expect(router.setAuthenticated.calledWith(true)).to.be.true;
+    });
+
+    it('CLUSTER_INSTALLING_3. user is on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_INSTALLING_3';
+      router.redirectToInstaller(router, currentClusterStatus, true);
+      expect(router.transitionTo.calledWith('step9')).to.be.true;
+    });
+
+    it('CLUSTER_INSTALLING_3. user is not on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_INSTALLING_3';
+      router.redirectToInstaller(router, currentClusterStatus, false);
+      expect(router.transitionTo.calledWith('installer.step9')).to.be.true;
+    });
+
+    it('SERVICE_STARTING_3. user is on installer', function () {
+      currentClusterStatus.clusterState = 'SERVICE_STARTING_3';
+      router.redirectToInstaller(router, currentClusterStatus, true);
+      expect(router.transitionTo.calledWith('step9')).to.be.true;
+    });
+
+    it('SERVICE_STARTING_3. user is not on installer', function () {
+      currentClusterStatus.clusterState = 'SERVICE_STARTING_3';
+      router.redirectToInstaller(router, currentClusterStatus, false);
+      expect(router.transitionTo.calledWith('installer.step9')).to.be.true;
+    });
+
+    it('CLUSTER_INSTALLED_4. user is on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_INSTALLED_4';
+      router.redirectToInstaller(router, currentClusterStatus, true);
+      expect(router.transitionTo.calledWith('step10')).to.be.true;
+      expect(router.setAuthenticated.calledWith(true)).to.be.true;
+    });
+
+    it('CLUSTER_INSTALLED_4. user is not on installer', function () {
+      currentClusterStatus.clusterState = 'CLUSTER_INSTALLED_4';
+      router.redirectToInstaller(router, currentClusterStatus, false);
+      expect(router.transitionTo.calledWith('installer.step10')).to.be.true;
+      expect(router.setAuthenticated.calledWith(true)).to.be.true;
+    });
+
+  });
+
+});
\ No newline at end of file


Mime
View raw message