mneethiraj commented on code in PR #886:
URL: https://github.com/apache/ranger/pull/886#discussion_r3012785783


##########
audit-server/audit-common/src/main/java/org/apache/ranger/audit/utils/AuditMessageQueueUtils.java:
##########


Review Comment:
   Following methods don't seem to be used anymore. Please review and remove:
   - isSolrConsumerEnabled()
   - isHDFSConsumerEnabled()
   - isTopicReady()



##########
audit-server/audit-common/src/main/java/org/apache/ranger/audit/utils/AuditServerUtils.java:
##########


Review Comment:
   There will be only once instance of `AuditProviderFactory` in a JVM - due to 
use of `static AuditProviderFactory sFactory` in `AuditProviderFactory` class. 
Hence the following in `AuditServerUtils`, which assumes multiple 
`AuditProviderFactory` instances  (one per appId per host) is incorrect. Please 
review and update.
   
   ```
       private final ConcurrentHashMap<String, Map<String, 
AuditProviderFactory>> auditProviderMap = new ConcurrentHashMap<>();
   ```



##########
audit-server/audit-common/pom.xml:
##########
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ranger</groupId>
+        <artifactId>ranger</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../..</relativePath>
+    </parent>
+
+    <artifactId>ranger-audit-server-common</artifactId>
+    <packaging>jar</packaging>
+    <name>Ranger Audit Server Common</name>
+    <description>Shared classes between audit ingestor and 
dispatcher</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.kafka</groupId>
+            <artifactId>kafka-clients</artifactId>
+            <version>${kafka.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ranger</groupId>
+            <artifactId>ranger-plugins-common</artifactId>

Review Comment:
   It looks like `ranger-plugins-common` is dragged in only for 
`RangerConfiguration`. Getting rid of this dependency would make audit 
audit-common a lot lighter. Consider `AuditConfig` not extend 
`RangerConfiguration`; instead just make this class self-sufficient. 



##########
audit-server/audit-dispatcher/dispatcher-app/src/main/java/org/apache/ranger/audit/dispatcher/AuditDispatcherApplication.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.audit.dispatcher;
+
+import org.apache.ranger.audit.server.AuditConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditDispatcherApplication {
+    private static final Logger LOG                           = 
LoggerFactory.getLogger(AuditDispatcherApplication.class);
+    private static final String APP_NAME                      = 
"audit-dispatcher";
+    private static final String CONFIG_PREFIX                 = 
"ranger.audit.dispatcher.";
+    private static final String COMMON_CONFIG_FILE            = 
"ranger-audit-dispatcher-site.xml";
+    private static final String HDFS_DISPATCHER_MANAGER_CLASS = 
"org.apache.ranger.audit.dispatcher.HdfsDispatcherManager";
+    private static final String SOLR_DISPATCHER_MANAGER_CLASS = 
"org.apache.ranger.audit.dispatcher.SolrDispatcherManager";
+
+    private AuditDispatcherApplication() {
+    }
+
+    public static void main(String[] args) {
+        AuditConfig config = AuditConfig.getInstance();
+        config.addResourceIfReadable(COMMON_CONFIG_FILE);
+        LOG.info("Loaded common configuration from classpath: {}", 
COMMON_CONFIG_FILE);
+
+        String dispatcherType = System.getProperty(CONFIG_PREFIX + "type");
+        if (dispatcherType == null) {
+            dispatcherType = config.get(CONFIG_PREFIX + "type");
+            if (dispatcherType != null) {
+                System.setProperty(CONFIG_PREFIX + "type", dispatcherType);

Review Comment:
   Consider removing the dependency on setting system property (line 46). 



##########
audit-server/audit-dispatcher/dispatcher-app/src/main/java/org/apache/ranger/audit/dispatcher/AuditDispatcherApplication.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.audit.dispatcher;
+
+import org.apache.ranger.audit.server.AuditConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditDispatcherApplication {
+    private static final Logger LOG                           = 
LoggerFactory.getLogger(AuditDispatcherApplication.class);
+    private static final String APP_NAME                      = 
"audit-dispatcher";
+    private static final String CONFIG_PREFIX                 = 
"ranger.audit.dispatcher.";
+    private static final String COMMON_CONFIG_FILE            = 
"ranger-audit-dispatcher-site.xml";
+    private static final String HDFS_DISPATCHER_MANAGER_CLASS = 
"org.apache.ranger.audit.dispatcher.HdfsDispatcherManager";
+    private static final String SOLR_DISPATCHER_MANAGER_CLASS = 
"org.apache.ranger.audit.dispatcher.SolrDispatcherManager";
+
+    private AuditDispatcherApplication() {
+    }
+
+    public static void main(String[] args) {
+        AuditConfig config = AuditConfig.getInstance();
+        config.addResourceIfReadable(COMMON_CONFIG_FILE);
+        LOG.info("Loaded common configuration from classpath: {}", 
COMMON_CONFIG_FILE);
+
+        String dispatcherType = System.getProperty(CONFIG_PREFIX + "type");
+        if (dispatcherType == null) {
+            dispatcherType = config.get(CONFIG_PREFIX + "type");
+            if (dispatcherType != null) {
+                System.setProperty(CONFIG_PREFIX + "type", dispatcherType);
+            }
+        }
+
+        // Load dispatcher-specific configuration from classpath
+        if (dispatcherType != null) {
+            String specificConfig = "ranger-audit-dispatcher-" + 
dispatcherType + "-site.xml";
+            config.addResourceIfReadable(specificConfig);
+            LOG.info("Loaded dispatcher-specific configuration from classpath: 
{}", specificConfig);
+        } else {
+            LOG.warn("No dispatcher type specified. Service might fail to 
start correctly.");
+        }
+
+        
LOG.info("==========================================================================");
+        LOG.info("==> Starting Ranger Audit Dispatcher Service (Type: {})", 
dispatcherType);
+        
LOG.info("==========================================================================");
+
+        // Initialization dispatcher manager based on dispatcher type before 
starting EmbeddedServer
+        boolean initSuccess = false;
+        try {
+            if ("hdfs".equalsIgnoreCase(dispatcherType)) {
+                initSuccess = 
initializeDispatcherManager(HDFS_DISPATCHER_MANAGER_CLASS);
+            } else if ("solr".equalsIgnoreCase(dispatcherType)) {
+                initSuccess = 
initializeDispatcherManager(SOLR_DISPATCHER_MANAGER_CLASS);
+            } else {

Review Comment:
   For other values of `dispatcherType`, how about reading the implementation 
class name from configuration and initialize - similar to 
`AuditProviderFactory.getProviderFromConfig()`?
   ```
   String className = config.get(CONFIG_PREFIX + dispatcherType + ".classname");
   
   if (StringUtils.isNotBlank(className)) {
       initSuccess = initializeDispatcherManager(className);
   } else {
       LOG.error("Unknown dispatcher type: {}. Cannot initialize dispatcher 
manager.", dispatcherType);
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to