WebSphere Application Server & Liberty

 View Only

Modernization of Java EE Applications using OpenShift - Part 1

By dai hira posted Thu January 23, 2020 09:50 PM

  
This article is an English translation of my article posted on Japan’s most famous IT news site ITmedia on Nov 11, 2019, translated with the permission of ITmedia.
https://www.atmarkit.co.jp/ait/articles/1911/15/news002.html


Introduction

I contributed an article named “Modernization of Java EE Applications using OpenShift” that uses “Red Hat OpenShift on IBM Cloud”.

”OpenShift on IBM Cloud” used in that article is a paid service, so I think that it might be difficult for many people to try using the steps written in the article.  Therefore, I have re-written the steps using MiniShift, which can be used free of charge, so that you can easily experience the modernization of Java EE in OpenShift.

In this article, I would like to try a case where all applications and databases are containerized.  In Code patterns, the database I used was IBM Cloud’s managed service “Compose for MySQL”.

screenshot2020-01-24_10_57_17.png
Modernization of Java using OpenShift
There is a code pattern called “Java EE application modernization with OpenShift” in IBM Code Patterns.  I want to use this code pattern to actually experience the modernization of JAVA EE for myself with my own hands. I think this will be easy for you to visualize if you think of the series of flows as corresponding from the transition from on-premises to the cloud.  Let’s try being a solution architect and experience the modernization journey in the cloud! 

Example Health Context

“Example Health” is a conceptual healthcare or health insurance company. It has been around a long time and has hundreds of thousands of patient records. The company’s health records look very similar to the health records of most insurance companies.

Originally, Example Health used a monolithic application structure for the health records application. The application structure was a full stack Java application running on WebSphere Application Server, connected to a DB2 database on System z.

Recently, Example Health decided to modernize the health records application and break it up into microservices. The development team decided to move to a SQL database connected to a Java EE application (as shown in this code pattern) running on Open Liberty for the business logic and a Node.js application for the patient application user interface. In addition, Example Health decided to deploy these applications on Red Hat OpenShift on IBM Cloud. (Java EE application modernization with OpenShift By Max Shapiro, Yan Koyfman, Anton McConville, Greg Dritschler)


Preparing MiniShift

Install Docker version 17.09 or later on the host that will booth MiniShift.  I recommend installing the latest version of Docker CE (Communication Edition).  This is because the syntax to change the owner of the file with the ADD/COPY --chown flag will be used later.  The Docker version that runs the Virtual Machine (VM) is 1.13, so it is troublesome.  By the way, if you set Dockerfile to not use the --chown flag, you can avoid this annoyance, but this time we will continue on without changing the code pattern resource.

We will not be using MiniShift in the first half of this procedure.  Please turn off MiniShift until you need to use it.

# minishift stop

After booting MiniShift, if you are using the "# eval $ (minishift docker-env)" command, register the image in Docker in the host that MiniShift’s Virtual Machine (VM) will run on.  This time around, since we want to register an image in Docker that runs the “# eval$(minishift docker-env)” command after booting MiniShift, if there is a value in DOCKER_TLS_VERIFY、DOCKER_CERT_PATH after running the “# env | grep DOCKER” command, use the following procedure to empty the environmental variables.

export DOCKER_TLS_VERIFY=""
export DOCKER_HOST=""
export DOCKER_CERT_PATH=""

Procedure
1. Install Maven(the JDK is also installed due to Maven dependency)
# yum install maven

2. Check that Docker Daemon boots.
We will be building with Docker, so confirm in docker that the daemon has booted.
# systemctl status docker

3. Clone the project in GitHub.
When cloned, a folder called example-health-jee-openshift will be created.
# git clone https://github.com/daihiraoka/example-health-jee-openshift.git
Cloning into 'example-health-jee-openshift'...
remote: Enumerating objects: 263, done.
remote: Counting objects: 100% (263/263), done.
remote: Compressing objects: 100% (175/175), done.
remote: Total 263 (delta 108), reused 204 (delta 53), pack-reused 0
Receiving objects: 100% (263/263), 17.82 MiB | 5.57 MiB/s, done.
Resolving deltas: 100% (108/108), done.
# cd example-health-jee-openshift
# ls
example-health-api  generate  LICENSE  readme_images  README.md  screenshots

