[CONTROLLER-1758] Class FileModuleShardConfigProvider does not load configurations from classpath properly Created: 25/Aug/17  Updated: 25/Jul/23  Resolved: 04/Sep/17

Status: Resolved
Project: controller
Component/s: mdsal
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Samuel Kontris Assignee: Jakub Toth
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 9056

 Description   

Loading configurations from classpath in class FileModuleShardConfigProvider [1] does not work properly, because it tries to read from file name instead of file path.

This is code that read configs:

Config moduleShardsConfig = null;
if (moduleShardsFile.exists())

{ LOG.info("module shards config file exists - reading config from it"); moduleShardsConfig = ConfigFactory.parseFile(moduleShardsFile); } else { LOG.warn("module shards configuration read from resource"); moduleShardsConfig = ConfigFactory.load(moduleShardsFile.getName()); // <------------------- }

Config modulesConfig = null;
if (modulesFile.exists()) { LOG.info("modules config file exists - reading config from it"); modulesConfig = ConfigFactory.parseFile(modulesFile); } else { LOG.warn("modules configuration read from resource"); modulesConfig = ConfigFactory.load(modulesFile.getName()); // <------------------- }

And it should look something like this:

Config moduleShardsConfig = null;
if (moduleShardsFile.exists()) { LOG.info("module shards config file exists - reading config from it"); moduleShardsConfig = ConfigFactory.parseFile(moduleShardsFile); }

else

{ LOG.warn("module shards configuration read from resource"); final String path = moduleShardsFile.getPath().replace("\\", "/"); // in case of windows OS moduleShardsConfig = ConfigFactory.load(path); }

Config modulesConfig = null;
if (modulesFile.exists())

{ LOG.info("modules config file exists - reading config from it"); modulesConfig = ConfigFactory.parseFile(modulesFile); }

else

{ LOG.warn("modules configuration read from resource"); final String path = modulesFile.getPath().replace("\\", "/"); // in case of windows OS modulesConfig = ConfigFactory.load(path); }

[1] - org.opendaylight.controller.cluster.datastore.config.FileModuleShardConfigProvider



 Comments   
Comment by Jakub Toth [ 30/Aug/17 ]

In this way, we don't need to use replace method on getPath() because the resulting string uses the system-dependent default name-separator character to separate the names. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '
'.

https://git.opendaylight.org/gerrit/#/c/62439/

Comment by Juraj Veverka [ 04/Sep/17 ]

(In reply to Jakub Toth from comment #1)
> In this way, we don't need to use replace method on getPath() because the
> resulting string uses the system-dependent default name-separator character
> to separate the names. This field is initialized to contain the first
> character of the value of the system property file.separator. On UNIX
> systems the value of this field is '/'; on Microsoft Windows systems it is
> '
'.
>
> https://git.opendaylight.org/gerrit/#/c/62439/

this is true, but in this case is file path used as classpath and on systems with File.separator != '/' this code will never work.
to avoid character replacements, you can use string paths directly like this:

moduleShardsConfig = ConfigFactory.load(moduleShardsConfigPath);
modulesConfig = ConfigFactory.load(modulesConfigPath);

original strings are private members of FileModuleShardConfigProvider class.

Comment by Jakub Toth [ 04/Sep/17 ]

https://git.opendaylight.org/gerrit/#/c/62634

Generated at Wed Feb 07 19:56:23 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.