Skip to content

Commit

Permalink
Added back in helper scripts for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tdl-jturner committed Aug 19, 2019
1 parent c6dc61a commit 5e4606e
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
74 changes: 74 additions & 0 deletions casquatch-examples/.setup.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions casquatch-examples/loadtest/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NAME=loadtest
SCHEMA=schema.cql
RUN_COMMAND="mvn clean test package;java -jar target/loadtest-0.0.1-SNAPSHOT.jar"
12 changes: 12 additions & 0 deletions casquatch-examples/run.sh
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions casquatch-examples/springconfigserver/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NAME=springconfigserver
SCHEMA=schema.cql
RUN_COMMAND="mvn clean test spring-boot:run"
3 changes: 3 additions & 0 deletions casquatch-examples/springrest/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NAME=springrest
SCHEMA=schema.cql
RUN_COMMAND="mvn clean test spring-boot:run"
12 changes: 12 additions & 0 deletions casquatch-examples/test.sh
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 5e4606e

Please sign in to comment.