-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateAllocationsForFeatureFlagInEnvironment_3662093014.java
More file actions
74 lines (68 loc) · 3.16 KB
/
CreateAllocationsForFeatureFlagInEnvironment_3662093014.java
File metadata and controls
74 lines (68 loc) · 3.16 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
// Create allocation for a flag in an environment returns "Created" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.FeatureFlagsApi;
import com.datadog.api.client.v2.model.AllocationDataRequest;
import com.datadog.api.client.v2.model.AllocationDataType;
import com.datadog.api.client.v2.model.AllocationResponse;
import com.datadog.api.client.v2.model.AllocationType;
import com.datadog.api.client.v2.model.CreateAllocationsRequest;
import com.datadog.api.client.v2.model.UpsertAllocationRequest;
import com.datadog.api.client.v2.model.VariantWeightRequest;
import java.util.Collections;
import java.util.UUID;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
FeatureFlagsApi apiInstance = new FeatureFlagsApi(defaultClient);
// there is a valid "feature_flag" in the system
UUID FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID = null;
try {
FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID =
UUID.fromString(System.getenv("FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID"));
} catch (IllegalArgumentException e) {
System.err.println("Error parsing UUID: " + e.getMessage());
}
UUID FEATURE_FLAG_DATA_ID = null;
try {
FEATURE_FLAG_DATA_ID = UUID.fromString(System.getenv("FEATURE_FLAG_DATA_ID"));
} catch (IllegalArgumentException e) {
System.err.println("Error parsing UUID: " + e.getMessage());
}
// there is a valid "environment" in the system
UUID ENVIRONMENT_DATA_ID = null;
try {
ENVIRONMENT_DATA_ID = UUID.fromString(System.getenv("ENVIRONMENT_DATA_ID"));
} catch (IllegalArgumentException e) {
System.err.println("Error parsing UUID: " + e.getMessage());
}
CreateAllocationsRequest body =
new CreateAllocationsRequest()
.data(
new AllocationDataRequest()
.type(AllocationDataType.ALLOCATIONS)
.attributes(
new UpsertAllocationRequest()
.name("New targeting rule Example-Feature-Flag")
.key("new-targeting-rule-example-feature-flag")
.variantWeights(
Collections.singletonList(
new VariantWeightRequest()
.variantId(FEATURE_FLAG_DATA_ATTRIBUTES_VARIANTS_0_ID)
.value(100.0)))
.type(AllocationType.CANARY)));
try {
AllocationResponse result =
apiInstance.createAllocationsForFeatureFlagInEnvironment(
FEATURE_FLAG_DATA_ID, ENVIRONMENT_DATA_ID, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println(
"Exception when calling FeatureFlagsApi#createAllocationsForFeatureFlagInEnvironment");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}