bahmni-erp-connect application properties not getting overridden by system or env properties

Description

Problem:

  • Bahmni-erp-connect loads all properties from a packaged file "atomfeed.properties".
    However

  • The properties are loaded such a way that one can not override the properties through system or env variables. For example: if the openerp instance is not on localhost, then this can not be overriden. same for any other properties like user/pwd for other systems (OpenMRS, OpenELIS etc). By convention, all bahmni services properties should be externalizable and for this specific service, it is done through
    "/opt/bahmni-erp-connect/etc/bahmni-erp-connect.conf". Right now, this is not so.

  • Also, some of the beans are getting registered twice. This can be validated by using a @PostConstruct annotated method in "OpenERPAtomFeedProperties.java".

Additional Context
1. Bahmni-erp-connect is an integrator service doing the sync between OpenMRS<->OpenERP
2. Bahmni-erp-connect is essentially the openerp-atomfeed-service packaged to run with embedded tomcat.

Building Bahmni-erp-connect
1. in "openerp-atomfeed-service": mvn clean install

  • will generate "openerp-atomfeed-service.war"
    2. Copy the war file to bahmni-package/bahmni-erp-connect/resources

  • cd to bahmni-package/bahmni-erp-connect

  • ./gradlew buildrpm to build the rpm

  • you might want to bump up the version of the rpm. To do so, you can change "bahmni-package/gradle.properties" => bahmniRelease
    3. Copy the rpm to target machine.

  • install by command: rpm -Uvh <bahmni-erp-connect-0.92-1.noarch.rpm>

In Scope:
1. "openERPFeedServiceContext.xml" - change definition of

  • <contextroperty-placeholder location="classpath:atomfeed.properties"/>
    to something like below (or use appropriate properties when using the <contextroperty-placeholder>

  • <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:atomfeed.properties</value>
    </list>
    </property>
    <property name="searchSystemEnvironment" value="true"/>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    </bean>

2. the "web.xml" file registers 2 contexts, and also has duplicate component scanning. One is through dispatcher servlet, and the other through contextConfigListener. There are several times the components are getting scanned and recreated.

  • "openerpmvc-config.xml"

  • openERPFeedServiceContext.xml

  • applicationContext-openerp-client

Separate out the atomfeed library component definitions in another context file. (right now, its loaded from "atomFeedContext.xml" imported from dependency "atomfeed-spring-server.jar")
In "openERPFeedServiceContext.xml"
a) remove the line
<import resource="classpath:atomFeedContext.xml"/>
b) add a new context xml (e.g. erp-atomfeed-context.xml) with the content of the "atomFeedContext.xml" but replace the properties definition: <contextroperty-placeholder location="classpath*:*.properties"/>

c) import the new context xml in "openERPFeedServiceContext.xml"
<import resource="classpath:erp-atomfeed-context.xml"/>

4. Refactor "OpenERPAtomFeedProperties.java"

  • Don't use ResourceBundle to load the properties.

  • use annotation like "@Value("${openerp.host}") over appropriate fields. use the field(s) to return value for the methods.

Pointers to Test
1. Ensure that the properties are loaded only once.

  • For this, modify the log4j.xml file (bahmni-erp-connect/WEB-INF/classes/log4j.xml) and change level to DEBUG.

  • Check the output (either in /home/bahmni/nohup.out or /var/log/bahmni-erp-connect/bahmni-erp-connect.log) for the text "DEBUG OpenERPAtomFeedProperties", the properties will be listed below.

2. Ensure that you can change the properties from external means
There are 2 ways to do so (lets take example of "scheduler.initial.delay" property)
a) From java command line: you can use "-D" options to pass any parameter. However to do this, you will have to change the "bahmni-erp-connect/bin/start.sh" to something like

> " .... java -jar -Dscheduler.start.delay=12500 $SERVER_OPTS /opt/bahmni-erp-connect/lib/bahmni-erp-connect.jar ... "

Note the above is in plain text, but you can inject through another system variable and use something like
> " .... java -jar -Dscheduler.start.delay=$SCHEUDLER_START_DELAY $SERVER_OPTS /opt/bahmni-erp-connect/lib/bahmni-erp-connect.jar ... "

