This is an automated email from the ASF dual-hosted git repository.
yihua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 03a94d9ff5 [HUDI-4331] Allow loading external config file from class
loader (#5987)
03a94d9ff5 is described below
commit 03a94d9ff5bc673fc68da6681eea7b7d881e1881
Author: wenningd <[email protected]>
AuthorDate: Wed Jun 29 17:04:34 2022 -0700
[HUDI-4331] Allow loading external config file from class loader (#5987)
Co-authored-by: Wenning Ding <[email protected]>
---
.../hudi/common/config/DFSPropertiesConfiguration.java | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java
b/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java
index e417649948..f3614a64b7 100644
---
a/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java
+++
b/hudi-common/src/main/java/org/apache/hudi/common/config/DFSPropertiesConfiguration.java
@@ -38,6 +38,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
+import java.net.URL;
import java.util.HashSet;
import java.util.Set;
@@ -90,11 +91,24 @@ public class DFSPropertiesConfiguration {
}
/**
- * Load global props from hudi-defaults.conf which is under
CONF_FILE_DIR_ENV_NAME.
+ * Load global props from hudi-defaults.conf which is under class loader or
CONF_FILE_DIR_ENV_NAME.
* @return Typed Properties
*/
public static TypedProperties loadGlobalProps() {
DFSPropertiesConfiguration conf = new DFSPropertiesConfiguration();
+
+ // First try loading the external config file from class loader
+ URL configFile =
Thread.currentThread().getContextClassLoader().getResource(DEFAULT_PROPERTIES_FILE);
+ if (configFile != null) {
+ try (BufferedReader br = new BufferedReader(new
InputStreamReader(configFile.openStream()))) {
+ conf.addPropsFromStream(br);
+ return conf.getProps();
+ } catch (IOException ioe) {
+ throw new HoodieIOException(
+ String.format("Failed to read %s from class loader",
DEFAULT_PROPERTIES_FILE), ioe);
+ }
+ }
+ // Try loading the external config file from local file system
Option<Path> defaultConfPath = getConfPathFromEnv();
if (defaultConfPath.isPresent()) {
conf.addPropsFromFile(defaultConfPath.get());