Toad World Blog

Benchmark Factory REST API (Part 2)

May 15, 2017 10:16:22 AM by Kevin Dalton

In the first part of this blog series on the new BMF REST API I covered the basics on how to create a new connection, a new job which uses that new connection, and how to execute that job.  In this the second part I will cover more on how to modify existing objects like jobs/tests/connections like you would in common testing automation scenarios.

So as a reminder here is the current REST structure as shown in the last blog.

Jobs (GP)
                Job (GDU)
                                Schedule (GU)
                                Tests (GP)
                                                Test (GDU)
Connections (GP)
                Connection (GDU)
TestRuns (G)
                TestRun (GDU) (Update comment only)
                                Connection (G)
                                Test (G)

G = GET (retrieves the objects XML representation)
P = POST (Adds a new object based on the XML supplied in the HTTP data area)
U = PUT (Updates the object to the value(s) supplied in the XML supplied in the HTTP data area)
D = DELETE (Deletes the object)

 

Modify a connection (change database)

I have seen many a testing labs which have multiple test databases, typically of varying size, storage system, or configurations.  Having the different databases allows them to perform test runs without having to go through the time intensive process of creating and initializing the varying databases before each test run.  With the BMF REST API this can be quickly done by doing an HTTP PUT to the connection which you want to make the modification, so for example if you are using a SQL Server connection named “MyTestDatabase” which contains two databases, Test500G and Test1TB. To switch the connection to start using the Test1TB database you would perform the following REST API call.

 

Modify a job to use a different connection

When trying to compare performance of two systems, such as on-premise vs. cloud, a user typically has two connections created and will run the same workload against the two systems.  So changing the connection used by a job for execution is a common practice.  To do this using the REST API a user just needs to perform a HTTP PUT to the desired job and change the connection (profile) used.  Below is an example of such a REST API call to perform just this.

 

Opening a Saved Job File

If you have been using BMF you probably have existing jobs you may want to use or just want to use the BMF UI to create/edit a job and save it in a job file (*.bfj), you a can use the BMF REST API to create a job based on that job file (with a small bit of editing).

A BFJ file is in XML format but does have an extra XML element which does prevents the creation of the job, so you will need to remove the <BMF_Project> node from the file.  Fortunately this can be done simply in many scripting languages or using a XSLT.   For this example I will use an XSLT and a PowerShell script to remove the node and send the REST request to add the job.

The XSLT is very simple and looks like;

<!-- remove the BMF_Project node template -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
 <xsl:template match="/BMF_Project">
    <xsl:copy-of select="node()"/>
</xsl:template>
 </xsl:stylesheet>

And here is the PowerShell script that I used.

$xsl = "C:BMFRESTRemoveBMFProjectNode.xslt"
$xml = "C:BMFRESTRESTImportJob.bfj"
  
# First transform the saved job file
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load($xsl);
$outstr = New-Object System.IO.StringWriter
$arglist = new-object System.Xml.Xsl.XsltArgumentList
$xslt.Transform($xml, $arglist, $outstr);
 
# now import using REST
Invoke-RestMethod -Method Post -Uri http://localhost:30100/api/jobs -Body $outstr.ToString()

In part 3 of this series I will cover some special functions within the Benchmark Factory REST API which might be done as part automated test execution as well as common errors that I have seen with the REST API.  Please tell us what you think in the comments section below!

Tags: Benchmark Factory DevOps

Kevin Dalton

Written by Kevin Dalton

Kevin Dalton is a Senior Software Development Engineer at Quest Software, where, for 20+ years, he has been the Benchmark Factory for Database Development Manager. Now working as a product architect for a variety of products, he has experience with several database technologies including Oracle, SQL Server, MySQL, SAP, IBM UDB, and others. Kevin also has experience in Database DevOps and the implementation of Continuous processes to database development.