#-----------------------------------------------------------------
# Copyright (c) 2019 Quest Software
#
# Description:
# The following script is a sample of how to create and execute
# a SQL Scalability test using the BMF REST API against an
# Oracle database
#
#-----------------------------------------------------------------
# This script requires PowerShell version 3.0 or higher
if ($PSVersionTable.PSVersion.Major -lt 3)
{
Throw "PowerShell version 3.0 or higher required to run this test script."
}
Set-Variable -Name JobComplete -Value 1
Set-Variable -Name JobRunning -Value 2
Set-Variable -Name JobReady -Value 3
Set-Variable -Name JobHold -Value 4
Set-Variable -Name JobStopping -Value 5
Set-Variable -Name TestInComplete -Value 0
Set-Variable -Name TestCompletewithError -Value 1
Set-Variable -Name Testcancelled -Value 2
Set-Variable -Name TestRunning -Value 3
Set-Variable -Name TestError -Value 4
Set-Variable -Name TestCompleted -Value 5
# Set the machne name/ip on which BMF is running
$bmfserver = "localhost"
# set global trap
trap
{
Write-Host $_
exit 1
}
# Clear any errors
clear
$Error.Clear()
function Main()
{
$bmfpath="C:\Program Files\Quest Software\Benchmark Factory 8.3.0 x64\bin\BMFServer.exe" #set the BMF Console BFactory or BMFServer Path
Start-Process -filepath $bmfpath #Launch BMF
Write-host "Launch BMF"
start-sleep -Seconds 5
Create-OracleConnection
Add-BenchmarkJob "TPC-C"
Put-Connection "Oracle122c" "TPC-C Job"
Run-Job "TPC-C Job"
GET-Currentresult "TPC-C Job" 0
Get-Currentresult "TPC-C Job" 1
Delete-Connection "Oracle122c"
Delete-Job "TPC-C Job"
Stop-Process -name BMFServer -Force #Close BMF
}
function Create-OracleConnection()
{
# This will add a job to BMF
Write-Host "Creating Connection......"
$OracleIP="10.##.##.##"
$ServiceName="ora122c"
$ConnectionXML="
Oracle
Oracle122c
c##bmf
bmf
false
$OracleIP
1521
true
$ServiceName
Normal
false
3
10
"
$uri = "http://"+$bmfserver+":30100/api/connections"
$response = Invoke-RestMethod -Method Post -ContentType "text/xml" -Uri $uri -Body $ConnectionXML
}
function Add-BenchmarkJob($Benchmark)
{
# This will add a job to BMF
Write-Host "Creating job $Benchmark...."
$jobxml=get-content -Path "D:\BenchmarkJobXMLFile\$Benchmark.txt"
$uri = "http://"+$bmfserver+":30100/api/jobs"
$response = Invoke-RestMethod -Method Post -ContentType "text/xml" -Uri $uri -Body $jobxml
}
function Put-Connection($ConnectionName,$JobName)
{
Write-Host "Update job Connection: $ConnectionName"
$uri = "http://"+$bmfserver+":30100/api/jobs/"+$jobname
Invoke-RestMethod -Method Put -ContentType "text/xml" -Uri $uri -Body "$connectionName"
}
function Run-Job($JobName)
{
Write-Host "Starting job "$jobname"...."
$uri = "http://"+$bmfserver+":30100/api/jobs/"+$jobname
Invoke-RestMethod -Method Put -ContentType "text/xml" -Uri $uri -Body "2"
Start-Sleep -Seconds 5
# Get the current job status
$uri = "http://"+$bmfserver+":30100/api/jobs/"+$jobname+"/status"
$response = Invoke-RestMethod -Method Get -Uri $uri
# See if we are still running
if ($response.status -ne $JobRunning)
{
Write-Host "Job completed"
break
}
else {write-host "Job is running"}
Start-Sleep -Seconds 10
}
function GET-Currentresult($JobName,$TestID)
{
$uri = "http://"+$bmfserver+":30100/api/jobs/"+$jobname+"/tests/$TestID/currentresult"
$response = Invoke-RestMethod -Method Get -Uri $uri
$ErrMsg="Test is not running"
$timeout=45000
do
{
# Sleep for 5 seconds
Start-Sleep -Seconds 10
$uri = "http://"+$bmfserver+":30100/api/jobs/"+$jobname+"/tests/$TestID/currentresult"
$response = Invoke-RestMethod -Method Get -Uri $uri
# See if we are still running
if ($response.errormessage -eq $ErrMsg)
{
Write-Host "Test completed"
break
}
else {write-host $response.status
if ($response.status -eq "Sampling")
{
$response | format-table #List Currentresult
}
}
# Still running, so increment timeout counter and check for timeout
$waittime += 10
if ($waittime -ge $timeout)
{
Write-Host "Job execution timeout exceeded"
throw "Job execution timeout exceeded"
break
}
}
while ($True)
}
function Delete-Job($JobName)
{
Write-Host "Delete job $JobName......"
$uri = "http://"+$bmfserver+":30100/api/jobs/"+$jobname
Invoke-RestMethod -Method Delete -Uri $uri
}
function Delete-Connection($ConnectionName)
{
Write-Host "Delete Connection $ConnectionName......"
$uri = "http://"+$bmfserver+":30100/api/connections/"+$ConnectionName
Invoke-RestMethod -Method Delete -Uri $uri
}
Main