Spring Cloud Data Flow:无法启动同一任务的多个实例 [英] Spring Cloud Data Flow : Unable to launch multiple instances of the same Task

查看:47
本文介绍了Spring Cloud Data Flow:无法启动同一任务的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL;DR

即使 文档 说这是默认行为.我们如何允许 SCDF 使用 Java DSL 同时运行同一任务的多个实例来启动任务?为了让事情变得更有趣,例如,当使用 curl 直接命中其余端点时,多次启动相同的任务可以正常工作.

Spring Cloud Data Flow does not allow multiple executions of the same Task even though the documentation says that this is the default behavior. How can we allow SCDF to run multiple instances of the same task at the same time using the Java DSL to launch tasks? To make things more interesting, launching of the same task multiple times works fine when directly hitting the rest enpoints using curl for example.

背景:

我有一个 Spring Cloud 数据流任务,我已经在 Spring Cloud 数据流 UI 仪表板

I have a Spring Cloud Data Flow Task that I have pre-registered in the Spring Cloud Data Flow UI Dashboard

@SpringBootApplication
@EnableTask
public class TaskApplication implements ApplicationRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(TaskApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws InterruptedException {
        //Some application code
    }
    
}

我正在使用 任务 Java DSL 在其他一些主程序中:

I am launching this task using the Task Java DSL in some other main program :

URI dataFlowUri = URI.create(scdfUri);
DataFlowOperations dataFlowOperations = new DataFlowTemplate(dataFlowUri);
Task task = Task.builder(dataFlowOperations).name("Task1").definition("a:task1")
                .description("Task launched from DSL").build();         
long executionId = task.launch(new ArrayList<>());

这第一次运行得很好;但是,当我尝试重新运行上述代码时,在上述程序中出现以下异常:

This works perfectly fine the first time; however, when I try to rerun the above code, I get the following exception in the above program :

[main] DEBUG org.springframework.web.client.RestTemplate - Response 409 CONFLICT

SCDF 服务器日志显示了类似的问题:

The SCDF server logs show a similar issue :

2021-05-12 15:12:31.387  WARN 1 --- [nio-9393-exec-3] o.s.c.d.s.c.RestControllerAdvice         : Caught exception while handling a request: Cannot register task Task1 because another one has already been registered with the same name

有趣的部分是,如果我使用 API 指南

The interesting part is that I am able to launch multiple instances of the same task if I use the curl command as shown in the API guide

问题:

  1. 根据 SCDF 任务文档,默认情况下可以重新运行任务.无需额外配置即可重新运行相同的任务;然而,事实似乎恰恰相反.SCDF 默认不允许任务重新运行?

  1. As per the SCDF Task documentation, a Task can be rerun by default. There is no additional configuration required to be able to rerun the same task; however, it looks like the opposite is true. SCDF does not allow a task to be rerun by default?

我尝试按照建议添加 Spring 集成 jar 并将 spring.cloud.task.single-instance-enabled 属性显式设置为 false,但开始遇到 NoClassDefFoundError 相关问题.我也尝试将此属性传递给 Task.launch 方法,但这并没有解决问题.

I tried adding Spring integration jars as suggested and explicitly set the spring.cloud.task.single-instance-enabled property to false but started running into NoClassDefFoundError related issues. I also tried passing this property to the Task.launch method but that did not solve the issue.

为什么同一个任务在使用 curl 命令时可以多次重新启动,而在使用 Java DSL 时不能多次重新启动?

Why can the same task be relaunched multiple times when using the curl command but cannot be relaunched multiple times when using the Java DSL?

推荐答案

在这种情况下,您似乎正在尝试重新创建任务定义.您应该只需要创建一次任务定义.根据这个定义,您可以多次启动.例如:

In this case it looks like you are trying to recreate the task definition. You should only need to create the task definition once. From this definition you can launch multiple times. For example:

URI dataFlowUri = URI.create(scdfUri);
DataFlowOperations dataFlowOperations = new DataFlowTemplate(dataFlowUri);
Task task = Task.builder(dataFlowOperations).name("Task1").definition("a:task1")
                .description("Task launched from DSL").build();         
long executionId = task.launch(new ArrayList<>());
executionId = task.launch(new ArrayList<>());
executionId = task.launch(new ArrayList<>());

这篇关于Spring Cloud Data Flow:无法启动同一任务的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