Search code examples
mysqlwildfly-10openshift-origin

Configure a Wildfly 10 MSQL datasource in OpenShift v3


I have an application currently working on my local Dev machine. It uses Wildfly 10, MySQL 5.7 and Hibernate. My application looks for the 'AppDS' datasource from within Wildfly.

I've created a Wildfly 10 container and a MySQL container on OpenShift V3. Typically, I would log into Wildfly and configure a datasource, but all that configuration is lost when a container restarts. I thought it would be a matter of finding my connection environment settings, and using the pre-configured database connections, but I can't find what the variables should be set to, and the default connections don't work without them.

I downloaded and read OpenShift for Developers, but they side-step the issue by creating a direct database connection, rather than going through a datasource.

exporting the environment variables failed because 'no matches for apps.openshift.io/, Kind=DeploymentConfig'. Is the book out of date? Are they not using deployment config to store environment variables?

I would appreciate it greatly if someone could point me in the right direction.


Solution

  • I have a project running locally on my machine that uses Wildfly 10, Mysql 5.7 and Hibernate. I found the documentation to be incomplete. After a few days of working with it, I have figured out how to deploy a simple J2EE project with this stack.

    I am updating my question with the step-by-step I wish I'd had. I hope this saves someone some time in the future.

    1. create new openshift user
    2. create project dbtest
    3. add MySQL to dbtest project: The following service(s) have been created in your project: mysql:

      Username: test Password: test Database Name: testdb Connection URL: mysql://mysql:3306/

    4. add Wildfly to the project:

    oc login https://api.starter-us-west-1.openshift.com oc project dbtest oc status

    1. scale current wildfly pod to 0. (you won't have enough CPU to run 3 pods, and redeploy tries to start a new one and hot swap them)
    2. From left menu: Applications->Deployments->(dbtest)Wildfly10 pod->environment(tab)-> add: MYSQL_DATABASE=testdb MYSQL_DB_ENABLED=true MYSQL_USER:test MYSQL_PASSWORD: test
    3. push wildfly pod back to 1.
    4. use terminal in Wildfly to run ./add-user.sh
    5. oc port-forward wildfly10-6-rkr58 :9990 (replace wildfly10-6-rkr58 with your pod name, found by clicking on the running pod [circle with a 1 in it] and noting the pod name in the upper left corner])
    6. login to Wildfly from 127.0.0.1: and test the MySQLDS. It should now connect.