|
| 1 | +// Create backfilled degradation returns "Created" response |
| 2 | +import com.datadog.api.client.ApiClient; |
| 3 | +import com.datadog.api.client.ApiException; |
| 4 | +import com.datadog.api.client.v2.api.StatusPagesApi; |
| 5 | +import com.datadog.api.client.v2.model.CreateBackfilledDegradationRequest; |
| 6 | +import com.datadog.api.client.v2.model.CreateBackfilledDegradationRequestData; |
| 7 | +import com.datadog.api.client.v2.model.CreateBackfilledDegradationRequestDataAttributes; |
| 8 | +import com.datadog.api.client.v2.model.CreateBackfilledDegradationRequestDataAttributesUpdatesItems; |
| 9 | +import com.datadog.api.client.v2.model.CreateDegradationRequestDataAttributesComponentsAffectedItems; |
| 10 | +import com.datadog.api.client.v2.model.CreateDegradationRequestDataAttributesStatus; |
| 11 | +import com.datadog.api.client.v2.model.Degradation; |
| 12 | +import com.datadog.api.client.v2.model.PatchDegradationRequestDataType; |
| 13 | +import com.datadog.api.client.v2.model.StatusPagesComponentDataAttributesStatus; |
| 14 | +import java.time.OffsetDateTime; |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.Collections; |
| 17 | +import java.util.UUID; |
| 18 | + |
| 19 | +public class Example { |
| 20 | + public static void main(String[] args) { |
| 21 | + ApiClient defaultClient = ApiClient.getDefaultApiClient(); |
| 22 | + StatusPagesApi apiInstance = new StatusPagesApi(defaultClient); |
| 23 | + |
| 24 | + // there is a valid "status_page" in the system |
| 25 | + UUID STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID = null; |
| 26 | + try { |
| 27 | + STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID = |
| 28 | + UUID.fromString( |
| 29 | + System.getenv("STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID")); |
| 30 | + } catch (IllegalArgumentException e) { |
| 31 | + System.err.println("Error parsing UUID: " + e.getMessage()); |
| 32 | + } |
| 33 | + UUID STATUS_PAGE_DATA_ID = null; |
| 34 | + try { |
| 35 | + STATUS_PAGE_DATA_ID = UUID.fromString(System.getenv("STATUS_PAGE_DATA_ID")); |
| 36 | + } catch (IllegalArgumentException e) { |
| 37 | + System.err.println("Error parsing UUID: " + e.getMessage()); |
| 38 | + } |
| 39 | + |
| 40 | + CreateBackfilledDegradationRequest body = |
| 41 | + new CreateBackfilledDegradationRequest() |
| 42 | + .data( |
| 43 | + new CreateBackfilledDegradationRequestData() |
| 44 | + .attributes( |
| 45 | + new CreateBackfilledDegradationRequestDataAttributes() |
| 46 | + .title("Past API Outage") |
| 47 | + .updates( |
| 48 | + Arrays.asList( |
| 49 | + new CreateBackfilledDegradationRequestDataAttributesUpdatesItems() |
| 50 | + .componentsAffected( |
| 51 | + Collections.singletonList( |
| 52 | + new CreateDegradationRequestDataAttributesComponentsAffectedItems() |
| 53 | + .id( |
| 54 | + STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID) |
| 55 | + .status( |
| 56 | + StatusPagesComponentDataAttributesStatus |
| 57 | + .DEGRADED))) |
| 58 | + .description("We detected elevated error rates in the API.") |
| 59 | + .startedAt(OffsetDateTime.now().plusHours(-1)) |
| 60 | + .status( |
| 61 | + CreateDegradationRequestDataAttributesStatus |
| 62 | + .INVESTIGATING), |
| 63 | + new CreateBackfilledDegradationRequestDataAttributesUpdatesItems() |
| 64 | + .componentsAffected( |
| 65 | + Collections.singletonList( |
| 66 | + new CreateDegradationRequestDataAttributesComponentsAffectedItems() |
| 67 | + .id( |
| 68 | + STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID) |
| 69 | + .status( |
| 70 | + StatusPagesComponentDataAttributesStatus |
| 71 | + .DEGRADED))) |
| 72 | + .description( |
| 73 | + "Root cause identified as a misconfigured deployment.") |
| 74 | + .startedAt(OffsetDateTime.now().plusMinutes(-30)) |
| 75 | + .status( |
| 76 | + CreateDegradationRequestDataAttributesStatus |
| 77 | + .IDENTIFIED), |
| 78 | + new CreateBackfilledDegradationRequestDataAttributesUpdatesItems() |
| 79 | + .componentsAffected( |
| 80 | + Collections.singletonList( |
| 81 | + new CreateDegradationRequestDataAttributesComponentsAffectedItems() |
| 82 | + .id( |
| 83 | + STATUS_PAGE_DATA_ATTRIBUTES_COMPONENTS_0_COMPONENTS_0_ID) |
| 84 | + .status( |
| 85 | + StatusPagesComponentDataAttributesStatus |
| 86 | + .OPERATIONAL))) |
| 87 | + .description( |
| 88 | + "The issue has been resolved and API is operating" |
| 89 | + + " normally.") |
| 90 | + .startedAt(OffsetDateTime.now()) |
| 91 | + .status( |
| 92 | + CreateDegradationRequestDataAttributesStatus |
| 93 | + .RESOLVED)))) |
| 94 | + .type(PatchDegradationRequestDataType.DEGRADATIONS)); |
| 95 | + |
| 96 | + try { |
| 97 | + Degradation result = apiInstance.createBackfilledDegradation(STATUS_PAGE_DATA_ID, body); |
| 98 | + System.out.println(result); |
| 99 | + } catch (ApiException e) { |
| 100 | + System.err.println("Exception when calling StatusPagesApi#createBackfilledDegradation"); |
| 101 | + System.err.println("Status code: " + e.getCode()); |
| 102 | + System.err.println("Reason: " + e.getResponseBody()); |
| 103 | + System.err.println("Response headers: " + e.getResponseHeaders()); |
| 104 | + e.printStackTrace(); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments