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


##########
audit-server/audit-dispatcher/dispatcher-app/src/main/java/org/apache/ranger/audit/dispatcher/AuditDispatcherApplication.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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 AuditDispatcherApplication() {
+    }
+
+    public static void main(String[] args) {
+        AuditConfig config = new AuditConfig();
+        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");
+        }
+
+        // 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 {
+            String dispatcherMgrClass = config.get(CONFIG_PREFIX + 
dispatcherType + ".class");
+            if (dispatcherMgrClass != null && 
!dispatcherMgrClass.trim().isEmpty()) {
+                initSuccess = initializeDispatcherManager(dispatcherMgrClass);
+            } else {
+                LOG.error("Unknown dispatcher type: {}. Cannot initialize 
dispatcher manager.", dispatcherType);
+            }
+        } catch (Exception e) {
+            LOG.error("Failed to initialize DispatcherManager", e);
+        }
+
+        if (!initSuccess) {
+            LOG.error("Dispatcher initialization failed. The service will 
continue running to allow log inspection, but no audits will be dispatched.");

Review Comment:
   Shouldn't the dispatcher application exit in this condition?



##########
audit-server/audit-dispatcher/dispatcher-hdfs/src/main/java/org/apache/ranger/audit/dispatcher/HdfsDispatcherManager.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.dispatcher.kafka.AuditDispatcher;
+import org.apache.ranger.audit.dispatcher.kafka.AuditDispatcherRegistry;
+import org.apache.ranger.audit.provider.MiscUtil;
+import org.apache.ranger.audit.server.AuditServerConstants;
+import org.apache.ranger.audit.server.HdfsDispatcherConfig;
+import org.apache.ranger.audit.utils.AuditServerLogFormatter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Spring component that manages the lifecycle of HDFS dispatcher threads.
+ * This manager:
+ * - Initializes the dispatcher registry
+ * - Creates HDFS dispatcher instances
+ * - Starts dispatcher threads
+ * - Handles graceful shutdown
+ */
+@Component
+public class HdfsDispatcherManager {

Review Comment:
   Instance is created in `AuditDispatcherApplication` using reflection. Is 
`@Component` annotation needed here? Same for `@PostConstruct` as well.



##########
audit-server/audit-dispatcher/dispatcher-hdfs/src/main/java/org/apache/ranger/audit/server/HdfsDispatcherConfig.java:
##########
@@ -23,39 +23,40 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * Loads HDFS consumer-specific configuration files including Hadoop configs.
+ * Loads HDFS dispatcher-specific configuration files including Hadoop configs.
  */
-public class HdfsConsumerConfig extends AuditConfig {
-    private static final    Logger             LOG                   = 
LoggerFactory.getLogger(HdfsConsumerConfig.class);
-    private static final    String             CONFIG_FILE_PATH      = 
"conf/ranger-audit-consumer-hdfs-site.xml";
-    private static final    String             CORE_SITE_FILE_PATH   = 
"conf/core-site.xml";
-    private static final    String             HDFS_SITE_FILE_PATH   = 
"conf/hdfs-site.xml";
-    private static volatile HdfsConsumerConfig sInstance;
-
-    private HdfsConsumerConfig() {
+public class HdfsDispatcherConfig extends AuditConfig {

Review Comment:
   Are classes `HdfsDispatcherConfig` and `SolrDispatcherConfig` necessary, 
since loading of dispatcher type specific configuration is already handled in 
`AuditDispatcherApplication`?



##########
audit-server/audit-dispatcher/dispatcher-common/src/main/java/org/apache/ranger/audit/dispatcher/kafka/AuditDispatcherRegistry.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.kafka;
+
+import org.apache.ranger.audit.provider.AuditProviderFactory;
+import org.apache.ranger.audit.provider.MiscUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Registry for managing audit dispatcher factories and instances.
+ * Supports dynamic dispatcher registration and creation based on 
configuration.
+ */
+public class AuditDispatcherRegistry {

Review Comment:
   Is `AuditDispatcherRegistry` needed any more, given dispatcher instances are 
created based on configuration `ranger.audit.disppatcher.<type>.class`?



-- 
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