【问题标题】:Spring Cloud Data Flow : Unable to launch multiple instances of the same TaskSpring Cloud Data Flow:无法启动同一任务的多个实例
【发布时间】:2021-05-12 15:32:24
【问题描述】:

TL;DR

Spring Cloud Data Flow 不允许多次执行同一个任务,即使 documentation 表示这是默认行为。我们如何允许 SCDF 使用 Java DSL 启动任务同时运行同一任务的多个实例?为了让事情变得更有趣,例如,在使用 curl 直接点击其余端点时,多次启动相同的任务可以正常工作。

背景:

我在Spring Cloud Data Flow UI Dashboard预注册了一个Spring Cloud Data Flow Task

@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
    }
    
}

我在其他一些主程序中使用Task Java DSL 启动这个任务:

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<>());

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

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

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

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

有趣的是,如果我使用 curl 命令(如 API guide 所示),我可以启动同一任务的多个实例

问题:

  1. 根据SCDF Task documentation,默认情况下可以重新运行任务。无需额外配置即可重新运行相同的任务;但是,看起来情况恰恰相反。 SCDF默认不允许任务重新运行?

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

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

【问题讨论】:

    标签: java spring-cloud-dataflow spring-cloud-task


    【解决方案1】:

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

    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<>());
    

    【讨论】:

    • 看来我误解了 API。这解决了问题。我现在面临的另一个问题是我无法以编程方式注册 Docker 映像。我尝试使用dataFlowOperations.appRegistryOperations().importFromResource(docker://&lt;docker-uri&gt;) API,但这不起作用。在我可以从我的 Java 代码启动任务之前,我不得不从 UI 仪表板预注册 docker 映像。
    猜你喜欢
    • 1970-01-01
    • 2018-02-06
    • 2019-06-28
    • 2017-11-03
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    相关资源
    最近更新 更多