簡體   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