Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 926c079

Browse files
dmiusDmitry
authored andcommitted
Dual params for sql code and conf
1 parent 7d0c49e commit 926c079

File tree

1 file changed

+80
-25
lines changed

1 file changed

+80
-25
lines changed

nancy_run.sh

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ while true; do
2323
--db-dump-path )
2424
DB_DUMP_PATH="$2"; shift 2 ;;
2525
--after-db-init-code )
26-
#s3 url|filename +
26+
#s3 url|filename|content
2727
AFTER_DB_INIT_CODE="$2"; shift 2 ;;
2828
--workload-full-path )
2929
#s3 url
@@ -32,18 +32,18 @@ while true; do
3232
#Still unsuported
3333
WORKLOAD_BASIS_PATH="$2"; shift 2 ;;
3434
--workload-custom-sql )
35-
#s3 url|filename +
35+
#s3 url|filename|content
3636
WORKLOAD_CUSTOM_SQL="$2"; shift 2 ;;
3737
--workload-replay-speed )
3838
WORKLOAD_REPLAY_SPEED="$2"; shift 2 ;;
3939
--target-ddl-do )
40-
#s3 url|filename +
40+
#s3 url|filename|content
4141
TARGET_DDL_DO="$2"; shift 2 ;;
4242
--target-ddl-undo )
43-
#s3 url|filename +
43+
#s3 url|filename|content
4444
TARGET_DDL_UNDO="$2"; shift 2 ;;
4545
--target-config )
46-
#s3 url|filename +
46+
#s3 url|filename|content
4747
TARGET_CONFIG="$2"; shift 2 ;;
4848
--artifacts-destination )
4949
ARTIFACTS_DESTINATION="$2"; shift 2 ;;
@@ -125,13 +125,9 @@ function checkPath() {
125125
eval "$1=\"$path\"" # update original variable
126126
return 0 # file found
127127
else
128-
return 3 # file not found
128+
return 2 # file not found
129129
fi
130130
fi
131-
if [ -f $path ]
132-
then
133-
return 0;
134-
fi
135131
return -1 # incorrect path
136132
}
137133

