diff --git a/cli/src/main/java/io/kestra/cli/AbstractApiCommand.java b/cli/src/main/java/io/kestra/cli/AbstractApiCommand.java index 0197a90705..124ee2959a 100644 --- a/cli/src/main/java/io/kestra/cli/AbstractApiCommand.java +++ b/cli/src/main/java/io/kestra/cli/AbstractApiCommand.java @@ -1,5 +1,7 @@ package io.kestra.cli; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import io.micronaut.core.annotation.Nullable; import io.micronaut.http.HttpHeaders; import io.micronaut.http.HttpRequest; @@ -90,7 +92,7 @@ public abstract class AbstractApiCommand extends AbstractCommand { throw new IllegalArgumentException("'path' must be non-null and start with '/'"); } - return tenantId == null ? "/api/v1" + path : "/api/v1/" + tenantId + path; + return tenantId == null ? "/api/v1/" + MAIN_TENANT + path : "/api/v1/" + tenantId + path; } @Builder diff --git a/cli/src/main/java/io/kestra/cli/commands/flows/FlowTestCommand.java b/cli/src/main/java/io/kestra/cli/commands/flows/FlowTestCommand.java index a88b4bb87b..286aa17c29 100644 --- a/cli/src/main/java/io/kestra/cli/commands/flows/FlowTestCommand.java +++ b/cli/src/main/java/io/kestra/cli/commands/flows/FlowTestCommand.java @@ -89,7 +89,7 @@ public class FlowTestCommand extends AbstractCommand { try { runner.run(); - repositoryLoader.load(null, file.toFile()); + repositoryLoader.load(file.toFile()); List all = flowRepository.findAllForAllTenants(); if (all.size() != 1) { diff --git a/cli/src/main/java/io/kestra/cli/services/LocalFlowFileWatcher.java b/cli/src/main/java/io/kestra/cli/services/LocalFlowFileWatcher.java index 76c93c1cc8..93619ef183 100644 --- a/cli/src/main/java/io/kestra/cli/services/LocalFlowFileWatcher.java +++ b/cli/src/main/java/io/kestra/cli/services/LocalFlowFileWatcher.java @@ -15,7 +15,7 @@ public class LocalFlowFileWatcher implements FlowFilesManager { @Override public FlowWithSource createOrUpdateFlow(final GenericFlow flow) { - return flowRepository.findById(null, flow.getNamespace(), flow.getId()) + return flowRepository.findById(flow.getTenantId(), flow.getNamespace(), flow.getId()) .map(previous -> flowRepository.update(flow, previous)) .orElseGet(() -> flowRepository.create(flow)); } diff --git a/cli/src/test/java/io/kestra/cli/commands/flows/FlowUpdatesCommandTest.java b/cli/src/test/java/io/kestra/cli/commands/flows/FlowUpdatesCommandTest.java index 57992b3535..510b028f9e 100644 --- a/cli/src/test/java/io/kestra/cli/commands/flows/FlowUpdatesCommandTest.java +++ b/cli/src/test/java/io/kestra/cli/commands/flows/FlowUpdatesCommandTest.java @@ -142,7 +142,7 @@ class FlowUpdatesCommandTest { }; PicocliRunner.call(FlowUpdatesCommand.class, ctx, args); - assertThat(out.toString()).contains("Invalid entity: flow.namespace: io.kestra.outsider_quattro_-1 - flow namespace is invalid"); + assertThat(out.toString()).contains("Invalid entity: flow.namespace: main_io.kestra.outsider_quattro_-1 - flow namespace is invalid"); } } diff --git a/cli/src/test/java/io/kestra/cli/commands/namespaces/kv/KvUpdateCommandTest.java b/cli/src/test/java/io/kestra/cli/commands/namespaces/kv/KvUpdateCommandTest.java index 9b261a873e..032d950cb5 100644 --- a/cli/src/test/java/io/kestra/cli/commands/namespaces/kv/KvUpdateCommandTest.java +++ b/cli/src/test/java/io/kestra/cli/commands/namespaces/kv/KvUpdateCommandTest.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.nio.file.Files; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; class KvUpdateCommandTest { @@ -40,7 +41,7 @@ class KvUpdateCommandTest { PicocliRunner.call(KvUpdateCommand.class, ctx, args); KVStoreService kvStoreService = ctx.getBean(KVStoreService.class); - KVStore kvStore = kvStoreService.get(null, "io.kestra.cli", null); + KVStore kvStore = kvStoreService.get(MAIN_TENANT, "io.kestra.cli", null); assertThat(kvStore.getValue("string").get()).isEqualTo(new KVValue("stringValue")); assertThat(((InternalKVStore) kvStore).getRawValue("string").get()).isEqualTo("\"stringValue\""); @@ -68,7 +69,7 @@ class KvUpdateCommandTest { PicocliRunner.call(KvUpdateCommand.class, ctx, args); KVStoreService kvStoreService = ctx.getBean(KVStoreService.class); - KVStore kvStore = kvStoreService.get(null, "io.kestra.cli", null); + KVStore kvStore = kvStoreService.get(MAIN_TENANT, "io.kestra.cli", null); assertThat(kvStore.getValue("int").get()).isEqualTo(new KVValue(1)); assertThat(((InternalKVStore) kvStore).getRawValue("int").get()).isEqualTo("1"); @@ -98,7 +99,7 @@ class KvUpdateCommandTest { PicocliRunner.call(KvUpdateCommand.class, ctx, args); KVStoreService kvStoreService = ctx.getBean(KVStoreService.class); - KVStore kvStore = kvStoreService.get(null, "io.kestra.cli", null); + KVStore kvStore = kvStoreService.get(MAIN_TENANT, "io.kestra.cli", null); assertThat(kvStore.getValue("intStr").get()).isEqualTo(new KVValue("1")); assertThat(((InternalKVStore) kvStore).getRawValue("intStr").get()).isEqualTo("\"1\""); @@ -126,7 +127,7 @@ class KvUpdateCommandTest { PicocliRunner.call(KvUpdateCommand.class, ctx, args); KVStoreService kvStoreService = ctx.getBean(KVStoreService.class); - KVStore kvStore = kvStoreService.get(null, "io.kestra.cli", null); + KVStore kvStore = kvStoreService.get(MAIN_TENANT, "io.kestra.cli", null); assertThat(kvStore.getValue("object").get()).isEqualTo(new KVValue(Map.of("some", "json"))); assertThat(((InternalKVStore) kvStore).getRawValue("object").get()).isEqualTo("{some:\"json\"}"); @@ -156,7 +157,7 @@ class KvUpdateCommandTest { PicocliRunner.call(KvUpdateCommand.class, ctx, args); KVStoreService kvStoreService = ctx.getBean(KVStoreService.class); - KVStore kvStore = kvStoreService.get(null, "io.kestra.cli", null); + KVStore kvStore = kvStoreService.get(MAIN_TENANT, "io.kestra.cli", null); assertThat(kvStore.getValue("objectStr").get()).isEqualTo(new KVValue("{\"some\":\"json\"}")); assertThat(((InternalKVStore) kvStore).getRawValue("objectStr").get()).isEqualTo("\"{\\\"some\\\":\\\"json\\\"}\""); @@ -190,7 +191,7 @@ class KvUpdateCommandTest { PicocliRunner.call(KvUpdateCommand.class, ctx, args); KVStoreService kvStoreService = ctx.getBean(KVStoreService.class); - KVStore kvStore = kvStoreService.get(null, "io.kestra.cli", null); + KVStore kvStore = kvStoreService.get(MAIN_TENANT, "io.kestra.cli", null); assertThat(kvStore.getValue("objectFromFile").get()).isEqualTo(new KVValue(Map.of("some", "json", "from", "file"))); assertThat(((InternalKVStore) kvStore).getRawValue("objectFromFile").get()).isEqualTo("{some:\"json\",from:\"file\"}"); diff --git a/cli/src/test/java/io/kestra/cli/services/FileChangedEventListenerTest.java b/cli/src/test/java/io/kestra/cli/services/FileChangedEventListenerTest.java index 6139351d8a..695fe04ca5 100644 --- a/cli/src/test/java/io/kestra/cli/services/FileChangedEventListenerTest.java +++ b/cli/src/test/java/io/kestra/cli/services/FileChangedEventListenerTest.java @@ -18,6 +18,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.core.utils.Rethrow.throwRunnable; import static org.assertj.core.api.Assertions.assertThat; @@ -57,7 +58,7 @@ class FileChangedEventListenerTest { @RetryingTest(5) // Flaky on CI but always pass locally void test() throws IOException, TimeoutException { // remove the flow if it already exists - flowRepository.findByIdWithSource(null, "io.kestra.tests.watch", "myflow").ifPresent(flow -> flowRepository.delete(flow)); + flowRepository.findByIdWithSource(MAIN_TENANT, "io.kestra.tests.watch", "myflow").ifPresent(flow -> flowRepository.delete(flow)); // create a basic flow String flow = """ @@ -71,11 +72,11 @@ class FileChangedEventListenerTest { """; Files.write(Path.of(FILE_WATCH + "/myflow.yaml"), flow.getBytes()); Await.until( - () -> flowRepository.findById(null, "io.kestra.tests.watch", "myflow").isPresent(), + () -> flowRepository.findById(MAIN_TENANT, "io.kestra.tests.watch", "myflow").isPresent(), Duration.ofMillis(100), Duration.ofSeconds(10) ); - Flow myflow = flowRepository.findById(null, "io.kestra.tests.watch", "myflow").orElseThrow(); + Flow myflow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests.watch", "myflow").orElseThrow(); assertThat(myflow.getTasks()).hasSize(1); assertThat(myflow.getTasks().getFirst().getId()).isEqualTo("hello"); assertThat(myflow.getTasks().getFirst().getType()).isEqualTo("io.kestra.plugin.core.log.Log"); @@ -83,7 +84,7 @@ class FileChangedEventListenerTest { // delete the flow Files.delete(Path.of(FILE_WATCH + "/myflow.yaml")); Await.until( - () -> flowRepository.findById(null, "io.kestra.tests.watch", "myflow").isEmpty(), + () -> flowRepository.findById(MAIN_TENANT, "io.kestra.tests.watch", "myflow").isEmpty(), Duration.ofMillis(100), Duration.ofSeconds(10) ); @@ -92,7 +93,7 @@ class FileChangedEventListenerTest { @RetryingTest(5) // Flaky on CI but always pass locally void testWithPluginDefault() throws IOException, TimeoutException { // remove the flow if it already exists - flowRepository.findByIdWithSource(null, "io.kestra.tests.watch", "pluginDefault").ifPresent(flow -> flowRepository.delete(flow)); + flowRepository.findByIdWithSource(MAIN_TENANT, "io.kestra.tests.watch", "pluginDefault").ifPresent(flow -> flowRepository.delete(flow)); // create a flow with plugin default String pluginDefault = """ @@ -110,11 +111,11 @@ class FileChangedEventListenerTest { """; Files.write(Path.of(FILE_WATCH + "/plugin-default.yaml"), pluginDefault.getBytes()); Await.until( - () -> flowRepository.findById(null, "io.kestra.tests.watch", "pluginDefault").isPresent(), + () -> flowRepository.findById(MAIN_TENANT, "io.kestra.tests.watch", "pluginDefault").isPresent(), Duration.ofMillis(100), Duration.ofSeconds(10) ); - Flow pluginDefaultFlow = flowRepository.findById(null, "io.kestra.tests.watch", "pluginDefault").orElseThrow(); + Flow pluginDefaultFlow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests.watch", "pluginDefault").orElseThrow(); assertThat(pluginDefaultFlow.getTasks()).hasSize(1); assertThat(pluginDefaultFlow.getTasks().getFirst().getId()).isEqualTo("helloWithDefault"); assertThat(pluginDefaultFlow.getTasks().getFirst().getType()).isEqualTo("io.kestra.plugin.core.log.Log"); @@ -122,7 +123,7 @@ class FileChangedEventListenerTest { // delete both files Files.delete(Path.of(FILE_WATCH + "/plugin-default.yaml")); Await.until( - () -> flowRepository.findById(null, "io.kestra.tests.watch", "pluginDefault").isEmpty(), + () -> flowRepository.findById(MAIN_TENANT, "io.kestra.tests.watch", "pluginDefault").isEmpty(), Duration.ofMillis(100), Duration.ofSeconds(10) ); diff --git a/cli/src/test/resources/application-file-watch.yml b/cli/src/test/resources/application-file-watch.yml index 34f7856c6b..3516f72ec2 100644 --- a/cli/src/test/resources/application-file-watch.yml +++ b/cli/src/test/resources/application-file-watch.yml @@ -2,6 +2,7 @@ micronaut: io: watch: enabled: true + tenantId: main paths: - build/file-watch diff --git a/core/src/main/java/io/kestra/core/models/flows/FlowWithPath.java b/core/src/main/java/io/kestra/core/models/flows/FlowWithPath.java index 5eec653598..2a48299204 100644 --- a/core/src/main/java/io/kestra/core/models/flows/FlowWithPath.java +++ b/core/src/main/java/io/kestra/core/models/flows/FlowWithPath.java @@ -27,6 +27,7 @@ public class FlowWithPath { public static FlowWithPath of(FlowInterface flow, String path) { return FlowWithPath.builder() + .tenantId(flow.getTenantId()) .id(flow.getId()) .namespace(flow.getNamespace()) .path(path) diff --git a/core/src/main/java/io/kestra/core/models/templates/Template.java b/core/src/main/java/io/kestra/core/models/templates/Template.java index dade9aa39d..a4500693e6 100644 --- a/core/src/main/java/io/kestra/core/models/templates/Template.java +++ b/core/src/main/java/io/kestra/core/models/templates/Template.java @@ -46,6 +46,7 @@ public class Template implements DeletedInterface, TenantInterface, HasUID { }) .setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); + @Setter @Hidden @Pattern(regexp = "^[a-z0-9][a-z0-9_-]*") private String tenantId; diff --git a/core/src/main/java/io/kestra/core/repositories/LocalFlowRepositoryLoader.java b/core/src/main/java/io/kestra/core/repositories/LocalFlowRepositoryLoader.java index e4859b36cd..77fbfb0c13 100644 --- a/core/src/main/java/io/kestra/core/repositories/LocalFlowRepositoryLoader.java +++ b/core/src/main/java/io/kestra/core/repositories/LocalFlowRepositoryLoader.java @@ -32,6 +32,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.core.utils.Rethrow.throwConsumer; @Singleton @@ -48,7 +49,7 @@ public class LocalFlowRepositoryLoader { private PluginDefaultService pluginDefaultService; public void load(URL basePath) throws IOException, URISyntaxException { - load(null, basePath); + load(MAIN_TENANT, basePath); } public void load(String tenantId, URL basePath) throws IOException, URISyntaxException { @@ -78,7 +79,7 @@ public class LocalFlowRepositoryLoader { } public void load(File basePath) throws IOException { - load(null, basePath); + load(MAIN_TENANT, basePath); } public void load(String tenantId, File basePath) throws IOException { diff --git a/core/src/main/java/io/kestra/core/runners/DefaultRunContext.java b/core/src/main/java/io/kestra/core/runners/DefaultRunContext.java index 46fbd5a747..b89eb98655 100644 --- a/core/src/main/java/io/kestra/core/runners/DefaultRunContext.java +++ b/core/src/main/java/io/kestra/core/runners/DefaultRunContext.java @@ -35,7 +35,6 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.security.GeneralSecurityException; -import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; diff --git a/core/src/main/java/io/kestra/core/runners/RunContextFactory.java b/core/src/main/java/io/kestra/core/runners/RunContextFactory.java index 41d9410c25..3d8fb81443 100644 --- a/core/src/main/java/io/kestra/core/runners/RunContextFactory.java +++ b/core/src/main/java/io/kestra/core/runners/RunContextFactory.java @@ -1,5 +1,7 @@ package io.kestra.core.runners; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import com.google.common.annotations.VisibleForTesting; import io.kestra.core.metrics.MetricRegistry; import io.kestra.core.models.executions.Execution; @@ -180,7 +182,7 @@ public class RunContextFactory { @Override public String getTenantId() { var tenantId = ((Map)variables.getOrDefault("flow", Map.of())).get("tenantId"); - return Optional.ofNullable(tenantId).map(Object::toString).orElse(null); + return Optional.ofNullable(tenantId).map(Object::toString).orElse(MAIN_TENANT); } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/io/kestra/core/tenant/TenantService.java b/core/src/main/java/io/kestra/core/tenant/TenantService.java index dd25930b98..3f279bd280 100644 --- a/core/src/main/java/io/kestra/core/tenant/TenantService.java +++ b/core/src/main/java/io/kestra/core/tenant/TenantService.java @@ -5,13 +5,15 @@ import jakarta.inject.Singleton; @Singleton public class TenantService { + public static final String MAIN_TENANT = "main"; + /** * Resolve the current tenant and return its identifier. - * If the tenant is the default tenant, it returns null, which is always the case on OSS as Tenant is an EE feature. + * If the tenant is the default tenant, it returns main, which is always the case on OSS as Tenant is an EE feature. * * @return the current tenant identifier */ public String resolveTenant() { - return null; + return MAIN_TENANT; } } diff --git a/core/src/test/java/io/kestra/core/http/client/HttpClientTest.java b/core/src/test/java/io/kestra/core/http/client/HttpClientTest.java index 435e861ca5..92c941fe2f 100644 --- a/core/src/test/java/io/kestra/core/http/client/HttpClientTest.java +++ b/core/src/test/java/io/kestra/core/http/client/HttpClientTest.java @@ -2,6 +2,7 @@ package io.kestra.core.http.client; import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.net.HttpHeaders; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.http.HttpRequest; import io.kestra.core.http.HttpResponse; @@ -15,7 +16,6 @@ import io.kestra.core.models.property.Property; import io.kestra.core.queues.QueueFactoryInterface; import io.kestra.core.queues.QueueInterface; import io.kestra.core.runners.RunContext; -import io.kestra.core.runners.RunContextFactory; import io.kestra.core.serializers.JacksonMapper; import io.kestra.core.utils.IdUtils; import io.kestra.core.utils.TestsUtils; @@ -71,7 +71,7 @@ class HttpClientTest { private ApplicationContext applicationContext; @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; private URI embeddedServerUri; diff --git a/core/src/test/java/io/kestra/core/models/flows/sla/types/ExecutionAssertionSLATest.java b/core/src/test/java/io/kestra/core/models/flows/sla/types/ExecutionAssertionSLATest.java index faa627b524..f14cb4b3f7 100644 --- a/core/src/test/java/io/kestra/core/models/flows/sla/types/ExecutionAssertionSLATest.java +++ b/core/src/test/java/io/kestra/core/models/flows/sla/types/ExecutionAssertionSLATest.java @@ -1,5 +1,6 @@ package io.kestra.core.models.flows.sla.types; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.InternalException; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.flows.sla.Violation; @@ -18,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @KestraTest class ExecutionAssertionSLATest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void shouldEvaluateToAViolation() throws InternalException { diff --git a/core/src/test/java/io/kestra/core/models/hierarchies/FlowGraphTest.java b/core/src/test/java/io/kestra/core/models/hierarchies/FlowGraphTest.java index 9b1a8ba83d..f92211225a 100644 --- a/core/src/test/java/io/kestra/core/models/hierarchies/FlowGraphTest.java +++ b/core/src/test/java/io/kestra/core/models/hierarchies/FlowGraphTest.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -300,7 +301,7 @@ class FlowGraphTest { IllegalArgumentException illegalArgumentException = Assertions.assertThrows(IllegalArgumentException.class, () -> graphService.flowGraph(flow, Collections.singletonList("root.launch"))); assertThat(illegalArgumentException.getMessage()).isEqualTo("Can't expand subflow task 'launch' because namespace and/or flowId contains dynamic values. This can only be viewed on an execution."); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "task-flow-dynamic", 1, (f, e) -> Map.of( + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "task-flow-dynamic", 1, (f, e) -> Map.of( "namespace", f.getNamespace(), "flowId", "switch" )); @@ -377,7 +378,10 @@ class FlowGraphTest { File file = new File(resource.getFile()); - return YamlParser.parse(file, FlowWithSource.class).toBuilder().source(Files.readString(file.toPath())).build(); + return YamlParser.parse(file, FlowWithSource.class).toBuilder() + .tenantId(MAIN_TENANT) + .source(Files.readString(file.toPath())) + .build(); } private static AbstractGraph node(FlowGraph flowGraph, String taskId) { diff --git a/core/src/test/java/io/kestra/core/models/property/PropertyTest.java b/core/src/test/java/io/kestra/core/models/property/PropertyTest.java index 47564f7b76..58e1d27d55 100644 --- a/core/src/test/java/io/kestra/core/models/property/PropertyTest.java +++ b/core/src/test/java/io/kestra/core/models/property/PropertyTest.java @@ -1,5 +1,6 @@ package io.kestra.core.models.property; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.runners.RunContextFactory; @@ -20,6 +21,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static java.util.Map.entry; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -28,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class PropertyTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Inject private StorageInterface storage; @@ -155,7 +157,7 @@ class PropertyTest { FileSerde.writeAll(Files.newBufferedWriter(messages), Flux.fromIterable(inputValues)).block(); URI uri; try (var input = new FileInputStream(messages.toFile())) { - uri = storage.put(null, null, URI.create("/messages.ion"), input); + uri = storage.put(MAIN_TENANT, null, URI.create("/messages.ion"), input); } var task = DynamicPropertyExampleTask.builder() diff --git a/core/src/test/java/io/kestra/core/models/tasks/runners/ScriptServiceTest.java b/core/src/test/java/io/kestra/core/models/tasks/runners/ScriptServiceTest.java index 1322564355..c5ec23c268 100644 --- a/core/src/test/java/io/kestra/core/models/tasks/runners/ScriptServiceTest.java +++ b/core/src/test/java/io/kestra/core/models/tasks/runners/ScriptServiceTest.java @@ -1,5 +1,6 @@ package io.kestra.core.models.tasks.runners; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.executions.TaskRun; @@ -28,7 +29,7 @@ import static org.hamcrest.Matchers.*; @KestraTest class ScriptServiceTest { public static final Pattern COMMAND_PATTERN_CAPTURE_LOCAL_PATH = Pattern.compile("my command with an internal storage file: (.*)"); - @Inject private RunContextFactory runContextFactory; + @Inject private TestRunContextFactory runContextFactory; @Test void replaceInternalStorage() throws IOException { @@ -39,7 +40,7 @@ class ScriptServiceTest { command = ScriptService.replaceInternalStorage(runContext, "my command", false); assertThat(command).isEqualTo("my command"); - Path path = Path.of("/tmp/unittest/file.txt"); + Path path = Path.of("/tmp/unittest/main/file.txt"); if (!path.toFile().exists()) { Files.createFile(path); } @@ -71,7 +72,7 @@ class ScriptServiceTest { void uploadInputFiles() throws IOException { var runContext = runContextFactory.of(); - Path path = Path.of("/tmp/unittest/file.txt"); + Path path = Path.of("/tmp/unittest/main/file.txt"); if (!path.toFile().exists()) { Files.createFile(path); } @@ -118,12 +119,12 @@ class ScriptServiceTest { @Test void uploadOutputFiles() throws IOException { var runContext = runContextFactory.of(); - Path path = Path.of("/tmp/unittest/file.txt"); + Path path = Path.of("/tmp/unittest/main/file.txt"); if (!path.toFile().exists()) { Files.createFile(path); } - var outputFiles = ScriptService.uploadOutputFiles(runContext, Path.of("/tmp/unittest")); + var outputFiles = ScriptService.uploadOutputFiles(runContext, Path.of("/tmp/unittest/main")); assertThat(outputFiles, not(anEmptyMap())); assertThat(outputFiles.get("file.txt")).isEqualTo(URI.create("kestra:///file.txt")); diff --git a/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java b/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java index 6b9a37bce3..28a8d39d0a 100644 --- a/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java +++ b/core/src/test/java/io/kestra/core/repositories/AbstractExecutionRepositoryTest.java @@ -36,6 +36,7 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.*; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.groups.Tuple.tuple; import static org.hamcrest.Matchers.*; @@ -60,6 +61,7 @@ public abstract class AbstractExecutionRepositoryTest { Execution.ExecutionBuilder execution = Execution.builder() .id(FriendlyId.createFriendlyId()) .namespace(namespace) + .tenantId(MAIN_TENANT) .flowId(flowId == null ? FLOW : flowId) .flowRevision(1) .state(finalState); @@ -155,7 +157,7 @@ public abstract class AbstractExecutionRepositoryTest { protected void find() { inject(); - ArrayListTotal executions = executionRepository.find(Pageable.from(1, 10), null, null); + ArrayListTotal executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, null); assertThat(executions.getTotal()).isEqualTo(28L); assertThat(executions.size()).isEqualTo(10); @@ -164,7 +166,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.EQUALS) .value( List.of(State.Type.RUNNING, State.Type.FAILED)) .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(8L); filters = List.of(QueryFilter.builder() @@ -172,7 +174,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.EQUALS) .value(Map.of("key", "value")) .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(1L); filters = List.of(QueryFilter.builder() @@ -180,7 +182,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.EQUALS) .value(Map.of("key", "value2")) .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(0L); filters = List.of(QueryFilter.builder() @@ -189,7 +191,7 @@ public abstract class AbstractExecutionRepositoryTest { .value(Map.of("key", "value", "keyTest", "valueTest")) .build() ); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(1L); filters = List.of(QueryFilter.builder() @@ -197,7 +199,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.EQUALS) .value("second") .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(13L); filters = List.of(QueryFilter.builder() @@ -211,7 +213,7 @@ public abstract class AbstractExecutionRepositoryTest { .value(NAMESPACE) .build() ); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(13L); filters = List.of(QueryFilter.builder() @@ -219,7 +221,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.STARTS_WITH) .value("io.kestra") .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(28L); } @@ -235,7 +237,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.EQUALS) .value(executionTriggerId) .build()); - ArrayListTotal executions = executionRepository.find(Pageable.from(1, 10), null, filters); + ArrayListTotal executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(28L); assertThat(executions.size()).isEqualTo(10); assertThat(executions.getFirst().getTrigger().getVariables().get("executionId")).isEqualTo(executionTriggerId); @@ -245,7 +247,7 @@ public abstract class AbstractExecutionRepositoryTest { .value(ExecutionRepositoryInterface.ChildFilter.CHILD) .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(28L); assertThat(executions.size()).isEqualTo(10); assertThat(executions.getFirst().getTrigger().getVariables().get("executionId")).isEqualTo(executionTriggerId); @@ -256,12 +258,12 @@ public abstract class AbstractExecutionRepositoryTest { .value(ExecutionRepositoryInterface.ChildFilter.MAIN) .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters ); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters ); assertThat(executions.getTotal()).isEqualTo(28L); assertThat(executions.size()).isEqualTo(10); assertThat(executions.getFirst().getTrigger()).isNull(); - executions = executionRepository.find(Pageable.from(1, 10), null,null); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, null); assertThat(executions.getTotal()).isEqualTo(56L); } @@ -269,7 +271,7 @@ public abstract class AbstractExecutionRepositoryTest { protected void findWithSort() { inject(); - ArrayListTotal executions = executionRepository.find(Pageable.from(1, 10, Sort.of(Sort.Order.desc("id"))), null, null); + ArrayListTotal executions = executionRepository.find(Pageable.from(1, 10, Sort.of(Sort.Order.desc("id"))), MAIN_TENANT, null); assertThat(executions.getTotal()).isEqualTo(28L); assertThat(executions.size()).isEqualTo(10); @@ -278,7 +280,7 @@ public abstract class AbstractExecutionRepositoryTest { .operation(QueryFilter.Op.EQUALS) .value(List.of(State.Type.RUNNING, State.Type.FAILED)) .build()); - executions = executionRepository.find(Pageable.from(1, 10), null, filters); + executions = executionRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(executions.getTotal()).isEqualTo(8L); } @@ -286,7 +288,7 @@ public abstract class AbstractExecutionRepositoryTest { protected void findTaskRun() { inject(); - ArrayListTotal taskRuns = executionRepository.findTaskRun(Pageable.from(1, 10), null, null); + ArrayListTotal taskRuns = executionRepository.findTaskRun(Pageable.from(1, 10), MAIN_TENANT, null); assertThat(taskRuns.getTotal()).isEqualTo(74L); assertThat(taskRuns.size()).isEqualTo(10); @@ -296,7 +298,7 @@ public abstract class AbstractExecutionRepositoryTest { .value(Map.of("key", "value")) .build()); - taskRuns = executionRepository.findTaskRun(Pageable.from(1, 10), null, filters); + taskRuns = executionRepository.findTaskRun(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(taskRuns.getTotal()).isEqualTo(1L); assertThat(taskRuns.size()).isEqualTo(1); } @@ -306,7 +308,7 @@ public abstract class AbstractExecutionRepositoryTest { protected void findById() { executionRepository.save(ExecutionFixture.EXECUTION_1); - Optional full = executionRepository.findById(null, ExecutionFixture.EXECUTION_1.getId()); + Optional full = executionRepository.findById(MAIN_TENANT, ExecutionFixture.EXECUTION_1.getId()); assertThat(full.isPresent()).isTrue(); full.ifPresent(current -> { @@ -330,7 +332,7 @@ public abstract class AbstractExecutionRepositoryTest { protected void purge() { executionRepository.save(ExecutionFixture.EXECUTION_1); - Optional full = executionRepository.findById(null, ExecutionFixture.EXECUTION_1.getId()); + Optional full = executionRepository.findById(MAIN_TENANT, ExecutionFixture.EXECUTION_1.getId()); assertThat(full.isPresent()).isTrue(); executionRepository.purge(ExecutionFixture.EXECUTION_1); @@ -343,12 +345,12 @@ public abstract class AbstractExecutionRepositoryTest { protected void delete() { executionRepository.save(ExecutionFixture.EXECUTION_1); - Optional full = executionRepository.findById(null, ExecutionFixture.EXECUTION_1.getId()); + Optional full = executionRepository.findById(MAIN_TENANT, ExecutionFixture.EXECUTION_1.getId()); assertThat(full.isPresent()).isTrue(); executionRepository.delete(ExecutionFixture.EXECUTION_1); - full = executionRepository.findById(null, ExecutionFixture.EXECUTION_1.getId()); + full = executionRepository.findById(MAIN_TENANT, ExecutionFixture.EXECUTION_1.getId()); assertThat(full.isPresent()).isFalse(); } @@ -357,7 +359,7 @@ public abstract class AbstractExecutionRepositoryTest { executionRepository.save(ExecutionFixture.EXECUTION_2); executionRepository.save(ExecutionFixture.EXECUTION_1); - ArrayListTotal page1 = executionRepository.findByFlowId(null, NAMESPACE, FLOW, Pageable.from(1, 10)); + ArrayListTotal page1 = executionRepository.findByFlowId(MAIN_TENANT, NAMESPACE, FLOW, Pageable.from(1, 10)); assertThat(page1.size()).isEqualTo(2); } @@ -376,7 +378,7 @@ public abstract class AbstractExecutionRepositoryTest { Map>> result = executionRepository.dailyGroupByFlowStatistics( null, - null, + MAIN_TENANT, null, null, null, @@ -405,7 +407,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyGroupByFlowStatistics( null, - null, + MAIN_TENANT, null, null, null, @@ -426,7 +428,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyGroupByFlowStatistics( null, - null, + MAIN_TENANT, null, null, List.of(ExecutionRepositoryInterface.FlowFilter.builder().namespace("io.kestra.unittest").id(FLOW).build()), @@ -489,7 +491,7 @@ public abstract class AbstractExecutionRepositoryTest { Thread.sleep(500); List result = executionRepository.lastExecutions( - null, + MAIN_TENANT, List.of( ExecutionRepositoryInterface.FlowFilter.builder() .id(FLOW) @@ -531,7 +533,7 @@ public abstract class AbstractExecutionRepositoryTest { List result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, null, null, null, @@ -551,7 +553,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, List.of(FlowScope.USER, FlowScope.SYSTEM), null, null, @@ -566,7 +568,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, List.of(FlowScope.USER), null, null, @@ -580,7 +582,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, List.of(FlowScope.SYSTEM), null, null, @@ -609,7 +611,7 @@ public abstract class AbstractExecutionRepositoryTest { List result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, null, null, null, @@ -629,7 +631,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, List.of(FlowScope.USER, FlowScope.SYSTEM), null, null, @@ -644,7 +646,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, List.of(FlowScope.USER), null, null, @@ -658,7 +660,7 @@ public abstract class AbstractExecutionRepositoryTest { result = executionRepository.dailyStatistics( null, - null, + MAIN_TENANT, List.of(FlowScope.SYSTEM), null, null, @@ -685,7 +687,7 @@ public abstract class AbstractExecutionRepositoryTest { Thread.sleep(500); List result = executionRepository.executionCounts( - null, + MAIN_TENANT, List.of( new Flow(NAMESPACE, "first"), new Flow(NAMESPACE, "second"), @@ -704,7 +706,7 @@ public abstract class AbstractExecutionRepositoryTest { assertThat(result.stream().filter(executionCount -> executionCount.getFlowId().equals("missing")).findFirst().get().getCount()).isEqualTo(0L); result = executionRepository.executionCounts( - null, + MAIN_TENANT, List.of( new Flow(NAMESPACE, "first"), new Flow(NAMESPACE, "second"), @@ -721,7 +723,7 @@ public abstract class AbstractExecutionRepositoryTest { assertThat(result.stream().filter(executionCount -> executionCount.getFlowId().equals("third")).findFirst().get().getCount()).isEqualTo(9L); result = executionRepository.executionCounts( - null, + MAIN_TENANT, null, null, null, @@ -741,7 +743,7 @@ public abstract class AbstractExecutionRepositoryTest { Execution updated = execution.toBuilder().labels(List.of(label)).build(); executionRepository.update(updated); - Optional validation = executionRepository.findById(null, updated.getId()); + Optional validation = executionRepository.findById(MAIN_TENANT, updated.getId()); assertThat(validation.isPresent()).isTrue(); assertThat(validation.get().getLabels().size()).isEqualTo(1); assertThat(validation.get().getLabels().getFirst()).isEqualTo(label); @@ -755,7 +757,7 @@ public abstract class AbstractExecutionRepositoryTest { executionRepository.save(earliest); executionRepository.save(latest); - Optional result = executionRepository.findLatestForStates(null, "io.kestra.unittest", "full", List.of(State.Type.CREATED)); + Optional result = executionRepository.findLatestForStates(MAIN_TENANT, "io.kestra.unittest", "full", List.of(State.Type.CREATED)); assertThat(result.isPresent()).isTrue(); assertThat(result.get().getId()).isEqualTo(latest.getId()); } @@ -799,6 +801,7 @@ public abstract class AbstractExecutionRepositoryTest { return Execution.builder() .id(IdUtils.create()) .namespace("io.kestra.unittest") + .tenantId(MAIN_TENANT) .flowId("full") .flowRevision(1) .state(new State(State.Type.CREATED, List.of(new State.History(State.Type.CREATED, instant)))) @@ -811,7 +814,7 @@ public abstract class AbstractExecutionRepositoryTest { protected void findAllAsync() { inject(); - List executions = executionRepository.findAllAsync(null).collectList().block(); + List executions = executionRepository.findAllAsync(MAIN_TENANT).collectList().block(); assertThat(executions).hasSize(29); // used by the backup so it contains TEST executions } } diff --git a/core/src/test/java/io/kestra/core/repositories/AbstractFlowRepositoryTest.java b/core/src/test/java/io/kestra/core/repositories/AbstractFlowRepositoryTest.java index 85d899b331..0604c0c9b6 100644 --- a/core/src/test/java/io/kestra/core/repositories/AbstractFlowRepositoryTest.java +++ b/core/src/test/java/io/kestra/core/repositories/AbstractFlowRepositoryTest.java @@ -36,6 +36,7 @@ import java.util.*; import java.util.concurrent.TimeoutException; import jakarta.validation.ConstraintViolationException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.doReturn; @@ -59,7 +60,7 @@ public abstract class AbstractFlowRepositoryTest { @BeforeEach protected void init() throws IOException, URISyntaxException { - TestsUtils.loads(null, repositoryLoader); + TestsUtils.loads(MAIN_TENANT, repositoryLoader); FlowListener.reset(); } @@ -77,15 +78,16 @@ public abstract class AbstractFlowRepositoryTest { @Test void findById() { FlowWithSource flow = builder() + .tenantId(MAIN_TENANT) .revision(3) .build(); flow = flowRepository.create(GenericFlow.of(flow)); try { - Optional full = flowRepository.findById(null, flow.getNamespace(), flow.getId()); + Optional full = flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId()); assertThat(full.isPresent()).isTrue(); assertThat(full.get().getRevision()).isEqualTo(1); - full = flowRepository.findById(null, flow.getNamespace(), flow.getId(), Optional.empty()); + full = flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId(), Optional.empty()); assertThat(full.isPresent()).isTrue(); } finally { deleteFlow(flow); @@ -95,15 +97,16 @@ public abstract class AbstractFlowRepositoryTest { @Test void findByIdWithoutAcl() { FlowWithSource flow = builder() + .tenantId(MAIN_TENANT) .revision(3) .build(); flow = flowRepository.create(GenericFlow.of(flow)); try { - Optional full = flowRepository.findByIdWithoutAcl(null, flow.getNamespace(), flow.getId(), Optional.empty()); + Optional full = flowRepository.findByIdWithoutAcl(MAIN_TENANT, flow.getNamespace(), flow.getId(), Optional.empty()); assertThat(full.isPresent()).isTrue(); assertThat(full.get().getRevision()).isEqualTo(1); - full = flowRepository.findByIdWithoutAcl(null, flow.getNamespace(), flow.getId(), Optional.empty()); + full = flowRepository.findByIdWithoutAcl(MAIN_TENANT, flow.getNamespace(), flow.getId(), Optional.empty()); assertThat(full.isPresent()).isTrue(); } finally { deleteFlow(flow); @@ -113,13 +116,14 @@ public abstract class AbstractFlowRepositoryTest { @Test void findByIdWithSource() { FlowWithSource flow = builder() + .tenantId(MAIN_TENANT) .revision(3) .build(); String source = "# comment\n" + flow.sourceOrGenerateIfNull(); - flow = flowRepository.create(GenericFlow.fromYaml(null, source)); + flow = flowRepository.create(GenericFlow.fromYaml(MAIN_TENANT, source)); try { - Optional full = flowRepository.findByIdWithSource(null, flow.getNamespace(), flow.getId()); + Optional full = flowRepository.findByIdWithSource(MAIN_TENANT, flow.getNamespace(), flow.getId()); assertThat(full.isPresent()).isTrue(); full.ifPresent(current -> { @@ -159,14 +163,14 @@ public abstract class AbstractFlowRepositoryTest { @Test void findAll() { - List save = flowRepository.findAll(null); + List save = flowRepository.findAll(MAIN_TENANT); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT); } @Test void findAllWithSource() { - List save = flowRepository.findAllWithSource(null); + List save = flowRepository.findAllWithSource(MAIN_TENANT); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT); } @@ -187,25 +191,25 @@ public abstract class AbstractFlowRepositoryTest { @Test void findByNamespace() { - List save = flowRepository.findByNamespace(null, "io.kestra.tests"); + List save = flowRepository.findByNamespace(MAIN_TENANT, "io.kestra.tests"); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT - 22); - save = flowRepository.findByNamespace(null, "io.kestra.tests2"); + save = flowRepository.findByNamespace(MAIN_TENANT, "io.kestra.tests2"); assertThat((long) save.size()).isEqualTo(1L); - save = flowRepository.findByNamespace(null, "io.kestra.tests.minimal.bis"); + save = flowRepository.findByNamespace(MAIN_TENANT, "io.kestra.tests.minimal.bis"); assertThat((long) save.size()).isEqualTo(1L); } @Test void findByNamespacePrefix() { - List save = flowRepository.findByNamespacePrefix(null, "io.kestra.tests"); + List save = flowRepository.findByNamespacePrefix(MAIN_TENANT, "io.kestra.tests"); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT - 1); - save = flowRepository.findByNamespace(null, "io.kestra.tests2"); + save = flowRepository.findByNamespace(MAIN_TENANT, "io.kestra.tests2"); assertThat((long) save.size()).isEqualTo(1L); - save = flowRepository.findByNamespace(null, "io.kestra.tests.minimal.bis"); + save = flowRepository.findByNamespace(MAIN_TENANT, "io.kestra.tests.minimal.bis"); assertThat((long) save.size()).isEqualTo(1L); } @@ -215,10 +219,10 @@ public abstract class AbstractFlowRepositoryTest { .revision(3) .build(); String flowSource = "# comment\n" + flow.sourceOrGenerateIfNull(); - flow = flowRepository.create(GenericFlow.fromYaml(null, flowSource)); + flow = flowRepository.create(GenericFlow.fromYaml(MAIN_TENANT, flowSource)); try { - List save = flowRepository.findByNamespaceWithSource(null, flow.getNamespace()); + List save = flowRepository.findByNamespaceWithSource(MAIN_TENANT, flow.getNamespace()); assertThat((long) save.size()).isEqualTo(1L); assertThat(save.getFirst().getSource()).isEqualTo(FlowService.cleanupSource(flowSource)); @@ -229,51 +233,51 @@ public abstract class AbstractFlowRepositoryTest { @Test protected void find() { - List save = flowRepository.find(Pageable.from(1, (int) Helpers.FLOWS_COUNT - 1, Sort.UNSORTED), null, null, null, null, null); + List save = flowRepository.find(Pageable.from(1, (int) Helpers.FLOWS_COUNT - 1, Sort.UNSORTED), null, MAIN_TENANT, null, null, null); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT - 1); - save = flowRepository.find(Pageable.from(1, (int) Helpers.FLOWS_COUNT + 1, Sort.UNSORTED), null, null, null, null, null); + save = flowRepository.find(Pageable.from(1, (int) Helpers.FLOWS_COUNT + 1, Sort.UNSORTED), null, MAIN_TENANT, null, null, null); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT); - save = flowRepository.find(Pageable.from(1), null, null, null, "io.kestra.tests.minimal.bis", Collections.emptyMap()); + save = flowRepository.find(Pageable.from(1), null, MAIN_TENANT, null, "io.kestra.tests.minimal.bis", Collections.emptyMap()); assertThat((long) save.size()).isEqualTo(1L); - save = flowRepository.find(Pageable.from(1, 100, Sort.UNSORTED), null, null, null, null, Map.of("country", "FR")); + save = flowRepository.find(Pageable.from(1, 100, Sort.UNSORTED), null, MAIN_TENANT, null, null, Map.of("country", "FR")); assertThat(save.size()).isEqualTo(1); - save = flowRepository.find(Pageable.from(1), null, null, null, "io.kestra.tests", Map.of("key2", "value2")); + save = flowRepository.find(Pageable.from(1), null, MAIN_TENANT, null, "io.kestra.tests", Map.of("key2", "value2")); assertThat((long) save.size()).isEqualTo(1L); - save = flowRepository.find(Pageable.from(1), null, null, null, "io.kestra.tests", Map.of("key1", "value2")); + save = flowRepository.find(Pageable.from(1), null, MAIN_TENANT, null, "io.kestra.tests", Map.of("key1", "value2")); assertThat((long) save.size()).isEqualTo(0L); } @Test protected void findSpecialChars() { - ArrayListTotal> save = flowRepository.findSourceCode(Pageable.unpaged(), "https://api.chucknorris.io", null, null); + ArrayListTotal> save = flowRepository.findSourceCode(Pageable.unpaged(), "https://api.chucknorris.io", MAIN_TENANT, null); assertThat((long) save.size()).isEqualTo(2L); } @Test void findWithSource() { - List save = flowRepository.findWithSource(null, null, null, "io.kestra.tests", Collections.emptyMap()); + List save = flowRepository.findWithSource(null, MAIN_TENANT, null, "io.kestra.tests", Collections.emptyMap()); assertThat((long) save.size()).isEqualTo(Helpers.FLOWS_COUNT - 1); - save = flowRepository.findWithSource(null, null, null, "io.kestra.tests2", Collections.emptyMap()); + save = flowRepository.findWithSource(null, MAIN_TENANT, null, "io.kestra.tests2", Collections.emptyMap()); assertThat((long) save.size()).isEqualTo(1L); - save = flowRepository.findWithSource(null, null, null, "io.kestra.tests.minimal.bis", Collections.emptyMap()); + save = flowRepository.findWithSource(null, MAIN_TENANT, null, "io.kestra.tests.minimal.bis", Collections.emptyMap()); assertThat((long) save.size()).isEqualTo(1L); } @Test void delete() { - Flow flow = builder().build(); + Flow flow = builder().tenantId(MAIN_TENANT).build(); FlowWithSource save = flowRepository.create(GenericFlow.of(flow)); try { - assertThat(flowRepository.findById(null, save.getNamespace(), save.getId()).isPresent()).isTrue(); + assertThat(flowRepository.findById(MAIN_TENANT, save.getNamespace(), save.getId()).isPresent()).isTrue(); } catch (Throwable e) { deleteFlow(save); throw e; @@ -281,10 +285,10 @@ public abstract class AbstractFlowRepositoryTest { Flow delete = flowRepository.delete(save); - assertThat(flowRepository.findById(null, flow.getNamespace(), flow.getId()).isPresent()).isFalse(); - assertThat(flowRepository.findById(null, flow.getNamespace(), flow.getId(), Optional.of(save.getRevision())).isPresent()).isTrue(); + assertThat(flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId()).isPresent()).isFalse(); + assertThat(flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId(), Optional.of(save.getRevision())).isPresent()).isTrue(); - List revisions = flowRepository.findRevisions(null, flow.getNamespace(), flow.getId()); + List revisions = flowRepository.findRevisions(MAIN_TENANT, flow.getNamespace(), flow.getId()); assertThat(revisions.getLast().getRevision()).isEqualTo(delete.getRevision()); } @@ -295,6 +299,7 @@ public abstract class AbstractFlowRepositoryTest { Flow flow = Flow.builder() .id(flowId) .namespace(TEST_NAMESPACE) + .tenantId(MAIN_TENANT) .inputs(List.of(StringInput.builder().type(Type.STRING).id("a").build())) .tasks(Collections.singletonList(Return.builder().id(TEST_FLOW_ID).type(Return.class.getName()).format(Property.of(TEST_FLOW_ID)).build())) .build(); @@ -302,11 +307,12 @@ public abstract class AbstractFlowRepositoryTest { Flow save = flowRepository.create(GenericFlow.of(flow)); try { - assertThat(flowRepository.findById(null, flow.getNamespace(), flow.getId()).isPresent()).isTrue(); + assertThat(flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId()).isPresent()).isTrue(); Flow update = Flow.builder() .id(IdUtils.create()) .namespace("io.kestra.unittest2") + .tenantId(MAIN_TENANT) .inputs(List.of(StringInput.builder().type(Type.STRING).id("b").build())) .tasks(Collections.singletonList(Return.builder().id(TEST_FLOW_ID).type(Return.class.getName()).format(Property.of(TEST_FLOW_ID)).build())) .build(); @@ -330,6 +336,7 @@ public abstract class AbstractFlowRepositoryTest { Flow flow = Flow.builder() .id(flowId) .namespace(TEST_NAMESPACE) + .tenantId(MAIN_TENANT) .triggers(Collections.singletonList(AbstractSchedulerTest.UnitTest.builder() .id("sleep") .type(AbstractSchedulerTest.UnitTest.class.getName()) @@ -339,11 +346,12 @@ public abstract class AbstractFlowRepositoryTest { flow = flowRepository.create(GenericFlow.of(flow)); try { - assertThat(flowRepository.findById(null, flow.getNamespace(), flow.getId()).isPresent()).isTrue(); + assertThat(flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId()).isPresent()).isTrue(); Flow update = Flow.builder() .id(flowId) .namespace(TEST_NAMESPACE) + .tenantId(MAIN_TENANT) .tasks(Collections.singletonList(Return.builder().id(TEST_FLOW_ID).type(Return.class.getName()).format(Property.of(TEST_FLOW_ID)).build())) .build(); ; @@ -362,12 +370,13 @@ public abstract class AbstractFlowRepositoryTest { @Test - void removeTriggerDelete() throws TimeoutException, QueueException { + void removeTriggerDelete() throws TimeoutException { String flowId = IdUtils.create(); Flow flow = Flow.builder() .id(flowId) .namespace(TEST_NAMESPACE) + .tenantId(MAIN_TENANT) .triggers(Collections.singletonList(AbstractSchedulerTest.UnitTest.builder() .id("sleep") .type(AbstractSchedulerTest.UnitTest.class.getName()) @@ -377,7 +386,7 @@ public abstract class AbstractFlowRepositoryTest { Flow save = flowRepository.create(GenericFlow.of(flow)); try { - assertThat(flowRepository.findById(null, flow.getNamespace(), flow.getId()).isPresent()).isTrue(); + assertThat(flowRepository.findById(MAIN_TENANT, flow.getNamespace(), flow.getId()).isPresent()).isTrue(); } finally { deleteFlow(save); } @@ -389,45 +398,10 @@ public abstract class AbstractFlowRepositoryTest { @Test void findDistinctNamespace() { - List distinctNamespace = flowRepository.findDistinctNamespace(null); + List distinctNamespace = flowRepository.findDistinctNamespace(MAIN_TENANT); assertThat((long) distinctNamespace.size()).isEqualTo(8L); } - @SuppressWarnings("deprecation") - @Test - void templateDisabled() { - Template template = Template.builder() - .id(IdUtils.create()) - .type(Template.class.getName()) - .namespace(TEST_FLOW_ID) - .templateId("testTemplate") - .build(); - - Template templateSpy = spy(template); - - doReturn(Collections.emptyList()) - .when(templateSpy) - .allChildTasks(); - - Flow flow = Flow.builder() - .id(IdUtils.create()) - .namespace(TEST_NAMESPACE) - .tasks(Collections.singletonList(templateSpy)) - .build(); - - flow = flowRepository.create(GenericFlow.of(flow)); - - try { - Optional found = flowRepository.findById(null, flow.getNamespace(), flow.getId()); - - assertThat(found.isPresent()).isTrue(); - assertThat(found.get() instanceof FlowWithException).isTrue(); - assertThat(((FlowWithException) found.get()).getException()).contains("Templates are disabled"); - } finally { - deleteFlow(flow); - } - } - @Test protected void shouldReturnNullRevisionForNonExistingFlow() { assertThat(flowRepository.lastRevision(TEST_TENANT_ID, TEST_NAMESPACE, IdUtils.create())).isNull(); @@ -583,7 +557,7 @@ public abstract class AbstractFlowRepositoryTest { @Test void shouldReturnForFindGivenQueryWildcard() { - ArrayListTotal flows = flowRepository.find(Pageable.from(1, 10), "*", null, null, null, Map.of()); + ArrayListTotal flows = flowRepository.find(Pageable.from(1, 10), "*", MAIN_TENANT, null, null, Map.of()); assertThat(flows.size()).isEqualTo(10); assertThat(flows.getTotal()).isEqualTo(Helpers.FLOWS_COUNT); } @@ -593,7 +567,7 @@ public abstract class AbstractFlowRepositoryTest { List filters = List.of( QueryFilter.builder().field(QueryFilter.Field.QUERY).operation(QueryFilter.Op.EQUALS).value("*").build() ); - ArrayListTotal flows = flowRepository.find(Pageable.from(1, 10), null, filters); + ArrayListTotal flows = flowRepository.find(Pageable.from(1, 10), MAIN_TENANT, filters); assertThat(flows.size()).isEqualTo(10); assertThat(flows.getTotal()).isEqualTo(Helpers.FLOWS_COUNT); } @@ -601,12 +575,14 @@ public abstract class AbstractFlowRepositoryTest { @Test void findByExecution() { Flow flow = builder() + .tenantId(MAIN_TENANT) .revision(1) .build(); flowRepository.create(GenericFlow.of(flow)); Execution execution = Execution.builder() .id(IdUtils.create()) .namespace(flow.getNamespace()) + .tenantId(MAIN_TENANT) .flowId(flow.getId()) .flowRevision(flow.getRevision()) .state(new State()) @@ -667,7 +643,7 @@ public abstract class AbstractFlowRepositoryTest { Flow flow = createTestFlowForNamespace(TEST_NAMESPACE); toDelete = flowRepository.create(GenericFlow.of(flow)); // When - int count = flowRepository.count(null); + int count = flowRepository.count(MAIN_TENANT); // Then Assertions.assertTrue(count > 0); @@ -686,10 +662,10 @@ public abstract class AbstractFlowRepositoryTest { toDelete.add(flowRepository.create(GenericFlow.of(createTestFlowForNamespace("io.kestra.unittest.shouldcountbynamespacefornulltenant")))); toDelete.add(flowRepository.create(GenericFlow.of(createTestFlowForNamespace("com.kestra.unittest")))); - int count = flowRepository.countForNamespace(null, "io.kestra.unittest.shouldcountbynamespacefornulltenant"); + int count = flowRepository.countForNamespace(MAIN_TENANT, "io.kestra.unittest.shouldcountbynamespacefornulltenant"); assertThat(count).isEqualTo(1); - count = flowRepository.countForNamespace(null, TEST_NAMESPACE); + count = flowRepository.countForNamespace(MAIN_TENANT, TEST_NAMESPACE); assertThat(count).isEqualTo(2); } finally { for (FlowWithSource flow : toDelete) { @@ -702,6 +678,7 @@ public abstract class AbstractFlowRepositoryTest { return Flow.builder() .id(IdUtils.create()) .namespace(namespace) + .tenantId(MAIN_TENANT) .tasks(List.of(Return.builder() .id(IdUtils.create()) .type(Return.class.getName()) @@ -710,7 +687,7 @@ public abstract class AbstractFlowRepositoryTest { .build(); } - private void deleteFlow(Flow flow) { + protected void deleteFlow(Flow flow) { if (flow == null) { return; } diff --git a/core/src/test/java/io/kestra/core/repositories/ExecutionFixture.java b/core/src/test/java/io/kestra/core/repositories/ExecutionFixture.java index 0bf04f9c7f..990a7b9162 100644 --- a/core/src/test/java/io/kestra/core/repositories/ExecutionFixture.java +++ b/core/src/test/java/io/kestra/core/repositories/ExecutionFixture.java @@ -1,5 +1,7 @@ package io.kestra.core.repositories; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import com.google.common.collect.ImmutableMap; import io.kestra.core.models.executions.*; import io.kestra.core.models.flows.State; @@ -12,6 +14,7 @@ class ExecutionFixture { public static final Execution EXECUTION_1 = Execution.builder() .id(IdUtils.create()) .namespace("io.kestra.unittest") + .tenantId(MAIN_TENANT) .flowId("full") .flowRevision(1) .state(new State()) @@ -36,6 +39,7 @@ class ExecutionFixture { public static final Execution EXECUTION_2 = Execution.builder() .id(IdUtils.create()) .namespace("io.kestra.unittest") + .tenantId(MAIN_TENANT) .flowId("full") .flowRevision(1) .state(new State()) diff --git a/core/src/test/java/io/kestra/core/runners/AbstractRunnerTest.java b/core/src/test/java/io/kestra/core/runners/AbstractRunnerTest.java index f75885a52b..84aeac4f61 100644 --- a/core/src/test/java/io/kestra/core/runners/AbstractRunnerTest.java +++ b/core/src/test/java/io/kestra/core/runners/AbstractRunnerTest.java @@ -1,5 +1,6 @@ package io.kestra.core.runners; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.ExecuteFlow; @@ -42,7 +43,7 @@ public abstract class AbstractRunnerTest { private RestartCaseTest restartCaseTest; @Inject - private FlowTriggerCaseTest flowTriggerCaseTest; + protected FlowTriggerCaseTest flowTriggerCaseTest; @Inject protected MultipleConditionTriggerCaseTest multipleConditionTriggerCaseTest; @@ -494,7 +495,7 @@ public abstract class AbstractRunnerTest { @Test @LoadFlows({"flows/valids/if.yaml"}) void multipleIf() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "if", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if", null, (f, e) -> Map.of("if1", true, "if2", false, "if3", true)); assertThat(execution.getTaskRunList()).hasSize(12); diff --git a/core/src/test/java/io/kestra/core/runners/ChangeStateTestCase.java b/core/src/test/java/io/kestra/core/runners/ChangeStateTestCase.java index 13995d926a..4082593e02 100644 --- a/core/src/test/java/io/kestra/core/runners/ChangeStateTestCase.java +++ b/core/src/test/java/io/kestra/core/runners/ChangeStateTestCase.java @@ -17,6 +17,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @Singleton @@ -74,7 +75,7 @@ public class ChangeStateTestCase { }); // run the parent flow - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "subflow-parent-of-failed"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "subflow-parent-of-failed"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat(execution.getTaskRunList()).hasSize(1); assertThat(execution.getTaskRunList().getFirst().getState().getCurrent()).isEqualTo(State.Type.FAILED); diff --git a/core/src/test/java/io/kestra/core/runners/DefaultRunContextTest.java b/core/src/test/java/io/kestra/core/runners/DefaultRunContextTest.java index 50ec854407..2abb60ea21 100644 --- a/core/src/test/java/io/kestra/core/runners/DefaultRunContextTest.java +++ b/core/src/test/java/io/kestra/core/runners/DefaultRunContextTest.java @@ -1,5 +1,6 @@ package io.kestra.core.runners; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.encryption.EncryptionService; import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.models.tasks.common.EncryptedString; @@ -25,7 +26,7 @@ class DefaultRunContextTest { private String secretKey; @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void shouldGetKestraVersion() { diff --git a/core/src/test/java/io/kestra/core/runners/EmptyVariablesTest.java b/core/src/test/java/io/kestra/core/runners/EmptyVariablesTest.java index 03ef4c5a96..0018d55436 100644 --- a/core/src/test/java/io/kestra/core/runners/EmptyVariablesTest.java +++ b/core/src/test/java/io/kestra/core/runners/EmptyVariablesTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -25,7 +26,7 @@ public class EmptyVariablesTest { @LoadFlows({"flows/valids/empty-variables.yml"}) void emptyVariables() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "empty-variables", null, diff --git a/core/src/test/java/io/kestra/core/runners/ExecutionServiceTest.java b/core/src/test/java/io/kestra/core/runners/ExecutionServiceTest.java index b12b45fbcf..eea3364d2b 100644 --- a/core/src/test/java/io/kestra/core/runners/ExecutionServiceTest.java +++ b/core/src/test/java/io/kestra/core/runners/ExecutionServiceTest.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; @@ -56,7 +57,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/restart_last_failed.yaml"}) void restartSimple() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "restart_last_failed"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "restart_last_failed"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -75,11 +76,11 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/restart_last_failed.yaml"}) void restartSimpleRevision() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "restart_last_failed"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "restart_last_failed"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); - FlowWithSource flow = flowRepository.findByIdWithSource(null, "io.kestra.tests", "restart_last_failed").orElseThrow(); + FlowWithSource flow = flowRepository.findByIdWithSource(MAIN_TENANT, "io.kestra.tests", "restart_last_failed").orElseThrow(); flowRepository.update( GenericFlow.of(flow), flow.updateTask( @@ -108,7 +109,7 @@ class ExecutionServiceTest { @RetryingTest(5) @LoadFlows({"flows/valids/restart-each.yaml"}) void restartFlowable() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "restart-each", null, (f, e) -> ImmutableMap.of("failed", "FIRST")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "restart-each", null, (f, e) -> ImmutableMap.of("failed", "FIRST")); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); Execution restart = executionService.restart(execution, null); @@ -124,7 +125,7 @@ class ExecutionServiceTest { @RetryingTest(5) @LoadFlows({"flows/valids/restart-each.yaml"}) void restartFlowable2() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "restart-each", null, (f, e) -> ImmutableMap.of("failed", "SECOND")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "restart-each", null, (f, e) -> ImmutableMap.of("failed", "SECOND")); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); Execution restart = executionService.restart(execution, null); @@ -140,7 +141,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/working-directory.yaml"}) void restartDynamic() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory", null, (f, e) -> ImmutableMap.of("failed", "true")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory", null, (f, e) -> ImmutableMap.of("failed", "true")); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -156,7 +157,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/logs.yaml"}) void replayFromBeginning() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "logs"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "logs"); assertThat(execution.getTaskRunList()).hasSize(5); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -177,7 +178,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/logs.yaml"}) void replaySimple() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "logs"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "logs"); assertThat(execution.getTaskRunList()).hasSize(5); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -196,7 +197,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/restart-each.yaml"}) void replayFlowable() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "restart-each", null, (f, e) -> ImmutableMap.of("failed", "NO")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "restart-each", null, (f, e) -> ImmutableMap.of("failed", "NO")); assertThat(execution.getTaskRunList()).hasSize(20); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -214,7 +215,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/parallel-nested.yaml"}) void replayParallel() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "parallel-nested"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "parallel-nested"); assertThat(execution.getTaskRunList()).hasSize(11); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -272,7 +273,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/dynamic-task.yaml"}) void replayWithADynamicTask() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "dynamic-task"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "dynamic-task"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -292,7 +293,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/each-parallel-nested.yaml"}) void replayEachPara() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "each-parallel-nested"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "each-parallel-nested"); assertThat(execution.getTaskRunList()).hasSize(11); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -312,7 +313,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/each-parallel-nested.yaml"}) void markAsEachPara() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "each-parallel-nested"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "each-parallel-nested"); Flow flow = flowRepository.findByExecution(execution); assertThat(execution.getTaskRunList()).hasSize(11); @@ -344,7 +345,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/pause.yaml"}) void resumePausedToRunning() throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause"); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause"); Flow flow = flowRepository.findByExecution(execution); assertThat(execution.getTaskRunList()).hasSize(1); @@ -364,7 +365,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/pause.yaml"}) void resumePausedToKilling() throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause"); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause"); Flow flow = flowRepository.findByExecution(execution); assertThat(execution.getTaskRunList()).hasSize(1); @@ -403,7 +404,7 @@ class ExecutionServiceTest { @Test @LoadFlows({"flows/valids/pause_no_tasks.yaml"}) void shouldKillPausedExecutions() throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause_no_tasks"); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause_no_tasks"); Flow flow = flowRepository.findByExecution(execution); assertThat(execution.getTaskRunList()).hasSize(1); diff --git a/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java b/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java index fc777fb750..a6bc3b7673 100644 --- a/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java +++ b/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java @@ -1,5 +1,6 @@ package io.kestra.core.runners; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import jakarta.inject.Inject; import org.apache.commons.io.FileUtils; @@ -14,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; @KestraTest class FilesServiceTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void overrideExistingInputFile() throws Exception { diff --git a/core/src/test/java/io/kestra/core/runners/FlowConcurrencyCaseTest.java b/core/src/test/java/io/kestra/core/runners/FlowConcurrencyCaseTest.java index 4971626803..8d550184cf 100644 --- a/core/src/test/java/io/kestra/core/runners/FlowConcurrencyCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/FlowConcurrencyCaseTest.java @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,8 +38,8 @@ public class FlowConcurrencyCaseTest { protected QueueInterface executionQueue; public void flowConcurrencyCancel() throws TimeoutException, QueueException, InterruptedException { - Execution execution1 = runnerUtils.runOneUntilRunning(null, "io.kestra.tests", "flow-concurrency-cancel", null, null, Duration.ofSeconds(30)); - Execution execution2 = runnerUtils.runOne(null, "io.kestra.tests", "flow-concurrency-cancel"); + Execution execution1 = runnerUtils.runOneUntilRunning(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-cancel", null, null, Duration.ofSeconds(30)); + Execution execution2 = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-cancel"); assertThat(execution1.getState().isRunning()).isTrue(); assertThat(execution2.getState().getCurrent()).isEqualTo(State.Type.CANCELLED); @@ -60,8 +61,8 @@ public class FlowConcurrencyCaseTest { } public void flowConcurrencyFail() throws TimeoutException, QueueException, InterruptedException { - Execution execution1 = runnerUtils.runOneUntilRunning(null, "io.kestra.tests", "flow-concurrency-fail", null, null, Duration.ofSeconds(30)); - Execution execution2 = runnerUtils.runOne(null, "io.kestra.tests", "flow-concurrency-fail"); + Execution execution1 = runnerUtils.runOneUntilRunning(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-fail", null, null, Duration.ofSeconds(30)); + Execution execution2 = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-fail"); assertThat(execution1.getState().isRunning()).isTrue(); assertThat(execution2.getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -83,9 +84,9 @@ public class FlowConcurrencyCaseTest { } public void flowConcurrencyQueue() throws TimeoutException, QueueException, InterruptedException { - Execution execution1 = runnerUtils.runOneUntilRunning(null, "io.kestra.tests", "flow-concurrency-queue", null, null, Duration.ofSeconds(30)); + Execution execution1 = runnerUtils.runOneUntilRunning(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-queue", null, null, Duration.ofSeconds(30)); Flow flow = flowRepository - .findById(null, "io.kestra.tests", "flow-concurrency-queue", Optional.empty()) + .findById(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-queue", Optional.empty()) .orElseThrow(); Execution execution2 = Execution.newExecution(flow, null, null, Optional.empty()); executionQueue.emit(execution2); @@ -163,9 +164,9 @@ public class FlowConcurrencyCaseTest { }); - Execution execution1 = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "flow-concurrency-queue-pause"); + Execution execution1 = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-queue-pause"); Flow flow = flowRepository - .findById(null, "io.kestra.tests", "flow-concurrency-queue-pause", Optional.empty()) + .findById(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-queue-pause", Optional.empty()) .orElseThrow(); Execution execution2 = Execution.newExecution(flow, null, null, Optional.empty()); executionQueue.emit(execution2); @@ -215,9 +216,9 @@ public class FlowConcurrencyCaseTest { } }); - Execution execution1 = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "flow-concurrency-cancel-pause"); + Execution execution1 = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-cancel-pause"); Flow flow = flowRepository - .findById(null, "io.kestra.tests", "flow-concurrency-cancel-pause", Optional.empty()) + .findById(MAIN_TENANT, "io.kestra.tests", "flow-concurrency-cancel-pause", Optional.empty()) .orElseThrow(); Execution execution2 = Execution.newExecution(flow, null, null, Optional.empty()); executionQueue.emit(execution2); diff --git a/core/src/test/java/io/kestra/core/runners/FlowListenersTest.java b/core/src/test/java/io/kestra/core/runners/FlowListenersTest.java index e11ce2be73..c735b2cbe3 100644 --- a/core/src/test/java/io/kestra/core/runners/FlowListenersTest.java +++ b/core/src/test/java/io/kestra/core/runners/FlowListenersTest.java @@ -1,6 +1,5 @@ package io.kestra.core.runners; -import io.kestra.core.models.flows.FlowInterface; import io.kestra.core.models.flows.FlowWithSource; import io.kestra.core.models.flows.GenericFlow; import io.kestra.core.models.property.Property; @@ -17,6 +16,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import jakarta.inject.Inject; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -28,6 +28,7 @@ abstract public class FlowListenersTest { FlowWithSource flow = FlowWithSource.builder() .id(flowId) .namespace("io.kestra.unittest") + .tenantId(MAIN_TENANT) .revision(1) .tasks(Collections.singletonList(Return.builder() .id(taskId) diff --git a/core/src/test/java/io/kestra/core/runners/FlowTriggerCaseTest.java b/core/src/test/java/io/kestra/core/runners/FlowTriggerCaseTest.java index 566e0becf2..b04342361c 100644 --- a/core/src/test/java/io/kestra/core/runners/FlowTriggerCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/FlowTriggerCaseTest.java @@ -1,7 +1,6 @@ package io.kestra.core.runners; import io.kestra.core.models.executions.Execution; -import io.kestra.core.models.executions.LogEntry; import io.kestra.core.models.flows.State; import io.kestra.core.queues.QueueException; import io.kestra.core.queues.QueueFactoryInterface; @@ -19,6 +18,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -53,7 +53,7 @@ public class FlowTriggerCaseTest { } }); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger", "trigger-flow"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-flow"); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -97,7 +97,7 @@ public class FlowTriggerCaseTest { } }); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.pause", "trigger-flow-with-pause"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.pause", "trigger-flow-with-pause"); assertThat(execution.getTaskRunList().size()).isEqualTo(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); diff --git a/core/src/test/java/io/kestra/core/runners/InputsTest.java b/core/src/test/java/io/kestra/core/runners/InputsTest.java index 72f4418a84..a1e4ffbe54 100644 --- a/core/src/test/java/io/kestra/core/runners/InputsTest.java +++ b/core/src/test/java/io/kestra/core/runners/InputsTest.java @@ -34,6 +34,7 @@ import java.time.LocalTime; import java.util.*; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -91,7 +92,7 @@ public class InputsTest { private FlowInputOutput flowInputOutput; private Map typedInputs(Map map) { - return typedInputs(map, flowRepository.findById(null, "io.kestra.tests", "inputs").get()); + return typedInputs(map, flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "inputs").get()); } private Map typedInputs(Map map, Flow flow) { @@ -100,6 +101,7 @@ public class InputsTest { Execution.builder() .id("test") .namespace(flow.getNamespace()) + .tenantId(MAIN_TENANT) .flowRevision(1) .flowId(flow.getId()) .build(), @@ -142,7 +144,7 @@ public class InputsTest { assertThat(typeds.get("time")).isEqualTo(LocalTime.parse("18:27:49")); assertThat(typeds.get("duration")).isEqualTo(Duration.parse("PT5M6S")); assertThat((URI) typeds.get("file")).isEqualTo(new URI("kestra:///io/kestra/tests/inputs/executions/test/inputs/file/application-test.yml")); - assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(null, null, (URI) typeds.get("file"))))).isEqualTo(CharStreams.toString(new InputStreamReader(new FileInputStream((String) inputs.get("file"))))); + assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(MAIN_TENANT, null, (URI) typeds.get("file"))))).isEqualTo(CharStreams.toString(new InputStreamReader(new FileInputStream((String) inputs.get("file"))))); assertThat(typeds.get("json")).isEqualTo(Map.of("a", "b")); assertThat(typeds.get("uri")).isEqualTo("https://www.google.com"); assertThat(((Map) typeds.get("nested")).get("string")).isEqualTo("a string"); @@ -183,7 +185,7 @@ public class InputsTest { @LoadFlows({"flows/valids/inputs.yaml"}) void inputFlow() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "inputs", null, @@ -358,7 +360,7 @@ public class InputsTest { map.put("json", "{}"); Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "inputs", null, @@ -379,7 +381,7 @@ public class InputsTest { Flux receive = TestsUtils.receive(logQueue, l -> {}); Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "input-log-secret", null, diff --git a/core/src/test/java/io/kestra/core/runners/ListenersTest.java b/core/src/test/java/io/kestra/core/runners/ListenersTest.java index 2b6c93378e..bbeaf35170 100644 --- a/core/src/test/java/io/kestra/core/runners/ListenersTest.java +++ b/core/src/test/java/io/kestra/core/runners/ListenersTest.java @@ -15,6 +15,7 @@ import java.net.URISyntaxException; import java.util.Objects; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -28,17 +29,17 @@ class ListenersTest { @BeforeEach void initListeners() throws IOException, URISyntaxException { - repositoryLoader.load(null, Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners.yaml"))); - repositoryLoader.load(null, Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-flowable.yaml"))); - repositoryLoader.load(null, Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-multiple.yaml"))); - repositoryLoader.load(null, Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-multiple-failed.yaml"))); - repositoryLoader.load(null, Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-failed.yaml"))); + repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners.yaml"))); + repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-flowable.yaml"))); + repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-multiple.yaml"))); + repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-multiple-failed.yaml"))); + repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/listeners-failed.yaml"))); } @Test void success() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "listeners", null, @@ -53,7 +54,7 @@ class ListenersTest { @Test void failed() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "listeners", null, @@ -68,7 +69,7 @@ class ListenersTest { @Test void flowableExecution() throws TimeoutException, QueueException{ Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "listeners-flowable", null, @@ -84,7 +85,7 @@ class ListenersTest { @Test void multipleListeners() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "listeners-multiple" ); @@ -97,7 +98,7 @@ class ListenersTest { @Test void failedListeners() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "listeners-failed" ); @@ -111,7 +112,7 @@ class ListenersTest { @Test void failedMultipleListeners() throws TimeoutException, QueueException{ Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "listeners-multiple-failed" ); diff --git a/core/src/test/java/io/kestra/core/runners/ListenersTestTask.java b/core/src/test/java/io/kestra/core/runners/ListenersTestTask.java index e9dc44f26e..a5973eaa12 100644 --- a/core/src/test/java/io/kestra/core/runners/ListenersTestTask.java +++ b/core/src/test/java/io/kestra/core/runners/ListenersTestTask.java @@ -1,5 +1,7 @@ package io.kestra.core.runners; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import io.kestra.core.models.tasks.retrys.Exponential; import io.kestra.core.repositories.ExecutionRepositoryInterface; import io.kestra.core.utils.RetryUtils; @@ -37,7 +39,7 @@ public class ListenersTestTask extends Task implements RunnableTask executionRepository.findById(null, executionRendererId) + () -> executionRepository.findById(MAIN_TENANT, executionRendererId) .filter(e -> e.getState().getCurrent().isTerminated()) .orElseThrow(() -> new NoSuchElementException("Unable to find execution '" + executionRendererId + "'")) ); diff --git a/core/src/test/java/io/kestra/core/runners/LogToFileTest.java b/core/src/test/java/io/kestra/core/runners/LogToFileTest.java index ce7b081457..4c66f5c8c1 100644 --- a/core/src/test/java/io/kestra/core/runners/LogToFileTest.java +++ b/core/src/test/java/io/kestra/core/runners/LogToFileTest.java @@ -15,6 +15,7 @@ import java.nio.charset.StandardCharsets; import java.util.List; import org.junit.jupiter.api.Test; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -32,7 +33,7 @@ public class LogToFileTest { TaskRunAttempt attempt = taskRun.getAttempts().getFirst(); assertThat(attempt.getLogFile()).isNotNull(); - InputStream inputStream = storage.get(null, "io.kestra.tests", attempt.getLogFile()); + InputStream inputStream = storage.get(MAIN_TENANT, "io.kestra.tests", attempt.getLogFile()); List strings = IOUtils.readLines(inputStream, StandardCharsets.UTF_8); assertThat(strings).isNotNull(); assertThat(strings.size()).isEqualTo(1); diff --git a/core/src/test/java/io/kestra/core/runners/MultipleConditionTriggerCaseTest.java b/core/src/test/java/io/kestra/core/runners/MultipleConditionTriggerCaseTest.java index ff9a2d9cea..6ae0e3c00c 100644 --- a/core/src/test/java/io/kestra/core/runners/MultipleConditionTriggerCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/MultipleConditionTriggerCaseTest.java @@ -24,6 +24,7 @@ import jakarta.inject.Named; import jakarta.inject.Singleton; import reactor.core.publisher.Flux; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -60,7 +61,7 @@ public class MultipleConditionTriggerCaseTest { }); // first one - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger", + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-multiplecondition-flow-a", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -70,7 +71,7 @@ public class MultipleConditionTriggerCaseTest { assertThat(ended.size()).isEqualTo(1); // second one - execution = runnerUtils.runOne(null, "io.kestra.tests.trigger", + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-multiplecondition-flow-b", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -80,7 +81,7 @@ public class MultipleConditionTriggerCaseTest { receive.blockLast(); assertThat(ended.size()).isEqualTo(3); - Flow flow = flowRepository.findById(null, "io.kestra.tests.trigger", + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-multiplecondition-listener").orElseThrow(); Execution triggerExecution = ended.entrySet() .stream() @@ -110,7 +111,7 @@ public class MultipleConditionTriggerCaseTest { }); // first one - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger", + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-multiplecondition-flow-c", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -120,7 +121,7 @@ public class MultipleConditionTriggerCaseTest { assertThat(listener.get()).isNull(); // second one - execution = runnerUtils.runOne(null, "io.kestra.tests.trigger", + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-multiplecondition-flow-d", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -147,17 +148,17 @@ public class MultipleConditionTriggerCaseTest { }); // flowA - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.preconditions", + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.preconditions", "flow-trigger-preconditions-flow-a", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); // flowB: we trigger it two times, as flow-trigger-flow-preconditions-flow-listen is configured with resetOnSuccess: false it should be triggered two times - execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.preconditions", + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.preconditions", "flow-trigger-preconditions-flow-a", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.preconditions", + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.preconditions", "flow-trigger-preconditions-flow-b", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -189,13 +190,13 @@ public class MultipleConditionTriggerCaseTest { }); // flowB - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.preconditions", + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.preconditions", "flow-trigger-preconditions-flow-b", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); // flowA - execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.preconditions", + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.preconditions", "flow-trigger-preconditions-flow-a", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -226,7 +227,7 @@ public class MultipleConditionTriggerCaseTest { } }); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger.paused", + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger.paused", "flow-trigger-paused-flow", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList().size()).isEqualTo(2); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); diff --git a/core/src/test/java/io/kestra/core/runners/NoEncryptionConfiguredTest.java b/core/src/test/java/io/kestra/core/runners/NoEncryptionConfiguredTest.java index 1ffb3c3223..3b35cf656d 100644 --- a/core/src/test/java/io/kestra/core/runners/NoEncryptionConfiguredTest.java +++ b/core/src/test/java/io/kestra/core/runners/NoEncryptionConfiguredTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.TestInstance; import java.util.HashMap; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -59,12 +60,13 @@ public class NoEncryptionConfiguredTest implements TestPropertyProvider { @Test @LoadFlows({"flows/valids/inputs.yaml"}) void secretInput() { - assertThat(flowRepository.findById(null, "io.kestra.tests", "inputs").isPresent()).isTrue(); + assertThat(flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "inputs").isPresent()).isTrue(); - Flow flow = flowRepository.findById(null, "io.kestra.tests", "inputs").get(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "inputs").get(); Execution execution = Execution.builder() .id("test") .namespace(flow.getNamespace()) + .tenantId(MAIN_TENANT) .flowRevision(1) .flowId(flow.getId()) .build(); diff --git a/core/src/test/java/io/kestra/core/runners/NullOutputTest.java b/core/src/test/java/io/kestra/core/runners/NullOutputTest.java index a9220f382f..922fbe1f8b 100644 --- a/core/src/test/java/io/kestra/core/runners/NullOutputTest.java +++ b/core/src/test/java/io/kestra/core/runners/NullOutputTest.java @@ -1,17 +1,15 @@ package io.kestra.core.runners; +import io.kestra.core.junit.annotations.ExecuteFlow; import io.kestra.core.junit.annotations.KestraTest; -import io.kestra.core.junit.annotations.LoadFlows; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.State; -import io.kestra.core.queues.QueueException; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URISyntaxException; -import java.util.concurrent.TimeoutException; import static org.assertj.core.api.Assertions.assertThat; @@ -20,9 +18,6 @@ public class NullOutputTest { @Inject protected StandAloneRunner runner; - @Inject - protected RunnerUtils runnerUtils; - @BeforeEach protected void init() throws IOException, URISyntaxException { if (!runner.isRunning()) { @@ -31,10 +26,8 @@ public class NullOutputTest { } @Test - @LoadFlows("flows/valids/null-output.yaml") - void shouldIncludeNullOutput() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "null-output"); - + @ExecuteFlow("flows/valids/null-output.yaml") + void shouldIncludeNullOutput(Execution execution){ assertThat(execution).isNotNull(); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList()).hasSize(1); diff --git a/core/src/test/java/io/kestra/core/runners/PluginDefaultsCaseTest.java b/core/src/test/java/io/kestra/core/runners/PluginDefaultsCaseTest.java index 5d9121f647..0817904229 100644 --- a/core/src/test/java/io/kestra/core/runners/PluginDefaultsCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/PluginDefaultsCaseTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.concurrent.TimeoutException; import java.util.stream.Stream; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @Singleton @@ -32,7 +33,7 @@ public class PluginDefaultsCaseTest { private RunnerUtils runnerUtils; public void taskDefaults() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "plugin-defaults", Duration.ofSeconds(60)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "plugin-defaults", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList()).hasSize(8); diff --git a/core/src/test/java/io/kestra/core/runners/RestartCaseTest.java b/core/src/test/java/io/kestra/core/runners/RestartCaseTest.java index 44db24a4ed..22a6f2c82e 100644 --- a/core/src/test/java/io/kestra/core/runners/RestartCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/RestartCaseTest.java @@ -23,6 +23,8 @@ import jakarta.inject.Inject; import jakarta.inject.Named; import jakarta.inject.Singleton; import reactor.core.publisher.Flux; + +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static io.kestra.core.utils.Rethrow.throwRunnable; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -43,9 +45,9 @@ public class RestartCaseTest { private QueueInterface executionQueue; public void restartFailedThenSuccess() throws Exception { - Flow flow = flowRepository.findById(null, "io.kestra.tests", "restart_last_failed").orElseThrow(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "restart_last_failed").orElseThrow(); - Execution firstExecution = runnerUtils.runOne(null, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); + Execution firstExecution = runnerUtils.runOne(MAIN_TENANT, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); assertThat(firstExecution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat(firstExecution.getTaskRunList()).hasSize(3); @@ -82,9 +84,9 @@ public class RestartCaseTest { } public void restartFailedThenFailureWithGlobalErrors() throws Exception { - Flow flow = flowRepository.findById(null, "io.kestra.tests", "restart_always_failed").orElseThrow(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "restart_always_failed").orElseThrow(); - Execution firstExecution = runnerUtils.runOne(null, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); + Execution firstExecution = runnerUtils.runOne(MAIN_TENANT, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); assertThat(firstExecution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat(firstExecution.getTaskRunList()).hasSize(2); @@ -117,9 +119,9 @@ public class RestartCaseTest { } public void restartFailedThenFailureWithLocalErrors() throws Exception { - Flow flow = flowRepository.findById(null, "io.kestra.tests", "restart_local_errors").orElseThrow(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "restart_local_errors").orElseThrow(); - Execution firstExecution = runnerUtils.runOne(null, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); + Execution firstExecution = runnerUtils.runOne(MAIN_TENANT, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); assertThat(firstExecution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat(firstExecution.getTaskRunList()).hasSize(5); @@ -154,9 +156,9 @@ public class RestartCaseTest { } public void replay() throws Exception { - Flow flow = flowRepository.findById(null, "io.kestra.tests", "restart-each").orElseThrow(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "restart-each").orElseThrow(); - Execution firstExecution = runnerUtils.runOne(null, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); + Execution firstExecution = runnerUtils.runOne(MAIN_TENANT, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60)); assertThat(firstExecution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -186,7 +188,7 @@ public class RestartCaseTest { } public void restartMultiple() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "failed-first"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "failed-first"); assertThat(execution.getTaskRunList()).hasSize(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -221,7 +223,7 @@ public class RestartCaseTest { } }); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "restart-parent"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "restart-parent"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); diff --git a/core/src/test/java/io/kestra/core/runners/RunContextPropertyTest.java b/core/src/test/java/io/kestra/core/runners/RunContextPropertyTest.java index 071d040658..83f348f9a1 100644 --- a/core/src/test/java/io/kestra/core/runners/RunContextPropertyTest.java +++ b/core/src/test/java/io/kestra/core/runners/RunContextPropertyTest.java @@ -1,5 +1,6 @@ package io.kestra.core.runners; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.property.Property; @@ -15,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; @KestraTest class RunContextPropertyTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void asShouldReturnEmptyForNullProperty() throws IllegalVariableEvaluationException { diff --git a/core/src/test/java/io/kestra/core/runners/RunContextTest.java b/core/src/test/java/io/kestra/core/runners/RunContextTest.java index 1c92d2a31f..0c585b11b9 100644 --- a/core/src/test/java/io/kestra/core/runners/RunContextTest.java +++ b/core/src/test/java/io/kestra/core/runners/RunContextTest.java @@ -60,6 +60,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; import static org.hamcrest.MatcherAssert.assertThat; @@ -110,7 +111,7 @@ class RunContextTest { LogEntry matchingLog; Flux receive = TestsUtils.receive(workerTaskLogQueue, either -> logs.add(either.getLeft())); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "logs"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "logs"); assertThat(execution.getTaskRunList()).hasSize(5); @@ -147,7 +148,7 @@ class RunContextTest { inputs.put("string", new String(chars)); Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "inputs-large", null, @@ -179,7 +180,7 @@ class RunContextTest { @Test void taskDefaults() throws TimeoutException, QueueException, IOException, URISyntaxException { - repositoryLoader.load(null, Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/plugin-defaults.yaml"))); + repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/plugin-defaults.yaml"))); pluginDefaultsCaseTest.taskDefaults(); } @@ -195,7 +196,7 @@ class RunContextTest { p.destroy(); URI uri = runContext.storage().putFile(path.toFile()); - assertThat(storageInterface.getAttributes(null, null, uri).getSize()).isEqualTo(size + 1); + assertThat(storageInterface.getAttributes(MAIN_TENANT, null, uri).getSize()).isEqualTo(size + 1); } @Test diff --git a/core/src/test/java/io/kestra/core/runners/SLATestCase.java b/core/src/test/java/io/kestra/core/runners/SLATestCase.java index 0bbd11265b..6f3f6cbff4 100644 --- a/core/src/test/java/io/kestra/core/runners/SLATestCase.java +++ b/core/src/test/java/io/kestra/core/runners/SLATestCase.java @@ -10,6 +10,7 @@ import jakarta.inject.Singleton; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @Singleton @@ -18,31 +19,31 @@ public class SLATestCase { private RunnerUtils runnerUtils; public void maxDurationSLAShouldFail() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sla-max-duration-fail"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "sla-max-duration-fail"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); } public void maxDurationSLAShouldPass() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sla-max-duration-ok"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "sla-max-duration-ok"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); } public void executionConditionSLAShouldPass() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sla-execution-condition"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "sla-execution-condition"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); } public void executionConditionSLAShouldCancel() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sla-execution-condition", null, (f, e) -> Map.of("string", "CANCEL")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "sla-execution-condition", null, (f, e) -> Map.of("string", "CANCEL")); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.CANCELLED); } public void executionConditionSLAShouldLabel() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sla-execution-condition", null, (f, e) -> Map.of("string", "LABEL")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "sla-execution-condition", null, (f, e) -> Map.of("string", "LABEL")); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getLabels()).contains(new Label("sla", "violated")); diff --git a/core/src/test/java/io/kestra/core/runners/ScheduleDateCaseTest.java b/core/src/test/java/io/kestra/core/runners/ScheduleDateCaseTest.java index 0668d12934..b29ea349a2 100644 --- a/core/src/test/java/io/kestra/core/runners/ScheduleDateCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/ScheduleDateCaseTest.java @@ -18,6 +18,7 @@ import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -32,7 +33,7 @@ public class ScheduleDateCaseTest { public void shouldScheduleOnDate() throws QueueException, InterruptedException { ZonedDateTime scheduleOn = ZonedDateTime.now().plusSeconds(1); - Flow flow = flowRepository.findById(null, "io.kestra.tests", "minimal").orElseThrow(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "minimal").orElseThrow(); Execution execution = Execution.newExecution(flow, null, null, Optional.of(scheduleOn)); this.executionQueue.emit(execution); diff --git a/core/src/test/java/io/kestra/core/runners/SkipExecutionCaseTest.java b/core/src/test/java/io/kestra/core/runners/SkipExecutionCaseTest.java index 0a8f7af636..c0052be100 100644 --- a/core/src/test/java/io/kestra/core/runners/SkipExecutionCaseTest.java +++ b/core/src/test/java/io/kestra/core/runners/SkipExecutionCaseTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @Singleton @@ -46,17 +47,18 @@ public class SkipExecutionCaseTest { skipExecutionService.setSkipExecutions(List.of(execution1Id)); executionQueue.emit(execution1); - Execution execution2 = runnerUtils.runOne(null, "io.kestra.tests", "minimal"); + Execution execution2 = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "minimal"); // the execution 2 should be in success and the 1 still created assertThat(execution2.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution1 = Await.until(() -> executionRepository.findById(null, execution1Id).orElse(null), Duration.ofMillis(100), Duration.ofSeconds(1)); + execution1 = Await.until(() -> executionRepository.findById(MAIN_TENANT, execution1Id).orElse(null), Duration.ofMillis(100), Duration.ofSeconds(1)); assertThat(execution1.getState().getCurrent()).isEqualTo(State.Type.CREATED); } private Flow createFlow() { return Flow.builder() .id(IdUtils.create()) + .tenantId(MAIN_TENANT) .namespace("io.kestra.unittest") .revision(1) .tasks(Collections.singletonList(Return.builder() diff --git a/core/src/test/java/io/kestra/core/runners/TaskWithAllowFailureTest.java b/core/src/test/java/io/kestra/core/runners/TaskWithAllowFailureTest.java index 05583e8d06..fe02878802 100644 --- a/core/src/test/java/io/kestra/core/runners/TaskWithAllowFailureTest.java +++ b/core/src/test/java/io/kestra/core/runners/TaskWithAllowFailureTest.java @@ -1,5 +1,6 @@ package io.kestra.core.runners; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.ExecuteFlow; @@ -46,7 +47,7 @@ public class TaskWithAllowFailureTest { @LoadFlows({"flows/valids/task-allow-failure-executable-flow.yml", "flows/valids/for-each-item-subflow-failed.yaml"}) void executableTask_Flow() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "task-allow-failure-executable-flow"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "task-allow-failure-executable-flow"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.WARNING); assertThat(execution.getTaskRunList()).hasSize(2); } @@ -57,7 +58,7 @@ public class TaskWithAllowFailureTest { void executableTask_ForEachItem() throws TimeoutException, QueueException, URISyntaxException, IOException { URI file = storageUpload(); Map inputs = Map.of("file", file.toString()); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "task-allow-failure-executable-foreachitem", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "task-allow-failure-executable-foreachitem", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs)); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.WARNING); assertThat(execution.getTaskRunList()).hasSize(4); @@ -76,7 +77,7 @@ public class TaskWithAllowFailureTest { Files.write(tempFile.toPath(), content()); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/file.txt"), new FileInputStream(tempFile) diff --git a/core/src/test/java/io/kestra/core/runners/TaskWithAllowWarningTest.java b/core/src/test/java/io/kestra/core/runners/TaskWithAllowWarningTest.java index 6415407c42..4e9b7a33c0 100644 --- a/core/src/test/java/io/kestra/core/runners/TaskWithAllowWarningTest.java +++ b/core/src/test/java/io/kestra/core/runners/TaskWithAllowWarningTest.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.concurrent.TimeoutException; import java.util.stream.IntStream; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -47,7 +48,7 @@ public class TaskWithAllowWarningTest { @LoadFlows({"flows/valids/task-allow-warning-executable-flow.yml", "flows/valids/for-each-item-subflow-failed.yaml"}) void executableTask_Flow() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "task-allow-warning-executable-flow"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "task-allow-warning-executable-flow"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList()).hasSize(2); } @@ -57,7 +58,7 @@ public class TaskWithAllowWarningTest { void executableTask_ForEachItem() throws TimeoutException, QueueException, URISyntaxException, IOException { URI file = storageUpload(); Map inputs = Map.of("file", file.toString()); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "task-allow-warning-executable-foreachitem", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "task-allow-warning-executable-foreachitem", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs)); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList()).hasSize(4); @@ -76,7 +77,7 @@ public class TaskWithAllowWarningTest { Files.write(tempFile.toPath(), content()); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/file.txt"), new FileInputStream(tempFile) diff --git a/core/src/test/java/io/kestra/core/runners/TestSuiteTest.java b/core/src/test/java/io/kestra/core/runners/TestSuiteTest.java index 4d849404b8..9a5a903f03 100644 --- a/core/src/test/java/io/kestra/core/runners/TestSuiteTest.java +++ b/core/src/test/java/io/kestra/core/runners/TestSuiteTest.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; @@ -133,7 +134,7 @@ class TestSuiteTest { } private Execution runReturnFlow(List fixtures) throws TimeoutException, QueueException { - var flow = flowRepository.findById(null, "io.kestra.tests", "return", Optional.empty()).orElseThrow(); + var flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "return", Optional.empty()).orElseThrow(); var execution = Execution.builder() .id(IdUtils.create()) diff --git a/core/src/test/java/io/kestra/core/runners/pebble/functions/FileExistsFunctionTest.java b/core/src/test/java/io/kestra/core/runners/pebble/functions/FileExistsFunctionTest.java index fc6457ba5b..77607b49c8 100644 --- a/core/src/test/java/io/kestra/core/runners/pebble/functions/FileExistsFunctionTest.java +++ b/core/src/test/java/io/kestra/core/runners/pebble/functions/FileExistsFunctionTest.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.junit.jupiter.api.Assertions.*; @KestraTest @@ -33,7 +34,7 @@ class FileExistsFunctionTest { } private URI getInternalStorageFile(URI internalStorageURI, String text) throws IOException { - return storageInterface.put(null, NAMESPACE, internalStorageURI, new ByteArrayInputStream(text.getBytes())); + return storageInterface.put(MAIN_TENANT, NAMESPACE, internalStorageURI, new ByteArrayInputStream(text.getBytes())); } @Test @@ -46,7 +47,8 @@ class FileExistsFunctionTest { Map variables = Map.of( "flow", Map.of( "id", FLOW, - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId) ); boolean render = Boolean.parseBoolean(variableRenderer.render("{{ fileExists('" + internalStorageFile + "') }}", variables)); @@ -57,12 +59,12 @@ class FileExistsFunctionTest { void readNamespaceFileWithNamespace() throws IllegalVariableEvaluationException, IOException { String namespace = "io.kestra.tests"; String filePath = "file.txt"; - storageInterface.createDirectory(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); - storageInterface.put(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("NOT AN EMPTY FILE".getBytes())); + storageInterface.createDirectory(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); + storageInterface.put(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("NOT AN EMPTY FILE".getBytes())); boolean render = Boolean.parseBoolean( variableRenderer.render("{{ fileExists('" + filePath + "', namespace='" + namespace + "') }}", - Map.of("flow", Map.of("namespace", "flow.namespace")))); + Map.of("flow", Map.of("namespace", "flow.namespace", "tenantId", MAIN_TENANT)))); assertTrue(render); } @@ -76,7 +78,8 @@ class FileExistsFunctionTest { Map variables = Map.of( "flow", Map.of( "id", FLOW, - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId) ); boolean render = Boolean.parseBoolean(variableRenderer.render("{{ fileExists('" + internalStorageFile + "') }}", variables)); diff --git a/core/src/test/java/io/kestra/core/runners/pebble/functions/FileSizeFunctionTest.java b/core/src/test/java/io/kestra/core/runners/pebble/functions/FileSizeFunctionTest.java index 556089c173..eab4607f49 100644 --- a/core/src/test/java/io/kestra/core/runners/pebble/functions/FileSizeFunctionTest.java +++ b/core/src/test/java/io/kestra/core/runners/pebble/functions/FileSizeFunctionTest.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.validator.internal.util.Contracts.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -42,7 +43,8 @@ public class FileSizeFunctionTest { Map variables = Map.of( "flow", Map.of( "id", FLOW, - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId) ); @@ -54,10 +56,10 @@ public class FileSizeFunctionTest { void readNamespaceFileWithNamespace() throws IllegalVariableEvaluationException, IOException { String namespace = "io.kestra.tests"; String filePath = "file.txt"; - storageInterface.createDirectory(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); - storageInterface.put(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream(FILE_TEXT.getBytes())); + storageInterface.createDirectory(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); + storageInterface.put(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream(FILE_TEXT.getBytes())); - String render = variableRenderer.render("{{ fileSize('" + filePath + "', namespace='" + namespace + "') }}", Map.of("flow", Map.of("namespace", "flow.namespace"))); + String render = variableRenderer.render("{{ fileSize('" + filePath + "', namespace='" + namespace + "') }}", Map.of("flow", Map.of("namespace", "flow.namespace", "tenantId", MAIN_TENANT))); assertThat(render).isEqualTo(FILE_SIZE); } @@ -70,12 +72,14 @@ public class FileSizeFunctionTest { Map variables = Map.of( "flow", Map.of( "id", "subflow", - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", IdUtils.create()), "trigger", Map.of( "flowId", FLOW, "namespace", NAMESPACE, - "executionId", executionId + "executionId", executionId, + "tenantId", MAIN_TENANT ) ); @@ -92,7 +96,8 @@ public class FileSizeFunctionTest { Map variables = Map.of( "flow", Map.of( "id", "subflow", - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", IdUtils.create()) ); @@ -109,11 +114,13 @@ public class FileSizeFunctionTest { Map variables = Map.of( "flow", Map.of( "id", "subflow", - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", IdUtils.create()), "trigger", Map.of( "flowId", FLOW, - "executionId", executionId + "executionId", executionId, + "tenantId", MAIN_TENANT ) ); @@ -135,7 +142,8 @@ public class FileSizeFunctionTest { Map variables = Map.of( "flow", Map.of( "id", FLOW, - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId), "file", internalStorageFile ); @@ -153,12 +161,14 @@ public class FileSizeFunctionTest { Map variables = Map.of( "flow", Map.of( "id", "subflow", - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", IdUtils.create()), "trigger", Map.of( "flowId", FLOW, "namespace", NAMESPACE, - "executionId", executionId + "executionId", executionId, + "tenantId", MAIN_TENANT ), "file", internalStorageFile ); @@ -172,6 +182,6 @@ public class FileSizeFunctionTest { } private URI getInternalStorageFile(URI internalStorageURI) throws IOException { - return storageInterface.put(null, null, internalStorageURI, new ByteArrayInputStream(FILE_TEXT.getBytes())); + return storageInterface.put(MAIN_TENANT, null, internalStorageURI, new ByteArrayInputStream(FILE_TEXT.getBytes())); } } diff --git a/core/src/test/java/io/kestra/core/runners/pebble/functions/FromIonFunctionTest.java b/core/src/test/java/io/kestra/core/runners/pebble/functions/FromIonFunctionTest.java index a48c327b14..6292773a8c 100644 --- a/core/src/test/java/io/kestra/core/runners/pebble/functions/FromIonFunctionTest.java +++ b/core/src/test/java/io/kestra/core/runners/pebble/functions/FromIonFunctionTest.java @@ -14,6 +14,7 @@ import java.io.*; import java.net.URI; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; @@ -49,12 +50,12 @@ class FromIonFunctionTest { } Map variables = Map.of( - "flow", Map.of("id", "test", "namespace", "unit"), + "flow", Map.of("id", "test", "namespace", "unit", "tenantId", MAIN_TENANT), "execution", Map.of("id", "id-exec") ); URI internalStorageURI = URI.create("/unit/test/executions/id-exec/" + IdUtils.create() + ".ion"); - URI internalStorageFile = storageInterface.put(null, "unit", internalStorageURI, new FileInputStream(tempFile)); + URI internalStorageFile = storageInterface.put(MAIN_TENANT, "unit", internalStorageURI, new FileInputStream(tempFile)); String render = variableRenderer.render("{{ fromIon(read('" + internalStorageFile + "'), allRows=true) }}", variables); assertThat(render).contains("\"id\":0"); diff --git a/core/src/test/java/io/kestra/core/runners/pebble/functions/IsFileEmptyFunctionTest.java b/core/src/test/java/io/kestra/core/runners/pebble/functions/IsFileEmptyFunctionTest.java index 42a1056e5f..71493c4f7e 100644 --- a/core/src/test/java/io/kestra/core/runners/pebble/functions/IsFileEmptyFunctionTest.java +++ b/core/src/test/java/io/kestra/core/runners/pebble/functions/IsFileEmptyFunctionTest.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.junit.jupiter.api.Assertions.*; @KestraTest @@ -33,7 +34,7 @@ class IsFileEmptyFunctionTest { } private URI getInternalStorageFile(URI internalStorageURI, String text) throws IOException { - return storageInterface.put(null, NAMESPACE, internalStorageURI, new ByteArrayInputStream(text.getBytes())); + return storageInterface.put(MAIN_TENANT, NAMESPACE, internalStorageURI, new ByteArrayInputStream(text.getBytes())); } @Test @@ -46,7 +47,8 @@ class IsFileEmptyFunctionTest { Map variables = Map.of( "flow", Map.of( "id", FLOW, - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId) ); boolean render = Boolean.parseBoolean(variableRenderer.render("{{ isFileEmpty('" + internalStorageFile + "') }}", variables)); @@ -57,12 +59,12 @@ class IsFileEmptyFunctionTest { void readNamespaceFileWithNamespace() throws IllegalVariableEvaluationException, IOException { String namespace = "io.kestra.tests"; String filePath = "file.txt"; - storageInterface.createDirectory(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); - storageInterface.put(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("NOT AN EMPTY FILE".getBytes())); + storageInterface.createDirectory(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); + storageInterface.put(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("NOT AN EMPTY FILE".getBytes())); boolean render = Boolean.parseBoolean( variableRenderer.render("{{ isFileEmpty('" + filePath + "', namespace='" + namespace + "') }}", - Map.of("flow", Map.of("namespace", "flow.namespace")))); + Map.of("flow", Map.of("namespace", "flow.namespace", "tenantId", MAIN_TENANT)))); assertFalse(render); } @@ -76,7 +78,8 @@ class IsFileEmptyFunctionTest { Map variables = Map.of( "flow", Map.of( "id", FLOW, - "namespace", NAMESPACE), + "namespace", NAMESPACE, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId) ); boolean render = Boolean.parseBoolean(variableRenderer.render("{{ isFileEmpty('" + internalStorageFile + "') }}", variables)); diff --git a/core/src/test/java/io/kestra/core/runners/pebble/functions/ReadFileFunctionTest.java b/core/src/test/java/io/kestra/core/runners/pebble/functions/ReadFileFunctionTest.java index b8c14cdf18..99ae966d76 100644 --- a/core/src/test/java/io/kestra/core/runners/pebble/functions/ReadFileFunctionTest.java +++ b/core/src/test/java/io/kestra/core/runners/pebble/functions/ReadFileFunctionTest.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -34,10 +35,10 @@ class ReadFileFunctionTest { void readNamespaceFile() throws IllegalVariableEvaluationException, IOException { String namespace = "io.kestra.tests"; String filePath = "file.txt"; - storageInterface.createDirectory(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); - storageInterface.put(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("Hello from {{ flow.namespace }}".getBytes())); + storageInterface.createDirectory(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); + storageInterface.put(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("Hello from {{ flow.namespace }}".getBytes())); - String render = variableRenderer.render("{{ render(read('" + filePath + "')) }}", Map.of("flow", Map.of("namespace", namespace))); + String render = variableRenderer.render("{{ render(read('" + filePath + "')) }}", Map.of("flow", Map.of("namespace", namespace, "tenantId", MAIN_TENANT))); assertThat(render).isEqualTo("Hello from " + namespace); } @@ -45,10 +46,10 @@ class ReadFileFunctionTest { void readNamespaceFileWithNamespace() throws IllegalVariableEvaluationException, IOException { String namespace = "io.kestra.tests"; String filePath = "file.txt"; - storageInterface.createDirectory(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); - storageInterface.put(null, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("Hello but not from flow.namespace".getBytes())); + storageInterface.createDirectory(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace))); + storageInterface.put(MAIN_TENANT, namespace, URI.create(StorageContext.namespaceFilePrefix(namespace) + "/" + filePath), new ByteArrayInputStream("Hello but not from flow.namespace".getBytes())); - String render = variableRenderer.render("{{ read('" + filePath + "', namespace='" + namespace + "') }}", Map.of("flow", Map.of("namespace", "flow.namespace"))); + String render = variableRenderer.render("{{ read('" + filePath + "', namespace='" + namespace + "') }}", Map.of("flow", Map.of("namespace", "flow.namespace", "tenantId", MAIN_TENANT))); assertThat(render).isEqualTo("Hello but not from flow.namespace"); } @@ -65,13 +66,14 @@ class ReadFileFunctionTest { String flowId = "flow"; String executionId = IdUtils.create(); URI internalStorageURI = URI.create("/" + namespace.replace(".", "/") + "/" + flowId + "/executions/" + executionId + "/tasks/task/" + IdUtils.create() + "/123456.ion"); - URI internalStorageFile = storageInterface.put(null, namespace, internalStorageURI, new ByteArrayInputStream("Hello from a task output".getBytes())); + URI internalStorageFile = storageInterface.put(MAIN_TENANT, namespace, internalStorageURI, new ByteArrayInputStream("Hello from a task output".getBytes())); // test for an authorized execution Map variables = Map.of( "flow", Map.of( "id", flowId, - "namespace", namespace), + "namespace", namespace, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId) ); @@ -82,12 +84,14 @@ class ReadFileFunctionTest { variables = Map.of( "flow", Map.of( "id", "subflow", - "namespace", namespace), + "namespace", namespace, + "tenantId", MAIN_TENANT), "execution", Map.of("id", IdUtils.create()), "trigger", Map.of( "flowId", flowId, "namespace", namespace, - "executionId", executionId + "executionId", executionId, + "tenantId", MAIN_TENANT ) ); @@ -102,13 +106,14 @@ class ReadFileFunctionTest { String flowId = "flow"; String executionId = IdUtils.create(); URI internalStorageURI = URI.create("/" + namespace.replace(".", "/") + "/" + flowId + "/executions/" + executionId + "/tasks/task/" + IdUtils.create() + "/123456.ion"); - URI internalStorageFile = storageInterface.put(null, namespace, internalStorageURI, new ByteArrayInputStream("Hello from a task output".getBytes())); + URI internalStorageFile = storageInterface.put(MAIN_TENANT, namespace, internalStorageURI, new ByteArrayInputStream("Hello from a task output".getBytes())); // test for an authorized execution Map variables = Map.of( "flow", Map.of( "id", flowId, - "namespace", namespace), + "namespace", namespace, + "tenantId", MAIN_TENANT), "execution", Map.of("id", executionId), "file", internalStorageFile ); @@ -120,12 +125,14 @@ class ReadFileFunctionTest { variables = Map.of( "flow", Map.of( "id", "subflow", - "namespace", namespace), + "namespace", namespace, + "tenantId", MAIN_TENANT), "execution", Map.of("id", IdUtils.create()), "trigger", Map.of( "flowId", flowId, "namespace", namespace, - "executionId", executionId + "executionId", executionId, + "tenantId", MAIN_TENANT ) ); @@ -139,12 +146,13 @@ class ReadFileFunctionTest { String flowId = "flow"; String executionId = IdUtils.create(); URI internalStorageURI = URI.create("/" + namespace.replace(".", "/") + "/" + flowId + "/executions/" + executionId + "/tasks/task/" + IdUtils.create() + "/123456.ion"); - URI internalStorageFile = storageInterface.put(null, namespace, internalStorageURI, new ByteArrayInputStream("Hello from a task output".getBytes())); + URI internalStorageFile = storageInterface.put(MAIN_TENANT, namespace, internalStorageURI, new ByteArrayInputStream("Hello from a task output".getBytes())); Map variables = Map.of( "flow", Map.of( "id", "notme", - "namespace", "notme"), + "namespace", "notme", + "tenantId", MAIN_TENANT), "execution", Map.of("id", "notme") ); diff --git a/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java b/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java index 861afedba4..d2253f4393 100644 --- a/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java +++ b/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java @@ -1,5 +1,6 @@ package io.kestra.core.secret; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.exceptions.IllegalVariableEvaluationException; @@ -56,7 +57,7 @@ public class SecretFunctionTest { List logs = new CopyOnWriteArrayList<>(); Flux receive = TestsUtils.receive(logQueue, either -> logs.add(either.getLeft())); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "secrets"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "secrets"); assertThat(execution.getTaskRunList().getFirst().getOutputs().get("value")).isEqualTo("secretValue"); assertThat(execution.getTaskRunList().get(2).getOutputs().get("value")).isEqualTo("passwordveryveryveyrlongpasswordveryveryveyrlongpasswordveryveryveyrlongpasswordveryveryveyrlongpasswordveryveryveyrlong"); assertThat(execution.getTaskRunList().get(3).getOutputs().get("value")).isEqualTo("secretValue"); @@ -122,7 +123,7 @@ public class SecretFunctionTest { public static class TestSecretService extends SecretService { private static final Map SECRETS = Map.of( - "io.kestra.unittest.json-secret", """ + "io.kestra.unittest.json-secret", """ { "string": "value", "number": 42, diff --git a/core/src/test/java/io/kestra/core/services/LabelServiceTest.java b/core/src/test/java/io/kestra/core/services/LabelServiceTest.java index 5913c0c1df..3feaf1c1cf 100644 --- a/core/src/test/java/io/kestra/core/services/LabelServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/LabelServiceTest.java @@ -1,5 +1,6 @@ package io.kestra.core.services; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.Label; import io.kestra.core.models.flows.Flow; @@ -22,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class LabelServiceTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void shouldFilterSystemLabels() { diff --git a/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java b/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java index a4c5751952..009dcf5ee1 100644 --- a/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/PluginDefaultServiceTest.java @@ -43,6 +43,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Stream; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; @@ -70,7 +71,7 @@ class PluginDefaultServiceTest { @Test void shouldInjectGivenFlowWithNullSource() throws FlowProcessingException { // Given - FlowInterface flow = GenericFlow.fromYaml(null, TEST_LOG_FLOW_SOURCE); + FlowInterface flow = GenericFlow.fromYaml(MAIN_TENANT, TEST_LOG_FLOW_SOURCE); // When FlowWithSource result = pluginDefaultService.injectAllDefaults(flow, true); @@ -193,7 +194,7 @@ class PluginDefaultServiceTest { - id: test type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester set: 666 - + pluginDefaults: - type: "%s" forced: false @@ -236,12 +237,12 @@ class PluginDefaultServiceTest { String source = """ id: default-test namespace: io.kestra.tests - + tasks: - id: test type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester set: 1 - + pluginDefaults: - type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester forced: true @@ -283,7 +284,7 @@ class PluginDefaultServiceTest { - id: test type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester set: 666 - + pluginDefaults: - type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester values: @@ -308,7 +309,7 @@ class PluginDefaultServiceTest { @Test void shouldInjectFlowDefaultsGivenAlias() throws FlowProcessingException { // Given - GenericFlow flow = GenericFlow.fromYaml(null, """ + GenericFlow flow = GenericFlow.fromYaml(MAIN_TENANT, """ id: default-test namespace: io.kestra.tests @@ -316,7 +317,7 @@ class PluginDefaultServiceTest { - id: test type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester set: 666 - + pluginDefaults: - type: io.kestra.core.services.DefaultTesterAlias values: @@ -332,7 +333,7 @@ class PluginDefaultServiceTest { @Test void shouldInjectFlowDefaultsGivenType() throws FlowProcessingException { - GenericFlow flow = GenericFlow.fromYaml(null, """ + GenericFlow flow = GenericFlow.fromYaml(MAIN_TENANT, """ id: default-test namespace: io.kestra.tests @@ -340,7 +341,7 @@ class PluginDefaultServiceTest { - id: test type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester set: 666 - + pluginDefaults: - type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester values: @@ -355,7 +356,7 @@ class PluginDefaultServiceTest { @Test public void shouldNotInjectDefaultsGivenExistingTaskValue() throws FlowProcessingException { // Given - GenericFlow flow = GenericFlow.fromYaml(null, """ + GenericFlow flow = GenericFlow.fromYaml(MAIN_TENANT, """ id: default-test namespace: io.kestra.tests @@ -364,7 +365,7 @@ class PluginDefaultServiceTest { type: io.kestra.plugin.core.log.Log message: testing level: INFO - + pluginDefaults: - type: io.kestra.core.services.PluginDefaultServiceTest$DefaultTester values: diff --git a/core/src/test/java/io/kestra/core/storages/InternalKVStoreTest.java b/core/src/test/java/io/kestra/core/storages/InternalKVStoreTest.java index 714d1b181e..da416e3b88 100644 --- a/core/src/test/java/io/kestra/core/storages/InternalKVStoreTest.java +++ b/core/src/test/java/io/kestra/core/storages/InternalKVStoreTest.java @@ -28,6 +28,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; class InternalKVStoreTest { private static final Instant date = Instant.now().truncatedTo(ChronoUnit.MILLIS); @@ -46,7 +47,7 @@ class InternalKVStoreTest { @Test void list() throws IOException { - Instant before = Instant.now().minusMillis(100); + Instant now = Instant.now(); InternalKVStore kv = kv(); assertThat(kv.list().size()).isZero(); @@ -54,14 +55,13 @@ class InternalKVStoreTest { kv.put(TEST_KV_KEY, new KVValueAndMetadata(new KVMetadata(Duration.ofMinutes(5)), complexValue)); kv.put("my-second-key", new KVValueAndMetadata(new KVMetadata(Duration.ofMinutes(10)), complexValue)); kv.put("expired-key", new KVValueAndMetadata(new KVMetadata(Duration.ofMillis(1)), complexValue)); - Instant after = Instant.now().plusMillis(100); List list = kv.list(); assertThat(list.size()).isEqualTo(2); list.forEach(kvEntry -> { - assertThat(kvEntry.creationDate().isAfter(before) && kvEntry.creationDate().isBefore(after)).isTrue(); - assertThat(kvEntry.updateDate().isAfter(before) && kvEntry.updateDate().isBefore(after)).isTrue(); + assertThat(kvEntry.creationDate()).isCloseTo(now, within(1, ChronoUnit. SECONDS)); + assertThat(kvEntry.updateDate()).isCloseTo(now, within(1, ChronoUnit. SECONDS)); }); Map map = list.stream().collect(Collectors.toMap(KVEntry::key, Function.identity())); diff --git a/core/src/test/java/io/kestra/core/storages/StateStoreTest.java b/core/src/test/java/io/kestra/core/storages/StateStoreTest.java index 935350946c..7acfb571ac 100644 --- a/core/src/test/java/io/kestra/core/storages/StateStoreTest.java +++ b/core/src/test/java/io/kestra/core/storages/StateStoreTest.java @@ -1,5 +1,6 @@ package io.kestra.core.storages; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.MigrationRequiredException; import io.kestra.core.exceptions.ResourceExpiredException; import io.kestra.core.runners.RunContext; @@ -23,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; @MicronautTest public class StateStoreTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void all() throws IOException, ResourceExpiredException { diff --git a/core/src/test/java/io/kestra/core/tasks/PluginUtilsServiceTest.java b/core/src/test/java/io/kestra/core/tasks/PluginUtilsServiceTest.java index 1becc98dfa..a14ec5e913 100644 --- a/core/src/test/java/io/kestra/core/tasks/PluginUtilsServiceTest.java +++ b/core/src/test/java/io/kestra/core/tasks/PluginUtilsServiceTest.java @@ -1,5 +1,6 @@ package io.kestra.core.tasks; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.models.tasks.runners.PluginUtilsService; import io.kestra.core.runners.RunContextFactory; @@ -20,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @KestraTest public class PluginUtilsServiceTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void outputFiles() throws IOException { diff --git a/core/src/test/java/io/kestra/core/tenant/TenantServiceTest.java b/core/src/test/java/io/kestra/core/tenant/TenantServiceTest.java index 24188ab5de..f91242ae6f 100644 --- a/core/src/test/java/io/kestra/core/tenant/TenantServiceTest.java +++ b/core/src/test/java/io/kestra/core/tenant/TenantServiceTest.java @@ -14,7 +14,7 @@ class TenantServiceTest { @Test void test() { var tenant = tenantService.resolveTenant(); - assertThat(tenant).isNull(); + assertThat(tenant).isEqualTo("main"); } } \ No newline at end of file diff --git a/core/src/test/java/io/kestra/core/utils/NamespaceFilesUtilsTest.java b/core/src/test/java/io/kestra/core/utils/NamespaceFilesUtilsTest.java index 6cbb39bbc9..16043f52be 100644 --- a/core/src/test/java/io/kestra/core/utils/NamespaceFilesUtilsTest.java +++ b/core/src/test/java/io/kestra/core/utils/NamespaceFilesUtilsTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -54,7 +55,7 @@ class NamespaceFilesUtilsTest { ByteArrayInputStream data = new ByteArrayInputStream("a".repeat(1024).getBytes(StandardCharsets.UTF_8)); for (int i = 0; i < 100; i++) { - storageInterface.put(null, namespace, toNamespacedStorageUri(namespace, URI.create("/" + i + ".txt")), data); + storageInterface.put(MAIN_TENANT, namespace, toNamespacedStorageUri(namespace, URI.create("/" + i + ".txt")), data); } namespaceFilesUtils.loadNamespaceFiles(runContext, NamespaceFiles.builder().build()); @@ -78,7 +79,7 @@ class NamespaceFilesUtilsTest { ByteArrayInputStream data = new ByteArrayInputStream("a".repeat(1024).getBytes(StandardCharsets.UTF_8)); for (int i = 0; i < 100; i++) { - storageInterface.put(null, namespace, toNamespacedStorageUri(namespace, URI.create("/" + i + ".txt")), data); + storageInterface.put(MAIN_TENANT, namespace, toNamespacedStorageUri(namespace, URI.create("/" + i + ".txt")), data); } namespaceFilesUtils.loadNamespaceFiles(runContext, NamespaceFiles.builder().namespaces(Property.of(List.of(namespace))).build()); @@ -101,9 +102,9 @@ class NamespaceFilesUtilsTest { String namespace = IdUtils.create(); ByteArrayInputStream data = new ByteArrayInputStream("a".repeat(1024).getBytes(StandardCharsets.UTF_8)); - storageInterface.put(null, namespace, toNamespacedStorageUri(namespace, URI.create("/folder1/test.txt")), data); - storageInterface.put(null, namespace, toNamespacedStorageUri(namespace, URI.create("/folder2/test.txt")), data); - storageInterface.put(null, namespace, toNamespacedStorageUri(namespace, URI.create("/test.txt")), data); + storageInterface.put(MAIN_TENANT, namespace, toNamespacedStorageUri(namespace, URI.create("/folder1/test.txt")), data); + storageInterface.put(MAIN_TENANT, namespace, toNamespacedStorageUri(namespace, URI.create("/folder2/test.txt")), data); + storageInterface.put(MAIN_TENANT, namespace, toNamespacedStorageUri(namespace, URI.create("/test.txt")), data); namespaceFilesUtils.loadNamespaceFiles(runContext, NamespaceFiles.builder().namespaces(Property.of(List.of(namespace))).build()); diff --git a/core/src/test/java/io/kestra/plugin/core/execution/ExitTest.java b/core/src/test/java/io/kestra/plugin/core/execution/ExitTest.java index 97fb2bb0e2..56d64c85d4 100644 --- a/core/src/test/java/io/kestra/plugin/core/execution/ExitTest.java +++ b/core/src/test/java/io/kestra/plugin/core/execution/ExitTest.java @@ -21,6 +21,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -55,7 +56,7 @@ class ExitTest { }); // we cannot use the runnerUtils as it may not see the RUNNING state before the execution is killed - Flow flow = flowRepository.findById(null, "io.kestra.tests", "exit-killed", Optional.empty()).orElseThrow(); + Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "exit-killed", Optional.empty()).orElseThrow(); Execution execution = Execution.newExecution(flow, null, null, Optional.empty()); executionQueue.emit(execution); diff --git a/core/src/test/java/io/kestra/plugin/core/execution/FailTest.java b/core/src/test/java/io/kestra/plugin/core/execution/FailTest.java index 52b943fef4..c793addea8 100644 --- a/core/src/test/java/io/kestra/plugin/core/execution/FailTest.java +++ b/core/src/test/java/io/kestra/plugin/core/execution/FailTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.execution; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.KestraTest; @@ -23,8 +24,8 @@ public class FailTest { @Test @LoadFlows({"flows/valids/fail-on-switch.yaml"}) void failOnSwitch() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "fail-on-switch", null, - (f, e) -> Map.of("param", "fail") , Duration.ofSeconds(120)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "fail-on-switch", null, + (f, e) -> Map.of("param", "fail") , Duration.ofSeconds(20)); assertThat(execution.getTaskRunList()).hasSize(1); assertThat(execution.findTaskRunsByTaskId("switch").getFirst().getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -34,8 +35,8 @@ public class FailTest { @Test @LoadFlows({"flows/valids/fail-on-condition.yaml"}) void failOnCondition() throws TimeoutException, QueueException{ - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "fail-on-condition", null, - (f, e) -> Map.of("param", "fail") , Duration.ofSeconds(120)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "fail-on-condition", null, + (f, e) -> Map.of("param", "fail") , Duration.ofSeconds(20)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("fail").getFirst().getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -45,8 +46,8 @@ public class FailTest { @Test @LoadFlows({"flows/valids/fail-on-condition.yaml"}) void dontFailOnCondition() throws TimeoutException, QueueException{ - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "fail-on-condition", null, - (f, e) -> Map.of("param", "success") , Duration.ofSeconds(120)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "fail-on-condition", null, + (f, e) -> Map.of("param", "success") , Duration.ofSeconds(20)); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.findTaskRunsByTaskId("fail").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); diff --git a/core/src/test/java/io/kestra/plugin/core/execution/PurgeExecutionsTest.java b/core/src/test/java/io/kestra/plugin/core/execution/PurgeExecutionsTest.java index b42dbbdd84..532a58f8d4 100644 --- a/core/src/test/java/io/kestra/plugin/core/execution/PurgeExecutionsTest.java +++ b/core/src/test/java/io/kestra/plugin/core/execution/PurgeExecutionsTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.execution; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.State; @@ -20,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; @KestraTest class PurgeExecutionsTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Inject private ExecutionRepositoryInterface executionRepository; diff --git a/core/src/test/java/io/kestra/plugin/core/execution/ResumeTest.java b/core/src/test/java/io/kestra/plugin/core/execution/ResumeTest.java index 3cca1d672b..ebb67a6430 100644 --- a/core/src/test/java/io/kestra/plugin/core/execution/ResumeTest.java +++ b/core/src/test/java/io/kestra/plugin/core/execution/ResumeTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test; import java.time.Duration; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -28,14 +29,14 @@ class ResumeTest { @LoadFlows({"flows/valids/pause.yaml", "flows/valids/resume-execution.yaml"}) void resume() throws Exception { - Execution pause = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause"); + Execution pause = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause"); String pauseId = pause.getId(); - Execution resume = runnerUtils.runOne(null, "io.kestra.tests", "resume-execution", null, (flow, execution) -> Map.of("executionId", pauseId)); + Execution resume = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "resume-execution", null, (flow, execution) -> Map.of("executionId", pauseId)); assertThat(resume.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); Await.until( - () -> executionRepository.findById(null, pauseId).orElseThrow().getState().getCurrent().isTerminated(), + () -> executionRepository.findById(MAIN_TENANT, pauseId).orElseThrow().getState().getCurrent().isTerminated(), Duration.ofMillis(100), Duration.ofSeconds(5) ); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/AllowFailureTest.java b/core/src/test/java/io/kestra/plugin/core/flow/AllowFailureTest.java index 2e7d09098d..f30f883bfa 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/AllowFailureTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/AllowFailureTest.java @@ -14,6 +14,7 @@ import io.kestra.core.models.flows.State; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -37,7 +38,7 @@ class AllowFailureTest { @LoadFlows({"flows/valids/allow-failure.yaml"}) void failed() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "allow-failure", null, diff --git a/core/src/test/java/io/kestra/plugin/core/flow/CorrelationIdTest.java b/core/src/test/java/io/kestra/plugin/core/flow/CorrelationIdTest.java index ae2dea7a6f..5a0c06ce40 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/CorrelationIdTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/CorrelationIdTest.java @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -53,7 +54,7 @@ class CorrelationIdTest { } }); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "subflow-parent"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "subflow-parent"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertTrue(countDownLatch.await(1, TimeUnit.MINUTES)); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/DagTest.java b/core/src/test/java/io/kestra/plugin/core/flow/DagTest.java index c4bfdb41a7..411b5c927e 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/DagTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/DagTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.ExecuteFlow; @@ -70,7 +71,7 @@ public class DagTest { @LoadFlows({"flows/valids/finally-dag.yaml"}) void errors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "finally-dag", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) diff --git a/core/src/test/java/io/kestra/plugin/core/flow/EachSequentialTest.java b/core/src/test/java/io/kestra/plugin/core/flow/EachSequentialTest.java index ccbd1480fb..01242edcb9 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/EachSequentialTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/EachSequentialTest.java @@ -24,6 +24,7 @@ import jakarta.inject.Inject; import jakarta.inject.Named; import reactor.core.publisher.Flux; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -95,7 +96,7 @@ public class EachSequentialTest { List logs = new CopyOnWriteArrayList<>(); Flux receive = TestsUtils.receive(logQueue, either -> logs.add(either.getLeft())); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "each-null", Duration.ofSeconds(60)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "each-null", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList()).hasSize(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/FinallyTest.java b/core/src/test/java/io/kestra/plugin/core/flow/FinallyTest.java index 5af46fb592..c63660ce66 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/FinallyTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/FinallyTest.java @@ -15,10 +15,13 @@ import java.time.Duration; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) class FinallyTest { + + public static final String NAMESPACE = "io.kestra.tests"; @Inject protected RunnerUtils runnerUtils; @@ -29,8 +32,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-sequential.yaml"}) void sequentialWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-sequential", null, + MAIN_TENANT, + NAMESPACE, "finally-sequential", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -46,8 +49,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-sequential.yaml"}) void sequentialWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-sequential", null, + MAIN_TENANT, + NAMESPACE, "finally-sequential", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -63,8 +66,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-sequential-error.yaml"}) void sequentialErrorBlockWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-sequential-error", null, + MAIN_TENANT, + NAMESPACE, "finally-sequential-error", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -79,7 +82,7 @@ class FinallyTest { @Test @LoadFlows({"flows/valids/finally-sequential-error-first.yaml"}) void sequentialErrorFirst() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "finally-sequential-error-first"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, NAMESPACE, "finally-sequential-error-first"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); @@ -92,8 +95,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-sequential-error.yaml"}) void sequentialErrorBlockWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-sequential-error", null, + MAIN_TENANT, + NAMESPACE, "finally-sequential-error", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -111,8 +114,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-allowfailure.yaml"}) void allowFailureWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-allowfailure", null, + MAIN_TENANT, + NAMESPACE, "finally-allowfailure", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -128,8 +131,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-allowfailure.yaml"}) void allowFailureWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-allowfailure", null, + MAIN_TENANT, + NAMESPACE, "finally-allowfailure", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -147,8 +150,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-parallel.yaml"}) void parallelWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-parallel", null, + MAIN_TENANT, + NAMESPACE, "finally-parallel", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -164,8 +167,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-parallel.yaml"}) void parallelWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-parallel", null, + MAIN_TENANT, + NAMESPACE, "finally-parallel", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -183,8 +186,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-foreach.yaml"}) void forEachWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-foreach", null, + MAIN_TENANT, + NAMESPACE, "finally-foreach", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -200,8 +203,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-foreach.yaml"}) void forEachWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-foreach", null, + MAIN_TENANT, + NAMESPACE, "finally-foreach", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -219,8 +222,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-eachparallel.yaml"}) void eachParallelWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-eachparallel", null, + MAIN_TENANT, + NAMESPACE, "finally-eachparallel", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -236,8 +239,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-eachparallel.yaml"}) void eachParallelWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-eachparallel", null, + MAIN_TENANT, + NAMESPACE, "finally-eachparallel", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -255,8 +258,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-dag.yaml"}) void dagWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-dag", null, + MAIN_TENANT, + NAMESPACE, "finally-dag", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -272,8 +275,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-dag.yaml"}) void dagWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-dag", null, + MAIN_TENANT, + NAMESPACE, "finally-dag", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -291,8 +294,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-flow.yaml"}) void flowWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-flow", null, + MAIN_TENANT, + NAMESPACE, "finally-flow", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -308,8 +311,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-flow.yaml"}) void flowWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-flow", null, + MAIN_TENANT, + NAMESPACE, "finally-flow", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -325,8 +328,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-flow-error.yaml"}) void flowErrorBlockWithoutErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-flow-error", null, + MAIN_TENANT, + NAMESPACE, "finally-flow-error", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", false)), Duration.ofSeconds(60) ); @@ -342,8 +345,8 @@ class FinallyTest { @LoadFlows({"flows/valids/finally-flow-error.yaml"}) void flowErrorBlockWithErrors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", "finally-flow-error", null, + MAIN_TENANT, + NAMESPACE, "finally-flow-error", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) ); @@ -360,7 +363,7 @@ class FinallyTest { @Test @LoadFlows({"flows/valids/finally-flow-error-first.yaml"}) void flowErrorFirst() throws QueueException, TimeoutException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "finally-flow-error-first"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, NAMESPACE, "finally-flow-error-first"); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/FlowCaseTest.java b/core/src/test/java/io/kestra/plugin/core/flow/FlowCaseTest.java index 62bd0cd7b2..5d6d5ed379 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/FlowCaseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/FlowCaseTest.java @@ -21,6 +21,7 @@ import jakarta.inject.Named; import jakarta.inject.Singleton; import reactor.core.publisher.Flux; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @Singleton @@ -61,7 +62,7 @@ public class FlowCaseTest { }); Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "subflow-old-task-name" ); @@ -92,7 +93,7 @@ public class FlowCaseTest { }); Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", testInherited ? "task-flow" : "task-flow-inherited-labels", null, diff --git a/core/src/test/java/io/kestra/plugin/core/flow/ForEachItemCaseTest.java b/core/src/test/java/io/kestra/plugin/core/flow/ForEachItemCaseTest.java index abfa13c1a5..6a5f68eac4 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/ForEachItemCaseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/ForEachItemCaseTest.java @@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.IntStream; import static io.kestra.core.models.flows.State.Type.FAILED; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.core.utils.Rethrow.throwRunnable; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -78,7 +79,7 @@ public class ForEachItemCaseTest { URI file = storageUpload(); Map inputs = Map.of("file", file.toString(), "batch", 4); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "for-each-item", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "for-each-item", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(30)); @@ -112,7 +113,7 @@ public class ForEachItemCaseTest { public void forEachItemEmptyItems() throws TimeoutException, URISyntaxException, IOException, QueueException { URI file = emptyItems(); Map inputs = Map.of("file", file.toString(), "batch", 4); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "for-each-item", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "for-each-item", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(30)); @@ -140,7 +141,7 @@ public class ForEachItemCaseTest { URI file = storageUpload(); Map inputs = Map.of("file", file.toString()); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "for-each-item-no-wait", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "for-each-item-no-wait", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(30)); @@ -187,7 +188,7 @@ public class ForEachItemCaseTest { URI file = storageUpload(); Map inputs = Map.of("file", file.toString()); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "for-each-item-failed", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "for-each-item-failed", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(60)); @@ -230,7 +231,7 @@ public class ForEachItemCaseTest { URI file = storageUpload(); Map inputs = Map.of("file", file.toString()); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "for-each-item-outputs", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "for-each-item-outputs", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(30)); @@ -261,7 +262,7 @@ public class ForEachItemCaseTest { // asserts for subflow merged outputs Map mergeTaskOutputs = execution.getTaskRunList().get(3).getOutputs(); assertThat(mergeTaskOutputs.get("subflowOutputs")).isNotNull(); - InputStream stream = storageInterface.get(null, execution.getNamespace(), URI.create((String) mergeTaskOutputs.get("subflowOutputs"))); + InputStream stream = storageInterface.get(MAIN_TENANT, execution.getNamespace(), URI.create((String) mergeTaskOutputs.get("subflowOutputs"))); try (var br = new BufferedReader(new InputStreamReader(stream))) { // one line per sub-flows @@ -280,7 +281,7 @@ public class ForEachItemCaseTest { URI file = storageUpload(); Map inputs = Map.of("file", file.toString(), "batch", 20); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "restart-for-each-item", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "restart-for-each-item", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(30)); assertThat(execution.getTaskRunList()).hasSize(3); @@ -326,7 +327,7 @@ public class ForEachItemCaseTest { URI file = storageUpload(); Map inputs = Map.of("file", file.toString(), "batch", 4); - Execution execution = runnerUtils.runOne(null, TEST_NAMESPACE, "for-each-item-in-if", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, TEST_NAMESPACE, "for-each-item-in-if", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), Duration.ofSeconds(30)); @@ -361,7 +362,7 @@ public class ForEachItemCaseTest { Files.write(tempFile.toPath(), content()); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/file.txt"), new FileInputStream(tempFile) @@ -372,7 +373,7 @@ public class ForEachItemCaseTest { File tempFile = File.createTempFile("file", ".txt"); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/file.txt"), new FileInputStream(tempFile) diff --git a/core/src/test/java/io/kestra/plugin/core/flow/IfTest.java b/core/src/test/java/io/kestra/plugin/core/flow/IfTest.java index a9f80cd447..4e19591109 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/IfTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/IfTest.java @@ -14,6 +14,7 @@ import java.time.Duration; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -25,21 +26,21 @@ class IfTest { @Test @LoadFlows({"flows/valids/if-condition.yaml"}) void ifTruthy() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", true) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("when-true").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", "true") , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("when-true").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", 1) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); @@ -50,28 +51,28 @@ class IfTest { @Test @LoadFlows({"flows/valids/if-condition.yaml"}) void ifFalsy() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", false) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("when-false").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", "false") , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("when-false").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", 0) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("when-false").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests", "if-condition", null, + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-condition", null, (f, e) -> Map.of("param", -0) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); @@ -84,14 +85,14 @@ class IfTest { @Test @LoadFlows({"flows/valids/if-without-else.yaml"}) void ifWithoutElse() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "if-without-else", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-without-else", null, (f, e) -> Map.of("param", true) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.findTaskRunsByTaskId("when-true").getFirst().getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - execution = runnerUtils.runOne(null, "io.kestra.tests", "if-without-else", null, + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-without-else", null, (f, e) -> Map.of("param", false) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(1); assertThat(execution.findTaskRunsByTaskId("when-true").isEmpty()).isTrue(); @@ -101,7 +102,7 @@ class IfTest { @Test @LoadFlows({"flows/valids/if-in-flowable.yaml"}) void ifInFlowable() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "if-in-flowable", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "if-in-flowable", null, (f, e) -> Map.of("param", true) , Duration.ofSeconds(120)); assertThat(execution.getTaskRunList()).hasSize(8); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/ParallelTest.java b/core/src/test/java/io/kestra/plugin/core/flow/ParallelTest.java index e36fc07681..05f5c9746e 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/ParallelTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/ParallelTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.ExecuteFlow; @@ -41,7 +42,7 @@ class ParallelTest { @LoadFlows({"flows/valids/finally-parallel.yaml"}) void errors() throws QueueException, TimeoutException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "finally-parallel", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, Map.of("failed", true)), Duration.ofSeconds(60) diff --git a/core/src/test/java/io/kestra/plugin/core/flow/PauseTest.java b/core/src/test/java/io/kestra/plugin/core/flow/PauseTest.java index 515c00145a..b518d9f1bf 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/PauseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/PauseTest.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.core.utils.Rethrow.throwRunnable; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -148,7 +149,7 @@ public class PauseTest { protected QueueInterface executionQueue; public void run(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); Flow flow = flowRepository.findByExecution(execution); @@ -173,7 +174,7 @@ public class PauseTest { } public void runDelay(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause-delay", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause-delay", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.PAUSED); @@ -191,7 +192,7 @@ public class PauseTest { } public void runDurationFromInput(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause-duration-from-input", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause-duration-from-input", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.PAUSED); @@ -209,14 +210,14 @@ public class PauseTest { } public void runParallelDelay(RunnerUtils runnerUtils) throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "each-parallel-pause", Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "each-parallel-pause", Duration.ofSeconds(30)); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList()).hasSize(7); } public void runTimeout(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause-timeout", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause-timeout", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.PAUSED); @@ -235,7 +236,7 @@ public class PauseTest { } public void runEmptyTasks(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause_no_tasks", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause_no_tasks", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); Flow flow = flowRepository.findByExecution(execution); @@ -261,7 +262,7 @@ public class PauseTest { @SuppressWarnings("unchecked") public void runOnResume(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause_on_resume", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause_on_resume", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); Flow flow = flowRepository.findByExecution(execution); @@ -293,11 +294,11 @@ public class PauseTest { Map outputs = (Map) execution.findTaskRunsByTaskId("last").getFirst().getOutputs().get("values"); assertThat(outputs.get("asked")).isEqualTo("restarted"); assertThat((String) outputs.get("data")).startsWith("kestra://"); - assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(null, null, URI.create((String) outputs.get("data")))))).isEqualTo(executionId); + assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(MAIN_TENANT, null, URI.create((String) outputs.get("data")))))).isEqualTo(executionId); } public void runOnResumeMissingInputs(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause_on_resume", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause_on_resume", null, null, Duration.ofSeconds(30)); Flow flow = flowRepository.findByExecution(execution); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.PAUSED); @@ -312,7 +313,7 @@ public class PauseTest { @SuppressWarnings("unchecked") public void runOnResumeOptionalInputs(RunnerUtils runnerUtils) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause_on_resume_optional", null, null, Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause_on_resume_optional", null, null, Duration.ofSeconds(30)); String executionId = execution.getId(); Flow flow = flowRepository.findByExecution(execution); @@ -333,7 +334,7 @@ public class PauseTest { } public void runDurationWithBehavior(RunnerUtils runnerUtils, Pause.Behavior behavior) throws Exception { - Execution execution = runnerUtils.runOneUntilPaused(null, "io.kestra.tests", "pause-behavior", null, (unused, _unused) -> Map.of("behavior", behavior), Duration.ofSeconds(30)); + Execution execution = runnerUtils.runOneUntilPaused(MAIN_TENANT, "io.kestra.tests", "pause-behavior", null, (unused, _unused) -> Map.of("behavior", behavior), Duration.ofSeconds(30)); String executionId = execution.getId(); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.PAUSED); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/RetryCaseTest.java b/core/src/test/java/io/kestra/plugin/core/flow/RetryCaseTest.java index a89b5b5b08..656876719a 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/RetryCaseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/RetryCaseTest.java @@ -21,6 +21,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @Slf4j @@ -86,7 +87,7 @@ public class RetryCaseTest { }); runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "retry-new-execution-task-duration", null, @@ -113,7 +114,7 @@ public class RetryCaseTest { }); runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "retry-new-execution-task-attempts", null, @@ -140,7 +141,7 @@ public class RetryCaseTest { }); runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "retry-new-execution-flow-duration", null, @@ -167,7 +168,7 @@ public class RetryCaseTest { }); runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "retry-new-execution-flow-attempts", null, diff --git a/core/src/test/java/io/kestra/plugin/core/flow/RuntimeLabelsTest.java b/core/src/test/java/io/kestra/plugin/core/flow/RuntimeLabelsTest.java index 09b0472ca4..0c072e1ee3 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/RuntimeLabelsTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/RuntimeLabelsTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.is; @@ -27,7 +28,7 @@ class RuntimeLabelsTest { @LoadFlows({"flows/valids/labels-update-task.yml"}) void update() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "labels-update-task", null, @@ -75,7 +76,7 @@ class RuntimeLabelsTest { @LoadFlows({"flows/valids/primitive-labels-flow.yml"}) void primitiveTypeLabels() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "primitive-labels-flow", null, diff --git a/core/src/test/java/io/kestra/plugin/core/flow/StateTest.java b/core/src/test/java/io/kestra/plugin/core/flow/StateTest.java index 5f5d3a054a..e3e01c373c 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/StateTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/StateTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; @@ -29,17 +30,17 @@ class StateTest { void set() throws TimeoutException, QueueException { String stateName = IdUtils.create(); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", stateName)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", stateName)); assertThat(execution.getTaskRunList()).hasSize(5); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(((Map) execution.findTaskRunsByTaskId("createGet").getFirst().getOutputs().get("data")).get("value")).isEqualTo(1); - execution = runnerUtils.runOne(null, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", stateName)); + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", stateName)); assertThat(execution.getTaskRunList()).hasSize(5); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(((Map) execution.findTaskRunsByTaskId("updateGet").getFirst().getOutputs().get("data")).get("value")).isEqualTo("2"); - execution = runnerUtils.runOne(null, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", stateName)); + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", stateName)); assertThat(execution.getTaskRunList()).hasSize(5); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat((Integer) execution.findTaskRunsByTaskId("deleteGet").getFirst().getOutputs().get("count")).isZero(); @@ -50,7 +51,7 @@ class StateTest { @LoadFlows({"flows/valids/state.yaml"}) void each() throws TimeoutException, InternalException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", "each")); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "state", null, (f, e) -> ImmutableMap.of("state", "each")); assertThat(execution.getTaskRunList()).hasSize(17); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(((Map) execution.findTaskRunByTaskIdAndValue("regetEach1", List.of("b")).getOutputs().get("data")).get("value")).isEqualTo("null-b"); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/SwitchTest.java b/core/src/test/java/io/kestra/plugin/core/flow/SwitchTest.java index 1971be5cd0..25fc84da16 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/SwitchTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/SwitchTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; @@ -23,7 +24,7 @@ class SwitchTest { @LoadFlows({"flows/valids/switch.yaml"}) void switchFirst() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "switch", null, @@ -39,7 +40,7 @@ class SwitchTest { @LoadFlows({"flows/valids/switch.yaml"}) void switchSecond() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "switch", null, @@ -56,7 +57,7 @@ class SwitchTest { @LoadFlows({"flows/valids/switch.yaml"}) void switchThird() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "switch", null, @@ -74,7 +75,7 @@ class SwitchTest { @LoadFlows({"flows/valids/switch.yaml"}) void switchDefault() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "switch", null, @@ -90,7 +91,7 @@ class SwitchTest { @LoadFlows({"flows/valids/switch-impossible.yaml"}) void switchImpossible() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "switch-impossible", null, diff --git a/core/src/test/java/io/kestra/plugin/core/flow/TemplateTest.java b/core/src/test/java/io/kestra/plugin/core/flow/TemplateTest.java index 5bbae47546..7f1f5a1e08 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/TemplateTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/TemplateTest.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest(startRunner = true) @@ -49,6 +50,7 @@ public class TemplateTest { public static final io.kestra.core.models.templates.Template TEMPLATE_1 = io.kestra.core.models.templates.Template.builder() .id("template") .namespace("io.kestra.tests") + .tenantId(MAIN_TENANT) .tasks(Collections.singletonList(Log.builder().id("test").type(Log.class.getName()).message("{{ parent.outputs.args['my-forward'] }}").build())).build(); public static void withTemplate( @@ -62,7 +64,7 @@ public class TemplateTest { Flux receive = TestsUtils.receive(logQueue, either -> logs.add(either.getLeft())); Execution execution = runnerUtils.runOne( - null, + MAIN_TENANT, "io.kestra.tests", "with-template", null, @@ -92,7 +94,7 @@ public class TemplateTest { List logs = new CopyOnWriteArrayList<>(); Flux receive = TestsUtils.receive(logQueue, either -> logs.add(either.getLeft())); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "with-failed-template", Duration.ofSeconds(60)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "with-failed-template", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList()).hasSize(1); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/VariablesTest.java b/core/src/test/java/io/kestra/plugin/core/flow/VariablesTest.java index 1d1bb4c672..1c3ffccb02 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/VariablesTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/VariablesTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.ExecuteFlow; @@ -49,7 +50,7 @@ class VariablesTest { List logs = new CopyOnWriteArrayList<>(); Flux receive = TestsUtils.receive(workerTaskLogQueue, either -> logs.add(either.getLeft())); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "variables-invalid"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "variables-invalid"); assertThat(execution.getTaskRunList()).hasSize(2); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java b/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java index d8a03b863d..746346f191 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java @@ -3,24 +3,22 @@ package io.kestra.plugin.core.flow; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.flows.State; import io.kestra.core.queues.QueueException; -import io.kestra.core.repositories.FlowRepositoryInterface; import io.kestra.core.runners.RunnerUtils; import jakarta.inject.Inject; import java.util.Map; import java.util.concurrent.TimeoutException; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; public class WaitForCaseTest { - @Inject - FlowRepositoryInterface flowRepository; @Inject protected RunnerUtils runnerUtils; public void waitfor() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList().getFirst().getOutputs()).isNotNull(); @@ -28,7 +26,7 @@ public class WaitForCaseTest { } public void waitforMaxIterations() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-max-iterations"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor-max-iterations"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat(execution.getTaskRunList().getFirst().getOutputs()).isNotNull(); @@ -36,13 +34,13 @@ public class WaitForCaseTest { } public void waitforMaxDuration() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-max-duration"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor-max-duration"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); } public void waitforNoSuccess() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-no-success"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor-no-success"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList().getFirst().getOutputs()).isNotNull(); @@ -51,7 +49,7 @@ public class WaitForCaseTest { @SuppressWarnings("unchecked") public void waitforMultipleTasks() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-multiple-tasks"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor-multiple-tasks"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -62,14 +60,14 @@ public class WaitForCaseTest { } public void waitforMultipleTasksFailed() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-multiple-tasks-failed"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor-multiple-tasks-failed"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat(execution.getTaskRunList().getLast().attemptNumber()).isEqualTo(1); } public void waitForChildTaskWarning() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-child-task-warning"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "waitfor-child-task-warning"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.FAILED); assertThat((Integer) execution.getTaskRunList().getFirst().getOutputs().get("iterationCount")).isGreaterThan(1); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/WorkingDirectoryTest.java b/core/src/test/java/io/kestra/plugin/core/flow/WorkingDirectoryTest.java index 9fbe236960..e0bd349eef 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/WorkingDirectoryTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/WorkingDirectoryTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.flow; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -116,7 +117,7 @@ public class WorkingDirectoryTest { StorageInterface storageInterface; public void success(RunnerUtils runnerUtils) throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory", null, (f, e) -> ImmutableMap.of("failed", "false"), Duration.ofSeconds(60) ); @@ -126,7 +127,7 @@ public class WorkingDirectoryTest { } public void failed(RunnerUtils runnerUtils) throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory", null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory", null, (f, e) -> ImmutableMap.of("failed", "true"), Duration.ofSeconds(60) ); @@ -136,7 +137,7 @@ public class WorkingDirectoryTest { } public void each(RunnerUtils runnerUtils) throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-each", Duration.ofSeconds(60)); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-each", Duration.ofSeconds(60)); assertThat(execution.getTaskRunList()).hasSize(8); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -146,7 +147,7 @@ public class WorkingDirectoryTest { @SuppressWarnings("unchecked") public void outputFiles(RunnerUtils runnerUtils) throws TimeoutException, IOException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-outputs"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-outputs"); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -173,7 +174,7 @@ public class WorkingDirectoryTest { @SuppressWarnings("unchecked") public void inputFiles(RunnerUtils runnerUtils) throws TimeoutException, IOException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-inputs"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-inputs"); assertThat(execution.getTaskRunList()).hasSize(2); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -203,6 +204,7 @@ public class WorkingDirectoryTest { .builder() .namespace("io.kestra.tests") .id("working-directory-cache") + .tenantId(MAIN_TENANT) .build() ); InternalStorage storage = new InternalStorage( @@ -214,9 +216,9 @@ public class WorkingDirectoryTest { storage.deleteCacheFile("workingDir", null); URI cacheURI = storageContext.getCacheURI("workingdir", null); - assertFalse(storageInterface.exists(null, null, cacheURI)); + assertFalse(storageInterface.exists(MAIN_TENANT, null, cacheURI)); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-cache"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-cache"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getTaskRunList().stream() @@ -224,10 +226,10 @@ public class WorkingDirectoryTest { .findFirst().get() .getOutputs()).containsAllEntriesOf(Map.of("uris", Collections.emptyMap())); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); - assertTrue(storageInterface.exists(null, null, cacheURI)); + assertTrue(storageInterface.exists(MAIN_TENANT, null, cacheURI)); // a second run should use the cache so the task `exists` should output the cached file - execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-cache"); + execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-cache"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(((Map) execution.getTaskRunList().stream() @@ -240,7 +242,7 @@ public class WorkingDirectoryTest { } public void taskRun(RunnerUtils runnerUtils) throws TimeoutException, InternalException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-taskrun"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-taskrun"); assertThat(execution.getTaskRunList()).hasSize(3); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -248,7 +250,7 @@ public class WorkingDirectoryTest { } public void taskRunNested(RunnerUtils runnerUtils) throws TimeoutException, InternalException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-taskrun-nested"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-taskrun-nested"); assertThat(execution.getTaskRunList()).hasSize(6); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); @@ -261,7 +263,7 @@ public class WorkingDirectoryTest { put("/a/b/3.txt", "third"); put("/ignore/4.txt", "4th"); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-namespace-files"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-namespace-files"); assertThat(execution.getTaskRunList()).hasSize(6); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.WARNING); @@ -285,7 +287,7 @@ public class WorkingDirectoryTest { //third namespace put("/test/a/b/c/1.txt", "first in third namespace", "io.test.third"); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-namespace-files-with-namespaces"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-namespace-files-with-namespaces"); assertThat(execution.getTaskRunList()).hasSize(6); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.WARNING); @@ -297,7 +299,7 @@ public class WorkingDirectoryTest { @SuppressWarnings("unchecked") public void encryption(RunnerUtils runnerUtils, RunContextFactory runContextFactory) throws TimeoutException, GeneralSecurityException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "working-directory-taskrun-encrypted"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "working-directory-taskrun-encrypted"); assertThat(execution.getTaskRunList()).hasSize(3); Map encryptedString = (Map) execution.findTaskRunsByTaskId("encrypted").getFirst().getOutputs().get("value"); @@ -314,7 +316,7 @@ public class WorkingDirectoryTest { private void put(String path, String content, String namespace) throws IOException { storageInterface.put( - null, + MAIN_TENANT, null, URI.create(StorageContext.namespaceFilePrefix(namespace) + path), new ByteArrayInputStream(content.getBytes()) diff --git a/core/src/test/java/io/kestra/plugin/core/http/DownloadTest.java b/core/src/test/java/io/kestra/plugin/core/http/DownloadTest.java index 5dcfec6fb5..6dfd5bcadb 100644 --- a/core/src/test/java/io/kestra/plugin/core/http/DownloadTest.java +++ b/core/src/test/java/io/kestra/plugin/core/http/DownloadTest.java @@ -1,6 +1,7 @@ package io.kestra.plugin.core.http; import com.google.common.collect.ImmutableMap; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.http.client.HttpClientResponseException; import io.kestra.core.http.client.configurations.HttpConfiguration; import io.kestra.core.junit.annotations.KestraTest; @@ -26,6 +27,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.List; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -34,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class DownloadTest { public static final String FILE = "https://sampletestfile.com/wp-content/uploads/2023/07/500KB-CSV.csv"; @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Inject private StorageInterface storageInterface; @@ -54,7 +56,7 @@ class DownloadTest { Download.Output output = task.run(runContext); - assertThat(IOUtils.toString(this.storageInterface.get(null, null, output.getUri()), StandardCharsets.UTF_8)).isEqualTo(IOUtils.toString(new URI(FILE).toURL().openStream(), StandardCharsets.UTF_8)); + assertThat(IOUtils.toString(this.storageInterface.get(MAIN_TENANT, null, output.getUri()), StandardCharsets.UTF_8)).isEqualTo(IOUtils.toString(new URI(FILE).toURL().openStream(), StandardCharsets.UTF_8)); assertThat(output.getUri().toString()).endsWith(".csv"); } @@ -95,7 +97,7 @@ class DownloadTest { Download.Output output = assertDoesNotThrow(() -> task.run(runContext)); assertThat(output.getLength()).isEqualTo(0L); - assertThat(IOUtils.toString(this.storageInterface.get(null, null, output.getUri()), StandardCharsets.UTF_8)).isEqualTo(""); + assertThat(IOUtils.toString(this.storageInterface.get(MAIN_TENANT, null, output.getUri()), StandardCharsets.UTF_8)).isEqualTo(""); } @Test @@ -134,7 +136,7 @@ class DownloadTest { Download.Output output = task.run(runContext); - assertThat(this.storageInterface.get(null, null, output.getUri()).readAllBytes().length).isEqualTo(10000 * 12); + assertThat(this.storageInterface.get(MAIN_TENANT, null, output.getUri()).readAllBytes().length).isEqualTo(10000 * 12); } @Test diff --git a/core/src/test/java/io/kestra/plugin/core/http/RequestTest.java b/core/src/test/java/io/kestra/plugin/core/http/RequestTest.java index 445283bbca..d9445432b5 100644 --- a/core/src/test/java/io/kestra/plugin/core/http/RequestTest.java +++ b/core/src/test/java/io/kestra/plugin/core/http/RequestTest.java @@ -2,6 +2,7 @@ package io.kestra.plugin.core.http; import com.devskiller.friendly_id.FriendlyId; import com.google.common.collect.ImmutableMap; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.http.client.HttpClientRequestException; import io.kestra.core.http.client.HttpClientResponseException; import io.kestra.core.http.client.configurations.*; @@ -36,6 +37,7 @@ import java.util.Base64; import java.util.Map; import java.util.Objects; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.core.utils.Rethrow.throwFunction; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -43,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @KestraTest class RequestTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Inject private StorageInterface storageInterface; @@ -356,7 +358,7 @@ class RequestTest { File file = new File(Objects.requireNonNull(RequestTest.class.getClassLoader().getResource("application-test.yml")).toURI()); URI fileStorage = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/" + FriendlyId.createFriendlyId()), new FileInputStream(file) @@ -390,7 +392,7 @@ class RequestTest { File file = new File(Objects.requireNonNull(RequestTest.class.getClassLoader().getResource("application-test.yml")).toURI()); URI fileStorage = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/" + FriendlyId.createFriendlyId()), new FileInputStream(file) diff --git a/core/src/test/java/io/kestra/plugin/core/http/TriggerTest.java b/core/src/test/java/io/kestra/plugin/core/http/TriggerTest.java index 9dbdcb80ef..350b2b065f 100644 --- a/core/src/test/java/io/kestra/plugin/core/http/TriggerTest.java +++ b/core/src/test/java/io/kestra/plugin/core/http/TriggerTest.java @@ -60,7 +60,7 @@ class TriggerTest { worker.run(); scheduler.run(); - repositoryLoader.load(null, Objects.requireNonNull(TriggerTest.class.getClassLoader().getResource("flows/valids/http-listen.yaml"))); + repositoryLoader.load(Objects.requireNonNull(TriggerTest.class.getClassLoader().getResource("flows/valids/http-listen.yaml"))); assertTrue(queueCount.await(1, TimeUnit.MINUTES)); receive.blockLast(); @@ -89,7 +89,7 @@ class TriggerTest { worker.run(); scheduler.run(); - repositoryLoader.load(null, Objects.requireNonNull(TriggerTest.class.getClassLoader().getResource("flows/valids/http-listen-encrypted.yaml"))); + repositoryLoader.load(Objects.requireNonNull(TriggerTest.class.getClassLoader().getResource("flows/valids/http-listen-encrypted.yaml"))); assertTrue(queueCount.await(1, TimeUnit.MINUTES)); worker.shutdown(); diff --git a/core/src/test/java/io/kestra/plugin/core/log/PurgeLogsTest.java b/core/src/test/java/io/kestra/plugin/core/log/PurgeLogsTest.java index 002da11a4a..cfaeb6ce8b 100644 --- a/core/src/test/java/io/kestra/plugin/core/log/PurgeLogsTest.java +++ b/core/src/test/java/io/kestra/plugin/core/log/PurgeLogsTest.java @@ -5,7 +5,6 @@ import io.kestra.core.junit.annotations.LoadFlows; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.executions.LogEntry; import io.kestra.core.repositories.LogRepositoryInterface; -import io.kestra.core.runners.RunContextFactory; import io.kestra.core.runners.RunnerUtils; import jakarta.inject.Inject; import java.time.temporal.ChronoUnit; @@ -18,13 +17,12 @@ import org.slf4j.event.Level; import java.time.Instant; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @KestraTest(startRunner = true) class PurgeLogsTest { - @Inject - private RunContextFactory runContextFactory; @Inject private LogRepositoryInterface logRepository; @@ -39,13 +37,14 @@ class PurgeLogsTest { var logEntry = LogEntry.builder() .namespace("namespace") .flowId("flowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now()) .level(Level.INFO) .message("Hello World") .build(); logRepository.save(logEntry); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "purge_logs_no_arguments"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "purge_logs_no_arguments"); assertTrue(execution.getState().isSuccess()); assertThat(execution.getTaskRunList()).hasSize(1); @@ -59,7 +58,7 @@ class PurgeLogsTest { void run_with_full_arguments(LogEntry logEntry, int resultCount, String failingReason) throws Exception { logRepository.save(logEntry); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "purge_logs_full_arguments"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests", "purge_logs_full_arguments"); assertTrue(execution.getState().isSuccess()); assertThat(execution.getTaskRunList().size()).isEqualTo(1); @@ -71,6 +70,7 @@ class PurgeLogsTest { Arguments.of(LogEntry.builder() .namespace("purge.namespace") .flowId("purgeFlowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now().plus(5, ChronoUnit.HOURS)) .level(Level.INFO) .message("Hello World") @@ -78,6 +78,7 @@ class PurgeLogsTest { Arguments.of(LogEntry.builder() .namespace("purge.namespace") .flowId("purgeFlowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now().minus(5, ChronoUnit.HOURS)) .level(Level.INFO) .message("Hello World") @@ -85,6 +86,7 @@ class PurgeLogsTest { Arguments.of(LogEntry.builder() .namespace("uncorrect.namespace") .flowId("purgeFlowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now().minusSeconds(10)) .level(Level.INFO) .message("Hello World") @@ -92,6 +94,7 @@ class PurgeLogsTest { Arguments.of(LogEntry.builder() .namespace("purge.namespace") .flowId("wrongFlowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now().minusSeconds(10)) .level(Level.INFO) .message("Hello World") @@ -99,6 +102,7 @@ class PurgeLogsTest { Arguments.of(LogEntry.builder() .namespace("purge.namespace") .flowId("purgeFlowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now().minusSeconds(10)) .level(Level.WARN) .message("Hello World") @@ -106,6 +110,7 @@ class PurgeLogsTest { Arguments.of(LogEntry.builder() .namespace("purge.namespace") .flowId("purgeFlowId") + .tenantId(MAIN_TENANT) .timestamp(Instant.now().minusSeconds(10)) .level(Level.INFO) .message("Hello World") diff --git a/core/src/test/java/io/kestra/plugin/core/metric/PublishTest.java b/core/src/test/java/io/kestra/plugin/core/metric/PublishTest.java index e60c9c7474..1709ef6eb2 100644 --- a/core/src/test/java/io/kestra/plugin/core/metric/PublishTest.java +++ b/core/src/test/java/io/kestra/plugin/core/metric/PublishTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.metric; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.property.Property; import io.kestra.core.models.tasks.metrics.CounterMetric; @@ -19,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; @KestraTest public class PublishTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void run() throws Exception { diff --git a/core/src/test/java/io/kestra/plugin/core/namespace/UploadFilesTest.java b/core/src/test/java/io/kestra/plugin/core/namespace/UploadFilesTest.java index afd5a46309..aeefe0133c 100644 --- a/core/src/test/java/io/kestra/plugin/core/namespace/UploadFilesTest.java +++ b/core/src/test/java/io/kestra/plugin/core/namespace/UploadFilesTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -44,7 +45,7 @@ public class UploadFilesTest { File file = new File(Objects.requireNonNull(UploadFilesTest.class.getClassLoader().getResource("application-test.yml")).toURI()); URI fileStorage = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/" + FriendlyId.createFriendlyId()), new FileInputStream(file) @@ -169,7 +170,7 @@ public class UploadFilesTest { File file = new File(Objects.requireNonNull(UploadFilesTest.class.getClassLoader().getResource(fileToLoad)).toURI()); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/" + FriendlyId.createFriendlyId()), new FileInputStream(file) diff --git a/core/src/test/java/io/kestra/plugin/core/storage/ConcatTest.java b/core/src/test/java/io/kestra/plugin/core/storage/ConcatTest.java index fdc94bb744..3a837df955 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/ConcatTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/ConcatTest.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Objects; import jakarta.inject.Inject; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -38,7 +39,7 @@ class ConcatTest { .toURI()); URI put = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/get.yml"), new FileInputStream(Objects.requireNonNull(resource).getFile()) @@ -56,7 +57,7 @@ class ConcatTest { String s = CharStreams.toString(new InputStreamReader(new FileInputStream(file))); - assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(null, null, run.getUri())))).isEqualTo(s + "\n" + s + "\n"); + assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(MAIN_TENANT, null, run.getUri())))).isEqualTo(s + "\n" + s + "\n"); assertThat(run.getUri().getPath()).endsWith(".yml"); } diff --git a/core/src/test/java/io/kestra/plugin/core/storage/DeleteTest.java b/core/src/test/java/io/kestra/plugin/core/storage/DeleteTest.java index f0ba2469e6..4182f14b39 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/DeleteTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/DeleteTest.java @@ -1,10 +1,10 @@ package io.kestra.plugin.core.storage; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.property.Property; import org.junit.jupiter.api.Test; import io.kestra.core.runners.RunContext; -import io.kestra.core.runners.RunContextFactory; import io.kestra.core.storages.StorageInterface; import java.io.FileInputStream; @@ -14,13 +14,14 @@ import java.util.NoSuchElementException; import java.util.Objects; import jakarta.inject.Inject; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @KestraTest class DeleteTest { @Inject - RunContextFactory runContextFactory; + TestRunContextFactory runContextFactory; @Inject StorageInterface storageInterface; @@ -31,7 +32,7 @@ class DeleteTest { URL resource = DeleteTest.class.getClassLoader().getResource("application-test.yml"); URI put = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/get.yml"), new FileInputStream(Objects.requireNonNull(resource).getFile()) diff --git a/core/src/test/java/io/kestra/plugin/core/storage/LocalFilesTest.java b/core/src/test/java/io/kestra/plugin/core/storage/LocalFilesTest.java index ec89a4b716..46e8855880 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/LocalFilesTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/LocalFilesTest.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -35,7 +36,7 @@ class LocalFilesTest { var resource = ConcatTest.class.getClassLoader().getResource("application-test.yml"); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/get.yml"), new FileInputStream(Objects.requireNonNull(resource).getFile()) @@ -63,10 +64,10 @@ class LocalFilesTest { assertThat(outputs).isNotNull(); assertThat(outputs.getUris()).isNotNull(); assertThat(outputs.getUris().size()).isEqualTo(1); - assertThat(new String(storageInterface.get(null, null, outputs.getUris().get("hello-input.txt")).readAllBytes())).isEqualTo("Hello Input"); + assertThat(new String(storageInterface.get(MAIN_TENANT, null, outputs.getUris().get("hello-input.txt")).readAllBytes())).isEqualTo("Hello Input"); assertThat(runContext.workingDir().path().toFile().list().length).isEqualTo(2); assertThat(Files.readString(runContext.workingDir().path().resolve("execution.txt"))).isEqualTo("tata"); - assertThat(Files.readString(runContext.workingDir().path().resolve("application-test.yml"))).isEqualTo(new String(storageInterface.get(null, null, storageFile).readAllBytes())); + assertThat(Files.readString(runContext.workingDir().path().resolve("application-test.yml"))).isEqualTo(new String(storageInterface.get(MAIN_TENANT, null, storageFile).readAllBytes())); runContext.cleanup(); } @@ -91,11 +92,11 @@ class LocalFilesTest { assertThat(outputs).isNotNull(); assertThat(outputs.getUris()).isNotNull(); assertThat(outputs.getUris().size()).isEqualTo(3); - assertThat(new String(storageInterface.get(null, null, outputs.getUris().get("test/hello-input.txt")).readAllBytes())).isEqualTo("Hello Input"); - assertThat(new String(storageInterface.get(null, null, outputs.getUris().get("test/sub/dir/2/execution.txt")) + assertThat(new String(storageInterface.get(MAIN_TENANT, null, outputs.getUris().get("test/hello-input.txt")).readAllBytes())).isEqualTo("Hello Input"); + assertThat(new String(storageInterface.get(MAIN_TENANT, null, outputs.getUris().get("test/sub/dir/2/execution.txt")) .readAllBytes())).isEqualTo("tata"); - assertThat(new String(storageInterface.get(null, null, outputs.getUris().get("test/sub/dir/3/application-test.yml")) - .readAllBytes())).isEqualTo(new String(storageInterface.get(null, null, storageFile).readAllBytes())); + assertThat(new String(storageInterface.get(MAIN_TENANT, null, outputs.getUris().get("test/sub/dir/3/application-test.yml")) + .readAllBytes())).isEqualTo(new String(storageInterface.get(MAIN_TENANT, null, storageFile).readAllBytes())); runContext.cleanup(); } diff --git a/core/src/test/java/io/kestra/plugin/core/storage/PurgeCurrentExecutionFilesTest.java b/core/src/test/java/io/kestra/plugin/core/storage/PurgeCurrentExecutionFilesTest.java index 150997a845..9f9565e9bc 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/PurgeCurrentExecutionFilesTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/PurgeCurrentExecutionFilesTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.storage; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.flows.Flow; import io.kestra.core.runners.RunContextFactory; @@ -13,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; @KestraTest class PurgeCurrentExecutionFilesTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void run() throws Exception { diff --git a/core/src/test/java/io/kestra/plugin/core/storage/ReverseTest.java b/core/src/test/java/io/kestra/plugin/core/storage/ReverseTest.java index 67d99347eb..e69549de11 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/ReverseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/ReverseTest.java @@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.net.URI; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -28,7 +29,7 @@ class ReverseTest { RunContext runContext = runContextFactory.of(); URI put = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/get.yml"), new ByteArrayInputStream("1\n2\n3\n".getBytes()) @@ -42,6 +43,6 @@ class ReverseTest { Reverse.Output run = result.run(runContext); assertThat(run.getUri().getPath()).endsWith(".yml"); - assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(null, null, run.getUri())))).isEqualTo("3\n2\n1\n"); + assertThat(CharStreams.toString(new InputStreamReader(storageInterface.get(MAIN_TENANT, null, run.getUri())))).isEqualTo("3\n2\n1\n"); } } \ No newline at end of file diff --git a/core/src/test/java/io/kestra/plugin/core/storage/SizeTest.java b/core/src/test/java/io/kestra/plugin/core/storage/SizeTest.java index 805dd7b08f..630add91b5 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/SizeTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/SizeTest.java @@ -1,8 +1,8 @@ package io.kestra.plugin.core.storage; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.models.property.Property; import io.kestra.core.runners.RunContext; -import io.kestra.core.runners.RunContextFactory; import io.kestra.core.storages.StorageInterface; import io.kestra.core.junit.annotations.KestraTest; import org.junit.jupiter.api.Test; @@ -13,12 +13,13 @@ import java.util.Random; import jakarta.inject.Inject; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest class SizeTest { @Inject - RunContextFactory runContextFactory; + TestRunContextFactory runContextFactory; @Inject StorageInterface storageInterface; @@ -32,7 +33,7 @@ class SizeTest { new Random().nextBytes(randomBytes); URI put = storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/get.yml"), new ByteArrayInputStream(randomBytes) diff --git a/core/src/test/java/io/kestra/plugin/core/storage/SplitTest.java b/core/src/test/java/io/kestra/plugin/core/storage/SplitTest.java index 8100220942..23c6752adb 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/SplitTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/SplitTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -91,7 +92,7 @@ class SplitTest { private String readAll(List uris) throws IOException { return uris .stream() - .map(Rethrow.throwFunction(uri -> CharStreams.toString(new InputStreamReader(storageInterface.get(null, null, uri))))) + .map(Rethrow.throwFunction(uri -> CharStreams.toString(new InputStreamReader(storageInterface.get(MAIN_TENANT, null, uri))))) .collect(Collectors.joining()); } @@ -102,7 +103,7 @@ class SplitTest { Files.write(tempFile.toPath(), content(count)); return storageInterface.put( - null, + MAIN_TENANT, null, new URI("/file/storage/get.yml"), new FileInputStream(tempFile) diff --git a/core/src/test/java/io/kestra/plugin/core/storage/WriteTest.java b/core/src/test/java/io/kestra/plugin/core/storage/WriteTest.java index aa606c3af1..aa476f0569 100644 --- a/core/src/test/java/io/kestra/plugin/core/storage/WriteTest.java +++ b/core/src/test/java/io/kestra/plugin/core/storage/WriteTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import java.io.InputStream; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -33,7 +34,7 @@ class WriteTest { assertThat(output).isNotNull(); assertThat(output.getUri()).isNotNull(); - InputStream inputStream = storageInterface.get(null, null, output.getUri()); + InputStream inputStream = storageInterface.get(MAIN_TENANT, null, output.getUri()); assertThat(inputStream).isNotNull(); inputStream.close(); } diff --git a/core/src/test/java/io/kestra/plugin/core/templating/TemplatedTaskTest.java b/core/src/test/java/io/kestra/plugin/core/templating/TemplatedTaskTest.java index 4c68fc532b..329d72cd66 100644 --- a/core/src/test/java/io/kestra/plugin/core/templating/TemplatedTaskTest.java +++ b/core/src/test/java/io/kestra/plugin/core/templating/TemplatedTaskTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.templating; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.models.property.Property; import io.kestra.core.models.tasks.Output; import io.kestra.core.runners.RunContext; @@ -18,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class TemplatedTaskTest { @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Test void templatedType() throws Exception { diff --git a/core/src/test/java/io/kestra/plugin/core/trigger/ToggleTest.java b/core/src/test/java/io/kestra/plugin/core/trigger/ToggleTest.java index 3d9294e5c2..97d3352c59 100644 --- a/core/src/test/java/io/kestra/plugin/core/trigger/ToggleTest.java +++ b/core/src/test/java/io/kestra/plugin/core/trigger/ToggleTest.java @@ -1,5 +1,6 @@ package io.kestra.plugin.core.trigger; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import io.kestra.core.junit.annotations.KestraTest; @@ -60,7 +61,7 @@ class ToggleTest { } }); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests.trigger", "trigger-toggle"); + Execution execution = runnerUtils.runOne(MAIN_TENANT, "io.kestra.tests.trigger", "trigger-toggle"); assertThat(execution.getState().getCurrent()).isEqualTo(State.Type.SUCCESS); assertThat(execution.getTaskRunList()).hasSize(1); diff --git a/core/src/test/resources/flows/valids/sleep-short.yml b/core/src/test/resources/flows/valids/sleep-short.yml index d71333714c..8f9c96cfd9 100644 --- a/core/src/test/resources/flows/valids/sleep-short.yml +++ b/core/src/test/resources/flows/valids/sleep-short.yml @@ -4,4 +4,4 @@ namespace: io.kestra.tests tasks: - id: sleep-short type: io.kestra.plugin.core.flow.Sleep - duration: PT10S \ No newline at end of file + duration: PT3S \ No newline at end of file diff --git a/jdbc-h2/src/test/java/io/kestra/repository/h2/H2FlowRepositoryTest.java b/jdbc-h2/src/test/java/io/kestra/repository/h2/H2FlowRepositoryTest.java index 8aecc6ea73..0b4ef0a1f6 100644 --- a/jdbc-h2/src/test/java/io/kestra/repository/h2/H2FlowRepositoryTest.java +++ b/jdbc-h2/src/test/java/io/kestra/repository/h2/H2FlowRepositoryTest.java @@ -2,9 +2,15 @@ package io.kestra.repository.h2; import io.kestra.core.models.SearchResult; import io.kestra.core.models.flows.Flow; +import io.kestra.core.models.flows.FlowWithException; +import io.kestra.core.models.flows.GenericFlow; +import io.kestra.core.utils.IdUtils; import io.kestra.jdbc.repository.AbstractJdbcFlowRepositoryTest; +import io.kestra.plugin.core.flow.Template; import io.micronaut.data.model.Pageable; import io.micronaut.data.model.Sort; +import java.util.Collections; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,7 +18,10 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; public class H2FlowRepositoryTest extends AbstractJdbcFlowRepositoryTest { @@ -25,7 +34,7 @@ public class H2FlowRepositoryTest extends AbstractJdbcFlowRepositoryTest { @Test @Override public void findSourceCode() { - List> search = flowRepository.findSourceCode(Pageable.from(1, 10, Sort.UNSORTED), "io.kestra.plugin.core.condition.MultipleCondition", null, null); + List> search = flowRepository.findSourceCode(Pageable.from(1, 10, Sort.UNSORTED), "io.kestra.plugin.core.condition.MultipleCondition", MAIN_TENANT, null); // FIXME since the big task renaming, H2 return 6 instead of 2 // as no core change this is a test artefact, or a latent bug in H2. diff --git a/jdbc/src/test/java/io/kestra/jdbc/repository/AbstractJdbcFlowRepositoryTest.java b/jdbc/src/test/java/io/kestra/jdbc/repository/AbstractJdbcFlowRepositoryTest.java index 04ebf0ea93..21e233338d 100644 --- a/jdbc/src/test/java/io/kestra/jdbc/repository/AbstractJdbcFlowRepositoryTest.java +++ b/jdbc/src/test/java/io/kestra/jdbc/repository/AbstractJdbcFlowRepositoryTest.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.jdbc.repository.AbstractJdbcRepository.field; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +36,7 @@ public abstract class AbstractJdbcFlowRepositoryTest extends io.kestra.core.repo @Test public void findSourceCode() { - List> search = flowRepository.findSourceCode(Pageable.from(1, 10, Sort.UNSORTED), "io.kestra.plugin.core.condition.MultipleCondition", null, null); + List> search = flowRepository.findSourceCode(Pageable.from(1, 10, Sort.UNSORTED), "io.kestra.plugin.core.condition.MultipleCondition", MAIN_TENANT, null); assertThat((long) search.size()).isEqualTo(2L); @@ -72,7 +73,7 @@ public abstract class AbstractJdbcFlowRepositoryTest extends io.kestra.core.repo .execute(); }); - Optional flow = flowRepository.findByIdWithSource(null, "io.kestra.unittest", "invalid"); + Optional flow = flowRepository.findByIdWithSource(MAIN_TENANT, "io.kestra.unittest", "invalid"); try { assertThat(flow.isPresent()).isTrue(); diff --git a/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java b/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java index 4f5703bf58..555abd6dfc 100644 --- a/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java +++ b/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java @@ -23,11 +23,13 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; public abstract class JdbcRunnerTest extends AbstractRunnerTest { + public static final String NAMESPACE = "io.kestra.tests"; @Inject private JdbcTestUtils jdbcTestUtils; @@ -47,8 +49,8 @@ public abstract class JdbcRunnerTest extends AbstractRunnerTest { inputs.put("string", new String(chars)); Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", + MAIN_TENANT, + NAMESPACE, "inputs-large", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), @@ -73,8 +75,8 @@ public abstract class JdbcRunnerTest extends AbstractRunnerTest { inputs.put("string", new String(chars)); var exception = assertThrows(QueueException.class, () -> runnerUtils.runOne( - null, - "io.kestra.tests", + MAIN_TENANT, + NAMESPACE, "inputs-large", null, (flow, execution1) -> flowIO.readExecutionInputs(flow, execution1, inputs), @@ -95,8 +97,8 @@ public abstract class JdbcRunnerTest extends AbstractRunnerTest { either -> logs.add(either.getLeft())); Execution execution = runnerUtils.runOne( - null, - "io.kestra.tests", + MAIN_TENANT, + NAMESPACE, "workertask-result-too-large" ); @@ -122,7 +124,7 @@ public abstract class JdbcRunnerTest extends AbstractRunnerTest { Flux receive = TestsUtils.receive(logsQueue, either -> logs.add(either.getLeft())); - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "errors", null, null, + Execution execution = runnerUtils.runOne(MAIN_TENANT, NAMESPACE, "errors", null, null, Duration.ofSeconds(60)); assertThat(execution.getTaskRunList()).hasSize(7); @@ -137,7 +139,7 @@ public abstract class JdbcRunnerTest extends AbstractRunnerTest { @RetryingTest(5) @LoadFlows({"flows/valids/execution.yaml"}) void executionDate() throws Exception { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", + Execution execution = runnerUtils.runOne(MAIN_TENANT, NAMESPACE, "execution-start-date", null, null, Duration.ofSeconds(60)); assertThat((String) execution.getTaskRunList().getFirst().getOutputs().get("value")).matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{6}Z"); diff --git a/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcServiceLivenessCoordinatorTest.java b/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcServiceLivenessCoordinatorTest.java index 73bcf1a6c4..93dab9b53d 100644 --- a/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcServiceLivenessCoordinatorTest.java +++ b/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcServiceLivenessCoordinatorTest.java @@ -1,6 +1,7 @@ package io.kestra.jdbc.runner; import com.google.common.collect.ImmutableMap; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.conditions.ConditionContext; import io.kestra.core.models.executions.Execution; @@ -63,7 +64,7 @@ public abstract class JdbcServiceLivenessCoordinatorTest { private JdbcTestUtils jdbcTestUtils; @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Inject @Named(QueueFactoryInterface.WORKERJOB_NAMED) diff --git a/runner-memory/src/test/java/io/kestra/repository/memory/MemoryRepositoryTest.java b/runner-memory/src/test/java/io/kestra/repository/memory/MemoryRepositoryTest.java index e48be3be58..2174041bf0 100644 --- a/runner-memory/src/test/java/io/kestra/repository/memory/MemoryRepositoryTest.java +++ b/runner-memory/src/test/java/io/kestra/repository/memory/MemoryRepositoryTest.java @@ -6,6 +6,7 @@ import io.kestra.core.junit.annotations.KestraTest; import jakarta.inject.Inject; import org.junit.jupiter.api.Test; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; @KestraTest @@ -26,10 +27,10 @@ public class MemoryRepositoryTest { type: io.kestra.core.tasks.debugs.Return format: "Hello, World!" """; - flowRepositoryInterface.create(GenericFlow.fromYaml(null, flowSource)); + flowRepositoryInterface.create(GenericFlow.fromYaml(MAIN_TENANT, flowSource)); - assertThat(flowRepositoryInterface.findAll(null).size()).isEqualTo(1); + assertThat(flowRepositoryInterface.findAll(MAIN_TENANT).size()).isEqualTo(1); - assertThat(flowRepositoryInterface.findByIdWithSource(null, "some.namespace", "some-flow").get().getSource()).isEqualTo(flowSource); + assertThat(flowRepositoryInterface.findByIdWithSource(MAIN_TENANT, "some.namespace", "some-flow").get().getSource()).isEqualTo(flowSource); } } diff --git a/script/src/test/java/io/kestra/plugin/scripts/runners/LogConsumerTest.java b/script/src/test/java/io/kestra/plugin/scripts/runners/LogConsumerTest.java index 3f4a612728..18cf8c68fb 100644 --- a/script/src/test/java/io/kestra/plugin/scripts/runners/LogConsumerTest.java +++ b/script/src/test/java/io/kestra/plugin/scripts/runners/LogConsumerTest.java @@ -1,6 +1,7 @@ package io.kestra.plugin.scripts.runners; import com.google.common.collect.ImmutableMap; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.models.executions.LogEntry; import io.kestra.core.models.property.Property; import io.kestra.core.models.tasks.runners.TaskCommands; @@ -41,7 +42,7 @@ class LogConsumerTest { }; @Inject - private RunContextFactory runContextFactory; + private TestRunContextFactory runContextFactory; @Inject @Named(QueueFactoryInterface.WORKERTASKLOG_NAMED) @@ -115,6 +116,7 @@ class LogConsumerTest { Collections.emptyList() ); + Await.until(() -> logs.size() == 10, null, Duration.ofSeconds(5)); receive.blockLast(); assertThat(logs.stream().filter(m -> m.getLevel().equals(Level.INFO)).count()).isEqualTo(1L); diff --git a/tests/src/main/java/io/kestra/core/context/TestRunContextFactory.java b/tests/src/main/java/io/kestra/core/context/TestRunContextFactory.java new file mode 100644 index 0000000000..720a9fca30 --- /dev/null +++ b/tests/src/main/java/io/kestra/core/context/TestRunContextFactory.java @@ -0,0 +1,18 @@ +package io.kestra.core.context; + +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + +import com.google.common.annotations.VisibleForTesting; +import io.kestra.core.runners.RunContext; +import io.kestra.core.runners.RunContextFactory; +import jakarta.inject.Singleton; +import java.util.Map; + +@Singleton +public class TestRunContextFactory extends RunContextFactory { + + @VisibleForTesting + public RunContext of() { + return of(Map.of("flow", Map.of("id", "id", "namespace", "namespace", "tenantId", MAIN_TENANT))); + } +} diff --git a/tests/src/main/java/io/kestra/core/junit/annotations/ExecuteFlow.java b/tests/src/main/java/io/kestra/core/junit/annotations/ExecuteFlow.java index e31dc01bc9..6cbfcd699d 100644 --- a/tests/src/main/java/io/kestra/core/junit/annotations/ExecuteFlow.java +++ b/tests/src/main/java/io/kestra/core/junit/annotations/ExecuteFlow.java @@ -1,5 +1,7 @@ package io.kestra.core.junit.annotations; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import io.kestra.core.junit.extensions.FlowExecutorExtension; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -13,11 +15,10 @@ import org.junit.jupiter.api.extension.ExtendWith; @Retention(RetentionPolicy.RUNTIME) @ExtendWith(FlowExecutorExtension.class) public @interface ExecuteFlow { - String DEFAULT_TENANT_ID = ""; String value(); String timeout() default "PT60S"; - String tenantId() default DEFAULT_TENANT_ID; + String tenantId() default MAIN_TENANT; } \ No newline at end of file diff --git a/tests/src/main/java/io/kestra/core/junit/annotations/LoadFlows.java b/tests/src/main/java/io/kestra/core/junit/annotations/LoadFlows.java index adb0bdccca..607b9c60b0 100644 --- a/tests/src/main/java/io/kestra/core/junit/annotations/LoadFlows.java +++ b/tests/src/main/java/io/kestra/core/junit/annotations/LoadFlows.java @@ -1,5 +1,7 @@ package io.kestra.core.junit.annotations; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import io.kestra.core.junit.extensions.FlowLoaderExtension; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -11,9 +13,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @Retention(RetentionPolicy.RUNTIME) @ExtendWith(FlowLoaderExtension.class) public @interface LoadFlows { - String DEFAULT_TENANT_ID = ""; - String[] value(); - String tenantId() default DEFAULT_TENANT_ID; + String tenantId() default MAIN_TENANT; } \ No newline at end of file diff --git a/tests/src/main/java/io/kestra/core/junit/extensions/FlowExecutorExtension.java b/tests/src/main/java/io/kestra/core/junit/extensions/FlowExecutorExtension.java index 5cc84a1e79..7aa4eaff49 100644 --- a/tests/src/main/java/io/kestra/core/junit/extensions/FlowExecutorExtension.java +++ b/tests/src/main/java/io/kestra/core/junit/extensions/FlowExecutorExtension.java @@ -48,7 +48,7 @@ public class FlowExecutorExtension implements AfterEachCallback, ParameterResolv } ExecuteFlow executeFlow = getExecuteFlow(extensionContext); - String tenantId = ExecuteFlow.DEFAULT_TENANT_ID.equals(executeFlow.tenantId()) ? null : executeFlow.tenantId(); + String tenantId = executeFlow.tenantId(); String path = executeFlow.value(); URL url = getClass().getClassLoader().getResource(path); diff --git a/tests/src/main/java/io/kestra/core/junit/extensions/FlowLoaderExtension.java b/tests/src/main/java/io/kestra/core/junit/extensions/FlowLoaderExtension.java index 639d80c8bc..7cd9a7b4a8 100644 --- a/tests/src/main/java/io/kestra/core/junit/extensions/FlowLoaderExtension.java +++ b/tests/src/main/java/io/kestra/core/junit/extensions/FlowLoaderExtension.java @@ -2,7 +2,6 @@ package io.kestra.core.junit.extensions; import static io.kestra.core.junit.extensions.ExtensionUtils.loadFile; -import io.kestra.core.junit.annotations.ExecuteFlow; import io.kestra.core.junit.annotations.LoadFlows; import io.kestra.core.models.flows.Flow; import io.kestra.core.models.flows.FlowWithSource; @@ -45,12 +44,11 @@ public class FlowLoaderExtension implements BeforeEachCallback, AfterEachCallbac LocalFlowRepositoryLoader.class); LoadFlows loadFlows = getLoadFlows(extensionContext); - String tenantId = LoadFlows.DEFAULT_TENANT_ID.equals(loadFlows.tenantId()) ? null : loadFlows.tenantId(); for (String path : loadFlows.value()) { URL resource = loadFile(path); - TestsUtils.loads(tenantId, repositoryLoader, resource); + TestsUtils.loads(loadFlows.tenantId(), repositoryLoader, resource); } } diff --git a/tests/src/main/java/io/kestra/core/models/tasks/runners/AbstractTaskRunnerTest.java b/tests/src/main/java/io/kestra/core/models/tasks/runners/AbstractTaskRunnerTest.java index 74a35ad105..e02ce355b1 100644 --- a/tests/src/main/java/io/kestra/core/models/tasks/runners/AbstractTaskRunnerTest.java +++ b/tests/src/main/java/io/kestra/core/models/tasks/runners/AbstractTaskRunnerTest.java @@ -1,5 +1,6 @@ package io.kestra.core.models.tasks.runners; +import io.kestra.core.context.TestRunContextFactory; import io.kestra.core.junit.annotations.KestraTest; import io.kestra.core.models.executions.Execution; import io.kestra.core.models.executions.TaskRun; @@ -25,12 +26,13 @@ import java.nio.file.Path; import java.time.Instant; import java.util.*; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @KestraTest public abstract class AbstractTaskRunnerTest { - @Inject private RunContextFactory runContextFactory; + @Inject private TestRunContextFactory runContextFactory; @Inject private StorageInterface storage; @Test @@ -84,7 +86,7 @@ public abstract class AbstractTaskRunnerTest { var commands = initScriptCommands(runContext); // Generate internal storage file - FileUtils.writeStringToFile(Path.of("/tmp/unittest/internalStorage.txt").toFile(), "Hello from internal storage", StandardCharsets.UTF_8); + FileUtils.writeStringToFile(Path.of("/tmp/unittest/main/internalStorage.txt").toFile(), "Hello from internal storage", StandardCharsets.UTF_8); // Generate input files FileUtils.writeStringToFile(runContext.workingDir().resolve(Path.of("hello.txt")).toFile(), "Hello World", StandardCharsets.UTF_8); @@ -140,9 +142,9 @@ public abstract class AbstractTaskRunnerTest { assertThat(logEntries.stream().filter(e -> e.getKey().contains("Hello World")).findFirst().orElseThrow().getValue()).isFalse(); // Verify outputFiles - assertThat(IOUtils.toString(storage.get(null, "unittest", outputFiles.get("output.txt")), StandardCharsets.UTF_8)).isEqualTo("Hello World"); - assertThat(IOUtils.toString(storage.get(null, "unittest", outputFiles.get("file.txt")), StandardCharsets.UTF_8)).isEqualTo("file from output dir"); - assertThat(IOUtils.toString(storage.get(null, "unittest", outputFiles.get("nested/file.txt")), StandardCharsets.UTF_8)).isEqualTo("nested file from output dir"); + assertThat(IOUtils.toString(storage.get(MAIN_TENANT, "unittest", outputFiles.get("output.txt")), StandardCharsets.UTF_8)).isEqualTo("Hello World"); + assertThat(IOUtils.toString(storage.get(MAIN_TENANT, "unittest", outputFiles.get("file.txt")), StandardCharsets.UTF_8)).isEqualTo("file from output dir"); + assertThat(IOUtils.toString(storage.get(MAIN_TENANT, "unittest", outputFiles.get("nested/file.txt")), StandardCharsets.UTF_8)).isEqualTo("nested file from output dir"); assertThat(defaultLogConsumer.getOutputs().get("logOutput")).isEqualTo("Hello World"); } diff --git a/tests/src/main/java/io/kestra/core/storage/StorageTestSuite.java b/tests/src/main/java/io/kestra/core/storage/StorageTestSuite.java index 60e3a335ae..53bc67a4c1 100644 --- a/tests/src/main/java/io/kestra/core/storage/StorageTestSuite.java +++ b/tests/src/main/java/io/kestra/core/storage/StorageTestSuite.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; import static io.kestra.core.utils.Rethrow.throwConsumer; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.MatcherAssert.assertThat; @@ -51,24 +52,25 @@ public abstract class StorageTestSuite { @Test void getNoCrossTenant() throws Exception { String prefix = IdUtils.create(); - String tenantId = IdUtils.create(); + String fistTenant = IdUtils.create(); + String secondTenant = IdUtils.create(); - String withTenant = "/" + prefix + "/storage/withtenant.yml"; - putFile(tenantId, withTenant); - String nullTenant = "/" + prefix + "/storage/nulltenant.yml"; - putFile(null, nullTenant); + String fistTenantPath = "/" + prefix + "/storage/firstTenant.yml"; + putFile(fistTenant, fistTenantPath); + String secondTenantPath = "/" + prefix + "/storage/secondTenant.yml"; + putFile(secondTenant, secondTenantPath); - URI with = new URI(withTenant); - InputStream get = storageInterface.get(tenantId, prefix, with); + URI fistTenantUri = new URI(fistTenantPath); + InputStream get = storageInterface.get(fistTenant, prefix, fistTenantUri); assertThat(CharStreams.toString(new InputStreamReader(get))).isEqualTo(CONTENT_STRING); - assertTrue(storageInterface.exists(tenantId, prefix, with)); - assertThrows(FileNotFoundException.class, () -> storageInterface.get(null, null, with)); + assertTrue(storageInterface.exists(fistTenant, prefix, fistTenantUri)); + assertThrows(FileNotFoundException.class, () -> storageInterface.get(secondTenant, null, fistTenantUri)); - URI without = new URI(nullTenant); - get = storageInterface.get(null, prefix, without); + URI secondTenantUri = new URI(secondTenantPath); + get = storageInterface.get(secondTenant, prefix, secondTenantUri); assertThat(CharStreams.toString(new InputStreamReader(get))).isEqualTo(CONTENT_STRING); - assertTrue(storageInterface.exists(null, prefix, without)); - assertThrows(FileNotFoundException.class, () -> storageInterface.get(tenantId, null, without)); + assertTrue(storageInterface.exists(secondTenant, prefix, secondTenantUri)); + assertThrows(FileNotFoundException.class, () -> storageInterface.get(fistTenant, null, secondTenantUri)); } @@ -119,43 +121,43 @@ public abstract class StorageTestSuite { @Test void filesByPrefix() throws IOException { - storageInterface.put(null, "namespace", URI.create("/namespace/file.txt"), new ByteArrayInputStream(new byte[0])); + storageInterface.put(MAIN_TENANT, "namespace", URI.create("/namespace/file.txt"), new ByteArrayInputStream(new byte[0])); storageInterface.put("tenant", "namespace", URI.create("/namespace/tenant_file.txt"), new ByteArrayInputStream(new byte[0])); - storageInterface.put(null, "namespace", URI.create("/namespace/another_file.json"), new ByteArrayInputStream(new byte[0])); - storageInterface.put(null, "namespace", URI.create("/namespace/folder/file.txt"), new ByteArrayInputStream(new byte[0])); - storageInterface.put(null, "namespace", URI.create("/namespace/folder/some.yaml"), new ByteArrayInputStream(new byte[0])); - storageInterface.put(null, "namespace", URI.create("/namespace/folder/sub/script.py"), new ByteArrayInputStream(new byte[0])); + storageInterface.put(MAIN_TENANT, "namespace", URI.create("/namespace/another_file.json"), new ByteArrayInputStream(new byte[0])); + storageInterface.put(MAIN_TENANT, "namespace", URI.create("/namespace/folder/file.txt"), new ByteArrayInputStream(new byte[0])); + storageInterface.put(MAIN_TENANT, "namespace", URI.create("/namespace/folder/some.yaml"), new ByteArrayInputStream(new byte[0])); + storageInterface.put(MAIN_TENANT, "namespace", URI.create("/namespace/folder/sub/script.py"), new ByteArrayInputStream(new byte[0])); - List res = storageInterface.allByPrefix(null, "namespace", URI.create("kestra:///namespace/"), false); + List res = storageInterface.allByPrefix(MAIN_TENANT, "namespace", URI.create("kestra:///namespace/"), false); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///namespace/file.txt"), URI.create("kestra:///namespace/another_file.json"), URI.create("kestra:///namespace/folder/file.txt"), URI.create("kestra:///namespace/folder/some.yaml"), URI.create("kestra:///namespace/folder/sub/script.py")); res = storageInterface.allByPrefix("tenant", "namespace", URI.create("/namespace"), false); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///namespace/tenant_file.txt")); - res = storageInterface.allByPrefix(null, "namespace", URI.create("/namespace/folder"), false); + res = storageInterface.allByPrefix(MAIN_TENANT, "namespace", URI.create("/namespace/folder"), false); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///namespace/folder/file.txt"), URI.create("kestra:///namespace/folder/some.yaml"), URI.create("kestra:///namespace/folder/sub/script.py")); - res = storageInterface.allByPrefix(null, "namespace", URI.create("/namespace/folder/sub"), false); + res = storageInterface.allByPrefix(MAIN_TENANT, "namespace", URI.create("/namespace/folder/sub"), false); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///namespace/folder/sub/script.py")); - res = storageInterface.allByPrefix(null, "namespace", URI.create("/namespace/non-existing"), false); + res = storageInterface.allByPrefix(MAIN_TENANT, "namespace", URI.create("/namespace/non-existing"), false); assertThat(res).isEmpty(); } @Test void objectsByPrefix() throws IOException { - storageInterface.put(null, "some_namespace", URI.create("/some_namespace/file.txt"), new ByteArrayInputStream(new byte[0])); + storageInterface.put(MAIN_TENANT, "some_namespace", URI.create("/some_namespace/file.txt"), new ByteArrayInputStream(new byte[0])); storageInterface.put("tenant", "some_namespace", URI.create("/some_namespace/tenant_file.txt"), new ByteArrayInputStream(new byte[0])); - storageInterface.createDirectory(null, "some_namespace", URI.create("/some_namespace/folder/sub")); + storageInterface.createDirectory(MAIN_TENANT, "some_namespace", URI.create("/some_namespace/folder/sub")); - List res = storageInterface.allByPrefix(null, "some_namespace", URI.create("kestra:///some_namespace/"), true); + List res = storageInterface.allByPrefix(MAIN_TENANT, "some_namespace", URI.create("kestra:///some_namespace/"), true); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///some_namespace/file.txt"), URI.create("kestra:///some_namespace/folder/"), URI.create("kestra:///some_namespace/folder/sub/")); res = storageInterface.allByPrefix("tenant", "some_namespace", URI.create("/some_namespace"), true); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///some_namespace/tenant_file.txt")); - res = storageInterface.allByPrefix(null, "some_namespace", URI.create("/some_namespace/folder"), true); + res = storageInterface.allByPrefix(MAIN_TENANT, "some_namespace", URI.create("/some_namespace/folder"), true); assertThat(res).containsExactlyInAnyOrder(URI.create("kestra:///some_namespace/folder/sub/")); } @@ -832,9 +834,9 @@ public abstract class StorageTestSuite { @Test void createDirectoryShouldBeRecursive() throws IOException { String prefix = IdUtils.create(); - storageInterface.createDirectory(null, prefix, URI.create("/" + prefix + "/first/second/third")); + storageInterface.createDirectory(MAIN_TENANT, prefix, URI.create("/" + prefix + "/first/second/third")); - List list = storageInterface.list(null, prefix, URI.create("/" + prefix)); + List list = storageInterface.list(MAIN_TENANT, prefix, URI.create("/" + prefix)); assertThat(list, contains( hasProperty("fileName", is("first")) )); diff --git a/tests/src/main/java/io/kestra/core/utils/TestsUtils.java b/tests/src/main/java/io/kestra/core/utils/TestsUtils.java index 69658bab64..24f883d8b2 100644 --- a/tests/src/main/java/io/kestra/core/utils/TestsUtils.java +++ b/tests/src/main/java/io/kestra/core/utils/TestsUtils.java @@ -1,5 +1,7 @@ package io.kestra.core.utils; +import static io.kestra.core.tenant.TenantService.MAIN_TENANT; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.io.Files; @@ -110,20 +112,16 @@ abstract public class TestsUtils { return Flow.builder() .namespace(caller.getClassName().toLowerCase()) .id(caller.getMethodName().toLowerCase()) + .tenantId(MAIN_TENANT) .revision(1) .build(); } public static Execution mockExecution(FlowInterface flow, Map inputs) { - return TestsUtils.mockExecution(Thread.currentThread().getStackTrace()[2], flow, inputs, null); + return TestsUtils.mockExecution(flow, inputs, null); } - public static Execution mockExecution(FlowInterface flow, Map inputs, Map outputs) { - return TestsUtils.mockExecution(Thread.currentThread().getStackTrace()[2], flow, inputs, outputs); - } - - private static Execution mockExecution(StackTraceElement caller, - FlowInterface flow, + public static Execution mockExecution(FlowInterface flow, Map inputs, Map outputs) { return Execution.builder() @@ -138,15 +136,12 @@ abstract public class TestsUtils { .withState(State.Type.RUNNING); } - public static TaskRun mockTaskRun(FlowInterface flow, Execution execution, Task task) { - return TestsUtils.mockTaskRun(Thread.currentThread().getStackTrace()[2], execution, task); - } - - private static TaskRun mockTaskRun(StackTraceElement caller, Execution execution, Task task) { + private static TaskRun mockTaskRun(Execution execution, Task task) { return TaskRun.builder() .id(IdUtils.create()) .executionId(execution.getId()) .namespace(execution.getNamespace()) + .tenantId(execution.getTenantId()) .flowId(execution.getFlowId()) .taskId(task.getId()) .state(new State()) @@ -178,8 +173,8 @@ abstract public class TestsUtils { StackTraceElement caller = Thread.currentThread().getStackTrace()[2]; Flow flow = TestsUtils.mockFlow(caller); - Execution execution = TestsUtils.mockExecution(caller, flow, inputs, null); - TaskRun taskRun = TestsUtils.mockTaskRun(caller, execution, task); + Execution execution = TestsUtils.mockExecution(flow, inputs, null); + TaskRun taskRun = TestsUtils.mockTaskRun(execution, task); return runContextFactory.of(flow, task, execution, taskRun); } diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/BlueprintController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/BlueprintController.java index d1d99cde24..f00a9917c9 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/BlueprintController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/BlueprintController.java @@ -34,7 +34,7 @@ import java.util.Map; import java.util.Optional; @Validated -@Controller("/api/v1/blueprints/community") +@Controller("/api/v1/main/blueprints/community") public class BlueprintController { @Inject @Client("api") diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/ClusterController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/ClusterController.java index 8d146965d0..aeb64afac6 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/ClusterController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/ClusterController.java @@ -11,7 +11,7 @@ import io.micronaut.scheduling.annotation.ExecuteOn; import io.swagger.v3.oas.annotations.Operation; import jakarta.inject.Inject; -@Controller("/api/v1/cluster") +@Controller("/api/v1/main/cluster") @Requires(bean = ServiceInstanceRepositoryInterface.class) public class ClusterController { diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/DashboardController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/DashboardController.java index 2986a7aad1..3108864eca 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/DashboardController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/DashboardController.java @@ -1,6 +1,5 @@ package io.kestra.webserver.controllers.api; -import com.fasterxml.jackson.core.JsonProcessingException; import io.kestra.core.models.QueryFilter; import io.kestra.core.models.dashboards.Dashboard; import io.kestra.core.models.dashboards.charts.Chart; @@ -8,7 +7,6 @@ import io.kestra.core.models.dashboards.charts.DataChart; import io.kestra.core.models.validations.ModelValidator; import io.kestra.core.models.validations.ValidateConstraintViolation; import io.kestra.core.repositories.DashboardRepositoryInterface; -import io.kestra.core.serializers.JacksonMapper; import io.kestra.core.serializers.YamlParser; import io.kestra.core.tenant.TenantService; import io.kestra.core.utils.IdUtils; @@ -42,7 +40,7 @@ import java.util.Optional; import static io.kestra.core.utils.DateUtils.validateTimeline; @Validated -@Controller("/api/v1/dashboards") +@Controller("/api/v1/main/dashboards") @Slf4j public class DashboardController { @@ -82,7 +80,7 @@ public class DashboardController { public HttpResponse createDashboard( @RequestBody(description = "The dashboard definition as YAML") @Body String dashboard ) throws ConstraintViolationException { - Dashboard dashboardParsed = YamlParser.parse(dashboard, Dashboard.class).toBuilder().deleted(false).build(); + Dashboard dashboardParsed = parseDashboard(dashboard); modelValidator.validate(dashboardParsed); if (dashboardParsed.getId() != null) { @@ -124,17 +122,23 @@ public class DashboardController { public HttpResponse updateDashboard( @Parameter(description = "The dashboard id") @PathVariable String id, @RequestBody(description = "The dashboard definition as YAML") @Body String dashboard - ) throws ConstraintViolationException, JsonProcessingException { + ) throws ConstraintViolationException { Optional existingDashboard = dashboardRepository.get(tenantService.resolveTenant(), id); if (existingDashboard.isEmpty()) { return HttpResponse.status(HttpStatus.NOT_FOUND); } - Dashboard dashboardToSave = JacksonMapper.ofYaml().readValue(dashboard, Dashboard.class).toBuilder().deleted(false).build(); + Dashboard dashboardToSave = parseDashboard(dashboard); modelValidator.validate(dashboardToSave); return HttpResponse.ok(this.save(existingDashboard.get(), dashboardToSave, dashboard)); } + private Dashboard parseDashboard(String dashboard) { + return YamlParser.parse(dashboard, Dashboard.class).toBuilder() + .tenantId(tenantService.resolveTenant()) + .deleted(false).build(); + } + protected Dashboard save(Dashboard previousDashboard, Dashboard dashboard, String source) { return dashboardRepository.save(previousDashboard, dashboard, source); } diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java index 6dafec0a43..196bb26317 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/ExecutionController.java @@ -111,7 +111,7 @@ import static io.kestra.core.utils.Rethrow.throwFunction; @Slf4j @Validated -@Controller("/api/v1/executions") +@Controller("/api/v1/main/executions") public class ExecutionController { private static final Pattern SECRET_FUNCTION = Pattern.compile("(.*)(secret\\([^)]+\\))(.*)"); diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/FlowController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/FlowController.java index 3cc9a2f577..ece5e47d9a 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/FlowController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/FlowController.java @@ -68,7 +68,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; @Validated -@Controller("/api/v1/flows") +@Controller("/api/v1/main/flows") @Slf4j public class FlowController { private static final String WARNING_JSON_FLOW_ENDPOINT = "This endpoint is deprecated. Handling flows as 'application/json' is no longer supported and will be removed in a future release. Please use the same endpoint with an 'application/x-yaml' content type."; @@ -542,7 +542,7 @@ public class FlowController { ) throws ConstraintViolationException { List sources = flows != null ? List.of(flows.split("---")) : new ArrayList<>(); List genericFlows = sources.stream() - .map(source -> GenericFlow.fromYaml(null, source)) + .map(source -> GenericFlow.fromYaml(tenantService.resolveTenant(), source)) .toList(); return this.bulkUpdateOrCreate(namespace, genericFlows, delete, allowNamespaceChild); } diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/KVController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/KVController.java index ccee2eef38..9d6194dd52 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/KVController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/KVController.java @@ -22,14 +22,13 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody; import jakarta.inject.Inject; import java.io.*; -import java.net.URISyntaxException; import java.time.*; import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; @Validated -@Controller("/api/v1/namespaces/{namespace}/kv") +@Controller("/api/v1/main/namespaces/{namespace}/kv") public class KVController { @Inject private StorageInterface storageInterface; @@ -41,7 +40,7 @@ public class KVController { @Operation(tags = {"KV"}, summary = "List all keys for a namespace") public List listKeys( @Parameter(description = "The namespace id") @PathVariable String namespace - ) throws IOException, URISyntaxException { + ) throws IOException { return kvStore(namespace).list(); } @@ -51,7 +50,7 @@ public class KVController { public TypedValue getKeyValue( @Parameter(description = "The namespace id") @PathVariable String namespace, @Parameter(description = "The key") @PathVariable String key - ) throws IOException, URISyntaxException, ResourceExpiredException { + ) throws IOException, ResourceExpiredException { KVValue wrapper = kvStore(namespace) .getValue(key) .orElseThrow(() -> new NoSuchElementException("No value found for key '" + key + "' in namespace '" + namespace + "'")); @@ -70,7 +69,7 @@ public class KVController { @Parameter(description = "The namespace id") @PathVariable String namespace, @Parameter(description = "The key") @PathVariable String key, @RequestBody(description = "The value of the key") @Body String value - ) throws IOException, URISyntaxException, ResourceExpiredException { + ) throws IOException { String ttl = httpHeaders.get("ttl"); KVMetadata metadata = new KVMetadata(ttl == null ? null : Duration.parse(ttl)); try { @@ -88,7 +87,7 @@ public class KVController { public boolean deleteKeyValue( @Parameter(description = "The namespace id") @PathVariable String namespace, @Parameter(description = "The key") @PathVariable String key - ) throws IOException, URISyntaxException, ResourceExpiredException { + ) throws IOException { return kvStore(namespace).delete(key); } diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java index 1f5e297c04..4775f4a1ad 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/LogController.java @@ -41,7 +41,7 @@ import static io.kestra.core.utils.DateUtils.validateTimeline; @Validated -@Controller("/api/v1/") +@Controller("/api/v1/main/logs") @Requires(beans = LogRepositoryInterface.class) public class LogController { @Inject @@ -57,7 +57,7 @@ public class LogController { private LogStreamingService logStreamingService; @ExecuteOn(TaskExecutors.IO) - @Get(uri = "logs/search") + @Get(uri = "/search") @Operation(tags = {"Logs"}, summary = "Search for logs") public PagedResults searchLogs( @Parameter(description = "The current page") @QueryValue(defaultValue = "1") @Min(1) int page, @@ -106,7 +106,7 @@ public class LogController { } @ExecuteOn(TaskExecutors.IO) - @Get(uri = "logs/{executionId}") + @Get(uri = "/{executionId}") @Operation(tags = {"Logs"}, summary = "Get logs for a specific execution, taskrun or task") public List listLogsFromExecution( @Parameter(description = "The execution id") @PathVariable String executionId, @@ -127,7 +127,7 @@ public class LogController { } @ExecuteOn(TaskExecutors.IO) - @Get(uri = "logs/{executionId}/download", produces = MediaType.TEXT_PLAIN) + @Get(uri = "/{executionId}/download", produces = MediaType.TEXT_PLAIN) @Operation(tags = {"Logs"}, summary = "Download logs for a specific execution, taskrun or task") public StreamedFile downloadLogsFromExecution( @Parameter(description = "The execution id") @PathVariable String executionId, @@ -149,7 +149,7 @@ public class LogController { } @ExecuteOn(TaskExecutors.IO) - @Get(uri = "logs/{executionId}/follow", produces = MediaType.TEXT_EVENT_STREAM) + @Get(uri = "/{executionId}/follow", produces = MediaType.TEXT_EVENT_STREAM) @Operation(tags = {"Logs"}, summary = "Follow logs for a specific execution") public Flux> followLogsFromExecution( @Parameter(description = "The execution id") @PathVariable String executionId, @@ -173,7 +173,7 @@ public class LogController { } @ExecuteOn(TaskExecutors.IO) - @Delete(uri = "logs/{executionId}") + @Delete(uri = "/{executionId}") @Operation(tags = {"Logs"}, summary = "Delete logs for a specific execution, taskrun or task") public void deleteLogsFromExecution( @Parameter(description = "The execution id") @PathVariable String executionId, @@ -186,7 +186,7 @@ public class LogController { } @ExecuteOn(TaskExecutors.IO) - @Delete(uri = "logs/{namespace}/{flowId}") + @Delete(uri = "/{namespace}/{flowId}") @Operation(tags = {"Logs"}, summary = "Delete logs for a specific execution, taskrun or task") public void deleteLogsFromFlow( @Parameter(description = "The namespace") @PathVariable String namespace, diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/MetricController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/MetricController.java index e96bbc9132..91e64e3237 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/MetricController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/MetricController.java @@ -30,7 +30,7 @@ import java.util.List; import static io.kestra.core.utils.DateUtils.validateTimeline; @Validated -@Controller("/api/v1/metrics") +@Controller("/api/v1/main/metrics") @Requires(beans = MetricRepositoryInterface.class) public class MetricController { @Inject diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/MiscController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/MiscController.java index 57f6a9c3d1..c7302811e8 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/MiscController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/MiscController.java @@ -33,7 +33,7 @@ import java.util.List; import java.util.Optional; @Slf4j -@Controller("/api/v1") +@Controller("/api/v1/main") public class MiscController { @Inject VersionProvider versionProvider; @@ -87,7 +87,7 @@ public class MiscController { private List hiddenLabelsPrefixes; - @Get("{/tenant}/configs") + @Get("/configs") @ExecuteOn(TaskExecutors.IO) @Operation(tags = {"Misc"}, summary = "Get current configurations") public Configuration getConfiguration() throws JsonProcessingException { @@ -123,14 +123,14 @@ public class MiscController { return builder.build(); } - @Get("{/tenant}/usages/all") + @Get("/usages/all") @ExecuteOn(TaskExecutors.IO) @Operation(tags = {"Misc"}, summary = "Get instance usage information") public Usage getUsages() { return collectorService.metrics(true); } - @Post(uri = "{/tenant}/basicAuth") + @Post(uri = "/basicAuth") @ExecuteOn(TaskExecutors.IO) @Operation(tags = {"Misc"}, summary = "Create basic auth for the current instance") public HttpResponse createBasicAuth( diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceController.java index 9be207eb6c..dfbda84f5f 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceController.java @@ -32,7 +32,7 @@ import java.util.Locale; import java.util.stream.Collectors; @Validated -@Controller("/api/v1/namespaces") +@Controller("/api/v1/main/namespaces") public class NamespaceController implements NamespaceControllerInterface { @Inject private TenantService tenantService; diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceFileController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceFileController.java index 973c429458..599876bb15 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceFileController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceFileController.java @@ -38,7 +38,7 @@ import java.util.zip.ZipOutputStream; @Slf4j @Validated -@Controller("/api/v1/namespaces") +@Controller("/api/v1/main/namespaces") public class NamespaceFileController { public static final String FLOWS_FOLDER = "_flows"; @Inject diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceSecretController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceSecretController.java index 259b1fba91..c6d684d996 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceSecretController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/NamespaceSecretController.java @@ -28,7 +28,7 @@ import java.util.Set; import java.util.function.Function; @Validated -@Controller("/api/v1{/tenant}/namespaces") +@Controller("/api/v1/main/namespaces") public class NamespaceSecretController { @Inject protected TenantService tenantService; diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/PluginController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/PluginController.java index 390c35140a..f7f0a244b9 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/PluginController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/PluginController.java @@ -30,7 +30,7 @@ import java.util.stream.Stream; import static io.kestra.core.utils.Rethrow.throwFunction; @Validated -@Controller("/api/v1/plugins/") +@Controller("/api/v1/main/plugins/") public class PluginController { private static final String CACHE_DIRECTIVE = "public, max-age=3600"; diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java index e3433da56e..42f2ffef68 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/StatsController.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.Map; @Validated -@Controller("/api/v1/stats") +@Controller("/api/v1/main/stats") @Deprecated(forRemoval = true) @Hidden public class StatsController { diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/TaskRunController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/TaskRunController.java index 2e8f23a87b..3c163097b8 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/TaskRunController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/TaskRunController.java @@ -32,7 +32,7 @@ import java.util.List; import static io.kestra.core.utils.DateUtils.validateTimeline; -@Controller("/api/v1/taskruns") +@Controller("/api/v1/main/taskruns") @Requires(property = "kestra.repository.type", value = "elasticsearch") public class TaskRunController { @Inject diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/api/TemplateController.java b/webserver/src/main/java/io/kestra/webserver/controllers/api/TemplateController.java index c8e8bf50df..be5b6360a0 100644 --- a/webserver/src/main/java/io/kestra/webserver/controllers/api/TemplateController.java +++ b/webserver/src/main/java/io/kestra/webserver/controllers/api/TemplateController.java @@ -43,7 +43,7 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @Validated -@Controller("/api/v1/templates") +@Controller("/api/v1/main/templates") @TemplateEnabled @Deprecated(forRemoval = true) @Hidden @@ -88,6 +88,7 @@ public class TemplateController { public HttpResponse