Search in sources :

Example 1 with FlowRepositoryInterface

use of io.kestra.core.repositories.FlowRepositoryInterface in project kestra by kestra-io.

the class RestoreQueueService method flows.

public int flows(boolean noRecreate) {
    FlowRepositoryInterface flowRepository = applicationContext.getBean(FlowRepositoryInterface.class);
    List<Flow> flows = flowRepository.findAll().stream().flatMap(flow -> flowRepository.findRevisions(flow.getNamespace(), flow.getId()).stream()).filter(flow -> !(flow instanceof FlowSource)).collect(Collectors.toList());
    return this.send(flows, QueueFactoryInterface.FLOW_NAMED, Flow.class, noRecreate);
}
Also used : TemplateRepositoryInterface(io.kestra.core.repositories.TemplateRepositoryInterface) QueueFactoryInterface(io.kestra.core.queues.QueueFactoryInterface) KafkaAdminService(io.kestra.runner.kafka.services.KafkaAdminService) SneakyThrows(lombok.SneakyThrows) QueueInterface(io.kestra.core.queues.QueueInterface) Qualifiers(io.micronaut.inject.qualifiers.Qualifiers) Singleton(jakarta.inject.Singleton) Trigger(io.kestra.core.models.triggers.Trigger) FlowSource(io.kestra.core.models.flows.FlowSource) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationContext(io.micronaut.context.ApplicationContext) TriggerRepositoryInterface(io.kestra.core.repositories.TriggerRepositoryInterface) Optional(java.util.Optional) Flow(io.kestra.core.models.flows.Flow) Template(io.kestra.core.models.templates.Template) Inject(jakarta.inject.Inject) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) FlowSource(io.kestra.core.models.flows.FlowSource) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) Flow(io.kestra.core.models.flows.Flow)

Example 2 with FlowRepositoryInterface

use of io.kestra.core.repositories.FlowRepositoryInterface in project kestra by kestra-io.

the class FlowTestCommand method call.

@Override
public Integer call() throws Exception {
    super.call();
    MemoryRunner runner = applicationContext.getBean(MemoryRunner.class);
    LocalFlowRepositoryLoader repositoryLoader = applicationContext.getBean(LocalFlowRepositoryLoader.class);
    FlowRepositoryInterface flowRepository = applicationContext.getBean(FlowRepositoryInterface.class);
    RunnerUtils runnerUtils = applicationContext.getBean(RunnerUtils.class);
    Map<String, String> inputs = new HashMap<>();
    for (int i = 0; i < this.inputs.size(); i = i + 2) {
        if (this.inputs.size() <= i + 1) {
            throw new CommandLine.ParameterException(this.spec.commandLine(), "Invalid key pair value for inputs");
        }
        inputs.put(this.inputs.get(i), this.inputs.get(i + 1));
    }
    try {
        runner.run();
        repositoryLoader.load(file.toFile());
        List<Flow> all = flowRepository.findAll();
        if (all.size() != 1) {
            throw new IllegalArgumentException("Too many flow found, need 1, found " + all.size());
        }
        runnerUtils.runOne(all.get(0), (flow, execution) -> runnerUtils.typedInputs(flow, execution, inputs), Duration.ofHours(1));
        runner.close();
    } catch (MissingRequiredInput e) {
        throw new CommandLine.ParameterException(this.spec.commandLine(), e.getMessage());
    } catch (IOException | TimeoutException e) {
        throw new IllegalStateException(e);
    } finally {
        applicationContext.getProperty("kestra.storage.local.base-path", Path.class).ifPresent(path -> {
            try {
                FileUtils.deleteDirectory(path.toFile());
            } catch (IOException ignored) {
            }
        });
    }
    return 0;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IOException(java.io.IOException) Flow(io.kestra.core.models.flows.Flow) CommandLine(picocli.CommandLine) MemoryRunner(io.kestra.runner.memory.MemoryRunner) LocalFlowRepositoryLoader(io.kestra.core.repositories.LocalFlowRepositoryLoader) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) RunnerUtils(io.kestra.core.runners.RunnerUtils) MissingRequiredInput(io.kestra.core.exceptions.MissingRequiredInput) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with FlowRepositoryInterface

