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

Commit 138fbea

Browse files
dmiusDmitry
authored andcommitted
Some PR remarks fixed
1 parent f836230 commit 138fbea

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

nancy_run.sh

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ function check_cli_parameters() {
391391
exit 1
392392
fi
393393
if [[ -z ${AWS_REGION+x} ]]; then
394-
err "NOTICE: AWS EC2 region not given. Will used us-east-1."
394+
err "NOTICE: AWS EC2 region not given. Will use us-east-1."
395395
AWS_REGION='us-east-1'
396396
fi
397397
if [[ -z ${AWS_BLOCK_DURATION+x} ]]; then
398-
err "NOTICE: Container live time duration is not given. Will used 60 minutes."
398+
err "NOTICE: Container live time duration is not given. Will use 60 minutes."
399399
AWS_BLOCK_DURATION=60
400400
else
401401
case $AWS_BLOCK_DURATION in
@@ -408,6 +408,18 @@ function check_cli_parameters() {
408408
;;
409409
esac
410410
fi
411+
if [[ ! -z ${AWS_EBS_VOLUME_SIZE+x} ]]; then
412+
re='^[0-9]+$'
413+
if ! [[ $AWS_EBS_VOLUME_SIZE =~ $re ]] ; then
414+
err "ERROR: --aws-ebs-volume-size must be integer."
415+
exit 1
416+
fi
417+
else
418+
if [[ ! ${AWS_EC2_TYPE:0:2} == 'i3' ]]; then
419+
err "NOTICE: EBS volume size is not given, will be calculated based on the dump file size (might be not enough)."
420+
err "WARNING: It is recommended to specify EBS volume size explicitly (CLI option '--ebs-volume-size')."
421+
fi
422+
fi
411423
elif [[ "$RUN_ON" == "localhost" ]]; then
412424
if [[ ! -z ${AWS_KEYPAIR_NAME+x} ]] || [[ ! -z ${AWS_SSH_KEY_PATH+x} ]] ; then
413425
err "ERROR: options '--aws-keypair-name' and '--aws-ssh-key-path' must be used with '--run-on aws'."
@@ -489,6 +501,11 @@ function check_cli_parameters() {
489501
DB_DUMP_EXT=${DB_DUMP_FILENAME##*.}
490502
fi
491503

504+
if [[ -z ${DB_NAME+x} ]]; then
505+
dbg "NOTICE: Database name is not given. Will use 'test'"
506+
DB_NAME='test'
507+
fi
508+
492509
if [[ -z ${PG_CONFIG+x} ]]; then
493510
err "NOTICE: No PostgreSQL config is provided. Will use default."
494511
# TODO(NikolayS) use "auto-tuning" – shared_buffers=1/4 RAM, etc
@@ -514,11 +531,6 @@ function check_cli_parameters() {
514531
ARTIFACTS_DESTINATION="."
515532
fi
516533

517-
if [[ -z ${DB_NAME+x} ]]; then
518-
err "NOTICE: Database name is not given. Will use test"
519-
DB_NAME='test'
520-
fi
521-
522534
if [[ -z ${ARTIFACTS_FILENAME+x} ]]; then
523535
dbg "Artifacts naming is not set. Will use: '$DOCKER_MACHINE'"
524536
ARTIFACTS_FILENAME=$DOCKER_MACHINE
@@ -537,7 +549,7 @@ function check_cli_parameters() {
537549
if [[ ! -z ${WORKLOAD_CUSTOM_SQL+x} ]]; then
538550
check_path WORKLOAD_CUSTOM_SQL
539551
if [[ "$?" -ne "0" ]]; then
540-
#err "WARNING: Value given as workload-custom-sql: '$WORKLOAD_CUSTOM_SQL' not found as file will use as content"
552+
dbg "WARNING: Value given as workload-custom-sql: '$WORKLOAD_CUSTOM_SQL' not found as file will use as content"
541553
echo "$WORKLOAD_CUSTOM_SQL" > $TMP_PATH/workload_custom_sql_tmp.sql
542554
WORKLOAD_CUSTOM_SQL="$TMP_PATH/workload_custom_sql_tmp.sql"
543555
fi
@@ -546,7 +558,7 @@ function check_cli_parameters() {
546558
if [[ ! -z ${COMMANDS_AFTER_CONTAINER_INIT+x} ]]; then
547559
check_path COMMANDS_AFTER_CONTAINER_INIT
548560
if [[ "$?" -ne "0" ]]; then
549-
#err "WARNING: Value given as after_db_init_code: '$COMMANDS_AFTER_CONTAINER_INIT' not found as file will use as content"
561+
dbg "WARNING: Value given as after_db_init_code: '$COMMANDS_AFTER_CONTAINER_INIT' not found as file will use as content"
550562
echo "$COMMANDS_AFTER_CONTAINER_INIT" > $TMP_PATH/after_docker_init_code_tmp.sh
551563
COMMANDS_AFTER_CONTAINER_INIT="$TMP_PATH/after_docker_init_code_tmp.sh"
552564
fi
@@ -563,7 +575,7 @@ function check_cli_parameters() {
563575
if [[ ! -z ${SQL_BEFORE_DB_RESTORE+x} ]]; then
564576
check_path SQL_BEFORE_DB_RESTORE
565577
if [[ "$?" -ne "0" ]]; then
566-
#err "WARNING: Value given as before_db_init_code: '$SQL_BEFORE_DB_RESTORE' not found as file will use as content"
578+
dbg "WARNING: Value given as before_db_init_code: '$SQL_BEFORE_DB_RESTORE' not found as file will use as content"
567579
echo "$SQL_BEFORE_DB_RESTORE" > $TMP_PATH/before_db_init_code_tmp.sql
568580
SQL_BEFORE_DB_RESTORE="$TMP_PATH/before_db_init_code_tmp.sql"
569581
fi
@@ -592,21 +604,6 @@ function check_cli_parameters() {
592604
DELTA_CONFIG="$TMP_PATH/target_config_tmp.conf"
593605
fi
594606
fi
595-
596-
if [[ "$RUN_ON" == "aws" ]]; then
597-
if [[ ! -z ${AWS_EBS_VOLUME_SIZE+x} ]]; then
598-
re='^[0-9]+$'
599-
if ! [[ $AWS_EBS_VOLUME_SIZE =~ $re ]] ; then
600-
err "ERROR: --aws-ebs-volume-size must be integer."
601-
exit 1
602-
fi
603-
else
604-
if [[ ! ${AWS_EC2_TYPE:0:2} == 'i3' ]]; then
605-
err "NOTICE: EBS volume size is not given, will be calculated based on the dump file size (might be not enough)."
606-
err "WARNING: It is recommended to specify EBS volume size explicitly (CLI option '--ebs-volume-size')."
607-
fi
608-
fi
609-
fi
610607
### End of CLI parameters checks ###
611608
}
612609

@@ -626,7 +623,8 @@ function check_cli_parameters() {
626623
# (text) [5] AWS keypair to use
627624
# (text) [6] Path to Private Key file to use for instance
628625
# Matching public key with .pub extension should exist
629-
# (text) [7] The AWS region to launch the instance (us-east-1, eu-central-1)
626+
# (text) [7] The AWS region to launch the instance
627+
# (for example us-east-1, eu-central-1)
630628
# (text) [8] The AWS zone to launch the instance in (one of a,b,c,d,e)
631629
# Returns:
632630
# None
@@ -688,7 +686,7 @@ function wait_ec2_docker_machine_ready() {
688686
if $check_price ; then
689687
status=$( \
690688
aws --region=$AWS_REGION ec2 describe-spot-instance-requests \
691-
--filters="Name=launch.instance-type,Values=$AWS_EC2_TYPE" \
689+
--filters="Name=launch.instance-type,Values=$AWS_EC2_TYPE" \
692690
| jq '.SpotInstanceRequests | sort_by(.CreateTime) | .[] | .Status.Code' \
693691
| tail -n 1
694692
)
@@ -716,18 +714,18 @@ function determine_history_ec2_spot_price() {
716714
# TODO detect region and/or allow to choose via options
717715
prices=$(
718716
aws --region=$AWS_REGION ec2 \
719-
describe-spot-price-history --instance-types $AWS_EC2_TYPE --no-paginate \
720-
--start-time=$(date +%s) --product-descriptions="Linux/UNIX (Amazon VPC)" \
721-
--query 'SpotPriceHistory[*].{az:AvailabilityZone, price:SpotPrice}'
717+
describe-spot-price-history --instance-types $AWS_EC2_TYPE --no-paginate \
718+
--start-time=$(date +%s) --product-descriptions="Linux/UNIX (Amazon VPC)" \
719+
--query 'SpotPriceHistory[*].{az:AvailabilityZone, price:SpotPrice}'
722720
)
723721
minprice=$(echo $prices | jq 'min_by(.price) | .price')
724722
region=$(echo $prices | jq 'min_by(.price) | .az') #TODO(NikolayS) double-check zones&regions
725723
region="${region/\"/}"
726724
region="${region/\"/}"
727725
minprice="${minprice/\"/}"
728726
minprice="${minprice/\"/}"
729-
AWS_ZONE=${region: -1}
730-
AWS_REGION=${region:: -1}
727+
AWS_ZONE=${region:$((${#region}-1)):1}
728+
AWS_REGION=${region:0:$((${#region}-1))}
731729
msg "Min price from history: $minprice in $region (zone: $AWS_ZONE)"
732730
multiplier="1.01"
733731
price=$(echo "$minprice * $multiplier" | bc -l)

0 commit comments

Comments
 (0)