Package com.synopsys.defensics.api
Class ApiService
- java.lang.Object
-
- com.synopsys.defensics.api.ApiService
-
public class ApiService extends Object
Intermediate API service class between Jenkins job and Defensics client. Does things which client doesn't yet do and could map some exception/messages to be more suitable for Jenkins.NOTE: Exception handling is subject to change when client code is improved. Currently DefensicsClientException is inspected and InterruptedExceptions are thrown separately to handle job stopping more cleanly. DefensicsRequestException could be replaced with DefensicsClientException if InterruptedExceptions are handled some way.
-
-
Constructor Summary
Constructors Constructor Description ApiService(String defensicsInstanceUrl, String authenticationToken, boolean certificateValidationDisabled)
Constructor for Job object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Run
createNewRun()
Creates new empty Defensics run.void
deleteRun(String runId)
static String
formatUnhealthyHealthCheckLines(Map<String,HealthCheckResult> failingHealthChecks)
Returns formatted multiline string block about unhealthy health checks to be used in warnings.Optional<SuiteInstance>
getConfigurationSuite(String id)
Get suite information for given Defensics run.Map<String,HealthCheckResult>
getFailingHealthChecks()
Get server health check status and returns unhealthy check results.Run
getRun(String runId)
Get individual run.Optional<String>
getServerVersion()
Returns API server version as a string, or empty optional if request fails for some reason.Optional<Suite>
getSuiteInformationForRun(Run run)
Get Suite for the given run+suite-instance.boolean
healthCheck()
Checks API server health.void
saveResultPackage(FilePath resultFolder, String fileName, Run run)
Download the result package (zip-file) and saves it to provided result folder.void
saveResults(Run run, FilePath reportFolder)
Downloads the report for this job from Defensics.void
setTestConfigurationSettings(String runId, String settings)
Sends test configuration settings using CLI format.void
startRun(String runId)
Starts testrun using previously created test configuration.void
stopRun(String runId)
Makes a request to stop the test run.void
uploadTestPlan(String configurationId, FilePath testplan)
Upload a testplan file to the API server.
-
-
-
Method Detail
-
healthCheck
public boolean healthCheck() throws DefensicsRequestException, InterruptedException
Checks API server health.- Returns:
- true if server is up and healthy
- Throws:
DefensicsRequestException
- if server responds with errorInterruptedException
-
getFailingHealthChecks
public Map<String,HealthCheckResult> getFailingHealthChecks() throws DefensicsRequestException, InterruptedException
Get server health check status and returns unhealthy check results.- Returns:
- Unhealthy check information
- Throws:
DefensicsRequestException
- if health check information could not be fetchedInterruptedException
- If processing was interrupted
-
uploadTestPlan
public void uploadTestPlan(String configurationId, FilePath testplan) throws IOException, DefensicsRequestException, InterruptedException
Upload a testplan file to the API server.- Parameters:
configurationId
- Test configuration idtestplan
- Testplan file- Throws:
IOException
- if there's an issue communicating with the server or reading test plan fileDefensicsRequestException
- if server responds with errorInterruptedException
- if reading test plan file is interrupted
-
setTestConfigurationSettings
public void setTestConfigurationSettings(String runId, String settings) throws DefensicsRequestException, InterruptedException
Sends test configuration settings using CLI format.- Parameters:
runId
- configuration idsettings
- settings using Defensics CLI format- Throws:
DefensicsRequestException
- if server responds with errorInterruptedException
-
startRun
public void startRun(String runId) throws DefensicsRequestException, InterruptedException
Starts testrun using previously created test configuration.- Parameters:
runId
- ID for the started run- Throws:
DefensicsRequestException
- if server responds with errorInterruptedException
-
getRun
public Run getRun(String runId) throws DefensicsRequestException, InterruptedException
Get individual run.- Parameters:
runId
- run id for the run to get- Returns:
- Run object or null if run can't be found
- Throws:
DefensicsRequestException
InterruptedException
-
stopRun
public void stopRun(String runId) throws DefensicsRequestException, InterruptedException
Makes a request to stop the test run. Test run must be running or paused.- Parameters:
runId
- run id- Throws:
DefensicsRequestException
InterruptedException
-
saveResults
public void saveResults(Run run, FilePath reportFolder) throws IOException, DefensicsRequestException, InterruptedException
Downloads the report for this job from Defensics.- Throws:
IOException
- if there's an issue communicating with the server or writing report fileDefensicsRequestException
- if server responds with errorInterruptedException
- if reading test plan file is interrupted
-
saveResultPackage
public void saveResultPackage(FilePath resultFolder, String fileName, Run run) throws IOException, DefensicsRequestException, InterruptedException
Download the result package (zip-file) and saves it to provided result folder.- Throws:
IOException
- if there's an issue communicating with the server or writing report fileDefensicsRequestException
- if server responds with errorInterruptedException
- if FilePath actions fail
-
createNewRun
public Run createNewRun() throws DefensicsRequestException, InterruptedException
Creates new empty Defensics run. This need to be configured by uploading testplan (later on other configuration options can be available).- Returns:
- New Defensics run object
- Throws:
DefensicsRequestException
- if run cannot be created in the Defensics serverInterruptedException
-
getConfigurationSuite
public Optional<SuiteInstance> getConfigurationSuite(String id) throws DefensicsRequestException, InterruptedException
Get suite information for given Defensics run.- Parameters:
id
- Defensics run ID- Returns:
- Suite instance information or empty optional if suite was not found
- Throws:
DefensicsRequestException
- if suite information could not be fetched from Defensics serverInterruptedException
-
deleteRun
public void deleteRun(String runId) throws DefensicsRequestException, InterruptedException
-
getSuiteInformationForRun
public Optional<Suite> getSuiteInformationForRun(Run run)
Get Suite for the given run+suite-instance. Suite contains full suite name and some other information which cannot be found from suite-instance. Note: This eats client errors so refine error handling if suite information is necessary for run to proceed. Now suite is just used to print suite name and version.- Parameters:
run
- Run having assigned suite instance- Returns:
- Suite if found, otherwise empty optional.
-
getServerVersion
public Optional<String> getServerVersion()
Returns API server version as a string, or empty optional if request fails for some reason.- Returns:
- API server version (same as monitorVersion)
-
formatUnhealthyHealthCheckLines
public static String formatUnhealthyHealthCheckLines(Map<String,HealthCheckResult> failingHealthChecks)
Returns formatted multiline string block about unhealthy health checks to be used in warnings.- Parameters:
failingHealthChecks
- Unhealthy health checks- Returns:
- Unhealthy health check(s) information - check name and message. Format is unstable.
-
-