Skip to content

Commit cb8552c

Browse files
authored
PR TxEventQinOracleDB v1.1.2 Patch Update (#495)
* change graalvm uninstall process * update graalvm to 22.2.0 * fix issue with graalvm image name * fix uninstall graalvm script * Avoid stop script if a container or an image is missing. * wip password retype and validation * add precheck before try to create docker network * add msg regards cleanup env variables * add auto exec env.sh in bashrc * address issue 487 - add control to wait for Wallet in Kafka setup (#494)
1 parent f2e8aaa commit cb8552c

File tree

10 files changed

+183
-35
lines changed

10 files changed

+183
-35
lines changed

workshops/txeventq-kafka/cloud-setup/cmd/bash-cleanup

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@
22
# Copyright (c) 2021 Oracle and/or its affiliates.
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44

5+
56
sed '/LiveLab Setup -- BEGIN/,/LiveLab Setup -- END/d' "${HOME}"/.bashrc > "${HOME}"/.bashrc.tmp
7+
68
mv "${HOME}"/.bashrc.tmp "${HOME}"/.bashrc
9+
10+
source "${HOME}"/.bashrc
11+
12+
unset LAB_HOME
13+
14+
echo
15+
echo "Your shell was cleaned up!"
16+
echo "All workshop-related configurations were removed from your .bashrc"
17+
echo "But your environment variables are still present thus it is important to close this Cloud Shell section before any other use."
18+
echo

workshops/txeventq-kafka/cloud-setup/cmd/kafka-undeploy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44

55
# Fail on error
6-
set -e
6+
#set -e
77

88
if ! state_get KAFKA_SETUP; then
99
echo "ERROR: Kafka infrastructure should be setting up!"
1010
exit
1111
fi
1212

1313
# Start Kafka Infrastructure
14-
cd "$LAB_HOME"/cloud-setup/confluent-kafka
14+
cd "$LAB_HOME"/cloud-setup/confluent-kafka || exit 1 ;
1515
./docker-compose down
16-
cd "${HOME}"
16+
cd "${HOME}" || exit 1 ;
1717

1818
# Stop and remove containers
1919
docker container stop txeventq-consumer txeventq-producer kafka-consumer kafka-producer
@@ -26,4 +26,4 @@ docker images -a | grep "cp-kafka-connect-custom" | awk '{print $3}' | xargs do
2626
docker images -a | grep -E "confluentinc|7.0.1" | awk '{print $3}' | xargs docker rmi -f
2727

2828
# Remove Network
29-
docker network rm $(state_get LAB_KAFKA_NETWORK)
29+
docker network rm "$(state_get LAB_KAFKA_NETWORK)"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
9+
# Switch to SSH Key auth for the oci cli (workaround to perm issue awaiting fix)
10+
# source $LAB_HOME/cloud-setup/utils/oci-cli-cs-key-auth.sh
11+
12+
13+
# Remove from .bashrc
14+
sed -i.bak '/txeventqlab/d' ~/.bashrc
15+
16+
17+
# No destroy necessary for Live Labs
18+
if test "$(state_get RUN_TYPE)" == "3"; then
19+
echo "No teardown required for Live Labs"
20+
exit
21+
fi
22+
23+
# Run the graalvm-uninstall.sh in the background
24+
if ps -ef | grep "${LAB_HOME}/cloud-setup/java/graalvm-uninstall.sh" | grep -v grep; then
25+
echo "${LAB_HOME}/cloud-setup/java/graalvm-uninstall.sh is already running"
26+
else
27+
echo "Executing java/graalvm-uninstall.sh in the background"
28+
nohup "${LAB_HOME}"/cloud-setup/java/graalvm-uninstall.sh &>> "${LAB_LOG}"/graalvm-uninstall.log &
29+
fi
30+
31+
# Run the objstore-destroy.sh in the background
32+
if ps -ef | grep "${LAB_HOME}/cloud-setup/utils/objstore-destroy.sh" | grep -v grep; then
33+
echo "${LAB_HOME}/cloud-setup/utils/objstore-destroy.sh is already running"
34+
else
35+
echo "Executing objstore-destroy.sh in the background"
36+
nohup "${LAB_HOME}"/cloud-setup/utils/objstore-destroy.sh &>> "${LAB_LOG}"/objstore-destroy.log &
37+
fi
38+
39+
# Run the objstore-destroy.sh in the background
40+
if ps -ef | grep "${LAB_HOME}/cloud-setup/utils/terraform-destroy.sh" | grep -v grep; then
41+
echo "${LAB_HOME}/cloud-setup/utils/terraform-destroy.sh is already running"
42+
else
43+
echo "Executing terraform-destroy.sh in the background"
44+
nohup "${LAB_HOME}"/cloud-setup/utils/terraform-destroy.sh &>> "${LAB_LOG}"/terraform-destroy.log &
45+
fi
46+

workshops/txeventq-kafka/cloud-setup/confluent-kafka/kafka-setup.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44

55
# Fail on error
6-
set -eu
6+
set -e
77

88
# Install Docker Compose
99
while ! state_done DOCKER_COMPOSE; do
@@ -46,8 +46,13 @@ while ! state_done KAFKA_SETUP; do
4646

4747
echo "$(date): Create Containers Network"
4848
LAB_KAFKA_NETWORK="$(state_get RUN_NAME)_net"
49-
docker network create "${LAB_KAFKA_NETWORK}"
50-
state_set LAB_KAFKA_NETWORK "$LAB_KAFKA_NETWORK"
49+
50+
# Check if the lab's docker network exists and create if not.
51+
check_lab_net="$(docker network ls --filter name=${LAB_KAFKA_NETWORK} -q)"
52+
if [[ ${check_lab_net} == "" ]]; then
53+
docker network create "${LAB_KAFKA_NETWORK}"
54+
state_set LAB_KAFKA_NETWORK "$LAB_KAFKA_NETWORK"
55+
fi
5156

5257
cd "$LAB_HOME"
5358
state_set_done KAFKA_SETUP
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
function db_password_valid() {
9+
local password=$1
10+
(( ${#password} >= 12 )) || echo 'Error: Too short'
11+
(( ${#password} <= 30 )) || echo 'Error: Too long'
12+
[[ $password == *[[:digit:]]* ]] || echo 'Error: Does not contain a digit'
13+
[[ $password == *[[:lower:]]* ]] || echo 'Error: Does not contain a lower case letter'
14+
[[ $password == *[[:upper:]]* ]] || echo 'Error: Does not contain an upper case letter'
15+
[[ $password != *'"'* ]] || echo 'Error: Cannot contain the double quote (") character'
16+
[[ $(echo "$password" | tr '[:lower:]' '[:upper:]') != *'ADMIN'* ]] || echo 'Error: Cannot contain the word "admin".'
17+
}
18+
19+
echo
20+
echo 'Enter the password to be used for the lab database.'
21+
echo 'Database passwords must be 12 to 30 characters and contain at least one uppercase letter,'
22+
echo 'one lowercase letter, and one number. The password cannot contain the double quote (")'
23+
echo 'character or the word "admin".'
24+
echo
25+
26+
# Collect the DB password
27+
while true; do
28+
#read -s -r -p "Enter the password to be used for the lab database: " PW
29+
read -s -r -p "Please enter a password: " PW
30+
echo "***********"
31+
read -s -r -p "Retype a password: " second
32+
echo "***********"
33+
34+
if [ "$PW" != "$second" ]; then
35+
echo "You have entered different passwords. Please, try again.."
36+
echo
37+
continue
38+
fi
39+
40+
msg=$(db_password_valid "$PW");
41+
if [[ $msg != *'Error'* ]] ; then
42+
echo
43+
break
44+
else
45+
echo "$msg"
46+
echo "You have entered invalid passwords. Please, try again.."
47+
echo
48+
fi
49+
done
50+
BASE64_DB_PASSWORD=$(echo -n "$PW" | base64)
51+
52+
echo "my password $PW"
53+

workshops/txeventq-kafka/cloud-setup/env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cd "$LAB_HOME" || exit
2727
echo "LAB_HOME: $LAB_HOME"
2828

2929
# Java Home
30-
GRAALVM_VERSION=${1:-"22.1.0"}
30+
GRAALVM_VERSION=${1:-"22.2.0"}
3131
OS_NAME=$(uname)
3232
if ! [[ $OS_NAME == *"darwin"* ]]; then
3333
# Assume linux

workshops/txeventq-kafka/cloud-setup/java/graalvm-install.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
# Fail on error
66
set -eu
77

8-
GRAALVM_VERSION=${1:-"22.1.0"}
8+
GRAALVM_VERSION=${1:-"22.2.0"}
99
OS_NAME=$(uname)
1010

1111
# Install GraalVM
12-
# https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.1.0/graalvm-ce-java11-linux-amd64-22.1.0.tar.gz
12+
# https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.2.0/graalvm-ce-java11-linux-amd64-22.2.0.tar.gz
1313
if ! test -d ~/graalvm-ce-java11-"${GRAALVM_VERSION}"; then
1414
echo "$(date): Installing graalvm-ce-java11-${GRAALVM_VERSION}"
15-
(cd ~ && curl -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-"${GRAALVM_VERSION}"/graalvm-ce-java11-${OS_NAME}-amd64-${GRAALVM_VERSION}.tar.gz | tar xz)
15+
(cd ~ && curl -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-"${GRAALVM_VERSION}"/graalvm-ce-java11-"${OS_NAME}"-amd64-"${GRAALVM_VERSION}".tar.gz | tar xz)
1616
# mv graalvm-ce-java11-${GRAALVM_VERSION} ~/
1717
fi
1818

@@ -30,4 +30,11 @@ fi
3030
export PATH=$JAVA_HOME/bin/:$PATH
3131
echo "$(date): PATH ${PATH}"
3232

33+
if ! state_done CONTAINER_ENG_SETUP; then
34+
echo "$(date): Installing GraalVM CE Java 11 Image"
35+
docker pull ghcr.io/graalvm/graalvm-ce:ol8-java11 --quiet
36+
state_set CONTAINER_ENG_SETUP "ghcr.io/graalvm/graalvm-ce:ol8-java11"
37+
echo
38+
fi
39+
3340
state_set_done GRAALVM_INSTALLED

workshops/txeventq-kafka/cloud-setup/java/graalvm-uninstall.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@
55
# Fail on error
66
set -e
77

8-
GRAALVM_VERSION=${1:-"22.1.0"}
8+
GRAALVM_VERSION=${1:-"22.2.0"}
99

1010
if ! state_get GRAALVM_INSTALLED; then
1111
exit 1
1212
fi
1313

14-
# Install GraalVM
14+
# Uninstall GraalVM
1515
if test -d ~/graalvm-ce-java11-"${GRAALVM_VERSION}"; then
16+
echo "$(date): Uninstalling graalvm-ce-java11-${GRAALVM_VERSION} local installation."
1617
rm -rf ~/graalvm-ce-java11-"${GRAALVM_VERSION}"
1718
fi
19+
20+
# Uninstall GraalVM Image
21+
if state_done CONTAINER_ENG_SETUP; then
22+
result=$(docker inspect -f '{{.Id}}' "$(state_get CONTAINER_ENG_SETUP)")
23+
if [[ "$result" != "" ]]; then
24+
echo "$(date): Uninstalling $(state_get CONTAINER_ENG_SETUP) Image"
25+
docker rmi -f $(state_get CONTAINER_ENG_SETUP)
26+
state_reset CONTAINER_ENG_SETUP
27+
echo
28+
fi
29+
fi

workshops/txeventq-kafka/cloud-setup/utils/bash-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DIRNAME=$(state_get RUN_NAME)
1111
echo "export LAB_HOME=${HOME}/${DIRNAME}/microservices-datadriven/workshops/txeventq-kafka"
1212
echo "export JAVA_HOME=${JAVA_HOME}"
1313
echo "export PATH=${JAVA_HOME}/bin/:${LAB_HOME}/cloud-setup/utils:${LAB_HOME}/cloud-setup/cmd:${PATH}"
14+
echo "source ${LAB_HOME}/cloud-setup/env.sh"
1415
echo "# LiveLab Setup -- END"
1516
} >> "${HOME}"/.bashrc
1617

workshops/txeventq-kafka/cloud-setup/utils/main-setup.sh

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
# Fail on error
66
set -e
77

8+
function db_password_valid() {
9+
local password=$1
10+
(( ${#password} >= 12 )) || echo 'Error: Too short'
11+
(( ${#password} <= 30 )) || echo 'Error: Too long'
12+
[[ $password == *[[:digit:]]* ]] || echo 'Error: Does not contain a digit'
13+
[[ $password == *[[:lower:]]* ]] || echo 'Error: Does not contain a lower case letter'
14+
[[ $password == *[[:upper:]]* ]] || echo 'Error: Does not contain an upper case letter'
15+
[[ $password != *'"'* ]] || echo 'Error: Cannot contain the double quote (") character'
16+
[[ $(echo "$password" | tr '[:lower:]' '[:upper:]') != *'ADMIN'* ]] || echo 'Error: Cannot contain the word "admin".'
17+
}
18+
19+
820
# Check home is set
921
if test -z "$LAB_HOME"; then
1022
echo "ERROR: This script requires LAB_HOME to be set"
@@ -45,7 +57,7 @@ while ! state_done USER_OCID; do
4557
USER_OCID=$TEST_USER_OCID
4658
fi
4759
# Validate
48-
if test ""$(oci iam user get --user-id "$USER_OCID" --query 'data."lifecycle-state"' --raw-output 2>"${LAB_LOG}"/user_ocid_err) == 'ACTIVE'; then
60+
if test $(oci iam user get --user-id "$USER_OCID" --query 'data."lifecycle-state"' --raw-output 2>"${LAB_LOG}"/user_ocid_err) == 'ACTIVE'; then
4961
state_set USER_OCID "$USER_OCID"
5062
else
5163
echo "That user OCID could not be validated"
@@ -93,7 +105,7 @@ done
93105

94106
# Double check and then set the region
95107
while ! state_done REGION; do
96-
if test $(state_get RUN_TYPE) -eq 1; then
108+
if test "$(state_get RUN_TYPE)" -eq 1; then
97109
HOME_REGION=$(oci iam region-subscription list --query 'data[?"is-home-region"]."region-name" | join('\'' '\'', @)' --raw-output)
98110
state_set HOME_REGION "$HOME_REGION"
99111
fi
@@ -103,7 +115,7 @@ done
103115

104116
# Create the compartment
105117
while ! state_done COMPARTMENT_OCID; do
106-
if test $(state_get RUN_TYPE) -ne 3; then
118+
if test "$(state_get RUN_TYPE)" -ne 3; then
107119
echo "Resources will be created in a new compartment named $(state_get RUN_NAME)"
108120
export OCI_CLI_PROFILE=$(state_get HOME_REGION)
109121
LAB_DESCRIPTION="Simplify Event-driven Apps with TxEventQ in Oracle Database (with Kafka interoperability)"
@@ -176,7 +188,7 @@ while ! state_done NAMESPACE; do
176188
done
177189

178190
# Install GraalVM
179-
GRAALVM_VERSION="22.1.0"
191+
GRAALVM_VERSION="22.2.0"
180192
if ! state_get GRAALVM_INSTALLED; then
181193
if ps -ef | grep "$LAB_HOME/cloud-setup/java/graalvm-install.sh" | grep -v grep; then
182194
echo "$LAB_HOME/cloud-setup/java/graalvm-install.sh is already running"
@@ -186,17 +198,6 @@ if ! state_get GRAALVM_INSTALLED; then
186198
fi
187199
fi
188200

189-
if ! state_done CONTAINER_ENG_SETUP; then
190-
echo "$(date): Installing GraalVM CE Java 11 Image"
191-
docker pull ghcr.io/graalvm/graalvm-ce:ol8-java11 --quiet
192-
# echo "$(date): Create Containers Network"
193-
# LAB_KAFKA_NETWORK="$(state_get RUN_NAME)_net"
194-
# docker network create "${LAB_KAFKA_NETWORK}"
195-
# state_set LAB_KAFKA_NETWORK "$LAB_KAFKA_NETWORK"
196-
state_set_done CONTAINER_ENG_SETUP
197-
echo
198-
fi
199-
200201
# run oracle_db_setup.sh in background
201202
if ! state_get DB_SETUP; then
202203
if ps -ef | grep "$LAB_HOME/cloud-setup/database/oracle_db_setup.sh" | grep -v grep; then
@@ -211,22 +212,33 @@ fi
211212
# Collect DB password
212213
if ! state_done DB_PASSWORD; then
213214
echo
215+
echo 'Enter the password to be used for the lab database.'
214216
echo 'Database passwords must be 12 to 30 characters and contain at least one uppercase letter,'
215217
echo 'one lowercase letter, and one number. The password cannot contain the double quote (")'
216218
echo 'character or the word "admin".'
217219
echo
218220

219221
while true; do
220-
if test -z "$TEST_DB_PASSWORD"; then
221-
read -s -r -p "Enter the password to be used for the lab database: " PW
222-
else
223-
PW="$TEST_DB_PASSWORD"
224-
fi
225-
if [[ ${#PW} -ge 12 && ${#PW} -le 30 && "$PW" =~ [A-Z] && "$PW" =~ [a-z] && "$PW" =~ [0-9] && "$PW" != *admin* && "$PW" != *'"'* ]]; then
222+
#read -s -r -p "Enter the password to be used for the lab database: " PW
223+
read -s -r -p "Please enter a password: " PW
224+
echo "***********"
225+
read -s -r -p "Retype a password: " second
226+
echo "***********"
227+
228+
if [ "$PW" != "$second" ]; then
229+
echo "You have entered different passwords. Please, try again.."
230+
echo
231+
continue
232+
fi
233+
234+
msg=$(db_password_valid "$PW");
235+
if [[ $msg != *'Error'* ]] ; then
226236
echo
227237
break
228238
else
229-
echo "Invalid Password, please retry"
239+
echo "$msg"
240+
echo "You have entered invalid passwords. Please, try again.."
241+
echo
230242
fi
231243
done
232244
BASE64_DB_PASSWORD=$(echo -n "$PW" | base64)

0 commit comments

Comments
 (0)