Skip to content

Commit f80dded

Browse files
authored
Inventory PL/SQL implementation and a few fixes (#150)
* Pl/SQL Inventory Service * Polishing * Fixed deleteallorders and shortened sleeps * Turn of events for python and nodejs ATP-S does not support FAN * Wait for pod to stop between polyglot tests
1 parent 19b0e5a commit f80dded

File tree

10 files changed

+264
-14
lines changed

10 files changed

+264
-14
lines changed

grabdish/inventory-nodejs/inventory-nodejs-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spec:
3838
- name: DB_CP_QUEUE_TIMEOUT
3939
value: "10000"
4040
- name: DB_M_FAN_EVENTS
41-
value: "true"
41+
value: "false"
4242
- name: AQ_ORDERS_QUEUE_NAME
4343
value: "inventoryuser.orderqueue"
4444
- name: AQ_INVENTORY_QUEUE_NAME

grabdish/inventory-plsql/deploy.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
6+
export TNS_ADMIN=$GRABDISH_HOME/wallet
7+
INVENTORY_DB_SVC="$(state_get INVENTORY_DB_NAME)_tp"
8+
INVENTORY_USER=INVENTORYUSER
9+
DB_PASSWORD=`kubectl get secret dbuser -n msdataworkshop --template={{.data.dbpassword}} | base64 --decode`
10+
11+
U=$INVENTORY_USER
12+
SVC=$INVENTORY_DB_SVC
13+
14+
sqlplus /nolog <<!
15+
16+
connect $U/"$DB_PASSWORD"@$SVC
17+
18+
@$GRABDISH_HOME/inventory-plsql/inventory.sql
19+
20+
BEGIN
21+
DBMS_SCHEDULER.STOP_JOB('inventory_plsql_service');
22+
EXCEPTION
23+
WHEN OTHERS THEN
24+
NULL;
25+
END;
26+
/
27+
28+
BEGIN
29+
DBMS_SCHEDULER.DROP_JOB('inventory_plsql_service');
30+
EXCEPTION
31+
WHEN OTHERS THEN
32+
NULL;
33+
END;
34+
/
35+
36+
BEGIN
37+
DBMS_SCHEDULER.CREATE_JOB (
38+
job_name => 'inventory_plsql_service',
39+
job_type => 'STORED_PROCEDURE',
40+
job_action => 'inventory_plsql',
41+
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10');
42+
43+
DBMS_SCHEDULER.SET_ATTRIBUTE (
44+
'inventory_plsql_service', 'logging_level', DBMS_SCHEDULER.LOGGING_FULL);
45+
46+
DBMS_SCHEDULER.RUN_JOB(
47+
JOB_NAME => 'inventory_plsql_service',
48+
USE_CURRENT_SESSION => FALSE);
49+
END;
50+
/
51+
!
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- Copyright (c) 2021 Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
CREATE OR REPLACE PROCEDURE inventory_plsql
5+
IS
6+
dequeue_options dbms_aq.dequeue_options_t;
7+
enqueue_options dbms_aq.enqueue_options_t;
8+
message_properties dbms_aq.message_properties_t;
9+
message_handle RAW(16);
10+
message SYS.AQ$_JMS_TEXT_MESSAGE;
11+
12+
order_inv_id VARCHAR2(23767);
13+
order_inv_loc VARCHAR2(23767);
14+
order_json JSON_OBJECT_T;
15+
inventory_json JSON_OBJECT_T;
16+
BEGIN
17+
LOOP
18+
-- Wait for and dequeue the next order message
19+
dequeue_options.wait := dbms_aq.FOREVER;
20+
DBMS_AQ.DEQUEUE(
21+
queue_name => 'ORDERQUEUE',
22+
dequeue_options => dequeue_options,
23+
message_properties => message_properties,
24+
payload => message,
25+
msgid => message_handle);
26+
27+
-- Parse the order message
28+
order_json := JSON_OBJECT_T.parse(message.text_vc);
29+
order_inv_id := order_json.get_string('itemid');
30+
31+
-- Check the inventory
32+
update INVENTORYUSER.INVENTORY set inventorycount = inventorycount - 1
33+
where inventoryid = order_inv_id and inventorycount > 0 returning inventorylocation into order_inv_loc;
34+
if sql%rowcount = 0 then
35+
order_inv_loc := 'inventorydoesnotexist';
36+
end if;
37+
38+
-- Construct the inventory message
39+
inventory_json := new JSON_OBJECT_T;
40+
inventory_json.put('orderid', order_json.get_string('orderid'));
41+
inventory_json.put('itemid', order_inv_id);
42+
inventory_json.put('inventorylocation', order_inv_loc);
43+
inventory_json.put('suggestiveSale', 'beer');
44+
45+
-- Send the inventory message
46+
message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
47+
message.set_text(inventory_json.to_string());
48+
DBMS_AQ.ENQUEUE(queue_name => 'INVENTORYQUEUE',
49+
enqueue_options => enqueue_options,
50+
message_properties => message_properties,
51+
payload => message,
52+
msgid => message_handle);
53+
54+
-- commit
55+
commit;
56+
END LOOP;
57+
END;
58+
/

grabdish/inventory-plsql/status.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
6+
export TNS_ADMIN=$GRABDISH_HOME/wallet
7+
INVENTORY_DB_SVC="$(state_get INVENTORY_DB_NAME)_tp"
8+
INVENTORY_USER=INVENTORYUSER
9+
DB_PASSWORD=`kubectl get secret dbuser -n msdataworkshop --template={{.data.dbpassword}} | base64 --decode`
10+
11+
U=$INVENTORY_USER
12+
SVC=$INVENTORY_DB_SVC
13+
14+
sqlplus /nolog <<!
15+
16+
connect $U/"$DB_PASSWORD"@$SVC
17+
18+
select state, logging_level from USER_SCHEDULER_JOBS;
19+
SELECT to_char(log_date, 'DD-MON-YY HH24:MI:SS') TIMESTAMP, job_name,
20+
job_class, operation, status FROM USER_SCHEDULER_JOB_LOG
21+
WHERE job_name = 'JOB2' ORDER BY log_date;
22+
SELECT to_char(log_date, 'DD-MON-YY HH24:MI:SS') TIMESTAMP, job_name, status,
23+
SUBSTR(additional_info, 1, 40) ADDITIONAL_INFO
24+
FROM user_scheduler_job_run_details ORDER BY log_date;
25+
!

grabdish/inventory-plsql/undeploy.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
6+
export TNS_ADMIN=$GRABDISH_HOME/wallet
7+
INVENTORY_DB_SVC="$(state_get INVENTORY_DB_NAME)_tp"
8+
INVENTORY_USER=INVENTORYUSER
9+
DB_PASSWORD=`kubectl get secret dbuser -n msdataworkshop --template={{.data.dbpassword}} | base64 --decode`
10+
11+
U=$INVENTORY_USER
12+
SVC=$INVENTORY_DB_SVC
13+
14+
sqlplus /nolog <<!
15+
16+
connect $U/"$DB_PASSWORD"@$SVC
17+
18+
BEGIN
19+
DBMS_SCHEDULER.STOP_JOB('inventory_plsql_service');
20+
EXCEPTION
21+
WHEN OTHERS THEN
22+
NULL;
23+
END;
24+
/
25+
26+
BEGIN
27+
DBMS_SCHEDULER.DROP_JOB('inventory_plsql_service');
28+
EXCEPTION
29+
WHEN OTHERS THEN
30+
NULL;
31+
END;
32+
/
33+
!

grabdish/inventory-python/common/dbmgr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def run():
101101
max=db_connection_count,
102102
increment=0,
103103
threaded=True,
104-
events=True,
104+
events=False,
105105
getmode=cx_Oracle.SPOOL_ATTRVAL_TIMEDWAIT,
106106
waitTimeout=10000)
107107

grabdish/utils/func-test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ function placeOrderTest() {
2929
}
3030

3131
function showOrderTest() {
32-
echo "TEST_LOG: sleep for 20"
33-
sleep 20
34-
# Show order
32+
# Show order
3533
local ORDER_ID="$1"
3634
local SEARCH_FOR="$2"
3735
if wget -q --http-user grabdish --http-password "$TEST_UI_PASSWORD" --no-check-certificate --post-data "$(order "$ORDER_ID" 'showorder')" \
@@ -57,7 +55,7 @@ function verifyInventoryCountTest() {
5755
if grep "$SEARCH_FOR" $GRABDISH_LOG/inventory >/dev/null; then
5856
echo "TEST_LOG: $TEST_STEP verifyInventoryCountTest $ITEM_ID after ORDER_ID $ORDER_ID expected inventory count: '$SEARCH_FOR'"
5957
else
60-
echo "TEST_LOG: $TEST_STEP verifyInventoryCountTest $ITEM_ID after ORDER_ID $ORDER_ID unexpected inventory count, not '$SEARCH_FOR'" | tr '\n' ' ' ; cat $GRABDISH_LOG/inventory
58+
echo "TEST_LOG_FAILED: $TEST_STEP verifyInventoryCountTest $ITEM_ID after ORDER_ID $ORDER_ID unexpected inventory count, not '$SEARCH_FOR'" | tr '\n' ' ' ; cat $GRABDISH_LOG/inventory
6159
echo ...
6260
fi
6361
else
@@ -83,6 +81,7 @@ verifyInventoryCountTest "sushi" 0 "$ORDER_ID (before placing order)"
8381

8482
placeOrderTest $ORDER_ID
8583

84+
echo "TEST_LOG: sleep for 10"
8685
sleep 10
8786

8887
showOrderTest $ORDER_ID 'failed inventory does not exist'
@@ -96,6 +95,7 @@ ORDER_ID=$(($ORDER_ID + 1))
9695

9796
placeOrderTest "$ORDER_ID"
9897

98+
echo "TEST_LOG: sleep for 10"
9999
sleep 10
100100

101101
showOrderTest "$ORDER_ID" 'success inventory exists'

grabdish/utils/main-test.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ echo "TEST_LOG: #### Testing Lab2: Walkthrough Undeploy..."
2727

2828
# Undeploy to make it rerunable
2929
./undeploy.sh
30-
SERVICES="inventory-python inventory-nodejs inventory-dotnet inventory-go inventory-helidon-se"
30+
SERVICES="inventory-python inventory-nodejs inventory-dotnet inventory-go inventory-helidon-se inventory-plsql"
3131
for s in $SERVICES; do
3232
cd $GRABDISH_HOME/$s
3333
./undeploy.sh || true
@@ -81,10 +81,11 @@ function deleteallorders() {
8181
}
8282

8383
if wget --http-user grabdish --http-password "$TEST_UI_PASSWORD" --no-check-certificate --post-data "$(deleteallorders)" \
84-
--header='Content-Type: application/json' "$(state_get FRONTEND_URL)/placeorder" -O $GRABDISH_LOG/order; then
84+
--header='Content-Type: application/json' "$(state_get FRONTEND_URL)/command" -O $GRABDISH_LOG/order; then
8585
echo "TEST_LOG: $TEST_STEP deleteallorders succeeded"
8686
else
87-
echo "TEST_LOG_FAILED: $TEST_STEP deleteallorders failed"
87+
echo "TEST_LOG_FAILED_FATAL: $TEST_STEP deleteallorders failed"
88+
exit
8889
fi
8990

9091

grabdish/utils/polyglot-test.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,43 @@ set -e
77

88
# Deploy each inventory service and perform functional test
99
#SERVICES="inventory-python inventory-nodejs inventory-dotnet inventory-go inventory-helidon-se"
10-
SERVICES="inventory-dotnet inventory-go inventory-python inventory-nodejs inventory-helidon-se"
10+
SERVICES="inventory-dotnet inventory-go inventory-python inventory-nodejs inventory-helidon-se inventory-plsql"
1111
ORDER_ID=66
1212

1313
cd $GRABDISH_HOME/inventory-helidon
1414
./undeploy.sh
1515

16+
# Wait for Pod to stop
17+
while test 0 -lt `kubectl get pods -n msdataworkshop | egrep 'inventory-' | wc -l`; do
18+
echo "Waiting for pod to stop..."
19+
sleep 5
20+
done
21+
1622
for s in $SERVICES; do
1723
echo "Testing $s"
1824
cd $GRABDISH_HOME/$s
1925
./deploy.sh
2026

21-
while test 1 -gt `kubectl get pods -n msdataworkshop | grep "${s}" | grep "1/1" | wc -l`; do
22-
echo "Waiting for pod to start..."
23-
sleep 5
24-
done
27+
if test "$s" != 'inventory-plsql'; then # PL/SQL service is not deployed in k8s and starts immediately
28+
while test 1 -gt `kubectl get pods -n msdataworkshop | grep "${s}" | grep "1/1" | wc -l`; do
29+
echo "Waiting for pod to start..."
30+
sleep 5
31+
done
32+
fi
2533

2634
cd $GRABDISH_HOME
2735
ORDER_ID=$(($ORDER_ID + 100))
2836
utils/func-test.sh "Polyglot $s" $ORDER_ID $s
2937

3038
cd $GRABDISH_HOME/$s
3139
./undeploy.sh
40+
41+
# Wait for Pod to stop
42+
while test 0 -lt `kubectl get pods -n msdataworkshop | egrep 'inventory-' | wc -l`; do
43+
echo "Waiting for pod to stop..."
44+
sleep 5
45+
done
46+
3247
done
3348

3449
cd $GRABDISH_HOME/inventory-helidon
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
export TNS_ADMIN=$GRABDISH_HOME/wallet
6+
ORDER_DB_SVC="$(state_get ORDER_DB_NAME)_tp"
7+
INVENTORY_DB_SVC="$(state_get INVENTORY_DB_NAME)_tp"
8+
ORDER_USER=ORDERUSER
9+
INVENTORY_USER=INVENTORYUSER
10+
ORDER_LINK=ORDERTOINVENTORYLINK
11+
INVENTORY_LINK=INVENTORYTOORDERLINK
12+
ORDER_QUEUE=ORDERQUEUE
13+
INVENTORY_QUEUE=INVENTORYQUEUE
14+
DB_PASSWORD=`kubectl get secret dbuser -n msdataworkshop --template={{.data.dbpassword}} | base64 --decode`
15+
16+
U=$ORDER_USER
17+
SVC=$ORDER_DB_SVC
18+
TU=$INVENTORY_USER
19+
TSVC=$INVENTORY_DB_SVC
20+
LINK=$ORDER_LINK
21+
Q=$ORDER_QUEUE
22+
sqlplus /nolog <<!
23+
WHENEVER SQLERROR EXIT 1
24+
connect $U/"$DB_PASSWORD"@$SVC
25+
BEGIN
26+
27+
DBMS_AQADM.UNSCHEDULE_PROPAGATION (queue_name => '$U.$Q'
28+
,destination_queue => '$TU.$Q'
29+
,destination => '$LINK');
30+
31+
dbms_aqadm.schedule_propagation
32+
(queue_name => '$U.$Q'
33+
,destination_queue => '$TU.$Q'
34+
,destination => '$LINK'
35+
,start_time => sysdate --immediately
36+
,duration => null --until stopped
37+
,latency => 0); --No gap before propagating
38+
END;
39+
/
40+
!
41+
42+
U=$INVENTORY_USER
43+
SVC=$INVENTORY_DB_SVC
44+
TU=$ORDER_USER
45+
TSVC=$ORDER_DB_SVC
46+
LINK=$INVENTORY_LINK
47+
Q=$INVENTORY_QUEUE
48+
sqlplus /nolog <<!
49+
WHENEVER SQLERROR EXIT 1
50+
connect $U/"$DB_PASSWORD"@$SVC
51+
BEGIN
52+
53+
DBMS_AQADM.UNSCHEDULE_PROPAGATION (queue_name => '$U.$Q'
54+
,destination_queue => '$TU.$Q'
55+
,destination => '$LINK');
56+
57+
dbms_aqadm.schedule_propagation
58+
(queue_name => '$U.$Q'
59+
,destination_queue => '$TU.$Q'
60+
,destination => '$LINK'
61+
,start_time => sysdate --immediately
62+
,duration => null --until stopped
63+
,latency => 0); --No gap before propagating
64+
END;
65+
/
66+
!
67+

0 commit comments

Comments
 (0)