the SCHEUDLER_START_DELAY can be specified in "bahmni-erp-connect/etc/bahmni-erp-connect.conf". This conf file lists all env variables that are exported first. The reason for capitalisation/renaming to "SCHEUDLER_START_DELAY" is that "." (dot) is allowed for variable exported from system commands.

b) From external file configuration: bahmni-erp-connect properties now can be overridden by another file that needs to be mentioned through a system property called "APP_PROPERTIES_FILE". So you can create a file where the application can read from (must have rights) and mention the file location as the above parameter. For example
i) Create a file "/home/bahmni/bahmi-erp-connect.properties" and add the property
scheduler.start.delay=12500

ii) in "bahmni-erp-connect/etc/bahmni-erp-connect.conf", export a property
export APP_PROPERTIES_FILE=file:/home/bahmni/bahmni-erp-connect.properties

Restart bahmni-erp-connect service and check the properties. You can use this to change database connection properties as well (E.g. username, password).

Few other things to test
1. Make sure you can access the following URLs and have some results returned (to be hit from the machine the service runs)

curl http://localhost:8053/bahmni-erp-connect/tasks
curl http://localhost:8053/bahmni-erp-connect/feed/product/recent

2. Ensure that the integration of OpenMRS and OpenERP are working fine.

  • Create a concept with class Radiology and ensure it syncs to ERP as product

  • Order the concept and see a quotation is raised in ERP

PR: https://github.com/Bahmni/openerp-atomfeed-service/pull/3

Activity

Show:
Angshuman Sarkar
February 28, 2019, 2:19 PM
Edited

This must be resolved first before any work on BAH-406

Himabindu Akkinepalli
April 23, 2019, 6:49 AM
Angshuman Sarkar
April 26, 2019, 12:53 PM
Edited

Tested on qa08 (0.91 patch)

  • with command line parameter. edited "/opt/bahmni-erp-connect/bin/start.sh" to add -D parameter
    > nohup $JAVA_HOME/bin/java -jar -Dscheduler.initial.delay=30000 $SERVER_OPTS /opt/bahmni-erp-connect/lib/bahmni-erp-connect.jar &
    > echo $! > /var/run/bahmni-erp-connect/bahmni-erp-connect.pid

  • change "/opt/bahmni-erp-connect/bahmni-erp-connect/WEB-INF/classes/log4j.xml" to change root logger level to 'DEBUG'. also added a console appender

<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [openerp-atomfeed-service] [%c] %m%n"/>
</layout>
</appender>

<root>
<priority value="DEBUG"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="console"/>
</root>

  • restarted bahmni-erp-connect service, check /home/bahmni/nohup.out, and verified that "scheduler.initial.delay=30000" instead of default 60000

Angshuman Sarkar
April 26, 2019, 1:08 PM

Tested on product-qa08 (0.91 patch) with "APP_PROPERTIES_FILE"

  • added a file "/home/bahmni/bahmni-erp-connect.properties", containing a variable
    > scheduler.initial.delay=15000

  • changed "/opt/bahmni-erp-connect/etc/bahmni-erp-connect.conf" and added line
    > export APP_PROPERTIES_FILE=file:/home/bahmni/bahmni-erp-connect.properties

  • restart "bahmni-erp-connect" service

  • checked /home/bahmni/nohup.out, and verified that "scheduler.initial.delay=15000" instead of default 60000

Angshuman Sarkar
April 26, 2019, 1:23 PM
  • verified the above 2 approaches (using cmd line pararmeter using -D option, and also using external APP_PROPERTIES_FILE) on qa03 (0.92)

Fixed

Assignee

Angshuman Sarkar

Reporter

Angshuman Sarkar

Labels

Units

None

PercentDone

None

DueTime

None

Clients

None

External issue ID

None

UAT Assignee

angshuman sarkar

Reviewer

Himabindu Akkinepalli

Components

Sprint

0.93 Product M1

Fix versions

Configure