Browse Source

AMBARI-2547. Security wizard: Successive refreshes at some point results in blank screen. (jaimin)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1499599 13f79535-47bb-0310-9956-ffa450edef68
Jaimin Jetly 12 years ago
parent
commit
59d19e5c51

+ 42 - 1
ambari-web/app/controllers/main/admin/security/add/addSecurity_controller.js

@@ -68,12 +68,53 @@ App.AddSecurityController = App.WizardController.extend({
 
   },
 
+  saveServiceConfigProperties: function (stepController) {
+    var serviceConfigProperties = [];
+    stepController.get('stepConfigs').forEach(function (_content) {
+      _content.get('configs').forEach(function (_configProperties) {
+        var displayType = _configProperties.get('displayType');
+        if (displayType === 'directories' || displayType === 'directory') {
+          var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
+          _configProperties.set('value', value);
+        }
+        var overrides = _configProperties.get('overrides');
+        var overridesArray = [];
+        if(overrides!=null){
+          overrides.forEach(function(override){
+            var overrideEntry = {
+              value: override.get('value'),
+              hosts: []
+            };
+            override.get('selectedHostOptions').forEach(function(host){
+              overrideEntry.hosts.push(host);
+            });
+            overridesArray.push(overrideEntry);
+          });
+        }
+        overridesArray = (overridesArray.length) ? overridesArray : null;
+        var configProperty = {
+          id: _configProperties.get('id'),
+          name: _configProperties.get('name'),
+          value: _configProperties.get('value'),
+          defaultValue: _configProperties.get('defaultValue'),
+          serviceName: _configProperties.get('serviceName'),
+          domain:  _configProperties.get('domain'),
+          filename: _configProperties.get('filename'),
+          overrides: overridesArray
+        };
+        serviceConfigProperties.push(configProperty);
+      }, this);
+    }, this);
+    App.db.setSecureConfigProperties(serviceConfigProperties);
+    this.set('content.serviceConfigProperties', serviceConfigProperties);
+  },
+
   /**
    * Loads all service config properties
    */
 
   loadServiceConfigs: function () {
-    var serviceConfigProperties = App.db.getServiceConfigProperties();
+    var serviceConfigProperties = App.db.getSecureConfigProperties();
     this.set('content.serviceConfigProperties', serviceConfigProperties);
   }
 });

+ 52 - 28
ambari-web/app/controllers/main/admin/security/add/step3.js

@@ -75,6 +75,7 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
     if (this.get('stages').someProperty('isError', true)) {
       var failedStages = this.get('stages').filterProperty('isError', true);
       failedStages.setEach('isError', false);
+      failedStages.setEach('isSuccess', false);
       failedStages.setEach('isStarted', false);
     }
     this.moveToNextStage();
@@ -96,6 +97,8 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
         var runningStage = stages.filterProperty('isStarted', true).findProperty('isCompleted', false);
         runningStage.set('isStarted', false);
         this.get('stages').pushObjects(stages);
+      } else {
+        this.get('stages').pushObjects(stages);
       }
     } else {
       this.loadStages();
@@ -451,7 +454,11 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
   },
 
   loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
-    this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
+    if (stage3) {
+      stage3.set('isSuccess', false);
+      stage3.set('isError', true);
+    }
     console.log("TRACE: error code status is: " + request.status);
   },
 
@@ -504,11 +511,16 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
     if (this.get('noOfWaitingAjaxCalls') == 0) {
       var currentStage = this.get('stages').findProperty('stage', 'stage3');
       currentStage.set('isSuccess', true);
+      currentStage.set('isError', false);
     }
   },
 
   applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
