Skip to content

jacobdotcosta/circuit-breaker-example

This branch is 5 commits ahead of, 2 commits behind snowdrop/circuit-breaker-example:sb-2.7.x.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d3b56af · Jun 7, 2022
Feb 8, 2022
Jun 8, 2018
Feb 27, 2018
Jun 7, 2022
Feb 8, 2022
Jun 7, 2022
Jan 28, 2022
Jun 7, 2022
Jun 6, 2018
Jun 7, 2022
Jun 8, 2017
Jun 8, 2017
Feb 8, 2022
Jun 8, 2018
Jun 8, 2018
Jun 7, 2022
Jun 7, 2022
Feb 8, 2022
Feb 8, 2022
Jan 28, 2022

Repository files navigation

Circuit Breaker Spring Boot Example

Table of Contents

Introduction

https://appdev.openshift.io/docs/spring-boot-runtime.html#mission-circuit-breaker-spring-boot

Deploying application on OpenShift using Dekorate

  • 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

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 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

Deploying application on Kubernetes using Helm

Requirements:

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

Running Tests on OpenShift using Dekorate

sh run_tests_with_dekorate.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/circuit-breaker-example" branch-to-test

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/circuit-breaker-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"

Test the service

Maven Test

This service can be tested using the following Maven task.

$ mvn clean verify

Manual Test

$ 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!"}

About

Spring Boot Circuit Breaker Booster

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 57.4%
  • XSLT 25.4%
  • HTML 16.6%
  • Shell 0.6%