Browse Source

AMBARI-1215. Refactor hostComponent isSlaves and isMaster and add update methods for server mapper. (yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1435435 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 years ago
parent
commit
46f19b470f

+ 3 - 0
CHANGES.txt

@@ -17,6 +17,9 @@ Trunk (unreleased changes):
 
 
  IMPROVEMENTS
  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.
  AMBARI-1214. In any starts fails, "warn" the host and the overall install.
  (yusaku)
  (yusaku)
 
 

+ 31 - 0
ambari-web/app/mappers/server_data_mapper.js

@@ -17,6 +17,7 @@
  */
  */
 
 
 var App = require('app');
 var App = require('app');
+var stringUtils = require('utils/string_utils');
 
 
 App.ServerDataMapper = Em.Object.extend({
 App.ServerDataMapper = Em.Object.extend({
   jsonKey: false,
   jsonKey: false,
@@ -121,5 +122,35 @@ App.QuickDataMapper = App.ServerDataMapper.extend({
     }
     }
 
 
     return json;
     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));
+    });
   }
   }
 });
 });

+ 0 - 2
ambari-web/app/models/host_component.js

@@ -55,7 +55,6 @@ App.HostComponent = DS.Model.extend({
       default:
       default:
         return false;
         return false;
     }
     }
-    return this.get('componentName');
   }.property('componentName'),
   }.property('componentName'),
   isSlave: function(){
   isSlave: function(){
     switch (this.get('componentName')) {
     switch (this.get('componentName')) {
@@ -67,7 +66,6 @@ App.HostComponent = DS.Model.extend({
       default:
       default:
         return false;
         return false;
     }
     }
-    return this.get('componentName');
   }.property('componentName'),
   }.property('componentName'),
   /**
   /**
    * A host-component is decommissioning when it is in HDFS service's list of
    * A host-component is decommissioning when it is in HDFS service's list of

+ 6 - 8
ambari-web/app/utils/string_utils.js

@@ -52,14 +52,12 @@ module.exports = {
     return str;
     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;
   }
   }
 }
 }