Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Using JBoss DataGrid in Openshift PaaS

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

April 28, 2017
Francesco Marchioni
Related topics:
Kubernetes
Related products:
Red Hat Data GridRed Hat JBoss Enterprise Application PlatformRed Hat OpenShift Container Platform

    This article describes how to run a client-server application for JBoss Data Grid on Openshift using Red Hat Container Development Kit 3.0 Beta and Minishift. This environment for this tutorial can be set up quickly following up this previous post on the Developer Blog.

    First of all, you need to make sure you have available the ImageStreams and Templates, in order to run JBoss Data Grid in your Openshift Paas. You can check that your environment contains both of them through the oc command as follows:

    $ oc get is -n openshift | grep datagrid
    jboss-datagrid65-openshift            registry.access.redhat.com/jboss-datagrid-6/datagrid65-openshift               1.2,1.2-13,1.2-18 + 2 more...      2 weeks ago
    
    $ oc get templates -n openshift | grep datagrid
    datagrid65-basic                    Application template for JDG 6.5 applications.

    If you don’t have ImageStreams and Templates loaded yet then you can quickly download them from the official repository available at https://github.com/openshift/library/tree/master/official/datagrid.

    Now, you can create both resources as follows:

    # create imagestream
    $ oc create -f Jboss-datagrid65-openshift-rhel7.json
    # create template
    $ oc create -f datagrid65-basic.json

    Ok, now we’re ready to rock. As an example, we will create a new project named “jdg-demo” which will contain the JBoss DataGrid Service, which will be invoked from a client application running in an EAP 6 Service.

    By the way, as mentioned from the Documentation, at the moment Client-Server mode is the only native option to access JBoss Data Grid in a PaaS since Library Mode is not supported.

    In order to create your project, enter the following commands from a shell:

    $ oc new-project jdg-demo
    Now using project "jdg-demo" on server "https://192.168.42.149:8443"

    The New step will be adding a new application to it, using the datagrid65-basic template:

    $ oc new-app datagrid65-basic --name datagrid
    Deploying template "datagrid65-basic" in project "openshift"
    
    datagrid65-basic
    ---------
    Application template for JDG 6.5 applications.
    
    * With parameters:
    * APPLICATION_NAME=datagrid-app
    * HOSTNAME_HTTP=
    * USERNAME=
    * PASSWORD=
    * IMAGE_STREAM_NAMESPACE=openshift
    * INFINISPAN_CONNECTORS=hotrod,memcached,rest
    * CACHE_NAMES=
    * ENCRYPTION_REQUIRE_SSL_CLIENT_AUTH=
    * MEMCACHED_CACHE=default
    * REST_SECURITY_DOMAIN=
    * JGROUPS_CLUSTER_PASSWORD=sKPBot52 # generated
    
    Creating resources with label app=datagrid ...
    service "datagrid-app" created
    service "datagrid-app-memcached" created
    service "datagrid-app-hotrod" created
    route "datagrid-app" created
    deploymentconfig "datagrid-app" created
    Success
    Run 'oc status' to view your app.

    As you could see from the output, a set of services has been created in order to expose the service to the cluster. In particular, we’re interested in the service "datagrid-app-hotrod"  which will be contacted by our EAP client application. To confirm our services are ok, we will execute the following check:

    $ oc get svc
    NAME                     CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
    datagrid-app             172.30.139.80    <none>        8080/TCP    15s
    datagrid-app-hotrod      172.30.10.134    <none>        11333/TCP   15s
    datagrid-app-memcached   172.30.198.163   <none>        11211/TCP   15s

    Ok, we’re almost done. Although we will not explore cluster capabilities in this article, in order to use them the Kubernetes' PING protocol, which is used to look up other nodes in the Infinispan cluster, needs to be enabled. This can be done using the default Service Account as follows:

    $ oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)

    We are done with JBoss data Grid, and our Web console should reflect the status of your available services and route:

    Now let’s add another application, which is based on the jboss-eap64 template and does S2I of a simple web application hosted at https://github.com/fmarchioni/ in the Web Context eap-hotrod:

    $ oc new-app jboss-eap64-openshift~https://github.com/fmarchioni/ocpdemos --name eap-hotrod --context-dir=eap-hotrod -e HOTROD_SERVICE=datagrid-app-hotrod -e HOTROD_SERVICE_PORT=11333
    
    Creating resources with label app=eap-hotrod ...
    imagestream "eap-hotrod" created
    buildconfig "eap-hotrod" created
    deploymentconfig "eap-hotrod" created
    service "eap-hotrod" created
    Success
    Build scheduled, use 'oc logs -f bc/eap-hotrod' to track its progress.
    Run 'oc status' to view your app.

    As you could see, we have passed some environment variables to our application. These variables are used to solve the name of JDG Hot Rod service and its port. As you can see from the minimal Servlet contained in it, we abstract from the Hostname and Port where the Hot Rod service is running and just use the name of Openshift Service (and its port) passed as Environment variable:

    package infinispan;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    
    import java.util.UUID;
    
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.infinispan.client.hotrod.RemoteCache;
    import org.infinispan.client.hotrod.RemoteCacheManager;
    import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
    
    @SuppressWarnings("serial")
    @WebServlet(value = "/test")
    public class TestServlet extends HttpServlet {
    
     private RemoteCacheManager cacheManager;
     private RemoteCache < String, Object > cache;
    
     @Override
     public void init() {
    
      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.addServer().host(System.getenv("HOTROD_SERVICE"))
       .port(Integer.parseInt(System.getenv("HOTROD_SERVICE_PORT")));
      cacheManager = new RemoteCacheManager(builder.build());
      cache = cacheManager.getCache("default");
    
     }
    
     protected void doGet(HttpServletRequest req, HttpServletResponse res) {
      doPost(req, res);
     }
    
     @Override
     protected void doPost(HttpServletRequest req, HttpServletResponse res) {
    
      res.setContentType("text/html");
    
      String name = req.getParameter("name");
      String surname = req.getParameter("surname");
      String teamName = req.getParameter("teamname");
    
    
      PrintWriter out = null;
      try {
       out = res.getWriter();
    
       Player player = new Player();
       player.setName(name);
       player.setSurname(surname);
       player.setTeamName(teamName);
       String randomId = UUID.randomUUID().toString();
    
       cache.put(randomId, player);
    
       out.println("Added Player: " + cache.get(randomId));
    
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
    
     }
    }

    You can complete the example by exposing the EAP route as follows:

    $ oc expose service eap-hotrod
    route "eap-hotrod" exposed

    In a couple of minutes, your service should be available as you can see from the Web console:

    Clicking on the Service’s route, you will be redirected to the welcome page, which is a simple JSP frontend to the Servlet. Add some data in it to test it:

    Finally, when you are done with experimenting, you can remove everything using 'oc delete' command:

    $ oc delete all -l "app=eap-hotrod"
    $ oc delete all -l "app=datagrid"

    About the Author:

    Francesco Marchioni is a Senior Technical Account Manager on Middleware products based in Rome (Italy). Some of its contributions to the Community of JBoss developers are available on the site http://www.mastertheboss.com


    Click here to download JBoss Data Grid.

    Last updated: July 27, 2023

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.