Chapter 11. Deploying an EAP Infinispan Application with the JBoss Data Grid for OpenShift Image

Complete the steps in this tutorial to see how you can deploy an EAP Infinispan application with the JBoss Data Grid for OpenShift image.

This tutorial uses CarMart quickstart to deploy EAP 6.4 / EAP 7.1 Infinispan application that accesses a remote JBoss Data Grid server running in the same OpenShift project.

11.1. Importing the Latest EAP and JBoss Data Grid for OpenShift Image Streams and Templates

EAP and JBoss Data Grid for OpenShift images are pulled on demand from the Red Hat Registry. As a first step, import the EAP and JBoss Data Grid for OpenShift image streams and templates into the namespace of your OpenShift project.

11.1.1. Log In with Administrator Access

Importing EAP image streams and templates requires administration privileges in the openshift namespace (global project). On your master host(s), you must log in as a cluster administrator or a user with project administrator access to the openshift namespace.

For example, log in with the default system:admin user on the master as follows:

$ oc login -u system:admin

11.1.2. Importing the EAP Images

To import EAP 6.4, run the following command:

$ oc -n openshift import-image jboss-eap64-openshift:1.8

To import EAP 7.1, run the following command:

$ oc -n openshift import-image jboss-eap71-openshift:1.2

11.1.3. Creating the JBoss Data Grid for OpenShift Image Resources

Import the image and templates into Red Hat OpenShift. See Importing Image Templates.

11.2. Creating a Project

Create a new project as follows:

$ oc new-project jdg-bin-demo

11.3. Deploying the JBoss Data Grid 7.2 Server

Deploy the server and specify the following:

  • carcache-hotrod as the name of application,
  • A Hot Rod based connector, and
  • carcache as the name of the Infinispan cache to configure.

    $ oc new-app --name=carcache-hotrod \
    --image-stream=jboss-datagrid72-openshift:1.3 \
    -e INFINISPAN_CONNECTORS=hotrod \
    -e CACHE_NAMES=carcache \
    -e HOTROD_SERVICE_NAME=carcache-hotrod \
    -e HOTROD_AUTHENTICATION=true \
    -e USERNAME=jdguser \
    -e PASSWORD=P@ssword1
    --> Found image d83b4b2 (3 months old) in image stream "openshift/jboss-datagrid72-openshift" under tag "latest" for "jboss-datagrid72-openshift"
    
        JBoss Data Grid 7.2
        -------------------
        Provides a scalable in-memory distributed database designed for fast access to large volumes of data.
    
        Tags: datagrid, java, jboss, xpaas
    
        * This image will be deployed in deployment config "carcache"
        * Ports 11211/tcp, 11222/tcp, 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "carcache"
          * Other containers can access this service through the hostname "carcache"
    
    --> Creating resources ...
        deploymentconfig "carcache" created
        service "carcache" created
    --> Success
        Run 'oc status' to view your app.

11.4. Deploying a Binary Build of EAP 6.4 / EAP 7.1 CarMart Application

  1. Clone the source code.

    $ git clone https://github.com/jboss-openshift/openshift-quickstarts.git
  2. Configure the Red Hat JBoss Middleware Maven repository.
  3. Build the datagrid/carmart application.

    $ cd openshift-quickstarts/datagrid71/carmart/
    $ mvn clean package -Premote-jbossas,openshift
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building JBoss JDG Quickstart: carmart 1.2.0.Final
    [INFO] ------------------------------------------------------------------------
    ...
    [INFO] Building war: /tmp/openshift-quickstarts/datagrid/carmart/target/ROOT.war
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.360 s
    [INFO] Finished at: 2017-06-27T19:11:46+02:00
    [INFO] Final Memory: 34M/310M
    [INFO] ------------------------------------------------------------------------
  1. Verify the directory structure on the local file system.

    Application archives in the deployments/ subdirectory of the main binary build directory are copied directly to the deployments folder of the image being built on OpenShift. For the application to deploy, the directory hierarchy that contains the web application data must be correctly structured.

    However, the carmart application already includes the correct directory structure after building:

    $ ls
    deployments pom.xml  README.md  README-openshift.md  README-tomcat.md  src  target
    $ ls deployments
    ROOT.war
