瀏覽代碼

AMBARI-2351. Security Wizard: Misc fixes related to Navigation and user restriction. (Jaimin Jetly via yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1491678 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 年之前
父節點
當前提交
720145a398

+ 20 - 15
ambari-web/app/controllers/main/admin/security/add/step3.js

@@ -29,6 +29,7 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
   globalProperties: [],
 
   isSubmitDisabled: true,
+  isBackBtnDisabled: true,
 
   isOozieSelected: function () {
     return this.get('content.services').someProperty('serviceName', 'OOZIE');
@@ -47,23 +48,15 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
     return this.get('stages').someProperty('stage', 'stage3') && this.get('stages').findProperty('stage', 'stage3').get('isSuccess');
   }.property('stages.@each.isCompleted'),
 
-  isBackBtnDisabled: function () {
-    return  ((this.get('stages').someProperty('stage', 'stage3') &&
-      this.get('stages').findProperty('stage', 'stage3').get('isSuccess')) ||
-      (this.get('stages').someProperty('stage', 'stage2') &&
-        (!this.get('stages').findProperty('stage', 'stage2').get('isError')) ||
-        (this.get('stages').someProperty('stage', 'stage3') &&
-          (!this.get('stages').findProperty('stage', 'stage3').get('isError')))));
-  }.property('stages.@each.isCompleted'),
-
   clearStep: function () {
     this.get('stages').clear();
     this.set('isSubmitDisabled', true);
+    this.set('isBackBtnDisabled', true);
     this.get('serviceConfigTags').clear();
   },
 
   loadStep: function () {
-    this.set('secureMapping',require('data/secure_mapping').slice(0));
+    this.set('secureMapping', require('data/secure_mapping').slice(0));
     var stages = App.db.getSecurityDeployStages();
     this.prepareSecureConfigs();
     this.clearStep();
@@ -92,6 +85,10 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
   enableSubmit: function () {
     if (this.get('stages').someProperty('isError', true) || this.get('stages').everyProperty('isSuccess', true)) {
       this.set('isSubmitDisabled', false);
+      if (this.get('stages').someProperty('isError', true)) {
+        this.set('isBackBtnDisabled', false);
+        App.router.get('addSecurityController').setStepsEnable();
+      }
     }
   }.observes('stages.@each.isCompleted'),
 
@@ -317,7 +314,7 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
     var self = this;
     //prepare tags to fetch all configuration for a service
     this.get('content.services').forEach(function (_secureService) {
-        self.setServiceTagNames(_secureService, data.Clusters.desired_configs);
+      self.setServiceTagNames(_secureService, data.Clusters.desired_configs);
     });
     this.getAllConfigurations();
   },
@@ -374,7 +371,6 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
   applyConfigurationToClusterSuccessCallback: function (data) {
     this.set('noOfWaitingAjaxCalls', this.get('noOfWaitingAjaxCalls') - 1);
     if (this.get('noOfWaitingAjaxCalls') == 0) {
-      App.router.get('mainAdminSecurityController').setAddSecurityWizardStatus(null);
       var currentStage = this.get('stages').findProperty('stage', 'stage3');
       currentStage.set('isSuccess', true);
     }
@@ -410,8 +406,12 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
   getAllConfigurationsSuccessCallback: function (data) {
     console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
     this.get('serviceConfigTags').forEach(function (_tag) {
+      if (!data.items.someProperty('type', _tag.siteName)) {
+        console.log("Error: Metadata for secure services (secure_configs.js) is having config tags that are not being retrieved from server");
+        this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+      }
       _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
-    });
+    }, this);
     this.addSecureConfigs();
     this.applyConfigurationsToCluster();
   },
@@ -455,6 +455,11 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
       stages.pushObject(stage);
     }, this);
     App.db.setSecurityDeployStages(stages);
-  }.observes('stages.@each.requestId','stages.@each.isStarted','stages.@each.isCompleted')
-
+    App.clusterStatus.setClusterStatus({
+      clusterName: this.get('clusterName'),
+      clusterState: 'ADD_SECURITY_STEP_3',
+      wizardControllerName: App.router.get('addSecurityController.name'),
+      localdb: App.db.data
+    });
+  }.observes('stages.@each.requestId', 'stages.@each.isStarted', 'stages.@each.isCompleted')
 });

+ 11 - 1
ambari-web/app/controllers/main/admin/security/disable.js

@@ -232,8 +232,12 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
   getAllConfigurationsSuccessCallback: function (data) {
     console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
     this.get('serviceConfigTags').forEach(function (_tag) {
+      if (!data.items.someProperty('type', _tag.siteName)) {
+        console.log("Error: Metadata for secure services (secure_configs.js) is having config tags that are not being retrieved from server");
+        this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+      }
       _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
-    });
+    }, this);
     this.removeSecureConfigs();
     this.applyConfigurationsToCluster();
   },
