Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

leszko
Copy link

@leszko leszko commented Apr 24, 2019

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

fix #16074

Signed-off-by: Rafal Leszko rafal@hazelcast.com

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 24, 2019
Copy link
Member

@snicoll snicoll left a 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",
Copy link
Member

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.

Copy link
Author

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:

  1. System property: the file located in the hazelcast.config JVM argument, if present. It can be either XML or YAML.
  2. A file named hazelcast.xml located in the application's working directory
  3. A file named hazelcast.xml located on the classpath
  4. A file named hazelcast.yaml located in the application's working directory
  5. A file named hazelcast.yaml located on the classpath
  6. 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
Copy link
Member

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?

Copy link
Author

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;
Copy link
Member

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.

Copy link
Author

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",
Copy link
Member

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
Copy link
Member

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?

Copy link
Author

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" />
Copy link
Member

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?

Copy link
Author

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"/>
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Apr 25, 2019
Copy link
Author

@leszko leszko left a 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",
Copy link
Author

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:

  1. System property: the file located in the hazelcast.config JVM argument, if present. It can be either XML or YAML.
  2. A file named hazelcast.xml located in the application's working directory
  3. A file named hazelcast.xml located on the classpath
  4. A file named hazelcast.yaml located in the application's working directory
  5. A file named hazelcast.yaml located on the classpath
  6. 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
Copy link
Author

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;
Copy link
Author

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
Copy link
Author

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" />
Copy link
Author

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"/>
Copy link
Author

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>
@snicoll snicoll self-assigned this Apr 29, 2019
snicoll pushed a commit that referenced this pull request Apr 29, 2019
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
@snicoll snicoll closed this in 704da17 Apr 29, 2019
snicoll added a commit that referenced this pull request Apr 29, 2019
* pr/16632:
  Polish "Add support for Hazelcast YAML configuration"
  Add support for Hazelcast YAML configuration
@snicoll
Copy link
Member

snicoll commented Apr 29, 2019

@leszko thank you for making your first contribution to Spring Boot and following up quickly on feedback. This is now merged in master with a polish commit. What I've changed in particular is the check on xml vs. yaml, with an explicit check on yaml and a fallback on xml rather than the other way around.

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.

@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Apr 29, 2019
@snicoll snicoll added this to the 2.2.0.M3 milestone Apr 29, 2019
@leszko
Copy link
Author

leszko commented May 20, 2019

Thanks @snicoll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support YAML for Hazelcast configuration
3 participants