cluster_mapper.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. App.clusterMapper = App.QuickDataMapper.create({
  19. model : App.Cluster,
  20. map:function(json){
  21. if(!this.get('model')) {return;}
  22. if(json){
  23. var result = json;
  24. result = this.parseIt(result, this.config);
  25. App.store.load(this.get('model'), result);
  26. var cluster = App.Cluster.find(result.id);
  27. var clusterDesiredConfigs = [];
  28. // Create desired_configs_array
  29. if(json.Clusters.desired_configs){
  30. for(var site in json.Clusters.desired_configs){
  31. var tag = json.Clusters.desired_configs[site].tag;
  32. var configObj = App.ConfigSiteTag.create({
  33. site: site,
  34. tag: tag,
  35. hostOverrides: {}
  36. });
  37. if(json.Clusters.desired_configs[site].host_overrides!=null){
  38. var hostOverridesArray = {};
  39. json.Clusters.desired_configs[site].host_overrides.forEach(function(override){
  40. var hostname = override.host_name;
  41. hostOverridesArray[hostname] = override.tag;
  42. });
  43. configObj.set('hostOverrides', hostOverridesArray);
  44. }
  45. clusterDesiredConfigs.push(configObj);
  46. }
  47. }
  48. cluster.set('desiredConfigs', clusterDesiredConfigs);
  49. }
  50. },
  51. config : {
  52. id:'Clusters.cluster_id',
  53. cluster_name: 'Clusters.cluster_name',
  54. stack_name: 'Clusters.stack_name',
  55. version: 'Clusters.version',
  56. //$hosts: [1, 2, 3, 4],
  57. $racks: [1],
  58. max_hosts_per_rack: 'Clusters.max_hosts_per_rack'
  59. }
  60. });