Skip to content

Commit 94e188d

Browse files
mrm9084rossgrambo
andauthored
App Config Spring Provider Variant Object (#46744)
* Adding missing variant code back * Update FeatureFlagClient.java * Update Variant.java * Update FeatureFlagClientTest.java * formatting fixes * Apply suggestions from code review Co-authored-by: Ross Grambo <[email protected]> --------- Co-authored-by: Ross Grambo <[email protected]>
1 parent 4e6d39e commit 94e188d

File tree

5 files changed

+582
-21
lines changed

5 files changed

+582
-21
lines changed

sdk/spring/spring-cloud-azure-appconfiguration-config/src/main/java/com/azure/spring/cloud/appconfiguration/config/implementation/FeatureFlagClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import com.azure.data.appconfiguration.models.FeatureFlagFilter;
3939
import com.azure.data.appconfiguration.models.SettingSelector;
4040
import com.azure.spring.cloud.appconfiguration.config.implementation.feature.FeatureFlags;
41+
import com.azure.spring.cloud.appconfiguration.config.implementation.feature.entity.Allocation;
4142
import com.azure.spring.cloud.appconfiguration.config.implementation.feature.entity.Feature;
4243
import com.azure.spring.cloud.appconfiguration.config.implementation.feature.entity.FeatureTelemetry;
44+
import com.azure.spring.cloud.appconfiguration.config.implementation.feature.entity.Variant;
4345
import com.azure.spring.cloud.appconfiguration.config.implementation.http.policy.FeatureFlagTracing;
4446
import com.fasterxml.jackson.core.JsonProcessingException;
4547
import com.fasterxml.jackson.databind.JsonNode;
@@ -140,6 +142,24 @@ protected static Feature createFeature(FeatureFlagConfigurationSetting item, Str
140142

141143
feature = new Feature(item, requirementType, featureTelemetry);
142144

145+
// Parse variants if present
146+
JsonNode variantsNode = node.get("variants");
147+
if (variantsNode != null && variantsNode.isArray()) {
148+
List<Variant> variants = new ArrayList<>();
149+
for (JsonNode variantNode : variantsNode) {
150+
Variant variant = CASE_INSENSITIVE_MAPPER.convertValue(variantNode, Variant.class);
151+
variants.add(variant);
152+
}
153+
feature.setVariants(variants);
154+
}
155+
156+
// Parse allocation if present
157+
JsonNode allocationNode = node.get("allocation");
158+
if (allocationNode != null && !allocationNode.isNull()) {
159+
Allocation allocation = CASE_INSENSITIVE_MAPPER.convertValue(allocationNode, Allocation.class);
160+
feature.setAllocation(allocation);
161+
}
162+
143163
if (feature.getTelemetry() != null) {
144164
final FeatureTelemetry telemetry = feature.getTelemetry();
145165
if (telemetry.isEnabled()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.spring.cloud.appconfiguration.config.implementation.feature.entity;
4+
5+
import java.util.List;
6+
7+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
/**
11+
* Represents variant allocation settings for a feature flag.
12+
*/
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
public final class Allocation {
15+
16+
@JsonProperty("default_when_disabled")
17+
private String defaultWhenDisabled;
18+
19+
@JsonProperty("default_when_enabled")
20+
private String defaultWhenEnabled;
21+
22+
@JsonProperty("user")
23+
private List<UserAllocation> user;
24+
25+
@JsonProperty("group")
26+
private List<GroupAllocation> group;
27+
28+
@JsonProperty("percentile")
29+
private List<PercentileAllocation> percentile;
30+
31+
@JsonProperty("seed")
32+
private String seed;
33+
34+
/**
35+
* Default constructor.
36+
*/
37+
public Allocation() {
38+
}
39+
40+
/**
41+
* @return the defaultWhenDisabled
42+
*/
43+
public String getDefaultWhenDisabled() {
44+
return defaultWhenDisabled;
45+
}
46+
47+
/**
48+
* @param defaultWhenDisabled the defaultWhenDisabled to set
49+
*/
50+
public void setDefaultWhenDisabled(String defaultWhenDisabled) {
51+
this.defaultWhenDisabled = defaultWhenDisabled;
52+
}
53+
54+
/**
55+
* @return the defaultWhenEnabled
56+
*/
57+
public String getDefaultWhenEnabled() {
58+
return defaultWhenEnabled;
59+
}
60+
61+
/**
62+
* @param defaultWhenEnabled the defaultWhenEnabled to set
63+
*/
64+
public void setDefaultWhenEnabled(String defaultWhenEnabled) {
65+
this.defaultWhenEnabled = defaultWhenEnabled;
66+
}
67+
68+
/**
69+
* @return the user
70+
*/
71+
public List<UserAllocation> getUser() {
72+
return user;
73+
}
74+
75+
/**
76+
* @param user the user to set
77+
*/
78+
public void setUser(List<UserAllocation> user) {
79+
this.user = user;
80+
}
81+
82+
/**
83+
* @return the group
84+
*/
85+
public List<GroupAllocation> getGroup() {
86+
return group;
87+
}
88+
89+
/**
90+
* @param group the group to set
91+
*/
92+
public void setGroup(List<GroupAllocation> group) {
93+
this.group = group;
94+
}
95+
96+
/**
97+
* @return the percentile
98+
*/
99+
public List<PercentileAllocation> getPercentile() {
100+
return percentile;
101+
}
102+
103+
/**
104+
* @param percentile the percentile to set
105+
*/
106+
public void setPercentile(List<PercentileAllocation> percentile) {
107+
this.percentile = percentile;
108+
}
109+
110+
/**
111+
* @return the seed
112+
*/
113+
public String getSeed() {
114+
return seed;
115+
}
116+
117+
/**
118+
* @param seed the seed to set
119+
*/
120+
public void setSeed(String seed) {
121+
this.seed = seed;
122+
}
123+
124+
/**
125+
* Represents user allocation settings.
126+
*/
127+
@JsonIgnoreProperties(ignoreUnknown = true)
128+
public static final class UserAllocation {
129+
130+
@JsonProperty("variant")
131+
private String variant;
132+
133+
@JsonProperty("users")
134+
private List<String> users;
135+
136+
/**
137+
* Default constructor.
138+
*/
139+
public UserAllocation() {
140+
}
141+
142+
/**
143+
* @return the variant
144+
*/
145+
public String getVariant() {
146+
return variant;
147+
}
148+
149+
/**
150+
* @param variant the variant to set
151+
*/
152+
public void setVariant(String variant) {
153+
this.variant = variant;
154+
}
155+
156+
/**
157+
* @return the users
158+
*/
159+
public List<String> getUsers() {
160+
return users;
161+
}
162+
163+
/**
164+
* @param users the users to set
165+
*/
166+
public void setUsers(List<String> users) {
167+
this.users = users;
168+
}
169+
}
170+
171+
/**
172+
* Represents group allocation settings.
173+
*/
174+
@JsonIgnoreProperties(ignoreUnknown = true)
175+
public static final class GroupAllocation {
176+
177+
@JsonProperty("variant")
178+
private String variant;
179+
180+
@JsonProperty("groups")
181+
private List<String> groups;
182+
183+
/**
184+
* Default constructor.
185+
*/
186+
public GroupAllocation() {
187+
}
188+
189+
/**
190+
* @return the variant
191+
*/
192+
public String getVariant() {
193+
return variant;
194+
}
195+
196+
/**
197+
* @param variant the variant to set
198+
*/
199+
public void setVariant(String variant) {
200+
this.variant = variant;
201+
}
202+
203+
/**
204+
* @return the groups
205+
*/
206+
public List<String> getGroups() {
207+
return groups;
208+
}
209+
210+
/**
211+
* @param groups the groups to set
212+
*/
213+
public void setGroups(List<String> groups) {
214+
this.groups = groups;
215+
}
216+
}
217+
218+
/**
219+
* Represents percentile allocation settings.
220+
*/
221+
@JsonIgnoreProperties(ignoreUnknown = true)
222+
public static final class PercentileAllocation {
223+
224+
@JsonProperty("variant")
225+
private String variant;
226+
227+
@JsonProperty("from")
228+
private Double from;
229+
230+
@JsonProperty("to")
231+
private Double to;
232+
233+
/**
234+
* Default constructor.
235+
*/
236+
public PercentileAllocation() {
237+
}
238+
239+
/**
240+
* @return the variant
241+
*/
242+
public String getVariant() {
243+
return variant;
244+
}
245+
246+
/**
247+
* @param variant the variant to set
248+
*/
249+
public void setVariant(String variant) {
250+
this.variant = variant;
251+
}
252+
253+
/**
254+
* @return the from
255+
*/
256+
public Double getFrom() {
257+
return from;
258+
}
259+
260+
/**
261+
* @param from the from to set
262+
*/
263+
public void setFrom(Double from) {
264+
this.from = from;
265+
}
266+
267+
/**
268+
* @return the to
269+
*/
270+
public Double getTo() {
271+
return to;
272+
}
273+
274+
/**
275+
* @param to the to to set
276+
*/
277+
public void setTo(Double to) {
278+
this.to = to;
279+
}
280+
}
281+
}

sdk/spring/spring-cloud-azure-appconfiguration-config/src/main/java/com/azure/spring/cloud/appconfiguration/config/implementation/feature/entity/Feature.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT License.
33
package com.azure.spring.cloud.appconfiguration.config.implementation.feature.entity;
44

5+
import java.util.List;
6+
57
import com.azure.data.appconfiguration.models.FeatureFlagConfigurationSetting;
68
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
79
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -24,6 +26,12 @@ public final class Feature {
2426
@JsonProperty("conditions")
2527
private Conditions conditions;
2628

29+
@JsonProperty("variants")
30+
private List<Variant> variants;
31+
32+
@JsonProperty("allocation")
33+
private Allocation allocation;
34+
2735
@JsonProperty("telemetry")
2836
private FeatureTelemetry telemetry;
2937

@@ -105,6 +113,34 @@ public void setConditions(Conditions conditions) {
105113
this.conditions = conditions;
106114
}
107115

116+
/**
117+
* @return the variants
118+
*/
119+
public List<Variant> getVariants() {
120+
return variants;
121+
}
122+
123+
/**
124+
* @param variants the variants to set
125+
*/
126+
public void setVariants(List<Variant> variants) {
127+
this.variants = variants;
128+
}
129+
130+
/**
131+
* @return the allocation
132+
*/
133+
public Allocation getAllocation() {
134+
return allocation;
135+
}
136+
137+
/**
138+
* @param allocation the allocation to set
139+
*/
140+
public void setAllocation(Allocation allocation) {
141+
this.allocation = allocation;
142+
}
143+
108144
/**
109145
* @return the telemetry
110146
*/

0 commit comments

Comments
 (0)