-
Couldn't load subscription status.
- Fork 41.6k
Add auto-configuration support for Hazelcast client #7469
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
Conversation
|
I had a very quick look and my immediate reaction is to have a This has the advantage of leaving the current auto-configuration untouched and we can add a simple condition to make sure the server-side of things backs off if the client is configured All things considered, I am wondering if the auto-configuration of a separate Don't worry about having to set the type now for everything. We should move some of these in separate integration tests ( Can you rework the first part to separate the client in its own auto-config? Does that make sense? |
|
Thanks for the quick feedback @snicoll.
It makes sense, and actually it was the approach I've initially taken but the
Same thoughts here. |
The other thing must be an So should we remove that separate auto-configuration in caching? |
Yep, I've paid special attention to that part as well.
Are you referring to |
|
No overlap. It's a crazy idea I had and that I deeply regret now. Basically you can auto-configure Hazelcast and have a separate instance (with a different configuration) for caching purposes only. |
|
It sounds reasonable to remove the support for configuring a separate cache dedicated instance and guide users towards general Hazelcast instance auto-config. It just feels more natural that way, and 2.0 looks like an ideal target for a such change. I've updated the PR. |
|
@snicoll Is there anything further you need me to provide, given that I've updated the PR yesterday and the label |
|
Nope, thanks. |
|
I've rebased this against current
EDIT: Scratch that, build passed on TravisCI. |
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.
It's a very good first step, thank you. But I believe we should simplify the current proposal. Let me know what you think.
| @ConditionalOnClass(HazelcastInstance.class) | ||
| @ConditionalOnMissingBean(HazelcastInstance.class) | ||
| @EnableConfigurationProperties(HazelcastProperties.class) | ||
| @AutoConfigureAfter(HazelcastClientAutoConfiguration.class) |
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.
Rather than having two distinct auto-configuration, I'd like that we merge those in the same HazelcastAutoConfiguration with a HazelcastClientConfiguration and a HazelcastServerConfiguration.
It would be nice if we could have a spring.hazelcast.mode enum (HazelcastMode) that could either be CLIENT or SERVER. The default value would be to detect what would work in practice at runtime.
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.
😄 If you recall, that was exactly the situation when PR was initially opened (see your first comment on this PR). I've also been undecided between the two.
I'll try to go back to single HazelcastAutoConfiguration again with the next PR update.
| extends HazelcastClientConfigResourceCondition { | ||
|
|
||
| ClientConfigAvailableCondition() { | ||
| super("spring.hazelcast", "client-config"); |
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.
Is there a reason why you'd want to have a dedicated property for this. If you look at how Hazelcast has implemented the JSR-107 support they have a server and client flag (that leads to two CacheProvider implementations and each of them read the same properties as far as I know). I would not deviate from that so, IMO, that should read spring.hazelcast.config.
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 guess there shouldn't be a reason we couldn't reuse the existing property. Initially I went with simplest approach when putting this PR together, at the expense of some code duplication. I'll address this with next update.
|
|
||
| static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.client.config"; | ||
|
|
||
| protected HazelcastClientConfigResourceCondition(String prefix, String propertyName) { |
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.
Perhaps there is a way to abstract more since all that should change is the name of the file (hazelcast.xml vs. hazelcast-client.xml).
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.
Agreed.
| * @author Vedran Pavic | ||
| * @since 2.0.0 | ||
| */ | ||
| public class HazelcastClientInstanceFactory { |
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.
speaking out loud, I wonder if two different factories are deserved for this. Perhaps we should restructure the one we have a bit so that we could create a server or a client HazelcastInstance.
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.
Agreed.
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.
After looking into this a bit more I'd say we could even remove both factories. HazelcastInstanceFactory was introduced quite a while ago in db41fb1 to (from what I call tell) avoid having HazelcastCacheConfiguration directly rely on HazelcastAutoConfiguration#createHazelcastInstance. With your changes from #8470 there are no more uses of HazelcastInstanceFactory outside of HazelcastAutoConfiguration so we could move that logic back in there. 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.
We could but it's public API so I'd rather break the contract than remove it completely. It doesn't hurt to offer the feature to create an HazelcastInstance based on a Resource anyway.
| public static void close() { | ||
| System.clearProperty("hazelcast.jcache.provider.type"); | ||
| } | ||
|
|
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 don't like that. You shouldn't mess with this in the general CacheAutoConfiguration. Is it because the client is now on the classpath and the JCache support doesn't know what to do?
If that's the case, we should fix the JCache implementation to set the right flag based on the HazelcastInstance that is available.
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, it's due to client being on the classpath and Hazelcast prefers it in that case. See HazelcastCachingProvider#createClientProvider.
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.
If that's the case, that's what the test should assert then. And you should have a test that filters out the client (see that JUnit rule) to restore what happens when the client jar isn't on the classpath.
| * @author Stephane Nicoll | ||
| * @author Vedran Pavic | ||
| */ | ||
| public class AbstractHazelcastAutoConfigurationTests { |
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.
Meh. I'd really like we avoid separating things like that. In particular we could test what happens when both the server and the client is available (the client wins?). And then we could add an explicit spring.hazelcast.mode that sets the other one and we can validate the right instance has been auto-configured.
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.
There is such test already, see HazelcastClientAutoConfigurationTests#clientConfigHasPriority. I guess when we go back to single HazelcastAutoConfiguration it should help the situation with tests too.
|
@snicoll I've updated the PR to address your comments. However I didn't add
|
|
I am confused. Say that you have the If I understood properly, this use case will always attempt to create a client and you'll have no way to force it to use another mode. The only way you'll be able to force that is by excluding the client auto-configuration part but we've merged it into one (which IMO is the right call). Unless I am missing something, you need a way to tell us that looking at the classpath isn't enough to figure out the mode to use. The fact the issue you referenced is implemented or not makes no difference (a.k.a. you can't ensure that all apps will have a clean classpath). Having said that, it is a corner case for the property so perhaps we should create it only if someone complains. Let me know if I've missed anything. |
|
Thanks for the quick feedback.
Correct. Currently the only way to achieve this is by removing Hazelcast client from the classpath. I agree it's not ideal but I too consider this to be a corner case.
Yes, but the thing that bothers me with |
|
@snicoll How near is this to going live ? It may need amended again for the arrival of [http://jet.hazelcast.org/](Hazelcast Jet) which embeds jars from [https://hazelcast.org/](Hazelcast IMDG) |
|
@neilstevenson I have not make up my mind about the two properties yet. I have no idea what "Hazelcast Jet" is nor what you mean by "amending again". |
|
@snicoll I've logged #8863 to outline Hazelcast IMDG Client & Server and Hazelcast Jet Client & Server, with a link to sample project on github - #8863 I'm happy to make a fork to fix the issue myself, but just don't want this to clash with work already underway for this issue. Let me know what you'd prefer. |
|
Thanks for creating the issue; the reference to a sample is also much appreciated. Let's follow up there. |
How does it mess with them exactly? IMO, you are looking to this from a Hazelcast perspective, not a Spring Boot perspective. Spring Boot has an auto-configuration model so it can be smart about the environment and should provide a way-out if the smartness doesn't do the thing that the user is expecting. I hazelcast had such tool, I am not sure they would have come up with two distinct properties for this. Having said that, you made your case and I think we can introduce that property later if users are complaining. After all, if you have both on the classpath and you don't want to use the client and your config file is not using the default scheme, you're already quite far in customizations. That mode would be useful only for that. I'll resume without the mode then, thank you very much! |
What I've meant to say by that, but perhaps wasn't clear enough, is that In contrast two properties for config location would be focused on only that configuration scenario. But I agree your approach to start simple and introduce any additional configuration properties if the need arises. |
* pr/7469: Polish "Add auto-configuration support for Hazelcast client" Add auto-configuration support for Hazelcast client
|
Merged, thanks @vpavic! In the end I changed my mind on some minor area (typically the factory thing). |
As discussed in #4918, this is a WIP effort on auto-configuration support for Hazelcast client.
Most of the parts should be covered by this PR, however the tricky part is auto-config prioritization between server and client modes and I'm not quite sure how to approach that (
HazelcastClientAutoConfigurationTestsare failing).Hazelcast itself of course prefers client if both are available (see
HazelcastCachingProviderconstructor as an example) - this is whyCacheAutoConfigurationTestsrequired setting uphazelcast.jcache.provider.typeoncehazelcast-clientwas available on the classpath./cc @snicoll @neilstevenson