How do I use the SDK to run a reference application server?

I am doing the following:

  1. Run mysql 5.6 via docker

  2. Create an “openmrs” database on that mysql instance

  3. Then I use the SDK to create a server, giving it connection details for that mysql server

    mvn openmrs-sdk:setup -DserverId=openmrs -Dversion=2.3 -DdbDriver=mysql -DdbUser=root -DdbUri=jdbc:mysql://192.168.99.100:3306/openmrs -DdbPassword=openmrs

  4. Use the SDK to run that server

    mvn openmrs-sdk:run -DserverId=openmrs

At this point things fail, and the output includes these relevant lines:

WARN - OpenmrsUtil.getRuntimePropertiesFilePathName(2697) |2016-01-28 17:14:03,824| Unable to find properties file: /Users/djazayer/openmrs/openmrs/openmrs-runtime.properties
...
Caused by: java.sql.SQLException: Access denied for user 'test'@'localhost' (using password: YES)

Help! Why isn’t this recognizing the connection details I included in the setup command? How do I make this run?

One thing I notice is that in the folder that the SDK created for my server, there’s a file called “installation.properties” that looks like an OpenMRS runtime properties file, with extra properties. If I rename this to openmrs-runtime.properties, then do sdk:run, things get a bit further, but then it fails with:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'openmrs&sessionVariables=storage_engine=InnoDB'

