Skip to content

Commit 044e412

Browse files
authored
Name the step selection criteria after what they do: starts_with, contains, ends_with (#239)
1 parent 7250c66 commit 044e412

12 files changed

Lines changed: 66 additions & 65 deletions

File tree

maestro-common/src/main/java/com/netflix/maestro/models/instance/StepSelector.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
3636
@JsonInclude(JsonInclude.Include.NON_EMPTY)
3737
@JsonPropertyOrder(
38-
value = {"step_ids", "step_id_prefixes", "step_id_infixes", "step_id_suffixes"},
38+
value = {"step_ids", "step_id_starts_with", "step_id_contains", "step_id_ends_with"},
3939
alphabetic = true)
4040
@JsonDeserialize(builder = StepSelector.StepSelectorBuilder.class)
4141
@Builder(toBuilder = true)
@@ -46,45 +46,45 @@ public class StepSelector {
4646
@Nullable private final Set<@NotBlank String> stepIds;
4747

4848
/** Matches a step id that starts with any of these. */
49-
@Nullable private final Set<@NotBlank String> stepIdPrefixes;
49+
@Nullable private final Set<@NotBlank String> stepIdStartsWith;
5050

5151
/** Matches a step id that contains any of these. */
52-
@Nullable private final Set<@NotBlank String> stepIdInfixes;
52+
@Nullable private final Set<@NotBlank String> stepIdContains;
5353

5454
/** Matches a step id that ends with any of these. */
55-
@Nullable private final Set<@NotBlank String> stepIdSuffixes;
55+
@Nullable private final Set<@NotBlank String> stepIdEndsWith;
5656

5757
/**
5858
* Returns true if the step id matches any criterion. A selector with no criteria matches none.
5959
*/
6060
@JsonIgnore
6161
public boolean matches(String stepId) {
6262
return (stepIds != null && stepIds.contains(stepId))
63-
|| (stepIdPrefixes != null && stepIdPrefixes.stream().anyMatch(stepId::startsWith))
64-
|| (stepIdInfixes != null && stepIdInfixes.stream().anyMatch(stepId::contains))
65-
|| (stepIdSuffixes != null && stepIdSuffixes.stream().anyMatch(stepId::endsWith));
63+
|| (stepIdStartsWith != null && stepIdStartsWith.stream().anyMatch(stepId::startsWith))
64+
|| (stepIdContains != null && stepIdContains.stream().anyMatch(stepId::contains))
65+
|| (stepIdEndsWith != null && stepIdEndsWith.stream().anyMatch(stepId::endsWith));
6666
}
6767

6868
/** Whether this selector carries no criteria, in which case it matches nothing. */
6969
@JsonIgnore
7070
public boolean isEmpty() {
7171
return (stepIds == null || stepIds.isEmpty())
72-
&& (stepIdPrefixes == null || stepIdPrefixes.isEmpty())
73-
&& (stepIdInfixes == null || stepIdInfixes.isEmpty())
74-
&& (stepIdSuffixes == null || stepIdSuffixes.isEmpty());
72+
&& (stepIdStartsWith == null || stepIdStartsWith.isEmpty())
73+
&& (stepIdContains == null || stepIdContains.isEmpty())
74+
&& (stepIdEndsWith == null || stepIdEndsWith.isEmpty());
7575
}
7676

7777
/**
78-
* Returns the criteria this selector carries, e.g. {@code ids [s1, s2], prefixes [s]}. It omits
79-
* the unset criteria and sorts the values, so equal selectors return identical text.
78+
* Returns the criteria this selector carries, e.g. {@code ids [s1, s2], starts_with [s]}. It
79+
* omits the unset criteria and sorts the values, so equal selectors return identical text.
8080
*/
8181
@JsonIgnore
8282
public String describe() {
8383
return Stream.of(
8484
Map.entry("ids", orEmpty(stepIds)),
85-
Map.entry("prefixes", orEmpty(stepIdPrefixes)),
86-
Map.entry("infixes", orEmpty(stepIdInfixes)),
87-
Map.entry("suffixes", orEmpty(stepIdSuffixes)))
85+
Map.entry("starts_with", orEmpty(stepIdStartsWith)),
86+
Map.entry("contains", orEmpty(stepIdContains)),
87+
Map.entry("ends_with", orEmpty(stepIdEndsWith)))
8888
.filter(entry -> !entry.getValue().isEmpty())
8989
.map(entry -> entry.getKey() + " " + new TreeSet<>(entry.getValue()))
9090
.collect(Collectors.joining(", "));

maestro-common/src/main/java/com/netflix/maestro/validations/StepSelectionConstraint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static boolean isSelectorValid(
6565
context,
6666
"[step selection] "
6767
+ field
68-
+ " must set at least one step id, prefix, infix or suffix");
68+
+ " must set at least one step id, starts_with, contains or ends_with");
6969
}
7070
return true;
7171
}

