Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Automated services registration to replace manual URL entry, updated … #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,21 @@ $ cf push -f manifest-services.yml
+
This will push a Spring Cloud Config Server, a Eureka server, and a Hystrix Dashboard, all with random routes.

. Edit `scripts/create_services.sh` to add the random routes that were generated for you:
. Run `./scripts/provision_services.sh` to register these services and provision a Postgres database:
+
----
cf cups config-service -p '{"uri":"http://config-server-fluxional-suttee.cfapps.io"}'
cf cups service-registry -p '{"uri":"http://eureka-unprevalent-toper.cfapps.io"}'
cf cs elephantsql turtle fortunes-db
----
$ scripts/provision_services.sh
Provisioning service registry, config server and database as backing services

. Run `scripts/create-services.sh` to create the services that you need:
+
----
$ scripts/create_services.sh
Creating user provided service config-service in org platform-eng / space nfjs-workshop as [email protected]...
Creating user provided service config-service in org Example / space Example as [email protected]...
OK
Creating user provided service service-registry in org platform-eng / space nfjs-workshop as [email protected]...

Registering service registry application instance 'eureka-example.cfapps.io' as a backing service
Creating user provided service service-registry in org Example / space Example as [email protected]...
OK
Creating service fortunes-db in org platform-eng / space nfjs-workshop as [email protected]...

Provisioning PostgreSQL database
Creating service fortune-db in org Example / space Example as [email protected]...
OK
----

Expand All @@ -85,7 +83,15 @@ OK
$ cf push -f manifest-apps.yml
----
+
This will push the fortunes service and the ui application.
This will push the fortune-service and the fortune-ui application.

. Check the application routes created for your new microservices:
+
----
$ cf apps
----
+
This will show the custom URLs to access your fortune-ui web application and Hystrix dashboard.

== Testing the Application

Expand All @@ -94,12 +100,14 @@ This will push the fortunes service and the ui application.
image:docs/images/fortunes_1.png[]

. Now, in another browser tab, access the Hystrix Dashboard at the route that was created for you.
Enter the route for the UI application and click the ``Monitor Stream.''
Enter the route for the fortune-ui application and click the ``Monitor Stream.''
+
NOTE: On Pivotal Cloud Foundry, you can access a pre-configured Hystrix Dashboard by clicking on the *Manage* link for *Circuit Breaker Dashboard*. You will *NOT* need to paste in the route.
NOTE: On Pivotal Cloud Foundry, you can access a pre-configured Hystrix Dashboard by clicking on the *Manage* link for *Circuit Breaker Dashboard*. You will *NOT* need to paste in the route.
+
image:docs/images/fortunes_2.png[]

Note to modify this to your custom fortune-ui URL including a leading 'http://'' and trailing '/hystrix.stream'.

. Access the fortunes-ui and show that the circuit breaker is registering successful requests.
+
image:docs/images/fortunes_3.png[]
Expand Down Expand Up @@ -127,3 +135,6 @@ $ cf start fortunes
. Continue to access the fortunes-ui and watch the dashboard.
After the fortunes service has re-registered with Eureka and the fortunes-ui load balancer caches are refreshed, you will see the circuit breaker recover.
You should then start getting random fortunes again!

== Teardown
When you're done with the application, you can quickly delete the Fortune Teller application instances and services by running ./scripts/teardown.sh
3 changes: 0 additions & 3 deletions scripts/create_services.sh

This file was deleted.

31 changes: 31 additions & 0 deletions scripts/provision_services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

echo "Provisioning service registry, config server and database as backing services"

# Checking service not already registered
if ! [[ $(cf services | grep "service-registry") ]]; then
# Checking PWS is the target
if [[ $(cf target | grep "https://api.run.pivotal.io") ]]; then

CONFIG_SERVICE_URL=$(cf app config-server | grep "urls: " | cut -c7- )
echo ""
SERVICE_REGISTRY_URL=$(cf app service-registry| grep "urls: " | cut -c7- )

echo "Registering config server application instance '$CONFIG_SERVICE_URL' as a backing service"
echo "http://$CONFIG_SERVICE_URL/" | cf cups config-service -p "uri"

echo "Registering service registry application instance '$SERVICE_REGISTRY_URL' as a backing service"
echo "http://$SERVICE_REGISTRY_URL/" | cf cups service-registry -p "uri"

echo "Provisioning PostgreSQL database"
cf cs elephantsql turtle fortune-db

echo "Listing backing services"
cf services
else
echo "Exiting script as this is intended for provisioning on Pivotal Web Services with API 'https://api.run.pivotal.io'"
fi

else
echo "Exiting script as 'service-registry' found already running"
fi
21 changes: 21 additions & 0 deletions scripts/simulate_traffic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env zsh

echo "Opening Hystrix circuit breaker dashboard in browser to view Forture Teller application under simluated load"
CIRCUIT_BREAKER_URL=$(cf app circuit-breaker | grep "urls: " | cut -c7- )
FORTUNE_UI_URL=$(cf app fortune-ui | grep "urls: " | cut -c7- )

echo
if [[ $CIRCUIT_BREAKER_URL && FORTUNE_UI_URL ]];
then

echo "Request $FORTUNE_UI_URL to seed dashboard"
open "http://$FORTUNE_UI_URL"
echo "Open $FORTUNE_UI_URL service in Hystrix service dashboard at $CIRCUIT_BREAKER_URL"
open "http://$CIRCUIT_BREAKER_URL"'/hystrix/monitor?stream=http%3A%2F%2F'"$FORTUNE_UI_URL"'%2Fhystrix.stream'
echo "Wait 20 seconds for Hystrix dashboard to start streaming results from $FORTUNE_UI_URL"
sleep 20
echo "Hit Fortune Teller UI with 20 web requests to show load characteristics"
ab -m GET -c 1 -n 20 http://$FORTUNE_UI_URL/
else
echo "Script exiting: Expected command 'cf apps' to list apps 'circuit-breaker' and 'fortune-ui'"
fi
24 changes: 24 additions & 0 deletions scripts/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Reset all apps and backing services
if [[ $(cf apps | grep "fortune-service") ]];
then
echo 'Deleting Fortune Teller app instances'
echo Y | cf delete fortune-ui
echo Y | cf delete fortune-service

echo 'De-registering backing services'
echo Y | cf delete-service config-service
echo Y | cf delete-service service-registry
echo Y | cf delete-service fortune-db


echo 'Deleting backing services application instances'
echo Y | cf delete circuit-breaker
echo Y | cf delete config-server
echo Y | cf delete service-registry

echo 'Checking apps and services are now blank'
cf apps
cf services
else
echo "Exiting: No running Fortune Teller instances found. Check that the 'cf apps' command lists 'fortune-service'"
fi