From 5e4606e9eabeb033f26df62fe681f686f828a0cf Mon Sep 17 00:00:00 2001 From: Josh Turner Date: Mon, 19 Aug 2019 11:27:56 -0700 Subject: [PATCH] Added back in helper scripts for examples --- casquatch-examples/.setup.sh | 74 +++++++++++++++++++++++ casquatch-examples/loadtest/env | 3 + casquatch-examples/run.sh | 12 ++++ casquatch-examples/springconfigserver/env | 3 + casquatch-examples/springrest/env | 3 + casquatch-examples/test.sh | 12 ++++ 6 files changed, 107 insertions(+) create mode 100755 casquatch-examples/.setup.sh create mode 100644 casquatch-examples/loadtest/env create mode 100755 casquatch-examples/run.sh create mode 100644 casquatch-examples/springconfigserver/env create mode 100644 casquatch-examples/springrest/env create mode 100755 casquatch-examples/test.sh diff --git a/casquatch-examples/.setup.sh b/casquatch-examples/.setup.sh new file mode 100755 index 0000000..e5c0e56 --- /dev/null +++ b/casquatch-examples/.setup.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +PORT=$(( ( RANDOM % 300 ) + 9000 )) +GENERATOR=../../casquatch-generator/target/casquatch-generator-2.0-SNAPSHOT.jar +DOCKER_VERSION=cassandra:latest +TEST_COMMAND="mvn clean test" +RUN_COMMAND="mvn clean spring-boot:run" + +APP_LIST=(*/env); +APP_LIST_COUNT=${#APP_LIST[@]} + +retryLoop() { + command=$1 + timeout=$2 + lc=0 + retcode=-1 + sleep=10 + until [ $retcode -eq 0 ]; do + if [ $lc -gt $((timeout/sleep)) ]; then + return 1 + fi; + lc=$((lc+1)) + sleep $sleep; + eval $command + retcode=$? + done; + sleep $((sleep*2)) +} + +i=1 +if [ -z $1 ]; then + for app in "${APP_LIST[@]}"; do + echo "$i) "`echo $app | rev | cut -c 5- | rev` + i=$(( i + 1 )) + done; + echo -n "Please select an app to run: "; read appnum; +else + for app in "${APP_LIST[@]}"; do + if [ "$1" == "`echo $app | rev | cut -c 5- | rev`" ]; then + echo "Found Match" + echo `echo $app | rev | cut -c 5- | rev` + appnum=$i; + fi; + i=$(( i + 1 )) + done; +fi; + +source ${APP_LIST[appnum-1]} + +cd $NAME + +echo "---------------------------------------------" +echo "Starting Docker" +echo "---------------------------------------------" +echo "Docker will be started with cassandra on 127.0.0.1:$PORT" +docker kill $NAME +docker run --rm -p $PORT:9042 -d --label casquatch_example=$NAME --name $NAME -d cassandra:latest +retryLoop "echo exit | docker exec -i $NAME cqlsh 2>/dev/null " 300 + +echo "---------------------------------------------" +echo "Installing CQL" +echo "---------------------------------------------" +cat $SCHEMA | docker exec -i $NAME cqlsh + +echo "---------------------------------------------" +echo "Configure project" +echo "---------------------------------------------" +sed -i .old "s/127.0.0.1:[0-9]\{4\}/127.0.0.1:$PORT/" src/main/resources/application.conf +rm src/main/resources/application.conf.old + +echo "---------------------------------------------" +echo "Generate Entity" +echo "---------------------------------------------" +java -Dconfig.file=src/main/resources/application.conf -jar $GENERATOR diff --git a/casquatch-examples/loadtest/env b/casquatch-examples/loadtest/env new file mode 100644 index 0000000..fef7a0f --- /dev/null +++ b/casquatch-examples/loadtest/env @@ -0,0 +1,3 @@ +NAME=loadtest +SCHEMA=schema.cql +RUN_COMMAND="mvn clean test package;java -jar target/loadtest-0.0.1-SNAPSHOT.jar" \ No newline at end of file diff --git a/casquatch-examples/run.sh b/casquatch-examples/run.sh new file mode 100755 index 0000000..9a0a0aa --- /dev/null +++ b/casquatch-examples/run.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -d "casquatch-examples" ]; then + cd casquatch-examples +fi; + +source ./.setup.sh + +echo "---------------------------------------------" +echo "Run App" +echo "---------------------------------------------" +$RUN_COMMAND; \ No newline at end of file diff --git a/casquatch-examples/springconfigserver/env b/casquatch-examples/springconfigserver/env new file mode 100644 index 0000000..3dbcfc1 --- /dev/null +++ b/casquatch-examples/springconfigserver/env @@ -0,0 +1,3 @@ +NAME=springconfigserver +SCHEMA=schema.cql +RUN_COMMAND="mvn clean test spring-boot:run" \ No newline at end of file diff --git a/casquatch-examples/springrest/env b/casquatch-examples/springrest/env new file mode 100644 index 0000000..c50f15f --- /dev/null +++ b/casquatch-examples/springrest/env @@ -0,0 +1,3 @@ +NAME=springrest +SCHEMA=schema.cql +RUN_COMMAND="mvn clean test spring-boot:run" \ No newline at end of file diff --git a/casquatch-examples/test.sh b/casquatch-examples/test.sh new file mode 100755 index 0000000..e9be44e --- /dev/null +++ b/casquatch-examples/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -d "casquatch-examples" ]; then + cd casquatch-examples +fi; + +source ./.setup.sh + +echo "---------------------------------------------" +echo "Test App" +echo "---------------------------------------------" +$TEST_COMMAND; \ No newline at end of file