1+ #! /bin/bash
2+ # Copyright (c) 2021 Oracle and/or its affiliates.
3+ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+ # Fail on error
6+ set -e
7+
8+ # Deploy each inventory service and perform perf test
9+ SERVICES=" inventory-helidon inventory-dotnet inventory-go inventory-python inventory-nodejs inventory-helidon-se inventory-plsql"
10+ ORDER_COUNT=1000
11+
12+ # Delete all orders payload
13+ function deleteallorders() {
14+ echo ' {"serviceName": "order", "commandName": "deleteallorders", "orderId": -1, "orderItem": "", "deliverTo": ""}'
15+ }
16+
17+ function order() {
18+ echo ' {"serviceName": "order", "commandName": "' " $2 " ' ", "orderId": ' " $1 " ' , "orderItem": "sushi", "deliverTo": "780 PANORAMA DR, San francisco, CA"}'
19+ }
20+
21+ function inventory() {
22+ echo ' {"serviceName": "supplier", "commandName": "' " $2 " ' ", "orderId": -1, "orderItem": "' " $1 " ' ", "deliverTo": ""}'
23+ }
24+
25+ function placeOrderTest() {
26+ # Place order
27+ local ORDER_ID=" $1 "
28+ if ! wget -q --http-user grabdish --http-password " $TEST_UI_PASSWORD " --no-check-certificate --post-data " $( order " $ORDER_ID " ' placeOrder' ) " \
29+ --header=' Content-Type: application/json' " $( state_get FRONTEND_URL) /placeorder" -O $GRABDISH_LOG /order & > /dev/null;
30+ then
31+ echo " PERF_LOG_FAILED_FATAL: placeOrder $ORDER_ID failed"
32+ exit
33+ fi
34+ }
35+
36+ function addInventoryTest() {
37+ # Add inventory
38+ local ITEM_ID=" $1 "
39+ if ! wget --http-user grabdish --http-password " $TEST_UI_PASSWORD " --no-check-certificate --post-data " $( inventory " $ITEM_ID " ' addInventory' ) " \
40+ --header=' Content-Type: application/json' " $( state_get FRONTEND_URL) /command" -O $GRABDISH_LOG /inventory & > /dev/null;
41+ then
42+ echo " PERF_LOG_FAILED_FATAL: addInventory $ITEM_ID request failed"
43+ exit
44+ fi
45+ }
46+
47+ # Create the ext-order service
48+ cd $GRABDISH_HOME /order-helidon;
49+ kubectl apply -f ext-order-service.yaml -n msdataworkshop
50+
51+ # Install k6
52+ cd $GRABDISH_HOME /k6;
53+ if ! test -f k6; then
54+ wget https://github.com/loadimpact/k6/releases/download/v0.27.0/k6-v0.27.0-linux64.tar.gz;
55+ tar -xzf k6-v0.27.0-linux64.tar.gz;
56+ ln k6-v0.27.0-linux64/k6 k6
57+ fi
58+
59+ # Get LB (may have to retry)
60+ RETRIES=0
61+ while ! state_done EXT_ORDER_IP; do
62+ IP=` kubectl get services -n msdataworkshop | awk ' /ext-order/ {print $4}' `
63+ if [[ " $IP " =~ ^[0-9]{1,3}\. [0-9]{1,3}\. [0-9]{1,3}\. [0-9]{1,3}$ ]]; then
64+ state_set EXT_ORDER_IP " $IP "
65+ else
66+ RETRIES=$(( $RETRIES + 1 ))
67+ echo " Waiting for EXT_ORDER IP"
68+ if test $RETRIES -gt 24; then
69+ echo " ERROR: Failed to get EXT_ORDER_IP"
70+ exit
71+ fi
72+ sleep 5
73+ fi
74+ done
75+
76+
77+ for s in $SERVICES ; do
78+ echo " PERF_LOG: Testing $s "
79+
80+ # Delete all order (to refresh)
81+ if wget --http-user grabdish --http-password " $TEST_UI_PASSWORD " --no-check-certificate --post-data " $( deleteallorders) " \
82+ --header=' Content-Type: application/json' " $( state_get FRONTEND_URL) /command" -O $GRABDISH_LOG /order & > /dev/null;
83+ then
84+ echo " PERF_LOG: $s deleteallorders succeeded"
85+ else
86+ echo " PERF_LOG_FAILED_FATAL: $s deleteallorders failed"
87+ exit
88+ fi
89+
90+
91+ # Create a large number of orders
92+ cd $GRABDISH_HOME /k6;
93+ export LB=$( state_get EXT_ORDER_IP)
94+ ./test-perf.sh $ORDER_COUNT
95+
96+ # Add the inventory
97+ export TNS_ADMIN=$GRABDISH_HOME /wallet
98+ INVENTORY_DB_SVC=" $( state_get INVENTORY_DB_NAME) _tp"
99+ INVENTORY_USER=INVENTORYUSER
100+ DB_PASSWORD=` kubectl get secret dbuser -n msdataworkshop --template={{.data.dbpassword}} | base64 --decode`
101+ U=$INVENTORY_USER
102+ SVC=$INVENTORY_DB_SVC
103+ sqlplus /nolog << !
104+
105+ connect $U /"$DB_PASSWORD "@$SVC
106+ update inventory set inventorycount=$ORDER_COUNT ;
107+ commit;
108+ !
109+
110+
111+ # Deploy the test subject
112+ cd $GRABDISH_HOME /$s
113+ ./deploy.sh
114+
115+ if test " $s " ! = ' inventory-plsql' ; then # PL/SQL service is not deployed in k8s and starts immediately
116+ while test 1 -gt ` kubectl get pods -n msdataworkshop | grep " ${s} " | grep " 1/1" | wc -l` ; do
117+ echo " Waiting for pod to start..."
118+ sleep 1
119+ done
120+ fi
121+
122+ START_TIME=` date`
123+ START_SECONDS=" $( date -u +%s) "
124+ echo " PERF_LOG: $s Processing started at $START_TIME "
125+
126+ # Monitor to see how long it takes to consume all the inventory
127+ while true ;
128+ do
129+ if wget --http-user grabdish --http-password " $TEST_UI_PASSWORD " --no-check-certificate --post-data " $( inventory sushi ' getInventory' ) " \
130+ --header=' Content-Type: application/json' " $( state_get FRONTEND_URL) /command" -O $GRABDISH_LOG /inventory & > /dev/null;
131+ then
132+ if grep " inventorycount for sushi is now 0" $GRABDISH_LOG /inventory > /dev/null; then
133+ break
134+ fi
135+ else
136+ echo " PERF_LOG_FAILED_FATAL: $s Failed to get inventory count"
137+ exit
138+ fi
139+ sleep 1
140+ done
141+
142+ END_TIME=` date`
143+ END_SECONDS=" $( date -u +%s) "
144+ echo " PERF_LOG: $s Processing completed at $END_TIME "
145+ echo " PERF_LOG_STAT: $s Processed $ORDER_COUNT orders in $(( $END_SECONDS - $START_SECONDS )) seconds"
146+
147+ logpodnotail inventory > $GRABDISH_LOG /perflog-$s
148+
149+ # Undeploy the test subject
150+ cd $GRABDISH_HOME /$s
151+ ./undeploy.sh
152+
153+ # Wait for Pod to stop
154+ while test 0 -lt ` kubectl get pods -n msdataworkshop | egrep ' inventory-' | wc -l` ; do
155+ echo " Waiting for pod to stop..."
156+ sleep 5
157+ done
158+
159+ done
0 commit comments