You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2016/04/06 16:36:41 UTC

ambari git commit: AMBARI-15737: Host not expanding more than one field in host-name pattern (akovalenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 786d1ed6e -> fb8f34855


AMBARI-15737: Host not expanding more than one field in host-name pattern (akovalenko)


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

Branch: refs/heads/trunk
Commit: fb8f34855f81a0b439ebdb59d4ca297d835189fe
Parents: 786d1ed
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Wed Apr 6 15:12:09 2016 +0300
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Wed Apr 6 15:12:09 2016 +0300

----------------------------------------------------------------------
 .../app/controllers/wizard/step2_controller.js  | 71 ++++++++++++++------
 .../test/controllers/wizard/step2_test.js       | 20 ++++++
 2 files changed, 70 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fb8f3485/ambari-web/app/controllers/wizard/step2_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard/step2_controller.js b/ambari-web/app/controllers/wizard/step2_controller.js
index 1fd5dd9..1ed3f69 100644
--- a/ambari-web/app/controllers/wizard/step2_controller.js
+++ b/ambari-web/app/controllers/wizard/step2_controller.js
@@ -318,36 +318,65 @@ App.WizardStep2Controller = Em.Controller.extend({
    */
   parseHostNamesAsPatternExpression: function () {
     this.set('isPattern', false);
-    var self = this;
     var hostNames = [];
-    $.each(this.get('hostNameArr'), function (e, a) {
-      var start, end, extra = {0: ""};
-      if (/\[\d*\-\d*\]/.test(a)) {
-        start = a.match(/\[\d*/);
-        end = a.match(/\-\d*]/);
 
-        start = start[0].substr(1);
-        end = end[0].substr(1);
+    this.get('hostNameArr').forEach(function (a) {
+      var hn,
+          allPatterns = a.match(/\[\d*\-\d*\]/g),
+          patternsNumber = allPatterns ? allPatterns.length : 0;
+
+      if (patternsNumber) {
+        hn = [a];
+        for (var i = 0; i < patternsNumber; i++) {
+          hn = this._replacePatternInHosts(hn);
+        }
+        hostNames = hostNames.concat(hn);
+      } else {
+        hostNames.push(a);
+      }
+    }, this);
+
+    this.set('hostNameArr', hostNames.uniq());
+  },
+
+  /**
+   * return an array of results with pattern replacement for each host
+   * replace only first pattern in each host
+   * designed to be called recursively in <code>parseHostNamesAsPatternExpression</code>
+   *
+   * @param {Array} rawHostNames
+   * @private
+   * @return {Array}
+   */
+  _replacePatternInHosts: function (rawHostNames) {
+    var start, end, extra, allHostNames = [];
+    rawHostNames.forEach(function (rawHostName) {
+      var hostNames = [];
+      start = rawHostName.match(/\[\d*/);
+      end = rawHostName.match(/\-\d*]/);
+      extra = {0: ""};
 
-        if (parseInt(start) <= parseInt(end, 10) && parseInt(start, 10) >= 0) {
-          self.set('isPattern', true);
+      start = start[0].substr(1);
+      end = end[0].substr(1);
 
-          if (start[0] == "0" && start.length > 1) {
-            extra = start.match(/0*/);
-          }
+      if (parseInt(start) <= parseInt(end, 10) && parseInt(start, 10) >= 0) {
+        this.set('isPattern', true);
 
-          for (var i = parseInt(start, 10); i < parseInt(end, 10) + 1; i++) {
-            hostNames.push(a.replace(/\[\d*\-\d*\]/, extra[0].substring(0, start.length - i.toString().length) + i))
-          }
+        if (start[0] == "0" && start.length > 1) {
+          extra = start.match(/0*/);
+        }
 
-        } else {
-          hostNames.push(a);
+        for (var i = parseInt(start, 10); i < parseInt(end, 10) + 1; i++) {
+          hostNames.push(rawHostName.replace(/\[\d*\-\d*\]/, extra[0].substring(0, start.length - i.toString().length) + i))
         }
+
       } else {
-        hostNames.push(a);
+        hostNames.push(rawHostName);
       }
-    });
-    this.set('hostNameArr', hostNames.uniq());
+      allHostNames = allHostNames.concat(hostNames);
+    }, this);
+
+    return allHostNames;
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/fb8f3485/ambari-web/test/controllers/wizard/step2_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/wizard/step2_test.js b/ambari-web/test/controllers/wizard/step2_test.js
index 63887ab..6e6ad25 100644
--- a/ambari-web/test/controllers/wizard/step2_test.js
+++ b/ambari-web/test/controllers/wizard/step2_test.js
@@ -420,6 +420,26 @@ describe('App.WizardStep2Controller', function () {
       expect(result).to.equal(true);
     });
 
+    it('should parse hosts from multiple pattern expression to hostNameArr', function () {
+      var controller = App.WizardStep2Controller.create({
+        hostNameArr: ['test[1-2]host[01-05]']
+      });
+      controller.parseHostNamesAsPatternExpression();
+      var hosts = controller.get('hostNameArr');
+      expect(hosts).eql([
+          'test1host01',
+          'test1host02',
+          'test1host03',
+          'test1host04',
+          'test1host05',
+          'test2host01',
+          'test2host02',
+          'test2host03',
+          'test2host04',
+          'test2host05'
+      ]);
+    });
+
     it('should skip duplicates', function () {
       var controller = App.WizardStep2Controller.create({
         hostNameArr: ['host[1-3]', 'host2']