This is an automated email from the ASF dual-hosted git repository.
chaitalithombare pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new 60e6d8c0b ATLAS-5162 : Add support to load custom application
properties (#476)
60e6d8c0b is described below
commit 60e6d8c0b00e490f90b4201fdd680553949e0774
Author: chaitalicod <[email protected]>
AuthorDate: Tue Dec 2 14:30:20 2025 +0530
ATLAS-5162 : Add support to load custom application properties (#476)
Co-authored-by: chaitalithombare <[email protected]>
---
.../org/apache/atlas/ApplicationProperties.java | 56 +++++++++++++++++-----
.../apache/atlas/ApplicationPropertiesTest.java | 42 ++++++++++++++++
2 files changed, 85 insertions(+), 13 deletions(-)
diff --git a/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
index e54847c6e..a1c799de3 100644
--- a/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
+++ b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
@@ -124,27 +124,57 @@ public final class ApplicationProperties extends
PropertiesConfiguration {
return instance;
}
- public static Configuration get(String fileName) throws AtlasException {
- String confLocation =
System.getProperty(ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
+ public static Configuration getConfFromAbsolutePath(String
absoluteFilePath) throws AtlasException {
+ if (instance == null) {
+ synchronized (ApplicationProperties.class) {
+ if (instance == null) {
+ set(get(absoluteFilePath));
+ }
+ }
+ }
+ return instance;
+ }
+ public static Configuration get(PropertiesConfiguration clientConf) throws
AtlasException {
+ if (instance == null) {
+ synchronized (ApplicationProperties.class) {
+ if (instance == null) {
+ set(clientConf);
+ }
+ }
+ }
+ return instance;
+ }
+
+ public static Configuration get(String fileName) throws AtlasException {
try {
- URL url;
+ URL url = null;
- if (confLocation == null) {
- LOG.info("Looking for {} in classpath", fileName);
+ if (StringUtils.isNotBlank(fileName)) {
+ File file = new File(fileName);
+ if (file.exists()) {
+ url = file.toURI().toURL();
+ LOG.info("Loading {} from {}", fileName, url);
+ }
+ }
+ if (url == null) {
+ String confLocation =
System.getProperty(ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
- url =
ApplicationProperties.class.getClassLoader().getResource(fileName);
+ if (confLocation == null) {
+ LOG.info("Looking for {} in classpath", fileName);
- if (url == null) {
- LOG.info("Looking for /{} in classpath", fileName);
+ url =
ApplicationProperties.class.getClassLoader().getResource(fileName);
- url =
ApplicationProperties.class.getClassLoader().getResource("/" + fileName);
+ if (url == null) {
+ LOG.info("Looking for /{} in classpath", fileName);
+ url =
ApplicationProperties.class.getClassLoader().getResource("/" + fileName);
+ }
+ } else {
+ url = new File(confLocation, fileName).toURI().toURL();
}
- } else {
- url = new File(confLocation, fileName).toURI().toURL();
- }
- LOG.info("Loading {} from {}", fileName, url);
+ LOG.info("Loading {} from {}", fileName, url);
+ }
ApplicationProperties appProperties = new
ApplicationProperties(url);
diff --git a/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
index 5ac5b5628..38b66f3be 100644
--- a/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
+++ b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
@@ -19,20 +19,25 @@ package org.apache.atlas;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.util.AbstractMap;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
import static org.testng.Assert.fail;
/**
* Unit test for {@link ApplicationProperties}
*
*/
+
public class ApplicationPropertiesTest {
@Test
public void testGetFileAsInputStream() throws Exception {
@@ -157,4 +162,41 @@ public class ApplicationPropertiesTest {
assertEquals(AtlasConfigurationUtil.getRecentString(atlasConf, key,
oldVal), newVal);
assertEquals(AtlasConfigurationUtil.getRecentString(atlasConf,
"garbage", oldVal), oldVal);
}
+
+ @Test
+ public void verifyPropertyValues() throws AtlasException {
+ Configuration props =
ApplicationProperties.getConfFromAbsolutePath("src/test/resources/test.properties");
+ ApplicationProperties aProps = (ApplicationProperties) props;
+
+ String nameSpaceValue = "nm-sp-11";
+ String someKey = "atlas.metadata.namespace";
+
+ assertFalse(aProps.getString(someKey).equals(nameSpaceValue));
+ }
+
+ @Test
+ public void verifyCustomisedPathFailureExpected() throws AtlasException {
+ ApplicationProperties.forceReload();
+
+ AtlasException ex = expectThrows(
+ AtlasException.class,
+ () ->
ApplicationProperties.getConfFromAbsolutePath("src/test/resources/incorrectfile.properties"));
+
+ assertTrue(
+ ex.getMessage().contains("Failed to load application
properties"),
+ "Expected error message to contain 'Failed to load application
properties'");
+ }
+
+ @Test
+ public void verifyClientConfiguration() throws Exception {
+ PropertiesConfiguration props = new PropertiesConfiguration();
+
+ String defaultValue = "atlas";
+ String someKey = "atlas.service";
+
+ props.setProperty(someKey, defaultValue);
+ Configuration configuration = ApplicationProperties.get(props);
+
+ assertTrue(configuration.getProperty(someKey).equals(defaultValue));
+ }
}