4. Build the Java EE application.
# cd example-health-api/
# mvn package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building health-api 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom (7 KB at 7.4 KB/sec)
<<------------------------------------省略------------------------------------>>
[INFO] Building war: /root/example-health-jee-openshift/example-health-api/target/health-api.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.656s
[INFO] Finished at: Thu Oct 17 13:58:55 JST 2019
[INFO] Final Memory: 14M/143M
[INFO] ------------------------------------------------------------------------

5. Build a Java EE application Docker image.
# docker build -t ol-example-health:1 .
Sending build context to Docker daemon  13.48MB
Step 1/10 : FROM openliberty/open-liberty:javaee8-ubi-min
javaee8-ubi-min: Pulling from openliberty/open-liberty
bdb299bbb0dd: Pull complete 
22b1a8fa1ec0: Pull complete 
bccea9526f92: Pull complete 
ca821998be76: Pull complete 
7d738fac7181: Pull complete 
2356e9fc5285: Pull complete 
048ba391e9fe: Pull complete 
347eb7134a38: Pull complete 
94456b65cdbb: Pull complete 
Digest: sha256:1f08f83c3076aaec7a7d3639864ca06998a779cecad6ad1452d501008c56f63b
Status: Downloaded newer image for openliberty/open-liberty:javaee8-ubi-min
 ---> fc55e2d66c27
Step 2/10 : ENV INSTALL_DIR /opt/ol/wlp/
 ---> Running in 45aaeaaa0c92
Removing intermediate container 45aaeaaa0c92
 ---> 27fe222d05be
Step 3/10 : ENV CONFIG_DIR /opt/ol/wlp/usr/servers/defaultServer/
 ---> Running in 395e839afb7f
Removing intermediate container 395e839afb7f
 ---> 8632cfb62026
Step 4/10 : ADD --chown=default:root https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.16/mysql-connector-java-8.0.16.jar  ${INSTALL_DIR}lib/mysql-connector-java-8.0.16.jar
Downloading [==================================================>]  2.293MB/2.293MB

 ---> 61898c26bdb1
Step 5/10 : RUN chmod 644 ${INSTALL_DIR}lib/mysql-connector-java-8.0.16.jar
 ---> Running in 8011b3b50bac
Removing intermediate container 8011b3b50bac
 ---> 5909218a689a
Step 6/10 : COPY liberty-mysql/mysql-driver.xml ${CONFIG_DIR}configDropins/defaults/
 ---> f42f5684e5b0
Step 7/10 : COPY liberty/server.xml $CONFIG_DIR
 ---> 67938badab11
Step 8/10 : COPY liberty/jvm.options $CONFIG_DIR
 ---> 60c3c494f5ef
Step 9/10 : COPY target/health-api.war /opt/ol/wlp/usr/servers/defaultServer/apps
 ---> 1bcb2f837df9
Step 10/10 : EXPOSE 9080
 ---> Running in eba84e894ddc
Removing intermediate container eba84e894ddc
 ---> aa91da14cf12
Successfully built aa91da14cf12
Successfully tagged ol-example-health:1

6. If the Docker build is successful, the base image openliberty/open-liberty and the ol-example-health image that we created this time will be output.
# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
ol-example-health          1                   aa91da14cf12        48 seconds ago      348MB
openliberty/open-liberty   javaee8-ubi-min     fc55e2d66c27        16 hours ago        343MB

Note:
Red Hat UBI (Red Hat Universal Base Image) RHEL7 is used for the Open Liberty base image specified in the Dockerfile FROM clause. Red Hat UBI is a container image provided through Red Hat quality control and can be freely redistributed.Container images created based on Red Hat UBI can receive support when running on OpenShift on IBM Cloud. 

If you are using an environment that doesn’t use OpenShift, you cannot receive support, but there is an advantage in that you can use RHEL container images for free.If you are operating containers in your company, you may need to determine whether this is safe in terms of security as each department may be passing containers of unknown origin such as CENTOS or Ubuntu etc.

However, there were several times where I had to use them for various reasons while being worried about security.  With Red Hat UBI, I wasn’t worried because the containers are provided through Red Hat quality control.  If you are using CentOS or Ubuntu container images, why not try using Red Hat UBI?

