hbase.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('utils/configs/modification_handlers/modification_handler');
  19. module.exports = App.ServiceConfigModificationHandler.create({
  20. serviceId : 'HBASE',
  21. getConfig : function(allConfigs, configName, configFilename, configServiceName) {
  22. return allConfigs.findProperty("serviceName", configServiceName).get("configs").find(function(config) {
  23. return configName == config.get('name') && (configFilename == null || configFilename == config.get('filename'));
  24. });
  25. },
  26. updateConfigClasses : function(configClasses, authEnabled, affectedProperties, addOldValue) {
  27. if (configClasses != null) {
  28. var xaAuthCoProcessorClass = "com.xasecure.authorization.hbase.XaSecureAuthorizationCoprocessor";
  29. var nonXAClass = 'org.apache.hadoop.hbase.security.access.AccessController';
  30. var currentClassesList = configClasses.get('value').trim().length > 0 ? configClasses.get('value').trim().split(',') : [];
  31. var newClassesList = null, xaClassIndex, nonXaClassIndex;
  32. if (authEnabled) {
  33. var nonXaClassIndex = currentClassesList.indexOf(nonXAClass);
  34. if (nonXaClassIndex > -1) {
  35. currentClassesList.splice(nonXaClassIndex, 1);
  36. newClassesList = currentClassesList;
  37. }
  38. var xaClassIndex = currentClassesList.indexOf(xaAuthCoProcessorClass);
  39. if (xaClassIndex < 0) {
  40. currentClassesList.push(xaAuthCoProcessorClass);
  41. newClassesList = currentClassesList;
  42. }
  43. } else {
  44. var xaClassIndex = currentClassesList.indexOf(xaAuthCoProcessorClass);
  45. if (xaClassIndex > -1) {
  46. currentClassesList.splice(xaClassIndex, 1);
  47. newClassesList = currentClassesList;
  48. }
  49. if (addOldValue) {
  50. var nonXaClassIndex = currentClassesList.indexOf(nonXAClass);
  51. if (nonXaClassIndex < 0) {
  52. currentClassesList.push(nonXAClass);
  53. newClassesList = currentClassesList;
  54. }
  55. }
  56. }
  57. if (newClassesList != null) {
  58. affectedProperties.push({
  59. serviceName : "HBASE",
  60. sourceServiceName : "HBASE",
  61. propertyName : configClasses.get('name'),
  62. propertyDisplayName : configClasses.get('name'),
  63. newValue : newClassesList.join(','),
  64. curValue : configClasses.get('value'),
  65. changedPropertyName : 'ranger-hbase-plugin-enabled',
  66. removed : false,
  67. filename : 'hbase-site.xml'
  68. });
  69. }
  70. }
  71. },
  72. getDependentConfigChanges : function(changedConfig, selectedServices, allConfigs, securityEnabled) {
  73. var affectedProperties = [];
  74. var newValue = changedConfig.get("value");
  75. var hbaseAuthEnabledPropertyName = "ranger-hbase-plugin-enabled";
  76. var affectedPropertyName = changedConfig.get("name");
  77. if (affectedPropertyName == hbaseAuthEnabledPropertyName) {
  78. var configAuthEnabled = this.getConfig(allConfigs, 'hbase.security.authorization', 'hbase-site.xml', 'HBASE');
  79. var configMasterClasses = this.getConfig(allConfigs, 'hbase.coprocessor.master.classes', 'hbase-site.xml', 'HBASE');
  80. var configRegionClasses = this.getConfig(allConfigs, 'hbase.coprocessor.region.classes', 'hbase-site.xml', 'HBASE');
  81. var configRpcProtection = this.getConfig(allConfigs, 'hbase.rpc.protection', 'hbase-site.xml', 'HBASE');
  82. var authEnabled = newValue == "Yes";
  83. var newAuthEnabledValue = authEnabled ? "true" : "false";
  84. var newRpcProtectionValue = authEnabled ? "privacy" : "authentication";
  85. // Add Hive-Ranger configs
  86. this.updateConfigClasses(configMasterClasses, authEnabled, affectedProperties, configAuthEnabled.get('value') == 'true');
  87. this.updateConfigClasses(configRegionClasses, authEnabled, affectedProperties, configAuthEnabled.get('value') == 'true');
  88. if (newRpcProtectionValue !== configRpcProtection.get('value')) {
  89. affectedProperties.push({
  90. serviceName : "HBASE",
  91. sourceServiceName : "HBASE",
  92. propertyName : 'hbase.rpc.protection',
  93. propertyDisplayName : 'hbase.rpc.protection',
  94. newValue : newRpcProtectionValue,
  95. curValue : configRpcProtection.get('value'),
  96. changedPropertyName : hbaseAuthEnabledPropertyName,
  97. removed : false,
  98. filename : 'hbase-site.xml'
  99. });
  100. }
  101. if (authEnabled && newAuthEnabledValue !== configAuthEnabled.get('value')) {
  102. affectedProperties.push({
  103. serviceName : "HBASE",
  104. sourceServiceName : "HBASE",
  105. propertyName : 'hbase.security.authorization',
  106. propertyDisplayName : 'hbase.security.authorization',
  107. newValue : newAuthEnabledValue,
  108. curValue : configAuthEnabled.get('value'),
  109. changedPropertyName : hbaseAuthEnabledPropertyName,
  110. removed : false,
  111. filename : 'hbase-site.xml'
  112. });
  113. }
  114. }
  115. return affectedProperties;
  116. }
  117. });