Skip to content

Commit

Permalink
feat(*): skip executions for a namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mulier-p committed Jun 17, 2024
1 parent 1db6b57 commit dbb1a8e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class ExecutorCommand extends AbstractServerCommand {
@CommandLine.Option(names = {"--skip-flows"}, split=",", description = "a list of flow identifiers (tenant|namespace|flowId) to skip, separated by a coma; for troubleshooting purpose only")
private List<String> skipFlows = Collections.emptyList();

@CommandLine.Option(names = {"--skip-namespaces"}, split=",", description = "a list of namespaces to skip, separated by a coma; for troubleshooting purpose only")
private List<String> skipNamespaces = Collections.emptyList();

@CommandLine.Option(names = {"--start-executors"}, split=",", description = "a list of Kafka Stream executors to start, separated by a command. Use it only with the Kafka queue, for debugging purpose.")
private List<String> startExecutors = Collections.emptyList();

Expand All @@ -54,6 +57,7 @@ public static Map<String, Object> propertiesOverrides() {
public Integer call() throws Exception {
this.skipExecutionService.setSkipExecutions(skipExecutions);
this.skipExecutionService.setSkipFlows(skipFlows);
this.skipExecutionService.setSkipNamespaces(skipNamespaces);

this.startExecutorService.applyOptions(startExecutors, notStartExecutors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class StandAloneCommand extends AbstractServerCommand {
@CommandLine.Option(names = {"--skip-flows"}, split=",", description = "a list of flow identifiers (namespace.flowId) to skip, separated by a coma; for troubleshooting purpose only")
private List<String> skipFlows = Collections.emptyList();

@CommandLine.Option(names = {"--skip-namespaces"}, split=",", description = "a list of namespaces to skip, separated by a coma; for troubleshooting purpose only")
private List<String> skipNamespaces = Collections.emptyList();

@CommandLine.Option(names = {"--no-tutorials"}, description = "Flag to disable auto-loading of tutorial flows.")
boolean tutorialsDisabled = false;

Expand All @@ -74,6 +77,7 @@ public static Map<String, Object> propertiesOverrides() {
public Integer call() throws Exception {
this.skipExecutionService.setSkipExecutions(skipExecutions);
this.skipExecutionService.setSkipFlows(skipFlows);
this.skipExecutionService.setSkipNamespaces(skipNamespaces);

this.startExecutorService.applyOptions(startExecutors, notStartExecutors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class SkipExecutionService {
private volatile List<String> skipExecutions = Collections.emptyList();
private volatile List<FlowId> skipFlows = Collections.emptyList();
private volatile List<String> skipNamespaces = Collections.emptyList();

public synchronized void setSkipExecutions(List<String> skipExecutions) {
this.skipExecutions = skipExecutions;
Expand All @@ -21,6 +22,10 @@ public synchronized void setSkipFlows(List<String> skipFlows) {
this.skipFlows = skipFlows == null ? Collections.emptyList() : skipFlows.stream().map(flow -> FlowId.from(flow)).toList();
}

public synchronized void setSkipNamespaces(List<String> skipNamespaces) {
this.skipNamespaces = skipNamespaces == null ? Collections.emptyList() : skipNamespaces;
}

/**
* Warning: this method didn't check the flow, so it must be used only when neither of the others can be used.
*/
Expand All @@ -38,8 +43,9 @@ public boolean skipExecution(TaskRun taskRun) {

@VisibleForTesting
boolean skipExecution(String tenant, String namespace, String flow, String executionId) {
return skipExecutions.contains(executionId) ||
skipFlows.contains(new FlowId(tenant, namespace, flow));
return skipNamespaces.contains(namespace) ||
skipFlows.contains(new FlowId(tenant, namespace, flow)) ||
skipExecutions.contains(executionId);
}

record FlowId(String tenant, String namespace, String flow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ void skipExecutionByFlowId() {
assertThat(skipExecutionService.skipExecution(null, "namespace", "not_skipped", "random"), is(false));
assertThat(skipExecutionService.skipExecution("tenant", "namespace", "not_skipped", "random"), is(false));
}

@Test
void skipExecutionByNamespace() {
skipExecutionService.setSkipNamespaces(List.of("namespace"));

assertThat(skipExecutionService.skipExecution(null, "namespace", "someFlow", "someExecution"), is(true));
assertThat(skipExecutionService.skipExecution(null, "namespace", "anotherFlow", "anotherExecution"), is(true));
assertThat(skipExecutionService.skipExecution(null, "other.namespace", "someFlow", "someExecution"), is(false));
}
}

0 comments on commit dbb1a8e

Please sign in to comment.