@@ -358,6 +362,12 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
       stages.pushObject(stage);
     }, this);
     App.db.setSecurityDeployStages(stages);
+    App.clusterStatus.setClusterStatus({
+      clusterName: this.get('clusterName'),
+      clusterState: 'DISABLE_SECURITY',
+      wizardControllerName: this.get('name'),
+      localdb: App.db.data
+    });
   }.observes('stages.@each.requestId', 'stages.@each.isStarted', 'stages.@each.isCompleted')
 
 });

+ 2 - 1
ambari-web/app/models/cluster_states.js

@@ -22,7 +22,8 @@ App.clusterStatus = Ember.Object.create({
   validStates: ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3', 'CLUSTER_INSTALLED_4',  'CLUSTER_STARTED_5',
     'ADD_HOSTS_DEPLOY_PREP_2', 'ADD_HOSTS_INSTALLING_3', 'ADD_HOSTS_INSTALLED_4', 'ADD_HOSTS_COMPLETED_5',
     'ADD_SERVICES_DEPLOY_PREP_2', 'ADD_SERVICES_INSTALLING_3', 'ADD_SERVICES_INSTALLED_4', 'ADD_SERVICES_COMPLETED_5',
-    'STOPPING_SERVICES', 'STACK_UPGRADING', 'STACK_UPGRADE_FAILED', 'STACK_UPGRADED', 'STACK_UPGRADE_COMPLETED'],
+    'STOPPING_SERVICES', 'STACK_UPGRADING', 'STACK_UPGRADE_FAILED', 'STACK_UPGRADED', 'STACK_UPGRADE_COMPLETED','ADD_SECURITY_STEP_1',
+    'ADD_SECURITY_STEP_2','ADD_SECURITY_STEP_3','DISABLE_SECURITY','SECURITY_COMPLETED'],
   clusterState: 'CLUSTER_NOT_CREATED_1',
   wizardControllerName: null,
   localdb: null,

+ 9 - 1
ambari-web/app/router.js