PS, so, if I then edit the openmrs-runtime.properties file (that I renamed from installation.properties) and give it a connection URL that I coped from one of my other runtime properties files (jdbc:mysql://192.168.99.100:3306/openmrs?autoReconnect=true&sessionVariables=storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8) then I get a bit further.

It starts up seemingly okay:

INFO 1/28/16 5:33 PM:liquibase: Reading from `liquibasechangelog`
...
[INFO] Started Jetty Server

But then when I visit the initialsetup page, it gets into an infinite redirect loop, and the logs start by saying:

WARN - InitializationFilter$InitializationCompletion$1.run(1512) |2016-01-28 17:34:11,617| Error while trying to create tables and demo data
org.openmrs.util.DatabaseUpdateException: There was an error while updating the database to the latest. file: liquibase-schema-only.xml. Error: Unable to get a connection to the database.  Please check your openmrs runtime properties file and make sure you have the correct connection.username and connection.password set
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'openmrs&sessionVariables=storage_engine=InnoDB'

Where is this coming from?

(I guess perhaps from this line of code, but why is it using a different connection URL now that it was when creating the liquibase table?

Hmm, so I hacked even further, and I edited the runtime properties file further and I duplicated all of the connection.* lines as hibernate.connection.*, and this command now works:

mvn openmrs-sdk:run -DserverId=openmrs

It runs all the liquibase changesets, and it seems basically fine…until eventually it runs into

Exception in thread "Thread-31" java.lang.OutOfMemoryError: PermGen space

I’m at a loss here…

The first error you encountered i.e. Caused by: java.sql.SQLException: Access denied for user ‘test’@‘localhost’ (using password: YES) has started to appear recently, but it is not an actual error that prevents you from accessing the installation wizard through the browser. It may be some code in core trying to access database using wrong credentials before running the install wizard. We’ll need to have a look at what is causing it.

Also I noticed that saying -DdbUri=jdbc:mysql://192.168.99.100:3306/openmrs is not working properly (additional parameters are not appended correctly) and you actually need to put -DdbUri=jdbc:mysql://192.168.99.100:3306/openmrs?autoReconnect=true&sessionVariables=storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8

So start from scratch and use the full url.

1 Like

You are right, that “Access denied for user ‘test’@‘localhost’” seems to be a spurious error.

Summarizing our IRC exchange for anyone interested:

  • you need to increase the Java memory settings to run the whole reference application
  • you cannot do this in the mvn openmrs-sdk:run command, but you can do it by setting the MAVEN_OPTS environment variable.

So, I am now successfully able to set up for Reference Application development just by doing:

$ docker run --name openmrs-mysql -e MYSQL_ROOT_PASSWORD=openmrs -d -p 3306:3306 mysql:5.6
$ mvn openmrs-sdk:setup -DserverId=openmrs -Dversion=2.3 -DdbDriver=mysql -DdbUser=root -DdbPassword=openmrs -DdbUri=jdbc:mysql://192.168.99.100:3306/openmrs?autoReconnect=true&sessionVariables=storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8
$ export MAVEN_OPTS="-Xmx1024m -Xms1024m -XX:PermSize=256m -XX:MaxPermSize=512m"
$ mvn openmrs-sdk:run -DserverId=openmrs
1 Like

My Environment: JDK 8, Version 2.3 using OpenMRS SDK

I installed OpenMRS reference application with the following command mvn openmrs-sdk:setup -DserverId=openmrs -Dversion=2.3 -DdbDriver=mysql -DdbUser=root -DdbPassword=openmrs -DdbUri=“jdbc:mysql://192.168.99.100:3306/openmrs-openmrs?autoReconnect=true&sessionVariables=storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8”

I see that the database it creates is openmrs-(serverID). In my case the serverID=openmrs. Hence the database it creates is openmrs-openmrs. This caused errors when i was using the jdbc url “jdbc:mysql://192.168.99.100:3306/openmrs” and I had to use jdbc:mysql://192.168.99.100:3306/openmrs-openmrs" to get this working.

Is this expected?

No, it shouldn’t be creating a database, if you specify an existing database explicitly. Could you please create an issue in JIRA under SDK project so that it is fixed?

I created at ticket: https://issues.openmrs.org/browse/SDK-87 (I marked @justsans as the reporter, but I did reproduce this myself.)

The issue is fixed and a new version of SDK released. It may take up to a few hours for the central repo to get updated. The fixed version is 2.1.2 and you can upgrade using mvn openmrs-sdk:help -U if it doesn’t happen automatically by tomorrow.

1 Like

Tested this out. It works fine now.

It creates the database as per the url (‘openmrs’) instead of creating one with the serverId appended to it (‘openmrs-openmrs’). Thank you @raff for fixing this so quickly.

The command I am using to create a new server. mvn openmrs-sdk:setup -DserverId=openmrs -Dversion=2.3 -DdbDriver=mysql -DdbUser=root -DdbUri=“jdbc:mysql://localhost:3306/openmrs?autoReconnect=true&sessionVariables=storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8” -DdbPassword=password

Happy to help. BTW it is ok now to put just -DdbUri=“jdbc:mysql://localhost:3306/openmrs” and the rest of the URL will be appended automatically.

All,

I’m getting an error running SDK that was noted above as being resolved. Here’s the commands/results. Any help is much appreciated! Thanks much, Barry

mvn openmrs-sdk:setup -DserverId=test1 -Dversion=2.3 -DdbDriver=mysql -DdbUser=root -DdbUri=jdbc:mysql://localhost:3306/openmrs -DdbPassword=123

export MAVEN_OPTS="-Xmx1024m -Xms1024m -XX:PermSize=256m -XX:MaxPermSize=512m"

mvn openmrs-sdk:run

[INFO] Scanning for projects… INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO]

[INFO] [INFO] —

openmrs-sdk-maven-plugin:2.1.2:run (default-cli) @ standalone-pom —

Define value for property’serverId’: (default: ‘test1’) (possible: test1, Openmrs2.3, openmrsMaster, Openmrs2.2, SDK): test1

[INFO] Configuring Jetty forproject: Maven Stub Project (No POM) [INFO] Context path =/openmrs [INFO] Tmp directory =/Users/levine/OpenMRS/test1/tmp [INFO] Web defaults =org/eclipse/jetty/webapp/webdefault.xml [INFO] Web overrides = none [INFO] jetty-9.0.4.v20130625 [INFO] No Transaction manager found - if your webapp requires one, please configure one.

[INFO] No Spring WebApplicationInitializer types detected on classpath

[INFO] Set web app root system property: ‘webapp.root’ = [/Users/levine/OpenMRS/test1/tmp/webapp]

[INFO] Initializing log4j from [classpath:log4j.xml]

WARN - OpenmrsUtil.getRuntimePropertiesFilePathName(2669) |2016-05-26 12:51:46,102| Unable to find a runtime properties file at /Users/levine/openmrs-runtime.properties WARN - OpenmrsUtil.getRuntimePropertiesFilePathName(2697) |2016-05-26 12:51:46,110| Unable to find properties file: /Users/levine/openmrs/test1/openmrs-runtime.properties WARN - OpenmrsUtil.getRuntimeProperties(2630) |2016-05-26 12:51:46,112| Unable to find a runtime properties file. Initial setup is needed. View the webapp to run thesetup wizard. WARN - OpenmrsUtil.getRuntimePropertiesFilePathName(2669) |2016-05-26 12:51:46,299| Unable to find a runtime properties file at /Users/levine/openmrs-runtime.properties WARN - OpenmrsUtil.getRuntimePropertiesFilePathName(2697) |2016-05-26 12:51:46,300| Unable to find properties file: /Users/levine/openmrs/test1/openmrs-runtime.properties WARN - OpenmrsUtil.getRuntimeProperties(2630) |2016-05-26 12:51:46,300| Unable to find a runtime properties file. Initial setup is needed. View the webapp to run the setup wizard. ERROR - UpdateFilterModel.updateChanges(77) |2016-05-26 12:51:50,472| Unable to get the database changes java.lang.RuntimeException: Error occurred while trying to get the updates needed for the database. Unable to get a connection to the database. Please check your openmrs runtime properties file and make sure you have the correct connection.username and connection.password set ** at** org.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:637)

