-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateCustomAllocationRule.java
More file actions
73 lines (69 loc) · 4 KB
/
CreateCustomAllocationRule.java
File metadata and controls
73 lines (69 loc) · 4 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
// Create custom allocation rule returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CloudCostManagementApi;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequest;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestData;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributes;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributesStrategy;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems;
import com.datadog.api.client.v2.model.ArbitraryCostUpsertRequestDataType;
import com.datadog.api.client.v2.model.ArbitraryRuleResponse;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
CloudCostManagementApi apiInstance = new CloudCostManagementApi(defaultClient);
ArbitraryCostUpsertRequest body =
new ArbitraryCostUpsertRequest()
.data(
new ArbitraryCostUpsertRequestData()
.attributes(
new ArbitraryCostUpsertRequestDataAttributes()
.costsToAllocate(
Arrays.asList(
new ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems()
.condition("is")
.tag("account_id")
.value("123456789"),
new ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems()
.condition("in")
.tag("environment")
.value("")
.values(Arrays.asList("production", "staging"))))
.enabled(true)
.orderId(1L)
.provider(Arrays.asList("aws", "gcp"))
.ruleName("example-arbitrary-cost-rule")
.strategy(
new ArbitraryCostUpsertRequestDataAttributesStrategy()
.allocatedByTagKeys(Arrays.asList("team", "environment"))
.basedOnCosts(
Arrays.asList(
new ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems()
.condition("is")
.tag("service")
.value("web-api"),
new ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems()
.condition("not in")
.tag("team")
.value("")
.values(Arrays.asList("legacy", "deprecated"))))
.granularity("daily")
.method("proportional"))
.type("shared"))
.type(ArbitraryCostUpsertRequestDataType.UPSERT_ARBITRARY_RULE));
try {
ArbitraryRuleResponse result = apiInstance.createCustomAllocationRule(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println(
"Exception when calling CloudCostManagementApi#createCustomAllocationRule");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}