@@ -86,8 +86,8 @@ private List<String> getFeatureFlagNamesByFlagSets(List<String> flagSets) {
8686 private TreatmentLabelAndChangeNumber getTreatment (String matchingKey , String bucketingKey , ParsedSplit parsedSplit , Map <String ,
8787 Object > attributes ) throws ChangeNumberExceptionWrapper {
8888 try {
89+ String config = getConfig (parsedSplit , parsedSplit .defaultTreatment ());
8990 if (parsedSplit .killed ()) {
90- String config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
9191 return new TreatmentLabelAndChangeNumber (
9292 parsedSplit .defaultTreatment (),
9393 Labels .KILLED ,
@@ -96,6 +96,17 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
9696 parsedSplit .impressionsDisabled ());
9797 }
9898
99+ String bk = getBucketingKey (bucketingKey , matchingKey );
100+
101+ if (!parsedSplit .prerequisitesMatcher ().match (matchingKey , bk , attributes , _evaluationContext )) {
102+ return new TreatmentLabelAndChangeNumber (
103+ parsedSplit .defaultTreatment (),
104+ Labels .PREREQUISITES_NOT_MET ,
105+ parsedSplit .changeNumber (),
106+ config ,
107+ parsedSplit .impressionsDisabled ());
108+ }
109+
99110 /*
100111 * There are three parts to a single Feature flag: 1) Whitelists 2) Traffic Allocation
101112 * 3) Rollout. The flag inRollout is there to understand when we move into the Rollout
@@ -104,20 +115,17 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
104115 */
105116 boolean inRollout = false ;
106117
107- String bk = (bucketingKey == null ) ? matchingKey : bucketingKey ;
108-
109118 for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
110119
111- if (! inRollout && parsedCondition . conditionType () == ConditionType . ROLLOUT ) {
120+ if (checkRollout ( inRollout , parsedCondition ) ) {
112121
113122 if (parsedSplit .trafficAllocation () < 100 ) {
114123 // if the traffic allocation is 100%, no need to do anything special.
115124 int bucket = Splitter .getBucket (bk , parsedSplit .trafficAllocationSeed (), parsedSplit .algo ());
116125
117126 if (bucket > parsedSplit .trafficAllocation ()) {
118127 // out of split
119- String config = parsedSplit .configurations () != null ?
120- parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
128+ config = getConfig (parsedSplit , parsedSplit .defaultTreatment ());
121129 return new TreatmentLabelAndChangeNumber (parsedSplit .defaultTreatment (), Labels .NOT_IN_SPLIT ,
122130 parsedSplit .changeNumber (), config , parsedSplit .impressionsDisabled ());
123131 }
@@ -128,7 +136,7 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
128136
129137 if (parsedCondition .matcher ().match (matchingKey , bucketingKey , attributes , _evaluationContext )) {
130138 String treatment = Splitter .getTreatment (bk , parsedSplit .seed (), parsedCondition .partitions (), parsedSplit .algo ());
131- String config = parsedSplit . configurations () != null ? parsedSplit . configurations (). get ( treatment ) : null ;
139+ config = getConfig ( parsedSplit , treatment );
132140 return new TreatmentLabelAndChangeNumber (
133141 treatment ,
134142 parsedCondition .label (),
@@ -138,7 +146,8 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
138146 }
139147 }
140148
141- String config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
149+ config = getConfig (parsedSplit , parsedSplit .defaultTreatment ());
150+
142151 return new TreatmentLabelAndChangeNumber (
143152 parsedSplit .defaultTreatment (),
144153 Labels .DEFAULT_RULE ,
@@ -150,13 +159,24 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
150159 }
151160 }
152161
162+ private boolean checkRollout (boolean inRollout , ParsedCondition parsedCondition ) {
163+ return (!inRollout && parsedCondition .conditionType () == ConditionType .ROLLOUT );
164+ }
165+
166+ private String getBucketingKey (String bucketingKey , String matchingKey ) {
167+ return (bucketingKey == null ) ? matchingKey : bucketingKey ;
168+ }
169+
170+ private String getConfig (ParsedSplit parsedSplit , String returnedTreatment ) {
171+ return parsedSplit .configurations () != null ? parsedSplit .configurations ().get (returnedTreatment ) : null ;
172+ }
173+
153174 private TreatmentLabelAndChangeNumber evaluateParsedSplit (String matchingKey , String bucketingKey , Map <String , Object > attributes ,
154175 ParsedSplit parsedSplit ) {
155176 try {
156177 if (parsedSplit == null ) {
157178 return new TreatmentLabelAndChangeNumber (Treatments .CONTROL , Labels .DEFINITION_NOT_FOUND );
158179 }
159-
160180 return getTreatment (matchingKey , bucketingKey , parsedSplit , attributes );
161181 } catch (ChangeNumberExceptionWrapper e ) {
162182 _log .error ("Evaluator Exception" , e .wrappedException ());
0 commit comments