Skip to content

Commit

Permalink
fix(webserver): scope parameter for flows & executions is now a list
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mulier-p committed Sep 10, 2024
1 parent cf065cc commit af4fc14
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 52 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/io/kestra/core/models/flows/FlowScope.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.kestra.core.models.flows;

public enum FlowScope {
USER,
SYSTEM
}
USER,
SYSTEM
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ArrayListTotal<Execution> find(
Pageable pageable,
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand All @@ -61,7 +61,7 @@ ArrayListTotal<Execution> find(
default Flux<Execution> find(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand All @@ -77,7 +77,7 @@ default Flux<Execution> find(
Flux<Execution> find(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand Down Expand Up @@ -122,7 +122,7 @@ List<DailyExecutionStatistics> dailyStatisticsForAllTenants(
List<DailyExecutionStatistics> dailyStatistics(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ ArrayListTotal<Flow> find(
Pageable pageable,
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable Map<String, String> labels
);

List<FlowWithSource> findWithSource(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable Map<String, String> labels
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,22 @@ protected void dailyStatistics() throws InterruptedException {
result = executionRepository.dailyStatistics(
null,
null,
FlowScope.USER,
List.of(FlowScope.USER, FlowScope.SYSTEM),
null,
null,
ZonedDateTime.now().minusDays(10),
ZonedDateTime.now(),
null,
null,
false);

assertThat(result.size(), is(11));
assertThat(result.get(10).getExecutionCounts().get(State.Type.SUCCESS), is(21L));

result = executionRepository.dailyStatistics(
null,
null,
List.of(FlowScope.USER),
null,
null,
ZonedDateTime.now().minusDays(10),
Expand All @@ -463,7 +478,7 @@ protected void dailyStatistics() throws InterruptedException {
result = executionRepository.dailyStatistics(
null,
null,
FlowScope.SYSTEM,
List.of(FlowScope.SYSTEM),
null,
null,
ZonedDateTime.now().minusDays(10),
Expand Down Expand Up @@ -512,7 +527,22 @@ protected void taskRunsDailyStatistics() {
result = executionRepository.dailyStatistics(
null,
null,
FlowScope.USER,
List.of(FlowScope.USER, FlowScope.SYSTEM),
null,
null,
ZonedDateTime.now().minusDays(10),
ZonedDateTime.now(),
null,
null,
true);

assertThat(result.size(), is(11));
assertThat(result.get(10).getExecutionCounts().get(State.Type.SUCCESS), is(57L));

result = executionRepository.dailyStatistics(
null,
null,
List.of(FlowScope.USER),
null,
null,
ZonedDateTime.now().minusDays(10),
Expand All @@ -526,7 +556,7 @@ protected void taskRunsDailyStatistics() {
result = executionRepository.dailyStatistics(
null,
null,
FlowScope.SYSTEM,
List.of(FlowScope.SYSTEM),
null,
null,
ZonedDateTime.now().minusDays(10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -159,7 +154,7 @@ public ArrayListTotal<Execution> find(
Pageable pageable,
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand Down Expand Up @@ -198,7 +193,7 @@ public ArrayListTotal<Execution> find(
public Flux<Execution> find(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand Down Expand Up @@ -247,7 +242,7 @@ private SelectConditionStep<Record1<Object>> findSelect(
DSLContext context,
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand Down Expand Up @@ -365,7 +360,7 @@ public List<DailyExecutionStatistics> dailyStatisticsForAllTenants(
public List<DailyExecutionStatistics> dailyStatistics(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
Expand Down Expand Up @@ -462,7 +457,7 @@ private Results dailyStatisticsQuery(
List<Field<?>> fields,
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
List<FlowFilter> flows,
Expand Down Expand Up @@ -490,7 +485,7 @@ private Results dailyStatisticsQuery(
Condition defaultFilter,
List<Field<?>> fields,
@Nullable String query,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
List<FlowFilter> flows,
Expand Down Expand Up @@ -543,7 +538,7 @@ private Results dailyStatisticsQuery(

private <T extends Record> SelectConditionStep<T> filteringQuery(
SelectConditionStep<T> select,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable String flowId,
@Nullable List<FlowFilter> flows,
Expand All @@ -552,10 +547,10 @@ private <T extends Record> SelectConditionStep<T> filteringQuery(
@Nullable String triggerExecutionId,
@Nullable ChildFilter childFilter
) {
if (scope != null) {
if (scope.equals(FlowScope.USER)) {
if (scope != null && !scope.containsAll(Arrays.stream(FlowScope.values()).toList())) {
if (scope.contains(FlowScope.USER)) {
select = select.and(field("namespace").ne(namespaceUtils.getSystemFlowNamespace()));
} else if (scope.equals(FlowScope.SYSTEM)) {
} else if (scope.contains(FlowScope.SYSTEM)) {
select = select.and(field("namespace").eq(namespaceUtils.getSystemFlowNamespace()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public ArrayListTotal<Flow> find(
Pageable pageable,
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable Map<String, String> labels
) {
Expand All @@ -405,10 +405,10 @@ public ArrayListTotal<Flow> find(

select.and(this.findCondition(query, labels));

if (scope != null) {
if (scope.equals(FlowScope.USER)) {
if (scope != null && !scope.containsAll(Arrays.stream(FlowScope.values()).toList())) {
if (scope.contains(FlowScope.USER)) {
select = select.and(field("namespace").ne(namespaceUtils.getSystemFlowNamespace()));
} else if (scope.equals(FlowScope.SYSTEM)) {
} else if (scope.contains(FlowScope.SYSTEM)) {
select = select.and(field("namespace").eq(namespaceUtils.getSystemFlowNamespace()));
}
}
Expand All @@ -425,7 +425,7 @@ public ArrayListTotal<Flow> find(
public List<FlowWithSource> findWithSource(
@Nullable String query,
@Nullable String tenantId,
@Nullable FlowScope scope,
@Nullable List<FlowScope> scope,
@Nullable String namespace,
@Nullable Map<String, String> labels
) {
Expand All @@ -438,10 +438,10 @@ public List<FlowWithSource> findWithSource(

select.and(this.findCondition(query, labels));

if (scope != null) {
if (scope.equals(FlowScope.USER)) {
if (scope != null && !new HashSet<>(scope).containsAll(Arrays.stream(FlowScope.values()).toList())) {
if (scope.contains(FlowScope.USER)) {
select = select.and(field("namespace").ne(namespaceUtils.getSystemFlowNamespace()));
} else if (scope.equals(FlowScope.SYSTEM)) {
} else if (scope.contains(FlowScope.SYSTEM)) {
select = select.and(field("namespace").eq(namespaceUtils.getSystemFlowNamespace()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public PagedResults<Execution> find(
@Parameter(description = "The current page size") @QueryValue(defaultValue = "10") int size,
@Parameter(description = "The sort of current page") @Nullable @QueryValue List<String> sort,
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -349,7 +349,7 @@ public MutableHttpResponse<?> deleteByIds(
@Operation(tags = {"Executions"}, summary = "Delete executions filter by query parameters")
public HttpResponse<BulkResponse> deleteByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -762,7 +762,7 @@ public MutableHttpResponse<?> restartByIds(
@Operation(tags = {"Executions"}, summary = "Restart executions filter by query parameters")
public HttpResponse<BulkResponse> restartByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -963,7 +963,7 @@ public HttpResponse<?> changeStatusById(
@ApiResponse(responseCode = "422", description = "Changed status with errors", content = {@Content(schema = @Schema(implementation = BulkErrorResponse.class))})
public HttpResponse<?> changeStatusByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -1186,7 +1186,7 @@ public MutableHttpResponse<?> resumeByIds(
@Operation(tags = {"Executions"}, summary = "Resume executions filter by query parameters")
public HttpResponse<?> resumeByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -1228,7 +1228,7 @@ public HttpResponse<?> resumeByQuery(
@Operation(tags = {"Executions"}, summary = "Kill executions filter by query parameters")
public HttpResponse<?> killByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -1270,7 +1270,7 @@ public HttpResponse<?> killByQuery(
@Operation(tags = {"Executions"}, summary = "Create new executions from old ones filter by query parameters. Keep the flow revision")
public HttpResponse<?> replayByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down Expand Up @@ -1562,7 +1562,7 @@ public record SetLabelsByIdsRequest(List<String> executionsId, List<Label> execu
@Operation(tags = {"Executions"}, summary = "Set label on executions filter by query parameters")
public HttpResponse<?> setLabelsByQuery(
@Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") FlowScope scope,
@Parameter(description = "The scope of the executions to include") @Nullable @QueryValue(value = "scope") List<FlowScope> scope,
@Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
@Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@Parameter(description = "The start datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime startDate,
Expand Down
Loading

0 comments on commit af4fc14

Please sign in to comment.