From 6a7a05432e6b2308a8815d2095fb6701a4dbdfa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ko=C5=82odziejczyk?= Date: Thu, 29 Aug 2024 11:52:52 +0200 Subject: [PATCH] [NU-1740] example scenarios moved outside of the quickstart-setup (#189) --- docker-compose.yml | 6 + quickstart-setup/Dockerfile | 19 +- quickstart-setup/Readme.md | 5 +- ...ntinuously-send-http-generated-requests.sh | 39 ++-- .../data/http/send-http-static-requests.sh | 52 +++-- quickstart-setup/data/http/slugs.txt | 2 - ...tinuously-send-kafka-generated-messages.sh | 39 ++-- .../data/kafka/send-kafka-static-messages.sh | 49 +++-- quickstart-setup/data/kafka/topics.txt | 4 - quickstart-setup/data/keep-sending.sh | 25 ++- quickstart-setup/mocks/configure.sh | 24 +++ quickstart-setup/mocks/db/execute-ddls.sh | 49 +++++ .../mocks/db/is-postgres-ready.sh | 3 + quickstart-setup/mocks/db/postgres-init.sh | 27 +++ .../db/{scripts => }/postgres-operations.sh | 51 +++-- quickstart-setup/mocks/db/run-postgres.sh | 18 ++ .../mocks/db/scripts/configure.sh | 43 ---- .../mocks/db/scripts/run-postgres.sh | 19 -- .../configure-mock-http-services.sh | 57 ++++++ .../mocks/http-service/is-wiremock-ready.sh | 3 + .../mocks/http-service/mocks/__files/.gitkeep | 0 .../http-service/mocks/mappings/. gitkeep | 0 .../{scripts => }/run-wiremock.sh | 2 + quickstart-setup/run-mocks-setup-data.sh | 26 +++ quickstart-setup/run.sh | 17 -- quickstart-setup/services/postgres.sh | 3 + quickstart-setup/services/setup.sh | 3 + quickstart-setup/services/wiremock.sh | 3 + quickstart-setup/setup/is-setup-done.sh | 3 + quickstart-setup/setup/kafka/setup-topics.sh | 41 +++- quickstart-setup/setup/kafka/topics.txt | 11 - .../setup/nu/customize-nu-configuration.sh | 51 +++-- .../setup/nu/example-scenarios.txt | 6 - .../nu/import-and-deploy-example-scenarios.sh | 32 ++- .../nu/scenarios/DetermineOfferedPlan.json | 190 ------------------ quickstart-setup/setup/run-setup.sh | 26 ++- .../setup/schema-registry/active-schemas.txt | 11 - .../schemas/Customers.schema.json | 30 --- .../schemas/SmsesWithOffer.schema.json | 19 -- .../setup/schema-registry/setup-schemas.sh | 66 +++--- .../http/continuously-send-http-requests.sh | 12 +- .../send-request-to-nu-openapi-service.sh | 19 +- .../utils/kafka/continuously-send-to-topic.sh | 12 +- .../utils/kafka/create-topic-idempotently.sh | 17 +- quickstart-setup/utils/kafka/purge-topic.sh | 15 +- quickstart-setup/utils/kafka/send-to-topic.sh | 21 +- quickstart-setup/utils/lib.sh | 44 +++- ...loy-scenario-and-wait-for-running-state.sh | 37 ++-- .../utils/nu/load-scenario-from-json-file.sh | 53 ++--- .../utils/nu/load-scenario-from-json.sh | 4 +- .../utils/nu/reload-configuration.sh | 21 +- .../add-json-schema-idempotently.sh | 40 ++++ .../DetectLargeTransactions.json | 0 .../data/kafka/generated}/transactions.sh | 2 +- .../data/kafka/static}/transactions.txt | 0 .../setup/kafka/topics.txt | 2 + .../ProcessedTransactions.schema.json | 0 .../schema-registry}/Transactions.schema.json | 0 .../loan-request}/LoanRequest.json | 0 .../loan-request/data/http/generated}/loan.sh | 2 +- .../loan-request/data/http/static}/loan.txt | 0 ...rCustomerProposalBasedOnActivityEvent.json | 0 .../data/kafka/generated}/customerEvents.sh | 2 +- .../customer-api}/openapi/CustomerApi.yaml | 0 .../responses}/CustomerProfile.json | 0 .../responses}/CustomerTypeOffers0.json | 0 .../responses}/CustomerTypeOffers1.json | 0 .../responses}/CustomerTypeOffers2.json | 0 .../customer-api/GetCustomerProfile.json | 2 +- .../customer-api/GetOffersForCusomerType.json | 2 +- .../setup/kafka/topics.txt | 2 + .../nu-designer/custom-configuration.conf | 2 +- .../CustomerEvents.schema.json | 0 ...ProposalsBasedOnCustomerEvents.schema.json | 0 .../RTMClientNearPOS.json | 0 .../data/kafka/generated}/geoLocations.sh | 2 +- .../data/kafka/static}/geoLocations.txt | 0 .../mocks/db/rtm_near_pos.sql | 0 .../setup/kafka/topics.txt | 4 + .../nu-designer/custom-configuration.conf | 2 +- .../schema-registry}/GeoLocations.schema.json | 0 .../GeoLocationsOutputEmail.schema.json | 0 .../GeoLocationsOutputPush.schema.json | 0 .../GeoLocationsOutputSms.schema.json | 0 start.bat | 10 +- start.sh | 10 +- stop-and-clean.bat | 8 +- stop-and-clean.sh | 8 +- 88 files changed, 787 insertions(+), 642 deletions(-) delete mode 100644 quickstart-setup/data/http/slugs.txt delete mode 100644 quickstart-setup/data/kafka/topics.txt create mode 100755 quickstart-setup/mocks/configure.sh create mode 100755 quickstart-setup/mocks/db/execute-ddls.sh create mode 100755 quickstart-setup/mocks/db/is-postgres-ready.sh create mode 100755 quickstart-setup/mocks/db/postgres-init.sh rename quickstart-setup/mocks/db/{scripts => }/postgres-operations.sh (77%) create mode 100755 quickstart-setup/mocks/db/run-postgres.sh delete mode 100755 quickstart-setup/mocks/db/scripts/configure.sh delete mode 100755 quickstart-setup/mocks/db/scripts/run-postgres.sh create mode 100755 quickstart-setup/mocks/http-service/configure-mock-http-services.sh create mode 100755 quickstart-setup/mocks/http-service/is-wiremock-ready.sh delete mode 100644 quickstart-setup/mocks/http-service/mocks/__files/.gitkeep delete mode 100644 quickstart-setup/mocks/http-service/mocks/mappings/. gitkeep rename quickstart-setup/mocks/http-service/{scripts => }/run-wiremock.sh (90%) create mode 100755 quickstart-setup/run-mocks-setup-data.sh delete mode 100755 quickstart-setup/run.sh create mode 100755 quickstart-setup/services/postgres.sh create mode 100755 quickstart-setup/services/setup.sh create mode 100755 quickstart-setup/services/wiremock.sh create mode 100755 quickstart-setup/setup/is-setup-done.sh delete mode 100644 quickstart-setup/setup/kafka/topics.txt delete mode 100644 quickstart-setup/setup/nu/example-scenarios.txt delete mode 100644 quickstart-setup/setup/nu/scenarios/DetermineOfferedPlan.json delete mode 100644 quickstart-setup/setup/schema-registry/active-schemas.txt delete mode 100644 quickstart-setup/setup/schema-registry/schemas/Customers.schema.json delete mode 100644 quickstart-setup/setup/schema-registry/schemas/SmsesWithOffer.schema.json create mode 100755 quickstart-setup/utils/schema-registry/add-json-schema-idempotently.sh rename {quickstart-setup/setup/nu/scenarios => scenario-examples/detect-large-transactions}/DetectLargeTransactions.json (100%) rename {quickstart-setup/data/kafka/generate-messages => scenario-examples/detect-large-transactions/data/kafka/generated}/transactions.sh (89%) rename {quickstart-setup/data/kafka/static-messages => scenario-examples/detect-large-transactions/data/kafka/static}/transactions.txt (100%) create mode 100644 scenario-examples/detect-large-transactions/setup/kafka/topics.txt rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/detect-large-transactions/setup/schema-registry}/ProcessedTransactions.schema.json (100%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/detect-large-transactions/setup/schema-registry}/Transactions.schema.json (100%) rename {quickstart-setup/setup/nu/scenarios => scenario-examples/loan-request}/LoanRequest.json (100%) rename {quickstart-setup/data/http/generate-requests => scenario-examples/loan-request/data/http/generated}/loan.sh (93%) rename {quickstart-setup/data/http/static-requests => scenario-examples/loan-request/data/http/static}/loan.txt (100%) rename {quickstart-setup/setup/nu/scenarios => scenario-examples/offer-customer-proposal-based-on-activity-event}/OfferCustomerProposalBasedOnActivityEvent.json (100%) rename {quickstart-setup/data/kafka/generate-messages => scenario-examples/offer-customer-proposal-based-on-activity-event/data/kafka/generated}/customerEvents.sh (90%) rename {quickstart-setup/mocks/http-service/mocks/__files => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api}/openapi/CustomerApi.yaml (100%) rename {quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses}/CustomerProfile.json (100%) rename {quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses}/CustomerTypeOffers0.json (100%) rename {quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses}/CustomerTypeOffers1.json (100%) rename {quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses}/CustomerTypeOffers2.json (100%) rename {quickstart-setup/mocks/http-service/mocks => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api}/mappings/customer-api/GetCustomerProfile.json (78%) rename {quickstart-setup/mocks/http-service/mocks => scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api}/mappings/customer-api/GetOffersForCusomerType.json (90%) create mode 100644 scenario-examples/offer-customer-proposal-based-on-activity-event/setup/kafka/topics.txt rename quickstart-setup/setup/nu/configurations/OfferCustomerProposalBasedOnActivityEvent-related.conf => scenario-examples/offer-customer-proposal-based-on-activity-event/setup/nu-designer/custom-configuration.conf (83%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/offer-customer-proposal-based-on-activity-event/setup/schema-registry}/CustomerEvents.schema.json (100%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/offer-customer-proposal-based-on-activity-event/setup/schema-registry}/OfferProposalsBasedOnCustomerEvents.schema.json (100%) rename {quickstart-setup/setup/nu/scenarios => scenario-examples/rtm-client-near-pos}/RTMClientNearPOS.json (100%) rename {quickstart-setup/data/kafka/generate-messages => scenario-examples/rtm-client-near-pos/data/kafka/generated}/geoLocations.sh (94%) rename {quickstart-setup/data/kafka/static-messages => scenario-examples/rtm-client-near-pos/data/kafka/static}/geoLocations.txt (100%) rename quickstart-setup/mocks/db/mocks/__ddl/rtm_near_pos_example.sql => scenario-examples/rtm-client-near-pos/mocks/db/rtm_near_pos.sql (100%) create mode 100644 scenario-examples/rtm-client-near-pos/setup/kafka/topics.txt rename quickstart-setup/setup/nu/configurations/RTMClientNearPOS-related.conf => scenario-examples/rtm-client-near-pos/setup/nu-designer/custom-configuration.conf (97%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/rtm-client-near-pos/setup/schema-registry}/GeoLocations.schema.json (100%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/rtm-client-near-pos/setup/schema-registry}/GeoLocationsOutputEmail.schema.json (100%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/rtm-client-near-pos/setup/schema-registry}/GeoLocationsOutputPush.schema.json (100%) rename {quickstart-setup/setup/schema-registry/schemas => scenario-examples/rtm-client-near-pos/setup/schema-registry}/GeoLocationsOutputSms.schema.json (100%) diff --git a/docker-compose.yml b/docker-compose.yml index 23ddd4b0..0df07e6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/quickstart-setup/Dockerfile b/quickstart-setup/Dockerfile index 8bed9bc2..53e83403 100644 --- a/quickstart-setup/Dockerfile +++ b/quickstart-setup/Dockerfile @@ -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 @@ -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 diff --git a/quickstart-setup/Readme.md b/quickstart-setup/Readme.md index 4fad9a35..ba9e7623 100644 --- a/quickstart-setup/Readme.md +++ b/quickstart-setup/Readme.md @@ -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 \ No newline at end of file +# 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 \ No newline at end of file diff --git a/quickstart-setup/data/http/continuously-send-http-generated-requests.sh b/quickstart-setup/data/http/continuously-send-http-generated-requests.sh index 1c1f5d27..78a5d433 100755 --- a/quickstart-setup/data/http/continuously-send-http-generated-requests.sh +++ b/quickstart-setup/data/http/continuously-send-http-generated-requests.sh @@ -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 @@ -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" diff --git a/quickstart-setup/data/http/send-http-static-requests.sh b/quickstart-setup/data/http/send-http-static-requests.sh index e4d0fcef..35b7300d 100755 --- a/quickstart-setup/data/http/send-http-static-requests.sh +++ b/quickstart-setup/data/http/send-http-static-requests.sh @@ -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 @@ -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" diff --git a/quickstart-setup/data/http/slugs.txt b/quickstart-setup/data/http/slugs.txt deleted file mode 100644 index 41d9961f..00000000 --- a/quickstart-setup/data/http/slugs.txt +++ /dev/null @@ -1,2 +0,0 @@ -# Request-Response OpenAPI services slugs the static and generated requests should be sent to -loan diff --git a/quickstart-setup/data/kafka/continuously-send-kafka-generated-messages.sh b/quickstart-setup/data/kafka/continuously-send-kafka-generated-messages.sh index 8fc6acd8..6d20e84e 100755 --- a/quickstart-setup/data/kafka/continuously-send-kafka-generated-messages.sh +++ b/quickstart-setup/data/kafka/continuously-send-kafka-generated-messages.sh @@ -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 @@ -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" diff --git a/quickstart-setup/data/kafka/send-kafka-static-messages.sh b/quickstart-setup/data/kafka/send-kafka-static-messages.sh index c5fbc63d..b7644904 100755 --- a/quickstart-setup/data/kafka/send-kafka-static-messages.sh +++ b/quickstart-setup/data/kafka/send-kafka-static-messages.sh @@ -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 @@ -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" diff --git a/quickstart-setup/data/kafka/topics.txt b/quickstart-setup/data/kafka/topics.txt deleted file mode 100644 index 9a993968..00000000 --- a/quickstart-setup/data/kafka/topics.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Topic name the static and generated messages should be sent to -Transactions -CustomerEvents -GeoLocations diff --git a/quickstart-setup/data/keep-sending.sh b/quickstart-setup/data/keep-sending.sh index 8ddd0971..91b83450 100755 --- a/quickstart-setup/data/keep-sending.sh +++ b/quickstart-setup/data/keep-sending.sh @@ -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 \ No newline at end of file +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" \ No newline at end of file diff --git a/quickstart-setup/mocks/configure.sh b/quickstart-setup/mocks/configure.sh new file mode 100755 index 00000000..6b02ec38 --- /dev/null +++ b/quickstart-setup/mocks/configure.sh @@ -0,0 +1,24 @@ +#!/bin/bash -e + +cd "$(dirname "$0")" + +source ../utils/lib.sh + +shopt -s nullglob + +magenta_echo "-------- MOCK CONFIGURATION STAGE is starting... ----\n" + +for FOLDER in /scenario-examples/*; do + if is_scenario_enabled "$SCENARIO_DIR"; then + echo -e "Starting to configure mocks for scenarios from ${GREEN}$FOLDER directory...\n\n" + + ./db/execute-ddls.sh "$FOLDER" + ./http-service/configure-mock-http-services.sh "$FOLDER" + + echo -e "Mocks for scenarios from ${GREEN}$FOLDER directory configured!\n\n" + else + echo "Skipping configuring mocks for scenario from ${GREEN}$FOLDER directory." + fi +done + +magenta_echo "-------- MOCK CONFIGURATION STAGE is finished! ------\n\n" \ No newline at end of file diff --git a/quickstart-setup/mocks/db/execute-ddls.sh b/quickstart-setup/mocks/db/execute-ddls.sh new file mode 100755 index 00000000..9fdf043a --- /dev/null +++ b/quickstart-setup/mocks/db/execute-ddls.sh @@ -0,0 +1,49 @@ +#!/bin/bash -e + +cd "$(dirname "$0")" + +source postgres-operations.sh +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_ddl_script() { + if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) DDL file path\n" + exit 11 + fi + + set -e + + local DDL_FILE_NAME=$1 + + local SCHEMA_NAME + local DDL_CONTENT + + SCHEMA_NAME=$(basename "$(strip_extension "$DDL_FILE_NAME")") + echo -n "Creating schema: $SCHEMA_NAME... " + create_schema "$PG_USER" "$SCHEMA_NAME" > /dev/null + echo "OK" + + DDL_CONTENT=$(wrap_sql_with_current_schema "$SCHEMA_NAME" "$(cat "$DDL_FILE_NAME")") + echo -n "Executing DDL '$DDL_FILE_NAME'... " + echo "$DDL_CONTENT" | execute_sql "" "$PG_USER" "$PG_PASS" > /dev/null + echo "OK" +} + +SCENARIO_EXAMPLE_DIR_PATH=${1%/} + +echo "Starting to import Postgres DDL scripts..." + +shopt -s nullglob + +for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/mocks/db"/*; do + if [ -f "$ITEM" ]; then + execute_ddl_script "$ITEM" + fi +done + +echo -e "Postgres DDL scripts imported!\n" diff --git a/quickstart-setup/mocks/db/is-postgres-ready.sh b/quickstart-setup/mocks/db/is-postgres-ready.sh new file mode 100755 index 00000000..903d4607 --- /dev/null +++ b/quickstart-setup/mocks/db/is-postgres-ready.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +pg_isready -d mocks -U mocks > /dev/null diff --git a/quickstart-setup/mocks/db/postgres-init.sh b/quickstart-setup/mocks/db/postgres-init.sh new file mode 100755 index 00000000..d9a625c2 --- /dev/null +++ b/quickstart-setup/mocks/db/postgres-init.sh @@ -0,0 +1,27 @@ +#!/bin/bash -e + +cd "$(dirname "$0")" + +source postgres-operations.sh +source ../../utils/lib.sh + +init_db() { + init_bg_log_file + init_data_dir + init_custom_conf_dir + configure_pg_config + configure_authentication +} + +configure_users() { + create_user + create_custom_database + grant_privileges + alter_pg_user_pass +} + +init_db +postgres_start_bg +wait_until_started +configure_users +postgres_stop \ No newline at end of file diff --git a/quickstart-setup/mocks/db/scripts/postgres-operations.sh b/quickstart-setup/mocks/db/postgres-operations.sh similarity index 77% rename from quickstart-setup/mocks/db/scripts/postgres-operations.sh rename to quickstart-setup/mocks/db/postgres-operations.sh index 37d79b9a..87b35d32 100755 --- a/quickstart-setup/mocks/db/scripts/postgres-operations.sh +++ b/quickstart-setup/mocks/db/postgres-operations.sh @@ -1,5 +1,18 @@ #!/bin/bash -e +PG_DB_NAME="mocks" +PG_USER="mocks" +PG_PASS="mocks_pass" + +PG_BIN_DIR="/usr/lib/postgresql/16/bin" +PG_BASE_DIR="/home/postgres" +PG_DATA_DIR="$PG_BASE_DIR/data" +PG_CUSTOM_CONF_DIR="$PG_BASE_DIR/conf" +PG_CONF_FILE="$PG_CUSTOM_CONF_DIR/postgresql.conf" +PG_HBA_FILE="$PG_CUSTOM_CONF_DIR/pg_hba.conf" + +source /app/utils/lib.sh + init_data_dir() { if [ ! -e "$PG_DATA_DIR" ]; then mkdir -p "$PG_DATA_DIR" @@ -43,12 +56,12 @@ init_bg_log_file() { } wait_until_started() { - local max_startup_timeout_in_s=10 + local max_startup_timeout_in_s=${1:-10} while ! pg_isready >/dev/null 2>&1; do sleep 1 max_startup_timeout_in_s=$((max_startup_timeout_in_s - 1)) if ((max_startup_timeout_in_s <= 0)); then - echo "Postgres is not started" + red_echo "ERROR: Postgres is not started\n" exit 1 fi done @@ -61,7 +74,7 @@ create_custom_database() { if [ "$DB_EXISTS" != "1" ]; then echo "CREATE DATABASE \"$db_name\"" | execute_sql "" "postgres" "" else - echo "DB already exists - creation skipped" + echo "DB already exists - creation skipped" fi } @@ -104,27 +117,25 @@ alter_pg_user_pass() { } execute_sql() { - local -r db="${1:-}" - local -r user="${2:-postgres}" - local -r pass="${3:-}" - local opts - read -r -a opts <<<"${@:4}" - local args=("-U" "$user" "-p" "${PG_PORT:-5432}" "-h" "127.0.0.1") - [[ -n "$db" ]] && args+=("-d" "$db") - [[ "${#opts[@]}" -gt 0 ]] && args+=("${opts[@]}") - PGPASSWORD=$pass psql "${args[@]}" -} - -start_bg() { + local -r db="${1:-}" + local -r user="${2:-postgres}" + local -r pass="${3:-}" + local opts + read -r -a opts <<<"${@:4}" + local args=("-U" "$user" "-p" "${PG_PORT:-5432}" "-h" "127.0.0.1") + [[ -n "$db" ]] && args+=("-d" "$db") + [[ "${#opts[@]}" -gt 0 ]] && args+=("${opts[@]}") + PGPASSWORD=$pass psql "${args[@]}" +} + +postgres_start_bg() { /sbin/setuser postgres "$PG_BIN_DIR"/pg_ctl start -D "$PG_DATA_DIR" -l /var/log/postgres_bg.log } -start() { +postgres_start() { /sbin/setuser postgres "$PG_BIN_DIR"/postgres -D "$PG_DATA_DIR" "--hba_file=$PG_HBA_FILE" "--config-file=$PG_CONF_FILE" } -stop() { +postgres_stop() { /sbin/setuser postgres "$PG_BIN_DIR"/pg_ctl stop -w -D "$PG_DATA_DIR" -} - -"$@" +} \ No newline at end of file diff --git a/quickstart-setup/mocks/db/run-postgres.sh b/quickstart-setup/mocks/db/run-postgres.sh new file mode 100755 index 00000000..6c23ec76 --- /dev/null +++ b/quickstart-setup/mocks/db/run-postgres.sh @@ -0,0 +1,18 @@ +#!/bin/bash -e + +cd "$(dirname "$0")" + +source postgres-operations.sh + +echo "Starting Postgres service..." + +./postgres-init.sh + +stop() { + echo "Stopping Postgres service..." + postgres_stop +} + +trap stop EXIT + +postgres_start diff --git a/quickstart-setup/mocks/db/scripts/configure.sh b/quickstart-setup/mocks/db/scripts/configure.sh deleted file mode 100755 index 6562c31f..00000000 --- a/quickstart-setup/mocks/db/scripts/configure.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -e - -cd "$(dirname "$0")" - -source postgres-operations.sh -source ../../../utils/lib.sh - -init_db() { - init_bg_log_file - init_data_dir - init_custom_conf_dir - configure_pg_config - configure_authentication -} - -configure_users() { - create_user - create_custom_database - grant_privileges - alter_pg_user_pass -} - -execute_ddls() { - local schema_name - local ddl_content - for file in "$PG_DDL_DIR"/*; do - if [ -f "$file" ]; then - schema_name=$(basename "$(strip_extension "$file")") - echo "Creating schema: $schema_name" - create_schema "$PG_USER" "$schema_name" - ddl_content=$(wrap_sql_with_current_schema "$schema_name" "$(cat "$file")") - echo "Executing ddl: $file with content: $ddl_content" - echo "$ddl_content" | execute_sql "" "$PG_USER" "$PG_PASS" - fi - done -} - -init_db -start_bg -wait_until_started -configure_users -execute_ddls -stop diff --git a/quickstart-setup/mocks/db/scripts/run-postgres.sh b/quickstart-setup/mocks/db/scripts/run-postgres.sh deleted file mode 100755 index 1b21185f..00000000 --- a/quickstart-setup/mocks/db/scripts/run-postgres.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -e -set -x - -export PG_DB_NAME="mocks" -export PG_USER="mocks" -export PG_PASS="mocks_pass" - -export PG_BIN_DIR="/usr/lib/postgresql/16/bin" -export PG_BASE_DIR="/home/postgres" -export PG_DATA_DIR="$PG_BASE_DIR/data" -export PG_DDL_DIR="$PG_BASE_DIR/__ddl" -export PG_CUSTOM_CONF_DIR="$PG_BASE_DIR/conf" -export PG_CONF_FILE="$PG_CUSTOM_CONF_DIR/postgresql.conf" -export PG_HBA_FILE="$PG_CUSTOM_CONF_DIR/pg_hba.conf" - -/app/mocks/db/scripts/configure.sh -exec /app/mocks/db/scripts/postgres-operations.sh start diff --git a/quickstart-setup/mocks/http-service/configure-mock-http-services.sh b/quickstart-setup/mocks/http-service/configure-mock-http-services.sh new file mode 100755 index 00000000..3662d0b4 --- /dev/null +++ b/quickstart-setup/mocks/http-service/configure-mock-http-services.sh @@ -0,0 +1,57 @@ +#!/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 copy_files_and_mappings() { + if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) HTTP mocks folder path\n" + exit 11 + fi + + set -e + + local MOCKS_FOLDER_NAME=$1 + + mkdir -p /home/wiremock/mocks/__files/ + cp -r "$MOCKS_FOLDER_NAME/__files/." /home/wiremock/mocks/__files/ + + mkdir -p /home/wiremock/mocks/mappings/ + cp -r "$MOCKS_FOLDER_NAME/mappings/." /home/wiremock/mocks/mappings/ +} + +function reset_mappings() { + RESPONSE=$(curl -s -L -w "\n%{http_code}" \ + -X POST "http://localhost:8080/__admin/mappings/reset" \ + ) + + HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1) + RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) + + if [[ "$HTTP_STATUS" != 200 ]] ; then + red_echo "ERROR: Cannot reset Wiremock mappings.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" + exit 12 + fi +} + +SCENARIO_EXAMPLE_DIR_PATH=${1%/} + +echo "Starting to configure Wiremock mappings and files..." + +shopt -s nullglob + +for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/mocks/http-service"/*; do + if [ -d "$ITEM" ]; then + copy_files_and_mappings "$ITEM" + fi +done + +reset_mappings + +echo -e "Wirmock configured!\n" diff --git a/quickstart-setup/mocks/http-service/is-wiremock-ready.sh b/quickstart-setup/mocks/http-service/is-wiremock-ready.sh new file mode 100755 index 00000000..22eba925 --- /dev/null +++ b/quickstart-setup/mocks/http-service/is-wiremock-ready.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +curl -f -s http://localhost:8080/__admin/ > /dev/null \ No newline at end of file diff --git a/quickstart-setup/mocks/http-service/mocks/__files/.gitkeep b/quickstart-setup/mocks/http-service/mocks/__files/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/quickstart-setup/mocks/http-service/mocks/mappings/. gitkeep b/quickstart-setup/mocks/http-service/mocks/mappings/. gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/quickstart-setup/mocks/http-service/scripts/run-wiremock.sh b/quickstart-setup/mocks/http-service/run-wiremock.sh similarity index 90% rename from quickstart-setup/mocks/http-service/scripts/run-wiremock.sh rename to quickstart-setup/mocks/http-service/run-wiremock.sh index 10b2ea2b..e74e961c 100755 --- a/quickstart-setup/mocks/http-service/scripts/run-wiremock.sh +++ b/quickstart-setup/mocks/http-service/run-wiremock.sh @@ -1,5 +1,7 @@ #!/bin/sh -e +echo "RUNNING Wiremock service..." + java $JAVA_OPTS -cp /var/wiremock/lib/*:/var/wiremock/extensions/* wiremock.Run \ --port=8080 \ --root-dir=/home/wiremock/mocks \ diff --git a/quickstart-setup/run-mocks-setup-data.sh b/quickstart-setup/run-mocks-setup-data.sh new file mode 100755 index 00000000..9e3d2ea6 --- /dev/null +++ b/quickstart-setup/run-mocks-setup-data.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +cd "$(dirname "$0")" + +source /app/utils/lib.sh + +rm -rf /app/healthy + +if /app/mocks/db/is-postgres-ready.sh && /app/mocks/http-service/is-wiremock-ready.sh; then + green_echo "------ Nu scenarios library is being prepared... ---------\n" + + /app/mocks/configure.sh + /app/setup/run-setup.sh + /app/data/keep-sending.sh + + green_echo "------ Nu scenarios library sucessfully bootstrapped! ----\n\n" + + touch /app/healthy + + # loop forever (you can use manually called utils scripts now) + tail -f /dev/null +else + echo -e "\nWaiting for Postgres and Wiremock to be up and ready...\n" + sleep 5 + exit 1 +fi diff --git a/quickstart-setup/run.sh b/quickstart-setup/run.sh deleted file mode 100755 index 95d13ac3..00000000 --- a/quickstart-setup/run.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -e - -cd "$(dirname "$0")" - -rm -rf /app/healthy - -echo "Starting to setup Nu stack ..." - -/app/setup/run-setup.sh -/app/data/keep-sending.sh - -echo "Setup done!" - -touch /app/healthy - -# loop forever (you can use manually called utils scripts now) -tail -f /dev/null \ No newline at end of file diff --git a/quickstart-setup/services/postgres.sh b/quickstart-setup/services/postgres.sh new file mode 100755 index 00000000..74bce8ca --- /dev/null +++ b/quickstart-setup/services/postgres.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /app/mocks/db/run-postgres.sh \ No newline at end of file diff --git a/quickstart-setup/services/setup.sh b/quickstart-setup/services/setup.sh new file mode 100755 index 00000000..571e0b3f --- /dev/null +++ b/quickstart-setup/services/setup.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /app/run-mocks-setup-data.sh \ No newline at end of file diff --git a/quickstart-setup/services/wiremock.sh b/quickstart-setup/services/wiremock.sh new file mode 100755 index 00000000..d7089ba1 --- /dev/null +++ b/quickstart-setup/services/wiremock.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /app/mocks/http-service/run-wiremock.sh \ No newline at end of file diff --git a/quickstart-setup/setup/is-setup-done.sh b/quickstart-setup/setup/is-setup-done.sh new file mode 100755 index 00000000..b6cb932b --- /dev/null +++ b/quickstart-setup/setup/is-setup-done.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +test -f "/app/healthy" diff --git a/quickstart-setup/setup/kafka/setup-topics.sh b/quickstart-setup/setup/kafka/setup-topics.sh index b51c893e..6924aa41 100755 --- a/quickstart-setup/setup/kafka/setup-topics.sh +++ b/quickstart-setup/setup/kafka/setup-topics.sh @@ -2,29 +2,52 @@ cd "$(dirname "$0")" -function createTopic() { +source ../../utils/lib.sh + +if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) scenario example folder path\n" + exit 1 +fi + +function create_topic() { if [ "$#" -ne 1 ]; then - echo "Error: One parameter required: 1) topic name" + red_echo "ERROR: One parameter required: 1) topic name\n" exit 11 fi set -e local TOPIC_NAME=$1 - echo "Creating topic '$TOPIC_NAME'" + echo -n "Creating topic '$TOPIC_NAME'... " ../../utils/kafka/create-topic-idempotently.sh "$TOPIC_NAME" + echo "OK" } -echo "Starting to create preconfigured topics ..." +SCENARIO_EXAMPLE_DIR_PATH=${1%/} -while IFS= read -r TOPIC_NAME; do +echo "Starting to create preconfigured topics..." - if [[ $TOPIC_NAME == "#"* ]]; then +shopt -s nullglob + +for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/kafka"/*; do + if [ ! -f "$ITEM" ]; then continue fi - createTopic "$TOPIC_NAME" + if [[ ! "$ITEM" == *.txt ]]; then + red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with topic names\n" + exit 2 + fi + + while IFS= read -r TOPIC_NAME; do + + if [[ $TOPIC_NAME == "#"* ]]; then + continue + fi + + create_topic "$TOPIC_NAME" -done < "topics.txt" + done < "$ITEM" +done -echo -e "DONE!\n\n" +echo -e "Topics created!\n" diff --git a/quickstart-setup/setup/kafka/topics.txt b/quickstart-setup/setup/kafka/topics.txt deleted file mode 100644 index e2e5e6da..00000000 --- a/quickstart-setup/setup/kafka/topics.txt +++ /dev/null @@ -1,11 +0,0 @@ -# List of topics that should be created -Customers -ProcessedTransactions -SmsesWithOffer -Transactions -CustomerEvents -OfferProposalsBasedOnCustomerEvents -GeoLocations -GeoLocationsOutputEmail -GeoLocationsOutputSms -GeoLocationsOutputPush diff --git a/quickstart-setup/setup/nu/customize-nu-configuration.sh b/quickstart-setup/setup/nu/customize-nu-configuration.sh index eafccc83..5142798a 100755 --- a/quickstart-setup/setup/nu/customize-nu-configuration.sh +++ b/quickstart-setup/setup/nu/customize-nu-configuration.sh @@ -2,47 +2,60 @@ cd "$(dirname "$0")" -function customizeNuConfiguration() { - if [ "$#" -ne 1 ]; then - echo "Error: One parameter required: 1) configuration file name" +source ../../utils/lib.sh + +if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) scenario example folder path\n" + exit 1 +fi + +SCENARIO_EXAMPLE_DIR_PATH=${1%/} +CONFS_DIR=/opt/nussknacker/conf +APP_CUSTOMIZATION_FILE_PATH="$CONFS_DIR/application-customizations.conf" + +function customize_nu_configuration() { + if [ "$#" -ne 2 ]; then + red_echo "ERROR: Two parameters required: 1) configuration file path 2) example scenario id\n" exit 11 fi set -e - local EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME=$1 + local EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_PATH=$1 + local EXAMPLE_SCENARIO_ID=$2 + local EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME="${EXAMPLE_SCENARIO_ID}-$(basename "$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_PATH")" - echo "Including $EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME configuration" + echo -n "Including $EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_PATH configuration... " - cp -f "$(realpath configurations/"$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME")" "$CONFS_DIR" + cp -f "$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_PATH" "$CONFS_DIR/$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME" local INCLUDE_CONF_LINE="include \"$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME\"" if ! grep -qxF "$INCLUDE_CONF_LINE" "$APP_CUSTOMIZATION_FILE_PATH"; then echo "$INCLUDE_CONF_LINE" >> "$APP_CUSTOMIZATION_FILE_PATH" fi + echo "OK" } -echo "Starting to customize Nu configuration ..." - -CONFS_DIR=/opt/nussknacker/conf -APP_CUSTOMIZATION_FILE_PATH="$CONFS_DIR/application-customizations.conf" +echo "Starting to customize Nu configuration..." touch "$APP_CUSTOMIZATION_FILE_PATH" -while IFS= read -r EXAMPLE_SCENARIO_FILENAME; do +shopt -s nullglob - if [[ $EXAMPLE_SCENARIO_FILENAME == "#"* ]]; then +for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/nu-designer"/*; do + if [ ! -f "$ITEM" ]; then continue fi - EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME="$(basename "$EXAMPLE_SCENARIO_FILENAME" ".json")-related.conf" - - if [ -e "configurations/$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME" ]; then - customizeNuConfiguration "$EXAMPLE_SCENARIO_RELATED_CONFIGURAION_FILE_NAME" + if [[ ! "$ITEM" == *.conf ]]; then + red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.conf' and content with HOCON Nu configuration\n" + exit 2 fi - -done < "example-scenarios.txt" + + SCENARIO_EXAMPLE_ID=$(basename "$SCENARIO_EXAMPLE_DIR_PATH") + customize_nu_configuration "$ITEM" "$SCENARIO_EXAMPLE_ID" +done ../../utils/nu/reload-configuration.sh -echo -e "DONE!\n\n" \ No newline at end of file +echo -e "Configuration customized!\n" \ No newline at end of file diff --git a/quickstart-setup/setup/nu/example-scenarios.txt b/quickstart-setup/setup/nu/example-scenarios.txt deleted file mode 100644 index f7d343c2..00000000 --- a/quickstart-setup/setup/nu/example-scenarios.txt +++ /dev/null @@ -1,6 +0,0 @@ -# Scenarios to put as examples (file with scenario from the scenarios folder per line) -DetectLargeTransactions.json -#DetermineOfferedPlan.json -LoanRequest.json -OfferCustomerProposalBasedOnActivityEvent.json -RTMClientNearPOS.json diff --git a/quickstart-setup/setup/nu/import-and-deploy-example-scenarios.sh b/quickstart-setup/setup/nu/import-and-deploy-example-scenarios.sh index 754f6e91..4f3fd828 100755 --- a/quickstart-setup/setup/nu/import-and-deploy-example-scenarios.sh +++ b/quickstart-setup/setup/nu/import-and-deploy-example-scenarios.sh @@ -2,9 +2,18 @@ cd "$(dirname "$0")" -function importAndDeployScenario() { +source ../../utils/lib.sh + +if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) scenario example folder path\n" + exit 1 +fi + +SCENARIO_EXAMPLE_DIR_PATH=${1%/} + +function import_and_deploy_scenario() { if [ "$#" -ne 2 ]; then - echo "Error: Two parameters required: 1) scenario name, 2) example scenario file path" + red_echo "Error: Two parameters required: 1) scenario name, 2) example scenario file path\n" exit 11 fi @@ -17,18 +26,23 @@ function importAndDeployScenario() { ../../utils/nu/deploy-scenario-and-wait-for-running-state.sh "$EXAMPLE_SCENARIO_NAME" } -echo "Starting to import and deploy example scenarios ..." +echo "Starting to import and deploy example scenarios..." -while IFS= read -r EXAMPLE_SCENARIO_FILENAME; do +shopt -s nullglob - if [[ $EXAMPLE_SCENARIO_FILENAME == "#"* ]]; then +for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH"/*; do + if [ ! -f "$ITEM" ]; then continue fi - EXAMPLE_SCENARIO_NAME=$(basename "$EXAMPLE_SCENARIO_FILENAME" ".json") + if [[ ! "$ITEM" == *.json ]]; then + red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.json' and content with Nu scenario JSON\n" + exit 2 + fi - importAndDeployScenario "$EXAMPLE_SCENARIO_NAME" "$(realpath scenarios/"$EXAMPLE_SCENARIO_FILENAME")" + EXAMPLE_SCENARIO_NAME="$(basename "$ITEM" ".json")" -done < "example-scenarios.txt" + import_and_deploy_scenario "$EXAMPLE_SCENARIO_NAME" "$ITEM" +done -echo -e "DONE!\n\n" +echo -e "Scenarios imported and deployed!\n" diff --git a/quickstart-setup/setup/nu/scenarios/DetermineOfferedPlan.json b/quickstart-setup/setup/nu/scenarios/DetermineOfferedPlan.json deleted file mode 100644 index c73aad21..00000000 --- a/quickstart-setup/setup/nu/scenarios/DetermineOfferedPlan.json +++ /dev/null @@ -1,190 +0,0 @@ -{ - "metaData" : { - "id" : "DetermineOfferedPlan", - "additionalFields": { - "description": null, - "properties": { - "parallelism": "1", - "spillStateToDisk": "true" - }, - "metaDataType": "StreamMetaData" - } - }, - "nodes" : [ - { - "id" : "Customers", - "ref" : { - "typ" : "kafka", - "parameters" : [ - { - "name" : "Topic", - "expression" : { - "language" : "spel", - "expression" : "'Customers'" - } - }, - { - "name" : "Schema version", - "expression" : { - "language" : "spel", - "expression" : "'latest'" - } - } - ] - }, - "additionalFields" : { - "description" : null, - "layoutData" : { - "x" : 181, - "y" : 10 - } - }, - "type" : "Source" - }, - { - "id" : "DecisionTable", - "service" : { - "id" : "decision-table", - "parameters" : [ - { - "name" : "Decision Table", - "expression" : { - "language" : "tabularDataDefinition", - "expression" : "{\n \"rows\": [\n [\n null,\n \"17\",\n null,\n null,\n \"Junior Package\"\n ],\n [\n \"18\",\n \"30\",\n \"Male\",\n \"true\",\n \"Premium Data Plan\"\n ],\n [\n \"18\",\n \"30\",\n \"Male\",\n \"false\",\n \"Standard Data Plan\"\n ],\n [\n \"18\",\n \"30\",\n \"Female\",\n \"true\",\n \"Premium Data Plan\"\n ],\n [\n \"18\",\n \"30\",\n \"Female\",\n \"false\",\n \"Standard Data Plan\"\n ],\n [\n \"31\",\n \"50\",\n \"Male\",\n \"true\",\n \"Family Package\"\n ],\n [\n \"31\",\n \"50\",\n null,\n \"false\",\n \"Standard Data Plan\"\n ],\n [\n \"51\",\n null,\n null,\n null,\n \"Senior Citizen Plan\"\n ]\n ],\n \"columns\": [\n {\n \"name\": \"MinAge\",\n \"type\": \"java.lang.Integer\"\n },\n {\n \"name\": \"MaxAge\",\n \"type\": \"java.lang.Integer\"\n },\n {\n \"name\": \"Gender\",\n \"type\": \"java.lang.String\"\n },\n {\n \"name\": \"IsBigSpender\",\n \"type\": \"java.lang.Boolean\"\n },\n {\n \"name\": \"OfferedPlan\",\n \"type\": \"java.lang.String\"\n }\n ]\n}" - } - }, - { - "name" : "Match condition", - "expression" : { - "language" : "spel", - "expression" : "(#ROW.MinAge != null ? #input.age > #ROW.MinAge : true) && \n(#ROW.MaxAge != null ? #input.age <= #ROW.MaxAge : true) && \n(#ROW.Gender != null ? #input.gender == #ROW.Gender : true) && \n(#ROW.IsBigSpender != null ? #input.isBigSpender == #ROW.IsBigSpender : true)" - } - } - ] - }, - "output" : "offeredPlans", - "additionalFields" : { - "description" : "Plans assigned to customers", - "layoutData" : { - "x" : 180, - "y" : 180 - } - }, - "type" : "Enricher" - }, - { - "id" : "OfferedPlansOutput", - "varName" : "outputVar", - "value" : { - "language" : "spel", - "expression" : "#offeredPlans" - }, - "additionalFields" : { - "description" : "list of cars that need service", - "layoutData" : { - "x" : 180, - "y" : 360 - } - }, - "type" : "Variable" - }, - { - "nextFalse" : [ - { - "id" : "SendPremiumPlanSMS", - "ref" : { - "typ" : "kafka", - "parameters" : [ - { - "name" : "Topic", - "expression" : { - "language" : "spel", - "expression" : "'SmsesWithOffer'" - } - }, - { - "name" : "Schema version", - "expression" : { - "language" : "spel", - "expression" : "'latest'" - } - }, - { - "name" : "Key", - "expression" : { - "language" : "spel", - "expression" : "" - } - }, - { - "name" : "Raw editor", - "expression" : { - "language" : "spel", - "expression" : "false" - } - }, - { - "name" : "assignedOffer", - "expression" : { - "language" : "spel", - "expression" : "#offeredPlans[0].OfferedPlan" - } - }, - { - "name" : "name", - "expression" : { - "language" : "spel", - "expression" : "#input.name" - } - } - ] - }, - "endResult" : null, - "isDisabled" : null, - "additionalFields" : { - "description" : null, - "layoutData" : { - "x" : 446, - "y" : 708 - } - }, - "type" : "Sink" - } - ], - "id" : "IsStandardPlan", - "expression" : { - "language" : "spel", - "expression" : "#offeredPlans[0].OfferedPlan == \"Standard Data Plan\"" - }, - "isDisabled" : null, - "additionalFields" : { - "description" : null, - "layoutData" : { - "x" : 180, - "y" : 540 - } - }, - "type" : "Filter" - }, - { - "id" : "dead-end", - "ref" : { - "typ" : "dead-end", - "parameters" : [ - ] - }, - "endResult" : null, - "isDisabled" : null, - "additionalFields" : { - "description" : null, - "layoutData" : { - "x" : -73, - "y" : 714 - } - }, - "type" : "Sink" - } - ], - "additionalBranches" : [ - ] -} diff --git a/quickstart-setup/setup/run-setup.sh b/quickstart-setup/setup/run-setup.sh index b4f69d9c..6f9d03e0 100755 --- a/quickstart-setup/setup/run-setup.sh +++ b/quickstart-setup/setup/run-setup.sh @@ -2,7 +2,25 @@ cd "$(dirname "$0")" -./schema-registry/setup-schemas.sh -./kafka/setup-topics.sh -./nu/customize-nu-configuration.sh -./nu/import-and-deploy-example-scenarios.sh \ No newline at end of file +source ../utils/lib.sh + +shopt -s nullglob + +magenta_echo "-------- SETUP STAGE is starting... -------\n" + +for FOLDER in /scenario-examples/*; do + if is_scenario_enabled "$FOLDER"; then + echo -e "Starting to configure and run example scenarios from ${GREEN}$FOLDER directory...\n\n" + + ./schema-registry/setup-schemas.sh "$FOLDER" + ./kafka/setup-topics.sh "$FOLDER" + ./nu/customize-nu-configuration.sh "$FOLDER" + ./nu/import-and-deploy-example-scenarios.sh "$FOLDER" + + echo -e "Scenarios from ${GREEN}$FOLDER directory configured and running!\n\n" + else + echo "Skipping configuring and running example scenario from ${GREEN}$FOLDER directory." + fi +done + +magenta_echo "-------- SETUP STAGE is finished! ---------\n\n" diff --git a/quickstart-setup/setup/schema-registry/active-schemas.txt b/quickstart-setup/setup/schema-registry/active-schemas.txt deleted file mode 100644 index 24ecb09e..00000000 --- a/quickstart-setup/setup/schema-registry/active-schemas.txt +++ /dev/null @@ -1,11 +0,0 @@ -# JSON schemas to load (JSON schema file name from the schemas folder per line) -#Customers.schema.json -ProcessedTransactions.schema.json -#SmsesWithOffer.schema.json -Transactions.schema.json -CustomerEvents.schema.json -OfferProposalsBasedOnCustomerEvents.schema.json -GeoLocations.schema.json -GeoLocationsOutputEmail.schema.json -GeoLocationsOutputPush.schema.json -GeoLocationsOutputSms.schema.json diff --git a/quickstart-setup/setup/schema-registry/schemas/Customers.schema.json b/quickstart-setup/setup/schema-registry/schemas/Customers.schema.json deleted file mode 100644 index 109af2e1..00000000 --- a/quickstart-setup/setup/schema-registry/schemas/Customers.schema.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "type": "object", - "title": "Person", - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ - "name" - ], - "properties": { - "gender": { - "description": "The person's gender", - "type": "string", - "enum": [ - "Male", - "Female" - ] - }, - "name": { - "type": "string", - "description": "The person's full name" - }, - "isBigSpender": { - "description": "Indicates if the person is a big spender", - "type": "boolean" - }, - "age": { - "type": "integer", - "description": "The person's age in years" - } - } -} diff --git a/quickstart-setup/setup/schema-registry/schemas/SmsesWithOffer.schema.json b/quickstart-setup/setup/schema-registry/schemas/SmsesWithOffer.schema.json deleted file mode 100644 index 7a928e75..00000000 --- a/quickstart-setup/setup/schema-registry/schemas/SmsesWithOffer.schema.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "object", - "title": "OfferAssignment", - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ - "assignedOffer", - "name" - ], - "properties": { - "assignedOffer": { - "type": "string", - "description": "The assigned offer for the person" - }, - "name": { - "type": "string", - "description": "The person's full name" - } - } -} diff --git a/quickstart-setup/setup/schema-registry/setup-schemas.sh b/quickstart-setup/setup/schema-registry/setup-schemas.sh index 450f8fc8..31e12362 100755 --- a/quickstart-setup/setup/schema-registry/setup-schemas.sh +++ b/quickstart-setup/setup/schema-registry/setup-schemas.sh @@ -2,57 +2,47 @@ cd "$(dirname "$0")" -function createJsonSchema() { +source ../../utils/lib.sh + +if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) scenario example folder path\n" + exit 1 +fi + +function create_json_schema() { if [ "$#" -ne 2 ]; then - echo "Error: Two parameters required: 1) schema name, 2) schema file path" + red_echo "ERROR: Two parameters required: 1) schema name, 2) schema file path\n" exit 11 fi set -e local SCHEMA_NAME=$1 - local SCHEMA_FILE=$2 - - echo "Creating schema '$SCHEMA_NAME' ..." - ESCAPED_JSON_SCHEMA=$(awk 'BEGIN{ORS="\\n"} {gsub(/"/, "\\\"")} 1' < "$SCHEMA_FILE") - - local REQUEST_BODY="{ - \"schema\": \"$ESCAPED_JSON_SCHEMA\", - \"schemaType\": \"JSON\", - \"references\": [] - }" - - local RESPONSE - RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X POST "http://schema-registry:8081/subjects/${SCHEMA_NAME}/versions" \ - -H "Content-Type: application/vnd.schemaregistry.v1+json" -d "$REQUEST_BODY" - ) - - 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 -e "Error: Cannot create schema $SCHEMA_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" - exit 12 - fi - - echo "Schema '$SCHEMA_NAME' created!" + local SCHEMA_FILE_PATH=$2 + + echo -n "Creating schema '$SCHEMA_NAME'... " + ../../utils/schema-registry/add-json-schema-idempotently.sh "$SCHEMA_NAME" "$SCHEMA_FILE_PATH" + echo "OK" } -echo "Starting to add preconfigured schemas ..." +SCENARIO_EXAMPLE_DIR_PATH=${1%/} -while IFS= read -r SCHEMA_FILENAME; do +echo "Starting to add preconfigured schemas..." - if [[ $SCHEMA_FILENAME == "#"* ]]; then +shopt -s nullglob + +for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/schema-registry"/*; do + if [ ! -f "$ITEM" ]; then continue fi - SCHEMA_NAME="$(basename "$SCHEMA_FILENAME" ".schema.json")-value" - createJsonSchema "$SCHEMA_NAME" "$(realpath schemas/"$SCHEMA_FILENAME")" - -done < "active-schemas.txt" + if [[ ! "$ITEM" == *.schema.json ]]; then + red_echo "ERROR: Unrecognized file '$ITEM'. Required file with extension '.schema.json' and content with JSON schema\n" + exit 2 + fi + SCHEMA_NAME="$(basename "$ITEM" ".schema.json")-value" + create_json_schema "$SCHEMA_NAME" "$ITEM" +done -echo -e "DONE!\n\n" +echo -e "Schemas added!\n" diff --git a/quickstart-setup/utils/http/continuously-send-http-requests.sh b/quickstart-setup/utils/http/continuously-send-http-requests.sh index 1a7f4a8a..468e5474 100755 --- a/quickstart-setup/utils/http/continuously-send-http-requests.sh +++ b/quickstart-setup/utils/http/continuously-send-http-requests.sh @@ -1,18 +1,18 @@ #!/bin/bash -e -if [ "$#" -ne 2 ]; then - echo "Two parameters required: 1) OpenAPI service slug, 2) request generator script path" - exit 1 -fi - cd "$(dirname "$0")" source ../lib.sh +if [ "$#" -ne 2 ]; then + red_echo "ERROR: Two parameters required: 1) OpenAPI service slug, 2) request generator script path\n" + exit 1 +fi + OPENAPI_SERVICE_SLUG=$1 REQUEST_GENERATOR_SCRIPT=$2 -verifyBashScript "$REQUEST_GENERATOR_SCRIPT" +verify_bash_script "$REQUEST_GENERATOR_SCRIPT" while true; do sleep 0.1 diff --git a/quickstart-setup/utils/http/send-request-to-nu-openapi-service.sh b/quickstart-setup/utils/http/send-request-to-nu-openapi-service.sh index debbd89c..08a30d83 100755 --- a/quickstart-setup/utils/http/send-request-to-nu-openapi-service.sh +++ b/quickstart-setup/utils/http/send-request-to-nu-openapi-service.sh @@ -1,17 +1,24 @@ #!/bin/bash -e +cd "$(dirname "$0")" + +source ../lib.sh + if [ "$#" -ne 2 ]; then - echo "Two parameters required: 1) Nu OpenAPI service slug, 2) request payload" - exit 1 + red_echo "ERROR: Two parameters required: 1) Nu OpenAPI service slug, 2) request payload\n" + exit 1 fi -cd "$(dirname "$0")" +if ! [ -v NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS ] || [ -z "$NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS" ]; then + red_echo "ERROR: required variable NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS not set or empty\n" + exit 2 +fi OPENAPI_SERVICE_SLUG=$1 REQUEST_BODY=$2 RESPONSE=$(curl -s -L -w "\n%{http_code}" \ - -X POST "http://nginx:8181/scenario/$OPENAPI_SERVICE_SLUG" \ + -X POST "http://$NU_REQUEST_RESPONSE_OPEN_API_SERVICE_ADDRESS/scenario/$OPENAPI_SERVICE_SLUG" \ -H "Content-Type: application/json" -d "$REQUEST_BODY" ) @@ -19,8 +26,8 @@ HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1) RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) if [[ "$HTTP_STATUS" != 200 ]] ; then - echo -e "'$OPENAPI_SERVICE_SLUG' OpenAPI service unexpected response.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" - exit 12 + red_echo "ERROR: '$OPENAPI_SERVICE_SLUG' OpenAPI service unexpected response.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" + exit 3 fi echo "$RESPONSE_BODY" \ No newline at end of file diff --git a/quickstart-setup/utils/kafka/continuously-send-to-topic.sh b/quickstart-setup/utils/kafka/continuously-send-to-topic.sh index c96959ba..b4e5b85a 100755 --- a/quickstart-setup/utils/kafka/continuously-send-to-topic.sh +++ b/quickstart-setup/utils/kafka/continuously-send-to-topic.sh @@ -1,18 +1,18 @@ #!/bin/bash -e -if [ "$#" -ne 2 ]; then - echo "Two parameters required: 1) topic name, 2) generator script path" - exit 1 -fi - cd "$(dirname "$0")" source ../lib.sh +if [ "$#" -ne 2 ]; then + red_echo "ERROR: Two parameters required: 1) topic name, 2) generator script path\n" + exit 1 +fi + TOPIC=$1 GENERATOR_SCRIPT=$2 -verifyBashScript "$GENERATOR_SCRIPT" +verify_bash_script "$GENERATOR_SCRIPT" while true; do sleep 0.1 diff --git a/quickstart-setup/utils/kafka/create-topic-idempotently.sh b/quickstart-setup/utils/kafka/create-topic-idempotently.sh index dda99b6a..ea51cc65 100755 --- a/quickstart-setup/utils/kafka/create-topic-idempotently.sh +++ b/quickstart-setup/utils/kafka/create-topic-idempotently.sh @@ -1,14 +1,21 @@ #!/bin/bash -e +cd "$(dirname "$0")" + +source ../lib.sh + if [ "$#" -ne 1 ]; then - echo "One parameter required: 1) topic name" - exit 1 + red_echo "ERROR: One parameter required: 1) topic name\n" + exit 1 fi -cd "$(dirname "$0")" +if ! [ -v KAFKA_ADDRESS ] || [ -z "$KAFKA_ADDRESS" ]; then + red_echo "ERROR: required variable KAFKA_ADDRESS not set or empty\n" + exit 2 +fi TOPIC_NAME=$1 -if ! kaf --brokers=kafka:9092 topics ls | awk '{print $1}' | grep "^$TOPIC_NAME$" > /dev/null 2>&1; then - kaf --brokers=kafka:9092 topic create "$TOPIC_NAME" > /dev/null +if ! kaf --brokers="$KAFKA_ADDRESS" topics ls | awk '{print $1}' | grep "^$TOPIC_NAME$" > /dev/null 2>&1; then + kaf --brokers="$KAFKA_ADDRESS" topic create "$TOPIC_NAME" > /dev/null fi \ No newline at end of file diff --git a/quickstart-setup/utils/kafka/purge-topic.sh b/quickstart-setup/utils/kafka/purge-topic.sh index 85a5a3a1..a2681fff 100755 --- a/quickstart-setup/utils/kafka/purge-topic.sh +++ b/quickstart-setup/utils/kafka/purge-topic.sh @@ -1,13 +1,20 @@ #!/bin/bash -e +cd "$(dirname "$0")" + +source ../lib.sh + if [ "$#" -ne 1 ]; then - echo "One parameter required: 1) topic name" - exit 1 + red_echo "ERROR: One parameter required: 1) topic name\n" + exit 1 fi -cd "$(dirname "$0")" +if ! [ -v KAFKA_ADDRESS ] || [ -z "$KAFKA_ADDRESS" ]; then + red_echo "ERROR: required variable KAFKA_ADDRESS not set or empty\n" + exit 2 +fi TOPIC_NAME=$1 -kaf --brokers=kafka:9092 topic delete "$TOPIC_NAME" > /dev/null +kaf --brokers="$KAFKA_ADDRESS" topic delete "$TOPIC_NAME" > /dev/null ./create-topic-idempotently.sh diff --git a/quickstart-setup/utils/kafka/send-to-topic.sh b/quickstart-setup/utils/kafka/send-to-topic.sh index 9a48f702..65e8ecae 100755 --- a/quickstart-setup/utils/kafka/send-to-topic.sh +++ b/quickstart-setup/utils/kafka/send-to-topic.sh @@ -1,18 +1,25 @@ #!/bin/bash -e +cd "$(dirname "$0")" + +source ../lib.sh + if [ "$#" -ne 2 ]; then - echo "Two parameters required: 1) topic name, 2) message" - exit 1 + red_echo "ERROR: Two parameters required: 1) topic name, 2) message\n" + exit 1 fi -cd "$(dirname "$0")" +if ! [ -v KAFKA_ADDRESS ] || [ -z "$KAFKA_ADDRESS" ]; then + red_echo "ERROR: required variable KAFKA_ADDRESS not set or empty\n" + exit 2 +fi TOPIC_NAME=$1 MESSAGE=$2 -if kaf --brokers=kafka:9092 topics ls | awk '{print $1}' | grep "^$TOPIC_NAME$" > /dev/null 2>&1; then - echo "$MESSAGE" | kaf --brokers=kafka:9092 produce "$TOPIC_NAME" > /dev/null +if kaf --brokers="$KAFKA_ADDRESS" topics ls | awk '{print $1}' | grep "^$TOPIC_NAME$" > /dev/null 2>&1; then + echo "$MESSAGE" | kaf --brokers="$KAFKA_ADDRESS" produce "$TOPIC_NAME" > /dev/null else - echo "TOPIC_NAME $TOPIC_NAME not found" - exit 2 + red_echo "ERROR: Topic name '$TOPIC_NAME' not found\n" + exit 3 fi \ No newline at end of file diff --git a/quickstart-setup/utils/lib.sh b/quickstart-setup/utils/lib.sh index 785e6782..af6cd3d7 100755 --- a/quickstart-setup/utils/lib.sh +++ b/quickstart-setup/utils/lib.sh @@ -1,25 +1,42 @@ #!/bin/bash -e -function verifyBashScript() { +RED='\033[31m' +GREEN='\033[32m' +MAGENTA='\033[35m' +RESET='\033[0m' + +function red_echo() { + echo -e "${RED}$1${RESET}" +} + +function green_echo() { + echo -e "${GREEN}$1${RESET}" +} + +function magenta_echo() { + echo -e "${MAGENTA}$1${RESET}" +} + +function verify_bash_script() { local FILE=$1 if [[ -f "$FILE" ]]; then if [[ $(head -n 1 "$FILE") =~ ^#!/bin/bash ]]; then return 0 else - echo "$FILE exists but is not a Bash script." + echo "File '$FILE' exists but is not a Bash script." return 1 fi else - echo "$FILE does not exist." + echo "File '$FILE' does not exist." return 2 fi } function random_Ndigit_number() { if [ "$#" -ne 1 ]; then - echo "Error: One parameter required: 1) number of digits" - exit 1 + red_echo "ERROR: One parameter required: 1) number of digits\n" + return 1 fi local LENGTH=$1 @@ -62,4 +79,21 @@ function pick_randomly() { function strip_extension() { local file="$1" echo "${file%.*}" +} + +function is_scenario_enabled() { + if [ "$#" -ne 1 ]; then + red_echo "ERROR: One parameter required: 1) scenario folder path\n" + return 1 + fi + + SCENARIO_DIR=$1 + SCENARIO_NAME=$(basename "$SCENARIO_DIR") + + IS_DISABLED=$(echo "${SCENARIO_NAME}_DISABLED" | tr '-' '_' | awk '{print toupper($0)}') + if [[ "${!IS_DISABLED,,}" == "true" ]]; then + return 2 + fi + + return 0 } \ No newline at end of file diff --git a/quickstart-setup/utils/nu/deploy-scenario-and-wait-for-running-state.sh b/quickstart-setup/utils/nu/deploy-scenario-and-wait-for-running-state.sh index 17f3a67c..02713c1f 100755 --- a/quickstart-setup/utils/nu/deploy-scenario-and-wait-for-running-state.sh +++ b/quickstart-setup/utils/nu/deploy-scenario-and-wait-for-running-state.sh @@ -2,18 +2,25 @@ cd "$(dirname "$0")" +source ../lib.sh + if [ "$#" -lt 1 ]; then - echo "Error: One parameter required: 1) scenario name" + red_echo "ERROR: One parameter required: 1) scenario name\n" exit 1 fi +if ! [ -v NU_DESIGNER_ADDRESS ] || [ -z "$NU_DESIGNER_ADDRESS" ]; then + red_echo "ERROR: required variable NU_DESIGNER_ADDRESS not set or empty\n" + exit 2 +fi + SCENARIO_NAME=$1 TIMEOUT_SECONDS=${2:-60} WAIT_INTERVAL=5 -function deployScenario() { +function deploy_scenario() { if [ "$#" -ne 1 ]; then - echo "Error: One parameter required: 1) scenario name" + red_echo "ERROR: One parameter required: 1) scenario name\n" exit 11 fi @@ -23,7 +30,7 @@ function deployScenario() { local RESPONSE RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X POST "http://nginx:8080/api/processManagement/deploy/$SCENARIO_NAME" + -X POST "http://${NU_DESIGNER_ADDRESS}/api/processManagement/deploy/$SCENARIO_NAME" ) local HTTP_STATUS @@ -32,16 +39,16 @@ function deployScenario() { if [ "$HTTP_STATUS" != "200" ]; then local RESPONSE_BODY RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) - echo -e "Error: Cannot run scenario $SCENARIO_NAME deployment.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" + red_echo "ERROR: Cannot run scenario $SCENARIO_NAME deployment.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" exit 12 fi - echo "Scenario $SCENARIO_NAME deployment started ..." + echo "Scenario $SCENARIO_NAME deployment started..." } -function checkDeploymentStatus() { +function check_deployment_status() { if [ "$#" -ne 1 ]; then - echo "Error: One parameter required: 1) scenario name" + red_echo "ERROR: One parameter required: 1) scenario name\n" exit 21 fi @@ -51,7 +58,7 @@ function checkDeploymentStatus() { local RESPONSE RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X GET "http://nginx:8080/api/processes/$SCENARIO_NAME/status" + -X GET "http://${NU_DESIGNER_ADDRESS}/api/processes/$SCENARIO_NAME/status" ) local HTTP_STATUS @@ -60,7 +67,7 @@ function checkDeploymentStatus() { RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) if [ "$HTTP_STATUS" != "200" ]; then - echo -e "Error: Cannot check scenario $SCENARIO_NAME deployment status.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" + red_echo "ERROR: Cannot check scenario $SCENARIO_NAME deployment status.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" exit 22 fi @@ -69,15 +76,15 @@ function checkDeploymentStatus() { echo "$SCENARIO_STATUS" } -echo "Deploying scenario $SCENARIO_NAME ..." +echo "Deploying scenario $SCENARIO_NAME..." START_TIME=$(date +%s) END_TIME=$((START_TIME + TIMEOUT_SECONDS)) -deployScenario "$SCENARIO_NAME" +deploy_scenario "$SCENARIO_NAME" while true; do - DEPLOYMENT_STATUS=$(checkDeploymentStatus "$SCENARIO_NAME") + DEPLOYMENT_STATUS=$(check_deployment_status "$SCENARIO_NAME") if [ "$DEPLOYMENT_STATUS" == "RUNNING" ]; then break @@ -85,8 +92,8 @@ while true; do CURRENT_TIME=$(date +%s) if [ $CURRENT_TIME -gt $END_TIME ]; then - echo "Error: Timeout for waiting for the RUNNING state of $SCENARIO_NAME deployment reached!" - exit 2 + red_echo "ERROR: Timeout for waiting for the RUNNING state of $SCENARIO_NAME deployment reached!\n" + exit 3 fi echo "$SCENARIO_NAME deployment state is $DEPLOYMENT_STATUS. Checking again in $WAIT_INTERVAL seconds..." diff --git a/quickstart-setup/utils/nu/load-scenario-from-json-file.sh b/quickstart-setup/utils/nu/load-scenario-from-json-file.sh index e5e0378a..2ba17770 100755 --- a/quickstart-setup/utils/nu/load-scenario-from-json-file.sh +++ b/quickstart-setup/utils/nu/load-scenario-from-json-file.sh @@ -2,24 +2,31 @@ cd "$(dirname "$0")" +source ../lib.sh + if [ "$#" -lt 2 ]; then - echo "Error: Two parameters required: 1) scenario name, 2) scenario file path" + red_echo "ERROR: Two parameters required: 1) scenario name, 2) scenario file path\n" exit 1 fi +if ! [ -v NU_DESIGNER_ADDRESS ] || [ -z "$NU_DESIGNER_ADDRESS" ]; then + red_echo "ERROR: required variable NU_DESIGNER_ADDRESS not set or empty\n" + exit 2 +fi + SCENARIO_NAME=$1 SCENARIO_FILE_PATH=$2 CATEGORY=${3:-"Default"} if [ ! -f "$SCENARIO_FILE_PATH" ]; then - echo "Error: Cannot find file $SCENARIO_FILE_PATH with scenario" - exit 2 + red_echo "ERROR: Cannot find file $SCENARIO_FILE_PATH with scenario\n" + exit 3 fi -function createEmptyScenario() { +function create_empty_scenario() { if [ "$#" -ne 4 ]; then - echo "Error: Four parameters required: 1) scenario name, 2) processing mode, 3) category, 4) engine" - exit 11 + red_echo "ERROR: Four parameters required: 1) scenario name, 2) processing mode, 3) category, 4) engine\n" + exit 11 fi set -e @@ -39,7 +46,7 @@ function createEmptyScenario() { local RESPONSE RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X POST "http://nginx:8080/api/processes" \ + -X POST "http://${NU_DESIGNER_ADDRESS}/api/processes" \ -H "Content-Type: application/json" -d "$REQUEST_BODY" ) @@ -54,22 +61,22 @@ function createEmptyScenario() { echo "Scenario already exists." exit 0 else - echo -e "Error: Cannot create empty scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" + red_echo "ERROR: Cannot create empty scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" exit 12 fi elif [ "$HTTP_STATUS" != "201" ]; then local RESPONSE_BODY RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) - echo -e "Error: Cannot create empty scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" - exit 12 + red_echo "ERROR: Cannot create empty scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" + exit 13 fi echo "Empty scenario $SCENARIO_NAME created successfully." } -function importScenarioFromFile() { +function import_scenario_from_file() { if [ "$#" -ne 2 ]; then - echo "Error: Two parameters required: 1) scenario name, 2) scenario file path" + red_echo "ERROR: Two parameters required: 1) scenario name, 2) scenario file path\n" exit 21 fi @@ -80,7 +87,7 @@ function importScenarioFromFile() { local RESPONSE RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X POST "http://nginx:8080/api/processes/import/$SCENARIO_NAME" \ + -X POST "http://${NU_DESIGNER_ADDRESS}/api/processes/import/$SCENARIO_NAME" \ -F "process=@$SCENARIO_FILE" ) @@ -96,14 +103,14 @@ function importScenarioFromFile() { SCENARIO_GRAPH=$(echo "$RESPONSE_BODY" | jq '.scenarioGraph') echo "$SCENARIO_GRAPH" else - echo -e "Error: Cannot import scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" + red_echo "ERROR: Cannot import scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" exit 22 fi } -function saveScenario() { +function save_scenario() { if [ "$#" -ne 2 ]; then - echo "Error: Two parameters required: 1) scenario name, 2) scenario graph JSON representation" + red_echo "ERROR: Two parameters required: 1) scenario name, 2) scenario graph JSON representation\n" exit 31 fi @@ -119,7 +126,7 @@ function saveScenario() { local RESPONSE RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X PUT "http://nginx:8080/api/processes/$SCENARIO_NAME" \ + -X PUT "http://${NU_DESIGNER_ADDRESS}/api/processes/$SCENARIO_NAME" \ -H "Content-Type: application/json" -d "$REQUEST_BODY" ) @@ -129,7 +136,7 @@ function saveScenario() { if [ "$HTTP_STATUS" != "200" ]; then local RESPONSE_BODY RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) - echo -e "Error: Cannot save scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" + red_echo "ERROR: Cannot save scenario $SCENARIO_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" exit 32 fi @@ -151,11 +158,11 @@ case "$META_DATA_TYPE" in PROCESSING_MODE="Request-Response" ;; *) - echo "Error: Cannot import scenario with metadata type: $META_DATA_TYPE" - exit 2 + red_echo "ERROR: Cannot import scenario with metadata type: $META_DATA_TYPE\n" + exit 4 ;; esac -createEmptyScenario "$SCENARIO_NAME" "$PROCESSING_MODE" "$CATEGORY" "$ENGINE" -SCENARIO_GRAPH=$(importScenarioFromFile "$SCENARIO_NAME" "$SCENARIO_FILE_PATH") -saveScenario "$SCENARIO_NAME" "$SCENARIO_GRAPH" +create_empty_scenario "$SCENARIO_NAME" "$PROCESSING_MODE" "$CATEGORY" "$ENGINE" +SCENARIO_GRAPH=$(import_scenario_from_file "$SCENARIO_NAME" "$SCENARIO_FILE_PATH") +save_scenario "$SCENARIO_NAME" "$SCENARIO_GRAPH" diff --git a/quickstart-setup/utils/nu/load-scenario-from-json.sh b/quickstart-setup/utils/nu/load-scenario-from-json.sh index 8e80c5e7..de1f51ee 100755 --- a/quickstart-setup/utils/nu/load-scenario-from-json.sh +++ b/quickstart-setup/utils/nu/load-scenario-from-json.sh @@ -2,8 +2,10 @@ cd "$(dirname "$0")" +source ../lib.sh + if [ "$#" -lt 2 ]; then - echo "Error: Two parameters required: 1) scenario name, 2) scenario JSON" + red_echo "ERROR: Two parameters required: 1) scenario name, 2) scenario JSON\n" exit 1 fi diff --git a/quickstart-setup/utils/nu/reload-configuration.sh b/quickstart-setup/utils/nu/reload-configuration.sh index bfc58880..de796767 100755 --- a/quickstart-setup/utils/nu/reload-configuration.sh +++ b/quickstart-setup/utils/nu/reload-configuration.sh @@ -2,12 +2,19 @@ cd "$(dirname "$0")" -function reloadConfiguration() { +source ../lib.sh + +if ! [ -v NU_DESIGNER_ADDRESS ] || [ -z "$NU_DESIGNER_ADDRESS" ]; then + red_echo "ERROR: required variable NU_DESIGNER_ADDRESS not set or empty\n" + exit 1 +fi + +function reload_configuration() { set -e local RESPONSE RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ - -X POST "http://nginx:8080/api/app/processingtype/reload" + -X POST "http://${NU_DESIGNER_ADDRESS}/api/app/processingtype/reload" ) local HTTP_STATUS @@ -16,13 +23,11 @@ function reloadConfiguration() { RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) if [ "$HTTP_STATUS" != "204" ]; then - echo -e "Error: Cannot reload Nu configuration.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY" + red_echo "ERROR: Cannot reload Nu configuration.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" exit 22 fi } -echo "Reloading Nu configuration ..." - -reloadConfiguration - -echo "Nu configuration reloaded!" +echo -n "Reloading Nu configuration... " +reload_configuration +echo "OK" diff --git a/quickstart-setup/utils/schema-registry/add-json-schema-idempotently.sh b/quickstart-setup/utils/schema-registry/add-json-schema-idempotently.sh new file mode 100755 index 00000000..dd5cdc9a --- /dev/null +++ b/quickstart-setup/utils/schema-registry/add-json-schema-idempotently.sh @@ -0,0 +1,40 @@ +#!/bin/bash -e + +cd "$(dirname "$0")" + +source ../lib.sh + +if [ "$#" -ne 2 ]; then + red_echo "ERROR: Two parameters required: 1) schema name, 2) schema file path\n" + exit 1 +fi + +if ! [ -v SCHEMA_REGISTRY_ADDRESS ] || [ -z "$SCHEMA_REGISTRY_ADDRESS" ]; then + red_echo "ERROR: required variable SCHEMA_REGISTRY_ADDRESS not set or empty\n" + exit 2 +fi + +SCHEMA_NAME=$1 +SCHEMA_FILE=$2 + +ESCAPED_JSON_SCHEMA=$(awk 'BEGIN{ORS="\\n"} {gsub(/"/, "\\\"")} 1' < "$SCHEMA_FILE") + +REQUEST_BODY="{ + \"schema\": \"$ESCAPED_JSON_SCHEMA\", + \"schemaType\": \"JSON\", + \"references\": [] +}" + +RESPONSE=$(curl -s -L -w "\n%{http_code}" -u admin:admin \ + -X POST "http://${SCHEMA_REGISTRY_ADDRESS}/subjects/${SCHEMA_NAME}/versions" \ + -H "Content-Type: application/vnd.schemaregistry.v1+json" -d "$REQUEST_BODY" +) + +HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1) + +if [[ "$HTTP_STATUS" != 200 ]] ; then + RESPONSE_BODY + RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d) + red_echo "ERROR: Cannot create schema $SCHEMA_NAME.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n" + exit 3 +fi \ No newline at end of file diff --git a/quickstart-setup/setup/nu/scenarios/DetectLargeTransactions.json b/scenario-examples/detect-large-transactions/DetectLargeTransactions.json similarity index 100% rename from quickstart-setup/setup/nu/scenarios/DetectLargeTransactions.json rename to scenario-examples/detect-large-transactions/DetectLargeTransactions.json diff --git a/quickstart-setup/data/kafka/generate-messages/transactions.sh b/scenario-examples/detect-large-transactions/data/kafka/generated/transactions.sh similarity index 89% rename from quickstart-setup/data/kafka/generate-messages/transactions.sh rename to scenario-examples/detect-large-transactions/data/kafka/generated/transactions.sh index eb921793..f8004ec9 100755 --- a/quickstart-setup/data/kafka/generate-messages/transactions.sh +++ b/scenario-examples/detect-large-transactions/data/kafka/generated/transactions.sh @@ -2,7 +2,7 @@ cd "$(dirname "$0")" -source ../../../utils/lib.sh +source /app/utils/lib.sh ID=$((1 + $(random_4digit_number) % 5)) AMOUNT=$((1 + $(random_4digit_number) % 30)) diff --git a/quickstart-setup/data/kafka/static-messages/transactions.txt b/scenario-examples/detect-large-transactions/data/kafka/static/transactions.txt similarity index 100% rename from quickstart-setup/data/kafka/static-messages/transactions.txt rename to scenario-examples/detect-large-transactions/data/kafka/static/transactions.txt diff --git a/scenario-examples/detect-large-transactions/setup/kafka/topics.txt b/scenario-examples/detect-large-transactions/setup/kafka/topics.txt new file mode 100644 index 00000000..8efc1cf5 --- /dev/null +++ b/scenario-examples/detect-large-transactions/setup/kafka/topics.txt @@ -0,0 +1,2 @@ +ProcessedTransactions +Transactions diff --git a/quickstart-setup/setup/schema-registry/schemas/ProcessedTransactions.schema.json b/scenario-examples/detect-large-transactions/setup/schema-registry/ProcessedTransactions.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/ProcessedTransactions.schema.json rename to scenario-examples/detect-large-transactions/setup/schema-registry/ProcessedTransactions.schema.json diff --git a/quickstart-setup/setup/schema-registry/schemas/Transactions.schema.json b/scenario-examples/detect-large-transactions/setup/schema-registry/Transactions.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/Transactions.schema.json rename to scenario-examples/detect-large-transactions/setup/schema-registry/Transactions.schema.json diff --git a/quickstart-setup/setup/nu/scenarios/LoanRequest.json b/scenario-examples/loan-request/LoanRequest.json similarity index 100% rename from quickstart-setup/setup/nu/scenarios/LoanRequest.json rename to scenario-examples/loan-request/LoanRequest.json diff --git a/quickstart-setup/data/http/generate-requests/loan.sh b/scenario-examples/loan-request/data/http/generated/loan.sh similarity index 93% rename from quickstart-setup/data/http/generate-requests/loan.sh rename to scenario-examples/loan-request/data/http/generated/loan.sh index 2e6c5e0f..b46b7f78 100755 --- a/quickstart-setup/data/http/generate-requests/loan.sh +++ b/scenario-examples/loan-request/data/http/generated/loan.sh @@ -2,7 +2,7 @@ cd "$(dirname "$0")" -source ../../../utils/lib.sh +source /app/utils/lib.sh ID="$(random_4digit_number)" AMOUNT="$(random_4digit_number)" diff --git a/quickstart-setup/data/http/static-requests/loan.txt b/scenario-examples/loan-request/data/http/static/loan.txt similarity index 100% rename from quickstart-setup/data/http/static-requests/loan.txt rename to scenario-examples/loan-request/data/http/static/loan.txt diff --git a/quickstart-setup/setup/nu/scenarios/OfferCustomerProposalBasedOnActivityEvent.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/OfferCustomerProposalBasedOnActivityEvent.json similarity index 100% rename from quickstart-setup/setup/nu/scenarios/OfferCustomerProposalBasedOnActivityEvent.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/OfferCustomerProposalBasedOnActivityEvent.json diff --git a/quickstart-setup/data/kafka/generate-messages/customerEvents.sh b/scenario-examples/offer-customer-proposal-based-on-activity-event/data/kafka/generated/customerEvents.sh similarity index 90% rename from quickstart-setup/data/kafka/generate-messages/customerEvents.sh rename to scenario-examples/offer-customer-proposal-based-on-activity-event/data/kafka/generated/customerEvents.sh index 6deb43b5..476afdd9 100755 --- a/quickstart-setup/data/kafka/generate-messages/customerEvents.sh +++ b/scenario-examples/offer-customer-proposal-based-on-activity-event/data/kafka/generated/customerEvents.sh @@ -2,7 +2,7 @@ cd "$(dirname "$0")" -source ../../../utils/lib.sh +source /app/utils/lib.sh ID=$(random_Ndigit_number 10) EVENT_TYPE="$(pick_randomly "ClientCloseToShowroom" "ClientBrowseOffers" "ClientEndedCallWithCustomerService" "ClientSentTerminationLetter" "Other")" diff --git a/quickstart-setup/mocks/http-service/mocks/__files/openapi/CustomerApi.yaml b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/openapi/CustomerApi.yaml similarity index 100% rename from quickstart-setup/mocks/http-service/mocks/__files/openapi/CustomerApi.yaml rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/openapi/CustomerApi.yaml diff --git a/quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerProfile.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerProfile.json similarity index 100% rename from quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerProfile.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerProfile.json diff --git a/quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers0.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerTypeOffers0.json similarity index 100% rename from quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers0.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerTypeOffers0.json diff --git a/quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers1.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerTypeOffers1.json similarity index 100% rename from quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers1.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerTypeOffers1.json diff --git a/quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers2.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerTypeOffers2.json similarity index 100% rename from quickstart-setup/mocks/http-service/mocks/__files/responses/customer-api/CustomerTypeOffers2.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/__files/customer-api/responses/CustomerTypeOffers2.json diff --git a/quickstart-setup/mocks/http-service/mocks/mappings/customer-api/GetCustomerProfile.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/mappings/customer-api/GetCustomerProfile.json similarity index 78% rename from quickstart-setup/mocks/http-service/mocks/mappings/customer-api/GetCustomerProfile.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/mappings/customer-api/GetCustomerProfile.json index 5907b234..57153c01 100644 --- a/quickstart-setup/mocks/http-service/mocks/mappings/customer-api/GetCustomerProfile.json +++ b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/mappings/customer-api/GetCustomerProfile.json @@ -8,6 +8,6 @@ "headers": { "Content-Type": "application/json" }, - "bodyFileName": "responses/customer-api/CustomerProfile.json" + "bodyFileName": "customer-api/responses/CustomerProfile.json" } } \ No newline at end of file diff --git a/quickstart-setup/mocks/http-service/mocks/mappings/customer-api/GetOffersForCusomerType.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/mappings/customer-api/GetOffersForCusomerType.json similarity index 90% rename from quickstart-setup/mocks/http-service/mocks/mappings/customer-api/GetOffersForCusomerType.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/mappings/customer-api/GetOffersForCusomerType.json index 3da0c8a4..d19260ae 100644 --- a/quickstart-setup/mocks/http-service/mocks/mappings/customer-api/GetOffersForCusomerType.json +++ b/scenario-examples/offer-customer-proposal-based-on-activity-event/mocks/http-service/customer-api/mappings/customer-api/GetOffersForCusomerType.json @@ -19,7 +19,7 @@ "headers": { "Content-Type": "application/json" }, - "bodyFileName": "responses/customer-api/CustomerTypeOffers{{{pickRandom '0' '1' '2'}}}.json" + "bodyFileName": "customer-api/responses/CustomerTypeOffers{{{pickRandom '0' '1' '2'}}}.json" } } ] diff --git a/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/kafka/topics.txt b/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/kafka/topics.txt new file mode 100644 index 00000000..28e852c6 --- /dev/null +++ b/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/kafka/topics.txt @@ -0,0 +1,2 @@ +CustomerEvents +OfferProposalsBasedOnCustomerEvents diff --git a/quickstart-setup/setup/nu/configurations/OfferCustomerProposalBasedOnActivityEvent-related.conf b/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/nu-designer/custom-configuration.conf similarity index 83% rename from quickstart-setup/setup/nu/configurations/OfferCustomerProposalBasedOnActivityEvent-related.conf rename to scenario-examples/offer-customer-proposal-based-on-activity-event/setup/nu-designer/custom-configuration.conf index 40022e13..b26d8dc7 100644 --- a/quickstart-setup/setup/nu/configurations/OfferCustomerProposalBasedOnActivityEvent-related.conf +++ b/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/nu-designer/custom-configuration.conf @@ -8,7 +8,7 @@ scenarioTypes { # OpenAPI enrichers "customerProfileOffers" { providerType: "openAPI" - url: "http://quickstart-setup:8080/__admin/files/openapi/CustomerApi.yaml" + url: "http://quickstart-setup:8080/__admin/files/customer-api/openapi/CustomerApi.yaml" rootUrl: "http://quickstart-setup:8080/" namePattern: "get.*" allowedMethods: ["GET"] diff --git a/quickstart-setup/setup/schema-registry/schemas/CustomerEvents.schema.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/schema-registry/CustomerEvents.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/CustomerEvents.schema.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/setup/schema-registry/CustomerEvents.schema.json diff --git a/quickstart-setup/setup/schema-registry/schemas/OfferProposalsBasedOnCustomerEvents.schema.json b/scenario-examples/offer-customer-proposal-based-on-activity-event/setup/schema-registry/OfferProposalsBasedOnCustomerEvents.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/OfferProposalsBasedOnCustomerEvents.schema.json rename to scenario-examples/offer-customer-proposal-based-on-activity-event/setup/schema-registry/OfferProposalsBasedOnCustomerEvents.schema.json diff --git a/quickstart-setup/setup/nu/scenarios/RTMClientNearPOS.json b/scenario-examples/rtm-client-near-pos/RTMClientNearPOS.json similarity index 100% rename from quickstart-setup/setup/nu/scenarios/RTMClientNearPOS.json rename to scenario-examples/rtm-client-near-pos/RTMClientNearPOS.json diff --git a/quickstart-setup/data/kafka/generate-messages/geoLocations.sh b/scenario-examples/rtm-client-near-pos/data/kafka/generated/geoLocations.sh similarity index 94% rename from quickstart-setup/data/kafka/generate-messages/geoLocations.sh rename to scenario-examples/rtm-client-near-pos/data/kafka/generated/geoLocations.sh index 0f2901cf..3f247ee9 100755 --- a/quickstart-setup/data/kafka/generate-messages/geoLocations.sh +++ b/scenario-examples/rtm-client-near-pos/data/kafka/generated/geoLocations.sh @@ -2,7 +2,7 @@ cd "$(dirname "$0")" -source ../../../utils/lib.sh +source /app/utils/lib.sh case $(($(random_1digit_number) % 3)) in 0) diff --git a/quickstart-setup/data/kafka/static-messages/geoLocations.txt b/scenario-examples/rtm-client-near-pos/data/kafka/static/geoLocations.txt similarity index 100% rename from quickstart-setup/data/kafka/static-messages/geoLocations.txt rename to scenario-examples/rtm-client-near-pos/data/kafka/static/geoLocations.txt diff --git a/quickstart-setup/mocks/db/mocks/__ddl/rtm_near_pos_example.sql b/scenario-examples/rtm-client-near-pos/mocks/db/rtm_near_pos.sql similarity index 100% rename from quickstart-setup/mocks/db/mocks/__ddl/rtm_near_pos_example.sql rename to scenario-examples/rtm-client-near-pos/mocks/db/rtm_near_pos.sql diff --git a/scenario-examples/rtm-client-near-pos/setup/kafka/topics.txt b/scenario-examples/rtm-client-near-pos/setup/kafka/topics.txt new file mode 100644 index 00000000..5d9d2ae1 --- /dev/null +++ b/scenario-examples/rtm-client-near-pos/setup/kafka/topics.txt @@ -0,0 +1,4 @@ +GeoLocations +GeoLocationsOutputEmail +GeoLocationsOutputSms +GeoLocationsOutputPush diff --git a/quickstart-setup/setup/nu/configurations/RTMClientNearPOS-related.conf b/scenario-examples/rtm-client-near-pos/setup/nu-designer/custom-configuration.conf similarity index 97% rename from quickstart-setup/setup/nu/configurations/RTMClientNearPOS-related.conf rename to scenario-examples/rtm-client-near-pos/setup/nu-designer/custom-configuration.conf index 22150857..61b3869e 100644 --- a/quickstart-setup/setup/nu/configurations/RTMClientNearPOS-related.conf +++ b/scenario-examples/rtm-client-near-pos/setup/nu-designer/custom-configuration.conf @@ -37,5 +37,5 @@ rtmNearPosExampleDatabasePool { url: "jdbc:postgresql://quickstart-setup:5432/mocks" username: "mocks" password: "mocks_pass" - schema: "rtm_near_pos_example" + schema: "rtm_near_pos" } diff --git a/quickstart-setup/setup/schema-registry/schemas/GeoLocations.schema.json b/scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocations.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/GeoLocations.schema.json rename to scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocations.schema.json diff --git a/quickstart-setup/setup/schema-registry/schemas/GeoLocationsOutputEmail.schema.json b/scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocationsOutputEmail.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/GeoLocationsOutputEmail.schema.json rename to scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocationsOutputEmail.schema.json diff --git a/quickstart-setup/setup/schema-registry/schemas/GeoLocationsOutputPush.schema.json b/scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocationsOutputPush.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/GeoLocationsOutputPush.schema.json rename to scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocationsOutputPush.schema.json diff --git a/quickstart-setup/setup/schema-registry/schemas/GeoLocationsOutputSms.schema.json b/scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocationsOutputSms.schema.json similarity index 100% rename from quickstart-setup/setup/schema-registry/schemas/GeoLocationsOutputSms.schema.json rename to scenario-examples/rtm-client-near-pos/setup/schema-registry/GeoLocationsOutputSms.schema.json diff --git a/start.bat b/start.bat index c379f924..7660bf03 100644 --- a/start.bat +++ b/start.bat @@ -2,24 +2,24 @@ chcp 65001 >nul setlocal enabledelayedexpansion -echo Running Nussknacker Quickstart ... +echo Running Nussknacker Quickstart... echo. docker --version >nul 2>&1 if errorlevel 1 ( - echo No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/ + echo ERROR: No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/ exit /b 1 ) docker compose version >nul 2>&1 if errorlevel 1 ( - echo No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ + echo ERROR: No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ exit /b 2 ) docker compose config >nul 2>&1 if errorlevel 1 ( - echo Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ + echo ERROR: Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ exit /b 3 ) @@ -27,4 +27,4 @@ docker compose up -d --build --remove-orphans --wait echo. echo Nussknacker and its dependencies are up and running. -echo Open http://localhost:8080 and log in as admin:admin ... +echo Open http://localhost:8080 and log in as admin:admin... diff --git a/start.sh b/start.sh index 719ff503..e0cb5293 100755 --- a/start.sh +++ b/start.sh @@ -15,21 +15,21 @@ echo -e " " -echo "Running Nussknacker Quickstart ..." +echo "Running Nussknacker Quickstart..." echo "" if ! docker version &>/dev/null; then - echo "No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/" + echo "ERROR: No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/" exit 1 fi if ! docker compose version &>/dev/null; then - echo "No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" + echo "ERROR: No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" exit 2 fi if ! docker compose config > /dev/null; then - echo "Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" + echo "ERROR: Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" exit 3 fi @@ -37,4 +37,4 @@ docker compose up -d --build --remove-orphans --wait echo "" echo "Nussknacker and its dependencies are up and running." -echo "Open http://localhost:8080 and log in as admin:admin ..." +echo "Open http://localhost:8080 and log in as admin:admin..." diff --git a/stop-and-clean.bat b/stop-and-clean.bat index 9fb2e1f0..a89fffd1 100644 --- a/stop-and-clean.bat +++ b/stop-and-clean.bat @@ -3,24 +3,24 @@ setlocal enabledelayedexpansion cd /d "%~dp0" -echo Running Nussknacker Quickstart clean up ... +echo Running Nussknacker Quickstart clean up... echo. docker --version >nul 2>&1 if errorlevel 1 ( - echo No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/ + echo ERROR: No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/ exit /b 1 ) docker compose version >nul 2>&1 if errorlevel 1 ( - echo No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ + echo ERROR: No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ exit /b 2 ) docker compose config >nul 2>&1 if errorlevel 1 ( - echo Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ + echo ERROR: Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/ exit /b 3 ) diff --git a/stop-and-clean.sh b/stop-and-clean.sh index 4d65bb9e..5f4153a7 100755 --- a/stop-and-clean.sh +++ b/stop-and-clean.sh @@ -3,21 +3,21 @@ set -e cd "$(dirname "$0")" -echo "Running Nussknacker Quickstart clean up ..." +echo "Running Nussknacker Quickstart clean up... " echo "" if ! docker version &>/dev/null; then - echo "No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/" + echo "ERROR: No Docker found. Docker is required to run this Quickstart. See https://docs.docker.com/engine/install/" exit 1 fi if ! docker compose version &>/dev/null; then - echo "No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" + echo "ERROR: No docker compose found. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" exit 2 fi if ! docker compose config > /dev/null; then - echo "Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" + echo "ERROR: Cannot validate docker compose configuration. It seems you have to upgrade your Docker installation. See https://docs.docker.com/engine/install/" exit 3 fi