You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2014/06/17 16:48:40 UTC
git commit: AMBARI-6162. Behavior change: host filtering no longer
handles startsWith matches. (Buzhor Denys via onechiporenko)
Repository: ambari
Updated Branches:
refs/heads/trunk 20340ef3f -> 9bc9ed055
AMBARI-6162. Behavior change: host filtering no longer handles startsWith matches. (Buzhor Denys via onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9bc9ed05
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9bc9ed05
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9bc9ed05
Branch: refs/heads/trunk
Commit: 9bc9ed055f49d7a4a8de9ca11a0c677c1262ad0d
Parents: 20340ef
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Tue Jun 17 17:44:37 2014 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Tue Jun 17 17:44:37 2014 +0300
----------------------------------------------------------------------
ambari-web/app/controllers/main/host.js | 17 +++++++++++--
ambari-web/app/utils/validator.js | 13 +++++++++-
ambari-web/test/controllers/main/host_test.js | 29 ++++++++++++++++++++++
ambari-web/test/utils/validator_test.js | 24 +++++++++++++++++-
4 files changed, 79 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9bc9ed05/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 68b7ba2..d881858 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -202,6 +202,18 @@ App.MainHostController = Em.ArrayController.extend({
],
/**
+ * Validate and convert input string to valid url parameter.
+ * Detect if user have passed string as regular expression or extend
+ * string to regexp.
+ *
+ * @params {String} value
+ * @return {String}
+ **/
+ getRegExp: function (value) {
+ return validator.isValidMatchesRegexp(value) ? value.replace(/(\.+\*?|(\.\*)+)$/, '') + '.*' : '^$';
+ },
+
+ /**
* get query parameters computed from filter properties, sort properties and custom properties of view
* @return {Array}
*/
@@ -220,7 +232,6 @@ App.MainHostController = Em.ArrayController.extend({
type: 'EQUAL'
})
}, this);
-
savedFilterConditions.forEach(function (filter) {
var property = filterProperties.findProperty('key', colPropAssoc[filter.iColumn]);
if (property && filter.value.length > 0 && !filter.skipFilter) {
@@ -229,6 +240,9 @@ App.MainHostController = Em.ArrayController.extend({
value: filter.value,
type: property.type
};
+ if (filter.type === 'string') {
+ result.value = this.getRegExp(filter.value);
+ }
if (filter.type === 'number' || filter.type === 'ambari-bandwidth') {
result.type = this.getComparisonType(filter.value);
result.value = this.getProperValue(filter.value);
@@ -241,7 +255,6 @@ App.MainHostController = Em.ArrayController.extend({
}
}
}, this);
-
savedSortConditions.forEach(function (sort) {
var property = sortProperties.findProperty('key', sort.name);
http://git-wip-us.apache.org/repos/asf/ambari/blob/9bc9ed05/ambari-web/app/utils/validator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/validator.js b/ambari-web/app/utils/validator.js
index e59532f..602a377 100644
--- a/ambari-web/app/utils/validator.js
+++ b/ambari-web/app/utils/validator.js
@@ -143,5 +143,16 @@ module.exports = {
default :
return false;
}
-}
+ },
+ /**
+ * Validate string that will pass as parameter to .matches() url param.
+ * For example: /api/v1/clusters/c1/hosts?Hosts/host_name.matches(.*localhost.)
+ *
+ * @params {String} value - string to validate
+ * @return {Boolean}
+ * @method isValidMatchesRegexp
+ */
+ isValidMatchesRegexp: function(value) {
+ return /^((\.\*?)?([\w]+)?)+(\.\*?)?$/g.test(value);
+ }
};
http://git-wip-us.apache.org/repos/asf/ambari/blob/9bc9ed05/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 b491f3b..b425f5f 100644
--- a/ambari-web/test/controllers/main/host_test.js
+++ b/ambari-web/test/controllers/main/host_test.js
@@ -303,4 +303,33 @@ describe('MainHostController', function () {
});
+ describe('#getRegExp()', function() {
+ before(function() {
+ hostController = App.MainHostController.create({});
+ });
+
+ var message = '`{0}` should convert to `{1}`',
+ tests = [
+ { value: '.*', expected: '.*' },
+ { value: '.', expected: '.*' },
+ { value: '.*.*', expected: '.*' },
+ { 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.*' }
+ ]
+
+ tests.forEach(function(test){
+ it(message.format(test.value, test.expected), function() {
+ expect(hostController.getRegExp(test.value)).to.be.equal(test.expected);
+ });
+ });
+ });
+
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/9bc9ed05/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 262c068..65c8769 100644
--- a/ambari-web/test/utils/validator_test.js
+++ b/ambari-web/test/utils/validator_test.js
@@ -331,5 +331,27 @@ describe('validator', function () {
expect(validator.isValidConfigKey(test.i)).to.equal(test.e);
})
});
- })
+ });
+
+ describe('#isValidMatchesRegexp()', function() {
+ var message = '`{0}` should be {1}',
+ tests = [
+ { value: '.*', expected: true },
+ { value: '..', expected: true },
+ { value: '.a1', expected: true },
+ { value: '.*a1', expected: true },
+ { value: '.*a1.*', expected: true },
+ { value: '.*a1.a2', expected: true },
+ { value: '.*a1.*.a2', expected: true },
+ { value: '.*a1.*.a2.*.a3.a4.*.*', expected: true },
+ { value: '*', expected: false },
+ { value: '1>1', expected: false },
+ { value: '.*a1,*', expected: false }
+ ];
+ tests.forEach(function(test) {
+ it(message.format(test.value, (test.expected) ? 'valid' : 'not valid'), function() {
+ expect(validator.isValidMatchesRegexp(test.value)).to.equal(test.expected);
+ })
+ });
+ });
});