From 05bae0b2260393587ce7104dc136a77bb3ff59a4 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Tue, 9 Nov 2021 18:59:34 +0800 Subject: [PATCH] Refactor alert plugins and simplify its usage (#6723) --- .github/CODEOWNERS | 1 + .../dolphinscheduler/alert.properties.tpl | 30 -- docker/build/startup-init-conf.sh | 1 - docker/docker-swarm/config.env.sh | 1 - .../kubernetes/dolphinscheduler/values.yaml | 3 +- .../alert/dingtalk/DingTalkAlertPlugin.java | 34 --- .../alert/email/EmailAlertChannelFactory.java | 140 --------- .../plugin/alert/email/EmailAlertPlugin.java | 33 --- .../alert/feishu/FeiShuAlertPlugin.java | 30 -- .../plugin/alert/http/HttpAlertPlugin.java | 34 --- .../alert/http/HttpAlertPluginTest.java | 38 --- .../alert/script/ScriptAlertPlugin.java | 35 --- .../plugin/alert/slack/SlackAlertPlugin.java | 34 --- .../alert/slack/SlackAlertPluginTest.java | 36 --- .../dolphinscheduler-alert-wechat/pom.xml | 79 ------ .../wechat/WeChatAlertChannelFactory.java | 94 ------ .../alert/wechat/WeChatAlertPlugin.java | 34 --- .../exception/WeChatAlertException.java | 30 -- .../dolphinscheduler-alert-api/pom.xml | 38 +++ .../alert/api/AlertChannel.java | 24 ++ .../alert/api/AlertChannelFactory.java | 35 +++ .../alert/api/AlertConstants.java | 33 +++ .../dolphinscheduler/alert/api/AlertData.java | 168 +++++++++++ .../dolphinscheduler/alert/api/AlertInfo.java | 125 ++++++++ .../alert/api/AlertResult.java | 123 ++++++++ .../dolphinscheduler/alert/api/ShowType.java | 49 ++++ .../dolphinscheduler-alert-dingtalk/pom.xml | 55 +--- .../alert/dingtalk/DingTalkAlertChannel.java | 14 +- .../dingtalk/DingTalkAlertChannelFactory.java | 72 ++--- .../dingtalk/DingTalkParamsConstants.java | 10 +- .../plugin/alert/dingtalk/DingTalkSender.java | 82 ++++-- .../DingTalkAlertChannelFactoryTest.java | 10 +- .../alert/dingtalk/DingTalkSenderTest.java | 9 +- .../dolphinscheduler-alert-email}/pom.xml | 58 +--- .../plugin/alert/email/EmailAlertChannel.java | 25 +- .../alert/email/EmailAlertChannelFactory.java | 139 +++++++++ .../plugin/alert/email/EmailConstants.java | 49 ++-- .../plugin/alert/email/ExcelUtils.java | 18 +- .../alert/email/MailParamsConstants.java | 14 +- .../plugin/alert/email/MailSender.java | 72 ++--- .../email/exception/AlertEmailException.java | 12 - .../alert/email/template/AlertTemplate.java | 11 +- .../email/template/DefaultHTMLTemplate.java | 7 +- .../email/EmailAlertChannelFactoryTest.java | 17 +- .../alert/email/EmailAlertChannelTest.java | 111 ++++---- .../plugin/alert/email/ExcelUtilsTest.java | 0 .../plugin/alert/email/MailUtilsTest.java | 33 +-- .../template/DefaultHTMLTemplateTest.java | 33 +-- .../dolphinscheduler-alert-feishu/pom.xml | 54 +--- .../alert/feishu/FeiShuAlertChannel.java | 11 +- .../feishu/FeiShuAlertChannelFactory.java | 67 ++--- .../alert/feishu/FeiShuParamsConstants.java | 16 +- .../plugin/alert/feishu/FeiShuSender.java | 91 ++++-- .../plugin/alert/feishu/HttpRequestUtil.java | 5 +- .../feishu/FeiShuAlertChannelFactoryTest.java | 4 +- .../plugin/alert/feishu/FeiShuSenderTest.java | 40 +-- .../dolphinscheduler-alert-http}/pom.xml | 56 +--- .../plugin/alert/http/HttpAlertChannel.java | 14 +- .../alert/http/HttpAlertChannelFactory.java | 58 ++-- .../plugin/alert/http/HttpAlertConstants.java | 9 +- .../plugin/alert/http/HttpSender.java | 43 +-- .../http/HttpAlertChannelFactoryTest.java | 7 +- .../alert/http/HttpAlertChannelTest.java | 41 ++- .../plugin/alert/http/HttpSenderTest.java | 6 +- .../dolphinscheduler-alert-script/pom.xml | 36 +++ .../plugin/alert/script/OSUtils.java | 8 +- .../plugin/alert/script/ProcessUtils.java | 13 +- .../alert/script/ScriptAlertChannel.java | 16 +- .../script/ScriptAlertChannelFactory.java | 48 ++-- .../alert/script/ScriptParamsConstants.java | 14 +- .../plugin/alert/script/ScriptSender.java | 25 +- .../plugin/alert/script/ScriptType.java | 13 +- .../plugin/alert/script/StreamGobbler.java | 17 +- .../plugin/alert/script/ProcessUtilsTest.java | 2 +- .../script/ScriptAlertChannelFactoryTest.java | 4 +- .../plugin/alert/script/ScriptSenderTest.java | 6 +- .../src/test/script/shell/scriptExample.sh | 0 .../src/test/script/shell/test.sh | 0 .../dolphinscheduler-alert-slack/pom.xml | 41 +++ .../plugin/alert/slack/SlackAlertChannel.java | 14 +- .../alert/slack/SlackAlertChannelFactory.java | 37 ++- .../alert/slack/SlackParamsConstants.java | 11 +- .../plugin/alert/slack/SlackSender.java | 25 +- .../slack/SlackAlertChannelFactoryTest.java | 8 +- .../plugin/alert/slack/SlackSenderTest.java | 4 +- .../dolphinscheduler-alert-wechat}/pom.xml | 38 +-- .../alert/wechat/WeChatAlertChannel.java | 14 +- .../wechat/WeChatAlertChannelFactory.java | 93 ++++++ .../alert/wechat/WeChatAlertConstants.java | 14 +- .../wechat/WeChatAlertParamsConstants.java | 30 +- .../plugin/alert/wechat/WeChatSender.java | 267 ++++++++++-------- .../wechat/WeChatAlertChannelFactoryTest.java | 4 +- .../plugin/alert/wechat/WeChatSenderTest.java | 46 +-- .../dolphinscheduler-alert-plugins}/pom.xml | 16 +- .../dolphinscheduler-alert-server}/pom.xml | 112 ++++---- .../alert/AlertPluginManager.java | 89 ++++++ .../alert}/AlertRequestProcessor.java | 39 ++- .../dolphinscheduler/alert}/AlertSender.java | 79 ++---- .../dolphinscheduler/alert/AlertServer.java | 125 ++++++++ .../src/main/resources/logback-alert.xml | 4 +- .../alert/plugin/EmailAlertPluginTest.java | 149 +++++----- .../processor/AlertRequestProcessorTest.java | 20 +- .../alert/runner/AlertSenderTest.java | 85 +++--- dolphinscheduler-alert/pom.xml | 127 +++------ .../dolphinscheduler/alert/AlertServer.java | 156 ---------- .../alert/plugin/AlertPluginManager.java | 115 -------- .../alert/utils/Constants.java | 38 --- .../src/main/resources/alert.properties | 30 -- .../alert/AlertServerTest.java | 91 ------ .../alert/plugin/AlertPluginManagerTest.java | 65 ----- .../alert/plugin/DolphinPluginLoaderTest.java | 55 ---- .../common/utils/PropertyUtils.java | 55 ---- .../apache/dolphinscheduler/dao/AlertDao.java | 6 +- .../dolphinscheduler/dao/DaoFactory.java | 2 +- .../dolphinscheduler/dao/PluginDao.java | 8 +- .../dolphinscheduler/dao/AlertDaoTest.java | 4 +- dolphinscheduler-dist/pom.xml | 2 +- dolphinscheduler-dist/release-docs/LICENSE | 4 +- .../src/main/provisio/dolphinscheduler.xml | 31 -- .../dolphinscheduler/registry/api/Event.java | 107 ++++++- .../ZookeeperConnectionStateListener.java | 11 +- dolphinscheduler-registry/pom.xml | 6 - .../main/resources/config/install_config.conf | 6 - dolphinscheduler-spi/pom.xml | 2 +- .../spi/DolphinSchedulerPlugin.java | 10 - .../spi/alert/AlertChannel.java | 28 -- .../spi/alert/AlertChannelFactory.java | 33 --- .../spi/alert/AlertConstants.java | 26 -- .../dolphinscheduler/spi/alert/AlertData.java | 77 ----- .../dolphinscheduler/spi/alert/AlertInfo.java | 52 ---- .../spi/alert/AlertResult.java | 49 ---- .../dolphinscheduler/spi/alert/ShowType.java | 51 ---- .../plugin/DolphinPluginManagerConfig.java | 5 - .../spi/task/AbstractParameters.java | 6 +- .../dolphinscheduler/spi/utils/JSONUtils.java | 72 ----- dolphinscheduler-standalone-server/pom.xml | 2 +- .../server/StandaloneServer.java | 15 +- install.sh | 3 - pom.xml | 62 +++- tools/dependencies/known-dependencies.txt | 4 +- 140 files changed, 2338 insertions(+), 3299 deletions(-) delete mode 100644 docker/build/conf/dolphinscheduler/alert.properties.tpl delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPluginTest.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/exception/WeChatAlertException.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/pom.xml create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannelFactory.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertConstants.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/pom.xml (51%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java (80%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java (58%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java (92%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java (72%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java (91%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java (90%) rename {dolphinscheduler-alert-plugin/dolphinscheduler-alert-script => dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email}/pom.xml (51%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java (71%) create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java (52%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java (92%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java (92%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java (89%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java (83%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java (86%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java (95%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java (82%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java (57%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtilsTest.java (100%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java (88%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java (71%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/pom.xml (51%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java (81%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java (52%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java (91%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java (66%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java (92%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java (92%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java (74%) rename {dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack => dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http}/pom.xml (53%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java (78%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java (52%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java (91%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java (90%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java (93%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java (70%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java (95%) create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/pom.xml rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java (88%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java (84%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java (77%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java (52%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java (89%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java (86%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java (94%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java (81%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java (93%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java (91%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java (97%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh (100%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-script/src/test/script/shell/test.sh (100%) create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/pom.xml rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java (82%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java (61%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java (90%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java (88%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java (87%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java (95%) rename {dolphinscheduler-alert-plugin/dolphinscheduler-alert-http => dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat}/pom.xml (64%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java (80%) create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java (89%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java (90%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java (79%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java (92%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java (77%) rename {dolphinscheduler-alert-plugin => dolphinscheduler-alert/dolphinscheduler-alert-plugins}/pom.xml (80%) rename {dolphinscheduler-alert-plugin/dolphinscheduler-alert-email => dolphinscheduler-alert/dolphinscheduler-alert-server}/pom.xml (51%) create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java rename dolphinscheduler-alert/{src/main/java/org/apache/dolphinscheduler/alert/processor => dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert}/AlertRequestProcessor.java (56%) rename dolphinscheduler-alert/{src/main/java/org/apache/dolphinscheduler/alert/runner => dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert}/AlertSender.java (70%) create mode 100644 dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java rename dolphinscheduler-alert/{ => dolphinscheduler-alert-server}/src/main/resources/logback-alert.xml (95%) rename dolphinscheduler-alert/{ => dolphinscheduler-alert-server}/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java (63%) rename dolphinscheduler-alert/{ => dolphinscheduler-alert-server}/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java (77%) rename dolphinscheduler-alert/{ => dolphinscheduler-alert-server}/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java (60%) delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/Constants.java delete mode 100644 dolphinscheduler-alert/src/main/resources/alert.properties delete mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java delete mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManagerTest.java delete mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/DolphinPluginLoaderTest.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannel.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannelFactory.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertConstants.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertData.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertResult.java delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/ShowType.java diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9def4bee11..ec6c33caee 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -15,6 +15,7 @@ # limitations under the License. # +dolphinscheduler/dolphinscheduler-alert @kezhenxu94 dolphinscheduler/dolphinscheduler-e2e @kezhenxu94 dolphinscheduler/dolphinscheduler-registry @kezhenxu94 dolphinscheduler/dolphinscheduler-standalone-server @kezhenxu94 diff --git a/docker/build/conf/dolphinscheduler/alert.properties.tpl b/docker/build/conf/dolphinscheduler/alert.properties.tpl deleted file mode 100644 index 1ff6fe7adb..0000000000 --- a/docker/build/conf/dolphinscheduler/alert.properties.tpl +++ /dev/null @@ -1,30 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -#This configuration file configures the configuration parameters related to the AlertServer. -#These parameters are only related to the AlertServer, and it has nothing to do with the specific Alert Plugin. -#eg : max retry num. -#eg : Alert Server Listener port - -#alert.plugin.dir config the Alert Plugin dir . AlertServer while find and load the Alert Plugin Jar from this dir when deploy and start AlertServer on the server . -alert.plugin.dir=${ALERT_PLUGIN_DIR} - -#maven.local.repository=/Users/gaojun/Documents/jianguoyun/localRepository - -#alert.plugin.binding config the Alert Plugin need be load when development and run in IDE -#alert.plugin.binding=\ -# ./dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml diff --git a/docker/build/startup-init-conf.sh b/docker/build/startup-init-conf.sh index 47178341c0..23f5cfffac 100755 --- a/docker/build/startup-init-conf.sh +++ b/docker/build/startup-init-conf.sh @@ -107,7 +107,6 @@ export ALERT_LISTEN_HOST=${ALERT_LISTEN_HOST:-"localhost"} # Alert Server #============================================================================ export ALERT_SERVER_OPTS=${ALERT_SERVER_OPTS:-"-Xms512m -Xmx512m -Xmn256m"} -export ALERT_PLUGIN_DIR=${ALERT_PLUGIN_DIR:-"lib/plugin/alert"} #============================================================================ # Api Server diff --git a/docker/docker-swarm/config.env.sh b/docker/docker-swarm/config.env.sh index 0c79a045a2..4127102e35 100755 --- a/docker/docker-swarm/config.env.sh +++ b/docker/docker-swarm/config.env.sh @@ -109,7 +109,6 @@ ALERT_LISTEN_HOST=dolphinscheduler-alert # Alert Server #============================================================================ ALERT_SERVER_OPTS=-Xms512m -Xmx512m -Xmn256m -ALERT_PLUGIN_DIR=lib/plugin/alert #============================================================================ # Api Server diff --git a/docker/kubernetes/dolphinscheduler/values.yaml b/docker/kubernetes/dolphinscheduler/values.yaml index ef28b8edfb..8431060d20 100644 --- a/docker/kubernetes/dolphinscheduler/values.yaml +++ b/docker/kubernetes/dolphinscheduler/values.yaml @@ -299,7 +299,6 @@ alert: ## Configmap configmap: ALERT_SERVER_OPTS: "-Xms512m -Xmx512m -Xmn256m" - ALERT_PLUGIN_DIR: "lib/plugin/alert" ## Periodic probe of container liveness. Container will be restarted if the probe fails. Cannot be updated. ## More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes livenessProbe: @@ -411,4 +410,4 @@ ingress: path: "/dolphinscheduler" tls: enabled: false - secretName: "dolphinscheduler-tls" \ No newline at end of file + secretName: "dolphinscheduler-tls" diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertPlugin.java deleted file mode 100644 index 2d15f499c9..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertPlugin.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.dingtalk; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -/** - * DingTalkAlertPlugin - */ -public class DingTalkAlertPlugin implements DolphinSchedulerPlugin { - - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new DingTalkAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java deleted file mode 100644 index 54865f5cd2..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.email; - -import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_FALSE; -import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO; -import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE; -import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES; - -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.ShowType; -import org.apache.dolphinscheduler.spi.params.input.InputParam; -import org.apache.dolphinscheduler.spi.params.PasswordParam; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; -import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; -import org.apache.dolphinscheduler.spi.params.base.Validate; - -import java.util.ArrayList; -import java.util.List; - -/** - * email alert factory - */ -public class EmailAlertChannelFactory implements AlertChannelFactory { - @Override - public String getName() { - return "Email"; - } - - @Override - public List getParams() { - - List paramsList = new ArrayList<>(); - InputParam receivesParam = InputParam.newBuilder(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS, MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERS) - .setPlaceholder("please input receives") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam receiveCcsParam = InputParam.newBuilder(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERCCS, MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERCCS) - .build(); - - InputParam mailSmtpHost = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_HOST, MailParamsConstants.MAIL_SMTP_HOST) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - InputParam mailSmtpPort = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_PORT, MailParamsConstants.MAIL_SMTP_PORT) - .setValue("25") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam mailSender = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SENDER, MailParamsConstants.MAIL_SENDER) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - RadioParam enableSmtpAuth = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_AUTH, MailParamsConstants.MAIL_SMTP_AUTH) - .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) - .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) - .setValue(STRING_TRUE) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - InputParam mailUser = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_USER, MailParamsConstants.MAIL_USER) - .setPlaceholder("if enable use authentication, you need input user") - .build(); - - PasswordParam mailPassword = PasswordParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, MailParamsConstants.MAIL_PASSWD) - .setPlaceholder("if enable use authentication, you need input password") - .build(); - - RadioParam enableTls = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_STARTTLS_ENABLE, MailParamsConstants.MAIL_SMTP_STARTTLS_ENABLE) - .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) - .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) - .setValue(STRING_FALSE) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - RadioParam enableSsl = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_ENABLE, MailParamsConstants.MAIL_SMTP_SSL_ENABLE) - .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) - .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) - .setValue(STRING_FALSE) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - InputParam sslTrust = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_TRUST, MailParamsConstants.MAIL_SMTP_SSL_TRUST) - .setValue("*") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, AlertConstants.SHOW_TYPE) - .addParamsOptions(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false)) - .addParamsOptions(new ParamsOptions(ShowType.TEXT.getDescp(), ShowType.TEXT.getDescp(), false)) - .addParamsOptions(new ParamsOptions(ShowType.ATTACHMENT.getDescp(), ShowType.ATTACHMENT.getDescp(), false)) - .addParamsOptions(new ParamsOptions(ShowType.TABLEATTACHMENT.getDescp(), ShowType.TABLEATTACHMENT.getDescp(), false)) - .setValue(ShowType.TABLE.getDescp()) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - paramsList.add(receivesParam); - paramsList.add(receiveCcsParam); - paramsList.add(mailSmtpHost); - paramsList.add(mailSmtpPort); - paramsList.add(mailSender); - paramsList.add(enableSmtpAuth); - paramsList.add(mailUser); - paramsList.add(mailPassword); - paramsList.add(enableTls); - paramsList.add(enableSsl); - paramsList.add(sslTrust); - paramsList.add(showType); - - return paramsList; - } - - @Override - public AlertChannel create() { - return new EmailAlertChannel(); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertPlugin.java deleted file mode 100644 index 175b518189..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertPlugin.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.email; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -/** - * email alert plugin - */ -public class EmailAlertPlugin implements DolphinSchedulerPlugin { - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new EmailAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertPlugin.java deleted file mode 100644 index e71be3e2bd..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertPlugin.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.feishu; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -public class FeiShuAlertPlugin implements DolphinSchedulerPlugin { - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new FeiShuAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java deleted file mode 100644 index 973f1617a6..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.http; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -/** - * http alertPlugins - */ -public class HttpAlertPlugin implements DolphinSchedulerPlugin { - - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new HttpAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPluginTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPluginTest.java deleted file mode 100644 index 7dac686e88..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPluginTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.http; - -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import org.junit.Assert; -import org.junit.Test; - -/** - * HttpAlertPlugin UT - */ -public class HttpAlertPluginTest { - - @Test - public void getAlertChannelFactorysTest() { - - HttpAlertPlugin httpAlertPlugin = new HttpAlertPlugin(); - Iterable alertChannelFactorys = httpAlertPlugin.getAlertChannelFactorys(); - Assert.assertNotNull(alertChannelFactorys); - - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java deleted file mode 100644 index f2ba0e87d0..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.script; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -/** - * ScriptAlertPlugin - */ -public class ScriptAlertPlugin implements DolphinSchedulerPlugin { - - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new ScriptAlertChannelFactory()); - } - -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java deleted file mode 100644 index 59c45ae4ac..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPlugin.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.slack; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -/** - * Slack alert plugin - */ -public class SlackAlertPlugin implements DolphinSchedulerPlugin { - - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new SlackAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java deleted file mode 100644 index 5086352a46..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertPluginTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.slack; - -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import org.junit.Assert; -import org.junit.Test; - -public class SlackAlertPluginTest { - - private SlackAlertPlugin slackAlertPlugin = new SlackAlertPlugin(); - - @Test - public void testGetAlertChannelFactorys() { - Iterable alertChannelFactorys = slackAlertPlugin.getAlertChannelFactorys(); - for (AlertChannelFactory alertChannelFactory : alertChannelFactorys) { - Assert.assertTrue(alertChannelFactory instanceof SlackAlertChannelFactory); - } - } -} \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml deleted file mode 100644 index 2b0d3b666e..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - dolphinscheduler-alert-plugin - org.apache.dolphinscheduler - 2.0.0-SNAPSHOT - - 4.0.0 - - org.apache.dolphinscheduler - dolphinscheduler-alert-wechat - dolphinscheduler-plugin - - - - com.google.guava - guava - - - - ch.qos.logback - logback-classic - - - - org.apache.httpcomponents - httpclient - - - - com.fasterxml.jackson.core - jackson-databind - provided - - - - junit - junit - test - - - - org.mockito - mockito-core - jar - test - - - - org.jacoco - org.jacoco.agent - runtime - test - - - - - - dolphinscheduler-alert-wechat-${project.version} - - \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java deleted file mode 100644 index a5f7aa1af9..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.wechat; - -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.ShowType; -import org.apache.dolphinscheduler.spi.params.input.InputParam; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; -import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; -import org.apache.dolphinscheduler.spi.params.base.Validate; - -import java.util.Arrays; -import java.util.List; - -/** - * WeChatAlertChannelFactory - */ -public class WeChatAlertChannelFactory implements AlertChannelFactory { - - @Override - public String getName() { - return "WeChat"; - } - - @Override - public List getParams() { - InputParam corpIdParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_CORP_ID, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_CORP_ID) - .setPlaceholder("please input corp id ") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam secretParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_SECRET) - .setPlaceholder("please input secret ") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam usersParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USERS, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_USERS) - .setPlaceholder("please input users ") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam userSendMsgParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_USER_SEND_MSG) - .setPlaceholder("please input corp id ") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam agentIdParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_AGENT_ID, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_AGENT_ID) - .setPlaceholder("please input agent id ") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, AlertConstants.SHOW_TYPE) - .addParamsOptions(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false)) - .addParamsOptions(new ParamsOptions(ShowType.TEXT.getDescp(), ShowType.TEXT.getDescp(), false)) - .setValue(ShowType.TABLE.getDescp()) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); - - return Arrays.asList(corpIdParam, secretParam, usersParam, userSendMsgParam, agentIdParam, showType); - } - - @Override - public AlertChannel create() { - return new WeChatAlertChannel(); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertPlugin.java deleted file mode 100644 index 56c3c01f20..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertPlugin.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.wechat; - -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -import com.google.common.collect.ImmutableList; - -/** - * WeChatAlertPlugin - */ -public class WeChatAlertPlugin implements DolphinSchedulerPlugin { - - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new WeChatAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/exception/WeChatAlertException.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/exception/WeChatAlertException.java deleted file mode 100644 index f36bc2ff8a..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/exception/WeChatAlertException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.alert.wechat.exception; - -public class WeChatAlertException extends RuntimeException { - - /** - * Create Runtime Exception - * - * @param errMsg - Error message - */ - public WeChatAlertException(String errMsg) { - super(errMsg); - } -} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-api/pom.xml new file mode 100644 index 0000000000..e89435ae3c --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/pom.xml @@ -0,0 +1,38 @@ + + + + + + dolphinscheduler-alert + org.apache.dolphinscheduler + 2.0.0-SNAPSHOT + + 4.0.0 + dolphinscheduler-alert-api + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + + + diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java new file mode 100644 index 0000000000..fceff92d49 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java @@ -0,0 +1,24 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +public interface AlertChannel { + AlertResult process(AlertInfo info); +} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannelFactory.java new file mode 100644 index 0000000000..a55c7ffa4d --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannelFactory.java @@ -0,0 +1,35 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +import org.apache.dolphinscheduler.spi.params.base.PluginParams; + +import java.util.List; + +public interface AlertChannelFactory { + String name(); + + AlertChannel create(); + + /** + * Returns the configurable parameters that this plugin needs to display on the web ui + */ + List params(); +} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertConstants.java new file mode 100644 index 0000000000..9d85fd24bf --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertConstants.java @@ -0,0 +1,33 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +public final class AlertConstants { + /** + * the field name of alert show type + **/ + public static final String SHOW_TYPE = "$t('showType')"; + + public static final String NAME_SHOW_TYPE = "showType"; + + private AlertConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } +} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java new file mode 100644 index 0000000000..9d1db84779 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java @@ -0,0 +1,168 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +public class AlertData { + private int id; + private String title; + private String content; + private String log; + + public AlertData(int id, String title, String content, String log) { + this.id = id; + this.title = title; + this.content = content; + this.log = log; + } + + public AlertData() { + } + + public static AlertDataBuilder builder() { + return new AlertDataBuilder(); + } + + public int getId() { + return this.id; + } + + public AlertData setId(int id) { + this.id = id; + return this; + } + + public String getTitle() { + return this.title; + } + + public AlertData setTitle(String title) { + this.title = title; + return this; + } + + public String getContent() { + return this.content; + } + + public AlertData setContent(String content) { + this.content = content; + return this; + } + + public String getLog() { + return this.log; + } + + public AlertData setLog(String log) { + this.log = log; + return this; + } + + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof AlertData)) { + return false; + } + final AlertData other = (AlertData) o; + if (!other.canEqual((Object) this)) { + return false; + } + if (this.getId() != other.getId()) { + return false; + } + final Object this$title = this.getTitle(); + final Object other$title = other.getTitle(); + if (this$title == null ? other$title != null : !this$title.equals(other$title)) { + return false; + } + final Object this$content = this.getContent(); + final Object other$content = other.getContent(); + if (this$content == null ? other$content != null : !this$content.equals(other$content)) { + return false; + } + final Object this$log = this.getLog(); + final Object other$log = other.getLog(); + if (this$log == null ? other$log != null : !this$log.equals(other$log)) { + return false; + } + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof AlertData; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.getId(); + final Object $title = this.getTitle(); + result = result * PRIME + ($title == null ? 43 : $title.hashCode()); + final Object $content = this.getContent(); + result = result * PRIME + ($content == null ? 43 : $content.hashCode()); + final Object $log = this.getLog(); + result = result * PRIME + ($log == null ? 43 : $log.hashCode()); + return result; + } + + public String toString() { + return "AlertData(id=" + this.getId() + ", title=" + this.getTitle() + ", content=" + this.getContent() + ", log=" + this.getLog() + ")"; + } + + public static class AlertDataBuilder { + private int id; + private String title; + private String content; + private String log; + + AlertDataBuilder() { + } + + public AlertDataBuilder id(int id) { + this.id = id; + return this; + } + + public AlertDataBuilder title(String title) { + this.title = title; + return this; + } + + public AlertDataBuilder content(String content) { + this.content = content; + return this; + } + + public AlertDataBuilder log(String log) { + this.log = log; + return this; + } + + public AlertData build() { + return new AlertData(id, title, content, log); + } + + public String toString() { + return "AlertData.AlertDataBuilder(id=" + this.id + ", title=" + this.title + ", content=" + this.content + ", log=" + this.log + ")"; + } + } +} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java new file mode 100644 index 0000000000..6dbc8205e6 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java @@ -0,0 +1,125 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +import java.util.Map; + +public class AlertInfo { + private Map alertParams; + private AlertData alertData; + + public AlertInfo(Map alertParams, AlertData alertData) { + this.alertParams = alertParams; + this.alertData = alertData; + } + + public AlertInfo() { + } + + public static AlertInfoBuilder builder() { + return new AlertInfoBuilder(); + } + + public Map getAlertParams() { + return this.alertParams; + } + + public AlertInfo setAlertParams(Map alertParams) { + this.alertParams = alertParams; + return this; + } + + public AlertData getAlertData() { + return this.alertData; + } + + public AlertInfo setAlertData(AlertData alertData) { + this.alertData = alertData; + return this; + } + + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof AlertInfo)) { + return false; + } + final AlertInfo other = (AlertInfo) o; + if (!other.canEqual((Object) this)) { + return false; + } + final Object this$alertParams = this.getAlertParams(); + final Object other$alertParams = other.getAlertParams(); + if (this$alertParams == null ? other$alertParams != null : !this$alertParams.equals(other$alertParams)) { + return false; + } + final Object this$alertData = this.getAlertData(); + final Object other$alertData = other.getAlertData(); + if (this$alertData == null ? other$alertData != null : !this$alertData.equals(other$alertData)) { + return false; + } + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof AlertInfo; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $alertParams = this.getAlertParams(); + result = result * PRIME + ($alertParams == null ? 43 : $alertParams.hashCode()); + final Object $alertData = this.getAlertData(); + result = result * PRIME + ($alertData == null ? 43 : $alertData.hashCode()); + return result; + } + + public String toString() { + return "AlertInfo(alertParams=" + this.getAlertParams() + ", alertData=" + this.getAlertData() + ")"; + } + + public static class AlertInfoBuilder { + private Map alertParams; + private AlertData alertData; + + AlertInfoBuilder() { + } + + public AlertInfoBuilder alertParams(Map alertParams) { + this.alertParams = alertParams; + return this; + } + + public AlertInfoBuilder alertData(AlertData alertData) { + this.alertData = alertData; + return this; + } + + public AlertInfo build() { + return new AlertInfo(alertParams, alertData); + } + + public String toString() { + return "AlertInfo.AlertInfoBuilder(alertParams=" + this.alertParams + ", alertData=" + this.alertData + ")"; + } + } +} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java new file mode 100644 index 0000000000..4343c13408 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java @@ -0,0 +1,123 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +public class AlertResult { + private String status; + private String message; + + public AlertResult(String status, String message) { + this.status = status; + this.message = message; + } + + public AlertResult() { + } + + public static AlertResultBuilder builder() { + return new AlertResultBuilder(); + } + + public String getStatus() { + return this.status; + } + + public AlertResult setStatus(String status) { + this.status = status; + return this; + } + + public String getMessage() { + return this.message; + } + + public AlertResult setMessage(String message) { + this.message = message; + return this; + } + + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof AlertResult)) { + return false; + } + final AlertResult other = (AlertResult) o; + if (!other.canEqual((Object) this)) { + return false; + } + final Object this$status = this.getStatus(); + final Object other$status = other.getStatus(); + if (this$status == null ? other$status != null : !this$status.equals(other$status)) { + return false; + } + final Object this$message = this.getMessage(); + final Object other$message = other.getMessage(); + if (this$message == null ? other$message != null : !this$message.equals(other$message)) { + return false; + } + return true; + } + + protected boolean canEqual(final Object other) { + return other instanceof AlertResult; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $status = this.getStatus(); + result = result * PRIME + ($status == null ? 43 : $status.hashCode()); + final Object $message = this.getMessage(); + result = result * PRIME + ($message == null ? 43 : $message.hashCode()); + return result; + } + + public String toString() { + return "AlertResult(status=" + this.getStatus() + ", message=" + this.getMessage() + ")"; + } + + public static class AlertResultBuilder { + private String status; + private String message; + + AlertResultBuilder() { + } + + public AlertResultBuilder status(String status) { + this.status = status; + return this; + } + + public AlertResultBuilder message(String message) { + this.message = message; + return this; + } + + public AlertResult build() { + return new AlertResult(status, message); + } + + public String toString() { + return "AlertResult.AlertResultBuilder(status=" + this.status + ", message=" + this.message + ")"; + } + } +} diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java new file mode 100644 index 0000000000..48f9877528 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java @@ -0,0 +1,49 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.alert.api; + +public enum ShowType { + /** + * 0 TABLE; + * 1 TEXT; + * 2 attachment; + * 3 TABLE+attachment; + */ + TABLE(0, "table"), + TEXT(1, "text"), + ATTACHMENT(2, "attachment"), + TABLEATTACHMENT(3, "table attachment"); + + private final int code; + private final String descp; + + ShowType(int code, String descp) { + this.code = code; + this.descp = descp; + } + + public int getCode() { + return code; + } + + public String getDescp() { + return descp; + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/pom.xml similarity index 51% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/pom.xml index 646d5feb75..523402c2c9 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/pom.xml @@ -15,70 +15,27 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - dolphinscheduler-alert-plugin + dolphinscheduler-alert-plugins org.apache.dolphinscheduler 2.0.0-SNAPSHOT 4.0.0 - - org.apache.dolphinscheduler dolphinscheduler-alert-dingtalk - dolphinscheduler-plugin + jar - org.apache.httpcomponents httpclient + com.google.guava guava - - - ch.qos.logback - logback-classic - - - - org.slf4j - slf4j-api - - - - com.fasterxml.jackson.core - jackson-annotations - provided - - - - junit - junit - test - - - - org.mockito - mockito-core - jar - test - - - - org.jacoco - org.jacoco.agent - runtime - test - - - - dolphinscheduler-alert-dingtalk-${project.version} - - - \ No newline at end of file + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java similarity index 80% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java index 6b13f24d86..74c440fe76 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java @@ -17,21 +17,17 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; -/** - * DingTalkAlertChannel - */ -public class DingTalkAlertChannel implements AlertChannel { +public final class DingTalkAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo alertInfo) { - AlertData alertData = alertInfo.getAlertData(); Map paramsMap = alertInfo.getAlertParams(); if (null == paramsMap) { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java similarity index 58% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java index 38eb8d134f..27d95e7c67 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java @@ -22,67 +22,67 @@ import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO; import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE; import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.spi.params.PasswordParam; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import java.util.Arrays; import java.util.List; -/** - * DingTalkAlertChannelFactory - */ -public class DingTalkAlertChannelFactory implements AlertChannelFactory { +import com.google.auto.service.AutoService; + +@AutoService(AlertChannelFactory.class) +public final class DingTalkAlertChannelFactory implements AlertChannelFactory { @Override - public String getName() { + public String name() { return "DingTalk"; } @Override - public List getParams() { + public List params() { InputParam webHookParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_WEB_HOOK, DingTalkParamsConstants.DING_TALK_WEB_HOOK) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); InputParam keywordParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_KEYWORD, DingTalkParamsConstants.DING_TALK_KEYWORD) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); RadioParam isEnableProxy = RadioParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, DingTalkParamsConstants.DING_TALK_PROXY_ENABLE) - .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) - .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) - .setValue(STRING_TRUE) - .addValidate(Validate.newBuilder() - .setRequired(false) - .build()) - .build(); + .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) + .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) + .setValue(STRING_TRUE) + .addValidate(Validate.newBuilder() + .setRequired(false) + .build()) + .build(); InputParam proxyParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PROXY, DingTalkParamsConstants.DING_TALK_PROXY) - .addValidate(Validate.newBuilder() - .setRequired(false).build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(false).build()) + .build(); InputParam portParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PORT, DingTalkParamsConstants.DING_TALK_PORT) - .addValidate(Validate.newBuilder() - .setRequired(false).build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(false).build()) + .build(); InputParam userParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_USER, DingTalkParamsConstants.DING_TALK_USER) - .addValidate(Validate.newBuilder() - .setRequired(false).build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(false).build()) + .build(); PasswordParam passwordParam = PasswordParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD, DingTalkParamsConstants.DING_TALK_PASSWORD) - .setPlaceholder("if enable use authentication, you need input password") - .build(); + .setPlaceholder("if enable use authentication, you need input password") + .build(); return Arrays.asList(webHookParam, keywordParam, isEnableProxy, proxyParam, portParam, userParam, passwordParam); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java similarity index 92% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java index 5f8688abc7..ec0003a94f 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java @@ -17,12 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk; -/** - * DingTalkParamsConstants - */ -public class DingTalkParamsConstants { - - +public final class DingTalkParamsConstants { static final String DING_TALK_PROXY_ENABLE = "$t('isEnableProxy')"; static final String NAME_DING_TALK_PROXY_ENABLE = "IsEnableProxy"; @@ -45,7 +40,6 @@ public class DingTalkParamsConstants { static final String NAME_DING_TALK_PASSWORD = "Password"; private DingTalkParamsConstants() { - throw new IllegalStateException("Utility class"); + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } - } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java similarity index 72% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java index 0d87e4779a..a97fb006eb 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.commons.codec.binary.StringUtils; @@ -36,23 +36,17 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * Ding Talk Sender - */ -public class DingTalkSender { - private static final Logger logger = LoggerFactory.getLogger(DingTalkSender.class); - - private String url; - - private String keyword; - - private Boolean enableProxy; +public final class DingTalkSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(DingTalkSender.class); + private final String url; + private final String keyword; + private final Boolean enableProxy; private String proxy; @@ -72,12 +66,11 @@ public class DingTalkSender { user = config.get(DingTalkParamsConstants.DING_TALK_USER); password = config.get(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD); } - } - private static HttpPost constructHttpPost(String url, String msg, String charset) { + private static HttpPost constructHttpPost(String url, String msg) { HttpPost post = new HttpPost(url); - StringEntity entity = new StringEntity(msg, charset); + StringEntity entity = new StringEntity(msg, StandardCharsets.UTF_8); post.setEntity(entity); post.addHeader("Content-Type", "application/json; charset=utf-8"); return post; @@ -116,13 +109,13 @@ public class DingTalkSender { if (null == result) { alertResult.setMessage("send ding talk msg error"); - logger.info("send ding talk msg error,ding talk server resp is null"); + log.info("send ding talk msg error,ding talk server resp is null"); return alertResult; } DingTalkSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, DingTalkSendMsgResponse.class); if (null == sendMsgResponse) { alertResult.setMessage("send ding talk msg fail"); - logger.info("send ding talk msg error,resp error"); + log.info("send ding talk msg error,resp error"); return alertResult; } if (sendMsgResponse.errcode == 0) { @@ -131,7 +124,7 @@ public class DingTalkSender { return alertResult; } alertResult.setMessage(String.format("alert send ding talk msg error : %s", sendMsgResponse.getErrmsg())); - logger.info("alert send ding talk msg error : {}", sendMsgResponse.getErrmsg()); + log.info("alert send ding talk msg error : {}", sendMsgResponse.getErrmsg()); return alertResult; } @@ -141,7 +134,7 @@ public class DingTalkSender { String resp = sendMsg(title, content); return checkSendDingTalkSendMsgResult(resp); } catch (Exception e) { - logger.info("send ding talk alert msg exception : {}", e.getMessage()); + log.info("send ding talk alert msg exception : {}", e.getMessage()); alertResult = new AlertResult(); alertResult.setStatus("false"); alertResult.setMessage("send ding talk alert fail."); @@ -152,7 +145,7 @@ public class DingTalkSender { private String sendMsg(String title, String content) throws IOException { String msgToJson = textToJsonString(title + content + "#" + keyword); - HttpPost httpPost = constructHttpPost(url, msgToJson, "UTF-8"); + HttpPost httpPost = constructHttpPost(url, msgToJson); CloseableHttpClient httpClient; if (Boolean.TRUE.equals(enableProxy)) { @@ -173,19 +166,22 @@ public class DingTalkSender { } finally { response.close(); } - logger.info("Ding Talk send title :{},content : {}, resp: {}", title, content, resp); + log.info("Ding Talk send title :{},content : {}, resp: {}", title, content, resp); return resp; } finally { httpClient.close(); } } - public static class DingTalkSendMsgResponse { + static final class DingTalkSendMsgResponse { private Integer errcode; private String errmsg; + public DingTalkSendMsgResponse() { + } + public Integer getErrcode() { - return errcode; + return this.errcode; } public void setErrcode(Integer errcode) { @@ -193,12 +189,46 @@ public class DingTalkSender { } public String getErrmsg() { - return errmsg; + return this.errmsg; } public void setErrmsg(String errmsg) { this.errmsg = errmsg; } - } + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof DingTalkSendMsgResponse)) { + return false; + } + final DingTalkSendMsgResponse other = (DingTalkSendMsgResponse) o; + final Object this$errcode = this.getErrcode(); + final Object other$errcode = other.getErrcode(); + if (this$errcode == null ? other$errcode != null : !this$errcode.equals(other$errcode)) { + return false; + } + final Object this$errmsg = this.getErrmsg(); + final Object other$errmsg = other.getErrmsg(); + if (this$errmsg == null ? other$errmsg != null : !this$errmsg.equals(other$errmsg)) { + return false; + } + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $errcode = this.getErrcode(); + result = result * PRIME + ($errcode == null ? 43 : $errcode.hashCode()); + final Object $errmsg = this.getErrmsg(); + result = result * PRIME + ($errmsg == null ? 43 : $errmsg.hashCode()); + return result; + } + + public String toString() { + return "DingTalkSender.DingTalkSendMsgResponse(errcode=" + this.getErrcode() + ", errmsg=" + this.getErrmsg() + ")"; + } + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java similarity index 91% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java index 7c25f1ebf0..8b780427fc 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java @@ -17,26 +17,20 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.List; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; -/** - * DingTalkAlertChannelFactoryTest - */ -@Ignore public class DingTalkAlertChannelFactoryTest { - @Test public void testGetParams() { DingTalkAlertChannelFactory dingTalkAlertChannelFactory = new DingTalkAlertChannelFactory(); - List params = dingTalkAlertChannelFactory.getParams(); + List params = dingTalkAlertChannelFactory.params(); JSONUtils.toJsonString(params); Assert.assertEquals(7, params.size()); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java similarity index 90% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java index bc17d4185b..d2267a4919 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.HashMap; import java.util.Map; @@ -26,12 +26,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -/** - * DingTalkSenderTest - */ public class DingTalkSenderTest { - private static Map dingTalkConfig = new HashMap<>(); + private static final Map dingTalkConfig = new HashMap<>(); @Before public void initDingTalkConfig() { @@ -51,7 +48,7 @@ public class DingTalkSenderTest { dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, "true"); dingTalkSender = new DingTalkSender(dingTalkConfig); AlertResult alertResult = dingTalkSender.sendDingTalkMsg("title", "content test"); - Assert.assertEquals("false",alertResult.getStatus()); + Assert.assertEquals("false", alertResult.getStatus()); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/pom.xml similarity index 51% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/pom.xml index 0ab74785ef..85cb3b4383 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/pom.xml @@ -15,66 +15,36 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - dolphinscheduler-alert-plugin + dolphinscheduler-alert-plugins org.apache.dolphinscheduler 2.0.0-SNAPSHOT 4.0.0 - - org.apache.dolphinscheduler - dolphinscheduler-alert-script - dolphinscheduler-plugin + dolphinscheduler-alert-email + jar - - - com.google.guava - guava - - - - ch.qos.logback - logback-classic - - - org.slf4j - slf4j-api + org.apache.poi + poi - - - com.fasterxml.jackson.core - jackson-annotations - provided - - - junit - junit - test + org.apache.poi + poi-ooxml - org.mockito - mockito-core - jar - test + com.google.guava + guava - org.jacoco - org.jacoco.agent - runtime - test + org.apache.commons + commons-email - - - dolphinscheduler-alert-script-${project.version} - - - \ No newline at end of file + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java similarity index 71% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java index 3dbf0b8fb9..c5cdc333fd 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java @@ -17,21 +17,17 @@ package org.apache.dolphinscheduler.plugin.alert.email; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * email alert channel . use email to seed the alertInfo - */ -public class EmailAlertChannel implements AlertChannel { - private static final Logger logger = LoggerFactory.getLogger(EmailAlertChannel.class); +public final class EmailAlertChannel implements AlertChannel { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(EmailAlertChannel.class); @Override public AlertResult process(AlertInfo info) { @@ -44,25 +40,24 @@ public class EmailAlertChannel implements AlertChannel { MailSender mailSender = new MailSender(paramsMap); AlertResult alertResult = mailSender.sendMails(alert.getTitle(), alert.getContent()); - //send flag - boolean flag = false; + boolean flag; if (alertResult == null) { alertResult = new AlertResult(); alertResult.setStatus("false"); alertResult.setMessage("alert send error."); - logger.info("alert send error : {}", alertResult.getMessage()); + log.info("alert send error : {}", alertResult.getMessage()); return alertResult; } flag = Boolean.parseBoolean(String.valueOf(alertResult.getStatus())); if (flag) { - logger.info("alert send success"); + log.info("alert send success"); alertResult.setMessage("email send success."); } else { alertResult.setMessage("alert send error."); - logger.info("alert send error : {}", alertResult.getMessage()); + log.info("alert send error : {}", alertResult.getMessage()); } return alertResult; diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java new file mode 100644 index 0000000000..a2c5261877 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.email; + +import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_FALSE; +import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO; +import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE; +import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES; + +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.ShowType; +import org.apache.dolphinscheduler.spi.params.PasswordParam; +import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; + +import java.util.ArrayList; +import java.util.List; + +import com.google.auto.service.AutoService; + +@AutoService(AlertChannelFactory.class) +public final class EmailAlertChannelFactory implements AlertChannelFactory { + @Override + public String name() { + return "Email"; + } + + @Override + public List params() { + List paramsList = new ArrayList<>(); + InputParam receivesParam = InputParam.newBuilder(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS, MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERS) + .setPlaceholder("please input receives") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam receiveCcsParam = InputParam.newBuilder(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERCCS, MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERCCS) + .build(); + + InputParam mailSmtpHost = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_HOST, MailParamsConstants.MAIL_SMTP_HOST) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + InputParam mailSmtpPort = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_PORT, MailParamsConstants.MAIL_SMTP_PORT) + .setValue("25") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam mailSender = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SENDER, MailParamsConstants.MAIL_SENDER) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + RadioParam enableSmtpAuth = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_AUTH, MailParamsConstants.MAIL_SMTP_AUTH) + .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) + .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) + .setValue(STRING_TRUE) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + InputParam mailUser = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_USER, MailParamsConstants.MAIL_USER) + .setPlaceholder("if enable use authentication, you need input user") + .build(); + + PasswordParam mailPassword = PasswordParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, MailParamsConstants.MAIL_PASSWD) + .setPlaceholder("if enable use authentication, you need input password") + .build(); + + RadioParam enableTls = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_STARTTLS_ENABLE, MailParamsConstants.MAIL_SMTP_STARTTLS_ENABLE) + .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) + .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) + .setValue(STRING_FALSE) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + RadioParam enableSsl = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_ENABLE, MailParamsConstants.MAIL_SMTP_SSL_ENABLE) + .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) + .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) + .setValue(STRING_FALSE) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + InputParam sslTrust = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_TRUST, MailParamsConstants.MAIL_SMTP_SSL_TRUST) + .setValue("*") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, AlertConstants.SHOW_TYPE) + .addParamsOptions(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false)) + .addParamsOptions(new ParamsOptions(ShowType.TEXT.getDescp(), ShowType.TEXT.getDescp(), false)) + .addParamsOptions(new ParamsOptions(ShowType.ATTACHMENT.getDescp(), ShowType.ATTACHMENT.getDescp(), false)) + .addParamsOptions(new ParamsOptions(ShowType.TABLEATTACHMENT.getDescp(), ShowType.TABLEATTACHMENT.getDescp(), false)) + .setValue(ShowType.TABLE.getDescp()) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + paramsList.add(receivesParam); + paramsList.add(receiveCcsParam); + paramsList.add(mailSmtpHost); + paramsList.add(mailSmtpPort); + paramsList.add(mailSender); + paramsList.add(enableSmtpAuth); + paramsList.add(mailUser); + paramsList.add(mailPassword); + paramsList.add(enableTls); + paramsList.add(enableSsl); + paramsList.add(sslTrust); + paramsList.add(showType); + + return paramsList; + } + + @Override + public AlertChannel create() { + return new EmailAlertChannel(); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java similarity index 52% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java index 5eecaa07a7..4c6e1d37ee 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailConstants.java @@ -17,19 +17,11 @@ package org.apache.dolphinscheduler.plugin.alert.email; -public class EmailConstants { - - private EmailConstants() { - throw new IllegalStateException(EmailConstants.class.getName()); - } - - +public final class EmailConstants { public static final String XLS_FILE_PATH = "xls.file.path"; public static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol"; - public static final String DEFAULT_SMTP_PORT = "25"; - public static final String TEXT_HTML_CHARSET_UTF_8 = "text/html;charset=utf-8"; public static final int NUMBER_1000 = 1000; @@ -42,32 +34,23 @@ public class EmailConstants { public static final String TR_END = ""; - public static final String TITLE = "title"; - - public static final String CONTENT = "content"; - public static final String TH = ""; public static final String TH_END = ""; - public static final String MARKDOWN_QUOTE = ">"; - - public static final String MARKDOWN_ENTER = "\n"; - - public static final String HTML_HEADER_PREFIX = new StringBuilder("") - .append("") - .append("") - .append("dolphinscheduler") - .append("") - .append("") - .append("") - .append("") - .append(" ") - .toString(); + public static final String HTML_HEADER_PREFIX = "" + + "" + + "" + + "dolphinscheduler" + + "" + + "" + + "" + + "" + + "
"; public static final String TABLE_BODY_HTML_TAIL = "
"; @@ -76,4 +59,8 @@ public class EmailConstants { public static final String EXCEL_SUFFIX_XLSX = ".xlsx"; public static final String SINGLE_SLASH = "/"; + + private EmailConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java similarity index 92% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java index 90069c6e07..1986f1c08f 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java @@ -36,21 +36,15 @@ import java.util.List; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * excel utils - */ -public class ExcelUtils { +public final class ExcelUtils { + private static final int XLSX_WINDOW_ROW = 10000; + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ExcelUtils.class); private ExcelUtils() { - throw new IllegalStateException("Utility class"); + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } - private static final Logger logger = LoggerFactory.getLogger(ExcelUtils.class); - - private static final int XLSX_WINDOW_ROW = 10000; - /** * generate excel file * @@ -61,14 +55,14 @@ public class ExcelUtils { public static void genExcelFile(String content, String title, String xlsFilePath) { File file = new File(xlsFilePath); if (!file.exists() && !file.mkdirs()) { - logger.error("Create xlsx directory error, path:{}", xlsFilePath); + log.error("Create xlsx directory error, path:{}", xlsFilePath); throw new AlertEmailException("Create xlsx directory error"); } List itemsList = JSONUtils.toList(content, LinkedHashMap.class); if (CollectionUtils.isEmpty(itemsList)) { - logger.error("itemsList is null"); + log.error("itemsList is null"); throw new AlertEmailException("itemsList is null"); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java similarity index 92% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java index d3ccf04f44..7bd75b841e 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailParamsConstants.java @@ -17,22 +17,13 @@ package org.apache.dolphinscheduler.plugin.alert.email; -/** - * mail plugin params json use - */ -public class MailParamsConstants { - - private MailParamsConstants() { - throw new IllegalStateException("Utility class"); - } - +public final class MailParamsConstants { public static final String PLUGIN_DEFAULT_EMAIL_RECEIVERS = "$t('receivers')"; public static final String NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS = "receivers"; public static final String PLUGIN_DEFAULT_EMAIL_RECEIVERCCS = "$t('receiverCcs')"; public static final String NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERCCS = "receiverCcs"; - public static final String MAIL_PROTOCOL = "$t('transportProtocol')"; public static final String NAME_MAIL_PROTOCOL = "mail.protocol"; public static final String MAIL_SMTP_HOST = "$t('mailSmtpHost')"; @@ -62,4 +53,7 @@ public class MailParamsConstants { public static final String MAIL_SMTP_SSL_TRUST = "$t('mailSmtpSslTrust')"; public static final String NAME_MAIL_SMTP_SSL_TRUST = "smtpSslTrust"; + private MailParamsConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java similarity index 89% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java index c37dc3d603..552e7adfba 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java @@ -19,12 +19,12 @@ package org.apache.dolphinscheduler.plugin.alert.email; import static java.util.Objects.requireNonNull; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.AlertResult; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.plugin.alert.email.exception.AlertEmailException; import org.apache.dolphinscheduler.plugin.alert.email.template.AlertTemplate; import org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplate; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.AlertResult; -import org.apache.dolphinscheduler.spi.alert.ShowType; import org.apache.dolphinscheduler.spi.utils.StringUtils; import org.apache.commons.collections4.CollectionUtils; @@ -54,36 +54,30 @@ import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeUtility; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.sun.mail.smtp.SMTPProvider; -/** - * mail utils - */ -public class MailSender { - - public static final Logger logger = LoggerFactory.getLogger(MailSender.class); - - private List receivers; - private List receiverCcs; - private String mailProtocol = "SMTP"; - private String mailSmtpHost; - private String mailSmtpPort; - private String mailSenderEmail; - private String enableSmtpAuth; - private String mailUser; - private String mailPasswd; - private String mailUseStartTLS; - private String mailUseSSL; +public final class MailSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(MailSender.class); + + private final List receivers; + private final List receiverCcs; + private final String mailProtocol = "SMTP"; + private final String mailSmtpHost; + private final String mailSmtpPort; + private final String mailSenderEmail; + private final String enableSmtpAuth; + private final String mailUser; + private final String mailPasswd; + private final String mailUseStartTLS; + private final String mailUseSSL; + private final String sslTrust; + private final String showType; + private final AlertTemplate alertTemplate; + private final String mustNotNull = " must not be null"; private String xlsFilePath; - private String sslTrust; - private String showType; - private AlertTemplate alertTemplate; - private String mustNotNull = " must not be null"; public MailSender(Map config) { - String receiversConfig = config.get(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS); if (receiversConfig == null || "".equals(receiversConfig)) { throw new AlertEmailException(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS + mustNotNull); @@ -95,7 +89,7 @@ public class MailSender { receiverCcs = new ArrayList<>(); if (receiverCcsConfig != null && !"".equals(receiverCcsConfig)) { - receiverCcs = Arrays.asList(receiverCcsConfig.split(",")); + receiverCcs.addAll(Arrays.asList(receiverCcsConfig.split(","))); } mailSmtpHost = config.get(MailParamsConstants.NAME_MAIL_SMTP_HOST); @@ -145,16 +139,6 @@ public class MailSender { return sendMails(this.receivers, this.receiverCcs, title, content); } - /** - * send mail to receivers - * - * @param title email title - * @param content email content - */ - public AlertResult sendMailsToReceiverOnly(String title, String content) { - return sendMails(this.receivers, null, title, content); - } - /** * send mail * @@ -206,8 +190,8 @@ public class MailSender { try { String partContent = (showType.equals(ShowType.ATTACHMENT.getDescp()) - ? "Please see the attachment " + title + EmailConstants.EXCEL_SUFFIX_XLSX - : htmlTable(content, false)); + ? "Please see the attachment " + title + EmailConstants.EXCEL_SUFFIX_XLSX + : htmlTable(content, false)); attachment(title, content, partContent); @@ -396,12 +380,12 @@ public class MailSender { public void deleteFile(File file) { if (file.exists()) { if (file.delete()) { - logger.info("delete success: {}", file.getAbsolutePath()); + log.info("delete success: {}", file.getAbsolutePath()); } else { - logger.info("delete fail: {}", file.getAbsolutePath()); + log.info("delete fail: {}", file.getAbsolutePath()); } } else { - logger.info("file not exists: {}", file.getAbsolutePath()); + log.info("file not exists: {}", file.getAbsolutePath()); } } @@ -409,7 +393,7 @@ public class MailSender { * handle exception */ private void handleException(AlertResult alertResult, Exception e) { - logger.error("Send email to {} failed", receivers, e); + log.error("Send email to {} failed", receivers, e); alertResult.setMessage("Send email to {" + String.join(",", receivers) + "} failed," + e.toString()); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java similarity index 83% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java index 466ccc06de..5b64d8de1e 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/exception/AlertEmailException.java @@ -18,22 +18,10 @@ package org.apache.dolphinscheduler.plugin.alert.email.exception; public class AlertEmailException extends RuntimeException { - - /** - * Create Runtime exception - * - * @param errMsg - Error message - */ public AlertEmailException(String errMsg) { super(errMsg); } - /** - * Create Runtime exception - * - * @param errMsg - Error message - * @param cause - cause - */ public AlertEmailException(String errMsg, Throwable cause) { super(errMsg, cause); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java similarity index 86% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java index dec993d4d0..7f66e659b4 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/AlertTemplate.java @@ -17,19 +17,16 @@ package org.apache.dolphinscheduler.plugin.alert.email.template; -import org.apache.dolphinscheduler.spi.alert.ShowType; +import org.apache.dolphinscheduler.alert.api.ShowType; -/** - * alert message template - */ public interface AlertTemplate { /** * get a message from a specified alert template * - * @param content alert message content + * @param content alert message content * @param showType show type - * @param showAll whether to show all + * @param showAll whether to show all * @return a message from a specified alert template */ String getMessageFromTemplate(String content, ShowType showType, boolean showAll); @@ -37,7 +34,7 @@ public interface AlertTemplate { /** * default showAll is true * - * @param content alert message content + * @param content alert message content * @param showType show type * @return a message from a specified alert template */ diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java similarity index 95% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java index 57187aa70c..433cfda3f7 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplate.java @@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.alert.email.template; import static java.util.Objects.requireNonNull; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.plugin.alert.email.EmailConstants; -import org.apache.dolphinscheduler.spi.alert.ShowType; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.StringUtils; @@ -36,9 +36,6 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; -/** - * the default html alert message template - */ public class DefaultHTMLTemplate implements AlertTemplate { public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class); @@ -89,7 +86,7 @@ public class DefaultHTMLTemplate implements AlertTemplate { Map.Entry entry = iterator.next(); t.append(EmailConstants.TH).append(entry.getKey()).append(EmailConstants.TH_END); - cs.append(EmailConstants.TD).append(String.valueOf(entry.getValue())).append(EmailConstants.TD_END); + cs.append(EmailConstants.TD).append(entry.getValue()).append(EmailConstants.TD_END); } t.append(EmailConstants.TR_END); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java similarity index 82% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java index 37a11e47fb..5bb7c1d504 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.email; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import java.util.List; @@ -25,27 +25,14 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; -/** - * EmailAlertChannelFactory Tester. - * - * @version 1.0 - * @since
Aug 20, 2020
- */ public class EmailAlertChannelFactoryTest { - - /** - * Method: getParams() - */ @Test public void testGetParams() { EmailAlertChannelFactory emailAlertChannelFactory = new EmailAlertChannelFactory(); - List params = emailAlertChannelFactory.getParams(); + List params = emailAlertChannelFactory.params(); Assert.assertEquals(12, params.size()); } - /** - * Method: create() - */ @Test public void testCreate() { EmailAlertChannelFactory emailAlertChannelFactory = new EmailAlertChannelFactory(); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java similarity index 57% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java index 8d599c8b09..49f67b2ffa 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java @@ -17,18 +17,18 @@ package org.apache.dolphinscheduler.plugin.alert.email; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; -import org.apache.dolphinscheduler.spi.alert.ShowType; -import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.ArrayList; @@ -39,14 +39,7 @@ import java.util.Map; import org.junit.Assert; import org.junit.Test; -/** - * EmailAlertChannel Tester. - */ public class EmailAlertChannelTest { - - /** - * Method: process(AlertInfo info) - */ @Test public void testProcess() { EmailAlertChannel emailAlertChannel = new EmailAlertChannel(); @@ -62,9 +55,9 @@ public class EmailAlertChannelTest { String mapjson = JSONUtils.toJsonString(maps); alertData.setId(10) - .setContent(mapjson) - .setLog("10") - .setTitle("test"); + .setContent(mapjson) + .setLog("10") + .setTitle("test"); AlertInfo alertInfo = new AlertInfo(); alertInfo.setAlertData(alertData); Map paramsMap = PluginParamsTransfer.getPluginParamsMap(getEmailAlertParams()); @@ -78,62 +71,62 @@ public class EmailAlertChannelTest { public String getEmailAlertParams() { List paramsList = new ArrayList<>(); InputParam receivesParam = InputParam.newBuilder(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS, "receivers") - .setValue("540957506@qq.com") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setValue("540957506@qq.com") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); InputParam mailSmtpHost = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_HOST, "smtp.host") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("smtp.126.com") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("smtp.126.com") + .build(); InputParam mailSmtpPort = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_PORT, "smtp.port") - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .setValue("25") - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .setValue("25") + .build(); InputParam mailSender = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SENDER, "sender") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("dolphinscheduler@126.com") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("dolphinscheduler@126.com") + .build(); RadioParam enableSmtpAuth = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_AUTH, "smtp.auth") - .addParamsOptions(new ParamsOptions("YES", "true", false)) - .addParamsOptions(new ParamsOptions("NO", "false", false)) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("false") - .build(); + .addParamsOptions(new ParamsOptions("YES", "true", false)) + .addParamsOptions(new ParamsOptions("NO", "false", false)) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("false") + .build(); InputParam mailUser = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_USER, "user") - .setPlaceholder("if enable use authentication, you need input user") - .setValue("dolphinscheduler@126.com") - .build(); + .setPlaceholder("if enable use authentication, you need input user") + .setValue("dolphinscheduler@126.com") + .build(); PasswordParam mailPassword = PasswordParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, "passwd") - .setPlaceholder("if enable use authentication, you need input password") - .setValue("escheduler123") - .build(); + .setPlaceholder("if enable use authentication, you need input password") + .setValue("escheduler123") + .build(); RadioParam enableTls = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_STARTTLS_ENABLE, "starttls.enable") - .addParamsOptions(new ParamsOptions("YES", "true", false)) - .addParamsOptions(new ParamsOptions("NO", "false", false)) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("true") - .build(); + .addParamsOptions(new ParamsOptions("YES", "true", false)) + .addParamsOptions(new ParamsOptions("NO", "false", false)) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("true") + .build(); RadioParam enableSsl = RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_ENABLE, "smtp.ssl.enable") - .addParamsOptions(new ParamsOptions("YES", "true", false)) - .addParamsOptions(new ParamsOptions("NO", "false", false)) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("true") - .build(); + .addParamsOptions(new ParamsOptions("YES", "true", false)) + .addParamsOptions(new ParamsOptions("NO", "false", false)) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("true") + .build(); InputParam sslTrust = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_TRUST, "smtp.ssl.trust") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("smtp.126.com") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("smtp.126.com") + .build(); List emailShowTypeList = new ArrayList<>(); emailShowTypeList.add(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false)); @@ -141,10 +134,10 @@ public class EmailAlertChannelTest { emailShowTypeList.add(new ParamsOptions(ShowType.ATTACHMENT.getDescp(), ShowType.ATTACHMENT.getDescp(), false)); emailShowTypeList.add(new ParamsOptions(ShowType.TABLEATTACHMENT.getDescp(), ShowType.TABLEATTACHMENT.getDescp(), false)); RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, "showType") - .setOptions(emailShowTypeList) - .setValue(ShowType.TABLE.getDescp()) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setOptions(emailShowTypeList) + .setValue(ShowType.TABLE.getDescp()) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); paramsList.add(receivesParam); paramsList.add(mailSmtpHost); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtilsTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtilsTest.java similarity index 100% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtilsTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtilsTest.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java similarity index 88% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java index e748e71a9b..63ba4403c2 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/MailUtilsTest.java @@ -17,10 +17,10 @@ package org.apache.dolphinscheduler.plugin.alert.email; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.plugin.alert.email.template.AlertTemplate; import org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplate; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.ShowType; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.ArrayList; @@ -34,17 +34,12 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - */ public class MailUtilsTest { private static final Logger logger = LoggerFactory.getLogger(MailUtilsTest.class); - + static MailSender mailSender; private static Map emailConfig = new HashMap<>(); - private static AlertTemplate alertTemplate; - static MailSender mailSender; - @BeforeClass public static void initEmailConfig() { emailConfig.put(MailParamsConstants.NAME_MAIL_PROTOCOL, "smtp"); @@ -68,19 +63,19 @@ public class MailUtilsTest { public void testSendMails() { String content = "[\"id:69\"," - + "\"name:UserBehavior-0--1193959466\"," - + "\"Job name: Start workflow\"," - + "\"State: SUCCESS\"," - + "\"Recovery:NO\"," - + "\"Run time: 1\"," - + "\"Start time: 2018-08-06 10:31:34.0\"," - + "\"End time: 2018-08-06 10:31:49.0\"," - + "\"Host: 192.168.xx.xx\"," - + "\"Notify group :4\"]"; + + "\"name:UserBehavior-0--1193959466\"," + + "\"Job name: Start workflow\"," + + "\"State: SUCCESS\"," + + "\"Recovery:NO\"," + + "\"Run time: 1\"," + + "\"Start time: 2018-08-06 10:31:34.0\"," + + "\"End time: 2018-08-06 10:31:49.0\"," + + "\"Host: 192.168.xx.xx\"," + + "\"Notify group :4\"]"; mailSender.sendMails( - "Mysql Exception", - content); + "Mysql Exception", + content); } public String list2String() { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java similarity index 71% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java index 3d941962d9..d53c95bfbd 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/template/DefaultHTMLTemplateTest.java @@ -19,8 +19,8 @@ package org.apache.dolphinscheduler.plugin.alert.email.template; import static org.junit.Assert.assertEquals; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.plugin.alert.email.EmailConstants; -import org.apache.dolphinscheduler.spi.alert.ShowType; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.ArrayList; @@ -31,19 +31,12 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * test class for DefaultHTMLTemplate - */ public class DefaultHTMLTemplateTest { private static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplateTest.class); - /** - * only need test method GetMessageFromTemplate - */ @Test public void testGetMessageFromTemplate() { - DefaultHTMLTemplate template = new DefaultHTMLTemplate(); String tableTypeMessage = template.getMessageFromTemplate(list2String(), ShowType.TABLE, true); @@ -55,11 +48,7 @@ public class DefaultHTMLTemplateTest { assertEquals(textTypeMessage, generateMockTextTypeResultByHand()); } - /** - * generate some simulation data - */ private String list2String() { - LinkedHashMap map1 = new LinkedHashMap<>(); map1.put("mysql service name", "mysql200"); map1.put("mysql address", "192.168.xx.xx"); @@ -84,22 +73,20 @@ public class DefaultHTMLTemplateTest { } private String generateMockTableTypeResultByHand() { - return EmailConstants.HTML_HEADER_PREFIX - + "" - + "mysql service namemysql addressdatabase client connectionsportno index of number" - + "\n" - + "mysql200192.168.xx.xx190330680" - + "mysql210192.168.xx.xx90330610" - + EmailConstants.TABLE_BODY_HTML_TAIL; + + "" + + "mysql service namemysql addressdatabase client connectionsportno index of number" + + "\n" + + "mysql200192.168.xx.xx190330680" + + "mysql210192.168.xx.xx90330610" + + EmailConstants.TABLE_BODY_HTML_TAIL; } private String generateMockTextTypeResultByHand() { - return EmailConstants.HTML_HEADER_PREFIX - + "{\"mysql service name\":\"mysql200\",\"mysql address\":\"192.168.xx.xx\",\"database client connections\":\"190\",\"port\":\"3306\",\"no index of number\":\"80\"}" - + "{\"mysql service name\":\"mysql210\",\"mysql address\":\"192.168.xx.xx\",\"database client connections\":\"90\",\"port\":\"3306\",\"no index of number\":\"10\"}" - + EmailConstants.TABLE_BODY_HTML_TAIL; + + "{\"mysql service name\":\"mysql200\",\"mysql address\":\"192.168.xx.xx\",\"database client connections\":\"190\",\"port\":\"3306\",\"no index of number\":\"80\"}" + + "{\"mysql service name\":\"mysql210\",\"mysql address\":\"192.168.xx.xx\",\"database client connections\":\"90\",\"port\":\"3306\",\"no index of number\":\"10\"}" + + EmailConstants.TABLE_BODY_HTML_TAIL; } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/pom.xml similarity index 51% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/pom.xml index 3f13c8e342..19021cb2bf 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/pom.xml @@ -15,22 +15,19 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - dolphinscheduler-alert-plugin + dolphinscheduler-alert-plugins org.apache.dolphinscheduler 2.0.0-SNAPSHOT 4.0.0 - - org.apache.dolphinscheduler dolphinscheduler-alert-feishu - dolphinscheduler-plugin + jar - org.apache.httpcomponents httpclient @@ -39,46 +36,5 @@ com.google.guava guava - - - ch.qos.logback - logback-classic - - - - org.slf4j - slf4j-api - - - - com.fasterxml.jackson.core - jackson-annotations - provided - - - - junit - junit - test - - - - org.mockito - mockito-core - jar - test - - - - org.jacoco - org.jacoco.agent - runtime - test - - - - dolphinscheduler-alert-feishu-${project.version} - - - \ No newline at end of file + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java similarity index 81% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java index 3bbdaa9997..509eebe615 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java @@ -17,17 +17,16 @@ package org.apache.dolphinscheduler.plugin.alert.feishu; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; -public class FeiShuAlertChannel implements AlertChannel { +public final class FeiShuAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo alertInfo) { - AlertData alertData = alertInfo.getAlertData(); Map paramsMap = alertInfo.getAlertParams(); if (null == paramsMap) { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java similarity index 52% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java index 142c0aabea..da78b9f39b 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java @@ -22,59 +22,62 @@ import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO; import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE; import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.spi.params.PasswordParam; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import java.util.Arrays; import java.util.List; -public class FeiShuAlertChannelFactory implements AlertChannelFactory { +import com.google.auto.service.AutoService; + +@AutoService(AlertChannelFactory.class) +public final class FeiShuAlertChannelFactory implements AlertChannelFactory { @Override - public String getName() { + public String name() { return "Feishu"; } @Override - public List getParams() { + public List params() { InputParam webHookParam = InputParam.newBuilder(FeiShuParamsConstants.NAME_WEB_HOOK, FeiShuParamsConstants.WEB_HOOK) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); RadioParam isEnableProxy = - RadioParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE, FeiShuParamsConstants.FEI_SHU_PROXY_ENABLE) - .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) - .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) - .setValue(STRING_TRUE) - .addValidate(Validate.newBuilder() - .setRequired(false) - .build()) - .build(); + RadioParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE, FeiShuParamsConstants.FEI_SHU_PROXY_ENABLE) + .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false)) + .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false)) + .setValue(STRING_TRUE) + .addValidate(Validate.newBuilder() + .setRequired(false) + .build()) + .build(); InputParam proxyParam = - InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY, FeiShuParamsConstants.FEI_SHU_PROXY) - .addValidate(Validate.newBuilder() - .setRequired(false).build()) - .build(); + InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY, FeiShuParamsConstants.FEI_SHU_PROXY) + .addValidate(Validate.newBuilder() + .setRequired(false).build()) + .build(); InputParam portParam = InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PORT, FeiShuParamsConstants.FEI_SHU_PORT) - .addValidate(Validate.newBuilder() - .setRequired(false).build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(false).build()) + .build(); InputParam userParam = - InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_USER, FeiShuParamsConstants.FEI_SHU_USER) - .addValidate(Validate.newBuilder() - .setRequired(false).build()) - .build(); + InputParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_USER, FeiShuParamsConstants.FEI_SHU_USER) + .addValidate(Validate.newBuilder() + .setRequired(false).build()) + .build(); PasswordParam passwordParam = PasswordParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PASSWORD, FeiShuParamsConstants.FEI_SHU_PASSWORD) - .setPlaceholder("if enable use authentication, you need input password") - .build(); + .setPlaceholder("if enable use authentication, you need input password") + .build(); return Arrays.asList(webHookParam, isEnableProxy, proxyParam, portParam, userParam, passwordParam); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java similarity index 91% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java index 133c1fc86f..aa743903e9 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuParamsConstants.java @@ -17,18 +17,10 @@ package org.apache.dolphinscheduler.plugin.alert.feishu; -public class FeiShuParamsConstants { - - private FeiShuParamsConstants() { - throw new IllegalStateException("Utility class"); - } - +public final class FeiShuParamsConstants { + public static final String FEI_SHU_PROXY_ENABLE = "$t('isEnableProxy')"; static final String WEB_HOOK = "$t('webhook')"; - static final String NAME_WEB_HOOK = "WebHook"; - - public static final String FEI_SHU_PROXY_ENABLE = "$t('isEnableProxy')"; - static final String NAME_FEI_SHU_PROXY_ENABLE = "IsEnableProxy"; static final String FEI_SHU_PROXY = "$t('proxy')"; @@ -46,4 +38,8 @@ public class FeiShuParamsConstants { static final String FEI_SHU_PASSWORD = "$t('password')"; static final String NAME_FEI_SHU_PASSWORD = "Password"; + + private FeiShuParamsConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java similarity index 66% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java index 8fdafe7182..dd40c755ba 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java @@ -17,8 +17,8 @@ package org.apache.dolphinscheduler.plugin.alert.feishu; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.commons.codec.binary.StringUtils; @@ -31,23 +31,18 @@ import org.apache.http.util.EntityUtils; import java.io.IOException; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonProperty; -public class FeiShuSender { - - private static final Logger logger = LoggerFactory.getLogger(FeiShuSender.class); - - private String url; - - private Boolean enableProxy; +public final class FeiShuSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(FeiShuSender.class); + private final String url; + private final Boolean enableProxy; private String proxy; @@ -70,7 +65,6 @@ public class FeiShuSender { } private static String textToJsonString(AlertData alertData) { - Map items = new HashMap<>(2); items.put("msg_type", "text"); Map textContent = new HashMap<>(); @@ -87,14 +81,14 @@ public class FeiShuSender { if (org.apache.dolphinscheduler.spi.utils.StringUtils.isBlank(result)) { alertResult.setMessage("send fei shu msg error"); - logger.info("send fei shu msg error,fei shu server resp is null"); + log.info("send fei shu msg error,fei shu server resp is null"); return alertResult; } FeiShuSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, FeiShuSendMsgResponse.class); if (null == sendMsgResponse) { alertResult.setMessage("send fei shu msg fail"); - logger.info("send fei shu msg error,resp error"); + log.info("send fei shu msg error,resp error"); return alertResult; } if (sendMsgResponse.statusCode == 0) { @@ -103,7 +97,7 @@ public class FeiShuSender { return alertResult; } alertResult.setMessage(String.format("alert send fei shu msg error : %s", sendMsgResponse.getStatusMessage())); - logger.info("alert send fei shu msg error : {} ,Extra : {} ", sendMsgResponse.getStatusMessage(), sendMsgResponse.getExtra()); + log.info("alert send fei shu msg error : {} ,Extra : {} ", sendMsgResponse.getStatusMessage(), sendMsgResponse.getExtra()); return alertResult; } @@ -118,9 +112,7 @@ public class FeiShuSender { StringBuilder contents = new StringBuilder(100); contents.append(String.format("`%s`%n", alertData.getTitle())); for (Map map : list) { - Iterator> entries = map.entrySet().iterator(); - while (entries.hasNext()) { - Entry entry = entries.next(); + for (Entry entry : (Iterable>) map.entrySet()) { String key = entry.getKey(); String value = entry.getValue().toString(); contents.append(key + ":" + value); @@ -138,7 +130,7 @@ public class FeiShuSender { String resp = sendMsg(alertData); return checkSendFeiShuSendMsgResult(resp); } catch (Exception e) { - logger.info("send fei shu alert msg exception : {}", e.getMessage()); + log.info("send fei shu alert msg exception : {}", e.getMessage()); alertResult = new AlertResult(); alertResult.setStatus("false"); alertResult.setMessage("send fei shu alert fail."); @@ -161,7 +153,7 @@ public class FeiShuSender { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { - logger.error("send feishu message error, return http status code: {} ", statusCode); + log.error("send feishu message error, return http status code: {} ", statusCode); } String resp; try { @@ -171,14 +163,14 @@ public class FeiShuSender { } finally { response.close(); } - logger.info("Fei Shu send title :{} ,content :{}, resp: {}", alertData.getTitle(), alertData.getContent(), resp); + log.info("Fei Shu send title :{} ,content :{}, resp: {}", alertData.getTitle(), alertData.getContent(), resp); return resp; } finally { httpClient.close(); } } - public static class FeiShuSendMsgResponse { + static final class FeiShuSendMsgResponse { @JsonProperty("Extra") private String extra; @JsonProperty("StatusCode") @@ -186,29 +178,76 @@ public class FeiShuSender { @JsonProperty("StatusMessage") private String statusMessage; + public FeiShuSendMsgResponse() { + } + public String getExtra() { - return extra; + return this.extra; } + @JsonProperty("Extra") public void setExtra(String extra) { this.extra = extra; } public Integer getStatusCode() { - return statusCode; + return this.statusCode; } + @JsonProperty("StatusCode") public void setStatusCode(Integer statusCode) { this.statusCode = statusCode; } public String getStatusMessage() { - return statusMessage; + return this.statusMessage; } + @JsonProperty("StatusMessage") public void setStatusMessage(String statusMessage) { this.statusMessage = statusMessage; } - } + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof FeiShuSendMsgResponse)) { + return false; + } + final FeiShuSendMsgResponse other = (FeiShuSendMsgResponse) o; + final Object this$extra = this.getExtra(); + final Object other$extra = other.getExtra(); + if (this$extra == null ? other$extra != null : !this$extra.equals(other$extra)) { + return false; + } + final Object this$statusCode = this.getStatusCode(); + final Object other$statusCode = other.getStatusCode(); + if (this$statusCode == null ? other$statusCode != null : !this$statusCode.equals(other$statusCode)) { + return false; + } + final Object this$statusMessage = this.getStatusMessage(); + final Object other$statusMessage = other.getStatusMessage(); + if (this$statusMessage == null ? other$statusMessage != null : !this$statusMessage.equals(other$statusMessage)) { + return false; + } + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $extra = this.getExtra(); + result = result * PRIME + ($extra == null ? 43 : $extra.hashCode()); + final Object $statusCode = this.getStatusCode(); + result = result * PRIME + ($statusCode == null ? 43 : $statusCode.hashCode()); + final Object $statusMessage = this.getStatusMessage(); + result = result * PRIME + ($statusMessage == null ? 43 : $statusMessage.hashCode()); + return result; + } + + public String toString() { + return "FeiShuSender.FeiShuSendMsgResponse(extra=" + this.getExtra() + ", statusCode=" + this.getStatusCode() + ", statusMessage=" + this.getStatusMessage() + ")"; + } + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java similarity index 92% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java index 3d143579d4..eca9b07d15 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java @@ -28,7 +28,10 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -public class HttpRequestUtil { +public final class HttpRequestUtil { + private HttpRequestUtil() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } public static CloseableHttpClient getHttpClient(boolean enableProxy, String proxy, Integer port, String user, String password) { if (enableProxy) { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java similarity index 92% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java index d73355dbc0..ce51e00474 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactoryTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.feishu; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.utils.JSONUtils; @@ -31,7 +31,7 @@ public class FeiShuAlertChannelFactoryTest { @Test public void testGetParams() { FeiShuAlertChannelFactory feiShuAlertChannelFactory = new FeiShuAlertChannelFactory(); - List params = feiShuAlertChannelFactory.getParams(); + List params = feiShuAlertChannelFactory.params(); JSONUtils.toJsonString(params); Assert.assertEquals(6, params.size()); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java similarity index 74% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java index 05110d42fe..8d5dfdbc6a 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java @@ -17,8 +17,8 @@ package org.apache.dolphinscheduler.plugin.alert.feishu; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.HashMap; import java.util.Map; @@ -50,23 +50,23 @@ public class FeiShuSenderTest { @Test public void testFormatContent() { String alertMsg = "[\n" - + " {\n" - + " \"owner\": \"dolphinscheduler\",\n" - + " \"processEndTime\": \"2021-01-29 19:01:11\",\n" - + " \"processHost\": \"10.81.129.4:5678\",\n" - + " \"processId\": 2926,\n" - + " \"processName\": \"3-20210129190038108\",\n" - + " \"processStartTime\": \"2021-01-29 19:00:38\",\n" - + " \"processState\": \"SUCCESS\",\n" - + " \"processType\": \"START_PROCESS\",\n" - + " \"projectId\": 2,\n" - + " \"projectName\": \"testdelproject\",\n" - + " \"recovery\": \"NO\",\n" - + " \"retryTimes\": 0,\n" - + " \"runTimes\": 1,\n" - + " \"taskId\": 0\n" - + " }\n" - + "]"; + + " {\n" + + " \"owner\": \"dolphinscheduler\",\n" + + " \"processEndTime\": \"2021-01-29 19:01:11\",\n" + + " \"processHost\": \"10.81.129.4:5678\",\n" + + " \"processId\": 2926,\n" + + " \"processName\": \"3-20210129190038108\",\n" + + " \"processStartTime\": \"2021-01-29 19:00:38\",\n" + + " \"processState\": \"SUCCESS\",\n" + + " \"processType\": \"START_PROCESS\",\n" + + " \"projectId\": 2,\n" + + " \"projectName\": \"testdelproject\",\n" + + " \"recovery\": \"NO\",\n" + + " \"retryTimes\": 0,\n" + + " \"runTimes\": 1,\n" + + " \"taskId\": 0\n" + + " }\n" + + "]"; AlertData alertData = new AlertData(); alertData.setTitle(""); alertData.setContent(alertMsg); @@ -90,7 +90,7 @@ public class FeiShuSenderTest { AlertResult alertResult = feiShuSender.checkSendFeiShuSendMsgResult(""); Assert.assertFalse(Boolean.valueOf(alertResult.getStatus())); AlertResult alertResult2 = feiShuSender.checkSendFeiShuSendMsgResult("123"); - Assert.assertEquals("send fei shu msg fail",alertResult2.getMessage()); + Assert.assertEquals("send fei shu msg fail", alertResult2.getMessage()); String response = "{\"StatusCode\":\"0\",\"extra\":\"extra\",\"StatusMessage\":\"StatusMessage\"}"; AlertResult alertResult3 = feiShuSender.checkSendFeiShuSendMsgResult(response); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/pom.xml similarity index 53% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/pom.xml index 7dce712715..6bc4156bdb 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/pom.xml @@ -15,71 +15,33 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - dolphinscheduler-alert-plugin + dolphinscheduler-alert-plugins org.apache.dolphinscheduler 2.0.0-SNAPSHOT 4.0.0 - - org.apache.dolphinscheduler - dolphinscheduler-alert-slack - dolphinscheduler-plugin + dolphinscheduler-alert-http + jar - - - org.apache.httpcomponents - httpclient - - com.google.guava guava - ch.qos.logback - logback-classic - - - - org.slf4j - slf4j-api + org.apache.httpcomponents + httpclient com.fasterxml.jackson.core - jackson-annotations + jackson-databind provided - - - junit - junit - test - - - - org.mockito - mockito-core - jar - test - - - - org.jacoco - org.jacoco.agent - runtime - test - - - - dolphinscheduler-alert-slack-${project.version} - - - \ No newline at end of file + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java similarity index 78% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java index cb550b7541..14b416785d 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java @@ -17,20 +17,16 @@ package org.apache.dolphinscheduler.plugin.alert.http; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; -/** - * http alert channel,use sms message to seed the alertInfo - */ -public class HttpAlertChannel implements AlertChannel { +public final class HttpAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo alertInfo) { - AlertData alertData = alertInfo.getAlertData(); Map paramsMap = alertInfo.getAlertParams(); if (null == paramsMap) { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java similarity index 52% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java index 2dda6418bd..d5c628c90c 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java @@ -17,56 +17,56 @@ package org.apache.dolphinscheduler.plugin.alert.http; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; import java.util.Arrays; import java.util.List; -/** - * http alert factory - */ -public class HttpAlertChannelFactory implements AlertChannelFactory { +import com.google.auto.service.AutoService; + +@AutoService(AlertChannelFactory.class) +public final class HttpAlertChannelFactory implements AlertChannelFactory { @Override - public String getName() { + public String name() { return "Http"; } @Override - public List getParams() { + public List params() { InputParam url = InputParam.newBuilder(HttpAlertConstants.NAME_URL, HttpAlertConstants.URL) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); InputParam headerParams = InputParam.newBuilder(HttpAlertConstants.NAME_HEADER_PARAMS, HttpAlertConstants.HEADER_PARAMS) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); InputParam bodyParams = InputParam.newBuilder(HttpAlertConstants.NAME_BODY_PARAMS, HttpAlertConstants.BODY_PARAMS) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); InputParam contentField = InputParam.newBuilder(HttpAlertConstants.NAME_CONTENT_FIELD, HttpAlertConstants.CONTENT_FIELD) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); InputParam requestType = InputParam.newBuilder(HttpAlertConstants.NAME_REQUEST_TYPE, HttpAlertConstants.REQUEST_TYPE) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); return Arrays.asList(url, requestType, headerParams, bodyParams, contentField); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java similarity index 91% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java index 2e1bcf6179..6bbf0bfbe0 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java @@ -17,11 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.http; -public class HttpAlertConstants { - - private HttpAlertConstants() { - } - +public final class HttpAlertConstants { public static final String URL = "$t('url')"; public static final String NAME_URL = "url"; @@ -42,4 +38,7 @@ public class HttpAlertConstants { public static final String NAME_REQUEST_TYPE = "requestType"; + private HttpAlertConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java similarity index 90% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java index 803ecf91eb..93dca6f9d2 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.http; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.StringUtils; @@ -35,43 +35,27 @@ import java.util.HashMap; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -/** - * http send message - */ -public class HttpSender { - - public static final Logger logger = LoggerFactory.getLogger(HttpSender.class); - - private String url; - - private final String headerParams; - - private final String bodyParams; - - private final String contentField; - - private final String requestType; - - private HttpRequestBase httpRequest; - - +public final class HttpSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(HttpSender.class); private static final String URL_SPLICE_CHAR = "?"; - /** * request type post */ private static final String REQUEST_TYPE_POST = "POST"; - /** * request type get */ private static final String REQUEST_TYPE_GET = "GET"; - private static final String DEFAULT_CHARSET = "utf-8"; + private final String headerParams; + private final String bodyParams; + private final String contentField; + private final String requestType; + private String url; + private HttpRequestBase httpRequest; public HttpSender(Map paramsMap) { @@ -102,7 +86,7 @@ public class HttpSender { alertResult.setStatus("true"); alertResult.setMessage(resp); } catch (Exception e) { - logger.error("send http alert msg exception : {}", e.getMessage()); + log.error("send http alert msg exception : {}", e.getMessage()); alertResult.setStatus("false"); alertResult.setMessage("send http request alert fail."); } @@ -157,16 +141,15 @@ public class HttpSender { /** * set body params */ - private void setMsgInRequestBody(String msg) { + private void setMsgInRequestBody(String msg) { ObjectNode objectNode = JSONUtils.parseObject(bodyParams); //set msg content field objectNode.put(contentField, msg); try { StringEntity entity = new StringEntity(bodyParams, DEFAULT_CHARSET); - ((HttpPost)httpRequest).setEntity(entity); + ((HttpPost) httpRequest).setEntity(entity); } catch (Exception e) { - logger.error("send http alert msg exception : {}", e.getMessage()); + log.error("send http alert msg exception : {}", e.getMessage()); } } - } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java similarity index 93% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java index 25181ebd26..089f78f3af 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.http; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import java.util.List; @@ -26,9 +26,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -/** - * HttpAlertChannelFactory UT - */ public class HttpAlertChannelFactoryTest { private HttpAlertChannelFactory httpAlertChannelFactory; @@ -41,7 +38,7 @@ public class HttpAlertChannelFactoryTest { @Test public void getParamsTest() { - List pluginParamsList = httpAlertChannelFactory.getParams(); + List pluginParamsList = httpAlertChannelFactory.params(); Assert.assertEquals(5, pluginParamsList.size()); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java similarity index 70% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java index 2d29407e71..ca63902aae 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java @@ -17,13 +17,13 @@ package org.apache.dolphinscheduler.plugin.alert.http; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; -import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.ArrayList; @@ -33,9 +33,6 @@ import java.util.Map; import org.junit.Assert; import org.junit.Test; -/** - * HttpAlertChannel UT - */ public class HttpAlertChannelTest { @Test @@ -71,29 +68,29 @@ public class HttpAlertChannelTest { List paramsList = new ArrayList<>(); InputParam urlParam = InputParam.newBuilder("url", "url") - .setValue("http://www.baidu.com") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setValue("http://www.baidu.com") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); InputParam headerParams = InputParam.newBuilder("headerParams", "headerParams") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("{\"Content-Type\":\"application/json\"}") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("{\"Content-Type\":\"application/json\"}") + .build(); InputParam bodyParams = InputParam.newBuilder("bodyParams", "bodyParams") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("{\"number\":\"13457654323\"}") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("{\"number\":\"13457654323\"}") + .build(); InputParam content = InputParam.newBuilder("contentField", "contentField") - .setValue("content") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setValue("content") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); InputParam requestType = InputParam.newBuilder("requestType", "requestType") - .setValue("POST") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setValue("POST") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); paramsList.add(urlParam); paramsList.add(headerParams); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java similarity index 95% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java index 11019333b1..3432073a49 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.http; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.HashMap; import java.util.Map; @@ -25,14 +25,10 @@ import java.util.Map; import org.junit.Assert; import org.junit.Test; -/** - * HttpSender UT - */ public class HttpSenderTest { @Test public void sendTest() { - Map paramsMap = new HashMap<>(); paramsMap.put(HttpAlertConstants.NAME_URL, "http://www.baidu.com"); paramsMap.put(HttpAlertConstants.NAME_REQUEST_TYPE, "POST"); diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/pom.xml new file mode 100644 index 0000000000..1c99ac7f77 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/pom.xml @@ -0,0 +1,36 @@ + + + + + dolphinscheduler-alert-plugins + org.apache.dolphinscheduler + 2.0.0-SNAPSHOT + + 4.0.0 + dolphinscheduler-alert-script + jar + + + + com.google.guava + guava + + + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java similarity index 88% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java index b8816724c7..51e567b47e 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java @@ -17,13 +17,9 @@ package org.apache.dolphinscheduler.plugin.alert.script; -/** - * OSUtils - */ -public class OSUtils { - +public final class OSUtils { private OSUtils() { - throw new UnsupportedOperationException("Construct OSUtils"); + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } static Boolean isWindows() { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java similarity index 84% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java index d63a350051..7008267877 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -20,17 +20,12 @@ package org.apache.dolphinscheduler.plugin.alert.script; import java.io.IOException; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * ProcessUtils - */ -public class ProcessUtils { - - private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); +public final class ProcessUtils { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ProcessUtils.class); private ProcessUtils() { - throw new IllegalStateException("Utility class"); + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } /** @@ -53,7 +48,7 @@ public class ProcessUtils { errorStreamGobbler.start(); return process.waitFor(); } catch (IOException | InterruptedException e) { - logger.error("execute alert script error {}", e.getMessage()); + log.error("execute alert script error {}", e.getMessage()); Thread.currentThread().interrupt(); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java similarity index 77% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java index af0c27615f..bd52955b74 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java @@ -17,18 +17,14 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; -/** - * ScriptAlertChannel - */ -public class ScriptAlertChannel implements AlertChannel { - +public final class ScriptAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo alertinfo) { AlertData alertData = alertinfo.getAlertData(); @@ -36,6 +32,6 @@ public class ScriptAlertChannel implements AlertChannel { if (null == paramsMap) { return new AlertResult("false", "script params is null"); } - return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle(),alertData.getContent()); + return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle(), alertData.getContent()); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java similarity index 52% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java index 67cfc3931f..aacde95ba1 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java @@ -17,49 +17,49 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.input.InputParam; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import java.util.Arrays; import java.util.List; -/** - * ScriptAlertChannelFactory - */ -public class ScriptAlertChannelFactory implements AlertChannelFactory { +import com.google.auto.service.AutoService; +@AutoService(AlertChannelFactory.class) +public final class ScriptAlertChannelFactory implements AlertChannelFactory { @Override - public String getName() { + public String name() { return "Script"; } @Override - public List getParams() { + public List params() { InputParam scriptUserParam = InputParam.newBuilder(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS, ScriptParamsConstants.SCRIPT_USER_PARAMS) - .addValidate(Validate.newBuilder() - .setRequired(false) - .build()) - .setPlaceholder("please enter your custom parameters, which will be passed to you when calling your script") - .build(); + .addValidate(Validate.newBuilder() + .setRequired(false) + .build()) + .setPlaceholder("please enter your custom parameters, which will be passed to you when calling your script") + .build(); // need check file type and file exist InputParam scriptPathParam = InputParam.newBuilder(ScriptParamsConstants.NAME_SCRIPT_PATH, ScriptParamsConstants.SCRIPT_PATH) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .setPlaceholder("please upload the file to the disk directory of the alert server, and ensure that the path is absolute and has the corresponding access rights") - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .setPlaceholder("please upload the file to the disk directory of the alert server," + + " and ensure that the path is absolute and has the corresponding access rights") + .build(); RadioParam scriptTypeParams = RadioParam.newBuilder(ScriptParamsConstants.NAME_SCRIPT_TYPE, ScriptParamsConstants.SCRIPT_TYPE) - .addParamsOptions(new ParamsOptions(ScriptType.SHELL.getDescp(), ScriptType.SHELL.getDescp(), false)) - .setValue(ScriptType.SHELL.getDescp()) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .addParamsOptions(new ParamsOptions(ScriptType.SHELL.getDescp(), ScriptType.SHELL.getDescp(), false)) + .setValue(ScriptType.SHELL.getDescp()) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); return Arrays.asList(scriptUserParam, scriptPathParam, scriptTypeParams); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java similarity index 89% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java index 7552036f42..e680903fb2 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java @@ -17,15 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.script; -/** - * ScriptParamsConstants - */ -public class ScriptParamsConstants { - - private ScriptParamsConstants() { - throw new IllegalStateException("Utility class"); - } - +public final class ScriptParamsConstants { static final String SCRIPT_TYPE = "$t('scriptType')"; static final String NAME_SCRIPT_TYPE = "type"; @@ -37,4 +29,8 @@ public class ScriptParamsConstants { static final String SCRIPT_USER_PARAMS = "$t('userParams')"; static final String NAME_SCRIPT_USER_PARAMS = "userParams"; + + private ScriptParamsConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java similarity index 86% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java index 8e33b792d8..a4dbe1eabc 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -17,31 +17,20 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * ScriptSender - */ -public class ScriptSender { - - private static final Logger logger = LoggerFactory.getLogger(ScriptSender.class); - - private String scriptPath; - - private String scriptType; - - private String userParams; +public final class ScriptSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ScriptSender.class); private static final String ALERT_TITLE_OPTION = " -t "; - private static final String ALERT_CONTENT_OPTION = " -c "; - private static final String ALERT_USER_PARAMS_OPTION = " -p "; + private final String scriptPath; + private final String scriptType; + private final String userParams; ScriptSender(Map config) { scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH); @@ -73,7 +62,7 @@ public class ScriptSender { return alertResult; } alertResult.setMessage("send script alert msg error,exitCode is " + exitCode); - logger.info("send script alert msg error,exitCode is {}", exitCode); + log.info("send script alert msg error,exitCode is {}", exitCode); return alertResult; } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java similarity index 94% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java index ff3b8096bb..cbb3e11f28 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java @@ -17,26 +17,17 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import java.util.HashMap; -import java.util.Map; - -/** - * ScriptType - */ public enum ScriptType { - - SHELL(0, "SHELL"), ; + private final int code; + private final String descp; ScriptType(int code, String descp) { this.code = code; this.descp = descp; } - private final int code; - private final String descp; - public int getCode() { return code; } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java similarity index 81% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java index 41aabfe13d..6b1d19a072 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java @@ -23,16 +23,11 @@ import java.io.InputStream; import java.io.InputStreamReader; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * StreamGobbler - */ -public class StreamGobbler extends Thread { - - private static final Logger logger = LoggerFactory.getLogger(StreamGobbler.class); +public final class StreamGobbler extends Thread { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(StreamGobbler.class); - private InputStream inputStream; + private final InputStream inputStream; StreamGobbler(InputStream inputStream) { this.inputStream = inputStream; @@ -51,16 +46,16 @@ public class StreamGobbler extends Thread { output.append(System.getProperty("line.separator")); } if (output.length() > 0) { - logger.info("out put msg is{}", output); + log.info("out put msg is{}", output); } } catch (IOException e) { - logger.error("I/O error occurs {}", e.getMessage()); + log.error("I/O error occurs {}", e.getMessage()); } finally { try { inputBufferReader.close(); inputStreamReader.close(); } catch (IOException e) { - logger.error("I/O error occurs {}", e.getMessage()); + log.error("I/O error occurs {}", e.getMessage()); } } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java similarity index 93% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java index 1d847a0635..7ee473e9a7 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java @@ -26,7 +26,7 @@ public class ProcessUtilsTest { private static final String rootPath = System.getProperty("user.dir"); - private static final String shellFilPath = rootPath + "/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/test.sh"; + private static final String shellFilPath = rootPath + "/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/test.sh"; private String[] cmd = {"/bin/sh", "-c", shellFilPath + " -t 1"}; diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java similarity index 91% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java index 8cedc2c38e..ca45cf7aed 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import java.util.List; @@ -33,7 +33,7 @@ public class ScriptAlertChannelFactoryTest { @Test public void testGetParams() { ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); - List params = scriptAlertChannelFactory.getParams(); + List params = scriptAlertChannelFactory.params(); Assert.assertEquals(3, params.size()); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java similarity index 97% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java index e022b9ebf7..445d0738b5 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.HashMap; import java.util.Map; @@ -31,11 +31,9 @@ import org.junit.Test; */ public class ScriptSenderTest { - private static Map scriptConfig = new HashMap<>(); - private static final String rootPath = System.getProperty("user.dir"); - private static final String shellFilPath = rootPath + "/src/test/script/shell/scriptExample.sh"; + private static Map scriptConfig = new HashMap<>(); @Before public void initScriptConfig() { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh similarity index 100% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/test.sh b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/test.sh similarity index 100% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/test.sh rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/test.sh diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/pom.xml new file mode 100644 index 0000000000..ded01e7251 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/pom.xml @@ -0,0 +1,41 @@ + + + + + dolphinscheduler-alert-plugins + org.apache.dolphinscheduler + 2.0.0-SNAPSHOT + + 4.0.0 + dolphinscheduler-alert-slack + jar + + + + org.apache.httpcomponents + httpclient + + + + com.google.guava + guava + + + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java similarity index 82% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java index 6399d8bca9..b63fed0574 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannel.java @@ -17,18 +17,14 @@ package org.apache.dolphinscheduler.plugin.alert.slack; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; -/** - * SlackAlertChannel - */ -public class SlackAlertChannel implements AlertChannel { - +public final class SlackAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo alertInfo) { AlertData alertData = alertInfo.getAlertData(); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java similarity index 61% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java index d56976400a..9819ed4b33 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactory.java @@ -17,42 +17,41 @@ package org.apache.dolphinscheduler.plugin.alert.slack; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; import java.util.LinkedList; import java.util.List; -/** - * Slack alert factory, see {@link AlertChannelFactory} - */ -public class SlackAlertChannelFactory implements AlertChannelFactory { +import com.google.auto.service.AutoService; +@AutoService(AlertChannelFactory.class) +public final class SlackAlertChannelFactory implements AlertChannelFactory { @Override - public String getName() { + public String name() { return "Slack"; } @Override - public List getParams() { + public List params() { List paramsList = new LinkedList<>(); InputParam webHookParam = InputParam.newBuilder(SlackParamsConstants.SLACK_WEN_HOOK_URL_NAME, SlackParamsConstants.SLACK_WEB_HOOK_URL) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .setPlaceholder("Input WebHook Url") - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .setPlaceholder("Input WebHook Url") + .build(); InputParam botName = InputParam.newBuilder(SlackParamsConstants.SLACK_BOT_NAME, SlackParamsConstants.SLACK_BOT) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .setPlaceholder("Input the bot username") - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .setPlaceholder("Input the bot username") + .build(); paramsList.add(webHookParam); paramsList.add(botName); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java similarity index 90% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java index d0ec160c08..928eba6719 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackParamsConstants.java @@ -17,12 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.slack; -public class SlackParamsConstants { - - private SlackParamsConstants() { - - } - +public final class SlackParamsConstants { public static final String SLACK_WEB_HOOK_URL = "$t('webhook')"; public static final String SLACK_WEN_HOOK_URL_NAME = "webHook"; public static final String SLACK_BOT = "$t('Username')"; @@ -31,4 +26,8 @@ public class SlackParamsConstants { public static final String ATTACHMENT = "attachments"; public static final Integer MAX_SHOW_NUMBER = 100; + + private SlackParamsConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java similarity index 88% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java index 21a8286211..579fbaa05c 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/main/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSender.java @@ -39,17 +39,14 @@ import java.util.Objects; import java.util.stream.Collectors; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; -public class SlackSender { +public final class SlackSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(SlackSender.class); - private static final Logger logger = LoggerFactory.getLogger(SlackSender.class); - - private String webHookUrl; - - private String botName; + private final String webHookUrl; + private final String botName; public SlackSender(Map slackAlertParam) { webHookUrl = slackAlertParam.get(SlackParamsConstants.SLACK_WEN_HOOK_URL_NAME); @@ -86,7 +83,7 @@ public class SlackSender { HttpEntity entity = response.getEntity(); return EntityUtils.toString(entity, "UTF-8"); } catch (Exception e) { - logger.error("Send message to slack error.", e); + log.error("Send message to slack error.", e); return "System Exception"; } } @@ -122,17 +119,17 @@ public class SlackSender { final int elementLen = maxLen; StringBuilder stringBuilder = new StringBuilder(200); stringBuilder.append(headers.stream() - .map(header -> generateString(header, elementLen, " ")) - .collect(Collectors.joining("|"))); + .map(header -> generateString(header, elementLen, " ")) + .collect(Collectors.joining("|"))); stringBuilder.append("\n"); for (List element : elements) { stringBuilder.append(element.stream() - .map(lement -> generateString("", elementLen, "-")) - .collect(Collectors.joining("|"))); + .map(lement -> generateString("", elementLen, "-")) + .collect(Collectors.joining("|"))); stringBuilder.append("\n"); stringBuilder.append(element.stream() - .map(e -> generateString(e, elementLen, " ")) - .collect(Collectors.joining("|"))); + .map(e -> generateString(e, elementLen, " ")) + .collect(Collectors.joining("|"))); stringBuilder.append("\n"); } return String.format("```%s```", stringBuilder); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java similarity index 87% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java index e294365da7..21ba907ee7 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackAlertChannelFactoryTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.slack; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import java.util.List; @@ -31,12 +31,12 @@ public class SlackAlertChannelFactoryTest { @Test public void testTestGetName() { - Assert.assertEquals("Slack", slackAlertChannelFactory.getName()); + Assert.assertEquals("Slack", slackAlertChannelFactory.name()); } @Test public void testGetParams() { - List params = slackAlertChannelFactory.getParams(); + List params = slackAlertChannelFactory.params(); Assert.assertEquals(2, params.size()); } @@ -45,4 +45,4 @@ public class SlackAlertChannelFactoryTest { AlertChannel alertChannel = slackAlertChannelFactory.create(); Assert.assertTrue(alertChannel instanceof SlackAlertChannel); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java similarity index 95% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java index a488026b42..c675aca0e8 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-slack/src/test/java/org/apache/dolphinscheduler/plugin/alert/slack/SlackSenderTest.java @@ -29,11 +29,11 @@ public class SlackSenderTest { public void testSendMessage() { Map alertparam = new HashMap<>(); alertparam.put(SlackParamsConstants.SLACK_WEN_HOOK_URL_NAME, - "https://hooks.slack.com/services/123456"); + "https://hooks.slack.com/services/123456"); alertparam.put(SlackParamsConstants.SLACK_BOT_NAME, "Dolphinscheduler"); SlackSender slackSender = new SlackSender(alertparam); String response = slackSender.sendMessage("test title", "test content"); Assert.assertNotEquals("ok", response); } -} \ No newline at end of file +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/pom.xml similarity index 64% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/pom.xml index 0c0eaac7b9..9755bbb216 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/pom.xml @@ -15,20 +15,19 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - dolphinscheduler-alert-plugin + dolphinscheduler-alert-plugins org.apache.dolphinscheduler 2.0.0-SNAPSHOT 4.0.0 + dolphinscheduler-alert-wechat + jar - dolphinscheduler-alert-http - dolphinscheduler-plugin - com.google.guava guava @@ -49,30 +48,5 @@ jackson-databind provided - - - junit - junit - test - - - - org.mockito - mockito-core - jar - test - - - - org.jacoco - org.jacoco.agent - runtime - test - - - - dolphinscheduler-alert-http-${project.version} - - - \ No newline at end of file + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java similarity index 80% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java index 36cce09ff3..94b43ea300 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java @@ -17,18 +17,14 @@ package org.apache.dolphinscheduler.plugin.alert.wechat; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import java.util.Map; -/** - * WeChatAlertChannel - */ -public class WeChatAlertChannel implements AlertChannel { - +public final class WeChatAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo info) { AlertData alertData = info.getAlertData(); diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java new file mode 100644 index 0000000000..299ffdd310 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.alert.wechat; + +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.ShowType; +import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; + +import java.util.Arrays; +import java.util.List; + +import com.google.auto.service.AutoService; + +@AutoService(AlertChannelFactory.class) +public final class WeChatAlertChannelFactory implements AlertChannelFactory { + @Override + public String name() { + return "WeChat"; + } + + @Override + public List params() { + InputParam corpIdParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_CORP_ID, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_CORP_ID) + .setPlaceholder("please input corp id ") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam secretParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_SECRET) + .setPlaceholder("please input secret ") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam usersParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USERS, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_USERS) + .setPlaceholder("please input users ") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam userSendMsgParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_USER_SEND_MSG) + .setPlaceholder("please input corp id ") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam agentIdParam = InputParam.newBuilder(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_AGENT_ID, WeChatAlertParamsConstants.ENTERPRISE_WE_CHAT_AGENT_ID) + .setPlaceholder("please input agent id ") + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, AlertConstants.SHOW_TYPE) + .addParamsOptions(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false)) + .addParamsOptions(new ParamsOptions(ShowType.TEXT.getDescp(), ShowType.TEXT.getDescp(), false)) + .setValue(ShowType.TABLE.getDescp()) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + return Arrays.asList(corpIdParam, secretParam, usersParam, userSendMsgParam, agentIdParam, showType); + } + + @Override + public AlertChannel create() { + return new WeChatAlertChannel(); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java similarity index 89% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java index 9aec21b9d9..141542fa7f 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java @@ -17,15 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.wechat; -/** - * WeChatAlertConstants - */ -public class WeChatAlertConstants { - - private WeChatAlertConstants() { - throw new IllegalStateException(WeChatAlertConstants.class.getName()); - } - +public final class WeChatAlertConstants { static final String MARKDOWN_QUOTE = ">"; static final String MARKDOWN_ENTER = "\n"; @@ -35,4 +27,8 @@ public class WeChatAlertConstants { static final String WE_CHAT_PUSH_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}"; static final String WE_CHAT_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpId}&corpsecret={secret}"; + + private WeChatAlertConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java similarity index 90% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java index 17bc7830d7..e4c63813ae 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java @@ -17,43 +17,21 @@ package org.apache.dolphinscheduler.plugin.alert.wechat; -/** - * WeChatAlertParamsConstants - */ -public class WeChatAlertParamsConstants { - - private WeChatAlertParamsConstants() { - throw new IllegalStateException(WeChatAlertParamsConstants.class.getName()); - } - +public final class WeChatAlertParamsConstants { static final String ENTERPRISE_WE_CHAT_CORP_ID = "$t('corpId')"; - static final String NAME_ENTERPRISE_WE_CHAT_CORP_ID = "corpId"; - - static final String ENTERPRISE_WE_CHAT_SECRET = "$t('secret')"; - static final String NAME_ENTERPRISE_WE_CHAT_SECRET = "secret"; - static final String ENTERPRISE_WE_CHAT_TEAM_SEND_MSG = "$t('teamSendMsg')"; - static final String NAME_ENTERPRISE_WE_CHAT_TEAM_SEND_MSG = "teamSendMsg"; - - static final String ENTERPRISE_WE_CHAT_USER_SEND_MSG = "$t('userSendMsg')"; - static final String NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG = "userSendMsg"; - - static final String ENTERPRISE_WE_CHAT_AGENT_ID = "$t('agentId')"; - static final String NAME_ENTERPRISE_WE_CHAT_AGENT_ID = "agentId"; - - static final String ENTERPRISE_WE_CHAT_USERS = "$t('users')"; - - static final String NAME_ENTERPRISE_WE_CHAT_USERS = "users"; - + private WeChatAlertParamsConstants() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java similarity index 79% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java index 7499b004d4..76b23eaee3 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java @@ -19,10 +19,9 @@ package org.apache.dolphinscheduler.plugin.alert.wechat; import static java.util.Objects.requireNonNull; -import org.apache.dolphinscheduler.plugin.alert.wechat.exception.WeChatAlertException; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.AlertResult; -import org.apache.dolphinscheduler.spi.alert.ShowType; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.AlertResult; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.spi.utils.JSONUtils; import org.apache.dolphinscheduler.spi.utils.StringUtils; @@ -47,28 +46,9 @@ import java.util.Map.Entry; import java.util.Set; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * WeChatSender - */ -public class WeChatSender { - - private static Logger logger = LoggerFactory.getLogger(WeChatSender.class); - - private String weChatAgentId; - - private String weChatUsers; - - private String weChatUserSendMsg; - - private String weChatTokenUrlReplace; - - private String weChatToken; - - private String showType; - +public final class WeChatSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(WeChatSender.class); private static final String MUST_NOT_NULL = " must not null"; private static final String ALERT_STATUS = "false"; private static final String AGENT_ID_REG_EXP = "{agentId}"; @@ -77,6 +57,12 @@ public class WeChatSender { private static final String CORP_ID_REGEX = "{corpId}"; private static final String SECRET_REGEX = "{secret}"; private static final String TOKEN_REGEX = "{token}"; + private final String weChatAgentId; + private final String weChatUsers; + private final String weChatUserSendMsg; + private final String weChatTokenUrlReplace; + private final String weChatToken; + private final String showType; WeChatSender(Map config) { weChatAgentId = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_AGENT_ID); @@ -93,50 +79,6 @@ public class WeChatSender { weChatToken = getToken(); } - /** - * make user multi user message - * - * @param toUser the toUser - * @param agentId the agentId - * @param msg the msg - * @return Enterprise WeChat send message - */ - private String makeUserSendMsg(Collection toUser, String agentId, String msg) { - String listUser = mkString(toUser); - return weChatUserSendMsg.replace(USER_REG_EXP, listUser) - .replace(AGENT_ID_REG_EXP, agentId) - .replace(MSG_REG_EXP, msg); - } - - /** - * send Enterprise WeChat - * - * @return Enterprise WeChat resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""} - */ - public AlertResult sendEnterpriseWeChat(String title, String content) { - AlertResult alertResult; - List userList = Arrays.asList(weChatUsers.split(",")); - String data = markdownByAlert(title, content); - String msg = makeUserSendMsg(userList, weChatAgentId, data); - if (null == weChatToken) { - alertResult = new AlertResult(); - alertResult.setMessage("send we chat alert fail,get weChat token error"); - alertResult.setStatus(ALERT_STATUS); - return alertResult; - } - String enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken); - - try { - return checkWeChatSendMsgResult(post(enterpriseWeChatPushUrlReplace, msg)); - } catch (Exception e) { - logger.info("send we chat alert msg exception : {}", e.getMessage()); - alertResult = new AlertResult(); - alertResult.setMessage("send we chat alert fail"); - alertResult.setStatus(ALERT_STATUS); - } - return alertResult; - } - private static String post(String url, String data) throws IOException { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(url); @@ -150,7 +92,7 @@ public class WeChatSender { } finally { response.close(); } - logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", + log.info("Enterprise WeChat send [{}], param:{}, resp:{}", url, data, resp); return resp; } @@ -166,8 +108,8 @@ public class WeChatSender { private static String markdownTable(String title, String content) { List mapItemsList = JSONUtils.toList(content, LinkedHashMap.class); if (null == mapItemsList || mapItemsList.isEmpty()) { - logger.error("itemsList is null"); - throw new WeChatAlertException("itemsList is null"); + log.error("itemsList is null"); + throw new RuntimeException("itemsList is null"); } StringBuilder contents = new StringBuilder(200); for (LinkedHashMap mapItems : mapItemsList) { @@ -199,7 +141,7 @@ public class WeChatSender { if (StringUtils.isNotEmpty(content)) { List mapItemsList = JSONUtils.toList(content, LinkedHashMap.class); if (null == mapItemsList || mapItemsList.isEmpty()) { - logger.error("itemsList is null"); + log.error("itemsList is null"); throw new RuntimeException("itemsList is null"); } @@ -220,31 +162,6 @@ public class WeChatSender { return null; } - /** - * Determine the mardown style based on the show type of the alert - * - * @return the markdown alert table/text - */ - private String markdownByAlert(String title, String content) { - String result = ""; - if (showType.equals(ShowType.TABLE.getDescp())) { - result = markdownTable(title, content); - } else if (showType.equals(ShowType.TEXT.getDescp())) { - result = markdownText(title, content); - } - return result; - - } - - private String getToken() { - try { - return get(weChatTokenUrlReplace); - } catch (IOException e) { - logger.info("we chat alert get token error{}", e.getMessage()); - } - return null; - } - private static String get(String url) throws IOException { String resp; @@ -266,7 +183,6 @@ public class WeChatSender { } private static String mkString(Iterable list) { - if (null == list || StringUtils.isEmpty("|")) { return null; } @@ -284,40 +200,19 @@ public class WeChatSender { return sb.toString(); } - public static class WeChatSendMsgResponse { - private Integer errcode; - private String errmsg; - - public Integer getErrcode() { - return errcode; - } - - public void setErrcode(Integer errcode) { - this.errcode = errcode; - } - - public String getErrmsg() { - return errmsg; - } - - public void setErrmsg(String errmsg) { - this.errmsg = errmsg; - } - } - private static AlertResult checkWeChatSendMsgResult(String result) { AlertResult alertResult = new AlertResult(); alertResult.setStatus(ALERT_STATUS); if (null == result) { alertResult.setMessage("we chat send fail"); - logger.info("send we chat msg error,resp is null"); + log.info("send we chat msg error,resp is null"); return alertResult; } WeChatSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, WeChatSendMsgResponse.class); if (null == sendMsgResponse) { alertResult.setMessage("we chat send fail"); - logger.info("send we chat msg error,resp error"); + log.info("send we chat msg error,resp error"); return alertResult; } if (sendMsgResponse.errcode == 0) { @@ -329,4 +224,132 @@ public class WeChatSender { alertResult.setMessage(sendMsgResponse.getErrmsg()); return alertResult; } + + /** + * make user multi user message + * + * @param toUser the toUser + * @param agentId the agentId + * @param msg the msg + * @return Enterprise WeChat send message + */ + private String makeUserSendMsg(Collection toUser, String agentId, String msg) { + String listUser = mkString(toUser); + return weChatUserSendMsg.replace(USER_REG_EXP, listUser) + .replace(AGENT_ID_REG_EXP, agentId) + .replace(MSG_REG_EXP, msg); + } + + /** + * send Enterprise WeChat + * + * @return Enterprise WeChat resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""} + */ + public AlertResult sendEnterpriseWeChat(String title, String content) { + AlertResult alertResult; + List userList = Arrays.asList(weChatUsers.split(",")); + String data = markdownByAlert(title, content); + String msg = makeUserSendMsg(userList, weChatAgentId, data); + if (null == weChatToken) { + alertResult = new AlertResult(); + alertResult.setMessage("send we chat alert fail,get weChat token error"); + alertResult.setStatus(ALERT_STATUS); + return alertResult; + } + String enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken); + + try { + return checkWeChatSendMsgResult(post(enterpriseWeChatPushUrlReplace, msg)); + } catch (Exception e) { + log.info("send we chat alert msg exception : {}", e.getMessage()); + alertResult = new AlertResult(); + alertResult.setMessage("send we chat alert fail"); + alertResult.setStatus(ALERT_STATUS); + } + return alertResult; + } + + /** + * Determine the mardown style based on the show type of the alert + * + * @return the markdown alert table/text + */ + private String markdownByAlert(String title, String content) { + String result = ""; + if (showType.equals(ShowType.TABLE.getDescp())) { + result = markdownTable(title, content); + } else if (showType.equals(ShowType.TEXT.getDescp())) { + result = markdownText(title, content); + } + return result; + + } + + private String getToken() { + try { + return get(weChatTokenUrlReplace); + } catch (IOException e) { + log.info("we chat alert get token error{}", e.getMessage()); + } + return null; + } + + static final class WeChatSendMsgResponse { + private Integer errcode; + private String errmsg; + + public WeChatSendMsgResponse() { + } + + public Integer getErrcode() { + return this.errcode; + } + + public void setErrcode(Integer errcode) { + this.errcode = errcode; + } + + public String getErrmsg() { + return this.errmsg; + } + + public void setErrmsg(String errmsg) { + this.errmsg = errmsg; + } + + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof WeChatSendMsgResponse)) { + return false; + } + final WeChatSendMsgResponse other = (WeChatSendMsgResponse) o; + final Object this$errcode = this.getErrcode(); + final Object other$errcode = other.getErrcode(); + if (this$errcode == null ? other$errcode != null : !this$errcode.equals(other$errcode)) { + return false; + } + final Object this$errmsg = this.getErrmsg(); + final Object other$errmsg = other.getErrmsg(); + if (this$errmsg == null ? other$errmsg != null : !this$errmsg.equals(other$errmsg)) { + return false; + } + return true; + } + + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $errcode = this.getErrcode(); + result = result * PRIME + ($errcode == null ? 43 : $errcode.hashCode()); + final Object $errmsg = this.getErrmsg(); + result = result * PRIME + ($errmsg == null ? 43 : $errmsg.hashCode()); + return result; + } + + public String toString() { + return "WeChatSender.WeChatSendMsgResponse(errcode=" + this.getErrcode() + ", errmsg=" + this.getErrmsg() + ")"; + } + } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java similarity index 92% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java index cc62d5aabf..04ecc36482 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.alert.wechat; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.utils.JSONUtils; @@ -34,7 +34,7 @@ public class WeChatAlertChannelFactoryTest { @Test public void testGetParams() { WeChatAlertChannelFactory weChatAlertChannelFactory = new WeChatAlertChannelFactory(); - List params = weChatAlertChannelFactory.getParams(); + List params = weChatAlertChannelFactory.params(); JSONUtils.toJsonString(params); Assert.assertEquals(6, params.size()); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java similarity index 77% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java index 79e76ffab3..73d889b652 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java @@ -17,9 +17,9 @@ package org.apache.dolphinscheduler.plugin.alert.wechat; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.AlertResult; -import org.apache.dolphinscheduler.spi.alert.ShowType; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.AlertResult; +import org.apache.dolphinscheduler.alert.api.ShowType; import java.util.HashMap; import java.util.Map; @@ -36,24 +36,24 @@ public class WeChatSenderTest { private static Map weChatConfig = new HashMap<>(); private String content = "[{\"id\":\"69\"," - + - "\"name\":\"UserBehavior-0--1193959466\"," - + - "\"Job name\":\"Start workflow\"," - + - "\"State\":\"SUCCESS\"," - + - "\"Recovery\":\"NO\"," - + - "\"Run time\":\"1\"," - + - "\"Start time\": \"2018-08-06 10:31:34.0\"," - + - "\"End time\": \"2018-08-06 10:31:49.0\"," - + - "\"Host\": \"192.168.xx.xx\"," - + - "\"Notify group\" :\"4\"}]"; + + + "\"name\":\"UserBehavior-0--1193959466\"," + + + "\"Job name\":\"Start workflow\"," + + + "\"State\":\"SUCCESS\"," + + + "\"Recovery\":\"NO\"," + + + "\"Run time\":\"1\"," + + + "\"Start time\": \"2018-08-06 10:31:34.0\"," + + + "\"End time\": \"2018-08-06 10:31:49.0\"," + + + "\"Host\": \"192.168.xx.xx\"," + + + "\"Notify group\" :\"4\"}]"; @Before public void initDingTalkConfig() { @@ -62,8 +62,8 @@ public class WeChatSenderTest { weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_CORP_ID, "NAME_ENTERPRISE_WE_CHAT_CORP_ID"); weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET, "NAME_ENTERPRISE_WE_CHAT_SECRET"); weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG, "{\"touser\":\"{toUser}\",\"agentid\":{agentId}" - + - ",\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"{msg}\"}}" + + + ",\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"{msg}\"}}" ); weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USERS, "Kris"); weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_TEAM_SEND_MSG, "msg"); diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml similarity index 80% rename from dolphinscheduler-alert-plugin/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml index f5dc77b04f..d1e4ec0357 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml @@ -15,18 +15,16 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - dolphinscheduler + dolphinscheduler-alert org.apache.dolphinscheduler 2.0.0-SNAPSHOT 4.0.0 - - org.apache.dolphinscheduler - dolphinscheduler-alert-plugin + dolphinscheduler-alert-plugins pom @@ -40,12 +38,10 @@ - org.apache.dolphinscheduler - dolphinscheduler-spi - provided + dolphinscheduler-alert-api - \ No newline at end of file + diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml similarity index 51% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml index 9c2347ec25..4173d0a1bd 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml @@ -15,103 +15,107 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - + 4.0.0 - dolphinscheduler-alert-plugin org.apache.dolphinscheduler + dolphinscheduler-alert 2.0.0-SNAPSHOT - 4.0.0 - - org.apache.dolphinscheduler - dolphinscheduler-alert-email - - dolphinscheduler-plugin + dolphinscheduler-alert-server + ${project.artifactId} + jar + - org.apache.commons - commons-collections4 + org.apache.dolphinscheduler + dolphinscheduler-remote - - org.apache.poi - poi + org.apache.dolphinscheduler + dolphinscheduler-alert-dingtalk - org.apache.poi - poi-ooxml + org.apache.dolphinscheduler + dolphinscheduler-alert-email - - com.google.guava - guava + org.apache.dolphinscheduler + dolphinscheduler-alert-feishu - - ch.qos.logback - logback-classic + org.apache.dolphinscheduler + dolphinscheduler-alert-http - - org.slf4j - slf4j-api + org.apache.dolphinscheduler + dolphinscheduler-alert-script - - org.apache.commons - commons-email + org.apache.dolphinscheduler + dolphinscheduler-alert-slack - - com.fasterxml.jackson.core - jackson-annotations - provided + org.apache.dolphinscheduler + dolphinscheduler-alert-wechat - junit - junit - test + org.apache.dolphinscheduler + dolphinscheduler-dao + + + log4j-api + org.apache.logging.log4j + + - org.mockito - mockito-core - jar - test + com.fasterxml.jackson.core + jackson-core - org.powermock - powermock-module-junit4 - test + com.fasterxml.jackson.core + jackson-databind - org.powermock - powermock-api-mockito2 - test + com.google.guava + guava - org.mockito - mockito-core + jsr305 + com.google.code.findbugs + + ch.qos.logback + logback-classic + + + + + org.apache.poi + poi + + + + org.mockito + mockito-core + test + - org.jacoco - org.jacoco.agent - runtime + org.mockito + mockito-inline test - - dolphinscheduler-alert-email-${project.version} - - diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java new file mode 100644 index 0000000000..ca882ca0e7 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.alert; + +import static java.lang.String.format; + +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; +import org.apache.dolphinscheduler.common.enums.PluginType; +import org.apache.dolphinscheduler.dao.PluginDao; +import org.apache.dolphinscheduler.dao.entity.PluginDefine; +import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public final class AlertPluginManager { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(AlertPluginManager.class); + + private final PluginDao pluginDao; + + private final Map channelKeyedById = new HashMap<>(); + + public AlertPluginManager(PluginDao pluginDao) { + this.pluginDao = pluginDao; + } + + @PostConstruct + public void installPlugin() { + final Set names = new HashSet<>(); + + ServiceLoader.load(AlertChannelFactory.class).forEach(factory -> { + final String name = factory.name(); + + log.info("Registering alert plugin: {}", name); + + if (!names.add(name)) { + throw new IllegalStateException(format("Duplicate alert plugins named '%s'", name)); + } + + final AlertChannel alertChannel = factory.create(); + + log.info("Registered alert plugin: {}", name); + + final List params = factory.params(); + final String paramsJson = PluginParamsTransfer.transferParamsToJson(params); + + final PluginDefine pluginDefine = new PluginDefine(name, PluginType.ALERT.getDesc(), paramsJson); + final int id = pluginDao.addOrUpdatePluginDefine(pluginDefine); + + channelKeyedById.put(id, alertChannel); + }); + } + + public Optional getAlertChannel(int id) { + return Optional.ofNullable(channelKeyedById.get(id)); + } + + public int size() { + return channelKeyedById.size(); + } +} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertRequestProcessor.java similarity index 56% rename from dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java rename to dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertRequestProcessor.java index 9421a97546..0db7f70af3 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertRequestProcessor.java @@ -15,11 +15,10 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.alert.processor; +package org.apache.dolphinscheduler.alert; + +import static com.google.common.base.Preconditions.checkArgument; -import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; -import org.apache.dolphinscheduler.alert.runner.AlertSender; -import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.CommandType; import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; @@ -28,35 +27,33 @@ import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor; import org.apache.dolphinscheduler.remote.utils.JsonSerializer; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Preconditions; +import org.springframework.stereotype.Component; import io.netty.channel.Channel; -public class AlertRequestProcessor implements NettyRequestProcessor { +@Component +public final class AlertRequestProcessor implements NettyRequestProcessor { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(AlertRequestProcessor.class); - private final Logger logger = LoggerFactory.getLogger(AlertRequestProcessor.class); - private final AlertDao alertDao; - private final AlertPluginManager alertPluginManager; + private final AlertSender alertSender; - public AlertRequestProcessor(AlertDao alertDao, AlertPluginManager alertPluginManager) { - this.alertDao = alertDao; - this.alertPluginManager = alertPluginManager; + public AlertRequestProcessor(AlertSender alertSender) { + this.alertSender = alertSender; } @Override public void process(Channel channel, Command command) { - Preconditions.checkArgument(CommandType.ALERT_SEND_REQUEST == command.getType(), - String.format("invalid command type : %s", command.getType())); + checkArgument(CommandType.ALERT_SEND_REQUEST == command.getType(), "invalid command type: %s", command.getType()); AlertSendRequestCommand alertSendRequestCommand = JsonSerializer.deserialize( - command.getBody(), AlertSendRequestCommand.class); - logger.info("received command : {}", alertSendRequestCommand); + command.getBody(), AlertSendRequestCommand.class); - AlertSender alertSender = new AlertSender(alertDao, alertPluginManager); - AlertSendResponseCommand alertSendResponseCommand = alertSender.syncHandler(alertSendRequestCommand.getGroupId(), alertSendRequestCommand.getTitle(), alertSendRequestCommand.getContent()); - channel.writeAndFlush(alertSendResponseCommand.convert2Command(command.getOpaque())); + log.info("Received command : {}", alertSendRequestCommand); + AlertSendResponseCommand alertSendResponseCommand = alertSender.syncHandler( + alertSendRequestCommand.getGroupId(), + alertSendRequestCommand.getTitle(), + alertSendRequestCommand.getContent()); + channel.writeAndFlush(alertSendResponseCommand.convert2Command(command.getOpaque())); } } diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSender.java similarity index 70% rename from dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java rename to dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSender.java index bc0b4ef032..ebc57e82bf 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSender.java @@ -15,9 +15,12 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.alert.runner; +package org.apache.dolphinscheduler.alert; -import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertData; +import org.apache.dolphinscheduler.alert.api.AlertInfo; +import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.AlertDao; @@ -25,67 +28,50 @@ import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertData; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; import org.apache.commons.collections.CollectionUtils; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; -public class AlertSender { +@Component +public final class AlertSender { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(AlertSender.class); - private static final Logger logger = LoggerFactory.getLogger(AlertSender.class); - - private List alertList; - private AlertDao alertDao; + private final AlertDao alertDao; private final AlertPluginManager alertPluginManager; - public AlertSender(AlertPluginManager alertPluginManager) { - this.alertPluginManager = alertPluginManager; - } - public AlertSender(AlertDao alertDao, AlertPluginManager alertPluginManager) { - super(); - this.alertDao = alertDao; - this.alertPluginManager = alertPluginManager; - } - - public AlertSender(List alertList, AlertDao alertDao, AlertPluginManager alertPluginManager) { - super(); - this.alertList = alertList; this.alertDao = alertDao; this.alertPluginManager = alertPluginManager; } - public void run() { - for (Alert alert : alertList) { + public void send(List alerts) { + for (Alert alert : alerts) { //get alert group from alert int alertGroupId = alert.getAlertGroupId(); List alertInstanceList = alertDao.listInstanceByAlertGroupId(alertGroupId); if (CollectionUtils.isEmpty(alertInstanceList)) { - logger.error("send alert msg fail,no bind plugin instance."); + log.error("send alert msg fail,no bind plugin instance."); alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, "no bind plugin instance", alert.getId()); continue; } AlertData alertData = new AlertData(); alertData.setId(alert.getId()) - .setContent(alert.getContent()) - .setLog(alert.getLog()) - .setTitle(alert.getTitle()); + .setContent(alert.getContent()) + .setLog(alert.getLog()) + .setTitle(alert.getTitle()); for (AlertPluginInstance instance : alertInstanceList) { AlertResult alertResult = this.alertResultHandler(instance, alertData); AlertStatus alertStatus = Boolean.parseBoolean(String.valueOf(alertResult.getStatus())) ? AlertStatus.EXECUTION_SUCCESS : AlertStatus.EXECUTION_FAILURE; alertDao.updateAlert(alertStatus, alertResult.getMessage(), alert.getId()); - } } @@ -100,30 +86,28 @@ public class AlertSender { * @return AlertSendResponseCommand */ public AlertSendResponseCommand syncHandler(int alertGroupId, String title, String content) { - List alertInstanceList = alertDao.listInstanceByAlertGroupId(alertGroupId); AlertData alertData = new AlertData(); alertData.setContent(content) - .setTitle(title); + .setTitle(title); boolean sendResponseStatus = true; List sendResponseResults = new ArrayList<>(); if (CollectionUtils.isEmpty(alertInstanceList)) { - sendResponseStatus = false; AlertSendResponseResult alertSendResponseResult = new AlertSendResponseResult(); String message = String.format("Alert GroupId %s send error : not found alert instance", alertGroupId); - alertSendResponseResult.setStatus(sendResponseStatus); + alertSendResponseResult.setStatus(false); alertSendResponseResult.setMessage(message); sendResponseResults.add(alertSendResponseResult); - logger.error("Alert GroupId {} send error : not found alert instance", alertGroupId); - return new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); + log.error("Alert GroupId {} send error : not found alert instance", alertGroupId); + return new AlertSendResponseCommand(false, sendResponseResults); } for (AlertPluginInstance instance : alertInstanceList) { AlertResult alertResult = this.alertResultHandler(instance, alertData); AlertSendResponseResult alertSendResponseResult = new AlertSendResponseResult( - Boolean.parseBoolean(String.valueOf(alertResult.getStatus())), alertResult.getMessage()); + Boolean.parseBoolean(String.valueOf(alertResult.getStatus())), alertResult.getMessage()); sendResponseStatus = sendResponseStatus && alertSendResponseResult.getStatus(); sendResponseResults.add(alertSendResponseResult); } @@ -139,15 +123,14 @@ public class AlertSender { * @return AlertResult */ private AlertResult alertResultHandler(AlertPluginInstance instance, AlertData alertData) { - String pluginName = alertPluginManager.getPluginNameById(instance.getPluginDefineId()); - AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); + Optional alertChannel = alertPluginManager.getAlertChannel(instance.getPluginDefineId()); AlertResult alertResultExtend = new AlertResult(); String pluginInstanceName = instance.getInstanceName(); - if (alertChannel == null) { + if (!alertChannel.isPresent()) { String message = String.format("Alert Plugin %s send error : return value is null", pluginInstanceName); alertResultExtend.setStatus(String.valueOf(false)); alertResultExtend.setMessage(message); - logger.error("Alert Plugin {} send error : not found plugin {}", pluginInstanceName, pluginName); + log.error("Alert Plugin {} send error : not found plugin {}", pluginInstanceName, instance.getPluginDefineId()); return alertResultExtend; } @@ -157,29 +140,27 @@ public class AlertSender { alertInfo.setAlertParams(paramsMap); AlertResult alertResult; try { - alertResult = alertChannel.process(alertInfo); + alertResult = alertChannel.get().process(alertInfo); } catch (Exception e) { alertResult = new AlertResult("false", e.getMessage()); - logger.error("send alert error alert data id :{},", alertData.getId(), e); + log.error("send alert error alert data id :{},", alertData.getId(), e); } - if (alertResult == null) { String message = String.format("Alert Plugin %s send error : return alertResult value is null", pluginInstanceName); alertResultExtend.setStatus(String.valueOf(false)); alertResultExtend.setMessage(message); - logger.info("Alert Plugin {} send error : return alertResult value is null", pluginInstanceName); + log.info("Alert Plugin {} send error : return alertResult value is null", pluginInstanceName); } else if (!Boolean.parseBoolean(String.valueOf(alertResult.getStatus()))) { alertResultExtend.setStatus(String.valueOf(false)); alertResultExtend.setMessage(alertResult.getMessage()); - logger.info("Alert Plugin {} send error : {}", pluginInstanceName, alertResult.getMessage()); + log.info("Alert Plugin {} send error : {}", pluginInstanceName, alertResult.getMessage()); } else { String message = String.format("Alert Plugin %s send success", pluginInstanceName); alertResultExtend.setStatus(String.valueOf(true)); alertResultExtend.setMessage(message); - logger.info("Alert Plugin {} send success", pluginInstanceName); + log.info("Alert Plugin {} send success", pluginInstanceName); } return alertResultExtend; } - } diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java new file mode 100644 index 0000000000..eb938767d8 --- /dev/null +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.alert; + +import static org.apache.dolphinscheduler.common.Constants.ALERT_RPC_PORT; + +import org.apache.dolphinscheduler.common.thread.Stopper; +import org.apache.dolphinscheduler.dao.AlertDao; +import org.apache.dolphinscheduler.dao.PluginDao; +import org.apache.dolphinscheduler.dao.entity.Alert; +import org.apache.dolphinscheduler.remote.NettyRemotingServer; +import org.apache.dolphinscheduler.remote.command.CommandType; +import org.apache.dolphinscheduler.remote.config.NettyServerConfig; + +import java.io.Closeable; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(value = { + "org.apache.dolphinscheduler.alert", + "org.apache.dolphinscheduler.dao" +}) +public class AlertServer implements Closeable { + private static final Logger log = LoggerFactory.getLogger(AlertServer.class); + + private final PluginDao pluginDao; + private final AlertDao alertDao; + private final AlertPluginManager alertPluginManager; + private final AlertSender alertSender; + private final AlertRequestProcessor alertRequestProcessor; + + private NettyRemotingServer server; + + public AlertServer(PluginDao pluginDao, AlertDao alertDao, AlertPluginManager alertPluginManager, AlertSender alertSender, AlertRequestProcessor alertRequestProcessor) { + this.pluginDao = pluginDao; + this.alertDao = alertDao; + this.alertPluginManager = alertPluginManager; + this.alertSender = alertSender; + this.alertRequestProcessor = alertRequestProcessor; + } + + public static void main(String[] args) { + SpringApplication.run(AlertServer.class, args); + } + + @PostConstruct + public void start() { + log.info("Starting Alert server"); + + checkTable(); + startServer(); + + if (alertPluginManager.size() == 0) { + log.warn("No alert plugin, alert sender will exit."); + return; + } + + Executors.newScheduledThreadPool(1) + .scheduleAtFixedRate(new Sender(), 5, 5, TimeUnit.SECONDS); + } + + @Override + @PreDestroy + public void close() { + server.close(); + } + + private void checkTable() { + if (!pluginDao.checkPluginDefineTableExist()) { + log.error("Plugin Define Table t_ds_plugin_define Not Exist . Please Create it First !"); + System.exit(1); + } + } + + private void startServer() { + NettyServerConfig serverConfig = new NettyServerConfig(); + serverConfig.setListenPort(ALERT_RPC_PORT); + + server = new NettyRemotingServer(serverConfig); + server.registerProcessor(CommandType.ALERT_SEND_REQUEST, alertRequestProcessor); + server.start(); + } + + final class Sender implements Runnable { + @Override + public void run() { + if (!Stopper.isRunning()) { + return; + } + + try { + final List alerts = alertDao.listPendingAlerts(); + alertSender.send(alerts); + } catch (Exception e) { + log.error("Failed to send alert", e); + } + } + } +} diff --git a/dolphinscheduler-alert/src/main/resources/logback-alert.xml b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/resources/logback-alert.xml similarity index 95% rename from dolphinscheduler-alert/src/main/resources/logback-alert.xml rename to dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/resources/logback-alert.xml index 1718947dd1..48b3c35bff 100644 --- a/dolphinscheduler-alert/src/main/resources/logback-alert.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/resources/logback-alert.xml @@ -17,7 +17,7 @@ --> - + @@ -49,4 +49,4 @@ - \ No newline at end of file + diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java similarity index 63% rename from dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java index 285b1132ab..fb3a48d820 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java @@ -17,12 +17,14 @@ package org.apache.dolphinscheduler.alert.plugin; +import org.apache.dolphinscheduler.alert.AlertPluginManager; +import org.apache.dolphinscheduler.alert.AlertSender; import org.apache.dolphinscheduler.alert.AlertServer; -import org.apache.dolphinscheduler.alert.runner.AlertSender; -import org.apache.dolphinscheduler.alert.utils.Constants; +import org.apache.dolphinscheduler.alert.api.AlertConstants; +import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.common.enums.AlertStatus; +import org.apache.dolphinscheduler.common.enums.ProfileType; import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.DaoFactory; import org.apache.dolphinscheduler.dao.PluginDao; @@ -30,19 +32,14 @@ import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; import org.apache.dolphinscheduler.dao.entity.PluginDefine; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.ShowType; -import org.apache.dolphinscheduler.spi.params.input.InputParam; import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; -import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import org.apache.dolphinscheduler.spi.params.base.DataType; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.params.base.Validate; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; -import org.apache.dolphinscheduler.spi.utils.StringUtils; +import org.apache.dolphinscheduler.spi.params.input.InputParam; +import org.apache.dolphinscheduler.spi.params.radio.RadioParam; import java.util.ArrayList; import java.util.Date; @@ -53,16 +50,24 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; - -import com.google.common.collect.ImmutableList; - -/** - * test load and use alert plugin - */ +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@ActiveProfiles(ProfileType.H2) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AlertServer.class) public class EmailAlertPluginTest { - + @Autowired private AlertDao alertDao; + @Autowired private PluginDao pluginDao; + @Autowired + private AlertPluginManager manager; + @Autowired + private AlertSender alertSender; @BeforeClass public static void setUpClass() { @@ -77,7 +82,6 @@ public class EmailAlertPluginTest { @Test public void testRunSend() { - //create alert group AlertGroup alertGroup = new AlertGroup(); alertGroup.setDescription("test alert group 1"); @@ -115,26 +119,6 @@ public class EmailAlertPluginTest { List alertList = new ArrayList<>(); alertList.add(alert1); - //load email alert plugin - AlertPluginManager alertPluginManager = new AlertPluginManager(); - DolphinPluginManagerConfig alertPluginManagerConfig = new DolphinPluginManagerConfig(); - String path = DolphinPluginLoader.class.getClassLoader().getResource("").getPath(); - alertPluginManagerConfig.setPlugins(path + "../../../dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml"); - if (StringUtils.isNotBlank(PropertyUtils.getString(AlertServer.ALERT_PLUGIN_DIR))) { - alertPluginManagerConfig.setInstalledPluginsDir(PropertyUtils.getString(AlertServer.ALERT_PLUGIN_DIR, Constants.ALERT_PLUGIN_PATH).trim()); - } - - if (StringUtils.isNotBlank(PropertyUtils.getString(AlertServer.MAVEN_LOCAL_REPOSITORY))) { - alertPluginManagerConfig.setMavenLocalRepository(PropertyUtils.getString(AlertServer.MAVEN_LOCAL_REPOSITORY).trim()); - } - - DolphinPluginLoader alertPluginLoader = new DolphinPluginLoader(alertPluginManagerConfig, ImmutableList.of(alertPluginManager)); - try { - alertPluginLoader.loadPlugins(); - } catch (Exception e) { - throw new RuntimeException("load Alert Plugin Failed !", e); - } - //create email alert plugin instance AlertPluginInstance alertPluginInstance = new AlertPluginInstance(); alertPluginInstance.setCreateTime(new Date()); @@ -149,8 +133,7 @@ public class EmailAlertPluginTest { alertPluginInstance.setPluginInstanceParams(getEmailAlertParams()); alertDao.getAlertPluginInstanceMapper().insert(alertPluginInstance); - AlertSender alertSender = new AlertSender(alertList, alertDao, alertPluginManager); - alertSender.run(); + alertSender.send(alertList); Alert alertResult = alertDao.getAlertMapper().selectById(alert1.getId()); Assert.assertNotNull(alertResult); @@ -166,63 +149,63 @@ public class EmailAlertPluginTest { List paramsList = new ArrayList<>(); InputParam receivesParam = InputParam.newBuilder("receivers", "receivers") - .setValue("540957506@qq.com") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setValue("540957506@qq.com") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); InputParam mailSmtpHost = InputParam.newBuilder("mailServerHost", "mail.smtp.host") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("smtp.exmail.qq.com") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("smtp.exmail.qq.com") + .build(); InputParam mailSmtpPort = InputParam.newBuilder("mailServerPort", "mail.smtp.port") - .addValidate(Validate.newBuilder() - .setRequired(true) - .setType(DataType.NUMBER.getDataType()) - .build()) - .setValue(25) - .build(); + .addValidate(Validate.newBuilder() + .setRequired(true) + .setType(DataType.NUMBER.getDataType()) + .build()) + .setValue(25) + .build(); InputParam mailSender = InputParam.newBuilder("mailSender", "mail.sender") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("easyscheduler@analysys.com.cn") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("easyscheduler@analysys.com.cn") + .build(); RadioParam enableSmtpAuth = RadioParam.newBuilder("enableSmtpAuth", "mail.smtp.auth") - .addParamsOptions(new ParamsOptions("YES", true, false)) - .addParamsOptions(new ParamsOptions("NO", false, false)) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue(true) - .build(); + .addParamsOptions(new ParamsOptions("YES", true, false)) + .addParamsOptions(new ParamsOptions("NO", false, false)) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue(true) + .build(); InputParam mailUser = InputParam.newBuilder("mailUser", "mail.user") - .setPlaceholder("if enable use authentication, you need input user") - .setValue("easyscheduler@analysys.com.cn") - .build(); + .setPlaceholder("if enable use authentication, you need input user") + .setValue("easyscheduler@analysys.com.cn") + .build(); PasswordParam mailPassword = PasswordParam.newBuilder("mailPasswd", "mail.passwd") - .setPlaceholder("if enable use authentication, you need input password") - .setValue("xxxxxxx") - .build(); + .setPlaceholder("if enable use authentication, you need input password") + .setValue("xxxxxxx") + .build(); RadioParam enableTls = RadioParam.newBuilder("starttlsEnable", "mail.smtp.starttls.enable") - .addParamsOptions(new ParamsOptions("YES", true, false)) - .addParamsOptions(new ParamsOptions("NO", false, false)) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue(true) - .build(); + .addParamsOptions(new ParamsOptions("YES", true, false)) + .addParamsOptions(new ParamsOptions("NO", false, false)) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue(true) + .build(); RadioParam enableSsl = RadioParam.newBuilder("sslEnable", "mail.smtp.ssl.enable") - .addParamsOptions(new ParamsOptions("YES", true, false)) - .addParamsOptions(new ParamsOptions("NO", false, false)) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue(false) - .build(); + .addParamsOptions(new ParamsOptions("YES", true, false)) + .addParamsOptions(new ParamsOptions("NO", false, false)) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue(false) + .build(); InputParam sslTrust = InputParam.newBuilder("mailSmtpSslTrust", "mail.smtp.ssl.trust") - .addValidate(Validate.newBuilder().setRequired(true).build()) - .setValue("smtp.exmail.qq.com") - .build(); + .addValidate(Validate.newBuilder().setRequired(true).build()) + .setValue("smtp.exmail.qq.com") + .build(); List emailShowTypeList = new ArrayList<>(); emailShowTypeList.add(new ParamsOptions(ShowType.TABLE.getDescp(), ShowType.TABLE.getDescp(), false)); @@ -230,10 +213,10 @@ public class EmailAlertPluginTest { emailShowTypeList.add(new ParamsOptions(ShowType.ATTACHMENT.getDescp(), ShowType.ATTACHMENT.getDescp(), false)); emailShowTypeList.add(new ParamsOptions(ShowType.TABLEATTACHMENT.getDescp(), ShowType.TABLEATTACHMENT.getDescp(), false)); RadioParam showType = RadioParam.newBuilder(AlertConstants.NAME_SHOW_TYPE, "showType") - .setOptions(emailShowTypeList) - .setValue(ShowType.TABLE.getDescp()) - .addValidate(Validate.newBuilder().setRequired(true).build()) - .build(); + .setOptions(emailShowTypeList) + .setValue(ShowType.TABLE.getDescp()) + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); paramsList.add(receivesParam); paramsList.add(mailSmtpHost); diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java similarity index 77% rename from dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java index 052d2f3d55..20e67687a4 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java @@ -17,7 +17,10 @@ package org.apache.dolphinscheduler.alert.processor; -import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +import static org.mockito.Mockito.mock; + +import org.apache.dolphinscheduler.alert.AlertRequestProcessor; +import org.apache.dolphinscheduler.alert.AlertSender; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.CommandType; @@ -26,30 +29,21 @@ import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; import io.netty.channel.Channel; -/** - * alert request processor test - */ public class AlertRequestProcessorTest { - - private AlertDao alertDao; - private AlertPluginManager alertPluginManager; - private AlertRequestProcessor alertRequestProcessor; @Before public void before() { - alertDao = PowerMockito.mock(AlertDao.class); - alertPluginManager = PowerMockito.mock(AlertPluginManager.class); - alertRequestProcessor = new AlertRequestProcessor(alertDao, alertPluginManager); + final AlertDao alertDao = mock(AlertDao.class); + alertRequestProcessor = new AlertRequestProcessor(new AlertSender(alertDao, null)); } @Test public void testProcess() { - Channel channel = PowerMockito.mock(Channel.class); + Channel channel = mock(Channel.class); AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(1, "title", "content"); Command reqCommand = alertSendRequestCommand.convert2Command(); Assert.assertEquals(CommandType.ALERT_SEND_REQUEST, reqCommand.getType()); diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java similarity index 60% rename from dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java rename to dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java index 3b84bdbe67..160afeb5d9 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java @@ -17,34 +17,32 @@ package org.apache.dolphinscheduler.alert.runner; -import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.dolphinscheduler.alert.AlertPluginManager; +import org.apache.dolphinscheduler.alert.AlertSender; +import org.apache.dolphinscheduler.alert.api.AlertChannel; +import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.PluginDao; import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; import org.apache.dolphinscheduler.dao.entity.PluginDefine; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertResult; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Optional; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * alert sender test - */ public class AlertSenderTest { - private static final Logger logger = LoggerFactory.getLogger(AlertSenderTest.class); private AlertDao alertDao; @@ -55,10 +53,9 @@ public class AlertSenderTest { @Before public void before() { - alertDao = PowerMockito.mock(AlertDao.class); - pluginDao = PowerMockito.mock(PluginDao.class); - alertPluginManager = PowerMockito.mock(AlertPluginManager.class); - + alertDao = mock(AlertDao.class); + pluginDao = mock(PluginDao.class); + alertPluginManager = mock(AlertPluginManager.class); } @Test @@ -70,12 +67,12 @@ public class AlertSenderTest { alertSender = new AlertSender(alertDao, alertPluginManager); //1.alert instance does not exist - PowerMockito.when(alertDao.listInstanceByAlertGroupId(alertGroupId)).thenReturn(null); + when(alertDao.listInstanceByAlertGroupId(alertGroupId)).thenReturn(null); AlertSendResponseCommand alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); //2.alert plugin does not exist int pluginDefineId = 1; @@ -83,59 +80,52 @@ public class AlertSenderTest { String pluginInstanceName = "alert-instance-mail"; List alertInstanceList = new ArrayList<>(); AlertPluginInstance alertPluginInstance = new AlertPluginInstance( - pluginDefineId, pluginInstanceParams, pluginInstanceName); + pluginDefineId, pluginInstanceParams, pluginInstanceName); alertInstanceList.add(alertPluginInstance); - PowerMockito.when(alertDao.listInstanceByAlertGroupId(1)).thenReturn(alertInstanceList); + when(alertDao.listInstanceByAlertGroupId(1)).thenReturn(alertInstanceList); String pluginName = "alert-plugin-mail"; PluginDefine pluginDefine = new PluginDefine(pluginName, "1", null); - PowerMockito.when(pluginDao.getPluginDefineById(pluginDefineId)).thenReturn(pluginDefine); + when(pluginDao.getPluginDefineById(pluginDefineId)).thenReturn(pluginDefine); alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); //3.alert result value is null - AlertChannel alertChannelMock = PowerMockito.mock(AlertChannel.class); - PowerMockito.when(alertChannelMock.process(Mockito.any())).thenReturn(null); - Map alertChannelMap = new ConcurrentHashMap<>(); - alertChannelMap.put(pluginName, alertChannelMock); - PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); - PowerMockito.when(alertPluginManager.getPluginNameById(Mockito.anyInt())).thenReturn("alert-plugin-mail"); + AlertChannel alertChannelMock = mock(AlertChannel.class); + when(alertChannelMock.process(Mockito.any())).thenReturn(null); + when(alertPluginManager.getAlertChannel(1)).thenReturn(Optional.of(alertChannelMock)); alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); //4.abnormal information inside the alert plug-in code AlertResult alertResult = new AlertResult(); alertResult.setStatus(String.valueOf(false)); alertResult.setMessage("Abnormal information inside the alert plug-in code"); - PowerMockito.when(alertChannelMock.process(Mockito.any())).thenReturn(alertResult); - alertChannelMap = new ConcurrentHashMap<>(); - alertChannelMap.put(pluginName, alertChannelMock); - PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); + when(alertChannelMock.process(Mockito.any())).thenReturn(alertResult); + when(alertPluginManager.getAlertChannel(1)).thenReturn(Optional.of(alertChannelMock)); alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); //5.alert plugin send success alertResult = new AlertResult(); alertResult.setStatus(String.valueOf(true)); alertResult.setMessage(String.format("Alert Plugin %s send success", pluginInstanceName)); - PowerMockito.when(alertChannelMock.process(Mockito.any())).thenReturn(alertResult); - alertChannelMap = new ConcurrentHashMap<>(); - alertChannelMap.put(pluginName, alertChannelMock); - PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); + when(alertChannelMock.process(Mockito.any())).thenReturn(alertResult); + when(alertPluginManager.getAlertChannel(1)).thenReturn(Optional.of(alertChannelMock)); alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertTrue(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); } @@ -151,33 +141,28 @@ public class AlertSenderTest { alert.setContent(content); alertList.add(alert); - alertSender = new AlertSender(alertList, alertDao, alertPluginManager); + alertSender = new AlertSender(alertDao, alertPluginManager); int pluginDefineId = 1; String pluginInstanceParams = "alert-instance-mail-params"; String pluginInstanceName = "alert-instance-mail"; List alertInstanceList = new ArrayList<>(); AlertPluginInstance alertPluginInstance = new AlertPluginInstance( - pluginDefineId, pluginInstanceParams, pluginInstanceName); + pluginDefineId, pluginInstanceParams, pluginInstanceName); alertInstanceList.add(alertPluginInstance); - PowerMockito.when(alertDao.listInstanceByAlertGroupId(alertGroupId)).thenReturn(alertInstanceList); + when(alertDao.listInstanceByAlertGroupId(alertGroupId)).thenReturn(alertInstanceList); String pluginName = "alert-plugin-mail"; PluginDefine pluginDefine = new PluginDefine(pluginName, "1", null); - PowerMockito.when(pluginDao.getPluginDefineById(pluginDefineId)).thenReturn(pluginDefine); - PowerMockito.when(alertPluginManager.getPluginNameById(1)).thenReturn("alert-instance-mail"); + when(pluginDao.getPluginDefineById(pluginDefineId)).thenReturn(pluginDefine); AlertResult alertResult = new AlertResult(); alertResult.setStatus(String.valueOf(true)); alertResult.setMessage(String.format("Alert Plugin %s send success", pluginInstanceName)); - AlertChannel alertChannelMock = PowerMockito.mock(AlertChannel.class); - PowerMockito.when(alertChannelMock.process(Mockito.any())).thenReturn(alertResult); - ConcurrentHashMap alertChannelMap = new ConcurrentHashMap<>(); - alertChannelMap.put(pluginName, alertChannelMock); - PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); + AlertChannel alertChannelMock = mock(AlertChannel.class); + when(alertChannelMock.process(Mockito.any())).thenReturn(alertResult); + when(alertPluginManager.getAlertChannel(1)).thenReturn(Optional.of(alertChannelMock)); Assert.assertTrue(Boolean.parseBoolean(alertResult.getStatus())); - alertSender.run(); - + alertSender.send(alertList); } - } diff --git a/dolphinscheduler-alert/pom.xml b/dolphinscheduler-alert/pom.xml index 456c076e8f..2cd1f49c23 100644 --- a/dolphinscheduler-alert/pom.xml +++ b/dolphinscheduler-alert/pom.xml @@ -1,125 +1,68 @@ - - 4.0.0 + - org.apache.dolphinscheduler dolphinscheduler + org.apache.dolphinscheduler 2.0.0-SNAPSHOT + 4.0.0 + pom dolphinscheduler-alert - ${project.artifactId} - jar - - - UTF-8 - - - - - org.apache.dolphinscheduler - dolphinscheduler-remote - - - - org.apache.dolphinscheduler - dolphinscheduler-dao - - - log4j-api - org.apache.logging.log4j - - - - - junit - junit - test - - - - com.fasterxml.jackson.core - jackson-core - - - - com.fasterxml.jackson.core - jackson-databind - + + dolphinscheduler-alert-api + dolphinscheduler-alert-plugins + dolphinscheduler-alert-server + + org.slf4j slf4j-api - com.google.guava - guava - - - jsr305 - com.google.code.findbugs - - - - - ch.qos.logback - logback-classic - - - - - org.apache.poi - poi + com.google.auto.service + auto-service + true - org.powermock - powermock-module-junit4 - test - - - - org.mockito - mockito-core - test - - - - org.powermock - powermock-api-mockito2 + junit + junit test - - - org.mockito - mockito-core - - - org.jacoco org.jacoco.agent runtime test + + org.springframework.boot + spring-boot-starter-test + test + - diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java deleted file mode 100644 index b0a8c0348d..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.alert; - -import static org.apache.dolphinscheduler.alert.utils.Constants.ALERT_PROPERTIES_PATH; -import static org.apache.dolphinscheduler.common.Constants.ALERT_RPC_PORT; - -import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; -import org.apache.dolphinscheduler.alert.processor.AlertRequestProcessor; -import org.apache.dolphinscheduler.alert.runner.AlertSender; -import org.apache.dolphinscheduler.alert.utils.Constants; -import org.apache.dolphinscheduler.common.thread.Stopper; -import org.apache.dolphinscheduler.common.utils.PropertyUtils; -import org.apache.dolphinscheduler.dao.AlertDao; -import org.apache.dolphinscheduler.dao.DaoFactory; -import org.apache.dolphinscheduler.dao.PluginDao; -import org.apache.dolphinscheduler.dao.entity.Alert; -import org.apache.dolphinscheduler.remote.NettyRemotingServer; -import org.apache.dolphinscheduler.remote.command.CommandType; -import org.apache.dolphinscheduler.remote.config.NettyServerConfig; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; -import org.apache.dolphinscheduler.spi.utils.StringUtils; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableList; - -public class AlertServer { - - private static final Logger logger = LoggerFactory.getLogger(AlertServer.class); - - private final PluginDao pluginDao = DaoFactory.getDaoInstance(PluginDao.class); - - private final AlertDao alertDao = DaoFactory.getDaoInstance(AlertDao.class); - - private AlertPluginManager alertPluginManager; - - public static final String ALERT_PLUGIN_BINDING = "alert.plugin.binding"; - - public static final String ALERT_PLUGIN_DIR = "alert.plugin.dir"; - - public static final String MAVEN_LOCAL_REPOSITORY = "maven.local.repository"; - - private NettyRemotingServer server; - - private static class AlertServerHolder { - private static final AlertServer INSTANCE = new AlertServer(); - } - - public static AlertServer getInstance() { - return AlertServerHolder.INSTANCE; - } - - private AlertServer() { - - } - - private void checkTable() { - if (!pluginDao.checkPluginDefineTableExist()) { - logger.error("Plugin Define Table t_ds_plugin_define Not Exist . Please Create it First !"); - System.exit(1); - } - } - - private void initPlugin() { - DolphinPluginManagerConfig alertPluginManagerConfig = new DolphinPluginManagerConfig(); - alertPluginManagerConfig.setPlugins(PropertyUtils.getString(ALERT_PLUGIN_BINDING)); - if (StringUtils.isNotBlank(PropertyUtils.getString(ALERT_PLUGIN_DIR))) { - alertPluginManagerConfig.setInstalledPluginsDir(PropertyUtils.getString(ALERT_PLUGIN_DIR, Constants.ALERT_PLUGIN_PATH).trim()); - } - - if (StringUtils.isNotBlank(PropertyUtils.getString(MAVEN_LOCAL_REPOSITORY))) { - alertPluginManagerConfig.setMavenLocalRepository(PropertyUtils.getString(MAVEN_LOCAL_REPOSITORY).trim()); - } - - alertPluginManager = new AlertPluginManager(); - DolphinPluginLoader alertPluginLoader = new DolphinPluginLoader(alertPluginManagerConfig, ImmutableList.of(alertPluginManager)); - try { - alertPluginLoader.loadPlugins(); - } catch (Exception e) { - throw new RuntimeException("Load Alert Plugin Failed !", e); - } - } - - private void initRemoteServer() { - NettyServerConfig serverConfig = new NettyServerConfig(); - serverConfig.setListenPort(ALERT_RPC_PORT); - this.server = new NettyRemotingServer(serverConfig); - this.server.registerProcessor(CommandType.ALERT_SEND_REQUEST, new AlertRequestProcessor(alertDao, alertPluginManager)); - this.server.start(); - } - - private void runSender() { - new Thread(new Sender()).start(); - } - - public void start() { - PropertyUtils.loadPropertyFile(ALERT_PROPERTIES_PATH); - checkTable(); - initPlugin(); - initRemoteServer(); - logger.info("alert server ready start "); - runSender(); - } - - public void stop() { - this.server.close(); - logger.info("alert server shut down"); - } - - final class Sender implements Runnable { - @Override - public void run() { - while (Stopper.isRunning()) { - try { - Thread.sleep(Constants.ALERT_SCAN_INTERVAL); - } catch (InterruptedException e) { - logger.error(e.getMessage(), e); - Thread.currentThread().interrupt(); - } - if (alertPluginManager == null || alertPluginManager.getAlertChannelMap().size() == 0) { - logger.warn("No Alert Plugin . Cannot send alert info. "); - } else { - List alerts = alertDao.listWaitExecutionAlert(); - new AlertSender(alerts, alertDao, alertPluginManager).run(); - } - } - } - } - - public static void main(String[] args) { - AlertServer alertServer = AlertServer.getInstance(); - alertServer.start(); - Runtime.getRuntime().addShutdownHook(new Thread(alertServer::stop)); - } - -} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java deleted file mode 100644 index 02f4b0ff8a..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManager.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.alert.plugin; - -import static java.lang.String.format; -import static java.util.Objects.requireNonNull; - -import static com.google.common.base.Preconditions.checkState; - -import org.apache.dolphinscheduler.common.enums.PluginType; -import org.apache.dolphinscheduler.spi.plugin.AbstractDolphinPluginManager; -import org.apache.dolphinscheduler.dao.DaoFactory; -import org.apache.dolphinscheduler.dao.PluginDao; -import org.apache.dolphinscheduler.dao.entity.PluginDefine; -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.classloader.ThreadContextClassLoader; -import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * load the configured alert plugin and manager them - */ -public class AlertPluginManager extends AbstractDolphinPluginManager { - private static final Logger logger = LoggerFactory.getLogger(AlertPluginManager.class); - - private final Map alertChannelFactoryMap = new ConcurrentHashMap<>(); - private final Map alertChannelMap = new ConcurrentHashMap<>(); - - /** - * k->pluginDefineId v->pluginDefineName - */ - private final Map pluginDefineMap = new HashMap<>(); - - private final PluginDao pluginDao = DaoFactory.getDaoInstance(PluginDao.class); - - private void addAlertChannelFactory(AlertChannelFactory alertChannelFactory) { - requireNonNull(alertChannelFactory, "alertChannelFactory is null"); - - if (alertChannelFactoryMap.putIfAbsent(alertChannelFactory.getName(), alertChannelFactory) != null) { - throw new IllegalArgumentException(format("Alert Plugin '%s' is already registered", alertChannelFactory.getName())); - } - - try { - loadAlertChannel(alertChannelFactory.getName()); - } catch (Exception e) { - throw new IllegalArgumentException(format("Alert Plugin '%s' is can not load .", alertChannelFactory.getName())); - } - } - - private void loadAlertChannel(String name) { - requireNonNull(name, "name is null"); - - AlertChannelFactory alertChannelFactory = alertChannelFactoryMap.get(name); - checkState(alertChannelFactory != null, "Alert Plugin %s is not registered", name); - - try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(alertChannelFactory.getClass().getClassLoader())) { - AlertChannel alertChannel = alertChannelFactory.create(); - this.alertChannelMap.put(name, alertChannel); - } - - logger.info("-- Loaded Alert Plugin {} --", name); - } - - Map getAlertChannelFactoryMap() { - return alertChannelFactoryMap; - } - - public Map getAlertChannelMap() { - return alertChannelMap; - } - - public String getPluginNameById(int id) { - return pluginDefineMap.get(id); - } - - @Override - public void installPlugin(DolphinSchedulerPlugin dolphinSchedulerPlugin) { - for (AlertChannelFactory alertChannelFactory : dolphinSchedulerPlugin.getAlertChannelFactorys()) { - logger.info("Registering Alert Plugin '{}'", alertChannelFactory.getName()); - this.addAlertChannelFactory(alertChannelFactory); - List params = alertChannelFactory.getParams(); - String nameEn = alertChannelFactory.getName(); - String paramsJson = PluginParamsTransfer.transferParamsToJson(params); - - PluginDefine pluginDefine = new PluginDefine(nameEn, PluginType.ALERT.getDesc(), paramsJson); - int id = pluginDao.addOrUpdatePluginDefine(pluginDefine); - pluginDefineMap.put(id, pluginDefine.getPluginName()); - } - } -} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/Constants.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/Constants.java deleted file mode 100644 index 077f7ac26c..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/Constants.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.alert.utils; - -/** - * constants - */ -public class Constants { - private Constants() { - throw new IllegalStateException("Constants class"); - } - - /** - * alert properties path - */ - public static final String ALERT_PROPERTIES_PATH = "/alert.properties"; - - /** default alert plugin dir **/ - public static final String ALERT_PLUGIN_PATH = "lib/plugin/alert"; - - public static final int ALERT_SCAN_INTERVAL = 5000; - -} diff --git a/dolphinscheduler-alert/src/main/resources/alert.properties b/dolphinscheduler-alert/src/main/resources/alert.properties deleted file mode 100644 index c41ae61237..0000000000 --- a/dolphinscheduler-alert/src/main/resources/alert.properties +++ /dev/null @@ -1,30 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -#This configuration file configures the configuration parameters related to the AlertServer. -#These parameters are only related to the AlertServer, and it has nothing to do with the specific Alert Plugin. -#eg : max retry num. -#eg : Alert Server Listener port - -#alert.plugin.dir config the Alert Plugin dir . AlertServer while find and load the Alert Plugin Jar from this dir when deploy and start AlertServer on the server . -#alert.plugin.dir=lib/plugin/alert - -#maven.local.repository=/Users/gaojun/Documents/jianguoyun/localRepository - -#alert.plugin.binding config the Alert Plugin need be load when development and run in IDE -#alert.plugin.binding=\ -# ./dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java deleted file mode 100644 index 38fb6b055e..0000000000 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.alert; - -import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; -import org.apache.dolphinscheduler.alert.runner.AlertSender; -import org.apache.dolphinscheduler.alert.utils.Constants; -import org.apache.dolphinscheduler.dao.AlertDao; -import org.apache.dolphinscheduler.dao.DaoFactory; -import org.apache.dolphinscheduler.dao.PluginDao; -import org.apache.dolphinscheduler.remote.NettyRemotingServer; -import org.apache.dolphinscheduler.spi.alert.AlertChannel; - -import java.util.concurrent.ConcurrentHashMap; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({AlertServer.class, DaoFactory.class}) -public class AlertServerTest { - - @Before - public void before() { - - } - - @Test - public void testMain() throws Exception { - AlertDao alertDao = PowerMockito.mock(AlertDao.class); - PowerMockito.mockStatic(DaoFactory.class); - PowerMockito.when(DaoFactory.getDaoInstance(AlertDao.class)).thenReturn(alertDao); - - PluginDao pluginDao = PowerMockito.mock(PluginDao.class); - PowerMockito.when(DaoFactory.getDaoInstance(PluginDao.class)).thenReturn(pluginDao); - PowerMockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); - - AlertChannel alertChannelMock = PowerMockito.mock(AlertChannel.class); - - AlertPluginManager alertPluginManager = PowerMockito.mock(AlertPluginManager.class); - PowerMockito.whenNew(AlertPluginManager.class).withNoArguments().thenReturn(alertPluginManager); - ConcurrentHashMap alertChannelMap = new ConcurrentHashMap<>(); - alertChannelMap.put("pluginName", alertChannelMock); - PowerMockito.when(alertPluginManager.getPluginNameById(Mockito.anyInt())).thenReturn("pluginName"); - PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); - - DolphinPluginManagerConfig alertPluginManagerConfig = PowerMockito.mock(DolphinPluginManagerConfig.class); - PowerMockito.whenNew(DolphinPluginManagerConfig.class).withNoArguments().thenReturn(alertPluginManagerConfig); - - NettyRemotingServer nettyRemotingServer = PowerMockito.mock(NettyRemotingServer.class); - PowerMockito.whenNew(NettyRemotingServer.class).withAnyArguments().thenReturn(nettyRemotingServer); - AlertSender alertSender = PowerMockito.mock(AlertSender.class); - PowerMockito.whenNew(AlertSender.class).withAnyArguments().thenReturn(alertSender); - - DolphinPluginLoader dolphinPluginLoader = PowerMockito.mock(DolphinPluginLoader.class); - PowerMockito.whenNew(DolphinPluginLoader.class).withAnyArguments().thenReturn(dolphinPluginLoader); - - AlertServer alertServer = AlertServer.getInstance(); - Assert.assertNotNull(alertServer); - - new Thread(() -> alertServer.start()).start(); - - Thread.sleep(5 * Constants.ALERT_SCAN_INTERVAL); - - alertServer.stop(); - } - -} diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManagerTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManagerTest.java deleted file mode 100644 index 7bb64781c4..0000000000 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/AlertPluginManagerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.alert.plugin; - -import org.apache.dolphinscheduler.alert.AlertServer; -import org.apache.dolphinscheduler.alert.utils.Constants; -import org.apache.dolphinscheduler.common.utils.PropertyUtils; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; -import org.apache.dolphinscheduler.spi.utils.StringUtils; - -import java.util.Objects; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * AlertPluginManager Tester. - */ -public class AlertPluginManagerTest { - - private static final Logger logger = LoggerFactory.getLogger(AlertPluginManagerTest.class); - - @BeforeClass - public static void setUp() { - System.setProperty("spring.profiles.active", "h2"); - } - - @Test - public void testLoadPlugins() { - logger.info("begin test AlertPluginManagerTest"); - AlertPluginManager alertPluginManager = new AlertPluginManager(); - DolphinPluginManagerConfig alertPluginManagerConfig = new DolphinPluginManagerConfig(); - String path = Objects.requireNonNull(DolphinPluginLoader.class.getClassLoader().getResource("")).getPath(); - alertPluginManagerConfig.setPlugins(path + "../../../dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml"); - if (StringUtils.isNotBlank(PropertyUtils.getString(AlertServer.ALERT_PLUGIN_DIR))) { - alertPluginManagerConfig.setInstalledPluginsDir(PropertyUtils.getString(AlertServer.ALERT_PLUGIN_DIR, Constants.ALERT_PLUGIN_PATH).trim()); - } - - if (StringUtils.isNotBlank(PropertyUtils.getString(AlertServer.MAVEN_LOCAL_REPOSITORY))) { - alertPluginManagerConfig.setMavenLocalRepository(Objects.requireNonNull(PropertyUtils.getString(AlertServer.MAVEN_LOCAL_REPOSITORY)).trim()); - } - - Assert.assertNull(alertPluginManager.getAlertChannelFactoryMap().get("Email")); - } -} diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/DolphinPluginLoaderTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/DolphinPluginLoaderTest.java deleted file mode 100644 index aceb6a1f72..0000000000 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/DolphinPluginLoaderTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.alert.plugin; - -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; -import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; - -import java.util.Objects; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import com.google.common.collect.ImmutableList; - -/** - * DolphinPluginLoader Tester. - */ -@Ignore("load jar fail,don't care plugin,should mock plugin") -public class DolphinPluginLoaderTest { - - /** - * Method: loadPlugins() - */ - @Test - public void testLoadPlugins() { - AlertPluginManager alertPluginManager = new AlertPluginManager(); - DolphinPluginManagerConfig alertPluginManagerConfig = new DolphinPluginManagerConfig(); - String path = Objects.requireNonNull(DolphinPluginLoader.class.getClassLoader().getResource("")).getPath(); - alertPluginManagerConfig.setPlugins(path + "../../../dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml"); - DolphinPluginLoader alertPluginLoader = new DolphinPluginLoader(alertPluginManagerConfig, ImmutableList.of(alertPluginManager)); - try { - alertPluginLoader.loadPlugins(); - } catch (Exception e) { - throw new RuntimeException("load Alert Plugin Failed !", e); - } - - Assert.assertNotNull(alertPluginManager.getAlertChannelFactoryMap().get("Email")); - } -} diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java index 53a97d9755..120abab525 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java @@ -179,58 +179,6 @@ public class PropertyUtils { return val == null ? defaultVal : Long.parseLong(val); } - /** - * @param key key - * @return property value - */ - public static long getLong(String key) { - return getLong(key, -1); - } - - /** - * @param key key - * @param defaultVal default value - * @return property value - */ - public static double getDouble(String key, double defaultVal) { - String val = getString(key); - return val == null ? defaultVal : Double.parseDouble(val); - } - - /** - * get array - * - * @param key property name - * @param splitStr separator - * @return property value through array - */ - public static String[] getArray(String key, String splitStr) { - String value = getString(key); - if (value == null) { - return new String[0]; - } - try { - String[] propertyArray = value.split(splitStr); - return propertyArray; - } catch (NumberFormatException e) { - logger.info(e.getMessage(), e); - } - return new String[0]; - } - - /** - * @param key key - * @param type type - * @param defaultValue default value - * @param T - * @return get enum value - */ - public static > T getEnum(String key, Class type, - T defaultValue) { - String val = getString(key); - return val == null ? defaultValue : Enum.valueOf(type, val); - } - /** * get all properties with specified prefix, like: fs. * @@ -247,9 +195,6 @@ public class PropertyUtils { return matchedProperties; } - /** - * - */ public static void setValue(String key, String value) { properties.setProperty(key, value); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java index 18e8e0de4d..75978cb877 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java @@ -179,11 +179,9 @@ public class AlertDao extends AbstractBaseDao { } /** - * list the alert information of waiting to be executed - * - * @return alert list + * List alerts that are pending for execution */ - public List listWaitExecutionAlert() { + public List listPendingAlerts() { return alertMapper.listAlertByStatus(AlertStatus.WAIT_EXECUTION); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/DaoFactory.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/DaoFactory.java index 2db41a332f..4a88a34b54 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/DaoFactory.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/DaoFactory.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** - * dao factory + * dao factory TODO remove */ public class DaoFactory { diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java index afaa0bdb00..fe71a8ca20 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java @@ -34,9 +34,6 @@ import org.springframework.stereotype.Component; @Component public class PluginDao extends AbstractBaseDao { - - private final Logger logger = LoggerFactory.getLogger(getClass()); - @Autowired private PluginDefineMapper pluginDefineMapper; @@ -76,7 +73,10 @@ public class PluginDao extends AbstractBaseDao { List pluginDefineList = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType()); if (CollectionUtils.isEmpty(pluginDefineList)) { - return pluginDefineMapper.insert(pluginDefine); + if (pluginDefineMapper.insert(pluginDefine) == 1 && pluginDefine.getId() > 0) { + return pluginDefine.getId(); + } + throw new IllegalStateException("Failed to insert plugin definition"); } PluginDefine currPluginDefine = pluginDefineList.get(0); if (!currPluginDefine.getPluginParams().equals(pluginDefine.getPluginParams())) { diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java index abc56ca758..fe60aedaab 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java @@ -46,7 +46,7 @@ public class AlertDaoTest { alert.setAlertStatus(AlertStatus.WAIT_EXECUTION); alertDao.addAlert(alert); - List alerts = alertDao.listWaitExecutionAlert(); + List alerts = alertDao.listPendingAlerts(); Assert.assertNotNull(alerts); Assert.assertNotEquals(0, alerts.size()); } @@ -59,7 +59,7 @@ public class AlertDaoTest { String serverType = "Master"; alertDao.sendServerStopedAlert(alertGroupId, host, serverType); alertDao.sendServerStopedAlert(alertGroupId, host, serverType); - long count = alertDao.listWaitExecutionAlert() + long count = alertDao.listPendingAlerts() .stream() .filter(alert -> alert.getContent().contains(host)) .count(); diff --git a/dolphinscheduler-dist/pom.xml b/dolphinscheduler-dist/pom.xml index 877665a942..bf67d55485 100644 --- a/dolphinscheduler-dist/pom.xml +++ b/dolphinscheduler-dist/pom.xml @@ -49,7 +49,7 @@ org.apache.dolphinscheduler - dolphinscheduler-alert + dolphinscheduler-alert-server diff --git a/dolphinscheduler-dist/release-docs/LICENSE b/dolphinscheduler-dist/release-docs/LICENSE index 937216f9b6..a0c29a6c8c 100644 --- a/dolphinscheduler-dist/release-docs/LICENSE +++ b/dolphinscheduler-dist/release-docs/LICENSE @@ -233,7 +233,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt. commons-codec 1.11: https://mvnrepository.com/artifact/commons-codec/commons-codec/1.11, Apache 2.0 commons-collections 3.2.2: https://mvnrepository.com/artifact/commons-collections/commons-collections/3.2.2, Apache 2.0 commons-collections4 4.1: https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1, Apache 2.0 - commons-compress 1.19: https://mvnrepository.com/artifact/org.apache.commons/commons-compress/1.19, Apache 2.0 + commons-compress 1.4.1: https://mvnrepository.com/artifact/org.apache.commons/commons-compress/1.4.1, Apache 2.0 commons-configuration 1.10: https://mvnrepository.com/artifact/commons-configuration/commons-configuration/1.10, Apache 2.0 commons-daemon 1.0.13 https://mvnrepository.com/artifact/commons-daemon/commons-daemon/1.0.13, Apache 2.0 commons-dbcp 1.4: https://github.com/apache/commons-dbcp, Apache 2.0 @@ -242,7 +242,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt. commons-io 2.4: https://github.com/apache/commons-io, Apache 2.0 commons-lang 2.6: https://github.com/apache/commons-lang, Apache 2.0 commons-logging 1.1.1: https://github.com/apache/commons-logging, Apache 2.0 - commons-math3 3.6.1: https://mvnrepository.com/artifact/org.apache.commons/commons-math3/3.6.1, Apache 2.0 + commons-math3 3.1.1: https://mvnrepository.com/artifact/org.apache.commons/commons-math3/3.1.1, Apache 2.0 commons-net 3.1: https://github.com/apache/commons-net, Apache 2.0 commons-pool 1.6: https://github.com/apache/commons-pool, Apache 2.0 cron-utils 5.0.5: https://mvnrepository.com/artifact/com.cronutils/cron-utils/5.0.5, Apache 2.0 diff --git a/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml b/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml index d7119d009b..85ffa5a270 100644 --- a/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml +++ b/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml @@ -44,37 +44,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Event.java b/dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Event.java index be781db738..6afa5a2c26 100644 --- a/dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Event.java +++ b/dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Event.java @@ -19,30 +19,107 @@ package org.apache.dolphinscheduler.registry.api; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -@Getter -@Setter -@Builder -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Accessors(fluent = true) public class Event { private String key; private String path; private String data; private Type type; + public Event(String key, String path, String data, Type type) { + this.key = key; + this.path = path; + this.data = data; + this.type = type; + } + + public Event() { + } + + public static EventBuilder builder() { + return new EventBuilder(); + } + + public String key() { + return this.key; + } + + public String path() { + return this.path; + } + + public String data() { + return this.data; + } + + public Type type() { + return this.type; + } + + public Event key(String key) { + this.key = key; + return this; + } + + public Event path(String path) { + this.path = path; + return this; + } + + public Event data(String data) { + this.data = data; + return this; + } + + public Event type(Type type) { + this.type = type; + return this; + } + + public String toString() { + return "Event(key=" + this.key() + ", path=" + this.path() + ", data=" + this.data() + ", type=" + this.type() + ")"; + } + public enum Type { ADD, REMOVE, UPDATE } + + public static class EventBuilder { + private String key; + private String path; + private String data; + private Type type; + + EventBuilder() { + } + + public EventBuilder key(String key) { + this.key = key; + return this; + } + + public EventBuilder path(String path) { + this.path = path; + return this; + } + + public EventBuilder data(String data) { + this.data = data; + return this; + } + + public EventBuilder type(Type type) { + this.type = type; + return this; + } + + public Event build() { + return new Event(key, path, data, type); + } + + public String toString() { + return "Event.EventBuilder(key=" + this.key + ", path=" + this.path + ", data=" + this.data + ", type=" + this.type + ")"; + } + } } diff --git a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConnectionStateListener.java b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConnectionStateListener.java index 9526e0e060..7faa3db82b 100644 --- a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConnectionStateListener.java +++ b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConnectionStateListener.java @@ -23,14 +23,17 @@ import org.apache.dolphinscheduler.registry.api.ConnectionState; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.state.ConnectionStateListener; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; -@Slf4j -@RequiredArgsConstructor public final class ZookeeperConnectionStateListener implements ConnectionStateListener { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ZookeeperConnectionStateListener.class); + private final ConnectionListener listener; + public ZookeeperConnectionStateListener(ConnectionListener listener) { + this.listener = listener; + } + @Override public void stateChanged(CuratorFramework client, org.apache.curator.framework.state.ConnectionState newState) { diff --git a/dolphinscheduler-registry/pom.xml b/dolphinscheduler-registry/pom.xml index 8ce7c243f2..6e78c8b8f8 100644 --- a/dolphinscheduler-registry/pom.xml +++ b/dolphinscheduler-registry/pom.xml @@ -38,11 +38,5 @@ auto-service true - - org.projectlombok - lombok - 1.18.22 - provided - diff --git a/dolphinscheduler-server/src/main/resources/config/install_config.conf b/dolphinscheduler-server/src/main/resources/config/install_config.conf index 96174d9fc4..91d60cf2db 100755 --- a/dolphinscheduler-server/src/main/resources/config/install_config.conf +++ b/dolphinscheduler-server/src/main/resources/config/install_config.conf @@ -102,12 +102,6 @@ registryServers="192.168.xx.xx:2181,192.168.xx.xx:2181,192.168.xx.xx:2181" # The root of zookeeper, for now DolphinScheduler default registry server is zookeeper. zkRoot="/dolphinscheduler" -# --------------------------------------------------------- -# Alert Server -# --------------------------------------------------------- -# Alert Server plugin dir. DolphinScheduler will find and load the alert plugin jar package from this dir. -alertPluginDir="lib/plugin/alert" - # --------------------------------------------------------- # Worker Task Server # --------------------------------------------------------- diff --git a/dolphinscheduler-spi/pom.xml b/dolphinscheduler-spi/pom.xml index 3212ad16d4..e482deaac9 100644 --- a/dolphinscheduler-spi/pom.xml +++ b/dolphinscheduler-spi/pom.xml @@ -112,4 +112,4 @@ - \ No newline at end of file + diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/DolphinSchedulerPlugin.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/DolphinSchedulerPlugin.java index a073c53c8a..fe327b6400 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/DolphinSchedulerPlugin.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/DolphinSchedulerPlugin.java @@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.spi; import static java.util.Collections.emptyList; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; import org.apache.dolphinscheduler.spi.task.TaskChannelFactory; /** @@ -32,15 +31,6 @@ import org.apache.dolphinscheduler.spi.task.TaskChannelFactory; * Config contains custom parameters read from the plug-in configuration file. */ public interface DolphinSchedulerPlugin { - - /** - * get alert channel factory - * @return alert channel factory - */ - default Iterable getAlertChannelFactorys() { - return emptyList(); - } - /** * get task plugin factory * @return registry factory diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannel.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannel.java deleted file mode 100644 index a429a4ca02..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannel.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -/** - * alert channel interface . - * - * @author gaojun - */ -public interface AlertChannel { - - AlertResult process(AlertInfo info); -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannelFactory.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannelFactory.java deleted file mode 100644 index 8ac27ab309..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertChannelFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -import org.apache.dolphinscheduler.spi.common.UiChannelFactory; - -/** - * Each AlertPlugin need implement this interface - */ -public interface AlertChannelFactory extends UiChannelFactory { - - /** - * The parameters configured in the alert / xxx.properties file will be in the config map - * - * @return AlertChannel - */ - AlertChannel create(); -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertConstants.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertConstants.java deleted file mode 100644 index ca6d5c415c..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertConstants.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -public class AlertConstants { - - /** the field name of alert show type **/ - public static final String SHOW_TYPE = "$t('showType')"; - - public static final String NAME_SHOW_TYPE = "showType"; -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertData.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertData.java deleted file mode 100644 index 5e0abf299c..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertData.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -/** - * AlertData - */ -public class AlertData { - - /** - * alert primary key - */ - private int id; - /** - * title - */ - private String title; - /** - * content - */ - private String content; - /** - * log - */ - private String log; - - public int getId() { - return id; - } - - public AlertData setId(int id) { - this.id = id; - return this; - } - - public String getTitle() { - return title; - } - - public AlertData setTitle(String title) { - this.title = title; - return this; - } - - public String getContent() { - return content; - } - - public AlertData setContent(String content) { - this.content = content; - return this; - } - - public String getLog() { - return log; - } - - public AlertData setLog(String log) { - this.log = log; - return this; - } -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java deleted file mode 100644 index 8f61fe2f9d..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -import java.util.Map; - -/** - * AlertInfo - */ -public class AlertInfo { - - /** - * all params this plugin need is in alertProps - */ - private Map alertParams; - - /** - * the alert content - */ - private AlertData alertData; - - public Map getAlertParams() { - return alertParams; - } - - public void setAlertParams(Map alertParams) { - this.alertParams = alertParams; - } - - public AlertData getAlertData() { - return alertData; - } - - public void setAlertData(AlertData alertData) { - this.alertData = alertData; - } -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertResult.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertResult.java deleted file mode 100644 index 6ce5425f7f..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertResult.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -public class AlertResult { - - private String status; - - private String message; - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public AlertResult(String status, String message) { - this.status = status; - this.message = message; - } - - public AlertResult() { - } -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/ShowType.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/ShowType.java deleted file mode 100644 index a95e73ff7f..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/ShowType.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.spi.alert; - -/** - * show type for email - * all alert plugin can use ShowType , so let it in spi package - */ -public enum ShowType { - /** - * 0 TABLE; - * 1 TEXT; - * 2 attachment; - * 3 TABLE+attachment; - */ - TABLE(0, "table"), - TEXT(1, "text"), - ATTACHMENT(2, "attachment"), - TABLEATTACHMENT(3, "table attachment"); - - ShowType(int code, String descp) { - this.code = code; - this.descp = descp; - } - - private final int code; - private final String descp; - - public int getCode() { - return code; - } - - public String getDescp() { - return descp; - } -} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/plugin/DolphinPluginManagerConfig.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/plugin/DolphinPluginManagerConfig.java index 0d316a1705..4ea69de44d 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/plugin/DolphinPluginManagerConfig.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/plugin/DolphinPluginManagerConfig.java @@ -95,11 +95,6 @@ public class DolphinPluginManagerConfig { /** * When development and run server in IDE, this method can set plugins in alert.properties . * Then when you start AlertServer in IDE, the plugin can be load. - * eg: - * file: alert.properties - * alert.plugin=\ - * ../dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml, \ - * ../dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml * * @param plugins plugins * @return DolphinPluginManagerConfig diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractParameters.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractParameters.java index 55f5203967..ef6931d789 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractParameters.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/AbstractParameters.java @@ -23,7 +23,6 @@ import org.apache.dolphinscheduler.spi.utils.StringUtils; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -140,9 +139,8 @@ public abstract class AbstractParameters implements IParameters { public List> getListMapByString(String json) { List> allParams = new ArrayList<>(); ArrayNode paramsByJson = JSONUtils.parseArray(json); - Iterator listIterator = paramsByJson.iterator(); - while (listIterator.hasNext()) { - Map param = JSONUtils.toMap(listIterator.next().toString(), String.class, String.class); + for (JsonNode jsonNode : paramsByJson) { + Map param = JSONUtils.toMap(jsonNode.toString()); allParams.add(param); } return allParams; diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java index ed53cb2625..070e62f5a1 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java @@ -34,18 +34,14 @@ import java.util.TimeZone; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; @@ -169,47 +165,6 @@ public class JSONUtils { return Collections.emptyList(); } - /** - * check json object valid - * - * @param json json - * @return true if valid - */ - public static boolean checkJsonValid(String json) { - - if (StringUtils.isEmpty(json)) { - return false; - } - - try { - objectMapper.readTree(json); - return true; - } catch (IOException e) { - logger.error("check json object valid exception!", e); - } - - return false; - } - - /** - * Method for finding a JSON Object field with specified name in this - * node or its child nodes, and returning value it has. - * If no matching field is found in this node or its descendants, returns null. - * - * @param jsonNode json node - * @param fieldName Name of field to look for - * @return Value of first matching node found, if any; null if none - */ - public static String findValue(JsonNode jsonNode, String fieldName) { - JsonNode node = jsonNode.findValue(fieldName); - - if (node == null) { - return null; - } - - return node.asText(); - } - /** * json to map * {@link #toMap(String, Class, Class)} @@ -221,21 +176,6 @@ public class JSONUtils { return parseObject(json, new TypeReference>() {}); } - /** - * from the key-value generated json to get the str value no matter the real type of value - * @param json the json str - * @param nodeName key - * @return the str value of key - */ - public static String getNodeString(String json, String nodeName) { - try { - JsonNode rootNode = objectMapper.readTree(json); - return rootNode.has(nodeName) ? rootNode.get(nodeName).toString() : ""; - } catch (JsonProcessingException e) { - return ""; - } - } - /** * json to map * @@ -327,18 +267,6 @@ public class JSONUtils { } } - /** - * json serializer - */ - public static class JsonDataSerializer extends JsonSerializer { - - @Override - public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeRawValue(value); - } - - } - /** * json data deserializer */ diff --git a/dolphinscheduler-standalone-server/pom.xml b/dolphinscheduler-standalone-server/pom.xml index 83ab68d26e..c47bcfdc3d 100644 --- a/dolphinscheduler-standalone-server/pom.xml +++ b/dolphinscheduler-standalone-server/pom.xml @@ -49,7 +49,7 @@ org.apache.dolphinscheduler - dolphinscheduler-alert + dolphinscheduler-alert-server org.apache.dolphinscheduler diff --git a/dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java b/dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java index 50247b621d..2dfc66ae2a 100644 --- a/dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java +++ b/dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java @@ -42,30 +42,17 @@ public class StandaloneServer { startRegistry(); - startAlertServer(); - setTaskPlugin(); new SpringApplicationBuilder( ApiApplicationServer.class, MasterServer.class, WorkerServer.class, + AlertServer.class, PythonGatewayServer.class ).run(args); } - private static void startAlertServer() { - final Path alertPluginPath = Paths.get( - StandaloneServer.class.getProtectionDomain().getCodeSource().getLocation().getPath(), - "../../../dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml" - ).toAbsolutePath(); - if (Files.exists(alertPluginPath)) { - System.setProperty("alert.plugin.binding", alertPluginPath.toString()); - System.setProperty("alert.plugin.dir", ""); - } - AlertServer.getInstance().start(); - } - private static void startRegistry() throws Exception { final TestingServer server = new TestingServer(true); System.setProperty("registry.servers", server.getConnectString()); diff --git a/install.sh b/install.sh index c25d852b7b..5574df53c4 100755 --- a/install.sh +++ b/install.sh @@ -70,9 +70,6 @@ sed -i ${txt} "s@^#*worker.tenant.auto.create=.*@worker.tenant.auto.create=${wor sed -i ${txt} "s@^#*alert.listen.host=.*@alert.listen.host=${alertServer}@g" conf/worker.properties sed -i ${txt} "s@^#*task.plugin.dir=.*@task.plugin.dir=${installPath}/${taskPluginDir}@g" conf/worker.properties -# Change configuration in conf/alert.properties -sed -i ${txt} "s@^#*alert.plugin.dir=.*@alert.plugin.dir=${installPath}/${alertPluginDir}@g" conf/alert.properties - # Change configuration in conf/application-api.properties sed -i ${txt} "s@^#*server.port=.*@server.port=${apiServerPort}@g" conf/application-api.properties diff --git a/pom.xml b/pom.xml index bfc5f6cee4..5e916877f9 100644 --- a/pom.xml +++ b/pom.xml @@ -233,12 +233,7 @@ org.apache.dolphinscheduler - dolphinscheduler-registry - ${project.version} - - - org.apache.dolphinscheduler - dolphinscheduler-registry-zookeeper + dolphinscheduler-registry-plugin ${project.version} @@ -263,25 +258,69 @@ org.apache.dolphinscheduler - dolphinscheduler-alert + dolphinscheduler-spi ${project.version} org.apache.dolphinscheduler - dolphinscheduler-spi + dolphinscheduler-python ${project.version} org.apache.dolphinscheduler - dolphinscheduler-python + dolphinscheduler-alert-api + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-server + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-dingtalk + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-email + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-feishu + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-http + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-script + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-slack + ${project.version} + + + org.apache.dolphinscheduler + dolphinscheduler-alert-wechat ${project.version} - org.apache.dolphinscheduler dolphinscheduler-registry-api ${project.version} + + org.apache.dolphinscheduler + dolphinscheduler-registry-zookeeper + ${project.version} + org.apache.curator @@ -991,8 +1030,8 @@ + dolphinscheduler-alert dolphinscheduler-spi - dolphinscheduler-alert-plugin dolphinscheduler-registry dolphinscheduler-task-plugin dolphinscheduler-ui @@ -1000,7 +1039,6 @@ dolphinscheduler-common dolphinscheduler-api dolphinscheduler-dao - dolphinscheduler-alert dolphinscheduler-dist dolphinscheduler-remote dolphinscheduler-service diff --git a/tools/dependencies/known-dependencies.txt b/tools/dependencies/known-dependencies.txt index 7474f000b4..39c7b07b4c 100755 --- a/tools/dependencies/known-dependencies.txt +++ b/tools/dependencies/known-dependencies.txt @@ -30,7 +30,6 @@ commons-cli-1.2.jar commons-codec-1.11.jar commons-collections-3.2.2.jar commons-collections4-4.1.jar -commons-compress-1.19.jar commons-compress-1.4.1.jar commons-compiler-3.0.16.jar commons-configuration-1.10.jar @@ -42,7 +41,6 @@ commons-io-2.4.jar commons-lang-2.6.jar commons-logging-1.1.1.jar commons-math3-3.1.1.jar -commons-math3-3.6.1.jar commons-net-3.1.jar commons-pool-1.6.jar cron-utils-5.0.5.jar @@ -253,4 +251,4 @@ xmlbeans-3.1.0.jar xmlenc-0.52.jar xz-1.0.jar zookeeper-3.4.14.jar -Java-WebSocket-1.5.1.jar \ No newline at end of file +Java-WebSocket-1.5.1.jar