7. Register the Java EE application Docker image “ol-example-health”in Docker Hub.

- Please set up a Docker Hub in advance.Replace “daihiraoka”with your own Docker Hub account name and run.
- Tag the ol-example-health image in the format “Docker Hub account name / image name: tag name”.
# docker tag ol-example-health:1 daihiraoka/ol-example-health:1

A list of Docker images will be output and you can see that the image for daihiraoka/ol-example-health has been created.
# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
daihiraoka/ol-example-health   1                   901666e26ca5        27 minutes ago      450MB
ol-example-health              1                   901666e26ca5        27 minutes ago      450MB
openliberty/open-liberty       javaee8-ubi-min     bb992680821b        17 hours ago        445MB

Log into Docker Hub and register the image in daihiraoka/ol-example-health in the Docker Hub repository.
# docker login -u daihiraoka
Login Succeeded

# docker push daihiraoka/ol-example-health:1

Once the image registration has been completed, daihiraoka/ol-example-health will be displayed in the Docker Hub repository.
https___qiita-image-store_s3_ap-northeast-1_amazonaws_com_0_209170_c27602ab-7fa3-ec73-f779-229e2d85d852.png
8. Booting MiniShift.
# minishift start
-- Starting profile 'minishift'
-- Check if deprecated options are used ... OK
-- Checking if https://github.com is reachable ... OK
-- Checking if requested OpenShift version 'v3.11.0' is valid ... OK
-- Checking if requested OpenShift version 'v3.11.0' is supported ... OK
-- Checking if requested hypervisor 'kvm' is supported on this platform ... OK
Server Information ...
OpenShift server started.
<img width="400" alt="dockerhub-01.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/209170/d24a8d74-9aca-898e-1066-86395168ba48.png">

The server is accessible via web console at:
    https://192.168.42.138:8443/console

Applying environmental variables in MiniShift.
# eval $(minishift oc-env)    
# eval $(minishift docker-env)
# source <(oc completion bash)

When minishift oc-env is executed, the command to set the oc command PATH is output.
# minishift oc-env
export PATH="/root/.minishift/cache/oc/v3.11.0/linux:$PATH"
# Run this command to configure your shell:
# eval $(minishift oc-env)

# ls -1 /root/.minishift/cache/oc/v3.11.0/linux
oc

When minishift docker-env is executed, the connection information to Docker running on MiniShift VM on KVM is output as shown below.  By defining this environmental variable, the container image is handled not by the local Docker registry, but by the Docker registry of MiniShift VM.
# minishift docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.42.138:2376"
export DOCKER_CERT_PATH="/root/.minishift/certs"

9. Log in to the OpenShift CLI with your developer name.
(In MiniShift, you can use any password, so use a string of your choice.)
# oc login -u developer
Logged into "https://192.168.42.138:8443" as "developer" using existing credentials.

You have one project on this server: "myproject"

Using project "myproject".
10. Create a project for Example Health.
This creates a new project and sets it as a work project deployed as a Pod (container).
# oc new-project health
Now using project "health" on server "https://192.168.42.138:8443".

You can add applications to this project with the 'new-app' command. For example, try:

    oc new-app centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git

to build a new example application in Ruby.

11. The OpenShift project's ImageStream(is) to search for a MySQL catalog is output.
# oc get is -n openshift
NAME         DOCKER REPO                            TAGS                         UPDATED
dotnet       172.30.1.1:5000/openshift/dotnet       2.0,latest                   16 hours ago
httpd        172.30.1.1:5000/openshift/httpd        2.4,latest                   16 hours ago
jenkins      172.30.1.1:5000/openshift/jenkins      2,latest,1                   16 hours ago
mariadb      172.30.1.1:5000/openshift/mariadb      10.1,10.2,latest             16 hours ago
mongodb      172.30.1.1:5000/openshift/mongodb      2.6,3.2,3.4 + 3 more...      16 hours ago
mysql        172.30.1.1:5000/openshift/mysql        latest,5.5,5.6 + 1 more...   16 hours ago
nginx        172.30.1.1:5000/openshift/nginx        1.10,1.12,1.8 + 1 more...    16 hours ago
nodejs       172.30.1.1:5000/openshift/nodejs       4,6,8 + 4 more...            16 hours ago
perl         172.30.1.1:5000/openshift/perl         5.20,5.24,5.26 + 2 more...   16 hours ago
php          172.30.1.1:5000/openshift/php          7.1,latest,5.5 + 2 more...   16 hours ago
postgresql   172.30.1.1:5000/openshift/postgresql   9.4,9.5,9.6 + 3 more...      16 hours ago
python       172.30.1.1:5000/openshift/python       3.5,3.6,latest + 3 more...   16 hours ago
redis        172.30.1.1:5000/openshift/redis        3.2,latest                   16 hours ago
ruby         172.30.1.1:5000/openshift/ruby         2.2,2.3,2.4 + 3 more...      16 hours ago
wildfly      172.30.1.1:5000/openshift/wildfly      11.0,12.0,13.0 + 5 more...   16 hours ago

