Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-software-pl committed Aug 29, 2024
1 parent 5d159a7 commit 1ce0a4b
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

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

Expand Down Expand Up @@ -40,13 +40,13 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/generated"/*; do
fi

if [[ ! "$ITEM" == *.sh ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script\n"
exit 3
fi

OPENAPI_SERVICE_SLUG=$(basename "$ITEM" ".sh")

runRequestSending "$OPENAPI_SERVICE_SLUG" "$ITEM"
run_request_sending "$OPENAPI_SERVICE_SLUG" "$ITEM"

done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

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

Expand All @@ -37,7 +37,7 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/static"/*; do
fi

if [[ ! "$ITEM" == *.txt ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages\n"
exit 3
fi

Expand All @@ -48,7 +48,7 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/http/static"/*; do
continue
fi

sendRequest "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"
send_request "$OPENAPI_SERVICE_SLUG" "$REQUEST_BODY"

done < "$ITEM"
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

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

Expand Down Expand Up @@ -40,13 +40,13 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/generated"/*; do
fi

if [[ ! "$ITEM" == *.sh ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.sh' and content with bash script\n"
exit 3
fi

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

runMessageSending "$TOPIC_NAME" "$ITEM"
run_message_sending "$TOPIC_NAME" "$ITEM"

done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

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

Expand All @@ -37,7 +37,7 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/static"/*; do
fi

if [[ ! "$ITEM" == *.txt ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with JSON messages\n"
exit 3
fi

Expand All @@ -48,7 +48,7 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/data/kafka/static"/*; do
continue
fi

sendMessage "$TOPIC_NAME" "$MSG"
send_message "$TOPIC_NAME" "$MSG"

done < "$ITEM"
done
Expand Down
12 changes: 6 additions & 6 deletions scenario-examples-bootstrapper/data/keep-sending.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ cd "$(dirname "$0")"

source ../utils/lib.sh

echo -e "${MAGENTA}-------- DATA GENERATION ACTIVATION STAGE is starting... ------${RESET}\n"
magenta_echo "-------- DATA GENERATION ACTIVATION STAGE is starting... ------\n"

shopt -s nullglob

for FOLDER in /scenario-examples/*; do
if isScenarioEnabled "$FOLDER"; then
echo -e "Starting to send static and generated data for scenario from ${GREEN}$FOLDER${RESET} directory...\n\n"
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${RESET} directory are runnning!\n\n"
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${RESET} directory.\n"
echo -e "Skipping sending static and generated data for scenario from ${GREEN}$FOLDER directory.\n"
fi
done

echo -e "${MAGENTA}-------- DATA GENERATION ACTIVATION STAGE is finished! --------${RESET}\n\n"
magenta_echo "-------- DATA GENERATION ACTIVATION STAGE is finished! --------\n\n"
12 changes: 6 additions & 6 deletions scenario-examples-bootstrapper/mocks/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ source ../utils/lib.sh

shopt -s nullglob

echo -e "${MAGENTA}-------- MOCK CONFIGURATION STAGE is starting... ----${RESET}\n"
magenta_echo "-------- MOCK CONFIGURATION STAGE is starting... ----\n"

for FOLDER in /scenario-examples/*; do
if isScenarioEnabled "$SCENARIO_DIR"; then
echo -e "Starting to configure mocks for scenarios from ${GREEN}$FOLDER${RESET} directory...\n\n"
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${RESET} directory configured!\n\n"
echo -e "Mocks for scenarios from ${GREEN}$FOLDER directory configured!\n\n"
else
echo "Skipping configuring mocks for scenario from ${GREEN}$FOLDER${RESET} directory."
echo "Skipping configuring mocks for scenario from ${GREEN}$FOLDER directory."
fi
done

echo -e "${MAGENTA}-------- MOCK CONFIGURATION STAGE is finished! ------${RESET}\n\n"
magenta_echo "-------- MOCK CONFIGURATION STAGE is finished! ------\n\n"
4 changes: 2 additions & 2 deletions scenario-examples-bootstrapper/mocks/db/execute-ddls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ source postgres-operations.sh
source ../../utils/lib.sh

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

function execute_ddl_script() {
if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) DDL file path${RESET}\n"
red_echo "ERROR: One parameter required: 1) DDL file path\n"
exit 11
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ wait_until_started() {
sleep 1
max_startup_timeout_in_s=$((max_startup_timeout_in_s - 1))
if ((max_startup_timeout_in_s <= 0)); then
echo -e "${RED}ERROR: Postgres is not started${RESET}\n"
red_echo "ERROR: Postgres is not started\n"
exit 1
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

function copyFilesAndMappings() {
function copy_files_and_mappings() {
if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) HTTP mocks folder path${RESET}\n"
red_echo "ERROR: One parameter required: 1) HTTP mocks folder path\n"
exit 11
fi

Expand All @@ -26,7 +26,7 @@ function copyFilesAndMappings() {
cp -r "$MOCKS_FOLDER_NAME/mappings/." /home/wiremock/mocks/mappings/
}

function resetMappings() {
function reset_mappings() {
RESPONSE=$(curl -s -L -w "\n%{http_code}" \
-X POST "http://localhost:8080/__admin/mappings/reset" \
)
Expand All @@ -35,7 +35,7 @@ function resetMappings() {
RESPONSE_BODY=$(echo "$RESPONSE" | sed \$d)

if [[ "$HTTP_STATUS" != 200 ]] ; then
echo -e "${RED}ERROR: Cannot reset Wiremock mappings.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY${RESET}\n"
red_echo "ERROR: Cannot reset Wiremock mappings.\nHTTP status: $HTTP_STATUS, response body: $RESPONSE_BODY\n"
exit 12
fi
}
Expand All @@ -48,10 +48,10 @@ shopt -s nullglob

for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/mocks/http-service"/*; do
if [ -d "$ITEM" ]; then
copyFilesAndMappings "$ITEM"
copy_files_and_mappings "$ITEM"
fi
done

resetMappings
reset_mappings

echo -e "Wirmock configured!\n"
4 changes: 2 additions & 2 deletions scenario-examples-bootstrapper/run-mocks-setup-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ 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
echo -e "\n${GREEN}------ Nu scenarios library is being prepared... ---------${RESET}\n\n"
green_echo "------ Nu scenarios library is being prepared... ---------\n"

/app/mocks/configure.sh
/app/setup/run-setup.sh
/app/data/keep-sending.sh

echo -e "\n${GREEN}------ Nu scenarios library sucessfully bootstrapped! ----${RESET}\n\n"
green_echo "------ Nu scenarios library sucessfully bootstrapped! ----\n\n"

touch /app/healthy

Expand Down
10 changes: 5 additions & 5 deletions scenario-examples-bootstrapper/setup/kafka/setup-topics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

function createTopic() {
function create_topic() {
if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) topic name${RESET}\n"
red_echo "ERROR: One parameter required: 1) topic name\n"
exit 11
fi

Expand All @@ -35,7 +35,7 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/kafka"/*; do
fi

if [[ ! "$ITEM" == *.txt ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with topic names${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.txt' and content with topic names\n"
exit 2
fi

Expand All @@ -45,7 +45,7 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/kafka"/*; do
continue
fi

createTopic "$TOPIC_NAME"
create_topic "$TOPIC_NAME"

done < "$ITEM"
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

if [ "$#" -ne 1 ]; then
echo -e "${RED}ERROR: One parameter required: 1) scenario example folder path${RESET}\n"
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 customizeNuConfiguration() {
function customize_nu_configuration() {
if [ "$#" -ne 2 ]; then
echo -e "${RED}ERROR: Two parameters required: 1) configuration file path 2) example scenario id${RESET}\n"
red_echo "ERROR: Two parameters required: 1) configuration file path 2) example scenario id\n"
exit 11
fi

Expand Down Expand Up @@ -48,12 +48,12 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH/setup/nu-designer"/*; do
fi

if [[ ! "$ITEM" == *.conf ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.conf' and content with HOCON Nu configuration${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.conf' and content with HOCON Nu configuration\n"
exit 2
fi

SCENARIO_EXAMPLE_ID=$(basename "$SCENARIO_EXAMPLE_DIR_PATH")
customizeNuConfiguration "$ITEM" "$SCENARIO_EXAMPLE_ID"
customize_nu_configuration "$ITEM" "$SCENARIO_EXAMPLE_ID"
done

../../utils/nu/reload-configuration.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ cd "$(dirname "$0")"
source ../../utils/lib.sh

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

SCENARIO_EXAMPLE_DIR_PATH=${1%/}

function importAndDeployScenario() {
function import_and_deploy_scenario() {
if [ "$#" -ne 2 ]; then
echo -e "${RED}Error: Two parameters required: 1) scenario name, 2) example scenario file path${RESET}\n"
red_echo "Error: Two parameters required: 1) scenario name, 2) example scenario file path\n"
exit 11
fi

Expand All @@ -36,13 +36,13 @@ for ITEM in "$SCENARIO_EXAMPLE_DIR_PATH"/*; do
fi

if [[ ! "$ITEM" == *.json ]]; then
echo -e "${RED}ERROR: Unrecognized file $ITEM. Required file with extension '.json' and content with Nu scenario JSON${RESET}\n"
red_echo "ERROR: Unrecognized file $ITEM. Required file with extension '.json' and content with Nu scenario JSON\n"
exit 2
fi

EXAMPLE_SCENARIO_NAME="$(basename "$ITEM" ".json")"

importAndDeployScenario "$EXAMPLE_SCENARIO_NAME" "$ITEM"
import_and_deploy_scenario "$EXAMPLE_SCENARIO_NAME" "$ITEM"
done

echo -e "Scenarios imported and deployed!\n"
Loading

0 comments on commit 1ce0a4b

Please sign in to comment.