1
0

[HUDI-4331] Allow loading external config file from class loader (#5987)

Co-authored-by: Wenning Ding <wenningd@amazon.com>
This commit is contained in:
wenningd
2022-06-29 17:04:34 -07:00
committed by GitHub
parent e71f04768e
commit 03a94d9ff5

View File

@@ -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());