rm_ha_config_initializer.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. require('utils/configs/config_initializer_class');
  20. require('utils/configs/hosts_based_initializer_mixin');
  21. /**
  22. * Settings for <code>rm_hosts_with_port</code> initializer
  23. * Used for configs that have to be updated with Yarn Resourcemanager HA hosts
  24. * addresses and a port to the <code>rmhost1:port,rmhost2:port</code>
  25. *
  26. * @param {int} port
  27. * @returns {{type: string, port: *}}
  28. */
  29. function getRmHaHostsWithPort(port) {
  30. return {
  31. type: 'rm_hosts_with_port',
  32. port: port
  33. };
  34. }
  35. /**
  36. * Initializer for configs that are updated when Resource Manager HA-mode is activated
  37. *
  38. * @class {RmHaConfigInitializer}
  39. */
  40. App.RmHaConfigInitializer = App.HaConfigInitializerClass.create(App.HostsBasedInitializerMixin, {
  41. initializers: function () {
  42. return {
  43. 'yarn.resourcemanager.hostname.rm1': this.getHostWithPortConfig('RESOURCEMANAGER', true, '', '', ''),
  44. 'yarn.resourcemanager.hostname.rm2': this.getHostWithPortConfig('RESOURCEMANAGER', false,'', '', ''),
  45. 'yarn.resourcemanager.zk-address': this.getHostsWithPortConfig('ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  46. 'yarn.resourcemanager.webapp.address.rm1': this.getHostWithPortConfig('RESOURCEMANAGER', true, '', '', 'webAddressPort', true),
  47. 'yarn.resourcemanager.webapp.address.rm2': this.getHostWithPortConfig('RESOURCEMANAGER', false, '', '', 'webAddressPort', true),
  48. 'yarn.resourcemanager.webapp.https.address.rm1': this.getHostWithPortConfig('RESOURCEMANAGER', true, '', '', 'httpsWebAddressPort', true),
  49. 'yarn.resourcemanager.webapp.https.address.rm2': this.getHostWithPortConfig('RESOURCEMANAGER', false, '', '', 'httpsWebAddressPort', true),
  50. 'yarn.resourcemanager.ha': getRmHaHostsWithPort(8032),
  51. 'yarn.resourcemanager.scheduler.ha': getRmHaHostsWithPort(8030)
  52. };
  53. }.property(),
  54. initializerTypes: [
  55. {name: 'rm_hosts_with_port', method: '_initRmHaHostsWithPort'},
  56. ],
  57. /**
  58. * Initializer for configs that should be updated with yarn resourcemanager ha host addresses with port
  59. *
  60. * @param {configProperty} configProperty
  61. * @param {extendedTopologyLocalDB} localDB
  62. * @param {HaConfigDependencies} dependencies
  63. * @param {object} initializer
  64. * @returns {object}
  65. * @private
  66. * @method _initRmHaHostsWithPort
  67. */
  68. _initRmHaHostsWithPort: function (configProperty, localDB, dependencies, initializer) {
  69. var rmHosts = localDB.masterComponentHosts.filterProperty('component', 'RESOURCEMANAGER').getEach('hostName');
  70. for (rmHost in rmHosts) {
  71. rmHosts[rmHost] = rmHosts[rmHost] + ":" + initializer.port;
  72. }
  73. var value = rmHosts.join(',');
  74. Em.setProperties(configProperty, {
  75. 'value': value,
  76. 'recommendedValue': value
  77. });
  78. return configProperty;
  79. }
  80. });