Giter VIP home page Giter VIP logo

cache-example's Introduction

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"

cache-example's People

Contributors

alesj avatar atomist-bot avatar aureamunoz avatar cmoulliard avatar geoand avatar iocanel avatar jacobdotcosta avatar ladicek avatar lincolnthree avatar metacosm avatar sgitario avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cache-example's Issues

enforce TTL of 5 seconds for the "cute name" cache entry

Per the mission definition (https://github.com/fabric8-launcher/launcher-documentation/wiki/Mission:-Cache-Service), the cute name cache entry should have a TTL of 5 seconds. This booster doesn't do that, so the cache falls back to the default of 10 seconds as configured in service.cache.yaml. We could of course change that :-), but that's cheating -- we should demonstrate to users how to set the TTL per cache entry (or that's my understanding).

We could do some AOP magic to be able to keep using @Cacheable, but I think it would be easier and more instructive to just use the HotRod API directly.

Can't be deployed on OCP v4

After trying to deploy cache example using:
mvn clean fabric8:deploy -Popenshift
on openshift v4, the deployment fails with error message:
[ERROR] Failed to execute goal io.fabric8:fabric8-maven-plugin:4.4.0:deploy (default-cli) on project spring-boot-cache-greeting: Failed to create Route from openshift.yml. io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://api.ocp4.dynamic.rhoar:6443/oapi/v1/namespaces/mocenas/routes. Message: Forbidden! User rhoarqe/api-ocp4-dynamic-rhoar:6443 doesn't have permission. forbidden: User "rhoarqe" cannot post path "/oapi/v1/namespaces/mocenas/routes".. Route(apiVersion=v1, kind=Route, metadata=ObjectMeta(annotations={app.kubernetes.io/[email protected]:snowdrop/cache-example.git, app.kubernetes.io/connects-to=cute-name-service}, clusterName=null, creationTimestamp=null, deletionGracePeriodSeconds=null, deletionTimestamp=null, finalizers=[], generateName=null, generation=null, labels={app.kubernetes.io/part-of=cache-example, app.kubernetes.io/name=greeting-service, app.kubernetes.io/component=frontend, app.openshift.io/runtime=rh-spring-boot, app.openshift.io/runtime-version=2.3.4.RELEASE, app=spring-boot-cache-greeting, provider=fabric8, version=2.3.4-2-redhat, group=dev.snowdrop.example}, managedFields=[], name=spring-boot-cache-greeting, namespace=null, ownerReferences=[], resourceVersion=null, selfLink=null, uid=null, additionalProperties={}), spec=RouteSpec(alternateBackends=[], host=null, path=null, port=RoutePort(targetPort=IntOrString(IntVal=8080, Kind=0, StrVal=null, additionalProperties={}), additionalProperties={}), subdomain=null, tls=null, to=RouteTargetReference(kind=Service, name=spring-boot-cache-greeting, weight=null, additionalProperties={}), wildcardPolicy=null, additionalProperties={}), status=null, additionalProperties={}) -> [Help 1]

The error message states something about insufficient permission, but I get this message even with cluster-admin privilege.

OCP v3 seems unaffected by this problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.