Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

ISSUE-2341: Add a way to configure bookkeeper parameters #213

Open
sijie opened this issue May 21, 2020 · 0 comments
Open

ISSUE-2341: Add a way to configure bookkeeper parameters #213

sijie opened this issue May 21, 2020 · 0 comments

Comments

@sijie
Copy link
Member

sijie commented May 21, 2020

Original Issue: apache#2341


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

  1. 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

  1. Provide any additional detail on your proposed use case for this feature.

code snippet is shown below, any suggestions?

Main.java

        // 0. parse command line
        try {
            conf = parseCommandLine(args);
        } catch (IllegalArgumentException iae) {
            return ExitCode.INVALID_CONF;
        }

        try {
            conf = parseEnvironment(conf);
        } catch (IllegalArgumentException iae) {
            return ExitCode.INVALID_CONF;
        }

Read the variable with the prefix BK_ from the environment variable, and overwrite the variable value read from the command line through reflection

    private static ServerConfiguration parseEnvironment(ServerConfiguration conf) {
        System.getenv().entrySet().stream().filter(entry -> entry.getKey().startsWith("BK_"))
            .forEach(entry -> {
                String name = entry.getKey().substring("BK_".length());
                String value = entry.getValue();
                Arrays.stream(conf.getClass().getDeclaredMethods())
                    .filter(m -> m.getName().startsWith("set")).forEach(m -> {
                    try {
                        if (m.getName().toLowerCase().equals("set" + name.toLowerCase())
                            && m.getParameterCount() == 1) {
                            if (m.getParameterTypes()[0] == boolean.class) {
                                m.invoke(conf, Boolean.valueOf(value).booleanValue());
                            } else if (m.getParameterTypes()[0] == int.class) {
                                m.invoke(conf, Integer.valueOf(value).intValue());
                            } else if (m.getParameterTypes()[0] == long.class) {
                                m.invoke(conf, Long.valueOf(value).longValue());
                            } else if (m.getParameterTypes()[0] == double.class) {
                                m.invoke(conf, Double.valueOf(value).doubleValue());
                            } else if (m.getParameterTypes()[0] == float.class) {
                                m.invoke(conf, Float.valueOf(value).floatValue());
                            } else if (m.getParameterTypes()[0] == String.class) {
                                m.invoke(conf, value);
                            }
                        }
                    } catch (Exception e) {
                        log.error(
                            "Error parsing environment " + entry.getKey() + "=" + entry.getValue()
                                + " : ", e);
                    }
                });
            });
        return conf;
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants