New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple configuration contexts #48
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this LGTM overall. A few comments inline. Thx, @helpermethod!
|
||
@Option(names = { "--cluster" }, description = "URL of the Kafka Connect cluster to connect to", required = true) | ||
@Option(names = {"--cluster"}, description = "URL of the Kafka Connect cluster to connect to", required = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we default the options? http://localhost:8083 and localhost:9092 seem reasonable for KC and broker URLs? For the offset topic, we could leave that optional. If if it's not set for a given context, the future commands interacting with offsets wouldn't work without it, stating the need to specify a value in the chosen context. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
configuration.addConfigurationContext(contextName, context) | ||
); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Couldn't write context file ~/" + CONFIG_FILE, e); | ||
} | ||
} | ||
|
||
public URI getCluster() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method go away entirely, and all access be via getContext()
? And we'd log an error if no context has been defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By logging you mean logging to STDOUT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly.
@MethodSource("dev.morling.kccli.util.ConfigurationContextTest#setConfigurationArguments") | ||
@ParameterizedTest | ||
void should_create_a_new_configuration_when_no_configuration_exists(String contextName, Context context, String expectedConfiguration) throws IOException { | ||
System.setProperty("user.home", tempDir.getAbsolutePath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat trick :) Alternatively, there could be a constructor in ConfigurationContext
which takes the config directory, while the default constructor would use the home dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had the exact same idea, but didn't want to change too much code at first. Good suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
var configuration = objectMapper.readValue(configPath, Configuration.class); | ||
|
||
return configuration.configurationContexts().get(configuration.getCurrentContext()); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Couldn't read configuration file ~/" + CONFIG_FILE, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a sentence like "Create/update your configuration by running 'kcctl set-context ...'".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Yes, that's ok. We only should log a meaningful error in that case. Other than that, could you
Thanks again! |
c02d392
to
b5c24e5
Compare
Now adding a few lines to the README.md. |
Hi @gunnarmorling, that push should resolve most, if not all of your comments 馃槃. |
@helpermethod, could you also re-generate the completion script (see instructions in the README) for the new options? |
Thanks a lot, @helpermethod! So I've played around a bit, it looks great overall. I wonder though if we can make the experience a bit smoother by default, i.e. if the user has not configured any context yet. How about the following if no context has been configured:
WDYT? |
Great suggestions, I'll incorporate them over the weekend! |
@helpermethod, if you'd like me to wrap up this one, just let me know. Would love to have it in, so we can get to the offset reset stuff :) |
Hi @gunnarmorling, I'm on it, I'm currently stuffed with work so it's not easy to find some uninterrupted time 馃槃. I don't quite get the difference between
So in any case basically a warning is printed and a default is returned? |
8bbbecc
to
7c4ac6e
Compare
Yes, that'd be the idea. Only the wording of the messages might be slightly different ("Using..." for actual commands vs. "Will use..." for get-context), but perhaps I'm overthinking it and we can have one which fits for both :) |
@helpermethod, there's a few odd changes part of this now, like version downgrades in the POM and removal of the Dependabot config. |
Messed up the latest commit, fixing it right now. |
I hope that should do it 馃槄! |
Yepp, LGTM. Applied. Thanks a lot! |
Hi @gunnarmorling,
here comes the PR! I hope I've got the the requirements right 馃槃.
One thing I would like to challenge is supporting the old, properties-like config format. Because we are still pre 1.0.0, I guess it would be acceptable to not support the current (properties-like) configuration format anymore. Wdyt?
The current, context-aware format is very flexible, except for the context-name and cluster URL, every other property is
optional.
So both
and
are valid.
Fixes #24.