The container image that mysql will use this time is ImageStream.  The nodejs and dotnet are the same as in the console catalog in the image below.  OpenShift provides a mechanism to easily deploy applications even on CLI.
https___qiita-image-store_s3_ap-northeast-1_amazonaws_com_0_209170_f8eb2b89-51b3-b0e3-04b5-38b4a11c09b2.png
12. Create a MySQL database container using OpenShift S2I (Source to Image).
# oc new-app \
-e MYSQL_USER=admin \
-e MYSQL_PASSWORD=password \
-e MYSQL_DATABASE=health \
--name=mysql \
openshift/mysql:5.7~https://github.com/daihiraoka/example-health-jee-openshift.git

Define the environmental variables using “-e”.

Parameter Description
-e MYSQL_USER MySQL User Name
-e MYSQL_PASSWORD MySQL Password
-e MYSQL_DATABASE Database Name
--name Container Name
openshift/mysql:5.7  openshift / mysql: 5.7 is the image stream name of the base container image (mysql: 5.7 in the openshift project)
~https://github.com(ommit) The source code repository is specified on the right side after the ~(tilde)

This time, persistent storage used to save the data in the database is omitted.  If the Pod (container) is not configured for persistent storage, all of the data will be lost if the Pod (container) is stopped.  In this case, when a new Pod (container) is booted, it will be empty and the SQL schema import must be restarted.

--> Found image f83a293 (6 days old) in image stream "openshift/mysql" under tag "5.7" for "openshift/mysql:5.7"

    MySQL 5.7 
    --------- 
    MySQL is a multi-user, multi-threaded SQL database server. The container image provides a containerized packaging of the MySQL mysqld daemon and client application. The mysqld server daemon accepts connections from clients and provides access to content from MySQL databases on behalf of the clients.

    Tags: database, mysql, mysql57, rh-mysql57

    * A source build using source code from https://github.com/daihiraoka/example-health-jee-openshift.git will be created
      * The resulting image will be pushed to image stream tag "mysql:latest"
      * Use 'start-build' to trigger a new build
    * This image will be deployed in deployment config "mysql"
    * Port 3306/tcp will be load balanced by service "mysql"
      * Other containers can access this service through the hostname "mysql"

--> Creating resources ...
    imagestream.image.openshift.io "mysql" created
    buildconfig.build.openshift.io "mysql" created
    deploymentconfig.apps.openshift.io "mysql" created
    service "mysql" created
--> Success
    Build scheduled, use 'oc logs -f bc/mysql' to track its progress.
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/mysql' 
    Run 'oc status' to view your app.

After a while, the mysql Pod [ mysql-1-hktv2 ] will boot.
# oc get pod
NAME            READY     STATUS      RESTARTS   AGE
mysql-1-build   0/1       Completed   0          3m
mysql-1-hktv2   1/1       Running     0          2m

13. Create a MySQL container database schema
Log in to the container with the oc rsh command to create a database schema in MySQL.
# oc rsh mysql-1-hktv2

If you log in with the rsh command, you can see that the directory structure is in the container on github.
sh-4.2$ ls
LICENSE  README.md  example-health-api  generate  readme_images  screenshots

Import the patient health record data using the SQL schema.  file name: example-health-api/samples/health_schema.sql
sh-4.2$ mysql -u admin -ppassword health < ./example-health-api/samples/health_schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

