Author: yusaku
Date: Sat Jan 19 01:05:09 2013
New Revision: 1435435
URL: http://svn.apache.org/viewvc?rev=1435435&view=rev
Log:
AMBARI-1215. Refactor hostComponent isSlaves and isMaster and add update
methods for server mapper. (yusaku)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-web/app/mappers/server_data_mapper.js
incubator/ambari/trunk/ambari-web/app/models/host_component.js
incubator/ambari/trunk/ambari-web/app/utils/string_utils.js
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1435435&r1=1435434&r2=1435435&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Sat Jan 19 01:05:09 2013
@@ -17,6 +17,9 @@ Trunk (unreleased changes):
IMPROVEMENTS
+ AMBARI-1215. Refactor hostComponent isSlaves and isMaster and add update
+ methods for server mapper. (yusaku)
+
AMBARI-1214. In any starts fails, "warn" the host and the overall install.
(yusaku)
Modified: incubator/ambari/trunk/ambari-web/app/mappers/server_data_mapper.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/mappers/server_data_mapper.js?rev=1435435&r1=1435434&r2=1435435&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/mappers/server_data_mapper.js
(original)
+++ incubator/ambari/trunk/ambari-web/app/mappers/server_data_mapper.js Sat Jan
19 01:05:09 2013
@@ -17,6 +17,7 @@
*/
var App = require('app');
+var stringUtils = require('utils/string_utils');
App.ServerDataMapper = Em.Object.extend({
jsonKey: false,
@@ -121,5 +122,35 @@ App.QuickDataMapper = App.ServerDataMapp
}
return json;
+ },
+ /**
+ * update fields in record
+ * @param record
+ * @param json
+ * @param fieldsNotUpdate
+ */
+ updateRecord: function (record, json, fieldsNotUpdate) {
+ for (var field in json) {
+ if (json[field] !== undefined && !fieldsNotUpdate.contains(field)) {
+ if(json[field] instanceof Array){
+ this.updateHasMany(record, stringUtils.underScoreToCamelCase(field),
json[field]);
+ } else {
+ record.set(stringUtils.underScoreToCamelCase(field), json[field]);
+ }
+ }
+ }
+ },
+ /**
+ * update fields with hasMany type
+ * @param record
+ * @param field
+ * @param items
+ */
+ updateHasMany: function(record, field, items ){
+ var hasMany = record.get(field);
+ hasMany.clear();
+ items.forEach(function (item) {
+ hasMany.pushObject(hasMany.type.find(item));
+ });
}
});
Modified: incubator/ambari/trunk/ambari-web/app/models/host_component.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/models/host_component.js?rev=1435435&r1=1435434&r2=1435435&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/models/host_component.js (original)
+++ incubator/ambari/trunk/ambari-web/app/models/host_component.js Sat Jan 19
01:05:09 2013
@@ -55,7 +55,6 @@ App.HostComponent = DS.Model.extend({
default:
return false;
}
- return this.get('componentName');
}.property('componentName'),
isSlave: function(){
switch (this.get('componentName')) {
@@ -67,7 +66,6 @@ App.HostComponent = DS.Model.extend({
default:
return false;
}
- return this.get('componentName');
}.property('componentName'),
/**
* A host-component is decommissioning when it is in HDFS service's list of
Modified: incubator/ambari/trunk/ambari-web/app/utils/string_utils.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/utils/string_utils.js?rev=1435435&r1=1435434&r2=1435435&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/utils/string_utils.js (original)
+++ incubator/ambari/trunk/ambari-web/app/utils/string_utils.js Sat Jan 19
01:05:09 2013
@@ -52,14 +52,12 @@ module.exports = {
return str;
},
- underScoreToCamelCase: function(string){
- var result = string.split('');
- for(var i = 0; i < result.length; i++){
- if(result[i] === '_'){
- result[i] = result[i+1].toUpperCase();
- result.splice(i+1,1);
- }
+ underScoreToCamelCase: function(name){
+ var new_name = name.replace(/_\w/g,replacer);
+ function replacer(str, p1, p2, offset, s)
+ {
+ return str[1].toUpperCase();
}
- return result.join('');
+ return new_name;
}
}