11"""Splits module."""
22from enum import Enum
33from collections import namedtuple
4+ import logging
45
6+ from splitio .models import MatcherNotFoundException
57from splitio .models .grammar import condition
68
9+ _LOGGER = logging .getLogger (__name__ )
710
811SplitView = namedtuple (
912 'SplitView' ,
1013 ['name' , 'traffic_type' , 'killed' , 'treatments' , 'change_number' , 'configs' , 'default_treatment' , 'sets' ]
1114)
1215
16+ _DEFAULT_CONDITIONS_TEMPLATE = {
17+ "conditionType" : "ROLLOUT" ,
18+ "matcherGroup" : {
19+ "combiner" : "AND" ,
20+ "matchers" : [
21+ {
22+ "keySelector" : None ,
23+ "matcherType" : "ALL_KEYS" ,
24+ "negate" : False ,
25+ "userDefinedSegmentMatcherData" : None ,
26+ "whitelistMatcherData" : None ,
27+ "unaryNumericMatcherData" : None ,
28+ "betweenMatcherData" : None ,
29+ "dependencyMatcherData" : None ,
30+ "booleanMatcherData" : None ,
31+ "stringMatcherData" : None
32+ }]
33+ },
34+ "partitions" : [
35+ {
36+ "treatment" : "control" ,
37+ "size" : 100
38+ }
39+ ],
40+ "label" : "unsupported matcher type"
41+ }
42+
43+
1344
1445class Status (Enum ):
1546 """Split status."""
@@ -238,6 +269,27 @@ def from_raw(raw_split):
238269 :return: A parsed Split object capable of performing evaluations.
239270 :rtype: Split
240271 """
272+ try :
273+ return Split (
274+ raw_split ['name' ],
275+ raw_split ['seed' ],
276+ raw_split ['killed' ],
277+ raw_split ['defaultTreatment' ],
278+ raw_split ['trafficTypeName' ],
279+ raw_split ['status' ],
280+ raw_split ['changeNumber' ],
281+ [condition .from_raw (c ) for c in raw_split ['conditions' ]],
282+ raw_split .get ('algo' ),
283+ traffic_allocation = raw_split .get ('trafficAllocation' ),
284+ traffic_allocation_seed = raw_split .get ('trafficAllocationSeed' ),
285+ configurations = raw_split .get ('configurations' ),
286+ sets = set (raw_split .get ('sets' )) if raw_split .get ('sets' ) is not None else []
287+ )
288+ except MatcherNotFoundException as e :
289+ _LOGGER .error (str (e ))
290+ pass
291+
292+ _LOGGER .debug ("Using default conditions template for feature flag: %s" , raw_split ['name' ])
241293 return Split (
242294 raw_split ['name' ],
243295 raw_split ['seed' ],
@@ -246,7 +298,7 @@ def from_raw(raw_split):
246298 raw_split ['trafficTypeName' ],
247299 raw_split ['status' ],
248300 raw_split ['changeNumber' ],
249- [condition .from_raw (c ) for c in raw_split [ 'conditions' ] ],
301+ [condition .from_raw (_DEFAULT_CONDITIONS_TEMPLATE ) ],
250302 raw_split .get ('algo' ),
251303 traffic_allocation = raw_split .get ('trafficAllocation' ),
252304 traffic_allocation_seed = raw_split .get ('trafficAllocationSeed' ),
0 commit comments