Skip to content

Commit 3fd46db

Browse files
rameeshmRamesh Manimneethiraj
authored
RANGER-5520:Audit Server refactoring to segregate audit ingestion and… (#886)
* RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - copilot review comment fix * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - Fix review comments * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality -Fix review comments -set #2 * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality -Fix review comments - set #3 * addressed review suggestions * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - Fix review comments #4 - remove audit dispatcher registry * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - Fix merge conflit * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - fix dispatcher issue with handling failed audits * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - fix review comments #5 * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality -fix review comments * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - Fix review comments on docker file separation for ingestor and dispatchers * RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - Fixed review comment on docker file --------- Co-authored-by: Ramesh Mani <rmani@apache.org> Co-authored-by: Madhan Neethiraj <madhan@apache.org>
1 parent 6bf21ea commit 3fd46db

119 files changed

Lines changed: 5377 additions & 4753 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

audit-server/audit-common/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
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+
<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">
19+
<modelVersion>4.0.0</modelVersion>
20+
21+
<parent>
22+
<groupId>org.apache.ranger</groupId>
23+
<artifactId>ranger</artifactId>
24+
<version>3.0.0-SNAPSHOT</version>
25+
<relativePath>../..</relativePath>
26+
</parent>
27+
28+
<artifactId>ranger-audit-server-common</artifactId>
29+
<packaging>jar</packaging>
30+
<name>Ranger Audit Server Common</name>
31+
<description>Shared classes between audit ingestor and dispatcher</description>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.apache.kafka</groupId>
36+
<artifactId>kafka-clients</artifactId>
37+
<version>${kafka.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.apache.ranger</groupId>
41+
<artifactId>ranger-plugins-common</artifactId>
42+
<version>${project.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-api</artifactId>
47+
<version>${slf4j.version}</version>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<finalName>ranger-audit-server-common-${project.version}</finalName>
53+
</build>
54+
</project>

audit-server/common/src/main/java/org/apache/ranger/audit/server/AuditConfig.java renamed to audit-server/audit-common/src/main/java/org/apache/ranger/audit/server/AuditConfig.java

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,27 @@
1919

2020
package org.apache.ranger.audit.server;
2121

22-
import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
22+
import org.apache.commons.lang3.StringUtils;
23+
import org.apache.hadoop.conf.Configuration;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

27+
import java.io.File;
28+
import java.net.MalformedURLException;
29+
import java.net.URL;
2630
import java.util.Properties;
2731

2832
/**
2933
* Base configuration class for Ranger Audit Server services.
3034
* Can be extended by specific services to load their custom configuration files.
3135
*/
32-
public class AuditConfig extends RangerConfiguration {
33-
private static final Logger LOG = LoggerFactory.getLogger(AuditConfig.class);
34-
private static volatile AuditConfig sInstance;
36+
public class AuditConfig extends Configuration {
37+
private static final Logger LOG = LoggerFactory.getLogger(AuditConfig.class);
3538

36-
protected AuditConfig() {
39+
public AuditConfig() {
3740
super();
3841
}
3942

40-
/**
41-
* Get the singleton instance of AuditConfig.
42-
* Subclasses should override this method to return their specific instance.
43-
*/
44-
public static AuditConfig getInstance() {
45-
AuditConfig ret = AuditConfig.sInstance;
46-
47-
if (ret == null) {
48-
synchronized (AuditConfig.class) {
49-
ret = AuditConfig.sInstance;
50-
51-
if (ret == null) {
52-
ret = new AuditConfig();
53-
AuditConfig.sInstance = ret;
54-
}
55-
}
56-
}
57-
58-
return ret;
59-
}
60-
6143
public Properties getProperties() {
6244
return this.getProps();
6345
}
@@ -66,11 +48,11 @@ public Properties getProperties() {
6648
* Add a resource file to the configuration.
6749
* Subclasses can override to load their specific config files.
6850
*
69-
* @param resourcePath Path to the resource file (e.g., "conf/ranger-audit-server-site.xml")
51+
* @param resourcePath Path to the resource file (e.g., "conf/ranger-audit-ingestor-site.xml")
7052
* @param required Whether this resource is required
7153
* @return true if resource was loaded successfully or is optional, false otherwise
7254
*/
73-
protected boolean addAuditResource(String resourcePath, boolean required) {
55+
public boolean addAuditResource(String resourcePath, boolean required) {
7456
LOG.debug("==> addAuditResource(path={}, required={})", resourcePath, required);
7557

7658
boolean success = addResourceIfReadable(resourcePath);
@@ -87,4 +69,58 @@ protected boolean addAuditResource(String resourcePath, boolean required) {
8769

8870
return success || !required;
8971
}
72+
73+
public boolean addResourceIfReadable(String aResourceName) {
74+
LOG.debug("==> addResourceIfReadable({})", aResourceName);
75+
76+
boolean ret = false;
77+
URL fUrl = getFileLocation(aResourceName);
78+
79+
if (fUrl != null) {
80+
LOG.debug("addResourceIfReadable({}): resource file is {}", aResourceName, fUrl);
81+
82+
try {
83+
addResource(fUrl);
84+
85+
ret = true;
86+
} catch (Exception e) {
87+
LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", aResourceName, fUrl);
88+
89+
LOG.debug("Resource loading failed for {}", fUrl, e);
90+
}
91+
} else {
92+
LOG.debug("addResourceIfReadable({}): couldn't find resource file location", aResourceName);
93+
}
94+
95+
LOG.debug("<== addResourceIfReadable({}), result={}", aResourceName, ret);
96+
97+
return ret;
98+
}
99+
100+
private URL getFileLocation(String fileName) {
101+
URL lurl = null;
102+
103+
if (!StringUtils.isEmpty(fileName)) {
104+
lurl = AuditConfig.class.getClassLoader().getResource(fileName);
105+
106+
if (lurl == null) {
107+
lurl = AuditConfig.class.getClassLoader().getResource("/" + fileName);
108+
}
109+
110+
if (lurl == null) {
111+
File f = new File(fileName);
112+
if (f.exists()) {
113+
try {
114+
lurl = f.toURI().toURL();
115+
} catch (MalformedURLException e) {
116+
LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", fileName, f.getPath());
117+
}
118+
} else {
119+
LOG.debug("Conf file path {} does not exists", fileName);
120+
}
121+
}
122+
}
123+
124+
return lurl;
125+
}
90126
}

0 commit comments

Comments
 (0)