From 90492354e2bdcc6a0c48322f73028f078e2cfa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Thu, 11 Jul 2024 14:47:35 +0200 Subject: [PATCH] fix: merge issue --- .../kestra/plugin/core/storage/PurgeTest.java | 67 ------------------- .../repository/AbstractJdbcRepository.java | 5 ++ .../memory/MemoryExecutionRepository.java | 5 ++ 3 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 core/src/test/java/io/kestra/plugin/core/storage/PurgeTest.java diff --git a/core/src/test/java/io/kestra/plugin/core/storage/PurgeTest.java b/core/src/test/java/io/kestra/plugin/core/storage/PurgeTest.java deleted file mode 100644 index b0dd257b13..0000000000 --- a/core/src/test/java/io/kestra/plugin/core/storage/PurgeTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.kestra.plugin.core.storage; - -import io.kestra.core.junit.annotations.KestraTest; -import io.kestra.core.models.executions.Execution; -import io.kestra.core.models.flows.State; -import io.kestra.core.repositories.ExecutionRepositoryInterface; -import io.kestra.core.runners.RunContextFactory; -import io.kestra.core.utils.IdUtils; -import jakarta.inject.Inject; -import org.junit.jupiter.api.Test; - -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Map; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -@KestraTest -class PurgeTest { - @Inject - private RunContextFactory runContextFactory; - - @Inject - private ExecutionRepositoryInterface executionRepository; - - @Test - void run() throws Exception { - // create an execution to delete - var execution = Execution.builder() - .namespace("namespace") - .flowId("flowId") - .id(IdUtils.create()) - .state(new State().withState(State.Type.SUCCESS)) - .build(); - executionRepository.save(execution); - - var purge = Purge.builder() - .endDate(ZonedDateTime.now().plusMinutes(1).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)) - .build(); - var runContext = runContextFactory.of(Map.of("flow", Map.of("namespace", "namespace", "id", "flowId"))); - var output = purge.run(runContext); - - assertThat(output.getExecutionsCount(), is(1)); - } - - @Test - void deleted() throws Exception { - // create an execution to delete - var execution = Execution.builder() - .namespace("namespace") - .flowId("flowId") - .id(IdUtils.create()) - .state(new State().withState(State.Type.SUCCESS)) - .build(); - executionRepository.save(execution); - executionRepository.delete(execution); - - var purge = Purge.builder() - .endDate(ZonedDateTime.now().plusMinutes(1).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)) - .build(); - var runContext = runContextFactory.of(Map.of("flow", Map.of("namespace", "namespace", "id", "flowId"))); - var output = purge.run(runContext); - - assertThat(output.getExecutionsCount(), is(1)); - } -} \ No newline at end of file diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcRepository.java index 7f133b0685..6c778bd692 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcRepository.java @@ -23,6 +23,11 @@ protected Condition defaultFilter(String tenantId) { return tenant.and(field("deleted", Boolean.class).eq(false)); } + protected Condition defaultFilter(String tenantId, Boolean allowDeleted) { + var tenant = buildTenantCondition(tenantId); + return allowDeleted ? tenant : tenant.and(field("deleted", Boolean.class).eq(false)); + } + protected Condition buildTenantCondition(String tenantId) { return tenantId == null ? field("tenant_id").isNull() : field("tenant_id").eq(tenantId); } diff --git a/repository-memory/src/main/java/io/kestra/repository/memory/MemoryExecutionRepository.java b/repository-memory/src/main/java/io/kestra/repository/memory/MemoryExecutionRepository.java index 0f4c799bff..6188a324e8 100644 --- a/repository-memory/src/main/java/io/kestra/repository/memory/MemoryExecutionRepository.java +++ b/repository-memory/src/main/java/io/kestra/repository/memory/MemoryExecutionRepository.java @@ -38,6 +38,11 @@ public Flux find(@Nullable String query, @Nullable String tenantId, @ return null; } + @Override + public Flux find(@Nullable String query, @Nullable String tenantId, @Nullable String namespace, @Nullable String flowId, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, @Nullable List state, @Nullable Map labels, @Nullable String triggerExecutionId, @Nullable ChildFilter childFilter, boolean allowDeleted) { + return null; + } + @Override public ArrayListTotal findTaskRun(Pageable pageable, @Nullable String query, @Nullable String tenantId, @Nullable String namespace, @Nullable String flowId, @Nullable ZonedDateTime startDate, @Nullable ZonedDateTime endDate, @Nullable List states, @Nullable Map labels, @Nullable String triggerExecutionId, @Nullable ChildFilter childFilter) { throw new UnsupportedOperationException();