-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task 54140: automatically start load from pipeline rather than requir…
…ing start button in UI
- Loading branch information
Robin Bobbitt
committed
Feb 9, 2016
1 parent
add5569
commit e1cb879
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
$application = getenv("VCAP_APPLICATION"); | ||
$application_json = json_decode($application, true); | ||
$applicationURI = $application_json["application_uris"][0]; | ||
|
||
if (!isset($_GET['action']) || $_GET['action'] == 'status') { | ||
//Show status of load testing | ||
if (file_exists("RUNNING")) { | ||
echo "Load test is running. "; | ||
echo file_get_contents("RUNNING"); | ||
} else { | ||
echo "Load test is not running. Use http://$applicationURI/autoLoadTest.php?count=COUNT&delay=DELAY&action=start to start load testing."; | ||
} | ||
} else if ($_GET['action'] == 'stop') { | ||
//Turn off load test | ||
exec('rm -f RUNNING'); | ||
print "Load test is stopped.\n"; | ||
} else if ($_GET['action'] == 'start') { | ||
//If already running, tell user to issue a stop first. We could fancier and kill | ||
//the running script and update with the new params but for now let's just... | ||
if (file_exists("RUNNING")) { | ||
print("Load test is already running. Use http://$applicationURI/autoLoadTest.php?action=stop to stop the running test."); | ||
exit(); | ||
} | ||
|
||
//Calculate route to catalog loadTest URL | ||
$applicationName = $application_json["name"]; | ||
$catalogAppName = str_replace("ui-", "catalog-api-", $applicationName); | ||
$catalogAppName = str_replace("-ui", "-catalog-api", $catalogAppName); | ||
$catalogHost=substr_replace($applicationURI, $catalogAppName, 0, strlen($applicationName)); | ||
$catalogRoute = "http://" . $catalogHost; | ||
|
||
//Specify count in loadTest URL | ||
if (isset($_GET['count'])) { | ||
$count = $_GET['count']; | ||
} else { | ||
$count = 100; | ||
} | ||
$url = $catalogRoute . "/loadTest?count=" . $count; | ||
|
||
//Specify the delay between calls to loadTest | ||
if (isset($_GET['delay'])) { | ||
$delay = $_GET['delay']; | ||
} else { | ||
$delay = 0; | ||
} | ||
|
||
//Use a RUNNING file to indicate load test is running | ||
echo exec("echo 'Count: $count Delay: $delay' > RUNNING"); | ||
|
||
//Start the load script in the background and return | ||
#Print "load.sh -d $delay -u $url\n"; | ||
echo exec("sh load.sh -d $delay -u $url > load.log 2>&1 &"); | ||
print "Loaded started with delay $delay on $url\n"; | ||
} else { | ||
print "Unsupported action {$_GET['action']}"; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/sh | ||
# This script generates load on the specified URL. | ||
|
||
#Accepts a delay and a URL | ||
|
||
while getopts :d:u: opt; do | ||
case $opt in | ||
d) #set delay | ||
DELAY=$OPTARG | ||
#echo "DELAY = $DELAY" | ||
;; | ||
u) #set url | ||
URL=$OPTARG | ||
#echo "URL = $URL" | ||
;; | ||
\?) #invalid arg | ||
echo "Invalid argument -$OPTARG" | ||
exit 1; | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "$URL" ]; then | ||
echo "URL must be specified with -u"; | ||
exit 1; | ||
fi | ||
|
||
#Default delay to 0 if not specified | ||
if [ -z "$DELAY" ]; then | ||
DELAY=0; | ||
fi | ||
|
||
#echo "Delay: $DELAY"; | ||
|
||
#Check for RUNNING file to determine if load should be generated | ||
if [ ! -f "RUNNING" ] ; then | ||
echo "Load test not running. Exiting..."; | ||
exit 0; | ||
fi | ||
|
||
#Clean up the results log file if it exists | ||
if [ -f results.log ] ; then | ||
echo "Cleaning up old results.log" | ||
rm -f results.log | ||
fi | ||
|
||
#TODO: Get fancier to prevent someone from stopping and starting the load during sleep interval | ||
# and ending up with multiple load scripts continuing to run simultaneously. For example, could | ||
# put the PID in RUNNING and either verify it here or have the calling script kill this process. | ||
|
||
echo "Starting load to $URL"; | ||
|
||
while [ -f RUNNING ] ; | ||
do | ||
curl -s $URL -w "\n" >> results.log; | ||
sleep $DELAY; | ||
done | ||
|
||
echo "Done."; |