Hello all,
After a few years of analyze, test and implementation, Néréide team have
the pleasure to share an improvement of the configuration system.
What's going on.
With OFBiz dockerization, the OFBiz configuration management appears as
the big framework limitation.
It's not really easy to override some OFBiz configuration without
editing sensitive files of the framework and hard to work with
environment variable without framework code change.
We already discussed this on different issues like OFBIZ-12401[1],
OFBIZ-9498[2] or OFBIZ-10407[3]
So to solve this issue, we completely changed our point of view on how
configs could work.
- First we implemented the library typesafe Config[4] to have the
ability to read some configuration from HOCON file.
- Second, we changed how OFBiz reads xml configuration file.
Before, each file was read from a Sax stream to convert each element as
a Java class. Now we load each element from their XPath to Java class.
This way, we can have a unique id of each element.
- Third, we implement an override system through typesafe config to
check if we have a override element configuration on Hocon file. This
can allow to override a value or load a global configuration tree.
When you run OFBiz, a new container initializes the configuration
system, System and variable environment, collects all Hocon files and
merge it in a config object.
Next when a configuration reader runs, it loads xml file definition and
override value from typesafe config.
Example 1 :
you want use postgres with environment variable just put on your plugins
conf directory
All you have to add is this file
```json
// plugins/myplugin/conf/mydb.conf
{
"entityengine": {
"entity-config": {
"delegator": {
"default": {
"group-map": {
"org.apache.ofbiz": {"datasource-name": "localpostgres"}
}
}
}
"datasource": {
"localpostgres": {
"inline-jdbc": {
"jdbc-uri": "${POSTGRES_URI}",
"jdbc-username"="${POSTGRES_USER}",
"jdbc-password"="${POSTGRES_PWD}"
}
}
}
}
}
}
```
You don't have to edit any other files.
Example 2:
You can do more with adding new definitions like add new service engine,
directly in an plugin
```json
// plugins/myplugin/conf/engine.conf
{
"serviceengine": {
"service-config": {
"service-engine": {
"default": {
"engine": {
"name": "newEngine"
"class": "com.company.plugins.service.MyServiceEngine"
}
}
}
}
}
}
```
Example 3:
This way our plugin will work well on any OFBiz that support this config
implementation. Also with the capability from typesafe config to merge
them, you can keep each file as simple as possible.
An other improvement is that it also worls for property files
```json
//plugins/myplugin/conf/other-properties.conf
{
"general": {
"unique": {
"instanceId": "ofbizOverride"
}
},
"number": {
"default": {
"displaying" {
"format": "##0.000"
}
}
}
}
```
Example 4:
All of the above can be put in the same file
```json
//plugins/myplugin/conf/other-properties.conf
{
"entityengine": {
"entity-config": {
"delegator": {
"default": {
"group-map": {
"org.apache.ofbiz": {"datasource-name": "localpostgres"}
}
}
}
"datasource": {
"localpostgres": {
"inline-jdbc": {
"jdbc-uri": "${POSTGRES_URI}",
"jdbc-username"="${POSTGRES_USER}",
"jdbc-password"="${POSTGRES_PWD}"
}
}
}
}
}
"serviceengine": {
"service-config": {
"service-engine": {
"default": {
"engine": {
"name": "newEngine"
"class": "com.company.plugins.service.MyServiceEngine"
}
}
}
}
}
"general": {
"unique": {
"instanceId": "ofbizOverride"
}
},
"number": {
"default": {
"displaying" {
"format": "##0.000"
}
}
}
}
```
If you don't want use typesafe on your instance, you can easily disable it.
If you don't want to change anything, do nothing, the implementation is
fully retro-compatible.
To prevent the maximum possible number of regression, we implemented a
lot of unit tests to read current configuration file.
We share this first step on the concept that works well on properties
files and entityengine.
Depending on your suggestion and feedback, we plan to simplify
configuration file by splitting them into sample files.
And next big step, we want to have in webtools for super admin an
interface that displays each configuration and its origin.
We can have a look on it through pull request 1285 [5]
Any remarks are welcome to move forward on this big subject !
Nicolas on behalf Néréide Team
[1] https://issues.apache.org/jira/browse/OFBIZ-12401
[2] https://issues.apache.org/jira/browse/OFBIZ-9498
[3] https://issues.apache.org/jira/browse/OFBIZ-10407
[4] https://github.com/lightbend/config
[5] https://github.com/apache/ofbiz-framework/pull/1285