|
1 | 1 | package io.split.engine.evaluator; |
2 | 2 |
|
3 | 3 | import io.split.client.dtos.ConditionType; |
| 4 | +import io.split.client.dtos.FallbackTreatment; |
| 5 | +import io.split.client.dtos.FallbackTreatmentCalculator; |
4 | 6 | import io.split.client.dtos.FallbackTreatmentsConfiguration; |
5 | 7 | import io.split.client.exceptions.ChangeNumberExceptionWrapper; |
6 | 8 | import io.split.engine.experiments.ParsedCondition; |
|
20 | 22 | import java.util.Map; |
21 | 23 |
|
22 | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
23 | | -import static io.split.client.utils.Utils.checkFallbackTreatments; |
24 | 25 |
|
25 | 26 | public class EvaluatorImp implements Evaluator { |
26 | 27 | private static final Logger _log = LoggerFactory.getLogger(EvaluatorImp.class); |
27 | 28 |
|
28 | 29 | private final SegmentCacheConsumer _segmentCacheConsumer; |
29 | 30 | private final EvaluationContext _evaluationContext; |
30 | 31 | private final SplitCacheConsumer _splitCacheConsumer; |
31 | | - private final FallbackTreatmentsConfiguration _fallbackTreatmentsConfiguration; |
| 32 | + private final FallbackTreatmentCalculator _fallbackTreatmentCalculator; |
32 | 33 |
|
33 | 34 | public EvaluatorImp(SplitCacheConsumer splitCacheConsumer, SegmentCacheConsumer segmentCache, |
34 | 35 | RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer, |
35 | | - FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration) { |
| 36 | + FallbackTreatmentCalculator fallbackTreatmentCalculator) { |
36 | 37 | _splitCacheConsumer = checkNotNull(splitCacheConsumer); |
37 | 38 | _segmentCacheConsumer = checkNotNull(segmentCache); |
38 | 39 | _evaluationContext = new EvaluationContext(this, _segmentCacheConsumer, ruleBasedSegmentCacheConsumer); |
39 | | - _fallbackTreatmentsConfiguration = fallbackTreatmentsConfiguration; |
| 40 | + _fallbackTreatmentCalculator = fallbackTreatmentCalculator; |
40 | 41 | } |
41 | 42 |
|
42 | 43 | @Override |
@@ -179,16 +180,20 @@ private String getConfig(ParsedSplit parsedSplit, String returnedTreatment) { |
179 | 180 | private TreatmentLabelAndChangeNumber evaluateParsedSplit(String matchingKey, String bucketingKey, Map<String, Object> attributes, |
180 | 181 | ParsedSplit parsedSplit, String featureName) { |
181 | 182 | try { |
| 183 | + |
182 | 184 | if (parsedSplit == null) { |
183 | | - return checkFallbackTreatments(Treatments.CONTROL, Labels.DEFINITION_NOT_FOUND, featureName, null, _fallbackTreatmentsConfiguration); |
| 185 | + FallbackTreatment fallbackTreatment = _fallbackTreatmentCalculator.resolve(featureName, Labels.DEFINITION_NOT_FOUND); |
| 186 | + return new TreatmentLabelAndChangeNumber(fallbackTreatment.getTreatment(), fallbackTreatment.getLabel()); |
184 | 187 | } |
185 | 188 | return getTreatment(matchingKey, bucketingKey, parsedSplit, attributes); |
186 | 189 | } catch (ChangeNumberExceptionWrapper e) { |
187 | 190 | _log.error("Evaluator Exception", e.wrappedException()); |
188 | | - return checkFallbackTreatments(Treatments.CONTROL, Labels.EXCEPTION, featureName, e.changeNumber(), _fallbackTreatmentsConfiguration); |
| 191 | + FallbackTreatment fallbackTreatment = _fallbackTreatmentCalculator.resolve(featureName, Labels.EXCEPTION); |
| 192 | + return new TreatmentLabelAndChangeNumber(fallbackTreatment.getTreatment(), fallbackTreatment.getLabel(), e.changeNumber()); |
189 | 193 | } catch (Exception e) { |
190 | 194 | _log.error("Evaluator Exception", e); |
191 | | - return checkFallbackTreatments(Treatments.CONTROL, Labels.EXCEPTION, featureName, null, _fallbackTreatmentsConfiguration); |
| 195 | + FallbackTreatment fallbackTreatment = _fallbackTreatmentCalculator.resolve(featureName, Labels.EXCEPTION); |
| 196 | + return new TreatmentLabelAndChangeNumber(fallbackTreatment.getTreatment(), fallbackTreatment.getLabel()); |
192 | 197 | } |
193 | 198 | } |
194 | 199 |
|
|
0 commit comments