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 2015/08/17 14:01:26 UTC
[1/2] ambari git commit: AMBARI-12785. App.componentConfigMapper
takes too much time (onechiporenko)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1 6fcd95fe3 -> 9a5144252
AMBARI-12785. App.componentConfigMapper takes too much time (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/99f0af61
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/99f0af61
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/99f0af61
Branch: refs/heads/branch-2.1
Commit: 99f0af61397f7cd11b47d51f377da7d70ae79389
Parents: 6fcd95f
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Mon Aug 17 14:40:58 2015 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Mon Aug 17 14:40:58 2015 +0300
----------------------------------------------------------------------
.../app/controllers/global/update_controller.js | 2 +-
.../app/mappers/component_config_mapper.js | 6 +--
.../configs/stack_config_properties_mapper.js | 4 +-
ambari-web/app/mappers/server_data_mapper.js | 37 +++++++++++++++
.../test/mappers/server_data_mapper_test.js | 49 ++++++++++++++++++--
5 files changed, 88 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/99f0af61/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 34dcde1..23d9ff2 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -493,7 +493,7 @@ App.UpdateController = Em.Controller.extend({
},
updateComponentConfig: function (callback) {
var testUrl = '/data/services/host_component_stale_configs.json';
- var componentConfigUrl = this.getUrl(testUrl, '/components?ServiceComponentInfo/category.in(SLAVE,CLIENT)&host_components/HostRoles/stale_configs=true&fields=host_components/HostRoles/service_name,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,host_components/HostRoles/host_name,host_components/HostRoles/stale_configs,host_components/HostRoles/desired_admin_state&minimal_response=true');
+ var componentConfigUrl = this.getUrl(testUrl, '/components?host_components/HostRoles/stale_configs=true&fields=host_components/HostRoles/service_name,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,host_components/HostRoles/host_name,host_components/HostRoles/stale_configs,host_components/HostRoles/desired_admin_state&minimal_response=true');
App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
complete: callback
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/99f0af61/ambari-web/app/mappers/component_config_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/component_config_mapper.js b/ambari-web/app/mappers/component_config_mapper.js
index 50b537f..8ff3416 100644
--- a/ambari-web/app/mappers/component_config_mapper.js
+++ b/ambari-web/app/mappers/component_config_mapper.js
@@ -57,13 +57,11 @@ App.componentConfigMapper = App.QuickDataMapper.create({
var currentStaleConfigsState = Boolean(hostComponentJson);
var stateChanged = hostComponent.get('staleConfigs') !== currentStaleConfigsState;
- if (stateChanged && !hostComponent.get('isMaster')) {
+ if (stateChanged) {
hostComponent.set('staleConfigs', currentStaleConfigsState);
}
//delete loaded host-components, so only new ones left
- if (hostComponent.get('service.hostComponents').someProperty('id', id)) {
- delete hostComponentJsonMap[id];
- }
+ delete hostComponentJsonMap[id];
});
hostComponentJsonIds.forEach(function (hcId) {
var newHostComponent = hostComponentJsonMap[hcId];
http://git-wip-us.apache.org/repos/asf/ambari/blob/99f0af61/ambari-web/app/mappers/configs/stack_config_properties_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/configs/stack_config_properties_mapper.js b/ambari-web/app/mappers/configs/stack_config_properties_mapper.js
index 3c11fa1..29507df 100644
--- a/ambari-web/app/mappers/configs/stack_config_properties_mapper.js
+++ b/ambari-web/app/mappers/configs/stack_config_properties_mapper.js
@@ -45,7 +45,7 @@ App.stackConfigPropertiesMapper = App.QuickDataMapper.create({
},
map: function (json) {
- console.time('stackConfigPropertiesMapper execution time');
+ console.time('App.stackConfigPropertiesMapper execution time');
if (json && json.Versions) {
//hack for cluster versions
json = {items: [json]};
@@ -99,7 +99,7 @@ App.stackConfigPropertiesMapper = App.QuickDataMapper.create({
}, this);
App.store.loadMany(this.get('model'), configs);
}
- console.timeEnd('stackConfigPropertiesMapper execution time');
+ console.timeEnd('App.stackConfigPropertiesMapper execution time');
},
/******************* METHODS TO MERGE STACK PROPERTIES WITH STORED ON UI *********************************/
http://git-wip-us.apache.org/repos/asf/ambari/blob/99f0af61/ambari-web/app/mappers/server_data_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/server_data_mapper.js b/ambari-web/app/mappers/server_data_mapper.js
index a87cf78..99fd80f 100644
--- a/ambari-web/app/mappers/server_data_mapper.js
+++ b/ambari-web/app/mappers/server_data_mapper.js
@@ -159,5 +159,42 @@ App.QuickDataMapper = App.ServerDataMapper.extend({
return result;
}
return current;
+ },
+
+ /**
+ * Binary search <code>searchElement</code> in the array (should be sorted!)
+ * @param {number[]|string[]} array
+ * @param {number|string} searchElement
+ * @returns {number} position of the needed element or negative value, if value wasn't found
+ * @method binaryIndexOf
+ */
+ binaryIndexOf: function (array, searchElement) {
+ var minIndex = 0;
+ var maxIndex = array.length - 1;
+ var currentIndex;
+ var currentElement;
+ var resultIndex;
+
+ if (array[0] > searchElement || array[array.length - 1] < searchElement) {
+ return -1;
+ }
+ while (minIndex <= maxIndex) {
+ resultIndex = currentIndex = (minIndex + maxIndex) / 2 | 0;
+ currentElement = array[currentIndex];
+
+ if (currentElement < searchElement) {
+ minIndex = currentIndex + 1;
+ }
+ else
+ if (currentElement > searchElement) {
+ maxIndex = currentIndex - 1;
+ }
+ else {
+ return currentIndex;
+ }
+ }
+
+ return ~maxIndex;
}
+
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/99f0af61/ambari-web/test/mappers/server_data_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/server_data_mapper_test.js b/ambari-web/test/mappers/server_data_mapper_test.js
index da873d5..9c4adbb 100644
--- a/ambari-web/test/mappers/server_data_mapper_test.js
+++ b/ambari-web/test/mappers/server_data_mapper_test.js
@@ -18,6 +18,7 @@
var Ember = require('ember');
var App = require('app');
+var mapper;
require('mappers/server_data_mapper');
@@ -47,6 +48,10 @@ describe('App.QuickDataMapper', function () {
}
};
+ beforeEach(function () {
+ mapper = App.QuickDataMapper.create();
+ });
+
describe('#getJsonProperty', function() {
var tests = [
{i:'a1.b1.c1',e:'val1'},
@@ -57,7 +62,6 @@ describe('App.QuickDataMapper', function () {
];
tests.forEach(function(test) {
it(test.i, function() {
- var mapper = App.QuickDataMapper.create();
expect(mapper.getJsonProperty(test_json, test.i)).to.equal(test.e);
});
});
@@ -75,8 +79,12 @@ describe('App.QuickDataMapper', function () {
item: 'c2'
}
};
- var mapper = App.QuickDataMapper.create();
- var result = mapper.parseIt(test_json, config);
+ var result;
+
+ beforeEach(function () {
+ result = mapper.parseIt(test_json, config);
+ });
+
it('Property starts with $', function() {
expect(result.a2).to.equal('a2');
});
@@ -94,4 +102,39 @@ describe('App.QuickDataMapper', function () {
});
});
+ describe('#binaryIndexOf', function () {
+
+ var array1 = [1,2,3,4,5,6,7,8,9];
+ var array2 = ['b','c','d','e','f','g'];
+
+ array1.forEach(function(item, index) {
+ it('numeric array. test ' + (index + 1), function () {
+ expect(mapper.binaryIndexOf(array1, item)).to.equal(index);
+ });
+ });
+
+ it('numeric array. element doesn\'t exists', function () {
+ expect(mapper.binaryIndexOf(array1, 0) < 0).to.be.true;
+ });
+
+ it('numeric array. element doesn\'t exists 2', function () {
+ expect(mapper.binaryIndexOf(array1, 10) < 0).to.be.true;
+ });
+
+ array2.forEach(function(item, index) {
+ it('string array. test ' + (index + 1), function () {
+ expect(mapper.binaryIndexOf(array2, item)).to.equal(index);
+ });
+ });
+
+ it('string array. element doesn\'t exists', function () {
+ expect(mapper.binaryIndexOf(array2, 'a') < 0).to.be.true;
+ });
+
+ it('string array. element doesn\'t exists 2', function () {
+ expect(mapper.binaryIndexOf(array2, 'q') < 0).to.be.true;
+ });
+
+ });
+
});
[2/2] ambari git commit: AMBARI-12786. App.alertGroupsMapper
shouldn't commit not changed data (onechiporenko)
Posted by on...@apache.org.
AMBARI-12786. App.alertGroupsMapper shouldn't commit not changed data (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9a514425
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9a514425
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9a514425
Branch: refs/heads/branch-2.1
Commit: 9a51442520d93c393e6503ad85d8ee9e210e0576
Parents: 99f0af6
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Mon Aug 17 14:49:01 2015 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Mon Aug 17 14:49:01 2015 +0300
----------------------------------------------------------------------
ambari-web/app/mappers/alert_groups_mapper.js | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9a514425/ambari-web/app/mappers/alert_groups_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_groups_mapper.js b/ambari-web/app/mappers/alert_groups_mapper.js
index 50a8ea5..fffbd2c 100644
--- a/ambari-web/app/mappers/alert_groups_mapper.js
+++ b/ambari-web/app/mappers/alert_groups_mapper.js
@@ -20,6 +20,7 @@ var App = require('app');
/**
* Mapper for <code>App.AlertGroup</code>
* Save general information
+ * Doesn't save not changed data (check it using <code>App.cache['previousAlertGroupsFullMap']</code>)
* Use <code>App.cache['previousAlertGroupsMap']</code> to store map alertDefinitions-alertGroups. This map is used
* in the <code>App.AlertDefinitionsMapper</code> to correctly link alertDefinitions and alertGroups
*/
@@ -39,10 +40,14 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
},
map: function (json) {
+ if(Em.isNone(App.cache['previousAlertGroupsFullMap'])) {
+ App.cache['previousAlertGroupsFullMap'] = {};
+ }
if (!Em.isNone(json, 'items')) {
-
+ console.time('App.alertGroupsMapper execution time');
var alertGroups = [],
self = this,
+ groupsMap = {},
groupsToDelete = App.AlertGroup.find().mapProperty('id'),
/**
* AlertGroups-map for <code>App.AlertDefinitionsMappers</code>
@@ -65,7 +70,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
group.targets = [];
group.definitions = [];
if (item.AlertGroup.definitions) {
- item.AlertGroup.definitions.forEach(function(definition) {
+ item.AlertGroup.definitions.forEach(function (definition) {
if (!group.definitions.contains(definition.id)) {
group.definitions.push(definition.id);
}
@@ -76,7 +81,7 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
});
}
if (item.AlertGroup.targets) {
- item.AlertGroup.targets.forEach(function(target) {
+ item.AlertGroup.targets.forEach(function (target) {
if (!group.targets.contains(target.id)) {
group.targets.push(target.id);
}
@@ -86,7 +91,14 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
alertNotificationsGroupsMap[target.id].push(group.id);
});
}
- alertGroups.push(group);
+
+ groupsMap[group.id] = group;
+ var previousGroup = App.cache['previousAlertGroupsFullMap'][group.id] ? App.cache['previousAlertGroupsFullMap'][group.id] : {};
+ var changedFields = self.getDiscrepancies(group, previousGroup, ['name', 'description', 'default', 'targets', 'definitions']);
+ if (Object.keys(changedFields).length) {
+ alertGroups.push(group);
+ }
+
}, this);
groupsToDelete.forEach(function(groupId) {
@@ -94,9 +106,11 @@ App.alertGroupsMapper = App.QuickDataMapper.create({
});
App.cache['previousAlertGroupsMap'] = alertDefinitionsGroupsMap;
+ App.cache['previousAlertGroupsFullMap'] = groupsMap;
App.cache['alertNotificationsGroupsMap'] = alertNotificationsGroupsMap;
App.store.loadMany(this.get('model'), alertGroups);
App.store.commit();
+ console.timeEnd('App.alertGroupsMapper execution time');
}
}
});