Skip to content

snowdrop/cache-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cache Spring Boot Example

Purpose

The purpose of this use case is to demonstrate how to use Red Hat JBoss Data Grid for Openshift as a cache, to increase the response time of applications. This mission covers:

  • The deployment of the Red Hat JBoss Data Grid on OpenShift

  • How applications leverage this cache service

Technical details

The boosters demonstrates how Spring’s Caching support can interact with the JBoss Datagrid caching server. What that means practically, is that the business code simply uses Spring’s @Cacheable to cache return values

Deploying and interacting with the example

  • Create a new OpenShift project cache-example (or whatever you want to call it):

$ oc new-project cache-example
  • Deploy JBoss Datagrid to Openshift

$ oc apply -f .openshiftio/cache.yml
  • Build and deploy the Spring Boot applications using Dekorate

$ mvn clean verify -pl greeting-service -Popenshift -Ddekorate.deploy=true
$ mvn clean verify -pl cute-name-service -Popenshift -Ddekorate.deploy=true
  • Open the UI of the greeting-service. The URL can be determined by executing

$ oc get route/spring-boot-cache-greeting --template={{.spec.host}}

From the UI the user can invoke the greeting-service which in turn invokes the JBoss Datagrid and perhaps the name-service depending on the state of the cache

  • Execute the integration test using Dekorate to verify the behavior of the system

$ oc delete project cache-example --ignore-not-found=true
$ oc new-project cache-example
$ ./run_tests_with_dekorate_in_ocp.sh

Alternativelly, tests can be executed against a specific Spring Boot or Dekorate version by passing the version as a -D<variable property name>=value parameter. For instance overriding both the Spring Boot and the Dekorate versions using their corresponding version properties is done the following way:

./run_tests_with_dekorate_in_ocp.sh -Dspring-boot.version=2.7.3 -Ddekorate.version=2.11.1
  • Execute the integration test using S2i to verify the behavior of the system

$ oc delete project cache-example --ignore-not-found=true
$ oc new-project cache-example
$ ./run_tests_with_s2i.sh "https://github.com/snowdrop/cache-example" sb-2.4.x

Deploying application on OpenShift using Helm

First, make sure you have installed the Helm command line and connected/logged to a kubernetes cluster.

Then, you need to install the example by doing:

helm install cache ./helm --set cute-name-service.route.expose=true --set cute-name-service.s2i.source.repo=https://github.com/snowdrop/cache-example --set cute-name-service.s2i.source.ref=<branch-to-use> --set greeting-service.route.expose=true --set greeting-service.s2i.source.repo=https://github.com/snowdrop/cache-example --set greeting-service.s2i.source.ref=<branch-to-use>

note: Replace <branch-to-use> with one branch from https://github.com/snowdrop/cache-example/branches/all.

And to uninstall the chart, execute:

helm uninstall cache

Deploying application on Kubernetes using Helm

Requirements: - Have installed [the Helm command line](https://helm.sh/docs/intro/install/) - Have connected/logged to a kubernetes cluster

You need to install the example by doing:

helm install cache ./helm -n <k8s namespace> --set cute-name-service.ingress.host=<your k8s domain> --set greeting-service.ingress.host=<your k8s domain>

And to uninstall the chart, execute:

helm uninstall cache

Running Tests on OpenShift using Dekorate:

sh run_tests_with_dekorate_in_ocp.sh

Running Tests on OpenShift using S2i from Source:

./run_tests_with_s2i.sh

This script can take 2 parameters referring to the repository and the branch to use to source the images from.

./run_tests_with_s2i.sh "https://github.com/snowdrop/cache-example" branch-to-test

Running Tests on Kubernetes with External Registry:

mvn clean verify -Pkubernetes,kubernetes-it -Ddekorate.docker.registry=<url to your registry, example: quay.io> -Ddekorate.push=true

Running Tests on OpenShift using Helm

./run_tests_with_helm_in_ocp.sh

This script can take 2 parameters referring to the repository and the branch to use to source the images from.

./run_tests_with_helm_in_ocp.sh "https://github.com/snowdrop/cache-example" branch-to-test

Running Tests on Kubernetes using Helm

First, you need to create the k8s namespace:

kubectl create namespace <the k8s namespace>

Then, run the tests by specifying the container registry and the kubernetes namespace:

./run_tests_with_helm_in_k8s.sh <your container registry: for example "quay.io/user"> <the k8s namespace>

For example:

./run_tests_with_helm_in_k8s.sh "quay.io/user" "myNamespace"