繁体   English   中英

如何正确编译/打包 Spring 云数据流的任务

[英]How to properly compile/package a Task for Spring Cloud Data Flow

鉴于我需要使用多个数据源,我从 Spring Cloud Task Samples 在 IntelliJ Idea 2020.1.3 中编译了以下示例: https://github.com/mminella/spring-cloud-task/tree/master/spring-cloud -任务样本/多数据源

I then packaged it in a JAR using mvn package , copied it to the location where I launched docker-compose (as per official SCDF (Spring Cloud Data Flow) instructions for local deployment) and added it to SCDF running the following command inside the SCDF shell: app register --type task --name multiple-datasources --uri file://root/scdf/multiple-datasources-2.3.0-SNAPSHOT.jar

我使用 SCDF 添加了任务,如下所示:

在 SCDF 1/2 中创建多数据源任务

在 SCDF 2/2 中创建多数据源任务

当我尝试从仪表板运行任务时,执行实例没有提及任何开始时间或结束时间。 它也不会在仪表板中显示任何内容。

通过使用task execution log <instance>查阅来自 SCDF shell 的日志,显示了许多错误。 这似乎是最相关的部分:

2020-07-14 02:38:14.403  INFO 63 --- [           main] i.spring.MultipleDataSourcesApplication  : Starting MultipleDataSourcesApplication v2.3.0-SNAPSHOT on 5856acfa7c62 with PID 63 (/root/scdf/multiple-datasources-2.3.0-SNAPSHOT.jar started by root in /tmp/289541567048/multiple-datasources-9c75a131-4ea9-40ff-ac42-44729162e6f5)
2020-07-14 02:38:14.407  INFO 63 --- [           main] i.spring.MultipleDataSourcesApplication  : No active profile set, falling back to default profiles: default
2020-07-14 02:38:17.242  INFO 63 --- [           main] o.s.j.d.e.EmbeddedDatabaseFactory        : Starting embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
2020-07-14 02:38:18.145  INFO 63 --- [           main] o.s.j.d.e.EmbeddedDatabaseFactory        : Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa'
2020-07-14 02:38:18.810 DEBUG 63 --- [           main] o.s.c.t.c.SimpleTaskAutoConfiguration    : Using io.spring.configuration.CustomTaskConfigurer TaskConfigurer
2020-07-14 02:38:18.823 DEBUG 63 --- [           main] o.s.c.t.c.DefaultTaskConfigurer          : No EntityManager was found, using DataSourceTransactionManager
2020-07-14 02:38:18.928 DEBUG 63 --- [           main] o.s.c.t.r.s.TaskRepositoryInitializer    : Initializing task schema for h2 database
2020-07-14 02:38:19.036 ERROR 63 --- [           main] o.s.c.t.listener.TaskLifecycleListener   : An event to end a task has been received for a task that has not yet started.
2020-07-14 02:38:19.036  WARN 63 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 31 not found
2020-07-14 02:38:19.036  INFO 63 --- [           main] o.s.j.d.e.EmbeddedDatabaseFactory        : Shutting down embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false'
2020-07-14 02:38:19.245  INFO 63 --- [           main] o.s.j.d.e.EmbeddedDatabaseFactory        : Shutting down embedded database: url='jdbc:hsqldb:mem:testdb'
2020-07-14 02:38:19.258 ERROR 63 --- [           main] o.s.c.t.listener.TaskLifecycleListener   : An event to end a task has been received for a task that has not yet started.
2020-07-14 02:38:19.264  INFO 63 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-14 02:38:19.273 ERROR 63 --- [           main] o.s.boot.SpringApplication               : Application run failed

以下错误对我来说尤其突出:

2020-07-14 02:38:19.036  WARN 63 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 31 not found
2020-07-14 02:38:19.258 ERROR 63 --- [           main] o.s.c.t.listener.TaskLifecycleListener   : An event to end a task has been received for a task that has not yet started.
2020-07-14 02:38:19.264  INFO 63 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