…………………………………

Caused by: java.lang.Exception: Unable to get a connection to the database. Please check your openmrs runtime properties file and make sure you have the correct connection.username and connection.password set

………………………………………………………………………

Caused by: java.sql.SQLException: Access denied for user ‘test’@‘localhost’ (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)

………………………………………………………………………

[INFO] Started o.e.j.m.p.JettyWebAppContext@6b9a7cb8{/openmrs,file:/Users/levine/OpenMRS/test1/tmp/webapp/,AVAILABLE}{/Users/levine/OpenMRS/test1/openmrs-1.11.4.war} [INFO] Started ServerConnector@48b68d98{HTTP/1.1}{0.0.0.0:8080} [INFO] Started Jetty Server

I browsed to localhost:8080/openmrs It redirected to http://localhost:8080/openmrs/initialsetup

The openmrs db was createdwith no tables The browser hung at this point

** I stopped the jetty process and it generated the following:**

StoppedServerConnector@48b68d98{HTTP/1.1}{0.0.0.0:8080} [INFO] Stopped o.e.j.m.p.JettyWebAppContext@6b9a7cb8{/openmrs,file:/Users/levine/OpenMRS/test1/tmp/webapp/,UNAVAILABLE}{/Users/levine/OpenMRS/test1/openmrs-1.11.4.war} [WARNING] FAILED o.e.j.m.p.JettyWebAppContext@6b9a7cb8{/openmrs,file:/Users/levine/OpenMRS/test1/tmp/webapp/,UNAVAILABLE}{/Users/levine/OpenMRS/test1/openmrs-1.11.4.war}: org.openmrs.api.APIException: contextDAO is null org.openmrs.api.APIException: contextDAO is null at org.openmrs.api.context.Context.getContextDAO(Context.java:170)

The installation properties file follows:

openmrs.platform.version=2.3 create_database_user=false connection.username=root connection.url=jdbc:mysql://localhost:3306/openmrs?autoReconnect=true&sessionVariables=storage_engine%3DInnoDB&useUnicode=true&characterEncoding=UTF-8 server.id=test1 connection.driver_class=com.mysql.jdbc.Driver admin_user_password=Admin123 connection.password=123 install_method=auto module_web_admin=true add_demo_data=false create_tables=true has_current_openmrs_database=true openmrs.version=1.11.4 database_name=openmrs auto_update_database=false

Sorry, I forgot to mention I’m running this on Mac Yosemite

Is it the full output of openmrs-sdk:run command or you cut out some lines? We’ll need the entire output.

1 Like

I re-ran the commands and received the same error after executing “mvn openmrs-sdk:run”. However, in the past I used Chrome after receiving the error to start up; this time I used Firefox and it worked! Barry