[HUDI-4331] Allow loading external config file from class loader (#5987)
Co-authored-by: Wenning Ding <wenningd@amazon.com>
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user