Procházet zdrojové kódy

AMBARI-10838. Ranger Admin HA Wizard: different order after page refresh on step2. (akovalenko)

Aleksandr Kovalenko před 10 roky
rodič
revize
6cfff21078

+ 1 - 0
ambari-web/app/assets/test/tests.js

@@ -59,6 +59,7 @@ var files = ['test/init_model_test',
   'test/controllers/main/admin/highAvailability_controller_test',
   'test/controllers/main/admin/highAvailability/progress_controller_test',
   'test/controllers/main/admin/highAvailability/progress_popup_controller_test',
+  'test/controllers/main/admin/highAvailability/nameNode/step2_controller_test',
   'test/controllers/main/admin/highAvailability/nameNode/step3_controller_test',
   'test/controllers/main/admin/highAvailability/nameNode/step4_controller_test',
   'test/controllers/main/admin/highAvailability/resourceManager/step3_controller_test',

+ 3 - 1
ambari-web/app/controllers/main/admin/highAvailability/nameNode/step2_controller.js

@@ -32,7 +32,9 @@ App.HighAvailabilityWizardStep2Controller = Em.Controller.extend(App.BlueprintMi
 
   showCurrentPrefix: ['NAMENODE'],
 
-  showAdditionalPrefix: ['NAMENODE']
+  showAdditionalPrefix: ['NAMENODE'],
+
+  showInstalledMastersFirst: true
 
 });
 

+ 3 - 1
ambari-web/app/controllers/main/admin/highAvailability/rangerAdmin/step2_controller.js

@@ -31,7 +31,9 @@ App.RAHighAvailabilityWizardStep2Controller = Em.Controller.extend(App.Blueprint
 
   showAdditionalPrefix: ['RANGER_ADMIN'],
 
-  mastersAddableInHA: ['RANGER_ADMIN']
+  mastersAddableInHA: ['RANGER_ADMIN'],
+
+  showInstalledMastersFirst: true
 
 });
 

+ 3 - 1
ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step2_controller.js

@@ -30,6 +30,8 @@ App.RMHighAvailabilityWizardStep2Controller = Em.Controller.extend(App.Blueprint
 
   showCurrentPrefix: ['RESOURCEMANAGER'],
 
-  showAdditionalPrefix: ['RESOURCEMANAGER']
+  showAdditionalPrefix: ['RESOURCEMANAGER'],
+
+  showInstalledMastersFirst: true
 });
 

+ 25 - 5
ambari-web/app/mixins/wizard/assign_master_components.js

@@ -88,6 +88,12 @@ App.AssignMasterComponents = Em.Mixin.create({
    */
   additionalHostsList: [],
 
+  /**
+   * Define whether show already installed masters first
+   * @type {Boolean}
+   */
+  showInstalledMastersFirst: false,
+
   /**
    * Array of <code>servicesMasters</code> objects, that will be shown on the page
    * Are filtered using <code>mastersToShow</code>
@@ -96,16 +102,30 @@ App.AssignMasterComponents = Em.Mixin.create({
   servicesMastersToShow: function () {
     var mastersToShow = this.get('mastersToShow');
     var servicesMasters = this.get('servicesMasters');
+    var result = [];
     if (!mastersToShow.length) {
-      return servicesMasters;
+      result = servicesMasters;
     } else {
-      var result = [];
-      mastersToShow.forEach(function(master){
+      mastersToShow.forEach(function (master) {
         result = result.concat(servicesMasters.filterProperty('component_name', master));
       });
-      return result;
     }
-  }.property('servicesMasters.length', 'mastersToShow.length'),
+
+    if (this.get('showInstalledMastersFirst')) {
+      result = this.sortMasterComponents(result);
+    }
+
+    return result;
+  }.property('servicesMasters.length', 'mastersToShow.length', 'showInstalledMastersFirst'),
+
+  /**
+   * Sort masters, installed masters will be first.
+   * @param masters
+   * @returns {Array}
+   */
+  sortMasterComponents: function (masters) {
+    return [].concat(masters.filterProperty('isInstalled'), masters.filterProperty('isInstalled', false));
+  },
 
   /**
    * Check if <code>installerWizard</code> used

+ 63 - 0
ambari-web/test/controllers/main/admin/highAvailability/nameNode/step2_controller_test.js

@@ -0,0 +1,63 @@
+/**
+ * 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');
+
+describe('App.HighAvailabilityWizardStep2Controller', function () {
+  var controller = App.HighAvailabilityWizardStep2Controller.create();
+
+  describe('#sortMasterComponents', function () {
+
+    it('should sort installed masters first', function() {
+      expect(controller.sortMasterComponents([
+        Em.Object.create({
+          isInstalled: true
+        }),
+        Em.Object.create({
+          isInstalled: false
+        }),
+        Em.Object.create({
+          isInstalled: true
+        }),
+        Em.Object.create({
+          isInstalled: false
+        }),
+        Em.Object.create({
+          isInstalled: true
+        })
+      ])).to.eql([
+            Em.Object.create({
+              isInstalled: true
+            }),
+            Em.Object.create({
+              isInstalled: true
+            }),
+            Em.Object.create({
+              isInstalled: true
+            }),
+            Em.Object.create({
+              isInstalled: false
+            }),
+            Em.Object.create({
+              isInstalled: false
+            })
+          ]);
+    });
+  });
+
+});