Skip to content

Commit

Permalink
Fix regression in declarative config file resolution
Browse files Browse the repository at this point in the history
3.12 introduced a regression that configuration files with suffixes not
in [xml,yaml,yml] passed in system property are ignored silently and
the config resolution continues following the resolution priority, most
likely resolving the default XML configuration shipped with the jar. The
expected behavior is:
- if the system property is set we fail fast if we can't load the config
from the referenced resource/file
- if the file in the system property has a suffix [yaml,yml], we treat it
as YAML config
- if the file in the system property has any other suffix (or don't have
suffix), we treat it as XML config

Note that in 4.0 the fix will be different, we enforce the config files
to have suffix from the [xml,yaml,yml] list.

This commit fixes this behavior in member, client and client-failover
config resolution, with additional tests verifying the resolution logic.

Fixes hazelcast#14924
  • Loading branch information
blazember committed Apr 26, 2019
1 parent bacf1f1 commit f970fca
Show file tree
Hide file tree
Showing 39 changed files with 2,357 additions and 37 deletions.
Expand Up @@ -24,9 +24,17 @@
*/
public class XmlClientConfigLocator extends AbstractConfigLocator {

public XmlClientConfigLocator() {
super(false);
}

public XmlClientConfigLocator(boolean failIfSysPropWithNotExpectedSuffix) {
super(failIfSysPropWithNotExpectedSuffix);
}

@Override
public boolean locateFromSystemProperty() {
return loadFromSystemProperty("hazelcast.client.config", "xml");
return loadFromSystemProperty("hazelcast.client.config");
}

@Override
Expand Down
Expand Up @@ -24,9 +24,17 @@
*/
public class XmlClientFailoverConfigLocator extends AbstractConfigLocator {

public XmlClientFailoverConfigLocator() {
super(false);
}

public XmlClientFailoverConfigLocator(boolean failIfSysPropWithNotExpectedSuffix) {
super(failIfSysPropWithNotExpectedSuffix);
}

@Override
public boolean locateFromSystemProperty() {
return loadFromSystemProperty("hazelcast.client.failover.config", "xml");
return loadFromSystemProperty("hazelcast.client.failover.config");
}

@Override
Expand Down
Expand Up @@ -98,7 +98,7 @@ public YamlClientConfigBuilder() {
*/
public YamlClientConfigBuilder(YamlClientConfigLocator locator) {
if (locator == null) {
locator = new YamlClientConfigLocator();
locator = new YamlClientConfigLocator(true);
locator.locateEverywhere();
}

Expand Down
Expand Up @@ -24,6 +24,14 @@
*/
public class YamlClientConfigLocator extends AbstractConfigLocator {

public YamlClientConfigLocator() {
super(false);
}

public YamlClientConfigLocator(boolean failIfSysPropWithNotExpectedSuffix) {
super(failIfSysPropWithNotExpectedSuffix);
}

@Override
public boolean locateFromSystemProperty() {
return loadFromSystemProperty("hazelcast.client.config", "yaml", "yml");
Expand Down
Expand Up @@ -101,7 +101,7 @@ public YamlClientFailoverConfigBuilder() {
*/
public YamlClientFailoverConfigBuilder(YamlClientFailoverConfigLocator locator) {
if (locator == null) {
locator = new YamlClientFailoverConfigLocator();
locator = new YamlClientFailoverConfigLocator(true);
locator.locateEverywhere();
}

Expand Down
Expand Up @@ -24,9 +24,17 @@
*/
public class YamlClientFailoverConfigLocator extends AbstractConfigLocator {

public YamlClientFailoverConfigLocator() {
super(false);
}

public YamlClientFailoverConfigLocator(boolean failIfSysPropWithNotExpectedSuffix) {
super(failIfSysPropWithNotExpectedSuffix);
}

@Override
public boolean locateFromSystemProperty() {
return loadFromSystemProperty("hazelcast.client.failover.config", "yaml");
return loadFromSystemProperty("hazelcast.client.failover.config", "yaml", "yml");
}

@Override
Expand Down
Expand Up @@ -98,14 +98,14 @@ private static ClientFailoverConfig locateAndCreateClientFailoverConfig() {
XmlClientFailoverConfigLocator xmlConfigLocator = new XmlClientFailoverConfigLocator();
YamlClientFailoverConfigLocator yamlConfigLocator = new YamlClientFailoverConfigLocator();

if (xmlConfigLocator.locateFromSystemProperty()) {
// 1. Try loading config if provided in system property and it is an XML file
config = new XmlClientFailoverConfigBuilder(xmlConfigLocator).build();

} else if (yamlConfigLocator.locateFromSystemProperty()) {
// 2. Try loading config if provided in system property and it is an YAML file
if (yamlConfigLocator.locateFromSystemProperty()) {
// 1. Try loading config if provided in system property and it is an YAML file
config = new YamlClientFailoverConfigBuilder(yamlConfigLocator).build();

} else if (xmlConfigLocator.locateFromSystemProperty()) {
// 2. Try loading config if provided in system property and it is an XML file
config = new XmlClientFailoverConfigBuilder(xmlConfigLocator).build();

} else if (xmlConfigLocator.locateInWorkDirOrOnClasspath()) {
// 3. Try loading XML config from the working directory or from the classpath
config = new XmlClientFailoverConfigBuilder(xmlConfigLocator).build();
Expand All @@ -125,14 +125,14 @@ private static ClientConfig locateAndCreateClientConfig() {
XmlClientConfigLocator xmlConfigLocator = new XmlClientConfigLocator();
YamlClientConfigLocator yamlConfigLocator = new YamlClientConfigLocator();

if (xmlConfigLocator.locateFromSystemProperty()) {
// 1. Try loading config if provided in system property and it is an XML file
config = new XmlClientConfigBuilder(xmlConfigLocator).build();

} else if (yamlConfigLocator.locateFromSystemProperty()) {
// 2. Try loading config if provided in system property and it is an YAML file
if (yamlConfigLocator.locateFromSystemProperty()) {
// 1. Try loading config if provided in system property and it is an YAML file
config = new YamlClientConfigBuilder(yamlConfigLocator).build();

} else if (xmlConfigLocator.locateFromSystemProperty()) {
// 2. Try loading config if provided in system property and it is an XML file
config = new XmlClientConfigBuilder(xmlConfigLocator).build();

} else if (xmlConfigLocator.locateInWorkDirOrOnClasspath()) {
// 3. Try loading XML config from the working directory or from the classpath
config = new XmlClientConfigBuilder(xmlConfigLocator).build();
Expand Down

0 comments on commit f970fca

Please sign in to comment.