@@ -30,7 +30,7 @@ private LocalhostSanitizer() {
30
30
}
31
31
32
32
public static SplitChange sanitization (SplitChange splitChange ) {
33
- splitChange = sanitizeTillAndSince (splitChange );
33
+ sanitizeTillAndSince (splitChange );
34
34
splitChange .featureFlags .d = sanitizeFeatureFlags (splitChange .featureFlags .d );
35
35
splitChange .ruleBasedSegments .d = sanitizeRuleBasedSegments (splitChange .ruleBasedSegments .d );
36
36
@@ -62,7 +62,6 @@ private static List<RuleBasedSegment> sanitizeRuleBasedSegments(List<RuleBasedSe
62
62
63
63
private static List <Split > sanitizeFeatureFlags (List <Split > featureFlags ) {
64
64
List <Split > splitsToRemove = new ArrayList <>();
65
- SecureRandom random = new SecureRandom ();
66
65
if (featureFlags != null ) {
67
66
for (Split split : featureFlags ) {
68
67
if (split .name == null ) {
@@ -73,19 +72,10 @@ private static List<Split> sanitizeFeatureFlags(List<Split> featureFlags) {
73
72
split .status = sanitizeStatus (split .status );
74
73
split .defaultTreatment = sanitizeIfNullOrEmpty (split .defaultTreatment , LocalhostConstants .CONTROL );
75
74
split .changeNumber = sanitizeChangeNumber (split .changeNumber , 0 );
76
-
77
- if (split .trafficAllocation == null || split .trafficAllocation < 0 || split .trafficAllocation > LocalhostConstants .SIZE_100 ) {
78
- split .trafficAllocation = LocalhostConstants .SIZE_100 ;
79
- }
80
- if (split .trafficAllocationSeed == null || split .trafficAllocationSeed == 0 ) {
81
- split .trafficAllocationSeed = -random .nextInt (10 ) * LocalhostConstants .MILLI_SECONDS ;
82
- }
83
- if (split .seed == 0 ) {
84
- split .seed = -random .nextInt (10 ) * LocalhostConstants .MILLI_SECONDS ;
85
- }
86
- if (split .algo != LocalhostConstants .ALGO ) {
87
- split .algo = LocalhostConstants .ALGO ;
88
- }
75
+ split .trafficAllocation = sanitizeTrafficAllocation (split .trafficAllocation );
76
+ split .trafficAllocationSeed = sanitizeSeed (split .trafficAllocationSeed );
77
+ split .seed = sanitizeSeed (split .seed );
78
+ split .algo = sanitizeAlgo (split .algo );
89
79
split .conditions = sanitizeConditions ((ArrayList <Condition >) split .conditions , false , split .trafficTypeName );
90
80
}
91
81
featureFlags .removeAll (splitsToRemove );
@@ -95,6 +85,28 @@ private static List<Split> sanitizeFeatureFlags(List<Split> featureFlags) {
95
85
return featureFlags ;
96
86
}
97
87
88
+ private static int sanitizeSeed (Integer seed ) {
89
+ SecureRandom random = new SecureRandom ();
90
+ if (seed == null || seed == 0 ) {
91
+ seed = -random .nextInt (10 ) * LocalhostConstants .MILLI_SECONDS ;
92
+ }
93
+ return seed ;
94
+ }
95
+
96
+ private static int sanitizeAlgo (int algo ) {
97
+ if (algo != LocalhostConstants .ALGO ) {
98
+ algo = LocalhostConstants .ALGO ;
99
+ }
100
+ return algo ;
101
+ }
102
+
103
+ private static int sanitizeTrafficAllocation (Integer trafficAllocation ) {
104
+ if (trafficAllocation == null || trafficAllocation < 0 || trafficAllocation > LocalhostConstants .SIZE_100 ) {
105
+ trafficAllocation = LocalhostConstants .SIZE_100 ;
106
+ }
107
+ return trafficAllocation ;
108
+ }
109
+
98
110
private static ArrayList <Condition > sanitizeConditions (ArrayList <Condition > conditions , boolean createPartition , String trafficTypeName ) {
99
111
if (conditions == null ) {
100
112
conditions = new ArrayList <>();
@@ -114,18 +126,18 @@ private static ArrayList<Condition> sanitizeConditions(ArrayList<Condition> cond
114
126
}
115
127
return conditions ;
116
128
}
117
- private static String sanitizeIfNullOrEmpty (String toBeSantitized , String defaultValue ) {
118
- if (toBeSantitized == null || toBeSantitized .isEmpty ()) {
129
+ private static String sanitizeIfNullOrEmpty (String toBeSanitized , String defaultValue ) {
130
+ if (toBeSanitized == null || toBeSanitized .isEmpty ()) {
119
131
return defaultValue ;
120
132
}
121
- return toBeSantitized ;
133
+ return toBeSanitized ;
122
134
}
123
135
124
- private static long sanitizeChangeNumber (long toBeSantitized , long defaultValue ) {
125
- if (toBeSantitized < 0 ) {
136
+ private static long sanitizeChangeNumber (long toBeSanitized , long defaultValue ) {
137
+ if (toBeSanitized < 0 ) {
126
138
return defaultValue ;
127
139
}
128
- return toBeSantitized ;
140
+ return toBeSanitized ;
129
141
}
130
142
131
143
private static Status sanitizeStatus (Status toBeSanitized ) {
0 commit comments