use of io.kestra.core.repositories.FlowRepositoryInterface in project kestra by kestra-io.

the class FlowListenersRestoreCommandTest method run.

@Test
void run() throws InterruptedException {
    final int COUNT = 5;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    System.setOut(new PrintStream(out));
    try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) {
        FlowRepositoryInterface flowRepository = ctx.getBean(FlowRepositoryInterface.class);
        Thread thread = new Thread(() -> {
            Integer result = PicocliRunner.call(FlowListenersRestoreCommand.class, ctx, "--timeout=PT1S");
            assertThat(result, is(0));
        });
        thread.start();
        for (int i = 0; i < COUNT; i++) {
            flowRepository.create(RestoreQueueCommandTest.create());
            Thread.sleep(100);
        }
        thread.join();
        assertThat(out.toString(), containsString("Received 1 active flows"));
        assertThat(out.toString(), containsString("Received 5 active flows"));
    }
}
Also used : PrintStream(java.io.PrintStream) ApplicationContext(io.micronaut.context.ApplicationContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) Test(org.junit.jupiter.api.Test)

Example 4 with FlowRepositoryInterface

use of io.kestra.core.repositories.FlowRepositoryInterface in project kestra by kestra-io.

the class RestoreQueueCommandTest method run.

@SuppressWarnings("unchecked")
@Test
void run() throws InterruptedException {
    final int COUNT = 5;
    try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) {
        FlowRepositoryInterface flowRepository = ctx.getBean(FlowRepositoryInterface.class);
        QueueInterface<Flow> flowQueue = ctx.getBean(QueueInterface.class, Qualifiers.byName(QueueFactoryInterface.FLOW_NAMED));
        AtomicInteger atomicInteger = new AtomicInteger();
        for (int i = 0; i < COUNT; i++) {
            flowRepository.create(create());
        }
        CountDownLatch countDownLatch = new CountDownLatch(COUNT);
        flowQueue.receive(e -> {
            atomicInteger.incrementAndGet();
            countDownLatch.countDown();
        });
        PicocliRunner.call(RestoreQueueCommand.class, ctx);
        countDownLatch.await();
        assertThat(atomicInteger.get(), is(COUNT));
    }
}
Also used : ApplicationContext(io.micronaut.context.ApplicationContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FlowRepositoryInterface(io.kestra.core.repositories.FlowRepositoryInterface) CountDownLatch(java.util.concurrent.CountDownLatch) Flow(io.kestra.core.models.flows.Flow) Test(org.junit.jupiter.api.Test)

Aggregations

FlowRepositoryInterface (io.kestra.core.repositories.FlowRepositoryInterface)4 Flow (io.kestra.core.models.flows.Flow)3 ApplicationContext (io.micronaut.context.ApplicationContext)3 Test (org.junit.jupiter.api.Test)2 MissingRequiredInput (io.kestra.core.exceptions.MissingRequiredInput)1 FlowSource (io.kestra.core.models.flows.FlowSource)1 Template (io.kestra.core.models.templates.Template)1 Trigger (io.kestra.core.models.triggers.Trigger)1 QueueFactoryInterface (io.kestra.core.queues.QueueFactoryInterface)1 QueueInterface (io.kestra.core.queues.QueueInterface)1 LocalFlowRepositoryLoader (io.kestra.core.repositories.LocalFlowRepositoryLoader)1 TemplateRepositoryInterface (io.kestra.core.repositories.TemplateRepositoryInterface)1 TriggerRepositoryInterface (io.kestra.core.repositories.TriggerRepositoryInterface)1 RunnerUtils (io.kestra.core.runners.RunnerUtils)1 KafkaAdminService (io.kestra.runner.kafka.services.KafkaAdminService)1 MemoryRunner (io.kestra.runner.memory.MemoryRunner)1 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)1 Inject (jakarta.inject.Inject)1 Singleton (jakarta.inject.Singleton)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1