Note

The location of the standard deployments directory depends on the underlying base image that was used to deploy the application.

Table 11.1. Standard Location of the Deployments Directory

Name of the Underlying Base Image(s)Standard Location of the Deployments Directory

EAP for OpenShift 6.4 and 7.1

$JBOSS_HOME/standalone/deployments

Java S2I for OpenShift

/deployments

JWS for OpenShift

$JWS_HOME/webapps

  1. Identify the image stream for the EAP 6.4 / EAP 7.1 image.

    $ oc get is -n openshift | grep eap | cut -d ' ' -f 1
    jboss-eap64-openshift
    jboss-eap71-openshift
  1. Create new binary build, specifying image stream and application name.

    $ oc new-build --binary=true \
    --image-stream=jboss-eap64-openshift:1.8 \
    --name=eap-app
    --> Found image 8fbf0f7 (2 months old) in image stream "openshift/jboss-eap64-openshift" under tag "latest" for "jboss-eap64-openshift"
    
        JBoss EAP 6.4
        -------------
        Platform for building and running JavaEE applications on JBoss EAP 6.4
    
        Tags: builder, javaee, eap, eap6
    
        * A source build using binary input will be created
          * The resulting image will be pushed to image stream "eap-app:latest"
          * A binary build was created, use 'start-build --from-dir' to trigger a new build
    
    --> Creating resources with label build=eap-app ...
        imagestream "eap-app" created
        buildconfig "eap-app" created
    --> Success
    Note

    Specify jboss-eap71-openshift as the image stream name in the preceding command to use EAP 7.1 image for the application.

  2. Start the binary build. Instruct the oc executable to use the main directory of the binary build from the previous step as the directory that contains binary input for the OpenShift build.

    $ oc start-build eap-app --from-dir=deployments/ --follow
    Uploading directory "deployments" as binary input for the build ...
    build "eap-app-1" started
    Receiving source from STDIN as archive ...
    Copying all war artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all ear artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all rar artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all jar artifacts from /home/jboss/source/. directory into /opt/eap/standalone/deployments for later deployment...
    Copying all war artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    '/home/jboss/source/deployments/jboss-carmart.war' -> '/opt/eap/standalone/deployments/jboss-carmart.war'
    Copying all ear artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    Copying all rar artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    Copying all jar artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
    Pushing image 172.30.82.129:5000/jdg-bin-demo/eap-app:latest ...
    Pushed 0/7 layers, 1% complete
    Pushed 1/7 layers, 17% complete
    Pushed 2/7 layers, 31% complete
    Pushed 3/7 layers, 46% complete
    Pushed 4/7 layers, 81% complete
    Pushed 5/7 layers, 84% complete
    Pushed 6/7 layers, 99% complete
    Pushed 7/7 layers, 100% complete
    Push successful
  3. Create a new OpenShift application based on the build.

    $ oc new-app eap-app
    --> Found image ee25340 (3 minutes old) in image stream "jdg-bin-demo/eap-app" under tag "latest" for "eap-app"
    
        jdg-bin-demo/eap-app-1:4bab3f63
        -------------------------------
        Platform for building and running JavaEE applications on JBoss EAP 6.4
    
        Tags: builder, javaee, eap, eap6
    
        * This image will be deployed in deployment config "eap-app"
        * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "eap-app"
          * Other containers can access this service through the hostname "eap-app"
    
    --> Creating resources ...
        deploymentconfig "eap-app" created
        service "eap-app" created
    --> Success
        Run 'oc status' to view your app.
  4. Expose the service as route.

    $ oc get svc -o name
    service/carcache
    service/eap-app
    $ oc get route
    No resources found.
    $ oc expose svc/eap-app
    route "eap-app" exposed
    $ oc get route
    NAME      HOST/PORT                                    PATH      SERVICES   PORT       TERMINATION   WILDCARD
    eap-app   eap-app-jdg-bin-demo.openshift.example.com             eap-app    8080-tcp                 None
  5. Access the application.

    Access the CarMart application in your browser using the URL http://eap-app-jdg-bin-demo.openshift.example.com/. You can view and remove existing cars from the Home tab or add new cars from the New car tab.