The health database table list will be output.  If the SQL schema import completes successfully, the output result table will be displayed.
sh-4.2$ mysql -u admin -ppassword health -e "show tables;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------------+
| Tables_in_health |
+------------------+
| Allergies        |
| Appointments     |
| MESSAGE          |
| Observations     |
| Organizations    |
| Patients         |
| Prescriptions    |
| Providers        |
| SEQUENCE         |
+------------------+

Now that the database has been created, you can exit from the container using the “exit” command.
sh-4.2$ exit
exit

14. Communication settings for the business logic between the Java EE application and the MySQL container.

When you return to the working host and the the “pwd” command, you should be in the “example-health-jee-openshift/example-health-api” folder.
# pwd
/root/example-health-jee-openshift/example-health-api
# ls
create-secrets.sh  Dockerfile  kubernetes-openshift.yaml  liberty  liberty-mysql  pom.xml  samples  src  target

In order to connect MySQL with the business logic Java EE application, first, check the MySQL service name.
# oc get svc
NAME      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
mysql     ClusterIP   172.30.88.187   <none>        3306/TCP   9m
Communication between Pods is done using service names.  Remember the service name as it will be used in the next step.
We will set the connection information for MySQL using the example-health-api/create-secrets.sh script.
cat create-secrets.sh
#!/bin/bash
oc create secret generic db-secrets    \
     --from-literal=db_username=admin        \
     --from-literal=db_password=password       \
#    --from-literal=db_host="jdbc:mysql://ServiceName:PortNumber/DataBaseName?sessionVariables=sql_mode=''"
     --from-literal=db_host="jdbc:mysql://mysql:3306/health?sessionVariables=sql_mode=''"

Note: As of October 2019, create-secrets.sh has a “/”between “DB Name” and “?” in “DB Name/?sessionVariables”. There will be a connection error when connecting to JDBC because “/” is included in the DB name string, so please delete the “/”.

In OpenShift, authentication information such as passwords are stored in an object with a mechanism for storing confidential information called secrets. 
MySQL connection information is used as environment variables in the pod (container). To use it as an environment variable, link the environment variable and secrets in the Deployment object that defines the deployment of the pod (container) using the following procedure kubernetes-openshift.yaml.

An excerpt from kubernetes-openshift.yaml where env (environmental variables) are defined.
env:
- name: ENV_MYSQL_UR
  valueFrom:
    secretKeyRef:
      name: db-secrets
      key: db_host
- name: ENV_MYSQL_USER
  valueFrom:
    secretKeyRef:
      name: db-secrets
      key: db_username
- name: ENV_MYSQL_PWD
  valueFrom:
    secretKeyRef:
      name: db-secrets
      key: db_password

In the Open Liberty DataSource settings, use the environmental variables defined above to set the database connection parameters.

An excerpt from example-health-api/liberty/server.xml where the DataSource is set.
<dataSource id="DefaultDataSource" jndiName="jdbc/health-api" jdbcDriverRef="mysql-driver"
           type="javax.sql.ConnectionPoolDataSource" transactional="true">

   <properties url="${ENV_MYSQL_URL}"
               databaseName="${ENV_MYSQL_DB_NAME}"
               user="${ENV_MYSQL_USER}"
               password="${ENV_MYSQL_PWD}"/>

Note: There is an undefined variable above: ENV_MYSQL_DB_NAME, but this is because the database name environmental variable is defined within ENV_MYSQL_URL.  Here the original code from Code Patterns is displayed.

Run the script to create secrets in OpenShift. After creation, you can use the "oc get secrets" command to output the secrets list and confirm that it has been created under the name “db-secrets”.
#  ./create-secrets.sh 
secret/db-secrets created

# oc get secrets
NAME                       TYPE                                  DATA      AGE
db-secrets                 Opaque                                3         2d

15. Deploy Java EE applications
Edit the file: example-health-api/kubernetes-openshift.yam to change the image key in the containers section.
- Replace daihiraoka with your DockerHub account name.
- Update the ol-example-health tag from latest to 1

(before)
 containers:
  - name: example-health-api
    image: ykoyfman/ol-example-health:latest
