step3_controller.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. var App = require('app');
  19. App.HighAvailabilityWizardStep3Controller = Em.Controller.extend({
  20. name: "highAvailabilityWizardStep3Controller",
  21. selectedService: null,
  22. stepConfigs: [],
  23. serverConfigData: {},
  24. haConfig: $.extend(true, {}, require('data/HDP2/ha_properties').haConfig),
  25. once: false,
  26. isLoaded: false,
  27. versionLoaded: true,
  28. /**
  29. * Map of sites and properties to delete
  30. * @type Object
  31. */
  32. configsToRemove: {
  33. 'hdfs-site': ['dfs.namenode.secondary.http-address']
  34. },
  35. clearStep: function () {
  36. this.get('stepConfigs').clear();
  37. this.serverConfigData = {};
  38. },
  39. loadStep: function () {
  40. this.clearStep();
  41. this.loadConfigsTags();
  42. },
  43. loadConfigsTags: function () {
  44. App.ajax.send({
  45. name: 'config.tags',
  46. sender: this,
  47. success: 'onLoadConfigsTags',
  48. error: 'onTaskError'
  49. });
  50. },
  51. onLoadConfigsTags: function (data) {
  52. var urlParams = [];
  53. var hdfsSiteTag = data.Clusters.desired_configs['hdfs-site'].tag;
  54. var coreSiteTag = data.Clusters.desired_configs['core-site'].tag;
  55. urlParams.push('(type=hdfs-site&tag=' + hdfsSiteTag + ')');
  56. urlParams.push('(type=core-site&tag=' + coreSiteTag + ')');
  57. this.set("hdfsSiteTag", {name : "hdfsSiteTag", value : hdfsSiteTag});
  58. this.set("coreSiteTag", {name : "coreSiteTag", value : coreSiteTag});
  59. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  60. var hbaseSiteTag = data.Clusters.desired_configs['hbase-site'].tag;
  61. urlParams.push('(type=hbase-site&tag=' + hbaseSiteTag + ')');
  62. this.set("hbaseSiteTag", {name : "hbaseSiteTag", value : hbaseSiteTag});
  63. }
  64. App.ajax.send({
  65. name: 'admin.get.all_configurations',
  66. sender: this,
  67. data: {
  68. urlParams: urlParams.join('|')
  69. },
  70. success: 'onLoadConfigs',
  71. error: 'onTaskError'
  72. });
  73. },
  74. onLoadConfigs: function (data) {
  75. this.set('serverConfigData',data);
  76. this.removeConfigs(this.get('configsToRemove'), this.get('serverConfigData'));
  77. this.tweakServiceConfigs(this.get('haConfig.configs'));
  78. this.renderServiceConfigs(this.get('haConfig'));
  79. this.set('isLoaded', true);
  80. },
  81. tweakServiceConfigs: function(configs) {
  82. var nameServiceId = this.get('content.nameServiceId');
  83. var nameServiceConfig = configs.findProperty('name','dfs.nameservices');
  84. this.setConfigInitialValue(nameServiceConfig,nameServiceId);
  85. var defaultFsConfig = configs.findProperty('name','fs.defaultFS');
  86. this.setConfigInitialValue(defaultFsConfig, "hdfs://" + nameServiceId);
  87. this.tweakServiceConfigNames(configs,nameServiceId);
  88. this.tweakServiceConfigValues(configs,nameServiceId);
  89. },
  90. tweakServiceConfigNames: function(configs,nameServiceId) {
  91. var regex = new RegExp("\\$\\{dfs.nameservices\\}","g");
  92. configs.forEach(function(config) {
  93. if (config.name.contains("${dfs.nameservices}")) {
  94. config.name = config.name.replace(regex,nameServiceId);
  95. config.displayName = config.displayName.replace(regex,nameServiceId);
  96. }
  97. }, this);
  98. },
  99. tweakServiceConfigValues: function(configs,nameServiceId) {
  100. var currentNameNodeHost = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').findProperty('isInstalled', true).hostName;
  101. var newNameNodeHost = this.get('content.masterComponentHosts').filterProperty('component', 'NAMENODE').findProperty('isInstalled', false).hostName;
  102. var journalNodeHosts = this.get('content.masterComponentHosts').filterProperty('component', 'JOURNALNODE').mapProperty('hostName');
  103. var zooKeeperHosts = this.get('content.masterComponentHosts').filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  104. var config = configs.findProperty('name','dfs.namenode.rpc-address.' + nameServiceId + '.nn1');
  105. this.setConfigInitialValue(config,currentNameNodeHost + ':8020');
  106. config = configs.findProperty('name','dfs.namenode.rpc-address.' + nameServiceId + '.nn2');
  107. this.setConfigInitialValue(config,newNameNodeHost + ':8020');
  108. config = configs.findProperty('name','dfs.namenode.http-address.' + nameServiceId + '.nn1');
  109. this.setConfigInitialValue(config,currentNameNodeHost + ':50070');
  110. config = configs.findProperty('name','dfs.namenode.http-address.' + nameServiceId + '.nn2');
  111. this.setConfigInitialValue(config,newNameNodeHost + ':50070');
  112. config = configs.findProperty('name','dfs.namenode.https-address.' + nameServiceId + '.nn1');
  113. this.setConfigInitialValue(config,currentNameNodeHost + ':50470');
  114. config = configs.findProperty('name','dfs.namenode.https-address.' + nameServiceId + '.nn2');
  115. this.setConfigInitialValue(config,newNameNodeHost + ':50470');
  116. config = configs.findProperty('name','dfs.namenode.shared.edits.dir');
  117. this.setConfigInitialValue(config,'qjournal://' + journalNodeHosts[0] + ':8485;' + journalNodeHosts[1] + ':8485;' + journalNodeHosts[2] + ':8485/' + nameServiceId);
  118. config = configs.findProperty('name','ha.zookeeper.quorum');
  119. this.setConfigInitialValue(config,zooKeeperHosts[0] + ':2181,' + zooKeeperHosts[1] + ':2181,' + zooKeeperHosts[2] + ':2181');
  120. config = configs.findProperty('name','hbase.rootdir');
  121. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  122. var value = this.get('serverConfigData.items').findProperty('type', 'hbase-site').properties['hbase.rootdir'].replace(/\/\/[^\/]*/, '//' + nameServiceId);
  123. this.setConfigInitialValue(config,value);
  124. }
  125. config = configs.findProperty('name','dfs.journalnode.edits.dir');
  126. if (App.get('isHadoopWindowsStack') && App.Service.find().someProperty('serviceName', 'HDFS')) {
  127. var value = this.get('serverConfigData.items').findProperty('type', 'hdfs-site').properties['dfs.journalnode.edits.dir'];
  128. this.setConfigInitialValue(config, value);
  129. }
  130. },
  131. /**
  132. * Find and remove config properties in <code>serverConfigData</code>
  133. * @param configsToRemove - map of config sites and properties to remove
  134. * @param configs - configuration object
  135. * @returns {Object}
  136. */
  137. removeConfigs:function (configsToRemove, configs) {
  138. Em.keys(configsToRemove).forEach(function(site){
  139. var siteConfigs = configs.items.findProperty('type', site);
  140. if (siteConfigs) {
  141. configsToRemove[site].forEach(function (property) {
  142. delete siteConfigs.properties[property];
  143. });
  144. }
  145. });
  146. return configs;
  147. },
  148. setConfigInitialValue: function(config,value) {
  149. config.value = value;
  150. config.defaultValue = value;
  151. },
  152. renderServiceConfigs: function (_serviceConfig) {
  153. var serviceConfig = App.ServiceConfig.create({
  154. serviceName: _serviceConfig.serviceName,
  155. displayName: _serviceConfig.displayName,
  156. configCategories: [],
  157. showConfig: true,
  158. configs: []
  159. });
  160. _serviceConfig.configCategories.forEach(function (_configCategory) {
  161. if (App.Service.find().someProperty('serviceName', _configCategory.name)) {
  162. serviceConfig.configCategories.pushObject(_configCategory);
  163. }
  164. }, this);
  165. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  166. this.get('stepConfigs').pushObject(serviceConfig);
  167. this.set('selectedService', this.get('stepConfigs').objectAt(0));
  168. this.once = true;
  169. },
  170. /**
  171. * Load child components to service config object
  172. * @param _componentConfig
  173. * @param componentConfig
  174. */
  175. loadComponentConfigs: function (_componentConfig, componentConfig) {
  176. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  177. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  178. componentConfig.configs.pushObject(serviceConfigProperty);
  179. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  180. serviceConfigProperty.validate();
  181. }, this);
  182. },
  183. isNextDisabled: function () {
  184. return !this.get('isLoaded');
  185. }.property('isLoaded')
  186. });