kafka.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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: 'KAFKA',
  21. getDependentConfigChanges: function (changedConfig, selectedServices, allConfigs) {
  22. var rangerPluginEnabledName = "ranger-kafka-plugin-enabled";
  23. var affectedProperties = [];
  24. var affectedPropertyName = changedConfig.get("name");
  25. var authorizerClassName, kafkaLog4jContent, newLog4jContentValue;
  26. var isEnabling = changedConfig.get('value') === 'Yes';
  27. if (affectedPropertyName === rangerPluginEnabledName) {
  28. authorizerClassName = this.getConfig(allConfigs, 'authorizer.class.name', 'kafka-broker.xml', 'KAFKA');
  29. kafkaLog4jContent = this.getConfig(allConfigs, 'content', 'kafka-log4j.xml', 'KAFKA');
  30. newLog4jContentValue = kafkaLog4jContent.get('value');
  31. newLog4jContentValue += "\n\nlog4j.appender.rangerAppender=org.apache.log4j.DailyRollingFileAppender\n" +
  32. "log4j.appender.rangerAppender.DatePattern='.'yyyy-MM-dd-HH\n" +
  33. "log4j.appender.rangerAppender.File=${kafka.logs.dir}/ranger_kafka.log\n" +
  34. "log4j.appender.rangerAppender.layout=org.apache.log4j.PatternLayout\n" +
  35. "log4j.appender.rangerAppender.layout.ConversionPattern=%d{ISO8601} %p [%t] %C{6} (%F:%L) - %m%n\n" +
  36. "log4j.logger.org.apache.ranger=INFO, rangerAppender";
  37. affectedProperties = [
  38. {
  39. serviceName: "KAFKA",
  40. sourceServiceName: "KAFKA",
  41. propertyName: 'authorizer.class.name',
  42. propertyDisplayName: 'authorizer.class.name',
  43. newValue: isEnabling ? 'org.apache.ranger.authorization.kafka.authorizer.RangerKafkaAuthorizer' :
  44. App.StackConfigProperty.find().findProperty('name', 'authorizer.class.name').get('value'),
  45. curValue: authorizerClassName.get('value'),
  46. changedPropertyName: rangerPluginEnabledName,
  47. removed: false,
  48. filename: 'kafka-broker.xml'
  49. },
  50. {
  51. serviceName: "KAFKA",
  52. sourceServiceName: "KAFKA",
  53. propertyName: 'content',
  54. propertyDisplayName: 'content',
  55. newValue: isEnabling ? newLog4jContentValue : App.StackConfigProperty.find().filterProperty('filename', 'kafka-log4j.xml').findProperty('name', 'content').get('value'),
  56. curValue: kafkaLog4jContent.get('value'),
  57. changedPropertyName: rangerPluginEnabledName,
  58. removed: false,
  59. filename: 'kafka-log4j.xml'
  60. }
  61. ];
  62. }
  63. return affectedProperties;
  64. }
  65. });