This repository demonstrates how to connect to and use the latest release of Red Hat Data Grid 8.
RHDG provides libraries in several programming languages to consume entries stored in the grid. However, in this section, we will focus on the highly-optimized HotRod Java client. Here the documentation.
This Spring Boot application needs a running Red Hat Data Grid server to connect to either on OCP or locally. If you need help with this task, you can check the code that I have in this sibling repository: alvarolop/rhdg8-server.
If you don’t want a complex setup, you can use the easiest way to deploy the server:
podman run -it -p 11222:11222 -e USER="admin" -e PASS="password" --net=host quay.io/infinispan/server:14.0
This application uses several caches to stores and indexes a Book object serialized using Protostream. Therefore, both the server and the client need to know the details of the serialization. While the client application knows it thanks to several annotations, we need to send the book.proto
definition to the server prior to running the client application.
There are several mechanisms, but probably the REST API is the easiest one:
# Server deployed locally
curl -X POST -k -v -u admin:password --digest localhost:11222/rest/v2/schemas/book.proto -d @protos/book.proto
# Server on OCP
curl -X POST -k -v $RHDG_SECURITY $RHDG_SERVER_ROUTE/rest/v2/schemas/book.proto -d @protos/book.proto
Just use the following command to launch the application locally and test it:
mvn clean spring-boot:run
Deploying your client application on OCP requires creating several Openshift objects. Therefore, we are going to define some common variables that will be used from now onwards:
APP_NAME=rhdg-client
APP_NAMESPACE=rhdg8
RHDG_CLUSTER=rhdg
First, create a ConfigMap that will store your application configuration:
oc create configmap $APP_NAME-config \
--from-file=application.properties=src/main/resources/application-k8s.properties \
--from-file=logback-spring.xml=src/main/resources/logback-spring-k8s.xml -n $APP_NAMESPACE
Second, use an Openshift template to create the resources. There are two templates inside the templates
folder:
Template | Authentication | Authorization | SSL Encryption | Notes |
---|---|---|---|---|
✔️ Not by default |
✔️ Not by default |
❌ Not possible |
Does not allow SSL encryption |
|
✔️ Not by default |
✔️ Not by default |
✔️ By default |
Mounts |
This is the command to apply the template on your cluster:
oc process -f openshift/rhdg-client-basic.yaml \
-p APP_NAME=$APP_NAME \
-p APP_NAMESPACE=$APP_NAMESPACE \
-p RHDG_CLUSTER=$RHDG_CLUSTER \
-p DATAGRID_AUTH_ENABLED=$RHDG_AUTH_ENABLED \
-p DATAGRID_SSL_ENABLED=$RHDG_SSL_ENABLED | oc apply -f -
First, create a Service Monitor to grab metrics:
oc process -f openshift/02-rhdg-service-monitor.yaml \
-p APP_NAME=$APP_NAME \
-p APP_NAMESPACE=$APP_NAMESPACE | oc apply -f -
Second, create a Grafana Dashboard:
oc process -f https://raw.githubusercontent.com/alvarolop/rhdg8-server/main/grafana/grafana-04-dashboard.yaml \
-p DASHBOARD_GZIP="$(cat openshift/grafana-dashboard-rhdg8-client.json | gzip | base64 -w0)" \
-p DASHBOARD_NAME=grafana-dashboard-rhdg8-client | oc apply -f -
This app was conceived to test Hotrod features available in the Java dependency. It also has a simple mechanism to perform load tests on the Data Grid server using the Hot Rod protocol.
The application is split into different classes to simplify code readability.
API | Controller | Description |
---|---|---|
|
CRUD methods to test cache behavior using Spring Cache and Java Serialization |
|
|
CRUD methods to test cache behavior using Proto Serialization |
|
|
CRUD methods to test cache behavior using Proto Serialization over an indexed cache (With Queries) |
|
|
Example of how transactions work in DG, but this is not a real usage example |
|
|
Example of how to use sessions and their reutilization using Hotrod |
|
|
Uploading Proto files and Scripts as well as retrieving statistics |
|
|
Perform load testing to caches containing Strings or Byte[] |
You will need to define different variables depending on where the server is deployed
# 1) Deployed locally
APP_URL="http://localhost:8080"
# 2) Deployed on OCP (Check the rhdg8-server for more details of the deployment)
APP_URL=$(oc get route ${APP_NAME} -n ${APP_NAMESPACE} -o template='http://{{.spec.host}}')
# Put bytes from 0 to 49
curl -k -G -X PUT "${APP_URL}/api/book/cache/${CACHE_NAME}/bytes" -d size=1024 -d entries=50
# Put strings from 100 to 149
curl -k -G -X PUT "${APP_URL}/api/book/cache/${CACHE_NAME}/string" -d minkey=100 -d entries=50
# Get Bulk from 100 to 149
curl -k -G -X GET "${APP_URL}/api/book/cache/${CACHE_NAME}/bulk" -d minkey=100 -d entries=50
# Get byte entry 0
curl -k -G -X GET "${APP_URL}/api/book/cache/${CACHE_NAME}/byte" -d key=0 -d show=true
# Get string entry 101
curl -k -G -X GET "${APP_URL}/api/book/cache/${CACHE_NAME}/string" -d key=101 -d show=true
# Get keys
curl -k -G -X GET "${APP_URL}/api/book/cache/${CACHE_NAME}/keys"
# Remove entries (From 10 to 110)
curl -k -G -X DELETE "${APP_URL}/api/book/cache/${CACHE_NAME}" -d minkey=10 -d entries=100
💡
|
Queries and indexes
These features are not tested against the cache $CACHE_NAME , but against a cache named indexed-cache . It is possible to modify the cache you are going to use in the application.properties file and restart the client application.
|
|
Transactions
Work in progress
|
The REST API provides a very adequate alternative to the Java Hotrod client to interact with RH Data Grid. In the following section we explore the following topics:
-
Managing and configuring caches using the REST API.
-
CRUD operations in a
text/plain
cache. -
CRUD operations in a
application/json
cache. -
CRUD operations in a
application/x-protostream
cache.
>> Click Here <<
-
The RHDG operator provides certificates by default in a secret with name
${RHDG_CLUSTER_NAME}-cert-secret
. -
Both the Spring Starter and the
infinispan-client-hotrod
accept a certificate in.pem
format and build an in-memory KeyStore with all the certificates found under the path provided.
Add the following lines to your application.properties
to configure the Infinispan Spring Starter:
infinispan.remote.use-ssl=true
infinispan.remote.trust-store-path=config/tls.crt
infinispan.remote.sni-host-name=${RHDG_CLUSTER_NAME}.${CLUSTER_NAMESPACE}.svc
Add the following lines to your application.properties
to configure the infinispan-client-hotrod
:
infinispan.client.hotrod.use_ssl=true
infinispan.client.hotrod.trust_store_path=config/tls.crt
infinispan.client.hotrod.sni_host_name=${RHDG_CLUSTER_NAME}.${CLUSTER_NAMESPACE}.svc
For more information about configuration parameters check the following resources:
There are other mechanisms to add the credentials to the client application for cases where you need a custom certificate or non-standard config. For such cases, you can check this old commit previous to deleting that documentation for the sake of simplicity.