maestro-common/src/test/java/com/netflix/maestro/models/api/WorkflowInstanceRestartRequestTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public void testStepSelectionFromJson() throws Exception {
3939
WorkflowInstanceRestartRequest.class);
4040
StepSelector include = request.getStepSelection().getInclude();
4141
StepSelector exclude = request.getStepSelection().getExclude();
42-
assertEquals(Set.of("load_"), include.getStepIdPrefixes());
42+
assertEquals(Set.of("load_"), include.getStepIdStartsWith());
4343
assertEquals(Set.of("load_expensive"), exclude.getStepIds());
44-
assertEquals(Set.of("region"), exclude.getStepIdInfixes());
45-
assertEquals(Set.of("_child"), exclude.getStepIdSuffixes());
44+
assertEquals(Set.of("region"), exclude.getStepIdContains());
45+
assertEquals(Set.of("_child"), exclude.getStepIdEndsWith());
4646
}
4747
}

maestro-common/src/test/java/com/netflix/maestro/models/api/WorkflowStartRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void testRoundTripSerde() throws Exception {
3131
public void testStepSelectionFromJson() throws Exception {
3232
WorkflowStartRequest request =
3333
loadObject("fixtures/api/sample-workflow-start-request.json", WorkflowStartRequest.class);
34-
assertEquals(Set.of("load_"), request.getStepSelection().getInclude().getStepIdPrefixes());
34+
assertEquals(Set.of("load_"), request.getStepSelection().getInclude().getStepIdStartsWith());
3535
assertEquals(Set.of("load_expensive"), request.getStepSelection().getExclude().getStepIds());
3636
}
3737
}

maestro-common/src/test/java/com/netflix/maestro/models/instance/RunConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void testRoundTripSerde() throws Exception {
2828
@Test
2929
public void testStepSelectionFromJson() throws Exception {
3030
RunConfig config = loadObject("fixtures/instances/sample-run-config.json", RunConfig.class);
31-
assertEquals(Set.of("load_"), config.getStepSelection().getInclude().getStepIdPrefixes());
31+
assertEquals(Set.of("load_"), config.getStepSelection().getInclude().getStepIdStartsWith());
3232
assertEquals(Set.of("load_expensive"), config.getStepSelection().getExclude().getStepIds());
3333
}
3434
}

maestro-common/src/test/java/com/netflix/maestro/models/instance/StepSelectionTest.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ private static StepSelection selection(String includePrefix, String excludePrefi
2727
.include(
2828
includePrefix == null
2929
? null
30-
: StepSelector.builder().stepIdPrefixes(Set.of(includePrefix)).build())
30+
: StepSelector.builder().stepIdStartsWith(Set.of(includePrefix)).build())
3131
.exclude(
3232
excludePrefix == null
3333
? null
34-
: StepSelector.builder().stepIdPrefixes(Set.of(excludePrefix)).build())
34+
: StepSelector.builder().stepIdStartsWith(Set.of(excludePrefix)).build())
3535
.build();
3636
}
3737

