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);
}
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;
}
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"));
}
}
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));
}
}
Aggregations