@@ -206,6 +202,8 @@ function checkParams() {
206202
exit 1
207203
fi
208204

205+
[ -v DB_DUMP_PATH ] && ! checkPath DB_DUMP_PATH && >&2 echo "ERROR: file $DB_DUMP_PATH given by db_dump_path not found" && exit 1
206+
209207
if (([ ! -v TARGET_DDL_UNDO ] && [ -v TARGET_DDL_DO ]) || ([ ! -v TARGET_DDL_DO ] && [ -v TARGET_DDL_UNDO ]))
210208
then
211209
>&2 echo "ERROR: DDL code must have do and undo part."
@@ -224,21 +222,76 @@ function checkParams() {
224222
ARTIFACTS_FILENAME=$DOCKER_MACHINE
225223
fi
226224

227-
[ -v WORKLOAD_FULL_PATH ] && ! checkPath WORKLOAD_FULL_PATH && >&2 echo "WARNING: file $AFTER_DB_INIT_CODE not found"
225+
[ -v WORKLOAD_FULL_PATH ] && ! checkPath WORKLOAD_FULL_PATH && >&2 echo "ERROR: file $WORKLOAD_FULL_PATH given by workload_full_path not found" && exit 1
228226

229-
[ -v WORKLOAD_BASIS_PATH ] && ! checkPath WORKLOAD_BASIS_PATH && >&2 echo "WARNING: file $WORKLOAD_BASIS_PATH not found"
227+
echo "WORKLOAD_FULL_PATH: $WORKLOAD_FULL_PATH"
230228

231-
[ -v WORKLOAD_CUSTOM_SQL ] && ! checkPath WORKLOAD_CUSTOM_SQL && >&2 echo "WARNING: file $WORKLOAD_CUSTOM_SQL not found"
229+
[ -v WORKLOAD_BASIS_PATH ] && ! checkPath WORKLOAD_BASIS_PATH && >&2 echo "WARNING: file $WORKLOAD_BASIS_PATH given by workload_basis_path not found"
232230

233-
[ -v DB_DUMP_PATH ] && ! checkPath DB_DUMP_PATH && >&2 echo "WARNING: file $DB_DUMP_PATH not found"
231+
if [ -v WORKLOAD_CUSTOM_SQL ]
232+
then
233+
checkPath WORKLOAD_CUSTOM_SQL
234+
if [ "$?" -ne "0" ]
235+
then
236+
>&2 echo "WARNING: Value given as workload-custom-sql: '$WORKLOAD_CUSTOM_SQL' not found as file will use as content"
237+
echo "$WORKLOAD_CUSTOM_SQL" > $TMP_PATH/workload_custom_sql_tmp.sql
238+
WORKLOAD_CUSTOM_SQL="$TMP_PATH/workload_custom_sql_tmp.sql"
239+
else
240+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as workload-custom-sql will use as filename"
241+
fi
242+
fi
234243

235-
[ -v AFTER_DB_INIT_CODE ] && ! checkPath AFTER_DB_INIT_CODE && >&2 echo "WARNING: file $AFTER_DB_INIT_CODE not found"
244+
if [ -v AFTER_DB_INIT_CODE ]
245+
then
246+
checkPath AFTER_DB_INIT_CODE
247+
if [ "$?" -ne "0" ]
248+
then
249+
>&2 echo "WARNING: Value given as after_db_init_code: '$AFTER_DB_INIT_CODE' not found as file will use as content"
250+
echo "$AFTER_DB_INIT_CODE" > $TMP_PATH/after_db_init_code_tmp.sql
251+
AFTER_DB_INIT_CODE="$TMP_PATH/after_db_init_code_tmp.sql"
252+
else
253+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as after_db_init_code will use as filename"
254+
fi
255+
fi
236256

237-
[ -v TARGET_DDL_DO ] && ! checkPath TARGET_DDL_DO && >&2 echo "WARNING: file $TARGET_DDL_DO not found"
257+
if [ -v TARGET_DDL_DO ]
258+
then
259+
checkPath TARGET_DDL_DO
260+
if [ "$?" -ne "0" ]
261+
then
262+
>&2 echo "WARNING: Value given as target_ddl_do: '$TARGET_DDL_DO' not found as file will use as content"
263+
echo "$TARGET_DDL_DO" > $TMP_PATH/target_ddl_do_tmp.sql
264+
TARGET_DDL_DO="$TMP_PATH/target_ddl_do_tmp.sql"
265+
else
266+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as target_ddl_do will use as filename"
267+
fi
268+
fi
238269

239-
[ -v TARGET_DDL_UNDO ] && ! checkPath TARGET_DDL_UNDO && >&2 echo "WARNING: file $TARGET_DDL_UNDO not found"
270+
if [ -v TARGET_DDL_UNDO ]
271+
then
272+
checkPath TARGET_DDL_UNDO
273+
if [ "$?" -ne "0" ]
274+
then
275+
>&2 echo "WARNING: Value given as target_ddl_undo: '$TARGET_DDL_UNDO' not found as file will use as content"
276+
echo "$TARGET_DDL_UNDO" > $TMP_PATH/target_ddl_undo_tmp.sql
277+
TARGET_DDL_UNDO="$TMP_PATH/target_ddl_undo_tmp.sql"
278+
else
279+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as target_ddl_undo will use as filename"
280+
fi
281+
fi
240282

241-
[ -v TARGET_CONFIG ] && ! checkPath TARGET_CONFIG && >&2 echo "WARNING: file $TARGET_CONFIG not found"
283+
if [ -v TARGET_CONFIG ]
284+
then
285+
checkPath TARGET_CONFIG
286+
if [ "$?" -ne "0" ]
287+
then
288+
>&2 echo "WARNING: Value given as target_config: '$TARGET_CONFIG' not found as file will use as content"
289+
echo "$TARGET_CONFIG" > $TMP_PATH/target_config_tmp.conf
290+
TARGET_CONFIG="$TMP_PATH/target_config_tmp.conf"
291+
else
292+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as target_config will use as filename"
293+
fi
294+
fi
242295
}
243296

244297
checkParams;
@@ -258,7 +311,6 @@ function waitEC2Ready() {
258311
((STOP==1)) && return 0
259312
if [ $checkPrice -eq 1 ]
260313
then
261-
#status=$(aws ec2 describe-spot-instance-requests --filters="Name=launch.instance-type,Values=$AWS_EC2_TYPE" | jq '.SpotInstanceRequests[] | .Status.Code' | tail -n 1 )
262314
status=$(aws ec2 describe-spot-instance-requests --filters="Name=launch.instance-type,Values=$AWS_EC2_TYPE" | jq '.SpotInstanceRequests | sort_by(.CreateTime) | .[] | .Status.Code' | tail -n 1)
263315
if [ "$status" == "\"price-too-low\"" ]
264316
then
@@ -337,11 +389,13 @@ else
337389
fi
338390

339391
function cleanup {
340-
echo "Remove temp files..."
341-
rm -f "$TMP_PATH/conf_$DOCKER_MACHINE.tmp"
342-
rm -f "$TMP_PATH/ddl_do_$DOCKER_MACHINE.sql"
343-
rm -f "$TMP_PATH/ddl_undo_$DOCKER_MACHINE.sql"
344-
rm -f "$TMP_PATH/queries_custom_$DOCKER_MACHINE.sql"
392+
echo "Remove temp files..." # if exists
393+
rm -f "$TMP_PATH/after_db_init_code_tmp.sql"
394+
rm -f "$TMP_PATH/workload_custom_sql_tmp.sql"
395+
rm -f "$TMP_PATH/target_ddl_do_tmp.sql"
396+
rm -f "$TMP_PATH/target_ddl_undo_tmp.sql"
397+
rm -f "$TMP_PATH/target_config_tmp.conf"
398+
345399
if [ "$RUN_ON" = "localhost" ]; then
346400
rm -rf "$TMP_PATH/pg_nancy_home_${CURRENT_TS}"
347401
echo "Remove docker container"
@@ -390,6 +444,7 @@ sleep 1 # wait for postgres up&running
390444
DB_DUMP_FILENAME=$(basename $DB_DUMP_PATH)
391445
docker_exec bash -c "bzcat /machine_home/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
392446
# After init database sql code apply
447+
echo "Apply sql code after db init from $AFTER_DB_INIT_CODE"
393448
if ([ -v AFTER_DB_INIT_CODE ] && [ "$AFTER_DB_INIT_CODE" != "" ])
394449
then
395450
AFTER_DB_INIT_CODE_FILENAME=$(basename $AFTER_DB_INIT_CODE)
@@ -407,7 +462,7 @@ if ([ -v TARGET_DDL_DO ] && [ "$TARGET_DDL_DO" != "" ]); then
407462
docker_exec bash -c "psql -U postgres test -E -f /machine_home/$TARGET_DDL_DO_FILENAME"
408463
fi
409464
# Apply postgres configuration
410-
echo "Apply postgres conf from /machine_home/conf_$DOCKER_MACHINE.tmp"
465+
echo "Apply postgres conf from $TARGET_CONFIG"
411466
if ([ -v TARGET_CONFIG ] && [ "$TARGET_CONFIG" != "" ]); then
412467
TARGET_CONFIG_FILENAME=$(basename $TARGET_CONFIG)
413468
docker_exec bash -c "cat /machine_home/$TARGET_CONFIG_FILENAME >> /etc/postgresql/$PG_VERSION/main/postgresql.conf"

0 commit comments

Comments
 (0)