Overview

Skill Level: Beginner

This recipe describes how to deploy Sample DayTrader WebSphere Liberty Java EE application into IBM Cloud Private, by using Helm Charts. For demonstration purpose, the sample runs with Derby database and JMS embedded messaging.

Ingredients

IBM Cloud Private 2.1.0.3

IBM WebSphere Liberty Helm Chart version 1.6.0

DayTrader 7 benchmark sample from here

Kubectl command line (install from here)

Docker (as part of IBM Cloud Private installation)

Docker hub user id (user needs to register/create)

Helm command line (install from here)

Step-by-step

  1. Install IBM Cloud Private

    Install IBM Cloud Private 2.1.0.3 with the instruction here.

  2. Download DayTrader7 Sample

    Use Clone or Download from the git URL: here to download the sample to your file system.

    Reminder: Your file system is on the VM system where you can access/connect to IBM Cloud Private to run kubectl, docker command line.

  3. Maven Build DayTrader7 Sample

    From the sample’s git URL, follow the link Building and running the sample using the command line in the readme and build the sample.

    Once the build completes successfully, locate the following two files and make a note of the location, which will be used at later steps in building docker image of the sample application.

    • daytrader-ee7.ear under /../sample.daytrader7/daytrader-ee7-wlpcfg/servers/daytrader7Sample/apps
    • server.xml under /../sample.daytrader7/daytrader-ee7-wlpcfg/servers/daytrader7Sample/server.xml
  4. Update server.xml Configuration

    Open the sever.xml under /../sample.daytrader7/daytrader-ee7-wlpcfg/servers/daytrader7Sample

    • Make a note of the ssl port number 9443, which will be used at later steps in the helm chart configuration.

    Note: You may change the port to a different number if needed, as long as it’s consistent with the helm chart configuration.

    <httpEndpoint host=”*” httpPort=”9082″ httpsPort=”9443″ id=”defaultHttpEndpoint”> </httpEndpoint>

    • Update jdbcDriver fileset location from the original shared.resource.dir to server.config.dir.¬† (This is for the consistency in Dockerfile configuration below.)

    <!– <fileset dir=”${shared.resource.dir}/Daytrader7SampleDerbyLibs” id=”DerbyFileset” includes=”derby-10.10.1.1.jar”/> –>
    <fileset dir=”${server.config.dir}” id=”DerbyFileset” includes=”derby-10.10.1.1.jar”/>

     

  5. Create Dockerfile

    1. From the sample directory /../sample.daytrader7, use your editor to create a new file named Dockefile.

    2. Copy and paste the following lines into Dockerfile, and save it.  Note: The websphere-liberty image is at the current latest level from docker hub.

    FROM websphere-liberty:javaee7

    COPY daytrader-ee7-wlpcfg/servers/daytrader7Sample/apps/daytrader-ee7.ear /config/apps/daytrader-ee7.ear

    COPY daytrader-ee7-wlpcfg/servers/daytrader7Sample/server.xml /config/server.xml

    #DERBY

    COPY daytrader-ee7-wlpcfg/shared/resources/Daytrader7SampleDerbyLibs/derby-10.10.1.1.jar /config/derby-10.10.1.1.jar

    RUN installUtility install –acceptLicense defaultServer

  6. Build Docker Image of Sample DayTrader7

    1. From the sample directory /../sample.daytrader7 where Dockerfile exists, run the following command to build the docker image.

    docker build –no-cache -t sample.daytrader7 .

    Note: You may use different image name than the specified sample.daytrader7.  Also note the dot at the end of command, which indicates to build from the current directory.

    2. Once the docker build command is complete, run the following command to view the built image:

    docker images

    Make a note of image id under IMAGE ID to be used for next step.

  7. Push Docker Image to a Repository

    There are two types of repositories you can push the image to:

    Option 1: Push to docker hub

    Note: this option requires a docker hub id, password.

    • Docker login to docker hub by running the following command:

    docker login

    Enter your docker hub id and password:

    Username:

    Password:

    • Docker tag the image by running the following command:

    docker tag  <image id> <docker hub id>/sample.daytrader7:ee7

    • Docker push the image to docker hub by running the following command:

    docker push <docker hub id>/sample.daytrader7:ee7

    • Verify the image is pushed to docker hub by logging in to www.docker.com (or https://hub.docker.com/) and confirm the repository.

     

    Option 2: Push to IBM Cloud Private registry

    • Docker tag the image by running the following command:

    docker tag <image id> mycluster.icp:8500/default/sample.daytrader7:ee7

    Note: mycluster.icp in the command is the default value of the certificate authority (CA) domain that was set in the config.yaml file during IBM Cloud Private installation, default is the default namespace, and ee7 is the image tag name user defined.

    • View docker images with the new repository name created

    docker images

    • Docker login to IBM Cloud Private by running the following command with ICP management console admin id and password:

    docker login mycluster.icp:8500

    • Docker push the image to IBM Cloud Private by running the following command:

    docker push mycluster.icp:8500/default/sample.daytrader7:ee7

    • Verify the pushed image is displayed in ICP management console dashboard (https://<master IP>:8443)

    Login to the management console.

    From the dashboard, select Manage and Images.

  8. Install Sample DayTrader7 Using WebSphere Liberty Helm Chart

    From IBM Cloud Private management console, select Catalog tab on the right top menu, enter search text (for example, ‘liberty’), locate ‘ibm-websphere-liberty‘ tile and select:

     

    liberty_1

     

    From the next page, select the chart version 1.6.0 (Note: For the demonstration purpose, the version 1.6.0 is used).

     

    liberty_2

     

    Note: The readme page provides details regarding the helm chart, you may review for more information.

     

     On the bottom of readme page, click on Configure button to start configuring the helm chart.

     

    • Enter release name, select default namespace and check/accept the license

     

    liberty_3

     

    • Enter the image name under Repository
    • Note: By default, the image name websphere-liberty is listed under Repository, remove it and enter the image specified (for example, if using ICP private registry, the image name is mycluster.icp:8500/default/sample.daytrader7; if using docker hub image, the image name is <your dockerhub id>/sample.daytrader7); and by default the tag name latest is listed under Tag, remove it and enter the tag specified (for example, ee7)

     

    liberty_4-1

     

    • By default http service is enabled with ssl port 9443.

    liberty_5

     

    • Leave JMS Service and IIOP Service as default (without explicit enabelment). The sample daytrader liberty server.xml is enabled with wasJmsServer-1.0 feature which by default provides the jms provider service port.

     

    • By default, SSL is enabled (which will add the ssl feature to the liberty application server and will automatically generate a self-signed certificate, a keystore, and configuration for the defaultSSLConfig.)
    • Note: In this demonstration, the default SSL self-signed certificate is used; for cross-application communication, you may select ‘cluster SSL configuration’.¬† To learn more about the configuration, refer the helm chart readme page.

     

    liberty_7-1

     

    • Enable Ingress and enter the sample daytrader application context root /daytrader
    • Note: By default, if the Host and Secret name are not provided, the Host will be automatically resolved to proxy node IP and the secret will be automatically generated.

    liberty_8

     

    • Take the rest of configuration as default.

     

    • Select Install button at the bottom of the page.

     

    • After few seconds, the following pop-up is displayed.¬† Select View Helm Release for more details of the helm release installation.

     

    liberty_9

     

    • Note: Intermittently, in some case, the above pop-up doesn’t display and the error message similar to the following appeared.¬† Please ignore this known message on ICP 2.1.0.3, which has been fixed in the follow-on ICP releases.¬† This message doesn’t affect the helm installation.

     

    liberty_6

     

    • Note: If you miss the pop-up to select View Helm Release, you may access the page from the menu -> Workloads -> Helm Releases, and search for the installed helm release.

     

  9. Access Sample DayTrader7 Application

    Before accessing the Sample daytrader7 application via browser, check the helm chart deployment status.

    On the page of sample daytrader helm release, it provides a summary view of configuration including the deployment, ingress,  network service, secret, etc.

    To determine if the deployment is successful, validate the number uner AVAILABLE on the Deployment row where 1 indicates success and 0 failure.

     

    liberty_10-1

     

     

    • Once the deployment is successful, a Launch button at the upper right of the page can be clicked to access the sample daytrader application home page.
    • After clicking on Launch button, the application page will be displayed as follows.
    • Note: The URL on the browser should indicate the ssl access via https with the proxy node IP and the application context root /daytrader

     

    liberty_11

     

    Note: If the deployment is not succesful (that is, ‘0’ is under AVAILABLE from the helm release page after some time of deployment), you may check the logs under Logs tab of Pod page (inside the Deployment page) to determine the cause.

    Pod:

    liberty_16

  10. Database Configuration

    Before running the application (for user login, view their portfolio, lookup stock quotes, and buy or sell stock shares), the database configuration should be performed for creating database tables and populating users and quotes. 

    Reminder:

    1. In this demonstration, Derby database is configured as seen in server.xml and Dockerfile where the associated jdbc driver is set.

    2. When you check the pod logs from the helm release page even after the application is accessed, you may experience known error message such as “javax.ejb.NoSuchEJBException”, which is due to database configuration is not available yet.¬† See below steps for the related configuration.

    • Create tables and indexes by selecting Configuration tab on the application page and then selecting the link (Re)-create DayTrader Database Tables and Indexes.¬† The operation is then proceeded and the page is displayed with a result similar to the following.
      • Note: As indicated in the result page, the application is required to restart to take the change to effect.¬† From this deployment within ICP, this means the docker container to be restarted.¬† To restart docker container,
        • ssh to the worker node where the helm release is deployed. To locate the worker node, view the Helm Release page of the application where the deployment link will take you to the associated pod information including Host IP.
        • on the worker node, run docker ps to locate the CONTAINER ID for the deployment
        • run docker container restart <container id>

     

    liberty_12

     

    • Once the docker container is restarted, refresh the Sample daytrader7 application web page (https with the proxy node IP and the application context root /daytrader)
    • Populate database by selecting Configuration tab on the application page and then selecting the link (Re)-populate DayTrader Database. The operation is then proceeded and the page is displayed with the output similar to the following, where at the end of operation, the message “DayTrader Database Built – 15000users createdCurrent DayTrader Configuraiton” indicates the success in populating.
      • Note: The number of quotes and users is set as default as in the Configuration table (DayTrader Max Users, Trade Max Quotes).

     

    liberty_13

     

    . . .

     

    liberty_14

  11. Run Sample DayTrader7 Application

    From the Sample daytrader7 application web page, select Trading & Portfolios tab and select Log in

    Note: The users are pre-populated from the above step, and the password is pre-filled.¬† Select Log in to proceed.¬† You may replace username with different uid number (for exmaple, uid:14999 the last uid) as long as it’s within the populated users.

     

    liberty_15

     

    After logging in, start the trading from the tab Quotes/Trade (to buy), the tab Portfolio (to sell), and other tabs to look up the information.

    After finishing the trading, you may select Logoff tab to return to the Log in page.

     

    In conclusion, the sample daytrader7 application is running from IBM Cloud Private as it were running from an on-prem environment.

     

    By Mei-hsiang Chang

  12. Additional Notes

    1. The recipe describes the helm release deployment via ICP management console. Alternatively, the same deployment can also be performed via helm CLI.  Refer the ibm-websphere-liberty helm chart readme for more information.  For example,

    helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/

    helm install ibm-charts/ibm-websphere-liberty –version 1.6.0 –name sample-daytrader –set image.repository=mycluster.icp:8500/default/sample.daytrader7 –set image.tag=ee7 –set ingress.enabled=true –set ingress.path=”/daytrader” –set ingress.rewriteTarget=”/daytrader” –tls

    To view the deployed helm release:

    helm list –tls | grep daytrader¬† (or from the management console Helm Release page)

     

    2. The recipe describes where to check the logs on the pod from the management console.  Alternatively, you may use kubenetes command line to check, for example,

    kubectl get pods (to view the associated pod name on the sample daytrder deployment)

    kubectl logs -f <pod name>

     

    3. The sample daytrader application can be run with IBM DB2 database; to deploy the application on ICP using DB2, you will update Dockerfile and server.xml to reflect the DB2 jdbc driver, for example,

    Dockefile:

    #DB2
    COPY db2jars/db2jcc4.jar /config/db2jcc4.jar

    server.xml:

    <jdbcDriver id=”DB2JCC” libraryRef=”DB2JCCLib”/>
    <library id=”DB2JCCLib” filesetRef=”DB2JCCFileset”/>
    <fileset id=”DB2JCCFileset” dir=”${server.config.dir}” includes=”db2jcc4.jar”/>

    <authData id=”TradeDataSourceAuthData” user=”yourdb2id” password=”yourpassword”/>

    <authData id=”TradeAdminAuthData” user=”yourdb2id” password=”yourpassword”/>

    <dataSource jndiName=”jdbc/TradeDataSource” id=”DefaultDataSource” jdbcDriverRef=”DB2JCC” connectionManagerRef=”conMgr1″ statementCacheSize=”60″ isolationLevel=”TRANSACTION_READ_COMMITTED”>

    <properties serverName=”db2server host or ip” portNumber=”some number” databaseName=”tradedb” driverType=”4″ user=”yourdb2id” password=”yourpassword”/> </dataSource>

    • You will need to make the db2 server connection available for the related configuration in server.xml and the related jdbc driver in the location as specified in Dockerfile.
    • IBM DB2 helm chart is also available in ICP; if you would like to run the sample daytrader application with the DB2 deployed in ICP, you may refer another recipe for more information on how to deploy DB2 helm chart: here

Join The Discussion