(after)
  containers:
  - name: example-health-api
    image: daihiraoka/ol-example-health:1
Deploy example-health-api/kubernetes-openshift.yaml
# oc create -f kubernetes-openshift.yaml
service/example-health-api created
deployment.apps/example-health-api created

Inside example-health-api/kubernetes-openshift.yaml, Deployment describes Open Liberty’s Pod (container) deployment and Service describeshow Liberty’s Pod(container) accesses the EndPoint(IP).By running yaml, Open Liberty’s Pod(container) starts in OpenShift and can connect to Open Liberty’s Pod(container) using Service.

After some time, the OpenLiberty Pod (container) will boot.  If you execute the “oc get pod” command and output the list of Pods (containers), the STATUS of the “example-health-api-<any alphanumeric character>” will be “Running”.  

# oc get pod
NAME                                  READY     STATUS      RESTARTS   AGE
example-health-api-7fcb786fb6-l5kx9   1/1       Running     0          1m
mysql-1-build                         0/1       Completed   0          22m
mysql-1-hktv2                         1/1       Running     0          21m

16. Create Route, an OpenShift object to publish Java EE applications to the Internet.
# oc expose svc example-health-api
route.route.openshift.io/example-health-api exposed
Confirm that the Java EE application is functioning.  First, get the host name assigned to Route.
# oc get route
NAME                 HOST/PORT                                         PATH      SERVICES             PORT      TERMINATION   WILDCARD
example-health-api   example-health-api-health.192.168.42.138.nip.io             example-health-api   http                    None
In this case, the first NAME example-health-api is the Route name and the next HOST/PORT FQDN is the host name that is generated. If Route is accessed, it will access the IP address of EndPoint of the Pod (container) via example-health-api.

17. Check that the Java EE application is running in the browser

In a browser window,  go to /openapi/ui/.  OpenAPI endpoints and the specifications supported by Java EE applications will be displayed. eg)http://example-health-api-health.192.168.42.138.nip.io/openapi/ui/
https___qiita-image-store_s3_ap-northeast-1_amazonaws_com_0_209170_9cbe5d5b-99d5-d14f-c7c4-1765218a5c17.png
Your business logic is now running on Red Hat OpenShift on MiniShift.  Currently, the database has a SQL Schema created, but there is no data yet.  The USER will load the patient health record test data using the REST API using the following procedure along path ①.
https___qiita-image-store_s3_ap-northeast-1_amazonaws_com_0_209170_7077fbe0-6ec4-b885-a101-517a9c36c98f.png
18. Preparation of the patient health record rest data generation program
The test data will be loaded using via the REST API into MySQL by running generate.sh which created the patient health record test data.  In generate.sh, a program called synthea is used to synthesizer realistic (but not real) patient data and related records in various formats.

We will install csvtojson in Node.js which is required to run generate.sh.
# ls
example-health-api  generate  LICENSE  readme_images  README.md  screenshots
# cd generate/
# ls
generate.sh  package.json  README.md
# pwd
/root/example-health-jee-openshift/generate
# yum install npm
Installing:
 npm                      x86_64                   1:3.10.10-1.6.17.1.1.el7                    epel                   2.5 M
Installing for dependencies:
 libuv                    x86_64                   1:1.30.1-1.el7                              epel                   138 k
 nodejs                   x86_64                   1:6.17.1-1.el7                              epel                   4.7 M
# npm install csvtojson
synthea-generate@1.0.0 /root/example-health-jee-openshift/generate
└─┬ csvtojson@2.0.10 
  ├── bluebird@3.7.1 
  ├── lodash@4.17.15 
  └─┬ strip-bom@2.0.0 
    └── is-utf8@0.2.1 

# pwd
/root/example-health-jee-openshift/generate

- PATH Setting for csvtojson  
# PATH=$PATH:/root/example-health-jee-openshift/generate/node_modules/csvtojson/bin

19. Change the default timeout value in Route
We will change the default timeout value in the Route Name: example-health-api that we created in the previous procedure to 60 minutes.  When the USER runs generate.sh, it will call the Open Liberty Pod (container) using the REST API via the OpenShift application load balancer (ALB) router.Since OpenShift’s router default timeout period is 30 seconds, it is too short for long-running REST API calls such as entering test data, so it is necessary to make the timeout value longer.
# oc annotate route example-health-api --overwrite haproxy.router.openshift.io/timeout=60m
  route.route.openshift.io/example-api annotated

