-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: MK Software <[email protected]>
- Loading branch information
1 parent
36a8d2a
commit a3b0134
Showing
9 changed files
with
250 additions
and
15 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
scenario-examples-bootstrapper/data/flink/execute-flink-dml-scripts.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash -e | ||
|
||
cd "$(dirname "$0")" | ||
|
||
source ../../utils/lib.sh | ||
|
||
if [ "$#" -ne 1 ]; then | ||
red_echo "ERROR: One parameter required: 1) scenario example folder path\n" | ||
exit 1 | ||
fi | ||
|
||
function execute_flink_sql_file() { | ||
if [ "$#" -ne 1 ]; then | ||
red_echo "ERROR: One parameter required: 1) Flink SQL file\n" | ||
exit 11 | ||
fi | ||
|
||
set -e | ||
|
||
local FLINK_SQL_FILE_PATH=$1 | ||
|
||
echo "Executing Flink SQL file '$(basename "$FLINK_SQL_FILE_PATH")'... " | ||
../../utils/flink/execute-flink-sql-scripts.sh "$FLINK_SQL_FILE_PATH" | ||
} | ||
|
||
SCENARIO_EXAMPLE_DIR_PATH=${1%/} | ||
|
||
echo "Starting to execute Flink DML scripts..." | ||
|
||
shopt -s nullglob | ||
|
||
for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/flink/static"/*; do | ||
if [ ! -f "$ITEM" ]; then | ||
continue | ||
fi | ||
|
||
if [[ ! "$ITEM" == *.sql ]]; then | ||
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sql' and content with DML statements\n" | ||
exit 3 | ||
fi | ||
|
||
execute_flink_sql_file "$ITEM" | ||
done | ||
|
||
echo -e "Flink DML scripts executed!\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
scenario-examples-bootstrapper/setup/flink/execute-flink-ddl-scripts.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash -e | ||
|
||
cd "$(dirname "$0")" | ||
|
||
source ../../utils/lib.sh | ||
|
||
if [ "$#" -ne 1 ]; then | ||
red_echo "ERROR: One parameter required: 1) scenario example folder path\n" | ||
exit 1 | ||
fi | ||
|
||
function execute_flink_sql_file() { | ||
if [ "$#" -ne 1 ]; then | ||
red_echo "ERROR: One parameter required: 1) Flink SQL file\n" | ||
exit 11 | ||
fi | ||
|
||
set -e | ||
|
||
local FLINK_SQL_FILE_PATH=$1 | ||
|
||
echo "Executing Flink SQL file '$(basename "$FLINK_SQL_FILE_PATH")'... " | ||
../../utils/flink/execute-flink-sql-scripts.sh "$FLINK_SQL_FILE_PATH" | ||
} | ||
|
||
SCENARIO_EXAMPLE_DIR_PATH=${1%/} | ||
|
||
echo "Starting to run Flink DDL scripts..." | ||
|
||
shopt -s nullglob | ||
|
||
for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/flink"/*; do | ||
if [ ! -f "$ITEM" ]; then | ||
continue | ||
fi | ||
|
||
if [[ ! "$ITEM" == *.sql ]]; then | ||
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sql'\n" | ||
exit 2 | ||
fi | ||
|
||
execute_flink_sql_file "$ITEM" | ||
done | ||
|
||
echo -e "Flink DDL scripts executed!\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
scenario-examples-bootstrapper/utils/flink/execute-flink-sql-scripts.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/bin/bash -e | ||
|
||
cd "$(dirname "$0")" | ||
|
||
source ../lib.sh | ||
|
||
if [ "$#" -ne 1 ]; then | ||
red_echo "ERROR: One parameter required: 1) Flink SQL script path\n" | ||
exit 1 | ||
fi | ||
|
||
if ! [ -v FLINK_SQL_GATEWAY_ADDRESS ] || [ -z "$FLINK_SQL_GATEWAY_ADDRESS" ]; then | ||
red_echo "ERROR: required variable FLINK_SQL_GATEWAY_ADDRESS not set or empty\n" | ||
exit 2 | ||
fi | ||
|
||
FLINK_SQL_FILE_PATH=$1 | ||
|
||
if [ ! -f "$FLINK_SQL_FILE_PATH" ]; then | ||
red_echo "ERROR: Cannot find Flink SQL script file $FLINK_SQL_FILE_PATH\n" | ||
exit 3 | ||
fi | ||
|
||
HOST='localhost:8083' | ||
|
||
function apiCall() { | ||
if [ "$#" -lt 2 ]; then | ||
red_echo "Error: Two parameters required: 1) HTTP method, 2) endpoint (should start with /) \n" | ||
exit 11 | ||
fi | ||
|
||
set -e | ||
|
||
local METHOD=$1 | ||
local ENDPOINT=$2 | ||
local REQUEST_BODY=$3 | ||
|
||
local RESPONSE | ||
if [[ -n "$REQUEST_BODY" ]]; then | ||
RESPONSE=$(curl -s -L -w "\n%{http_code}" \ | ||
-X "$METHOD" "http://${FLINK_SQL_GATEWAY_ADDRESS}${ENDPOINT}" \ | ||
-H "Accept: application/json" \ | ||
-H "Content-Type: application/json" \ | ||
-d "$REQUEST_BODY" | ||
) | ||
else | ||
RESPONSE=$(curl -s -L -w "\n%{http_code}" \ | ||
-X "$METHOD" "http://${FLINK_SQL_GATEWAY_ADDRESS}${ENDPOINT}" \ | ||
-H "Accept: application/json" | ||
) | ||
fi | ||
|
||
local HTTP_STATUS | ||
HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1) | ||
|
||
if [ "$HTTP_STATUS" == "200" ]; then | ||
local RESPONSE_BODY | ||
RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) | ||
echo "$RESPONSE_BODY" | ||
else | ||
local RESPONSE_BODY | ||
RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) | ||
red_echo "ERROR: Call $METHOD $ENDPOINT failed. HTTP status: $HTTP_STATUS, Response: $RESPONSE_BODY" | ||
exit 1 | ||
fi | ||
} | ||
|
||
SESSIONHANDLE=$(apiCall "POST" "/sessions" '{"properties": {"execution.runtime-mode": "batch"}}' | jq -r '.sessionHandle' ) | ||
if [[ -z "$SESSIONHANDLE" ]]; then | ||
red_echo "ERROR: Failed to establish session." | ||
exit 1 | ||
fi | ||
echo "Session $SESSIONHANDLE established." | ||
|
||
SQL_CONTENT=$(<"$FLINK_SQL_FILE_PATH") | ||
IFS=';' | ||
|
||
echo "" | ||
for statement in $SQL_CONTENT; do | ||
|
||
if [[ -n "$statement" ]]; then | ||
SQL_STATEMENT_ONE_LINE_WITHOUT_COMMENTS="$(echo $statement | sed 's/--.*//' | tr '\n' ' ' | tr -s ' ');" | ||
|
||
echo -e "Processing SQL statement:\n$SQL_STATEMENT_ONE_LINE_WITHOUT_COMMENTS" | ||
|
||
OPERATIONHANDLE=$(apiCall "POST" "/sessions/$SESSIONHANDLE/statements" "{\"statement\": \"$SQL_STATEMENT_ONE_LINE_WITHOUT_COMMENTS\"}" | jq -r '.operationHandle') | ||
|
||
while true; do | ||
STATUS=$(apiCall "GET" "/sessions/$SESSIONHANDLE/operations/$OPERATIONHANDLE/status" | jq -r '.status') | ||
echo "Status: $STATUS" | ||
|
||
case $STATUS in | ||
"RUNNING") | ||
sleep 2 | ||
;; | ||
"FINISHED") | ||
break | ||
;; | ||
*) | ||
red_echo "ERROR: Unexpected status: $STATUS" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
echo "--------------------------" | ||
fi | ||
done | ||
|
||
unset IFS | ||
|
||
STATUS=$(apiCall "DELETE" "/sessions/$SESSIONHANDLE" | jq -r '.status') | ||
case $STATUS in | ||
"CLOSED") | ||
echo -e "\nSession $SESSIONHANDLE closed." | ||
;; | ||
*) | ||
red_echo "ERROR: Unexpected status: $STATUS" | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
LIBRARY_DOCKER_IMAGE_VERSION=0.3.0 | ||
LIBRARY_DOCKER_IMAGE_VERSION=0.4.0 |