Repository: ambari
Updated Branches:
  refs/heads/trunk da428c652 -> 12dd8bd51


AMBARI-6162. Behavior change: host filtering no longer handles startsWith 
matches. additional patch (Buzhor Denys via alexantonenko)


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

Branch: refs/heads/trunk
Commit: 12dd8bd51f1841aa049e54ff64baed7fff781250
Parents: da428c6
Author: Alex Antonenko <hiv...@gmail.com>
Authored: Thu Jun 19 22:11:12 2014 +0300
Committer: Alex Antonenko <hiv...@gmail.com>
Committed: Thu Jun 19 22:11:12 2014 +0300

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js      |  5 +++--
 ambari-web/app/controllers/main/host.js              |  4 +++-
 ambari-web/app/mixins/common/tableServerProvider.js  |  7 +++++++
 ambari-web/app/utils/validator.js                    | 15 ++++++++++++++-
 ambari-web/app/views/main/host.js                    |  7 +++++++
 ambari-web/test/controllers/main/host_test.js        | 15 +++++++--------
 ambari-web/test/utils/validator_test.js              | 12 +++++++++++-
 7 files changed, 52 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js 
b/ambari-web/app/controllers/global/update_controller.js
index bfd0822..f8288ac 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -155,7 +155,7 @@ App.UpdateController = Em.Controller.extend({
     }
   },
 
