-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateMaintenance_2202276054.java
More file actions
75 lines (71 loc) · 3.75 KB
/
CreateMaintenance_2202276054.java
File metadata and controls
75 lines (71 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Create maintenance returns "Created" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.StatusPagesApi;
import com.datadog.api.client.v2.model.CreateMaintenanceRequest;
import com.datadog.api.client.v2.model.CreateMaintenanceRequestData;
import com.datadog.api.client.v2.model.CreateMaintenanceRequestDataAttributes;
import com.datadog.api.client.v2.model.CreateMaintenanceRequestDataAttributesComponentsAffectedItems;
import com.datadog.api.client.v2.model.Maintenance;
import com.datadog.api.client.v2.model.PatchMaintenanceRequestDataAttributesComponentsAffectedItemsStatus;
import com.datadog.api.client.v2.model.PatchMaintenanceRequestDataType;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.UUID;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
StatusPagesApi apiInstance = new StatusPagesApi(defaultClient);
// there is a valid "status_page" in the system
UUID STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID = null;
try {
STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID =
UUID.fromString(
System.getenv("STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID"));
} catch (IllegalArgumentException e) {
System.err.println("Error parsing UUID: " + e.getMessage());
}
UUID STATUS_PAGE_DATA_ID = null;
try {
STATUS_PAGE_DATA_ID = UUID.fromString(System.getenv("STATUS_PAGE_DATA_ID"));
} catch (IllegalArgumentException e) {
System.err.println("Error parsing UUID: " + e.getMessage());
}
CreateMaintenanceRequest body =
new CreateMaintenanceRequest()
.data(
new CreateMaintenanceRequestData()
.attributes(
new CreateMaintenanceRequestDataAttributes()
.title("API Maintenance")
.scheduledDescription(
"We will be performing maintenance on the API to improve"
+ " performance.")
.inProgressDescription(
"We are currently performing maintenance on the API to improve"
+ " performance.")
.completedDescription(
"We have completed maintenance on the API to improve performance.")
.startDate(OffsetDateTime.now().plusHours(1))
.completedDate(OffsetDateTime.now().plusHours(2))
.componentsAffected(
Collections.singletonList(
new CreateMaintenanceRequestDataAttributesComponentsAffectedItems()
.id(
STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID)
.status(
PatchMaintenanceRequestDataAttributesComponentsAffectedItemsStatus
.OPERATIONAL))))
.type(PatchMaintenanceRequestDataType.MAINTENANCES));
try {
Maintenance result = apiInstance.createMaintenance(STATUS_PAGE_DATA_ID, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling StatusPagesApi#createMaintenance");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}