We can verify the change results using the “oc describe route” command.
# oc describe route example-health-api 
Name:           example-health-api
Namespace:      health
Created:        13 minutes ago
Labels:         app=example-health-api
Annotations:        haproxy.router.openshift.io/timeout=60m
            openshift.io/host.generated=true
Requested Host:     example-health-api-health.192.168.42.138.nip.io
              exposed on router router 13 minutes ago
Path:           <none>
TLS Termination:    <none>
Insecure Policy:    <none>
Endpoint Port:      http

Service:    example-health-api
Weight:     100 (100%)
Endpoints:  172.17.0.10:9080

20. Run the patient health record test data program
We will run the program now.  The options for generate.sh are -p for population and -u for the host name published in route. This time, we will load data for 150 people. 
# ./generate.sh -p 150 -u http://example-health-api-health.192.168.42.138.nip.io
Cloning into 'synthea'...
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 31698 (delta 7), reused 21 (delta 2), pack-reused 31660
Receiving objects: 100% (31698/31698), 605.79 MiB | 9.81 MiB/s, done.
Resolving deltas: 100% (18183/18183), done.
Checking out files: 100% (663/663), done.

BUILD SUCCESSFUL in 30s
4 actionable tasks: 2 executed, 2 up-to-date
The load completed several minutes after BUILD SUCCESSFUL was displayed.  If you want to check the status of the process, run the“oc logs-f example-health-api-<any alphanumeric>” command to check the OpenLiberty Pod (container) logs.  

21. Check the patient health record data that was loaded
Using the API “/resources/v1/getInfo/patients” which is used to obtain the patient list, we will check whether the patient health record data was loaded.  By running curl to specify the host name as /resources/v1/getInfo/patients in the URL, we can obtain the data for 150 patients which is the same number loaded previously.
# curl -X GET "http://example-health-api-health.192.168.42.138.nip.io/resources/v1/getInfo/patients" -H "accept: */*"
{"ResultSet Output":[{"CA_DOB":"1962-10-
<<<ommit>>>
09","CA_FIRST_NAME":"Sergio","CA_GENDER":"M","CA_LAST_NAME":"Castellanos"},{"CA_DOB":"1988-06-06","CA_FIRST_NAME":"Lorraine","CA_GENDER":"F","CA_LAST_NAME":"Ledner"},{"CA_DOB":"2018-01-29","CA_FIRST_NAME":"Shemika","CA_GENDER":"F","CA_LAST_NAME":"Terry"},{"CA_DOB":"1954-03-26","CA_FIRST_NAME":"Clyde","CA_GENDER":"M","CA_LAST_NAME":"Ferry"},{"CA_DOB":"1946-03-25","CA_FIRST_NAME":"Bobby","CA_GENDER":"M","CA_LAST_NAME":"Krajcik"}],"StatusCode":200,"StatusDescription":"Execution Successful"}

22. Summary
Example Health has now successfully split the business logic part from the monolithic Java EE application structure and run it as a Java EE application for business logic operating on Open Liberty on MiniShift’s OpenShift. We have been able to use the actual patient test data generation program (generator.sh) using the REST API to import patient health management test data into the MySQL database, and we have also been able to have the Java EE application access this data as well.  

After following these steps, it feels like we have climbed the first mountain in the modernization journey, but since only the REST API can be called at this moment, it is not sufficient as a service. In the next steps, I would like to deploy another patient UI Node.js application in OpenShift split from a monolithic Java EE application and integrate it with the business logic Java EE application that we created this time around.​

Next: Modernization of Java EE Applications using OpenShift - Part 2

https://community.ibm.com/community/user/imwuc/blogs/daisuke-hiraoka1/2020/01/27/modernization-of-java-ee-applications-using-opensh
#Openshift
#redhatopenshift
#RedHat
#CloudpakforApplications
#openshift4.4
#openshift4.3
#ApplicationModernization
1 comment
65 views

Permalink

Comments

Fri January 31, 2020 02:01 PM

Thanks Daisuke for great blog!