Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlloyd committed Apr 5, 2016
2 parents 4b463f6 + ecd1996 commit 9bfc8c0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 29 deletions.
22 changes: 8 additions & 14 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,18 @@ function install_jmeter() {
# Decide where to download jmeter from
#
# Order of preference:
# 1. Mirror, if the desired version is current
# 2. S3, if not current and we have a copy
# 1. S3, if we have a copy of the file
# 2. Mirror, if the desired version is current
# 3. Archive, as a backup
# ------------------------------------------------

# Mirrors only host the current version, get the preferred mirror for this location
preferred_mirror=$(curl -s 'http://www.apache.org/dyn/closer.cgi?as_json=1' | grep "preferred" | cut -d ':' -f3 | cut -d'"' -f1 | awk -F// '{print $NF}' | sed 's/.$//')
# Scrape the main binaries page to see what the current version is
current=$(curl -s 'http://www.apache.org/dist/jmeter/binaries/')

if [ $(echo $current | grep -c "$JMETER_VERSION") -gt "0" ] ; then
# This is the current version of jmeter so use the preferred mirror to download
echo "downloading from preferred mirror: http://$preferred_mirror/jmeter/binaries/$JMETER_VERSION.tgz"
wget -q -O $REMOTE_HOME/$JMETER_VERSION.tgz http://$preferred_mirror/jmeter/binaries/$JMETER_VERSION.tgz
elif [ $(curl -sI https://s3.amazonaws.com/jmeter-ec2/$JMETER_VERSION.tgz | grep -c "403 Forbidden") -eq "0" ] ; then
# It wasn't the current version but we have a copy on S3 so use that
if [ $(curl -sI https://s3.amazonaws.com/jmeter-ec2/$JMETER_VERSION.tgz | grep -c "403 Forbidden") -eq "0" ] ; then
# We have a copy on S3 so use that
echo "Downloading jmeter from S3"
wget -q -O $REMOTE_HOME/$JMETER_VERSION.tgz https://s3.amazonaws.com/jmeter-ec2/$JMETER_VERSION.tgz
elif [ $(echo $(curl -s 'http://www.apache.org/dist/jmeter/binaries/') | grep -c "$JMETER_VERSION") -gt "0" ] ; then
# Nothing found on S3 but this is the current version of jmeter so use the preferred mirror to download
echo "downloading jmeter from a Mirror"
wget -q -O $REMOTE_HOME/$JMETER_VERSION.tgz "http://www.apache.org/dyn/closer.cgi?filename=jmeter/binaries/$JMETER_VERSION.tgz&action=download"
else
# Fall back to the archive server
echo "Downloading jmeter from Apache Archive"
Expand Down
72 changes: 57 additions & 15 deletions jmeter-ec2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,18 @@ function runsetup() {
status_check_count=0
status_check_limit=90
status_check_limit=`echo "$status_check_limit + $countof_instanceids" | bc` # increase wait time based on instance count
echo -n "waiting for instance status checks to pass (this can take several minutes)..."
echo "waiting for instance status checks to pass (this can take several minutes)..."
count_passed=0
while [ "$count_passed" -ne "$instance_count" ] && [ $status_check_count -lt $status_check_limit ]
do
echo -n .
# Update progress bar
progressBar $countof_instanceids $count_passed
status_check_count=$(( $status_check_count + 1))
count_passed=$(ec2-describe-instance-status --region $REGION ${attempted_instanceids[@]} | awk '/INSTANCESTATUS/ {print $3}' | grep -c passed)
sleep 3
sleep 1
done
progressBar $countof_instanceids $count_passed true
echo

if [ $status_check_count -lt $status_check_limit ] ; then # all hosts started ok because count_passed==instance_count
# set the instanceids array to use from now on - attempted = actual
Expand All @@ -289,7 +292,7 @@ function runsetup() {

# set hosts array
hosts=(`ec2-describe-instances --region $REGION ${attempted_instanceids[@]} | awk '/INSTANCE/ {print $4}'`)
echo "all hosts ready"
# echo "all hosts ready"
else # Amazon probably failed to start a host [*** NOTE this is fairly common ***] so show a msg - TO DO. Could try to replace it with a new one?
original_count=$countof_instanceids
# filter requested instances for only those that started well
Expand Down Expand Up @@ -402,7 +405,7 @@ function runsetup() {

# scp install.sh
if [ "$setup" = "TRUE" ] ; then
echo -n "copying install.sh to $instance_count server(s)..."
echo "copying install.sh to $instance_count server(s)..."
for host in ${hosts[@]} ; do
(scp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
-i "$PEM_PATH/$PEM_FILE" \
Expand All @@ -417,32 +420,36 @@ function runsetup() {
res=0
while [ "$res" != "$instance_count" ] ;
do
echo -n .
# Update progress bar
progressBar $instance_count $res
res=$(grep -c "done" $project_home/$DATETIME*scpinstall.out \
| awk -F: '{ s+=$NF } END { print s }') # the awk command here sums up the output if multiple matches were found
sleep 3
sleep 1
done
echo "complete"
progressBar $instance_count $res true
echo
echo

# Install test software
echo "running install.sh on $instance_count server(s)..."
echo "running install.sh on $instance_count server(s) (this can take several minutes)..."
for host in ${hosts[@]} ; do
(ssh -nq -o StrictHostKeyChecking=no \
-i "$PEM_PATH/$PEM_FILE" $USER@$host -p $REMOTE_PORT \
"$REMOTE_HOME/install.sh $REMOTE_HOME $attemptjavainstall $JMETER_VERSION"\
"$REMOTE_HOME/install.sh $REMOTE_HOME $attemptjavainstall $JMETER_VERSION 2>&1"\
> $project_home/$DATETIME-$host-install.out) &
done

# check to see if the install scripts are complete
res=0
while [ "$res" != "$instance_count" ] ; do # Installation not complete (count of matches for 'software installed' not equal to count of hosts running the test)
echo -n .
# Update progress bar
progressBar $instance_count $res
res=$(grep -c "software installed" $project_home/$DATETIME*install.out \
| awk -F: '{ s+=$NF } END { print s }') # the awk command here sums up the output if multiple matches were found
sleep 3
sleep 1
done
echo "complete"
progressBar $instance_count $res true
echo
echo
fi

Expand Down Expand Up @@ -583,7 +590,7 @@ function runsetup() {
unset threads
done
echo
echo "...thread counts updated"
echo "thread counts updated"
echo

# scp the test files onto each host
Expand Down Expand Up @@ -1014,7 +1021,6 @@ function runcleanup() {
}

function updateTest() {

sqlstr="mysql -u $DB_USER -p$DB_PSWD $DB_NAME"

function dosql {
Expand Down Expand Up @@ -1072,6 +1078,42 @@ function updateTest() {
esac
}

progressBarWidth=50
spinnerIndex=1
sp="/-\|"

# Function to draw progress bar
progressBar() {
taskCount=$1
tasksDone=$2
progressDone=$3
# Calculate number of fill/empty slots in the bar
progress=$(echo "$progressBarWidth/$taskCount*$tasksDone" | bc -l)
fill=$(printf "%.0f\n" $progress)
if [ $fill -gt $progressBarWidth ]; then
fill=$progressBarWidth
fi
empty=$(($fill-$progressBarWidth))

# Percentage Calculation
percent=$(echo "100/$taskCount*$tasksDone" | bc -l)
percent=$(printf "%0.2f\n" $percent)
if [ $(echo "$percent>100" | bc) -gt 0 ]; then
percent="100.00"
fi

# Output to screen
printf "\r["
printf "%${fill}s" '' | tr ' ' \#
printf "%${empty}s" '' | tr ' ' " "
printf "] $percent%% - ($tasksDone of $taskCount) "
if [ $progressDone ] ; then
printf " - Done."
else
printf " \b${sp:spinnerIndex++%${#sp}:1} "
fi
}

function control_c(){
# Turn off the CTRL-C trap now that it has been invoked once already
trap - INT
Expand Down

0 comments on commit 9bfc8c0

Please sign in to comment.