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

feat: Enabling context variable to define dhis2_home #6573

Merged

Conversation

delcroip
Copy link
Contributor

@delcroip delcroip commented Nov 5, 2020

To be able to set the dhis2 home from a context var instead of system property so one can have multiple DHIS2 running without messing the env variable (and running multiple tomcat)

Solution inspired from https://stackoverflow.com/questions/372686/how-can-i-specify-system-properties-in-tomcat-configuration-on-startup

Example of context file to put on TOMCAT_HOME/conf/Catalina/localhost/[warname].xml when using Catalina engine and no specific host configured

<Context>

  <Environment name="dhis2-home" value="/home/dhis/config-2"
         type="java.lang.String" override="false"/>

</Context>

I tested the solution, DHIS2 detect the right value

@delcroip delcroip changed the title org.apache.catalina.startup.ContextConfig feat: Enabling context variable to define dhis2_home Nov 5, 2020
…sp/dhis/external/location/DefaultLocationManager.java
@delcroip
Copy link
Contributor Author

Dear @stian-sandvold ,

Is there any issue with that PR, If yes can I help ?

Thanks in advance

br

@larshelge
Copy link
Member

Thanks @delcroip for the patch. Just checking, is there any change in existing behavior here, i.e. would the system still read the DHIS 2 environment variable and system property as before? Which order/priority has the context variable?

@delcroip
Copy link
Contributor Author

Hello @larshelge
the order is this one:
1- systemProperty
2- context variable
3- Env variable

The reason is that in many case the Env variable is used to configure DHIS2; The goal of this change it to have several dhis2 on the same tomcat, so the context variable, when set, should have a priority in order to not mess with the existing DHIS2 install (if any)

best regards

@sonarqubecloud
Copy link

@delcroip
Copy link
Contributor Author

Hello @larshelge ,

I tried to solve a merge issue but it seems I don't respect some rules, the message from sonarcloud is not clear, can you tell me what I did wrong ? (I didn't change anything but add your import which was creating the conflict)
br

@stian-sandvold
Copy link
Contributor

Hey delcroip,

sorry for the slow response.

I had another look at your PR, and have some feedback:

  1. The priority order of the different variables looks good. Looks like the more specific options take priority.
  2. You are swallowing an exception in your PR. It would be great to either log (debug) and/or put a comment explaining why we are swallowing it, and what it implies.
  3. The failing codestyle check is most likely due to the 4 newlines you added on lines 93-96. I don't see any other style-issues just by looking at it.
  4. I do not know exactly what the 3 critical issues from SonarQube is, since the report is not available. But I suspect it's related to swallowing the exception and code complexity of the method. I suspect my problems re-running it is due to the PR residing in your repository and not the dhis2 one.

To me, I'm happy with merging this as long as you fix item 2. If you have ideas to reduce complexity they are also welcome.

@delcroip
Copy link
Contributor Author

delcroip commented Jul 29, 2021

@stian-sandvold
I changed the priority because the context variable is more specific than the system variable
I addressed point 2,
I remove the useless lines
I tried to reduce code complexity and make the code more readable

I tested (during maven build) with default, system var and Env var, I didn't retest the contex variable because I couldn't with maven, but I will do it a bit later

Also, I hope it is ok to piggyback a change in the json test to remove an error that block me every time I build on windows

@delcroip
Copy link
Contributor Author

@stian-sandvold is there an issue ?

@stian-sandvold stian-sandvold changed the base branch from master to DHIS2-12032 October 26, 2021 06:53
@stian-sandvold
Copy link
Contributor

Hey @delcroip , so sorry about the delay; It completely slipped my mind.

I had some test issues locally, but they seem unrelated, so I decided to create a new branch within the repo so we can run the automatic checks. I'll merge your PR into that branch, and I'll reach out if there are any issues :)

@stian-sandvold stian-sandvold merged commit 1da84a8 into dhis2:DHIS2-12032 Oct 26, 2021
stian-sandvold added a commit that referenced this pull request Oct 26, 2021
* feat: Enabling context variable to define dhis2_home (#6573)

* add DHIS2_HOME in context

* correct log message

* remove dot on context var

* Update dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java

* reduce code complexity

* remove error while building on windows (EOF related)

Co-authored-by: Stian Sandvold <stian@dhis2.org>
Co-authored-by: Patrick Delcroix <pmpdelcroix@gmail.com>

* style: Fix code style issues

Co-authored-by: Patrick Delcroix <delcroip@gmail.com>
Co-authored-by: Patrick Delcroix <pmpdelcroix@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants