Chapter 3. Getting Started with Red Hat JBoss Data Grid for OpenShift
JBoss Data Grid provides an JBoss Data Grid for OpenShift image stream and set of templates to help you quickly get up and running with JBoss Data Grid deployments on Red Hat OpenShift.
- datagrid72-image-stream
- Image stream for JBoss Data Grid.
- datagrid72-basic
- Run JBoss Data Grid for OpenShift without the need to create OpenShift Secrets.
- datagrid72-https
- Run JBoss Data Grid for OpenShift with an HTTPS route to securely access caches. Requires a JKS keystore in an OpenShift secret.
- datagrid72-mysql
- Run JBoss Data Grid for OpenShift with a MySQL database as an ephemeral cache store. Requires a JKS keystore in an OpenShift secret.
- datagrid72-mysql-persistent
- Run JBoss Data Grid for OpenShift with a MySQL database as a persistent cache store. Requires a JKS keystore in an OpenShift secret.
- datagrid72-postgresql
- Run JBoss Data Grid for OpenShift with a PostgreSQL database as an ephemeral cache store. Requires a JKS keystore in an OpenShift secret.
- datagrid72-postgresql-persistent
- Run JBoss Data Grid for OpenShift with a PostgreSQL database as a persistent cache store. Requires a JKS keystore in an OpenShift secret.
- datagrid72-partition
- Run JBoss Data Grid for OpenShift with a partitioned data directory that preserves metadata for cache entries when the pod restarts. Requires the DATAGRID_SPLIT environment variable. See Configuration Environment Variables.
3.1. Importing JBoss Data Grid for OpenShift Image Templates Copy linkLink copied to clipboard!
The first step to using the JBoss Data Grid for OpenShift image templates is to import them into OpenShift as follows:
On your master host(s), log in as a cluster administrator or a user with project administrator access to the
openshift
namespace.oc login -u system:admin
$ oc login -u system:admin
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import a specific template or all templates.
Import a specific template:
oc create -n openshift -f \ https://raw.githubusercontent.com/jboss-container-images/jboss-datagrid-7-openshift-image/1.3/templates/datagrid72-mysql.json
$ oc create -n openshift -f \ https://raw.githubusercontent.com/jboss-container-images/jboss-datagrid-7-openshift-image/1.3/templates/datagrid72-mysql.json
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import all templates:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow TipUse the
oc create
command to import a new template. Use theoc replace --force
command to overwrite an existing template.
Verify the templates are available on OpenShift.
oc get templates -n openshift | grep datagrid72
$ oc get templates -n openshift | grep datagrid72
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.1.1. Working with the JBoss Data Grid for OpenShift Image Copy linkLink copied to clipboard!
Importing the JBoss Data Grid for OpenShift image templates also imports the jboss-datagrid72-openshift image. When you create a new application from a template, or instantiate a template, you deploy the image in a pod that uses the configuration settings from the template.
In this way, the jboss-datagrid72-openshift image is a general purpose build of JBoss Data Grid. Each template configures the image for specific purposes.
3.1.1.1. Viewing Information about the JBoss Data Grid for OpenShift Image Copy linkLink copied to clipboard!
Run the following command after you import the image templates to view the available image streams for JBoss Data Grid for OpenShift:
oc get is -n openshift | grep datagrid
$ oc get is -n openshift | grep datagrid
The oc get
command shows the jboss-datagrid72-openshift image stream is available in the openshift
namespace. This image stream defines the JBoss Data Grid container image as an available resource for creating deployments.
Run the following command to view information about the jboss-datagrid72-openshift image stream:
oc describe is jboss-datagrid72-openshift -n openshift
$ oc describe is jboss-datagrid72-openshift -n openshift
The oc describe
command shows the tags for the jboss-datagrid72-openshift image stream as well as the location for the container image in the registry.
3.1.1.2. Importing the JBoss Data Grid for OpenShift Image Copy linkLink copied to clipboard!
You can optionally import the JBoss Data Grid for OpenShift image into the openshift
namespace separately to the templates.
To import the JBoss Data Grid for OpenShift image, run the following command:
oc -n openshift import-image jboss-datagrid72-openshift:1.3
$ oc -n openshift import-image jboss-datagrid72-openshift:1.3
JBoss Data Grid for OpenShift templates use the global openshift
namespace as the default for the jboss-datagrid72-openshift
image stream. You can set the IMAGE_STREAM_NAMESPACE environment variable to import templates in a different namespace or project. However you must also ensure that an image stream is available in that namespace.
3.1.2. Importing OpenShift Secrets Copy linkLink copied to clipboard!
You must import or create OpenShift secrets that contain HTTPS and JGroups keystores before you can instantiate templates that require authentication.
JBoss Data Grid for OpenShift provides an example HTTPS and JGroups keystore that you can import as an OpenShift secret. However, this secret is intended for evaluation purposes only. You should not use it in production environments.
Do the following to import the example secret into your project namespace:
oc create \ -f https://raw.githubusercontent.com/jboss-openshift/application-templates/master/secrets/datagrid-app-secret.json
$ oc create \
-f https://raw.githubusercontent.com/jboss-openshift/application-templates/master/secrets/datagrid-app-secret.json
For more information about creating secrets to secure network traffic, see Securing Network Traffic.
3.2. Configuring JBoss Data Grid for OpenShift Deployments Copy linkLink copied to clipboard!
You configure JBoss Data Grid for OpenShift deployments with environment variables that you can set:
- on the command line when you create new applications from templates.
- in templates that you import into OpenShift projects. You can then create pre-configured deployments from those templates.
You can also set environment variables through the OpenShift Web Console. See the relevant OpenShift documentation.
3.2.1. Getting Started with Image Configuration Copy linkLink copied to clipboard!
Run the following command to show the datagrid72-basic
template:
oc describe template datagrid72-basic -n openshift
$ oc describe template datagrid72-basic -n openshift
The output of the oc describe
command shows information about the template as well as the parameters that are set in the template. When you instantiate the datagrid72-basic
template, those parameters configure the following objects:
-
Service
defines a logical set of pods and access policies. -
Route
exposes services externally to pods. -
Deployment Configuration
configures triggers and replicas for the replication controller; also configures pod templates that contain exposed ports for services, environment variables for the image, and so on.
As an example, the output of the oc describe
command shows the following template parameters that set credentials and name caches:
The output of the oc describe
command shows the services, routes, and deployment configuration that the datagrid72-basic
template configures:
When you instantiate the datagrid72-basic
template, the launch script sets those parameters as environment variables for the image in the deployment configuration.
3.2.2. Setting Parameters on the Command Line Copy linkLink copied to clipboard!
Learn how to set parameters for JBoss Data Grid deployments on the command line.
Complete the following steps to:
-
Instantiate the
datagrid72-basic
template to create a new JBoss Data Grid for OpenShift deployment. Set parameters that:
- Define credentials to access the cache over HTTPS and Hot Rod.
-
Create a cache named
mycache
. - Configure the cache to start eagerly.
3.2.2.1. Instantiating the Template Copy linkLink copied to clipboard!
Create a new project.
oc new-project datagrid-env --display-name="Setting Environment Variables"
$ oc new-project datagrid-env --display-name="Setting Environment Variables"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy a new application with the
datagrid72-basic
template. Use the-e
option to pass parameter and value pairs.-
Specify a username:
-e USERNAME=developer
Specify a password:
-e PASSWORD=<value>
The password cannot be the same as the username or root, admin, or, administrator. It must contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), and 1 non-alphanumeric symbol(s).
-
Create a cache named 'mycache':
-e CACHE_NAMES=mycache
Configure the cache to start eagerly:
-e MYCACHE_CACHE_START=EAGER
oc new-app --template=datagrid72-basic --name=rhdg \ -e USERNAME=developer -e PASSWORD=******** \ -e CACHE_NAMES=mycache -e MYCACHE_CACHE_START=EAGER
$ oc new-app --template=datagrid72-basic --name=rhdg \ -e USERNAME=developer -e PASSWORD=******** \ -e CACHE_NAMES=mycache -e MYCACHE_CACHE_START=EAGER
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Specify a username:
Check the application status.
oc status
$ oc status
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2.2.2. Listing Environment Variables Copy linkLink copied to clipboard!
Retrieve the available pods in the project.
oc get pods
$ oc get pods NAME READY STATUS RESTARTS AGE datagrid-app-1-<id> 0/1 Running 1 1m datagrid-app-1-deploy 1/1 Running 0 1m
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List environment variables for the pod named
datagrid-app-1-<id>
. Where<id>
is a randomly generated string such as67q5h
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2.2.3. Changing Environment Variables Copy linkLink copied to clipboard!
Change the deployment configuration so that the cache starts lazily.
oc env dc/datagrid-app -e MYCACHE_CACHE_START=LAZY
$ oc env dc/datagrid-app -e MYCACHE_CACHE_START=LAZY
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command triggers the replication controller to deploys a new version of the application.
Retrieve the updated list of pods.
oc get pods
$ oc get pods NAME READY STATUS RESTARTS AGE datagrid-app-2-<id> 0/1 Running 0 58s datagrid-app-2-deploy 1/1 Running 0 59s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List environment variables for the pod named
datagrid-app-2-<id>
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2.3. Modifying JBoss Data Grid for OpenShift Image Templates Copy linkLink copied to clipboard!
Learn how to set parameters for JBoss Data Grid deployments in reusable image templates.
Complete the following steps to:
-
Export the
datagrid72-basic
template from Red Hat OpenShift. Modify the
datagrid72-basic
template to set parameters that:- Define credentials to access the cache over HTTPS and Hot Rod.
-
Create a cache named
mycache
. - Configure the cache to start eagerly.
- Import the modified template and instantiate it.
3.2.3.1. Exporting the Template Copy linkLink copied to clipboard!
On your master host(s), log in as a cluster administrator or a user with project administrator access to the
openshift
namespace.oc login -u system:admin
$ oc login -u system:admin
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Export the
datagrid72-basic
template to a file nameddatagrid72-extended
.TipYou can export templates with any filename to your home (
~/
) directory.oc export template datagrid72-basic -n openshift > datagrid72-extended
$ oc export template datagrid72-basic -n openshift > datagrid72-extended
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2.3.2. Modifying the Template Copy linkLink copied to clipboard!
Open the exported
datagrid72-extended
file with any text editor.TipTemplates define the deployment configuration in yaml or json format.
In the
labels
section, change the template label to datagrid72-extended.labels: template: datagrid72-extended
labels: template: datagrid72-extended
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the
metadata
section, change the template name to datagrid72-extended.metadata: name: datagrid72-extended
metadata: name: datagrid72-extended
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the
parameters
section, add values for the USERNAME, PASSWORD, CACHE_NAMES, and <CACHE_NAME>_CACHE_START environment variables.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add an 'env' definition for the <CACHE_NAME>_CACHE_START environment variable to the deployment configuration.
spec: containers: -env: -name: MYCACHE_CACHE_START value: ${MYCACHE_CACHE_START}
spec: containers: -env: -name: MYCACHE_CACHE_START value: ${MYCACHE_CACHE_START}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save and close the
datagrid72-extended
file.
3.2.3.3. Importing and Instantiating the Modified Template Copy linkLink copied to clipboard!
Import the modified template into the openshift
namespace.
oc create -n openshift -f datagrid72-extended
$ oc create -n openshift -f datagrid72-extended
After you import the modified template, instantiate it and then list environment variables for the deployed pod.
3.3. Invoking Cache Operations Through the REST Endpoint Copy linkLink copied to clipboard!
JBoss Data Grid provides a REST endpoint through which you can invoke cache operations using standard HTTP methods. The REST endpoint is available by default without the need for configuration.
Complete the following steps to:
-
Create a new project and instantiate the
datagrid72-basic
template. -
Invoke cache operations with the HTTP
GET
,POST
, andDELETE
methods.
3.3.1. Creating a Project and Instantiate a Template Copy linkLink copied to clipboard!
Log in to OpenShift.
oc login -u developer
$ oc login -u developer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a new project.
$ oc new-project datagrid --display-name="RHDG REST Example"
$ $ oc new-project datagrid --display-name="RHDG REST Example"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Instantiate the
datagrid72-basic
template.oc new-app --template=datagrid72-basic --name=rhdg
$ oc new-app --template=datagrid72-basic --name=rhdg
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3.2. Examining Deployed Services Copy linkLink copied to clipboard!
View the deployment status.
oc status
$ oc status
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
oc status
command shows adatagrid-app
HTTP service.In project RHDG REST Example (datagrid) on server https://192.0.2.0:8443 http://datagrid-app-datagrid.192.0.2.0.nip.io (svc/datagrid-app) dc/datagrid-app deploys openshift/jboss-datagrid72-openshift:1.3 deployment
In project RHDG REST Example (datagrid) on server https://192.0.2.0:8443 http://datagrid-app-datagrid.192.0.2.0.nip.io (svc/datagrid-app) dc/datagrid-app deploys openshift/jboss-datagrid72-openshift:1.3 deployment
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Show details about the
datagrid-app
route.oc describe route datagrid-app
$ oc describe route datagrid-app
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
oc describe route
command shows the route where the HTTP service is exposed.Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Note the hostname and IP address for the route. In the following command examples, you must substitute
192.0.2.0
with the correct IP address for your route to the REST endpoint.
3.3.3. Invoking a Get Operation on the Cache Copy linkLink copied to clipboard!
Attempt to get a value for a key named
a
from a cache nameddefault
.curl -i -H "Accept:application/json" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
$ curl -i -H "Accept:application/json" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The key named
a
does not exist in the cache nameddefault
. As a result, you get an HTTP 404 error.HTTP/1.1 404 Not Found content-length: 0 Set-Cookie: 3abf86065a054efa9e7658b871f83223=b78127f864341eb60be6916d847b8b06; path=/; HttpOnly Cache-control: private
HTTP/1.1 404 Not Found content-length: 0 Set-Cookie: 3abf86065a054efa9e7658b871f83223=b78127f864341eb60be6916d847b8b06; path=/; HttpOnly Cache-control: private
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3.4. Inserting and Retrieving an Entry in the Cache Copy linkLink copied to clipboard!
Insert a JSON formatted entry in a key named
a
into the cache nameddefault
.curl -X POST -i -H "Content-type:application/json" \ -d "{\"name\":\"Red Hat Data Grid\"}" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
$ curl -X POST -i -H "Content-type:application/json" \ -d "{\"name\":\"Red Hat Data Grid\"}" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the value of the key that you inserted.
curl -i -H "Accept:application/json" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
$ curl -i -H "Accept:application/json" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You get an HTTP 200 response that contains the key value you set.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3.5. Deleting the Entry from the Cache Copy linkLink copied to clipboard!
Delete the key named
a
.curl -X DELETE -i \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
$ curl -X DELETE -i \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Attempt to retrieve the key value again.
curl -i -H "Accept:application/json" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
$ curl -i -H "Accept:application/json" \ http://rhdgroute-datagrid.192.0.2.0.nip.io/rest/default/a
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You get an HTTP 404 error because you deleted the key.