You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rz...@apache.org on 2016/02/27 02:18:15 UTC
ambari git commit: AMBARI-15210. Combo Search: Implement "component
state" related filters (rzang)
Repository: ambari
Updated Branches:
refs/heads/trunk 27710808b -> 11137ea88
AMBARI-15210. Combo Search: Implement "component state" related filters (rzang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/11137ea8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/11137ea8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/11137ea8
Branch: refs/heads/trunk
Commit: 11137ea88607dae63c3bf330c298d19df57cc890
Parents: 2771080
Author: Richard Zang <rz...@apache.org>
Authored: Fri Feb 26 17:17:04 2016 -0800
Committer: Richard Zang <rz...@apache.org>
Committed: Fri Feb 26 17:17:33 2016 -0800
----------------------------------------------------------------------
.../app/controllers/global/update_controller.js | 3 +
ambari-web/app/controllers/main/host.js | 6 ++
.../controllers/main/host/combo_search_box.js | 90 +++++++++++++++++---
.../mixins/common/table_server_view_mixin.js | 13 +--
.../app/views/main/host/combo_search_box.js | 37 +++++---
5 files changed, 121 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/11137ea8/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 ebefd0f..72b3ca2 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -158,6 +158,9 @@ App.UpdateController = Em.Controller.extend({
}, this);
params += customKey;
break;
+ case 'COMBO':
+ params += App.router.get('mainHostComboSearchBoxController').generateQueryParam(param);
+ break;
}
params += '&';
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/11137ea8/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 dac005b..b7f6208 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -146,6 +146,11 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
name: 'hostStackVersion',
key: 'stack_versions',
type: 'EQUAL'
+ },
+ {
+ name: 'componentState',
+ key: '(host_components/HostRoles/component_name={0}&host_components/HostRoles/state={1})',
+ type: 'COMBO'
}
],
@@ -564,6 +569,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
associations[12] = 'rack';
associations[13] = 'services';
associations[14] = 'state';
+ associations[15] = 'componentState';
return associations;
}.property()
http://git-wip-us.apache.org/repos/asf/ambari/blob/11137ea8/ambari-web/app/controllers/main/host/combo_search_box.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host/combo_search_box.js b/ambari-web/app/controllers/main/host/combo_search_box.js
index 3cbb602..339ddc9 100644
--- a/ambari-web/app/controllers/main/host/combo_search_box.js
+++ b/ambari-web/app/controllers/main/host/combo_search_box.js
@@ -22,18 +22,6 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
name: 'mainHostComboSearchBoxController',
currentSuggestion: [],
page_size: 10,
- nameColumnMap: {
- 'Host Name': 'hostName',
- 'IP': 'ip',
- 'Health Status': 'hostName',
- 'Host Name': 'healthClass',
- 'Rack': 'rack',
- 'Cores': 'cpu',
- 'RAM': 'memoryFormatted',
- 'Service': 'service',
- 'Has Component': 'hostComponents',
- 'State': 'state'
- },
getPropertySuggestions: function(facet, searchTerm) {
return App.ajax.send({
name: 'hosts.with_searchTerm',
@@ -61,5 +49,83 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
commonSuggestionErrorCallback:function() {
// handle suggestion error
+ },
+
+ isComponentStateFacet: function(facet) {
+ return App.HostComponent.find().filterProperty('componentName', facet).length > 0;
+ },
+
+ isClientComponent: function(name) {
+ return name.indexOf('CLIENT') >= 0;
+ },
+
+ generateQueryParam: function(param) {
+ var expression = param.key;
+ var filterName = App.router.get('mainHostController.filterProperties').findProperty('key', expression).name;
+ if (filterName == 'componentState') {
+ var pHash = this.createComboParamHash(param);
+ return this.createComboParamURL(pHash, expression);
+ }
+ },
+
+ /**
+ * @param pHash {k1:v1, k2:[v1,v2], ...}
+ * @param expression
+ * @returns {string} 'k1=v1&(k2=v1|k2=v2)'
+ */
+ createComboParamURL: function(pHash, expression) {
+ var result = '';
+ for (key in pHash) {
+ var v = pHash[key];
+ if (Em.isArray(v)) {
+ var ex = '(';
+ v.forEach(function(item) {
+ var toAdd = expression.replace('{0}', key);
+ toAdd = toAdd.replace('{1}', item);
+ ex += toAdd + '|';
+ });
+ ex = ex.substring(0, ex.length - 1);
+ result += ex + ')';
+ } else {
+ var ex = expression.replace('{0}', key);
+ ex = ex.replace('{1}', v);
+ result += ex;
+ }
+ result += '&';
+ }
+
+ return result.substring(0, result.length - 1);
+ },
+
+ /**
+ * @param param ['k1:v1','k2:v1', 'k2:v2'] or 'k1:v1'
+ * @returns {k1:v1, k2:[v1,v2], ...}
+ */
+ createComboParamHash: function(param) {
+ var pHash = {};
+ if (Em.isArray(param.value)) {
+ param.value.forEach(function(item) {
+ var values = item.split(':');
+ var k = values[0];
+ var v = values[1];
+ if (v == 'STOPPED') { v = 'INSTALLED'; } // 'STOPPED' is not a valid internal state
+ if (!pHash[k]) {
+ pHash[k] = v;
+ } else {
+ if (Em.isArray(pHash[k])) {
+ if (pHash[k].indexOf(v) == -1) {
+ pHash[k].push(v);
+ }
+ } else {
+ pHash[k] = [pHash[k], v];
+ }
+ }
+ });
+ } else {
+ var values = param.value.split(':');
+ if (values[1] == 'STOPPED') { values[1] = 'INSTALLED'; }
+ pHash[values[0]] = values[1];
+ }
+ return pHash;
}
});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/11137ea8/ambari-web/app/mixins/common/table_server_view_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/table_server_view_mixin.js b/ambari-web/app/mixins/common/table_server_view_mixin.js
index 0f84633..b126efa 100644
--- a/ambari-web/app/mixins/common/table_server_view_mixin.js
+++ b/ambari-web/app/mixins/common/table_server_view_mixin.js
@@ -89,25 +89,28 @@ App.TableServerViewMixin = Em.Mixin.create({
updateComboFilter: function(searchCollection) {
var self = this;
+ var comboController = App.router.get('mainHostComboSearchBoxController');
clearTimeout(this.get('timeOut'));
this.set('controller.resetStartIndex', true);
this.set('filterConditions', []);
this.clearFilterConditionsFromLocalStorage();
searchCollection.models.forEach(function (model) {
var tag = model.attributes;
- var iColumn = App.router.get('mainHostController').get('colPropAssoc').indexOf(tag.category);
+ var isComponentState = comboController.isComponentStateFacet(tag.category);
+ var iColumn = App.router.get('mainHostController').get('colPropAssoc').indexOf(isComponentState? 'componentState' : tag.category);
var filterCondition = self.get('filterConditions').findProperty('iColumn', iColumn);
+ var filterValue = isComponentState? (tag.category + ':' + tag.value) : tag.value;
if (filterCondition) {
if (typeof filterCondition.value == 'string') {
- filterCondition.value = [filterCondition.value, tag.value];
- } else if (Em.isArray(filterCondition.value) && filterCondition.value.indexOf(tag.value) == -1) {
- filterCondition.value.push(tag.value);
+ filterCondition.value = [filterCondition.value, filterValue];
+ } else if (Em.isArray(filterCondition.value) && filterCondition.value.indexOf(filterValue) == -1) {
+ filterCondition.value.push(filterValue);
}
} else {
filterCondition = {
skipFilter: false,
iColumn: iColumn,
- value: tag.value,
+ value: filterValue,
type: 'string'
};
self.get('filterConditions').push(filterCondition);
http://git-wip-us.apache.org/repos/asf/ambari/blob/11137ea8/ambari-web/app/views/main/host/combo_search_box.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/combo_search_box.js b/ambari-web/app/views/main/host/combo_search_box.js
index 73dd347..b52d91f 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -37,26 +37,39 @@ App.MainHostComboSearchBoxView = Em.View.extend({
],
callbacks: {
search: function (query, searchCollection) {
- console.error('query: ' + query);
var tableView = self.get('parentView').get('parentView');
tableView.updateComboFilter(searchCollection);
},
facetMatches: function (callback) {
- callback([
- {label: 'hostName', category: 'Host'},
- {label: 'ip', category: 'Host'},
- // {label: 'version', category: 'Host'},
- {label: 'healthClass', category: 'Host'},
- {label: 'rack', category: 'Host'},
- {label: 'services', category: 'Service'},
- {label: 'hostComponents', category: 'Service'},
- // {label: 'state', category: 'Service'}
- ]);
+ var list = [
+ {label: 'Host Name', value: 'hostName', category: 'Host'},
+ {label: 'IP', value: 'ip', category: 'Host'},
+ {label: 'Heath Status', value: 'healthClass', category: 'Host'},
+ {label: 'Rack', value: 'rack', category: 'Host'},
+ {label: 'Service', value: 'services', category: 'Service'},
+ {label: 'Has Component', value: 'hostComponents', category: 'Service'},
+ ];
+ var hostComponentHash = {};
+ App.HostComponent.find().toArray().forEach(function(component) {
+ hostComponentHash[component.get('displayName')] = component;
+ });
+ for (key in hostComponentHash) {
+ var name = hostComponentHash[key].get('componentName');
+ var displayName = hostComponentHash[key].get('displayName');
+ if (displayName != null && !controller.isClientComponent(name)) {
+ list.push({label: displayName, value: name, category: 'Component'});
+ }
+ }
+ // Append host components
+ callback(list, {preserveOrder: true});
},
valueMatches: function (facet, searchTerm, callback) {
var category_mocks = require('data/host/categories');
+ if (controller.isComponentStateFacet(facet)) {
+ facet = 'componentState'
+ }
switch (facet) {
case 'hostName':
case 'ip':
@@ -83,6 +96,8 @@ App.MainHostComboSearchBoxView = Em.View.extend({
case 'state':
callback(App.HostComponentStatus.getStatusesList(), {preserveOrder: true});
break;
+ case 'componentState':
+ callback(['STARTED', 'STOPPED'], {preserveOrder: true});
}
}
}