- Circuit Breaker Spring Boot Example
- Introduction
- Deploying application on OpenShift using Dekorate
- Deploying application on OpenShift using Helm
- Deploying application on Kubernetes using Helm
- Running Tests on OpenShift using Dekorate
- Running Tests on OpenShift using S2i from Source
- Running Tests on OpenShift using Helm
- Running Tests on Kubernetes with Helm
- Test the service
https://appdev.openshift.io/docs/spring-boot-runtime.html#mission-circuit-breaker-spring-boot
- For the Greeting Service:
./mvnw clean verify -pl greeting-service -Popenshift -Ddekorate.deploy=true
- For the Name Service:
./mvnw clean verify -pl name-service -Popenshift -Ddekorate.deploy=true
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 circuit-breaker ./helm --set name-service.route.expose=true --set name-service.s2i.source.repo=https://github.com/snowdrop/circuit-breaker-example --set name-service.s2i.source.ref=<branch-to-use> --set greeting-service.route.expose=true --set greeting-service.s2i.source.repo=https://github.com/snowdrop/circuit-breaker-example --set greeting-service.s2i.source.ref=<branch-to-use>
note: Replace <branch-to-use>
with one branch from https://github.com/snowdrop/circuit-breaker-example/branches/all
.
And to uninstall the chart, execute:
helm uninstall circuit-breaker
Requirements:
- Have installed the Helm command line
- Have connected/logged to a kubernetes cluster
You need to install the example by doing:
helm install circuit-breaker ./helm -n <k8s namespace> --set name-service.ingress.host=<your k8s domain> --set greeting-service.ingress.host=<your k8s domain>
And to uninstall the chart, execute:
helm uninstall circuit-breaker
./run_tests_with_dekorate_in_ocp.sh
./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/circuit-breaker-example" branch-to-test
./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/circuit-breaker-example" branch-to-test
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"
This service can be tested using the following Maven task.
$ mvn clean verify
$ oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
greeting greeting-circuit-breaker.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance greeting 8080 None
spring-boot-circuit-breaker-greeting spring-boot-circuit-breaker-greeting-circuit-breaker.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance spring-boot-circuit-breaker-greeting 8080 None
spring-boot-circuit-breaker-name spring-boot-circuit-breaker-name-circuit-breaker.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance spring-boot-circuit-breaker-name 8080 None
Check the name-service state.
$ curl http://spring-boot-circuit-breaker-name-default.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/info
{"state":"ok"}
Call the name-service name service on OK state.
$ curl http://spring-boot-circuit-breaker-name-default.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/name
World
Set the service status to FAIL using GET.
$ curl "http://spring-boot-circuit-breaker-name-default.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/state?state=fail"
{"state":"fail"}
Call the name-service name service on fail state.
$ curl -v http://spring-boot-circuit-breaker-name-default.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/name
...
< HTTP/1.1 500
...
Name service down
Set the service status to OK using PUT.
$ curl -X PUT -H "Content-Type: application/json" --data '{"state":"ok"}' "http://spring-boot-circuit-breaker-name-default.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/state"
{"state":"ok"}
Call the greeting service having the name service OK.
$ curl -X PUT -H "Content-Type: application/json" --data '{"state":"ok"}' "http://greeting-circuit-breaker.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/state"
{"content":"Hello, World!"}
Set the service status to FAIL using PUT.
$ curl -X PUT -H "Content-Type: application/json" --data '{"state":"fail"}' "http://spring-boot-circuit-breaker-name-default.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/state"
{"state":"fail"}
Call the greeting service having the name service OK.
$ curl -X PUT -H "Content-Type: application/json" --data '{"state":"ok"}' "http://greeting-circuit-breaker.snowdrop-ocp-470-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-0000.my.openshift.instance/api/state"
{"content":"Hello, Fallback!"}