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

The scripts should get a valid access token from the Auth server #12

Open
wants to merge 2 commits 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
11 changes: 9 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
.. `springbox-recommendations`
.. `springbox-api-gateway`

. Load data into the reviews DB by running `springbox-reviews/scripts/loadReviews.sh`.
. For the scripts to work, you need to install `jq` which is a sed-like tool for working with JSON data. You can find it [here](https://stedolan.github.io/jq/download/).
. Load data into the reviews DB by running springbox-reviews/scripts/loadReviews.sh.

. Load data into the recommendations DB by running `springbox-recommendations/scripts/loadGraph.sh`.
cd springbox-reviews/scripts/
./loadReviews.sh localhost 9999 localhost 8081

. Load data into the recommendations DB by running springbox-recommendations/scripts/loadGraph.sh.

cd springbox-recommendations/scripts/
./loadGraph.sh localhost 9999 localhost 8082

. Visit http://localhost:9000 and you should see something like the following:
+
Expand Down
48 changes: 45 additions & 3 deletions springbox-recommendations/scripts/loadGraph.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
#!/bin/bash
./loadPeople.sh
./loadMovies.sh
./loadLikes.sh

usage() {
echo "Error: missing argument"
echo
echo "Usage: $0 [OAUTH_SERVER_HOSTNAME] [OAUTH_SERVER_PORT] [RECOMMENDATIONS_HOSTNAME] [RECOMMENDATIONS_PORT]"
echo " eg. $0 localhost 9999 localhost 8082"
exit 1
}

header() {
echo "================================================================================"
echo $@ | sed -e :a -e 's/^.\{1,77\}$/ & /;ta'
echo "================================================================================"

}

OAUTH_SERVER_HOSTNAME="$1"
if [ "$OAUTH_SERVER_HOSTNAME" == "" ] ; then
usage
fi

OAUTH_SERVER_PORT="$2"
if [ "$OAUTH_SERVER_PORT" == "" ] ; then
usage
fi

RECOMMENDATIONS_HOSTNAME="$3"
if [ "$RECOMMENDATIONS_HOSTNAME" == "" ] ; then
usage
fi
RECOMMENDATIONS_PORT="$4"
if [ "$RECOMMENDATIONS_PORT" == "" ] ; then
usage
fi

header "Getting access token from server..."
TOKEN=$(curl -X POST -d "grant_type=password&username=mstine&password=secret" http://${OAUTH_SERVER_HOSTNAME}:${OAUTH_SERVER_PORT}/uaa/oauth/token -H "Authorization: Basic YWNtZTphY21lc2VjcmV0" | jq -r '.access_token')
echo "access_token: ${TOKEN}"

header "Loading People..."
./loadPeople.sh ${TOKEN} ${RECOMMENDATIONS_HOSTNAME} ${RECOMMENDATIONS_PORT}
header "Loading Movies..."
./loadMovies.sh ${TOKEN} ${RECOMMENDATIONS_HOSTNAME} ${RECOMMENDATIONS_PORT}
header "Loading Likes..."
./loadLikes.sh ${TOKEN} ${RECOMMENDATIONS_HOSTNAME} ${RECOMMENDATIONS_PORT}
19 changes: 10 additions & 9 deletions springbox-recommendations/scripts/loadLikes.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
ROUTE=${ROUTE:-localhost:8082}
curl -X POST ${ROUTE}/recommendations/mstine/likes/1
curl -X POST ${ROUTE}/recommendations/mstine/likes/2
curl -X POST ${ROUTE}/recommendations/starbuxman/likes/2
curl -X POST ${ROUTE}/recommendations/starbuxman/likes/4
curl -X POST ${ROUTE}/recommendations/starbuxman/likes/5
curl -X POST ${ROUTE}/recommendations/littleidea/likes/2
curl -X POST ${ROUTE}/recommendations/littleidea/likes/3
curl -X POST ${ROUTE}/recommendations/littleidea/likes/5
TOKEN="$1"
ROUTE="$2:$3"
curl -X POST ${ROUTE}/recommendations/mstine/likes/1 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/mstine/likes/2 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/starbuxman/likes/2 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/starbuxman/likes/4 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/starbuxman/likes/5 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/littleidea/likes/2 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/littleidea/likes/3 -H "Authorization: Bearer ${TOKEN}"
curl -X POST ${ROUTE}/recommendations/littleidea/likes/5 -H "Authorization: Bearer ${TOKEN}"
13 changes: 7 additions & 6 deletions springbox-recommendations/scripts/loadMovies.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
ROUTE=${ROUTE:-localhost:8082}
curl ${ROUTE}/movies -X POST -d '{"mlId":"1","title":"Toy Story (1995)"}' -H "Content-Type: application/json"
curl ${ROUTE}/movies -X POST -d '{"mlId":"2","title":"GoldenEye (1995)"}' -H "Content-Type: application/json"
curl ${ROUTE}/movies -X POST -d '{"mlId":"3","title":"Four Rooms (1995)"}' -H "Content-Type: application/json"
curl ${ROUTE}/movies -X POST -d '{"mlId":"4","title":"Get Shorty (1995)"}' -H "Content-Type: application/json"
curl ${ROUTE}/movies -X POST -d '{"mlId":"5","title":"Copycat (1995)"}' -H "Content-Type: application/json"
TOKEN="$1"
ROUTE="$2:$3"
curl ${ROUTE}/movies -X POST -d '{"mlId":"1","title":"Toy Story (1995)"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
curl ${ROUTE}/movies -X POST -d '{"mlId":"2","title":"GoldenEye (1995)"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
curl ${ROUTE}/movies -X POST -d '{"mlId":"3","title":"Four Rooms (1995)"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
curl ${ROUTE}/movies -X POST -d '{"mlId":"4","title":"Get Shorty (1995)"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
curl ${ROUTE}/movies -X POST -d '{"mlId":"5","title":"Copycat (1995)"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
9 changes: 5 additions & 4 deletions springbox-recommendations/scripts/loadPeople.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
ROUTE=${ROUTE:-localhost:8082}
curl ${ROUTE}/people -X POST -d '{"userName":"mstine","firstName":"Matt","lastName":"Stine"}' -H "Content-Type: application/json"
curl ${ROUTE}/people -X POST -d '{"userName":"starbuxman","firstName":"Josh","lastName":"Long"}' -H "Content-Type: application/json"
curl ${ROUTE}/people -X POST -d '{"userName":"littleidea","firstName":"Andrew","lastName":"Shafer"}' -H "Content-Type: application/json"
TOKEN="$1"
ROUTE="$2:$3"
curl ${ROUTE}/people -X POST -d '{"userName":"mstine","firstName":"Matt","lastName":"Stine"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
curl ${ROUTE}/people -X POST -d '{"userName":"starbuxman","firstName":"Josh","lastName":"Long"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
curl ${ROUTE}/people -X POST -d '{"userName":"littleidea","firstName":"Andrew","lastName":"Shafer"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}"
58 changes: 49 additions & 9 deletions springbox-reviews/scripts/loadReviews.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
#!/bin/bash
ROUTE=${ROUTE:-localhost:8081}
curl ${ROUTE}/reviews -X POST -d '{"userName":"mstine","mlId":"1","title":"Toy Story (1995)","review":"Great movie!","rating":"5"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"mstine","mlId":"2","title":"GoldenEye (1995)","review":"Pretty good...","rating":"3"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"starbuxman","mlId":"2","title":"GoldenEye (1995)","review":"BOND BOND BOND!","rating":"5"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"starbuxman","mlId":"4","title":"Get Shorty (1995)","review":"Meh","rating":"3" }}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"starbuxman","mlId":"5","title":"Copycat (1995)","review":"Nicely done!","rating":"4"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"littleidea","mlId":"2","title":"GoldenEye (1995)","review":"Good show!","rating":"4"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"littleidea","mlId":"3","title":"Four Rooms (1995)","review":"Could have been better...","rating":"3"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -X POST -d '{"userName":"littleidea","mlId":"5","title":"Copycat (1995)","review":"Nicely done!","rating":"4"}' -H "Content-Type: application/json"

usage() {
echo "Error: missing argument"
echo
echo "Usage: $0 [OAUTH_SERVER_HOSTNAME] [OAUTH_SERVER_PORT] [REVIEWS_HOSTNAME] [REVIEWS_PORT]"
echo " eg. $0 localhost 9999 localhost 8081"
exit 1
}

header() {
echo "================================================================================"
echo $@ | sed -e :a -e 's/^.\{1,77\}$/ & /;ta'
echo "================================================================================"

}

OAUTH_SERVER_HOSTNAME="$1"
if [ "$OAUTH_SERVER_HOSTNAME" == "" ] ; then
usage
fi

OAUTH_SERVER_PORT="$2"
if [ "$OAUTH_SERVER_PORT" == "" ] ; then
usage
fi

REVIEWS_HOSTNAME="$3"
if [ "$REVIEWS_HOSTNAME" == "" ] ; then
usage
fi
REVIEWS_PORT="$4"
if [ "$REVIEWS_PORT" == "" ] ; then
usage
fi

header "Getting access token from server..."
TOKEN=$(curl -X POST -d "grant_type=password&username=mstine&password=secret" http://${OAUTH_SERVER_HOSTNAME}:${OAUTH_SERVER_PORT}/uaa/oauth/token -H "Authorization: Basic YWNtZTphY21lc2VjcmV0" | jq -r '.access_token')
echo "access_token: ${TOKEN}"

ROUTE=${REVIEWS_HOSTNAME}:${REVIEWS_PORT}

curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"mstine","mlId":"1","title":"Toy Story (1995)","review":"Great movie!","rating":"5"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"mstine","mlId":"2","title":"GoldenEye (1995)","review":"Pretty good...","rating":"3"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"starbuxman","mlId":"2","title":"GoldenEye (1995)","review":"BOND BOND BOND!","rating":"5"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"starbuxman","mlId":"4","title":"Get Shorty (1995)","review":"Meh","rating":"3" }}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"starbuxman","mlId":"5","title":"Copycat (1995)","review":"Nicely done!","rating":"4"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"littleidea","mlId":"2","title":"GoldenEye (1995)","review":"Good show!","rating":"4"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"littleidea","mlId":"3","title":"Four Rooms (1995)","review":"Could have been better...","rating":"3"}' -H "Content-Type: application/json"
curl ${ROUTE}/reviews -H "Authorization: Bearer ${TOKEN}" -X POST -d '{"userName":"littleidea","mlId":"5","title":"Copycat (1995)","review":"Nicely done!","rating":"4"}' -H "Content-Type: application/json"