@@ -54,7 +54,7 @@ public void testStepIdsAndPrefixesBothApply() {
5454
.include(
5555
StepSelector.builder()
5656
.stepIds(Set.of("transform"))
57-
.stepIdPrefixes(Set.of("load_"))
57+
.stepIdStartsWith(Set.of("load_"))
5858
.build())
5959
.build();
6060
assertFalse(selection.isSkipped("transform"));
@@ -66,7 +66,7 @@ public void testStepIdsAndPrefixesBothApply() {
6666
public void testStepIdsInExcludeAndExcludeStillWins() {
6767
StepSelection selection =
6868
StepSelection.builder()
69-
.include(StepSelector.builder().stepIdPrefixes(Set.of("load_")).build())
69+
.include(StepSelector.builder().stepIdStartsWith(Set.of("load_")).build())
7070
.exclude(StepSelector.builder().stepIds(Set.of("load_expensive")).build())
7171
.build();
7272
assertFalse(selection.isSkipped("load_users"));
@@ -107,7 +107,7 @@ public void testExcludeWinsOverInclude() {
107107
public void testInfixMatchesAnywhereInTheStepId() {
108108
StepSelection selection =
109109
StepSelection.builder()
110-
.include(StepSelector.builder().stepIdInfixes(Set.of("region")).build())
110+
.include(StepSelector.builder().stepIdContains(Set.of("region")).build())
111111
.build();
112112
assertFalse(selection.isSkipped("load_region"));
113113
assertFalse(selection.isSkipped("region_report"));
@@ -119,7 +119,7 @@ public void testInfixMatchesAnywhereInTheStepId() {
119119
public void testSuffixMatchesTheEndOnly() {
120120
StepSelection selection =
121121
StepSelection.builder()
122-
.exclude(StepSelector.builder().stepIdSuffixes(Set.of("_child")).build())
122+
.exclude(StepSelector.builder().stepIdEndsWith(Set.of("_child")).build())
123123
.build();
124124
assertTrue(selection.isSkipped("load_child"));
125125
assertTrue(selection.isSkipped("fanout_child"));
@@ -132,9 +132,9 @@ public void testEachCriterionMatchesOnItsOwnRule() {
132132
StepSelector selector =
133133
StepSelector.builder()
134134
.stepIds(Set.of("exact"))
135-
.stepIdPrefixes(Set.of("pre_"))
136-
.stepIdInfixes(Set.of("_mid_"))
137-
.stepIdSuffixes(Set.of("_post"))
135+
.stepIdStartsWith(Set.of("pre_"))
136+
.stepIdContains(Set.of("_mid_"))
137+
.stepIdEndsWith(Set.of("_post"))
138138
.build();
139139
assertTrue(selector.matches("exact"));
140140
assertTrue(selector.matches("pre_anything"));
@@ -160,37 +160,38 @@ public void testSelectorDescribesOnlyTheCriteriaItCarries() {
160160
"ids [load_expensive]",
161161
StepSelector.builder().stepIds(Set.of("load_expensive")).build().describe());
162162
assertEquals(
163-
"prefixes [load_]",
164-
StepSelector.builder().stepIdPrefixes(Set.of("load_")).build().describe());
163+
"starts_with [load_]",
164+
StepSelector.builder().stepIdStartsWith(Set.of("load_")).build().describe());
165165
assertEquals(
166-
"infixes [region]",
167-
StepSelector.builder().stepIdInfixes(Set.of("region")).build().describe());
166+
"contains [region]",
167+
StepSelector.builder().stepIdContains(Set.of("region")).build().describe());
168168
assertEquals(
169-
"suffixes [_child]",
170-
StepSelector.builder().stepIdSuffixes(Set.of("_child")).build().describe());
169+
"ends_with [_child]",
170+
StepSelector.builder().stepIdEndsWith(Set.of("_child")).build().describe());
171171
}
172172

173173
@Test
174174
public void testSelectorDescribesSeveralCriteriaInFixedOrder() {
175175
StepSelector selector =
176176
StepSelector.builder()
177177
.stepIds(Set.of("b", "a"))
178-
.stepIdPrefixes(Set.of("load_"))
179-
.stepIdInfixes(Set.of("region"))
180-
.stepIdSuffixes(Set.of("_child"))
178+
.stepIdStartsWith(Set.of("load_"))
179+
.stepIdContains(Set.of("region"))
180+
.stepIdEndsWith(Set.of("_child"))
181181
.build();
182182
assertEquals(
183-
"ids [a, b], prefixes [load_], infixes [region], suffixes [_child]", selector.describe());
183+
"ids [a, b], starts_with [load_], contains [region], ends_with [_child]",
184+
selector.describe());
184185
}
185186

186187
@Test
187188
public void testSelectionDescribesWhatItDoes() {
188189
assertEquals(
189-
"includes only steps matching prefixes [load_]", selection("load_", null).describe());
190+
"includes only steps matching starts_with [load_]", selection("load_", null).describe());
190191
assertEquals(
191-
"excludes steps matching prefixes [report_]", selection(null, "report_").describe());
192+
"excludes steps matching starts_with [report_]", selection(null, "report_").describe());
192193
assertEquals(
193-
"includes only steps matching prefixes [load_], and excludes steps matching prefixes"
194+
"includes only steps matching starts_with [load_], and excludes steps matching starts_with"
194195
+ " [load_expensive]",
195196
selection("load_", "load_expensive").describe());
196197
}
@@ -224,18 +225,18 @@ public void testFromJson() throws Exception {
224225
{
225226
"include": {
226227
"step_ids": ["transform"],
227-
"step_id_prefixes": ["load_"],
228-
"step_id_infixes": ["region"],
229-
"step_id_suffixes": ["_child"]
228+
"step_id_starts_with": ["load_"],
229+
"step_id_contains": ["region"],
230+
"step_id_ends_with": ["_child"]
230231
},
231232
"exclude": {"step_ids": ["load_expensive"]}
232233
}
233234
""",
234235
StepSelection.class);
235236
assertEquals(Set.of("transform"), selection.getInclude().getStepIds());
236-
assertEquals(Set.of("load_"), selection.getInclude().getStepIdPrefixes());
237-
assertEquals(Set.of("region"), selection.getInclude().getStepIdInfixes());
238-
assertEquals(Set.of("_child"), selection.getInclude().getStepIdSuffixes());
237+
assertEquals(Set.of("load_"), selection.getInclude().getStepIdStartsWith());
238+
assertEquals(Set.of("region"), selection.getInclude().getStepIdContains());
239+
assertEquals(Set.of("_child"), selection.getInclude().getStepIdEndsWith());
239240
assertEquals(Set.of("load_expensive"), selection.getExclude().getStepIds());
240241
}
241242
}

maestro-common/src/test/java/com/netflix/maestro/validations/StepSelectionConstraintTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testSelectionWithCriteriaAccepted() {
5555
assertTrue(
5656
validate(
5757
StepSelection.builder()
58-
.exclude(StepSelector.builder().stepIdPrefixes(Set.of("report_")).build())
58+
.exclude(StepSelector.builder().stepIdStartsWith(Set.of("report_")).build())
5959
.build())
6060
.isEmpty());
6161
}
@@ -75,7 +75,7 @@ public void testEmptyIncludeRejected() {
7575
validate(StepSelection.builder().include(StepSelector.builder().build()).build());
7676
assertEquals(1, violations.size());
7777
assertEquals(
78-
"[step selection] include must set at least one step id, prefix, infix or suffix",
78+
"[step selection] include must set at least one step id, starts_with, contains or ends_with",
7979
violations.iterator().next().getMessage());
8080
}
8181

@@ -86,7 +86,7 @@ public void testNullCriterionRejected() {
8686
StepSelection.builder()
8787
.include(
8888
StepSelector.builder()
89-
.stepIdPrefixes(new HashSet<>(Collections.singletonList(null)))
89+
.stepIdStartsWith(new HashSet<>(Collections.singletonList(null)))
9090
.build())
9191
.build());
9292
assertBlankCriterion(violations);
@@ -97,7 +97,7 @@ public void testBlankCriterionRejected() {
9797
Set<ConstraintViolation<TestSelection>> violations =
9898
validate(
9999
StepSelection.builder()
100-
.exclude(StepSelector.builder().stepIdInfixes(Set.of(" ")).build())
100+
.exclude(StepSelector.builder().stepIdContains(Set.of(" ")).build())
101101
.build());
102102
assertBlankCriterion(violations);
103103
}
@@ -116,7 +116,7 @@ public void testEmptyStepIdsListRejected() {
116116
.build());
117117
assertEquals(1, violations.size());
118118
assertEquals(
119-
"[step selection] exclude must set at least one step id, prefix, infix or suffix",
119+
"[step selection] exclude must set at least one step id, starts_with, contains or ends_with",
120120
violations.iterator().next().getMessage());
121121
}
122122
}

maestro-common/src/testFixtures/resources/fixtures/api/sample-workflow-restart-request.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
},
1818
"step_selection": {
1919
"include": {
20-
"step_id_prefixes": ["load_"]
20+
"step_id_starts_with": ["load_"]
2121
},
2222
"exclude": {
2323
"step_ids": ["load_expensive"],
24-
"step_id_infixes": ["region"],
25-
"step_id_suffixes": ["_child"]
24+
"step_id_contains": ["region"],
25+
"step_id_ends_with": ["_child"]
2626
}
2727
}
2828
}

maestro-common/src/testFixtures/resources/fixtures/api/sample-workflow-start-request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"step_selection": {
2121
"include": {
22-
"step_id_prefixes": ["load_"]
22+
"step_id_starts_with": ["load_"]
2323
},
2424
"exclude": {
2525
"step_ids": ["load_expensive"]

maestro-common/src/testFixtures/resources/fixtures/instances/sample-run-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"step_selection": {
4848
"include": {
49-
"step_id_prefixes": ["load_"]
49+
"step_id_starts_with": ["load_"]
5050
},
5151
"exclude": {
5252
"step_ids": ["load_expensive"]

0 commit comments

Comments
 (0)