Search in sources :

Example 1 with MissingRequiredInput

use of io.kestra.core.exceptions.MissingRequiredInput 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)

Aggregations

MissingRequiredInput (io.kestra.core.exceptions.MissingRequiredInput)1 Flow (io.kestra.core.models.flows.Flow)1 FlowRepositoryInterface (io.kestra.core.repositories.FlowRepositoryInterface)1 LocalFlowRepositoryLoader (io.kestra.core.repositories.LocalFlowRepositoryLoader)1 RunnerUtils (io.kestra.core.runners.RunnerUtils)1 MemoryRunner (io.kestra.runner.memory.MemoryRunner)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 CommandLine (picocli.CommandLine)1