Rest API - Support Data
The Reporter provides you with a Rest API that gives you direct access to the test data and statistics. The support data REST API enables you to conduct actions related support data (such as to collect data).
Concepts
-
Key - Key and value construct a tag. Each test has a subset of available tags with various values that describe the test specifics. Example: date.
-
Project - Concept derived from the cloud. Each project has it's own resources (users, devices) and can be used to created separation of testing efforts.
-
Test - Single test execution instance.
Gets support data (config, logs, and data), flows: Flow #1: The client waits until the file is ready then grabs it. /options (optional) > /prepare > /file Flow #2: The client polls from time to time until the files are ready then grabs it. /options (optional) > /start > /status (repeat periodically until state <> RUNNING) > /file
Get Support Data Options
Returns what can be included in the support data file, properties are:
Option | Description |
---|---|
config | Reporter's configuration files (config/ folder). |
logs | Reporter's log files(logs/ folder). |
database | Reporter's database's data, true when pg_dump utility is available. |
databaseConfig | PG's configuration file, true when: * PG is running in the same host as Reporter. * Reporter's database user has permission to query the 'data_directory' setting. * Reporter's OS user has permissions to access PG's 'data_directory'. |
databaseLog | PG's log files (latest <=10 MB), same rules as above. |
This API is available for Cloud Administrators only.
GET /reporter/api/supportData/options
Response Status: 200 OK
[
{
"config": true,
"logs": true,
"database": false,
"databaseConfig": true,
"databaseLog": true
}
]
Set Support Data Options
Prepares the support file replying until is ready.
This API is available for Cloud Administrators only.
POST /reporter/api/supportData/prepare
JSON parameter
Name | Type | Mandatory | Description |
---|---|---|---|
config | Boolean | Yes | Reporter's configuration files (config/ folder). |
logs | Boolean | Yes | Reporter's log files(logs/ folder). |
logs | Boolean | Yes | Reporter's database's data, true when pg_dump utility is available. |
databaseConfig | Boolean | Yes | PG's configuration file, true when: * PG is running in the same host as Reporter. * Reporter's database user has permission to query the 'data_directory' setting. * Reporter's OS user has permissions to access PG's 'data_directory'. |
databaseLog | Boolean | Yes | PG's log files (latest <=10 MB), same rules as above. |
Response Status: 200 OK
[
{
"config": true,
"logs": true,
"database": false,
"databaseConfig": true,
"databaseLog": true
}
]
Start Support Data
Start the support file preparation in the background, the payload is the same as above.
This API is available for Cloud Administrators only.
POST /reporter/api/supportData/start
JSON parameter
Name | Type | Mandatory | Description |
---|---|---|---|
config | Boolean | Yes | Reporter's configuration files (config/ folder). |
logs | Boolean | Yes | Reporter's log files(logs/ folder). |
logs | Boolean | Yes | Reporter's database's data, true when pg_dump utility is available. |
databaseConfig | Boolean | Yes | PG's configuration file, true when: * PG is running in the same host as Reporter. * Reporter's database user has permission to query 'data_directory' setting. * Reporter's OS user has permissions to access PG's 'data_directory'. |
databaseLog | Boolean | Yes | PG's log files (latest <=10 MB), same rules as above. |
Support Data Status
- This API is available for cloudAdmin only.
GET /reporter/api/supportData/status
Return the current status of the support file preparation.
Property | Description |
---|---|
state | One of this: IDLE, RUNNING, COMPLETED, CANCELING, CANCELED, ERROR |
startedAt | Reporter's log files(logs/ folder). |
startedBy | Username who started the process. |
canceledBy | Username who canceled the process (status CANCELING or CANCELED) |
progress | Percentage completed. |
finishedAt | Timestamp in which the process finished or canceled. |
error | n case the process ended because of an unexpected error, here is the error message. |
Progress may be slightly more than 100%; this is because at the beginning of the process the total data size is computed but it increases while the process runs.
Get Support Data
Gets the support data file.
This API is available for Cloud Administrators only.
GET /reporter/api/supportData/file
Code Example
The examples use the Unirest HTTP library. To compile and run them, use the following Maven dependency:
Maven dependency
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
Java Expand source
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.http.HttpHeaders;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
public class APIConfluence {
private HttpResponse<String> responseString;
private HttpResponse<InputStream> responseInputStream;
private String urlBase = "http://hostname:port/"; //TODO: modify hostname and port of your Reporter
private String user = "user"; //TODO: user name
private String password = "....."; //TODO: user password
private String accessKey= "....."; //TODO: user access key
String projectName = "projectName";//TODO: project name is here
String projectID = "projectID";//TODO: project ID is here
private String testID = "test ID";//TODO: test ID is here
@Test
public void getSupportDataOptions() {
String url = urlBase + "/api/supportData/options";
try {
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void prepareSupportData() {
String url = urlBase + "/api/supportData/prepare";
try {
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body("{\n" +
" \"config\" : true,\n" +
" \"logs\" : true,\n" +
" \"database\" : true,\n" +
" \"databaseConfig\" : true,\n" +
" \"databaseLog\" : true\n" +
"}")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getSupportDataFile() {
String url = urlBase + "/api/supportData/file";
try {
responseInputStream = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asBinary();
String destination = "destination";//TODO: Path to save the file - zip file
writeToFile(destination);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void startSupportData() {
String url = urlBase + "/api/supportData/start";
try {
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body("{\n" +
" \"config\" : true,\n" +
" \"logs\" : true,\n" +
" \"database\" : true,\n" +
" \"databaseConfig\" : true,\n" +
" \"databaseLog\" : true\n" +
"}")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getSupportDataStatus() {
String url = urlBase + "/api/supportData/status";
try {
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeToFile(String destination) {
InputStream inputStream = responseInputStream.getRawBody();
try {
FileOutputStream fileOutputStream = new FileOutputStream(destination);
int bytesRead = -1;
byte[] buffer = new byte[4096];
while ((bytesRead = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}