This library provides an easy to use Java implementation of Dynatrace Server REST API.
Library is available in maven central repository (starting with version 7.0.0; for previous versions see the Releases page).
- Add the following code to the <dependencies> section:
<dependency>
<groupId>com.dynatrace.sdk</groupId>
<artifactId>server-rest-sdk</artifactId>
<version>LATEST_VERSION</version>
</dependency>
- Put the following code in your dependencies block:
compile 'com.dynatrace.sdk:server-rest-sdk:LATEST_VERSION'
The SDK is divided into small modules called services
. Each service
corresponds to the appropriate Rest API endpoint. Documentation of Rest API endpoints can be found on your local Dynatrace Server: https://DTSERVER:8021/api-docs/current/.
General documentation for Server Rest interfaces is available here.
The SDK currently supports a small part of the available interfaces, therefore Pull Requests are highly appreciated.
Each service
takes a DynatraceClient as the only parameter in the constructor.
The DynatraceClient holds the Apache HTTPClient under the hood and therefore it is recommended to pass thesame DynatraceClient to all services
to avoid multiple client creation.
The DynatraceClient can be constructed using two constructors:
public DynatraceClient(ServerConfiguration configuration) {
//...
}
public DynatraceClient(ServerConfiguration configuration, CloseableHttpClient httpClient) {
//...
}
You most likely want to use the first one.
ServerConfiguration is an interface which has a basic implementation: BasicServerConfiguration
The most basic use-case would be to create a DynatraceClient the following way:
DynatraceClient client = new DynatraceClient(new BasicServerConfiguration("username","password"));
You may want to take a look at BasicServerConfiguration source-code for a list and documentation of other constructors.
import com.dynatrace.sdk.server.testautomation.TestAutomation;
//...
TestAutomation automation = new TestAutomation(DynatraceClient);
import com.dynatrace.sdk.server.sessions.Sessions
//...
Sessions sessions = new Sessions(DynatraceClient);
import com.dynatrace.sdk.server.systemprofiles.SystemProfiles
//...
SystemProfiles systemProfiles = new SystemProfiles(DynatraceClient);
import com.dynatrace.sdk.server.servermanagement.ServerManagement
//...
ServerManagement serverManagement = new ServerManagement(DynatraceClient);
In order to build the library, one must execute mvn clean install
or mvn clean package
.
The SDK comes with some unit tests, to run them, execute the following command:
mvn clean test