move_hm_config_initializer.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/move_hive_component_config_initializer_class');
  20. /**
  21. * Initializer for configs which should be affected when Hive Metastore is moved from one host to another
  22. *
  23. * @type {MoveHiveComponentConfigInitializerClass}
  24. */
  25. App.MoveHmConfigInitializer = App.MoveHiveComponentConfigInitializerClass.create({
  26. initializers: {
  27. 'hadoop.proxyuser.{{hiveUser}}.hosts': App.MoveHiveComponentConfigInitializerClass.getHostsWithComponentsConfig(['HIVE_SERVER', 'HIVE_METASTORE'], 'HIVE_METASTORE')
  28. },
  29. uniqueInitializers: {
  30. 'hive.metastore.uris': '_initHiveMetastoreUris',
  31. 'templeton.hive.properties': '_initTempletonHiveProperties'
  32. },
  33. /**
  34. * Unique initializer for <code>hive.metastore.uris</code>-config
  35. * Value example: 'thrift://host1:1234,thrift://host2:1234,thrift://host3:1234'
  36. *
  37. * @param {configProperty} configProperty
  38. * @param {extendedTopologyLocalDB} localDB
  39. * @param {reassignComponentDependencies} dependencies
  40. * @returns {object}
  41. * @private
  42. * @method _initHiveMetastoreUris
  43. */
  44. _initHiveMetastoreUris: function (configProperty, localDB, dependencies) {
  45. if (App.config.getConfigTagFromFileName(Em.get(configProperty, 'filename')) === 'hive-site') {
  46. var hiveMSHosts = this.__getHmHostsConsideringMoved(localDB, dependencies);
  47. var value = Em.get(configProperty, 'value');
  48. var port = value.match(/:[0-9]{2,4}/);
  49. port = port ? port[0].slice(1) : '9083';
  50. value = hiveMSHosts.uniq().map(function (hiveMSHost) {
  51. return 'thrift://' + hiveMSHost + ':' + port;
  52. }).join(',');
  53. Em.set(configProperty, 'value', value);
  54. }
  55. return configProperty;
  56. },
  57. /**
  58. * Unique initializer for <code>templeton.hive.properties</code>-config
  59. * Replace existing hosts with new
  60. * Value example: 'hive.metastore.local=false,hive.metastore.uris=thrift://host1:9083,hive.metastore.sasl.enabled=false,hive.metastore.execute.setugi=true'
  61. *
  62. * @param {configProperty} configProperty
  63. * @param {extendedTopologyLocalDB} localDB
  64. * @param {reassignComponentDependencies} dependencies
  65. * @returns {object}
  66. * @private
  67. * @method _initTempletonHiveProperties
  68. */
  69. _initTempletonHiveProperties: function (configProperty, localDB, dependencies) {
  70. var hiveMSHosts = this.__getHmHostsConsideringMoved(localDB, dependencies);
  71. var value = Em.get(configProperty, 'value');
  72. value = value.replace(/thrift.+[0-9]{2,},/i, hiveMSHosts.join('\\,') + ',');
  73. Em.set(configProperty, 'value', value);
  74. return configProperty;
  75. },
  76. /**
  77. * Get list of hosts where HIVE_METASTORE exists considering component's moving (host where it was is removed and host
  78. * where it will be is added)
  79. *
  80. * @param {extendedTopologyLocalDB} localDB
  81. * @param {reassignComponentDependencies} dependencies
  82. * @returns {string[]}
  83. * @private
  84. * @method __getHmHostsConsideringMoved
  85. */
  86. __getHmHostsConsideringMoved: function (localDB, dependencies) {
  87. var hiveMSHosts = localDB.masterComponentHosts.filterProperty('component', 'HIVE_METASTORE').mapProperty('hostName');
  88. hiveMSHosts = hiveMSHosts.removeObject(dependencies.sourceHostName).addObject(dependencies.targetHostName);
  89. return hiveMSHosts.uniq();
  90. }
  91. });