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 support for Hazelcast YAML configuration #16632
Conversation
Since Hazlecast 3.12, YAML configuration format is supported in addition to XML. Therefore, this change makes Spring Boot automatically discover not only `hazelcast.xml` (and `hazelcast-client.xml`), but also `hazelcast.yaml` (and `hazelcast-client.yaml`). Signed-off-by: Rafal Leszko <rafal@hazelcast.com>
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.
Thank you very much for opening your first PR. I've added some questions and suggestions. Also wondering if Hazelcast work with .yaml
and .yml
files. The latter is not taken into account and yet is a valid file extension.
@@ -79,7 +79,8 @@ public HazelcastInstance hazelcastInstance(ClientConfig config) { | |||
|
|||
ConfigAvailableCondition() { | |||
super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml", | |||
"classpath:/hazelcast-client.xml"); | |||
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", |
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 should probably group them (file
and classpath
) rather than mixing them. The order in this list is the precedence order so it must match the expectation. Right now, an xml file on the classpath has precedence over a yaml file at the root. That doesn't sound right to me.
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.
That is actually what we do in Hazelcast to be backwards-compatible. Before there was only XML, so it takes the precedence. The exact algorithm for Hazelcast is as follows:
- System property: the file located in the hazelcast.config JVM argument, if present. It can be either XML or YAML.
- A file named hazelcast.xml located in the application's working directory
- A file named hazelcast.xml located on the classpath
- A file named hazelcast.yaml located in the application's working directory
- A file named hazelcast.yaml located on the classpath
- The default configuration hazelcast-default.xml we distribute in our jar files
if (configFileName.endsWith(".xml")) { | ||
return new XmlClientConfigBuilder(configUrl).build(); | ||
} | ||
else { // yaml config available in the classpath |
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.
What does this comment mean?
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.
Actually it's useless, removed.
Config config = new XmlConfigBuilder(configUrl).build(); | ||
String configFileName = configUrl.getFile(); | ||
|
||
Config 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.
Rather than having a field initialization, I'd create a private method that returns the Config
instance.
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.
Changed
@@ -77,7 +77,8 @@ public HazelcastInstance hazelcastInstance(Config config) { | |||
|
|||
ConfigAvailableCondition() { | |||
super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast.xml", | |||
"classpath:/hazelcast.xml"); | |||
"classpath:/hazelcast.xml", "file:./hazelcast.yaml", |
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.
Same ordering remark
@@ -39,6 +39,8 @@ | |||
@Test | |||
public void defaultConfigFile() { | |||
// no hazelcast-client.xml and hazelcast.xml is present in root classpath | |||
// this also asserts that XML has priority over YAML |
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 seems wrong to me that XML on the classpath has priority over YAML on the file system. Is this really what Hazelcast does?
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.
yeah, as explained in the other comment.
@@ -5,7 +5,6 @@ | |||
<map name="defaultCache" /> | |||
<network> | |||
<join> | |||
<tcp-ip enabled="false" /> |
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.
This seems an unrelated change. I am happy to polish the support in a separate commit though. Can you explain why you've removed this line?
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.
Yeah, it's just not used. Reverted. Can be sent in a separate PR.
@@ -2,16 +2,13 @@ | |||
xmlns="http://www.hazelcast.com/schema/config" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |||
|
|||
<queue name="foobar"/> |
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.
Same remark. Is this related to the main purpose of this PR?
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.
Reverted.
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.
@snicoll Thanks for the review. I addressed your comments. PTAL.
Concerning the *.yml
extension, we don't use it automatically in Hazelcast, so I guess the behaviour of Spring Boot should be the same.
@@ -79,7 +79,8 @@ public HazelcastInstance hazelcastInstance(ClientConfig config) { | |||
|
|||
ConfigAvailableCondition() { | |||
super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml", | |||
"classpath:/hazelcast-client.xml"); | |||
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", |
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.
That is actually what we do in Hazelcast to be backwards-compatible. Before there was only XML, so it takes the precedence. The exact algorithm for Hazelcast is as follows:
- System property: the file located in the hazelcast.config JVM argument, if present. It can be either XML or YAML.
- A file named hazelcast.xml located in the application's working directory
- A file named hazelcast.xml located on the classpath
- A file named hazelcast.yaml located in the application's working directory
- A file named hazelcast.yaml located on the classpath
- The default configuration hazelcast-default.xml we distribute in our jar files
if (configFileName.endsWith(".xml")) { | ||
return new XmlClientConfigBuilder(configUrl).build(); | ||
} | ||
else { // yaml config available in the classpath |
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.
Actually it's useless, removed.
Config config = new XmlConfigBuilder(configUrl).build(); | ||
String configFileName = configUrl.getFile(); | ||
|
||
Config 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.
Changed
@@ -39,6 +39,8 @@ | |||
@Test | |||
public void defaultConfigFile() { | |||
// no hazelcast-client.xml and hazelcast.xml is present in root classpath | |||
// this also asserts that XML has priority over YAML |
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.
yeah, as explained in the other comment.
@@ -5,7 +5,6 @@ | |||
<map name="defaultCache" /> | |||
<network> | |||
<join> | |||
<tcp-ip enabled="false" /> |
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.
Yeah, it's just not used. Reverted. Can be sent in a separate PR.
@@ -2,16 +2,13 @@ | |||
xmlns="http://www.hazelcast.com/schema/config" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |||
|
|||
<queue name="foobar"/> |
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.
Reverted.
Signed-off-by: Rafal Leszko <rafal@hazelcast.com>
92b1ca4
to
bd58226
Compare
Since Hazlecast 3.12, YAML configuration format is supported in addition to XML. Therefore, this change makes Spring Boot automatically discover not only `hazelcast.xml` (and `hazelcast-client.xml`), but also `hazelcast.yaml` (and `hazelcast-client.yaml`). See gh-16632
* pr/16632: Polish "Add support for Hazelcast YAML configuration" Add support for Hazelcast YAML configuration
@leszko thank you for making your first contribution to Spring Boot and following up quickly on feedback. This is now merged in Also, tests assertions were all identical so that didn't really test that the right file was loaded. I couldn't fix it for system properties test of the server as I believe I've found an inconsistency in Hazelcast. I've raised hazelcast/hazelcast#14960. Thanks again. |
Thanks @snicoll |
Since Hazlecast 3.12, YAML configuration format is supported in
addition to XML. Therefore, this change makes Spring Boot automatically
discover not only
hazelcast.xml
(andhazelcast-client.xml
), but alsohazelcast.yaml
(andhazelcast-client.yaml
).fix #16074
Signed-off-by: Rafal Leszko rafal@hazelcast.com