Use environment variables in the bookkeeper parameters
- Dominant language
- Java
- Stars
- 2k
- Forks
- 976
- Avg merge
- 6d 15h
- Merged PRs (30d)
- 7
Description
**FEATURE REQUEST**
1. Please describe the feature you are requesting.
In docker, the environment variable parameters are used applying-config-from-env.py to modify bk_server.conf. This inconsistency can be confusing for non-container deployments
2. Indicate the importance of this issue to you (blocker, must-have, should-have, nice-to-have).
Are you currently using any workarounds to address this issue?
I think you can add a new parse method parseEnvironment and this method is executed after parseCommandLine. Environment variable parameters take precedence over command line parameters
3. Provide any additional detail on your proposed use case for this feature.
code snippet is shown below, any suggestions?
Main.java
```
@SuppressWarnings("deprecation")
private static ServerConfiguration parseArgs(String[] args)
throws IllegalArgumentException {
try {
BasicParser parser = new BasicParser();
CommandLine cmdLine = parser.parse(BK_OPTS, args);
if (cmdLine.hasOption('h')) {
throw new IllegalArgumentException();
}
ServerConfiguration conf = new ServerConfiguration();
loadConfEnv(conf);
if (cmdLine.hasOption('c')) {
String confFile = cmdLine.getOptionValue("c");
loadConfFile(conf, confFile);
}
...
...
private static void loadConfEnv(ServerConfiguration conf) throws IllegalArgumentException {
try{
conf.loadEnv();
conf.validate();
} catch (ConfigurationException e) {
log.error("Malformed configuration file: {}", e);
throw new IllegalArgumentException();
}
}
```
Read bookkeeper parameters with the prefix BK_ from the environment in AbstractConfiguration.java
```
public void loadEnv() {
System.getenv().entrySet().stream().filter(entry -> entry.getKey().startsWith(ENV_PREFIX))
.forEach(entry -> {
String name = entry.getKey().substring(ENV_PREFIX.length());
String value = entry.getValue();
log.info("load environment {}={}", name, value);
setProperty(name,value);
});
}
```
Contributor guide
Assessment
This issue has not been assessed yet.