@@ -268,11 +268,19 @@ App.Router = Em.Router.extend({
     }
     App.clusterStatus.updateFromServer();
     var clusterStatusOnServer = App.clusterStatus.get('value');
-    if (!localStorage.getObject('ambari').app.user.admin || clusterStatusOnServer && (clusterStatusOnServer.clusterState === 'CLUSTER_STARTED_5' || clusterStatusOnServer.clusterState === 'ADD_HOSTS_COMPLETED_5' || clusterStatusOnServer.clusterState === 'STACK_UPGRADE_COMPLETED' || clusterStatusOnServer.clusterState === 'REASSIGN_MASTER_COMPLETED')) {
+    if (!localStorage.getObject('ambari').app.user.admin || clusterStatusOnServer && (clusterStatusOnServer.clusterState === 'CLUSTER_STARTED_5' ||
+      clusterStatusOnServer.clusterState === 'ADD_HOSTS_COMPLETED_5' || clusterStatusOnServer.clusterState === 'STACK_UPGRADE_COMPLETED' ||
+      clusterStatusOnServer.clusterState === 'REASSIGN_MASTER_COMPLETED') ||clusterStatusOnServer.clusterState === 'SECURITY_COMPLETED' ) {
       return 'main.index';
     } else if (clusterStatusOnServer && clusterStatusOnServer.wizardControllerName === App.router.get('addHostController.name')) {
       // if wizardControllerName == "addHostController", then it means someone closed the browser or the browser was crashed when we were last in Add Hosts wizard
       return 'main.hostAdd';
+    } else if (clusterStatusOnServer && clusterStatusOnServer.wizardControllerName === App.router.get('addSecurityController.name')) {
+      // if wizardControllerName == "addSecurityController", then it means someone closed the browser or the browser was crashed when we were last in Add Security wizard
+      return 'main.admin.adminSecurity.adminAddSecurity';
+    } else if (clusterStatusOnServer && clusterStatusOnServer.wizardControllerName === App.router.get('mainAdminSecurityDisableController.name')) {
+      // if wizardControllerName == "disableSecurityController", then it means someone closed the browser or the browser was crashed when we were last in disable Security pop-up.
+      return 'main.admin.adminSecurity.disableSecurity';
     } else if (clusterStatusOnServer && clusterStatusOnServer.wizardControllerName === App.router.get('addServiceController.name')) {
       // if wizardControllerName == "addHostController", then it means someone closed the browser or the browser was crashed when we were last in Add Hosts wizard
       return 'main.serviceAdd';

+ 72 - 14
ambari-web/app/routes/add_security.js

@@ -23,6 +23,26 @@ module.exports = Em.Route.extend({
     console.log('in /security/add:enter');
 
     Ember.run.next(function () {
+      App.clusterStatus.updateFromServer();
+      var currentClusterStatus = App.clusterStatus.get('value');
+      if (currentClusterStatus) {
+        switch (currentClusterStatus.clusterState) {
+          case 'ADD_SECURITY_STEP_1' :
+            router.set('addSecurityController.currentStep', 1);
+            App.db.data = currentClusterStatus.localdb;
+            break;
+          case 'ADD_SECURITY_STEP_2' :
+            router.set('addSecurityController.currentStep', 2);
+            App.db.data = currentClusterStatus.localdb;
+            break;
+          case 'ADD_SECURITY_STEP_3' :
+            router.set('addSecurityController.currentStep', 3);
+            App.db.data = currentClusterStatus.localdb;
+            break;
+          default:
+            break;
+        }
+      }
       if (router.get('mainAdminSecurityController').getAddSecurityWizardStatus() === 'RUNNING') {
         var mainAdminSecurityController = router.get('mainAdminSecurityController');
         var addSecurityController = router.get('addSecurityController');
@@ -38,25 +58,36 @@ module.exports = Em.Route.extend({
           secondary: null,
           showFooter: false,
 
-          onPrimary: function () {
+          onClose: function () {
+            if (router.get('addSecurityController.currentStep') == 3) {
+              var applyingConfigStage = router.get('mainAdminSecurityAddStep3Controller.stages').findProperty('stage', 'stage3');
+              if (applyingConfigStage) {
+                var applyingConfig = (applyingConfigStage.get('isStarted')) && (!applyingConfigStage.get('isCompleted'));
+                if (applyingConfig) {
+                  return;
+                } else {
+                  router.get('mainAdminSecurityAddStep3Controller').clearStep();
+                }
+              }
+            }
             this.hide();
             App.router.get('updateController').set('isWorking', true);
+            mainAdminSecurityController.setAddSecurityWizardStatus(null);
+            App.db.setSecurityDeployStages(undefined);
+            router.get('addSecurityController').setCurrentStep(1);
+            App.clusterStatus.setClusterStatus({
+              clusterName: router.get('content.cluster.name'),
+              clusterState: 'SECURITY_COMPLETED',
+              wizardControllerName: router.get('addSecurityController.name'),
+              localdb: App.db.data
+            });
             router.transitionTo('adminSecurity.index');
           },
-          onClose: function () {
-            if (router.get('addSecurityController.currentStep') != 3 || (router.get('addSecurityController.currentStep') == 3 && router.get('mainAdminSecurityAddStep3Controller.isSubmitDisabled') === false)) {
-              this.hide();
-              App.router.get('updateController').set('isWorking', true);
-              mainAdminSecurityController.setAddSecurityWizardStatus(null);
-              App.db.setSecurityDeployStages(undefined);
-              router.get('addSecurityController').setCurrentStep(1);
-              router.transitionTo('adminSecurity.index');
-            }
-          },
           didInsertElement: function () {
             this.fitHeight();
           }
         });
+
         App.router.transitionTo('step' + currentStep);
       } else {
         router.transitionTo('adminSecurity.index');
@@ -66,6 +97,15 @@ module.exports = Em.Route.extend({
 
   step1: Em.Route.extend({
     route: '/start',
+    enter: function (router) {
+      App.clusterStatus.setClusterStatus({
+        clusterName: this.get('clusterName'),
+        clusterState: 'ADD_SECURITY_STEP_1',
+        wizardControllerName: router.get('addSecurityController.name'),
+        localdb: App.db.data
+      });
+    },
+
     connectOutlets: function (router) {
       console.log('in addSecurity.step1:connectOutlets');
       var controller = router.get('addSecurityController');
@@ -85,6 +125,15 @@ module.exports = Em.Route.extend({
 
   step2: Em.Route.extend({
     route: '/configure',
+
+    enter: function (router) {
+      App.clusterStatus.setClusterStatus({
+        clusterName: this.get('clusterName'),
+        clusterState: 'ADD_SECURITY_STEP_2',
+        wizardControllerName: router.get('addSecurityController.name'),
+        localdb: App.db.data
+      });
+    },
     connectOutlets: function (router) {
       console.log('in addSecurity.step2:connectOutlets');
       var controller = router.get('addSecurityController');
@@ -106,6 +155,16 @@ module.exports = Em.Route.extend({
 
   step3: Em.Route.extend({
     route: '/apply',
+
+    enter: function (router) {
+      App.clusterStatus.setClusterStatus({
+        clusterName: this.get('clusterName'),
+        clusterState: 'ADD_SECURITY_STEP_3',
+        wizardControllerName: router.get('addSecurityController.name'),
+        localdb: App.db.data
+      });
+    },
+
     connectOutlets: function (router) {
       console.log('in addSecurity.step3:connectOutlets');
       var controller = router.get('addSecurityController');
@@ -121,14 +180,13 @@ module.exports = Em.Route.extend({
     },
     back: function (router, context) {
       var controller = router.get('mainAdminSecurityAddStep3Controller');
-      if (!controller.get('isBackBtnDisabled')) {
+      if (!controller.get('isSubmitDisabled')) {
         router.transitionTo('step2');
       }
     },
     done: function (router, context) {
-      router.get('mainAdminSecurityController').setAddSecurityWizardStatus(null);
       var controller = router.get('mainAdminSecurityAddStep3Controller');
-      if (!controller.get('isSubmitDisabled')) {
+      if (!controller.get('isBackBtnDisabled')) {
         $(context.currentTarget).parents("#modal").find(".close").trigger('click');
       }
     }

+ 44 - 26
ambari-web/app/routes/main.js

@@ -686,36 +686,51 @@ module.exports = Em.Route.extend({
         route: '/disableSecurity',
         enter: function (router) {
           if (router.get('mainAdminSecurityController').getDisableSecurityStatus() === 'RUNNING') {
-          Ember.run.next(function () {
-            App.router.get('updateController').set('isWorking', false);
-            App.ModalPopup.show({
-              classNames: ['full-width-modal'],
-              header: Em.I18n.t('admin.removeSecurity.header'),
-              bodyClass: App.MainAdminSecurityDisableView.extend({
-                controllerBinding: 'App.router.mainAdminSecurityDisableController'
-              }),
-              primary: Em.I18n.t('form.cancel'),
-              secondary: null,
-              showFooter: false,
-
-              onPrimary: function () {
-                this.hide();
-                App.router.get('updateController').set('isWorking', true);
-              },
-              onClose: function () {
-                App.db.setSecurityDeployStages(undefined);
-                router.get('mainAdminSecurityController').setDisableSecurityStatus(undefined);
-                if (router.get('mainAdminSecurityDisableController.isSubmitDisabled') === false) {
+            App.clusterStatus.setClusterStatus({
+              clusterName: this.get('clusterName'),
+              clusterState: 'DISABLE_SECURITY',
+              wizardControllerName: router.get('mainAdminSecurityDisableController.name'),
+              localdb: App.db.data
+            });
+            Ember.run.next(function () {
+              App.router.get('updateController').set('isWorking', false);
+              App.ModalPopup.show({
+                classNames: ['full-width-modal'],
+                header: Em.I18n.t('admin.removeSecurity.header'),
+                bodyClass: App.MainAdminSecurityDisableView.extend({
+                  controllerBinding: 'App.router.mainAdminSecurityDisableController'
+                }),
+                primary: Em.I18n.t('form.cancel'),
+                secondary: null,
+                showFooter: false,
+
+                onClose: function () {
+                  var applyingConfigStage = router.get('mainAdminSecurityDisableController.stages').findProperty('stage', 'stage3');
+                  if (applyingConfigStage) {
+                    var applyingConfig = (applyingConfigStage.get('isStarted')) && (!applyingConfigStage.get('isCompleted'));
+                    if (applyingConfig) {
+                      return;
+                    } else {
+                      router.get('mainAdminSecurityDisableController').clearStep();
+                    }
+                  }
                   this.hide();
+                  App.db.setSecurityDeployStages(undefined);
+                  router.get('mainAdminSecurityController').setDisableSecurityStatus(undefined);
                   App.router.get('updateController').set('isWorking', true);
+                  App.clusterStatus.setClusterStatus({
+                    clusterName: router.get('content.cluster.name'),
+                    clusterState: 'SECURITY_COMPLETED',
+                    wizardControllerName: router.get('mainAdminSecurityDisableController.name'),
+                    localdb: App.db.data
+                  });
                   router.transitionTo('adminSecurity.index');
+                },
+                didInsertElement: function () {
+                  this.fitHeight();
                 }
-              },
-              didInsertElement: function () {
-                this.fitHeight();
-              }
+              });
             });
-          });
           } else {
             router.transitionTo('adminSecurity.index');
           }
@@ -726,7 +741,10 @@ module.exports = Em.Route.extend({
         },
 
         done: function (router, context) {
-          $(context.currentTarget).parents("#modal").find(".close").trigger('click');
+          var controller = router.get('mainAdminSecurityDisableController');
+          if (!controller.get('isSubmitDisabled')) {
+            $(context.currentTarget).parents("#modal").find(".close").trigger('click');
+          }
         }
       }),