-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add public API to load configuration files #16864
Conversation
It allows to load config from an external file and then customize it programmatically. This is useful when embedding Hazelcast into managed environments: When a runtime container wants to create an instance as if it was created via `Hazelcast.newHazelcastInstance()`, but it wants to inject an instance of `ManagedContext` into Hazelcast configuration. Without this capability all containers have to duplicate the `Config` location strategy: "First try this, then that, etc." Related to spring-projects/spring-boot#19487 TODO: Tests
…experiments/populate-config-from-default
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.
I like the change 👍
One improvement idea. Since this logic has become a public API now, perhaps it would make sense going forward to let the user control what happens if no config is found. Unsuccessful load attempts might indicate a deployment/environment issue that one might want to fail fast if it happens. So something like Config#load(MissingConfigFileBehavior)
and
enum MissingConfigFileBehavior {
LOAD_DEFAULT_CONFIG,
THROW_EXCEPTION
}
with
Config#load() {
load(LOAD_DEFAULT_CONFIG);
}
WDYT?
Thanks @blazember . I'll actually let you and the Core team decide on |
hazelcast/src/main/java/com/hazelcast/client/config/ClientConfig.java
Outdated
Show resolved
Hide resolved
@@ -168,6 +172,45 @@ public ClientConfig(ClientConfig config) { | |||
metricsConfig = new ClientMetricsConfig(config.metricsConfig); |
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.
Do we log which file got loaded? So that at least from the logging it is obvious which file is being used. It can be extremely annoying if you are fighting an configuration issue and then you finally determine that your file didn't get loaded in the first place.
I had that problem a few times with simulator and every time I wanted to smack my head into my desk.
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.
I think that we do log it. At least I see something like this in the logs:
INFO: Loading configuration '/opt/hazelcast/hazelcast.yaml' from System property 'hazelcast.config'
Perhaps it is simplest to return null or an exception instead of adding a strategy? KISS null can be checked and exception can be caught; especially when properly documented. |
verify |
Add
load()
method toConfig
,ClientConfig
, andClientFailoverConfig
. This method loads the config with the "known" locations. If not found, the default config is returned.fix #16809
Related to spring-projects/spring-boot#19487
This is the completion of the initial work done by @jerrinot and opened as a draft PR: #16386, I addressed all the comments from there.