Skip to content

Commit

Permalink
[NU-1740] example scenarios moved outside of the quickstart-setup (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL authored Aug 29, 2024
1 parent 33a2565 commit 6a7a054
Show file tree
Hide file tree
Showing 88 changed files with 787 additions and 642 deletions.
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ services:
condition: service_healthy
designer:
condition: service_healthy
environment:
NU_DESIGNER_ADDRESS: "nginx:8080"
NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS: "nginx:8181"
KAFKA_ADDRESS: "kafka:9092"
SCHEMA_REGISTRY_ADDRESS: "schema-registry:8081"
volumes:
- nussknacker_designer_shared_configuration:/opt/nussknacker/conf/
- ./scenario-examples:/scenario-examples
deploy:
resources:
limits:
Expand Down
19 changes: 7 additions & 12 deletions quickstart-setup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ CMD ["/sbin/my_init"]

WORKDIR /app

COPY run.sh /etc/service/setup/run

COPY setup/ /app/setup/
COPY mocks/ /app/mocks/
COPY data/ /app/data/
COPY utils/ /app/utils/
COPY run-mocks-setup-data.sh /app/run-mocks-setup-data.sh

COPY services/postgres.sh /etc/service/db/run
COPY services/wiremock.sh /etc/service/http-service/run
COPY services/setup.sh /etc/service/setup/run

# WIREMOCK & POSTGRES
COPY --from=wiremock /var/wiremock /var/wiremock
Expand All @@ -33,18 +36,10 @@ RUN apt update && \
apt -y install postgresql-16 && \
apt -y install openjdk-11-jre-headless && \
apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
curl https://raw.githubusercontent.com/birdayz/kaf/master/godownloader.sh | BINDIR=/bin bash && \
# wiremock service
mv /app/mocks/http-service/mocks/ /home/wiremock/ && \
mkdir -p /etc/service/http-service && \
mv /app/mocks/http-service/scripts/run-wiremock.sh /etc/service/http-service/run && \
# postgres service
mv /app/mocks/db/mocks /home/postgres && \
mkdir /etc/service/postgres && \
mv /app/mocks/db/scripts/run-postgres.sh /etc/service/postgres/run
curl https://raw.githubusercontent.com/birdayz/kaf/master/godownloader.sh | BINDIR=/bin bash

EXPOSE 8080
EXPOSE 5432

HEALTHCHECK --interval=10s --timeout=1s --retries=12 --start-period=30s \
CMD (/bin/bash -c 'test -f "/app/healthy"' && pg_isready -d mocks -U mocks && curl -f http://localhost:8080/__admin/) || exit 1
CMD (/app/setup/is-setup-done.sh && /app/mocks/db/is-postgres-ready.sh && /app/mocks/http-service/is-wiremock-ready.sh) || exit 1
5 changes: 4 additions & 1 deletion quickstart-setup/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ https://github.com/wiremock/wiremock-faker-extension/blob/main/docs/reference.md
https://docs.wiremock.io/response-templating/basics/
https://docs.wiremock.io/response-templating/dates-and-times/

# todo: delete
# todo:
- delete
- write about disabling examples (eg. LOAN_REQUEST_DISABLED: true)
- write about required envs: NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS, SCHEMA_REGISTRY_ADDRESS, KAFKA_ADDRESS, NU_DESIGNER_ADDRESS
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

cd "$(dirname "$0")"

function runRequestSending() {
source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
red_echo "ERROR: One parameter required: 1) scenario example folder path\n"
exit 1
fi

function run_request_sending() {
if [ "$#" -ne 2 ]; then
echo "Error: Two parameters required: 1) OpenAPI service slug, 2) request generator script"
red_echo "ERROR: Two parameters required: 1) OpenAPI service slug, 2) request generator script\n"
exit 11
fi

Expand All @@ -13,26 +20,34 @@ function runRequestSending() {
local OPENAPI_SERVICE_SLUG=$1
local REQUEST_GENERATOR_SCRIPT=$2

echo "Starting to send to '$OPENAPI_SERVICE_SLUG' OpenAPI service, requests generated by '$REQUEST_GENERATOR_SCRIPT' generator script"
echo -n "Starting to send to '$OPENAPI_SERVICE_SLUG' OpenAPI service, requests generated by '$REQUEST_GENERATOR_SCRIPT' generator script... "

mkdir -p /var/log/continuously-send-http-requests
nohup ../../utils/http/continuously-send-http-requests.sh "$OPENAPI_SERVICE_SLUG" "$REQUEST_GENERATOR_SCRIPT" > /var/log/continuously-send-http-requests/output.log 2>&1 &

echo "OK"
}

echo "Starting to send generated requests to Nu OpenAPI services ..."
SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send generated requests to Nu OpenAPI services..."

while IFS= read -r OPENAPI_SERVICE_SLUG; do
shopt -s nullglob

if [[ $OPENAPI_SERVICE_SLUG == "#"* ]]; then
for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/generated"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

REQUEST_GENERATOR_SCRIPT=$(find generate-requests -iname "$OPENAPI_SERVICE_SLUG.sh" | head)

if [[ -f "$REQUEST_GENERATOR_SCRIPT" ]]; then
runRequestSending "$OPENAPI_SERVICE_SLUG" "$(realpath $REQUEST_GENERATOR_SCRIPT)"
if [[ ! "$ITEM" == *.sh ]]; then
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script\n"
exit 3
fi

done < "slugs.txt"
OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".sh")

run_request_sending "$OPENAPI_SERVICE_SLUG" "$ITEM"

done

echo -e "DONE!\n\n"
echo -e "Generators are running!\n"
52 changes: 32 additions & 20 deletions quickstart-setup/data/http/send-http-static-requests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

cd "$(dirname "$0")"

function sendRequest() {
source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
red_echo "ERROR: One parameter required: 1) scenario example folder path\n"
exit 1
fi

function send_request() {
if [ "$#" -ne 2 ]; then
echo "Error: Two parameters required: 1) Request-Response OpenAPI service slug, 2) request body"
red_echo "ERROR: Two parameters required: 1) Request-Response OpenAPI service slug, 2) request body\n"
exit 11
fi

Expand All @@ -13,32 +20,37 @@ function sendRequest() {
local OPENAPI_SERVICE_SLUG=$1
local REQUEST_BODY=$2

echo "Sending request '$REQUEST_BODY' to Request-Response '$OPENAPI_SERVICE_SLUG' OpenAPI service ..."
local RESPONSE
RESPONSE=$(../../utils/http/send-request-to-nu-openapi-service.sh "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY")
echo "Response: $RESPONSE"
echo -n "Sending request '$REQUEST_BODY' to Request-Response '$OPENAPI_SERVICE_SLUG' OpenAPI service... "
../../utils/http/send-request-to-nu-openapi-service.sh "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"
echo "OK"
}

echo "Starting to send preconfigured Request-Response OpenAPI service requests ..."
SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send preconfigured Request-Response OpenAPI service requests..."

while IFS= read -r OPENAPI_SERVICE_SLUG; do
shopt -s nullglob

if [[ $OPENAPI_SERVICE_SLUG == "#"* ]]; then
for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/static"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

MESSAGES_FILE=$(find static-requests -iname "$OPENAPI_SERVICE_SLUG.txt" | head)
if [[ ! "$ITEM" == *.txt ]]; then
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages\n"
exit 3
fi

if [[ -f "$MESSAGES_FILE" ]]; then
while IFS= read -r REQUEST_BODY; do
if [[ $REQUEST_BODY == "#"* ]]; then
continue
fi
OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".txt")

sendRequest "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"
done < "$MESSAGES_FILE"
fi
while IFS= read -r REQUEST_BODY; do
if [[ $REQUEST_BODY == "#"* ]]; then
continue
fi

send_request "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"

done < "slugs.txt"
done < "$ITEM"
done

echo -e "DONE!\n\n"
echo -e "Requests sent!\n"
2 changes: 0 additions & 2 deletions quickstart-setup/data/http/slugs.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

cd "$(dirname "$0")"

function runMessageSending() {
source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
red_echo "ERROR: One parameter required: 1) scenario example folder path\n"
exit 1
fi

function run_message_sending() {
if [ "$#" -ne 2 ]; then
echo "Error: Two parameters required: 1) topic name, 2) message generator script"
red_echo "ERROR: Two parameters required: 1) topic name, 2) message generator script\n"
exit 11
fi

Expand All @@ -13,26 +20,34 @@ function runMessageSending() {
local TOPIC_NAME=$1
local MSG_GENERATOR_SCRIPT=$2

echo "Starting to send to '$TOPIC_NAME' messages generated by '$MSG_GENERATOR_SCRIPT' generator script"
echo -n "Starting to send to '$TOPIC_NAME' messages generated by '$MSG_GENERATOR_SCRIPT' generator script... "

mkdir -p /var/log/continuously-send-to-topic
nohup ../../utils/kafka/continuously-send-to-topic.sh "$TOPIC_NAME" "$MSG_GENERATOR_SCRIPT" > /var/log/continuously-send-to-topic/output.log 2>&1 &

echo "OK"
}

echo "Starting to send generated messages ..."
SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send generated messages..."

while IFS= read -r TOPIC_NAME; do
shopt -s nullglob

if [[ $TOPIC_NAME == "#"* ]]; then
for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/generated"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

MSG_GENERATION_SCRIPT=$(find generate-messages -iname "$TOPIC_NAME.sh" | head)

if [[ -f "$MSG_GENERATION_SCRIPT" ]]; then
runMessageSending "$TOPIC_NAME" "$(realpath $MSG_GENERATION_SCRIPT)"
if [[ ! "$ITEM" == *.sh ]]; then
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script\n"
exit 3
fi

done < "topics.txt"
TOPIC_NAME=$(basename "$ITEM" ".sh" | sed 's/.*/\u&/')

run_message_sending "$TOPIC_NAME" "$ITEM"

done

echo -e "DONE!\n\n"
echo -e "Generators are running!\n"
49 changes: 31 additions & 18 deletions quickstart-setup/data/kafka/send-kafka-static-messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

cd "$(dirname "$0")"

function sendMessage() {
source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
red_echo "ERROR: One parameter required: 1) scenario example folder path\n"
exit 1
fi

function send_message() {
if [ "$#" -ne 2 ]; then
echo "Error: Two parameters required: 1) topic name, 2) message"
red_echo "ERROR: Two parameters required: 1) topic name, 2) message\n"
exit 11
fi

Expand All @@ -13,31 +20,37 @@ function sendMessage() {
local TOPIC_NAME=$1
local MSG=$2

echo "Sending message $MSG to '$TOPIC_NAME'"
echo -n "Sending message $MSG to '$TOPIC_NAME'"
../../utils/kafka/send-to-topic.sh "$TOPIC_NAME" "$MSG"
echo "Message sent!"
echo "OK"
}

echo "Starting to send preconfigured messages ..."
SCENARIO_EXAMPLE_DIR_PATH=${1%/}

echo "Starting to send preconfigured messages..."

while IFS= read -r TOPIC_NAME; do
shopt -s nullglob

if [[ $TOPIC_NAME == "#"* ]]; then
for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/static"/*; do
if [ ! -f "$ITEM" ]; then
continue
fi

MESSAGES_FILE=$(find static-messages -iname "$TOPIC_NAME.txt" | head)
if [[ ! "$ITEM" == *.txt ]]; then
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages\n"
exit 3
fi

if [[ -f "$MESSAGES_FILE" ]]; then
while IFS= read -r MSG; do
if [[ $MSG == "#"* ]]; then
continue
fi
TOPIC_NAME=$(basename "$ITEM" ".sh" | sed 's/.*/\u&/')

sendMessage "$TOPIC_NAME" "$MSG"
done < "$MESSAGES_FILE"
fi
while IFS= read -r MSG; do
if [[ $MSG == "#"* ]]; then
continue
fi

send_message "$TOPIC_NAME" "$MSG"

done < "topics.txt"
done < "$ITEM"
done

echo -e "DONE!\n\n"
echo -e "Messages sent!\n"
4 changes: 0 additions & 4 deletions quickstart-setup/data/kafka/topics.txt

This file was deleted.

25 changes: 21 additions & 4 deletions quickstart-setup/data/keep-sending.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@

cd "$(dirname "$0")"

/app/data/http/send-http-static-requests.sh
/app/data//kafka/send-kafka-static-messages.sh
source ../utils/lib.sh

/app/data//http/continuously-send-http-generated-requests.sh
/app/data//kafka/continuously-send-kafka-generated-messages.sh
magenta_echo "-------- DATA GENERATION ACTIVATION STAGE is starting... ------\n"

shopt -s nullglob

for FOLDER in /scenario-examples/*; do
if is_scenario_enabled "$FOLDER"; then
echo -e "Starting to send static and generated data for scenario from ${GREEN}$FOLDER directory...\n\n"

./http/send-http-static-requests.sh "$FOLDER"
./kafka/send-kafka-static-messages.sh "$FOLDER"
./http/continuously-send-http-generated-requests.sh "$FOLDER"
./kafka/continuously-send-kafka-generated-messages.sh "$FOLDER"

echo -e "Static data sent and generators from ${GREEN}$FOLDER directory are runnning!\n\n"
else
echo -e "Skipping sending static and generated data for scenario from ${GREEN}$FOLDER directory.\n"
fi
done

magenta_echo "-------- DATA GENERATION ACTIVATION STAGE is finished! --------\n\n"
Loading

0 comments on commit 6a7a054

Please sign in to comment.