-  updateHost: function (callback) {
+  updateHost: function (callback, error) {
     var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : 
'/data/hosts/hosts.json';
     var realUrl = 
'/hosts?<parameters>fields=Hosts/host_name,Hosts/maintenance_state,Hosts/public_host_name,Hosts/cpu_count,Hosts/ph_cpu_count,Hosts/total_mem,'
 +
         
'Hosts/host_status,Hosts/last_heartbeat_time,Hosts/os_arch,Hosts/os_type,Hosts/ip,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,'
 +
@@ -165,7 +165,8 @@ App.UpdateController = Em.Controller.extend({
     this.get('queryParams').set('Hosts', 
App.router.get('mainHostController').getQueryParameters());
     var hostsUrl = this.getComplexUrl(testUrl, realUrl, 
this.get('queryParams.Hosts'));
     App.HttpClient.get(hostsUrl, App.hostsMapper, {
-      complete: callback
+      complete: callback,
+      error: error
     });
   },
   graphs: [],

http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/app/controllers/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host.js 
b/ambari-web/app/controllers/main/host.js
index f6ab34e..11bffd1 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -210,7 +210,9 @@ App.MainHostController = Em.ArrayController.extend({
    * @return {String}
    **/
   getRegExp: function (value) {
-    return validator.isValidMatchesRegexp(value) ? 
value.replace(/(\.+\*?|(\.\*)+)$/, '') + '.*' : '^$';
+    value = validator.isValidMatchesRegexp(value) ? 
value.replace(/(\.+\*?|(\.\*)+)$/, '') + '.*' : '^$';
+    value = /^\.\*/.test(value) || value == '^$' ? value : '.*' + value;
+    return value;
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/app/mixins/common/tableServerProvider.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/tableServerProvider.js 
b/ambari-web/app/mixins/common/tableServerProvider.js
index 07a8918..3315011 100644
--- a/ambari-web/app/mixins/common/tableServerProvider.js
+++ b/ambari-web/app/mixins/common/tableServerProvider.js
@@ -28,6 +28,11 @@ App.TableServerProvider = Em.Mixin.create({
    * total number of entities in table
    */
   totalCount: 0,
+  /**
+   * Request error data
+   *
+   */
+  requestError: null,
 
   filteredContent: function () {
     return this.get('content');
@@ -50,6 +55,8 @@ App.TableServerProvider = Em.Mixin.create({
     
this.get('updater')[this.get('updater.tableUpdaterMap')[this.get('tableName')]](function
 () {
       self.set('filteringComplete', true);
       self.propertyDidChange('pageContent');
+    }, function() {
+      self.set('requestError', arguments);
     });
     return true;
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/app/utils/validator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/validator.js 
b/ambari-web/app/utils/validator.js
index 602a377..3c41da2 100644
--- a/ambari-web/app/utils/validator.js
+++ b/ambari-web/app/utils/validator.js
@@ -146,6 +146,7 @@ module.exports = {
   },
   /**
    * Validate string that will pass as parameter to .matches() url param.
+   * Try to prevent invalid regexp.
    * For example: 
/api/v1/clusters/c1/hosts?Hosts/host_name.matches(.*localhost.)
    *
    * @params {String} value - string to validate
@@ -153,6 +154,18 @@ module.exports = {
    * @method isValidMatchesRegexp
    */
   isValidMatchesRegexp: function(value) {
-    return /^((\.\*?)?([\w]+)?)+(\.\*?)?$/g.test(value);
+    var checkPair = function(chars) {
+      chars = chars.map(function(char) { return '\\' + char; });
+      var charsReg = new RegExp(chars.join('|'), 'g');
+      if (charsReg.test(value)) {
+        var pairContentReg = new RegExp(chars.join('.*'), 'g');
+        if (!pairContentReg.test(value)) return false;
+        var pairCounts = chars.map(function(char) { return value.match(new 
RegExp(char, 'g')).length; });
+        if (pairCounts[0] != pairCounts[1] ) return false;
+      }
+      return true;
+    }
+    if (/^[\?\|\*\!,]/.test(value)) return false;
+    return /^((\.\*?)?([\w\[\]\?\-_,\|\*\!\{\}]*)?)+(\.\*?)?$/g.test(value) && 
(checkPair(['[',']'])) && (checkPair(['{','}']));
   }
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/app/views/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host.js 
b/ambari-web/app/views/main/host.js
index 8af2d8f..24608f2 100644
--- a/ambari-web/app/views/main/host.js
+++ b/ambari-web/app/views/main/host.js
@@ -62,6 +62,13 @@ App.MainHostView = 
App.TableView.extend(App.TableServerProvider, {
     return [];
   }.property('controller.content'),
 
+  onRequestErrorHandler: function() {
+    this.set('requestError', null);
+    this.get('controller').get('dataSource').setEach('isRequested', false);
+    this.set('filteringComplete', true);
+    this.propertyDidChange('pageContent');
+  }.observes('requestError'),
+
   /**
    * Contains content to show on the current page of data page view
    * @type {Array}

http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/test/controllers/main/host_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/host_test.js 
b/ambari-web/test/controllers/main/host_test.js
index b425f5f..1734d41 100644
--- a/ambari-web/test/controllers/main/host_test.js
+++ b/ambari-web/test/controllers/main/host_test.js
@@ -303,7 +303,7 @@ describe('MainHostController', function () {
 
   });
 
-  describe('#getRegExp()', function() {
+  describe.only('#getRegExp()', function() {
     before(function() {
       hostController = App.MainHostController.create({});
     });
@@ -316,13 +316,12 @@ describe('MainHostController', function () {
       { value: '*', expected: '^$' },
       { value: '........', expected: '.*' },
       { value: '........*', expected: '.*' },
-      { value: '........?', expected: '^$' },
-      { value: 'a1', expected: 'a1.*' },
-      { value: 'a1.', expected: 'a1.*' },
-      { value: 'a1...', expected: 'a1.*' },
-      { value: 'a1.*', expected: 'a1.*' },
-      { value: 'a1.*.a2.a3', expected: 'a1.*.a2.a3.*' },
-      { value: 'a1.*.a2...a3', expected: 'a1.*.a2...a3.*' }
+      { value: 'a1', expected: '.*a1.*' },
+      { value: 'a1.', expected: '.*a1.*' },
+      { value: 'a1...', expected: '.*a1.*' },
+      { value: 'a1.*', expected: '.*a1.*' },
+      { value: 'a1.*.a2.a3', expected: '.*a1.*.a2.a3.*' },
+      { value: 'a1.*.a2...a3', expected: '.*a1.*.a2...a3.*' }
     ]
 
     tests.forEach(function(test){

http://git-wip-us.apache.org/repos/asf/ambari/blob/12dd8bd5/ambari-web/test/utils/validator_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/validator_test.js 
b/ambari-web/test/utils/validator_test.js
index 65c8769..0ba85b7 100644
--- a/ambari-web/test/utils/validator_test.js
+++ b/ambari-web/test/utils/validator_test.js
@@ -346,7 +346,17 @@ describe('validator', function () {
           { value: '.*a1.*.a2.*.a3.a4.*.*', expected: true },
           { value: '*', expected: false },
           { value: '1>1', expected: false },
-          { value: '.*a1,*', expected: false }
+          { value: '.*a1,*', expected: false },
+          { value: '?a1[1]asd[1]', expected: false },
+          { value: 'a1[1]asd[1]', expected: true },
+          { value: 'a1[1]asd[1][', expected: false },
+          { value: 'a1[1|1]asd[1]', expected: true },
+          { value: 'a1-2!', expected: true },
+          { value: '|a1-2', expected: false },
+          { value: '[a1', expected: false },
+          { value: 'a{1}', expected: true },
+          { value: 'a{1,2}', expected: true },
+          { value: 'a{1,2}{', expected: false }
         ];
     tests.forEach(function(test) {
       it(message.format(test.value, (test.expected) ? 'valid' : 'not valid'), 
function() {

Reply via email to