-    this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
+    if (stage3) {
+      stage3.set('isSuccess', false);
+      stage3.set('isError', true);
+    }
   },
 
   /**
@@ -536,10 +548,14 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
 
   getAllConfigurationsSuccessCallback: function (data) {
     console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
     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);
+        if (stage3) {
+          stage3.set('isSuccess', false);
+          stage3.set('isError', true);
+        }
       }
       _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
     }, this);
@@ -548,7 +564,11 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
   },
 
   getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
-    this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
+    if (stage3) {
+      stage3.set('isSuccess', false);
+      stage3.set('isError', true);
+    }
     console.log("TRACE: In error function for the getServiceConfigsFromServer call");
     console.log("TRACE: error code status is: " + request.status);
   },
@@ -582,28 +602,32 @@ App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
 
   saveStages: function () {
     var stages = [];
-    this.get('stages').forEach(function (_stage) {
-      var stage = {
-        name: _stage.get('name'),
-        stage: _stage.get('stage'),
-        label: _stage.get('label'),
-        isPolling: _stage.get('isPolling'),
-        isStarted: _stage.get('isStarted'),
-        requestId: _stage.get('requestId'),
-        isSuccess: _stage.get('isSuccess'),
-        isError: _stage.get('isError'),
-        url: _stage.get('url'),
-        polledData: _stage.get('polledData'),
-        data: _stage.get('data')
-      };
-      stages.pushObject(stage);
-    }, this);
-    App.db.setSecurityDeployStages(stages);
-    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')
+    if (this.get('stages').length === 3) {
+      this.get('stages').forEach(function (_stage) {
+        var stage = {
+          name: _stage.get('name'),
+          stage: _stage.get('stage'),
+          label: _stage.get('label'),
+          isPolling: _stage.get('isPolling'),
+          isStarted: _stage.get('isStarted'),
+          requestId: _stage.get('requestId'),
+          isSuccess: _stage.get('isSuccess'),
+          isError: _stage.get('isError'),
+          url: _stage.get('url'),
+          polledData: _stage.get('polledData'),
+          data: _stage.get('data')
+        };
+        stages.pushObject(stage);
+      }, this);
+      App.db.setSecurityDeployStages(stages);
+      if (!App.testMode) {
+        App.clusterStatus.setClusterStatus({
+          clusterName: this.get('clusterName'),
+          clusterState: 'ADD_SECURITY_STEP_3',
+          wizardControllerName: App.router.get('addSecurityController.name'),
+          localdb: App.db.data.AddSecurity
+        });
+      }
+    }
+  }.observes('stages.@each.requestId')
 });

+ 52 - 28
ambari-web/app/controllers/main/admin/security/disable.js

@@ -44,6 +44,7 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
     if (this.get('stages').someProperty('isError', true)) {
       var failedStages = this.get('stages').filterProperty('isError', true);
       failedStages.setEach('isError', false);
+      failedStages.setEach('isSuccess', false);
       failedStages.setEach('isStarted', false);
     }
     this.moveToNextStage();
@@ -63,6 +64,8 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
         var runningStage = stages.filterProperty('isStarted', true).findProperty('isCompleted', false);
         runningStage.set('isStarted', false);
         this.get('stages').pushObjects(stages);
+      } else {
+        this.get('stages').pushObjects(stages);
       }
     } else {
       this.loadStages();
@@ -220,7 +223,11 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
   },
 
   loadClusterConfigsErrorCallback: function (request, ajaxOptions, error) {
-    this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
+    if (stage3) {
+      stage3.set('isSuccess', false);
+      stage3.set('isError', true);
+    }
     console.log("TRACE: error code status is: " + request.status);
   },
 
@@ -244,10 +251,14 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
 
   getAllConfigurationsSuccessCallback: function (data) {
     console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
     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);
+        if (stage3) {
+          stage3.set('isSuccess', false);
+          stage3.set('isError', true);
+        }
       }
       _tag.configs = data.items.findProperty('type', _tag.siteName).properties;
     }, this);
@@ -256,7 +267,11 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
   },
 
   getAllConfigurationsErrorCallback: function (request, ajaxOptions, error) {
-    this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
+    if (stage3) {
+      stage3.set('isSuccess', false);
+      stage3.set('isError', true);
+    }
     console.log("TRACE: In error function for the getServiceConfigsFromServer call");
     console.log("TRACE: error code status is: " + request.status);
   },
@@ -304,11 +319,16 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
     if (this.get('noOfWaitingAjaxCalls') == 0) {
       var currentStage = this.get('stages').findProperty('stage', 'stage3');
       currentStage.set('isSuccess', true);
+      currentStage.set('isError', false);
     }
   },
 
   applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
-    this.get('stages').findProperty('stage', 'stage3').set('isError', true);
+    var stage3 = this.get('stages').findProperty('stage', 'stage3');
+    if (stage3) {
+      stage3.set('isSuccess', false);
+      stage3.set('isError', true);
+    }
   },
 
 
@@ -362,29 +382,33 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
 
   saveStages: function () {
     var stages = [];
-    this.get('stages').forEach(function (_stage) {
-      var stage = {
-        name: _stage.get('name'),
-        stage: _stage.get('stage'),
-        label: _stage.get('label'),
-        isPolling: _stage.get('isPolling'),
-        isStarted: _stage.get('isStarted'),
-        requestId: _stage.get('requestId'),
-        isSuccess: _stage.get('isSuccess'),
-        isError: _stage.get('isError'),
-        url: _stage.get('url'),
-        polledData: _stage.get('polledData'),
-        data: _stage.get('data')
-      };
-      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')
+    if (this.get('stages').length === 3) {
+      this.get('stages').forEach(function (_stage) {
+        var stage = {
+          name: _stage.get('name'),
+          stage: _stage.get('stage'),
+          label: _stage.get('label'),
+          isPolling: _stage.get('isPolling'),
+          isStarted: _stage.get('isStarted'),
+          requestId: _stage.get('requestId'),
+          isSuccess: _stage.get('isSuccess'),
+          isError: _stage.get('isError'),
+          url: _stage.get('url'),
+          polledData: _stage.get('polledData'),
+          data: _stage.get('data')
+        };
+        stages.pushObject(stage);
+      }, this);
+      App.db.setSecurityDeployStages(stages);
+      if (!App.testMode) {
+        App.clusterStatus.setClusterStatus({
+          clusterName: this.get('clusterName'),
+          clusterState: 'DISABLE_SECURITY',
+          wizardControllerName: this.get('name'),
+          localdb: App.db.data.AddSecurity
+        });
+      }
+    }
+  }.observes('stages.@each.requestId')
 
 });

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

@@ -84,7 +84,7 @@ module.exports = Em.Route.extend({
                 clusterName: router.get('content.cluster.name'),
                 clusterState: 'SECURITY_COMPLETED',
                 wizardControllerName: router.get('addSecurityController.name'),
-                localdb: App.db.data
+                localdb: App.db.data.AddSecurity
               });
               router.transitionTo('adminSecurity.index');
             },
@@ -104,12 +104,13 @@ module.exports = Em.Route.extend({
   step1: Em.Route.extend({
     route: '/start',
     enter: function (router) {
+      router.get('addSecurityController').setCurrentStep('1');
       if(!App.testMode){
         App.clusterStatus.setClusterStatus({
           clusterName: this.get('clusterName'),
           clusterState: 'ADD_SECURITY_STEP_1',
           wizardControllerName: router.get('addSecurityController.name'),
-          localdb: App.db.data
+          localdb:  App.db.data.AddSecurity
         });
       }
     },
@@ -118,7 +119,6 @@ module.exports = Em.Route.extend({
       console.log('in addSecurity.step1:connectOutlets');
       var controller = router.get('addSecurityController');
       controller.dataLoading().done(function () {
-        controller.setCurrentStep('1');
         controller.loadAllPriorSteps();
         controller.connectOutlet('mainAdminSecurityAddStep1', controller.get('content'));
       })
@@ -135,12 +135,13 @@ module.exports = Em.Route.extend({
     route: '/configure',
 
     enter: function (router) {
+      router.get('addSecurityController').setCurrentStep('2');
       if(!App.testMode){
         App.clusterStatus.setClusterStatus({
           clusterName: this.get('clusterName'),
           clusterState: 'ADD_SECURITY_STEP_2',
           wizardControllerName: router.get('addSecurityController.name'),
-          localdb: App.db.data
+          localdb:  App.db.data.AddSecurity
         });
       }
     },
@@ -148,7 +149,6 @@ module.exports = Em.Route.extend({
       console.log('in addSecurity.step2:connectOutlets');
       var controller = router.get('addSecurityController');
       controller.dataLoading().done(function () {
-        controller.setCurrentStep('2');
         controller.loadAllPriorSteps();
         controller.connectOutlet('mainAdminSecurityAddStep2', controller.get('content'));
       })
@@ -166,15 +166,6 @@ 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');

+ 7 - 13
ambari-web/app/routes/main.js

@@ -656,12 +656,12 @@ module.exports = Em.Route.extend({
         if (!App.testMode) {
           App.clusterStatus.updateFromServer();
           var currentClusterStatus = App.clusterStatus.get('value');
-          App.db.data = currentClusterStatus.localdb;
-          if (currentClusterStatus.localdb.AddSecurity) {
-            App.db.setSecurityDeployStages(currentClusterStatus.localdb.AddSecurity.securityDeployStages);
-            controller.setAddSecurityWizardStatus(currentClusterStatus.localdb.AddSecurity.status);
-            App.db.setServiceConfigProperties(currentClusterStatus.localdb.Installer.configProperties);
-            App.db.setWizardCurrentStep('AddSecurity', currentClusterStatus.localdb.AddSecurity.currentStep);
+          App.db.data.AddSecurity = currentClusterStatus.localdb;
+          if (currentClusterStatus.localdb) {
+            App.db.setSecurityDeployStages(currentClusterStatus.localdb.securityDeployStages);
+            controller.setAddSecurityWizardStatus(currentClusterStatus.localdb.status);
+            App.db.setServiceConfigProperties(currentClusterStatus.localdb.secureConfigProperties);
+            App.db.setWizardCurrentStep('AddSecurity', currentClusterStatus.localdb.currentStep);
           }
           App.db.setDisableSecurityStatus(currentClusterStatus.localdb.disableSecurityStatus);
         }
@@ -699,12 +699,6 @@ module.exports = Em.Route.extend({
         enter: function (router) {
           //after refresh check if the wizard is open then restore it
           if (router.get('mainAdminSecurityController').getDisableSecurityStatus() === 'RUNNING') {
-            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({
@@ -746,7 +740,7 @@ module.exports = Em.Route.extend({
                     clusterName: router.get('content.cluster.name'),
                     clusterState: 'SECURITY_COMPLETED',
                     wizardControllerName: router.get('mainAdminSecurityDisableController.name'),
-                    localdb: App.db.data
+                    localdb: App.db.data.AddSecurity
                   });
                   this.hide();
                   router.transitionTo('adminSecurity.index');

+ 26 - 6
ambari-web/app/utils/db.js

@@ -21,21 +21,21 @@ App.db = {};
 if (typeof Storage !== 'undefined') {
   Storage.prototype.setObject = function (key, value) {
     this.setItem(key, JSON.stringify(value));
-  }
+  };
 
   Storage.prototype.getObject = function (key) {
     var value = this.getItem(key);
     return value && JSON.parse(value);
-  }
+  };
 } else {
   // stub for unit testing purposes
   window.localStorage = {};
   localStorage.setItem = function (key, val) {
     this[key] = val;
-  }
+  };
   localStorage.getItem = function (key) {
     return this[key];
-  }
+  };
   window.localStorage.setObject = function (key, value) {
     this[key] = value;
   };
@@ -306,7 +306,10 @@ App.db.setSecurityWizardStatus = function (status) {
 
 App.db.setDisableSecurityStatus = function (status) {
   App.db.data = localStorage.getObject('ambari');
-  App.db.data.disableSecurityStatus = status;
+  if (!App.db.data.AddSecurity) {
+    App.db.data.AddSecurity = {};
+  }
+  App.db.data.AddSecurity.disableSecurityStatus = status;
   localStorage.setObject('ambari', App.db.data);
 };
 
@@ -319,6 +322,15 @@ App.db.setSecurityDeployStages = function (securityStages) {
   localStorage.setObject('ambari', App.db.data);
 };
 
+App.db.setSecureConfigProperties  = function (secureConfigs) {
+  App.db.data = localStorage.getObject('ambari');
+  if (!App.db.data.AddSecurity) {
+    App.db.data.AddSecurity = {};
+  }
+  App.db.data.AddSecurity.secureConfigProperties = secureConfigs;
+  localStorage.setObject('ambari', App.db.data);
+};
+
 
 /*
  *  getter methods
@@ -507,7 +519,10 @@ App.db.getSecurityWizardStatus = function () {
 
 App.db.getDisableSecurityStatus = function () {
   App.db.data = localStorage.getObject('ambari');
-  return App.db.data.disableSecurityStatus;
+  if (!App.db.data.AddSecurity) {
+    App.db.data.AddSecurity = {};
+  }
+  return App.db.data.AddSecurity.disableSecurityStatus;
 };
 
 App.db.getSecurityDeployStages = function () {
@@ -515,6 +530,11 @@ App.db.getSecurityDeployStages = function () {
   return App.db.data.AddSecurity.securityDeployStages;
 };
 
+App.db.getSecureConfigProperties = function () {
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data.AddSecurity.secureConfigProperties;
+};
+
 App.db.getStacks = function () {
   App.db.data = localStorage.getObject('ambari');
   return App.db.data.app.stacksVersions;

+ 7 - 16
ambari-web/app/utils/polling.js

@@ -82,6 +82,7 @@ App.Poll = Em.Object.extend({
         console.log("TRACE: Polling-> value of the received data is: " + jsonData);
         if (jsonData === null) {
           self.set('isSuccess', true);
+          self.set('isError', false);
         } else {
           var requestId = jsonData.Requests.id;
           self.set('requestId', requestId);
@@ -92,6 +93,7 @@ App.Poll = Em.Object.extend({
       error: function () {
         console.log("ERROR");
         self.set('isError', true);
+        self.set('isSuccess', false);
       },
 
       statusCode: require('data/statusCodes')
@@ -136,8 +138,9 @@ App.Poll = Em.Object.extend({
         console.log("TRACE: In error function for the GET data");
         console.log("TRACE: value of the url is: " + url);
         console.log("TRACE: error code status is: " + request.status);
-        self.set('requestId', undefined);
-        self.set('isError', true);
+        if (!self.get('isSuccess')) {
+          self.set('isError', true);
+        }
       },
 
       statusCode: require('data/statusCodes')
@@ -176,7 +179,9 @@ App.Poll = Em.Object.extend({
     if (runningTasks === 0) {
       if (polledData.everyProperty('Tasks.status', 'COMPLETED')) {
         this.set('isSuccess', true);
+        this.set('isError', false);
       } else if (polledData.someProperty('Tasks.status', 'FAILED') || polledData.someProperty('Tasks.status', 'TIMEDOUT') || polledData.someProperty('Tasks.status', 'ABORTED')) {
+        this.set('isSuccess', false);
         this.set('isError', true);
       }
       return true;
@@ -204,20 +209,6 @@ App.Poll = Em.Object.extend({
       return false;
     }
     this.replacePolledData(tasksData);
-    /* this.hosts.forEach(function (_host) {
-     var actionsPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
-     if (actionsPerHost.length === 0) {
-     _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
-     console.log("INFO: No task is hosted on the host");
-     }
-     if (actionsPerHost !== null && actionsPerHost !== undefined && actionsPerHost.length !== 0) {
-     this.setLogTasksStatePerHost(actionsPerHost, _host);
-     this.onSuccessPerHost(actionsPerHost, _host);     // every action should be a success
-     this.onErrorPerHost(actionsPerHost, _host);     // any action should be a failure
-     this.onInProgressPerHost(actionsPerHost, _host);  // current running action for a host
-     totalProgress += self.progressPerHost(actionsPerHost, _host);
-     }
-     }, this); */
     var totalProgress = this.calculateProgressByTasks(tasksData);
     this.set('progress', totalProgress.toString());
     console.log("INFO: right now the progress is: " + this.get('progress'));