该示例在application.properties中有以下几行:

spring.application.name=Demo Multiple DataSources Task
logging.level.org.springframework.cloud.task=DEBUG`

所以如果我没记错的话,应该已经启用了调试。

具体来说,我的问题是:

1)鉴于这是一个示例并且即使没有修改也无法运行,我可能会忽略或做错什么?

2)我该怎么做才能正确启用调试?

谢谢

PS:repo 中的示例已经具有 H2 数据库依赖项,如在其 pom.xml 中使用 Spring Cloud Data Flow 注册自定义 Spring Cloud Task中的答案。

我没有尝试使用当前的引导初始化程序重新创建示例,但是尝试使用最新的初始化程序创建一个简单的 hello-world,但我得到了完全相同的错误。 我不认为错误是initializr。

我还没有尝试最后一个建议,压倒一切。 但是鉴于这是一个官方示例,我真的需要覆盖默认配置吗?

PPS:我知道我的 SCDF 安装工作正常,因为我能够运行示例中的预打包时间戳程序: https://cloud.spring.io/spring-cloud-task-app-starters/

我遇到了同样的问题:每当我开始批处理作业时,TaskExecution 都会增加。

我查询了数据库中的任务执行表(我在批处理作业中使用),没有发现与该执行 ID 相关的任何内容。

我试图删除批处理作业并从 Docker 注册表重新导入应用程序,但任务执行仍然增加,没有希望!

我查看了 SCDF server-config.yaml 文件,该文件用于在 Kubernetes 上安装 SCDF,发现 SCDF 使用 Mysql 数据库来存储其奇怪的东西!!

https://github.com/spring-cloud/spring-cloud-Dataflow/blob/main/src/kubernetes/server/server-config.yaml

url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql

我查询了mysql系统数据库,发现里面有ID信息的任务执行表!

问题解决了,SCDF 本身将任务执行 ID 保存在自己的数据库中,而我们的批处理应用程序使用不同的数据库,因此它产生了问题。 我必须将批处理应用程序数据库临时更改为 SCDF 的数据库,即 mysql 系统数据库。

来自: app.batch.spring.datasource.url=jdbc:mysql://mysql:3306/task?useSSL=false

到: app.batch.spring.datasource.url=jdbc:mysql://mysql:3306/mysql?useSSL=false

结论:SCDF 需要自己的数据库来管理任务执行,并且您的批处理应用程序(除了批处理的数据库)应该指向该 SCDF 的数据库才能工作。 另外,在 Kubernetes 中安装 SCDF 的过程中,您应该将 SCDF 的数据库更改为其他位置,而不是 mysql 系统数据库

本教程向您展示如何使您的批处理应用程序同时使用 2 个数据源

https://github.com/spring-cloud/spring-cloud-task/tree/main/spring-cloud-task-samples/multiple-datasources

此链接将添加有关该问题的更多信息:

https://github.com/spring-io/dataflow.spring.io/issues/161

背景:

我按照此链接安装 SCDF 服务器(这让我发疯)

https://dataflow.spring.io/docs/installation/kubernetes/kubectl/#deploy-data-flow-server

这指向

https://github.com/spring-cloud/spring-cloud-dataflow/blob/main/src/kubernetes/server/server-config.yaml

而这个链接

https://dataflow.spring.io/docs/batch-developer-guides/batch/spring-batch/

使用 mysql url url=jdbc:mysql://localhost:3306/task?useSSL=false

我想,Spring 应该更新文档并添加更多关于 SCDF 任务执行过程的说明

这看起来与任务应用程序相关的问题没有使用与 Spring 云数据流相同的数据库。 你需要确定,

  • 任务的数据源配置与SCDF相同
  • 您的任务应用程序中的数据源 jdbc 依赖项的版本与您使用的 SCDF 版本兼容。

您可以在此处阅读一些相关文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM