From 543aac5951209933eb20152b7add50ae921b40f6 Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Fri, 4 Sep 2020 14:06:04 +0800 Subject: [PATCH 01/44] [feature-3665][ui]Add element-ui (#3666) * [feature-3665][ui]Add element-ui * add license --- dolphinscheduler-dist/release-docs/LICENSE | 1 + .../licenses/ui-licenses/LICENSE-element-ui | 21 +++++++++++++++++++ dolphinscheduler-ui/build/config.js | 2 +- dolphinscheduler-ui/package.json | 1 + dolphinscheduler-ui/src/js/conf/home/index.js | 4 ++++ .../src/js/conf/login/index.js | 4 ++++ 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-element-ui diff --git a/dolphinscheduler-dist/release-docs/LICENSE b/dolphinscheduler-dist/release-docs/LICENSE index 707ea5cab1..95cd700970 100644 --- a/dolphinscheduler-dist/release-docs/LICENSE +++ b/dolphinscheduler-dist/release-docs/LICENSE @@ -491,6 +491,7 @@ MIT licenses clipboard 2.0.1: https://github.com/zenorocha/clipboard.js MIT codemirror 5.43.0: https://github.com/codemirror/CodeMirror MIT dayjs 1.7.8: https://github.com/iamkun/dayjs MIT + element-ui 2.13.2: https://github.com/ElemeFE/element MIT html2canvas 0.5.0-beta4: https://github.com/niklasvh/html2canvas MIT jquery 3.3.1: https://github.com/jquery/jquery MIT jquery-ui 1.12.1: https://github.com/jquery/jquery-ui MIT diff --git a/dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-element-ui b/dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-element-ui new file mode 100644 index 0000000000..d4462f3dcf --- /dev/null +++ b/dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-element-ui @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016-present ElemeFE + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/dolphinscheduler-ui/build/config.js b/dolphinscheduler-ui/build/config.js index 2800115d80..11bbec550f 100644 --- a/dolphinscheduler-ui/build/config.js +++ b/dolphinscheduler-ui/build/config.js @@ -207,7 +207,7 @@ const baseConfig = { 'jquery':'jquery/dist/jquery.min.js', 'jquery-ui': 'jquery-ui' }, - extensions: ['.js', 'json', '.vue', '.scss'] + extensions: ['*', '.js', 'json', '.vue', '.scss'] }, plugins: [ new VueLoaderPlugin(), diff --git a/dolphinscheduler-ui/package.json b/dolphinscheduler-ui/package.json index 9624fa6212..af6f2cd242 100644 --- a/dolphinscheduler-ui/package.json +++ b/dolphinscheduler-ui/package.json @@ -22,6 +22,7 @@ "d3": "^3.5.17", "dagre": "^0.8.5", "dayjs": "^1.7.8", + "element-ui": "2.13.2", "echarts": "4.1.0", "html2canvas": "^0.5.0-beta4", "jquery": "3.3.1", diff --git a/dolphinscheduler-ui/src/js/conf/home/index.js b/dolphinscheduler-ui/src/js/conf/home/index.js index efec218b30..bfa786cdec 100644 --- a/dolphinscheduler-ui/src/js/conf/home/index.js +++ b/dolphinscheduler-ui/src/js/conf/home/index.js @@ -18,6 +18,8 @@ // The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' import App from './App' import router from './router' import store from './store' @@ -39,6 +41,8 @@ import 'canvg/dist/browser/canvg.min.js' // Component internationalization const useOpt = i18n.globalScope.LOCALE === 'en_US' ? { locale: en_US } : {} +Vue.use(ElementUI) + // Vue.use(ans) Vue.use(ans, useOpt) diff --git a/dolphinscheduler-ui/src/js/conf/login/index.js b/dolphinscheduler-ui/src/js/conf/login/index.js index d9b93539bb..55ca0d4876 100644 --- a/dolphinscheduler-ui/src/js/conf/login/index.js +++ b/dolphinscheduler-ui/src/js/conf/login/index.js @@ -19,6 +19,8 @@ // (runtime-only or standalone) has been set in webpack.base.conf with an alias. // import $ from 'jquery' import Vue from 'vue' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' import App from './App' import i18n from '@/module/i18n' import 'ans-ui/lib/ans-ui.min.css' @@ -27,6 +29,8 @@ import ans from 'ans-ui/lib/ans-ui.min' import 'sass/conf/login/index.scss' import 'bootstrap/dist/js/bootstrap.min.js' +Vue.use(ElementUI) + Vue.use(ans) Vue.config.devtools = true From ab884dfde64036e32239f44b04e6a9dd49eb4b48 Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Mon, 7 Sep 2020 15:06:08 +0800 Subject: [PATCH 02/44] Add form-create plug-in and alarm group management add sample demo --- dolphinscheduler-dist/release-docs/LICENSE | 1 + .../LICENSE-@form-create-element-ui | 21 ++++++++ dolphinscheduler-ui/package.json | 5 +- dolphinscheduler-ui/src/js/conf/home/index.js | 4 ++ .../pages/warningGroups/_source/list.vue | 51 ++++++++++++++++++- .../src/js/conf/login/index.js | 4 ++ 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-@form-create-element-ui diff --git a/dolphinscheduler-dist/release-docs/LICENSE b/dolphinscheduler-dist/release-docs/LICENSE index 95cd700970..9a0fdae649 100644 --- a/dolphinscheduler-dist/release-docs/LICENSE +++ b/dolphinscheduler-dist/release-docs/LICENSE @@ -484,6 +484,7 @@ The text of each license is also included at licenses/ui-licenses/LICENSE-[proje ======================================== MIT licenses ======================================== + @form-create/element-ui 1.0.18: https://github.com/xaboy/form-create MIT ans-UI 1.1.7: https://github.com/analysys/ans-ui MIT axios 0.16.2: https://github.com/axios/axios MIT bootstrap 3.3.7: https://github.com/twbs/bootstrap MIT diff --git a/dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-@form-create-element-ui b/dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-@form-create-element-ui new file mode 100644 index 0000000000..5609421fb8 --- /dev/null +++ b/dolphinscheduler-dist/release-docs/licenses/ui-licenses/LICENSE-@form-create-element-ui @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 xaboy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/dolphinscheduler-ui/package.json b/dolphinscheduler-ui/package.json index af6f2cd242..af0ac54b0c 100644 --- a/dolphinscheduler-ui/package.json +++ b/dolphinscheduler-ui/package.json @@ -12,6 +12,7 @@ "build:release": "npm run clean && cross-env NODE_ENV=production PUBLIC_PATH=/dolphinscheduler/ui webpack --config ./build/webpack.config.release.js" }, "dependencies": { + "@form-create/element-ui": "^1.0.18", "@riophae/vue-treeselect": "^0.4.0", "ans-ui": "1.1.9", "axios": "^0.16.2", @@ -22,8 +23,8 @@ "d3": "^3.5.17", "dagre": "^0.8.5", "dayjs": "^1.7.8", - "element-ui": "2.13.2", "echarts": "4.1.0", + "element-ui": "2.13.2", "html2canvas": "^0.5.0-beta4", "jquery": "3.3.1", "jquery-ui": "^1.12.1", @@ -32,7 +33,7 @@ "lodash": "^4.17.11", "normalize.css": "^8.0.1", "vue": "^2.5.17", - "vue-router": "2.7.0", + "vue-router": "^2.7.0", "vuex": "^3.0.0", "vuex-router-sync": "^5.0.0" }, diff --git a/dolphinscheduler-ui/src/js/conf/home/index.js b/dolphinscheduler-ui/src/js/conf/home/index.js index bfa786cdec..d62ac4750d 100644 --- a/dolphinscheduler-ui/src/js/conf/home/index.js +++ b/dolphinscheduler-ui/src/js/conf/home/index.js @@ -38,6 +38,8 @@ import 'bootstrap/dist/css/bootstrap.min.css' import 'bootstrap/dist/js/bootstrap.min.js' import 'canvg/dist/browser/canvg.min.js' +import formCreate, {maker} from '@form-create/element-ui' + // Component internationalization const useOpt = i18n.globalScope.LOCALE === 'en_US' ? { locale: en_US } : {} @@ -46,6 +48,8 @@ Vue.use(ElementUI) // Vue.use(ans) Vue.use(ans, useOpt) +Vue.use(formCreate) + sync(store, router) Vue.config.devtools = true diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningGroups/_source/list.vue b/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningGroups/_source/list.vue index 528693af7d..71e6aa528f 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningGroups/_source/list.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningGroups/_source/list.vue @@ -16,6 +16,9 @@ */ diff --git a/dolphinscheduler-ui/src/sass/common/_table.scss b/dolphinscheduler-ui/src/sass/common/_table.scss index d643053bfc..074ecb6ba5 100644 --- a/dolphinscheduler-ui/src/sass/common/_table.scss +++ b/dolphinscheduler-ui/src/sass/common/_table.scss @@ -174,3 +174,9 @@ .el-table--enable-row-hover .el-table__body tr:hover>td { background-color: #ddecff; } +.el-table th>.cell { + color: #555; +} +.el-table td div { + color: #666; +} diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java b/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java index 2f7a5f9ca3..5eb07049ac 100644 --- a/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java +++ b/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java @@ -35,9 +35,9 @@ public class TenantManageLocator{ public static final By SUBMIT_BUTTON = By.xpath("//div[3]/button[2]/span"); - public static final By DELETE_TENANT_BUTTON = By.xpath("//div[3]/div[1]/div/table/tr[2]/td[8]/span/button"); + public static final By DELETE_TENANT_BUTTON = By.xpath("//table/tbody/tr[1]/td[8]/div/span/button/i"); - public static final By CONFIRM_DELETE_TENANT_BUTTON = By.xpath("//div[2]/div/button[2]/span"); + public static final By CONFIRM_DELETE_TENANT_BUTTON = By.xpath("//div[1]/div/button[2]/span"); - public static final By TENANT_CODE_FIRST = By.xpath("//table/tr[2]/td[2]/span"); + public static final By TENANT_CODE_FIRST = By.xpath("//table/tbody/tr[1]/td[2]/div"); } From 2df6ecb2fcbf68ca7072867431d64f226ac910e6 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Thu, 22 Oct 2020 19:57:30 +0800 Subject: [PATCH 09/44] the alert module support service. --- dolphinscheduler-alert/pom.xml | 4 + .../dolphinscheduler/alert/AlertServer.java | 52 +++++++- .../processor/AlertRequestProcessor.java | 67 ++++++++++ .../alert/runner/AlertSender.java | 115 ++++++++++++++---- dolphinscheduler-remote/pom.xml | 4 + .../remote/command/CommandType.java | 2 +- .../alert/AlertSendRequestCommand.java | 80 ++++++++++++ .../alert/AlertSendResponseCommand.java | 76 ++++++++++++ .../service/alert/AlertClientService.java | 96 +++++++++++++++ .../service/alert/AlertClientServiceTest.java | 58 +++++++++ .../spi/alert/AlertResult.java | 2 + 11 files changed, 527 insertions(+), 29 deletions(-) create mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java create mode 100644 dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommand.java create mode 100644 dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java create mode 100644 dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java create mode 100644 dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java diff --git a/dolphinscheduler-alert/pom.xml b/dolphinscheduler-alert/pom.xml index e79c9a2b20..abae84515a 100644 --- a/dolphinscheduler-alert/pom.xml +++ b/dolphinscheduler-alert/pom.xml @@ -35,6 +35,10 @@ org.apache.dolphinscheduler dolphinscheduler-spi + + org.apache.dolphinscheduler + dolphinscheduler-remote + junit junit 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 index ccd359da18..45184f03a4 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.alert; import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; import org.apache.dolphinscheduler.alert.plugin.DolphinPluginLoader; import org.apache.dolphinscheduler.alert.plugin.DolphinPluginManagerConfig; +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.alert.utils.PropertyUtils; @@ -28,6 +29,9 @@ 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.utils.StringUtils; import java.util.List; @@ -63,6 +67,11 @@ public class AlertServer { public static final String MAVEN_LOCAL_REPOSITORY = "maven.local.repository"; + /** + * netty server + */ + private NettyRemotingServer server; + private static class AlertServerHolder { private static final AlertServer INSTANCE = new AlertServer(); } @@ -96,11 +105,21 @@ public class AlertServer { } } - public void start() { - - initPlugin(); + /** + * init netty remoting server + */ + private void initRemoteServer() { + NettyServerConfig serverConfig = new NettyServerConfig(); + serverConfig.setListenPort(50501); + this.server = new NettyRemotingServer(serverConfig); + this.server.registerProcessor(CommandType.ALERT_SEND_REQUEST, new AlertRequestProcessor(alertDao, alertPluginManager, pluginDao)); + this.server.start(); + } - logger.info("alert server ready start "); + /** + * Cyclic alert info sending alert + */ + private void runSender() { while (Stopper.isRunning()) { try { Thread.sleep(Constants.ALERT_SCAN_INTERVAL); @@ -118,10 +137,35 @@ public class AlertServer { } } + /** + * start + */ + public void start() { + initPlugin(); + initRemoteServer(); + logger.info("alert server ready start "); + runSender(); + } + + /** + * stop + */ + public void stop() { + this.server.close(); + logger.info("alert server shut down"); + } + public static void main(String[] args) { System.out.println(System.getProperty("user.dir")); AlertServer alertServer = AlertServer.getInstance(); alertServer.start(); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + alertServer.stop(); + } + }); + } } diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java new file mode 100644 index 0000000000..5e8a8f89d6 --- /dev/null +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessor.java @@ -0,0 +1,67 @@ +/* + * 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.processor; + +import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +import org.apache.dolphinscheduler.alert.runner.AlertSender; +import org.apache.dolphinscheduler.common.utils.Preconditions; +import org.apache.dolphinscheduler.dao.AlertDao; +import org.apache.dolphinscheduler.dao.PluginDao; +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.CommandType; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; +import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor; +import org.apache.dolphinscheduler.remote.utils.JsonSerializer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.channel.Channel; + +/** + * alert request processor + */ +public class AlertRequestProcessor implements NettyRequestProcessor { + + private final Logger logger = LoggerFactory.getLogger(AlertRequestProcessor.class); + private AlertDao alertDao; + private PluginDao pluginDao; + private AlertPluginManager alertPluginManager; + + public AlertRequestProcessor(AlertDao alertDao, AlertPluginManager alertPluginManager, PluginDao pluginDao) { + this.alertDao = alertDao; + this.pluginDao = pluginDao; + this.alertPluginManager = alertPluginManager; + } + + @Override + public void process(Channel channel, Command command) { + Preconditions.checkArgument(CommandType.ALERT_SEND_REQUEST == command.getType(), + String.format("invalid command type : %s", command.getType())); + + AlertSendRequestCommand alertSendRequestCommand = JsonSerializer.deserialize( + command.getBody(), AlertSendRequestCommand.class); + logger.info("received command : {}", alertSendRequestCommand); + + AlertSender alertSender = new AlertSender(alertDao, alertPluginManager, pluginDao); + 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/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java index 4714a76ff1..341cd5f88a 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java @@ -23,11 +23,13 @@ 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.remote.command.alert.AlertSendResponseCommand; 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 java.util.ArrayList; import java.util.List; import org.slf4j.Logger; @@ -49,6 +51,13 @@ public class AlertSender { this.alertPluginManager = alertPluginManager; } + public AlertSender(AlertDao alertDao, AlertPluginManager alertPluginManager, PluginDao pluginDao) { + super(); + this.alertDao = alertDao; + this.pluginDao = pluginDao; + this.alertPluginManager = alertPluginManager; + } + public AlertSender(List alertList, AlertDao alertDao, AlertPluginManager alertPluginManager, PluginDao pluginDao) { super(); this.alertList = alertList; @@ -71,33 +80,91 @@ public class AlertSender { for (AlertPluginInstance instance : alertInstanceList) { - String pluginName = pluginDao.getPluginDefineById(instance.getPluginDefineId()).getPluginName(); - String pluginInstanceName = instance.getInstanceName(); - AlertInfo alertInfo = new AlertInfo(); - alertInfo.setAlertData(alertData); - alertInfo.setAlertParams(instance.getPluginInstanceParams()); - AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); - if (alertChannel == null) { - alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, "Alert send error, not found plugin " + pluginName, alert.getId()); - logger.error("Alert Plugin {} send error : not found plugin {}", pluginInstanceName, pluginName); - continue; - } - - AlertResult alertResult = alertChannel.process(alertInfo); - - if (alertResult == null) { - alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, "alert send error", alert.getId()); - logger.info("Alert Plugin {} send error : return value is null", pluginInstanceName); - } else if (!Boolean.parseBoolean(String.valueOf(alertResult.getStatus()))) { - alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, String.valueOf(alertResult.getMessage()), alert.getId()); - logger.info("Alert Plugin {} send error : {}", pluginInstanceName, alertResult.getMessage()); - } else { - alertDao.updateAlert(AlertStatus.EXECUTION_SUCCESS, alertResult.getMessage(), alert.getId()); - logger.info("Alert Plugin {} send success", pluginInstanceName); - } + AlertResult alertResult = getAlertResult(instance, alertData); + AlertStatus alertStatus = Boolean.parseBoolean(String.valueOf(alertResult.getStatus())) ? AlertStatus.EXECUTION_SUCCESS : AlertStatus.EXECUTION_FAILURE; + alertDao.updateAlert(alertStatus, alertResult.getMessage(), alert.getId()); + } } } + /** + * sync send alert handler + * @param alertGroupId alertGroupId + * @param title title + * @param content content + * @return AlertSendResponseCommand + */ + public AlertSendResponseCommand syncHandler(int alertGroupId, String title, String content) { + + List alertInstanceList = alertDao.listInstanceByAlertGroupId(alertGroupId); + AlertData alertData = new AlertData(); + alertData.setContent(title) + .setTitle(content); + + boolean sendResponseStatus = true; + List sendResponseResults = new ArrayList<>(); + + if (alertInstanceList == null || alertInstanceList.size() == 0) { + sendResponseStatus = false; + AlertResult alertResult = new AlertResult(); + String message = String.format("Alert GroupId %s send error : not found alert instance",alertGroupId); + alertResult.setStatus("false"); + alertResult.setMessage(message); + sendResponseResults.add(alertResult); + logger.error("Alert GroupId {} send error : not found alert instance", alertGroupId); + } + + for (AlertPluginInstance instance : alertInstanceList) { + + AlertResult alertResult = getAlertResult(instance, alertData); + sendResponseStatus = sendResponseStatus && Boolean.parseBoolean(String.valueOf(alertResult.getStatus())); + sendResponseResults.add(alertResult); + } + + return new AlertSendResponseCommand(sendResponseStatus,sendResponseResults); + } + + /** + * alert result expansion + * @param instance instance + * @param alertData alertData + * @return AlertResult + */ + private AlertResult getAlertResult(AlertPluginInstance instance, AlertData alertData) { + String pluginName = pluginDao.getPluginDefineById(instance.getPluginDefineId()).getPluginName(); + AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); + AlertResult alertResultExtend = new AlertResult(); + String pluginInstanceName = instance.getInstanceName(); + if (alertChannel == null) { + String message = String.format("Alert Plugin %s send error : return value is null",pluginInstanceName); + alertResultExtend.setStatus("false"); + alertResultExtend.setMessage(message); + logger.error("Alert Plugin {} send error : not found plugin {}", pluginInstanceName, pluginName); + } + + AlertInfo alertInfo = new AlertInfo(); + alertInfo.setAlertData(alertData); + alertInfo.setAlertParams(instance.getPluginInstanceParams()); + AlertResult alertResult = alertChannel.process(alertInfo); + + if (alertResult == null) { + String message = String.format("Alert Plugin %s send error : return value is null",pluginInstanceName); + alertResultExtend.setStatus("false"); + alertResultExtend.setMessage(message); + logger.info("Alert Plugin {} send error : return value is null", pluginInstanceName); + } else if (!Boolean.parseBoolean(String.valueOf(alertResult.getStatus()))) { + alertResultExtend.setStatus("false"); + alertResultExtend.setMessage(alertResult.getMessage()); + logger.info("Alert Plugin {} send error : {}", pluginInstanceName, alertResult.getMessage()); + } else { + String message = String.format("Alert Plugin %s send success",pluginInstanceName); + alertResultExtend.setStatus("true"); + alertResultExtend.setMessage(message); + logger.info("Alert Plugin {} send success", pluginInstanceName); + } + return alertResultExtend; + } + } diff --git a/dolphinscheduler-remote/pom.xml b/dolphinscheduler-remote/pom.xml index 4d398f3069..bc71241076 100644 --- a/dolphinscheduler-remote/pom.xml +++ b/dolphinscheduler-remote/pom.xml @@ -35,6 +35,10 @@ + + org.apache.dolphinscheduler + dolphinscheduler-spi + io.netty netty-all diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/CommandType.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/CommandType.java index d1ffc65f57..753216995e 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/CommandType.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/CommandType.java @@ -1 +1 @@ -/* * 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.remote.command; public enum CommandType { /** * remove task log request, */ REMOVE_TAK_LOG_REQUEST, /** * remove task log response */ REMOVE_TAK_LOG_RESPONSE, /** * roll view log request */ ROLL_VIEW_LOG_REQUEST, /** * roll view log response */ ROLL_VIEW_LOG_RESPONSE, /** * view whole log request */ VIEW_WHOLE_LOG_REQUEST, /** * view whole log response */ VIEW_WHOLE_LOG_RESPONSE, /** * get log bytes request */ GET_LOG_BYTES_REQUEST, /** * get log bytes response */ GET_LOG_BYTES_RESPONSE, WORKER_REQUEST, MASTER_RESPONSE, /** * execute task request */ TASK_EXECUTE_REQUEST, /** * execute task ack */ TASK_EXECUTE_ACK, /** * execute task response */ TASK_EXECUTE_RESPONSE, /** * kill task */ TASK_KILL_REQUEST, /** * kill task response */ TASK_KILL_RESPONSE, /** * ping */ PING, /** * pong */ PONG; } \ No newline at end of file +/* * 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.remote.command; public enum CommandType { /** * remove task log request, */ REMOVE_TAK_LOG_REQUEST, /** * remove task log response */ REMOVE_TAK_LOG_RESPONSE, /** * roll view log request */ ROLL_VIEW_LOG_REQUEST, /** * roll view log response */ ROLL_VIEW_LOG_RESPONSE, /** * view whole log request */ VIEW_WHOLE_LOG_REQUEST, /** * view whole log response */ VIEW_WHOLE_LOG_RESPONSE, /** * get log bytes request */ GET_LOG_BYTES_REQUEST, /** * get log bytes response */ GET_LOG_BYTES_RESPONSE, WORKER_REQUEST, MASTER_RESPONSE, /** * execute task request */ TASK_EXECUTE_REQUEST, /** * execute task ack */ TASK_EXECUTE_ACK, /** * execute task response */ TASK_EXECUTE_RESPONSE, /** * kill task */ TASK_KILL_REQUEST, /** * kill task response */ TASK_KILL_RESPONSE, /** * ping */ PING, /** * pong */ PONG, /** * alert send request */ ALERT_SEND_REQUEST, /** * alert send response */ ALERT_SEND_RESPONSE; } \ No newline at end of file diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommand.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommand.java new file mode 100644 index 0000000000..da56b0dc6b --- /dev/null +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommand.java @@ -0,0 +1,80 @@ +/* + * 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.remote.command.alert; + +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.CommandType; +import org.apache.dolphinscheduler.remote.utils.JsonSerializer; + +import java.io.Serializable; + +public class AlertSendRequestCommand implements Serializable { + + private int groupId; + + private String title; + + private String content; + + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public AlertSendRequestCommand(){ + + } + + public AlertSendRequestCommand(int groupId, String title, String content) { + this.groupId = groupId; + this.title = title; + this.content = content; + } + + /** + * package request command + * + * @return command + */ + public Command convert2Command() { + Command command = new Command(); + command.setType(CommandType.ALERT_SEND_REQUEST); + byte[] body = JsonSerializer.serialize(this); + command.setBody(body); + return command; + } +} diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java new file mode 100644 index 0000000000..fbde4cfe51 --- /dev/null +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java @@ -0,0 +1,76 @@ +/* + * 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.remote.command.alert; + +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.CommandType; +import org.apache.dolphinscheduler.remote.utils.JsonSerializer; +import org.apache.dolphinscheduler.spi.alert.AlertResult; + +import java.io.Serializable; +import java.util.List; + +public class AlertSendResponseCommand implements Serializable { + + /** + * true:All alert are successful, + * false:As long as one alert fails + */ + private boolean alertStatus; + + private List alertResults; + + public boolean getAlertStatus() { + return alertStatus; + } + + public void setAlertStatus(boolean alertStatus) { + this.alertStatus = alertStatus; + } + + public List getAlertResults() { + return alertResults; + } + + public void setAlertResults(List alertResults) { + this.alertResults = alertResults; + } + + public AlertSendResponseCommand() { + + } + + public AlertSendResponseCommand(boolean alertStatus, List alertResults) { + this.alertStatus = alertStatus; + this.alertResults = alertResults; + } + + /** + * package response command + * + * @param opaque request unique identification + * @return command + */ + public Command convert2Command(long opaque) { + Command command = new Command(opaque); + command.setType(CommandType.ALERT_SEND_RESPONSE); + byte[] body = JsonSerializer.serialize(this); + command.setBody(body); + return command; + } +} diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java new file mode 100644 index 0000000000..9581413c39 --- /dev/null +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java @@ -0,0 +1,96 @@ +/* + * 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.service.alert; + +import org.apache.dolphinscheduler.remote.NettyRemotingClient; +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; +import org.apache.dolphinscheduler.remote.config.NettyClientConfig; +import org.apache.dolphinscheduler.remote.utils.Host; +import org.apache.dolphinscheduler.remote.utils.JsonSerializer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AlertClientService { + + private static final Logger logger = LoggerFactory.getLogger(AlertClientService.class); + + private final NettyClientConfig clientConfig; + + private final NettyRemotingClient client; + + private volatile boolean isRunning; + + /** + * request time out + */ + private static final long ALERT_REQUEST_TIMEOUT = 10 * 1000L; + + /** + * alert client + */ + public AlertClientService() { + this.clientConfig = new NettyClientConfig(); + this.client = new NettyRemotingClient(clientConfig); + this.isRunning = true; + } + + /** + * close + */ + public void close() { + this.client.close(); + this.isRunning = false; + logger.info("alter client closed"); + } + + /** + * alert sync send data + * @param host host + * @param port port + * @param groupId groupId + * @param title title + * @param content content + * @return AlertSendResponseCommand + */ + public AlertSendResponseCommand sendAlert(String host, int port, int groupId, String title, String content) { + logger.info("sync alert send, host : {}, port : {}, groupId : {}, title : {} ", host, port, groupId, title); + AlertSendRequestCommand request = new AlertSendRequestCommand(groupId, title, content); + final Host address = new Host(host, port); + try { + Command command = request.convert2Command(); + Command response = this.client.sendSync(address, command, ALERT_REQUEST_TIMEOUT); + if (response != null) { + AlertSendResponseCommand sendResponse = JsonSerializer.deserialize( + response.getBody(), AlertSendResponseCommand.class); + return sendResponse; + } + } catch (Exception e) { + logger.error("sync alert send error", e); + } finally { + this.client.closeChannel(address); + } + return null; + } + + public boolean isRunning() { + return isRunning; + } +} diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java new file mode 100644 index 0000000000..98f2b14d54 --- /dev/null +++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java @@ -0,0 +1,58 @@ +/* + * 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.service.alert; + +import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; + +/** + * alert client service test + */ +public class AlertClientServiceTest { + + private static final Logger logger = LoggerFactory.getLogger(AlertClientServiceTest.class); + + + @Test + public void testSendAlert(){ + String host; + int port = 50501; + int groupId = 1; + String title = "test-title"; + String content = "test-content"; + AlertClientService alertClient = new AlertClientService(); + + // alter server does not exist + host = "128.0.10.1"; + AlertSendResponseCommand alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); + Assert.assertNull(alertSendResponseCommand); + + host = "127.0.0.1"; + AlertSendResponseCommand alertSendResponseCommand_1 = alertClient.sendAlert(host, port, groupId, title, content); + + if (Objects.nonNull(alertClient) && alertClient.isRunning()) { + alertClient.close(); + } + + } +} 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 index a327d09403..f91db97651 100644 --- 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 @@ -38,4 +38,6 @@ public class AlertResult { public void setMessage(String message) { this.message = message; } + + } From 30d75f21856ec86a41db914a3c21d7606effdab0 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Fri, 23 Oct 2020 09:55:27 +0800 Subject: [PATCH 10/44] the alert module support service. --- dolphinscheduler-alert/pom.xml | 4 ++++ .../java/org/apache/dolphinscheduler/alert/AlertServer.java | 4 +++- .../java/org/apache/dolphinscheduler/common/Constants.java | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-alert/pom.xml b/dolphinscheduler-alert/pom.xml index abae84515a..ebea0e8716 100644 --- a/dolphinscheduler-alert/pom.xml +++ b/dolphinscheduler-alert/pom.xml @@ -39,6 +39,10 @@ org.apache.dolphinscheduler dolphinscheduler-remote + + org.apache.dolphinscheduler + dolphinscheduler-common + junit junit 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 index 45184f03a4..41e76b370b 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -17,6 +17,8 @@ package org.apache.dolphinscheduler.alert; +import static org.apache.dolphinscheduler.common.Constants.ALERT_RPC_PORT; + import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; import org.apache.dolphinscheduler.alert.plugin.DolphinPluginLoader; import org.apache.dolphinscheduler.alert.plugin.DolphinPluginManagerConfig; @@ -110,7 +112,7 @@ public class AlertServer { */ private void initRemoteServer() { NettyServerConfig serverConfig = new NettyServerConfig(); - serverConfig.setListenPort(50501); + serverConfig.setListenPort(ALERT_RPC_PORT); this.server = new NettyRemotingServer(serverConfig); this.server.registerProcessor(CommandType.ALERT_SEND_REQUEST, new AlertRequestProcessor(alertDao, alertPluginManager, pluginDao)); this.server.start(); diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java index a8d04ced46..5c0ae1d638 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java @@ -387,13 +387,17 @@ public final class Constants { */ public static final int SEC_2_MINUTES_TIME_UNIT = 60; - /*** * * rpc port */ public static final int RPC_PORT = 50051; + /*** + * alert rpc port + */ + public static final int ALERT_RPC_PORT = 50052; + /** * forbid running task */ From 36cfcc43ce39f62b83144e3b62240b962a504384 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Fri, 23 Oct 2020 12:45:42 +0800 Subject: [PATCH 11/44] Delete blank lines. --- .../java/org/apache/dolphinscheduler/spi/alert/AlertResult.java | 2 -- 1 file changed, 2 deletions(-) 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 index f91db97651..a327d09403 100644 --- 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 @@ -38,6 +38,4 @@ public class AlertResult { public void setMessage(String message) { this.message = message; } - - } From a263455d6a7d1f596d19acf2f799179b42ac26f9 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Fri, 23 Oct 2020 13:08:07 +0800 Subject: [PATCH 12/44] add code checkstyle. --- .../service/alert/AlertClientServiceTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java index 98f2b14d54..1624c7dbaa 100644 --- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java +++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java @@ -18,13 +18,14 @@ package org.apache.dolphinscheduler.service.alert; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; + +import java.util.Objects; + import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Objects; - /** * alert client service test */ @@ -32,9 +33,8 @@ public class AlertClientServiceTest { private static final Logger logger = LoggerFactory.getLogger(AlertClientServiceTest.class); - @Test - public void testSendAlert(){ + public void testSendAlert() { String host; int port = 50501; int groupId = 1; @@ -48,7 +48,7 @@ public class AlertClientServiceTest { Assert.assertNull(alertSendResponseCommand); host = "127.0.0.1"; - AlertSendResponseCommand alertSendResponseCommand_1 = alertClient.sendAlert(host, port, groupId, title, content); + alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); if (Objects.nonNull(alertClient) && alertClient.isRunning()) { alertClient.close(); From 5c1561a32fdb9f0e61e33c774818b995e87d08af Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Fri, 23 Oct 2020 19:03:52 +0800 Subject: [PATCH 13/44] Solve the sonar bug. --- .../org/apache/dolphinscheduler/alert/runner/AlertSender.java | 1 + pom.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java index 341cd5f88a..01152af757 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java @@ -142,6 +142,7 @@ public class AlertSender { alertResultExtend.setStatus("false"); alertResultExtend.setMessage(message); logger.error("Alert Plugin {} send error : not found plugin {}", pluginInstanceName, pluginName); + return alertResultExtend; } AlertInfo alertInfo = new AlertInfo(); diff --git a/pom.xml b/pom.xml index c2cb96e27a..5b45dbce00 100644 --- a/pom.xml +++ b/pom.xml @@ -917,6 +917,7 @@ **/service/zk/ZKServerTest.java **/service/zk/CuratorZookeeperClientTest.java **/service/queue/TaskUpdateQueueTest.java + **/service/alert/AlertClientServiceTest.java **/dao/mapper/DataSourceUserMapperTest.java From 33413177aa3cfd65f33249c2bc7137bd655299f8 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Sat, 24 Oct 2020 12:47:40 +0800 Subject: [PATCH 14/44] Re-execute build. --- .../main/java/org/apache/dolphinscheduler/alert/AlertServer.java | 1 - 1 file changed, 1 deletion(-) 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 index 41e76b370b..30b3d8eedf 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -167,7 +167,6 @@ public class AlertServer { alertServer.stop(); } }); - } } From 500d481e726765fa5dbc18a3d76fc7f0ed97a696 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Tue, 27 Oct 2020 13:32:54 +0800 Subject: [PATCH 15/44] add test. --- .../alert/runner/AlertSender.java | 7 +- .../alert/AlertSendRequestCommandTest.java | 37 ++++++ .../alert/AlertSendResponseCommandTest.java | 34 ++++++ .../service/alert/AlertClientServiceTest.java | 106 +++++++++++++++++- pom.xml | 2 + 5 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java create mode 100644 dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java index 01152af757..89f4fb4fc2 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.alert.runner; import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; import org.apache.dolphinscheduler.common.enums.AlertStatus; +import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.PluginDao; import org.apache.dolphinscheduler.dao.entity.Alert; @@ -106,7 +107,7 @@ public class AlertSender { boolean sendResponseStatus = true; List sendResponseResults = new ArrayList<>(); - if (alertInstanceList == null || alertInstanceList.size() == 0) { + if (CollectionUtils.isEmpty(alertInstanceList)) { sendResponseStatus = false; AlertResult alertResult = new AlertResult(); String message = String.format("Alert GroupId %s send error : not found alert instance",alertGroupId); @@ -151,10 +152,10 @@ public class AlertSender { AlertResult alertResult = alertChannel.process(alertInfo); if (alertResult == null) { - String message = String.format("Alert Plugin %s send error : return value is null",pluginInstanceName); + String message = String.format("Alert Plugin %s send error : return alertResult value is null",pluginInstanceName); alertResultExtend.setStatus("false"); alertResultExtend.setMessage(message); - logger.info("Alert Plugin {} send error : return value is null", pluginInstanceName); + logger.info("Alert Plugin {} send error : return alertResult value is null", pluginInstanceName); } else if (!Boolean.parseBoolean(String.valueOf(alertResult.getStatus()))) { alertResultExtend.setStatus("false"); alertResultExtend.setMessage(alertResult.getMessage()); diff --git a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java new file mode 100644 index 0000000000..4d0e59c082 --- /dev/null +++ b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java @@ -0,0 +1,37 @@ +/* + * 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.remote.command.alert; + +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.CommandType; + +import org.junit.Assert; +import org.junit.Test; + +public class AlertSendRequestCommandTest { + + @Test + public void testConvert2Command() { + int groupId = 1; + String title = "test-title"; + String content = "test-content"; + AlertSendRequestCommand requestCommand = new AlertSendRequestCommand(groupId,title,content); + Command command = requestCommand.convert2Command(); + Assert.assertEquals(CommandType.ALERT_SEND_REQUEST,command.getType()); + } +} diff --git a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java new file mode 100644 index 0000000000..d55807f4b6 --- /dev/null +++ b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java @@ -0,0 +1,34 @@ +/* + * 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.remote.command.alert; + +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.CommandType; + +import org.junit.Assert; +import org.junit.Test; + +public class AlertSendResponseCommandTest { + + @Test + public void testConvert2Command() { + AlertSendResponseCommand alertSendResponseCommand = new AlertSendResponseCommand(); + Command command = alertSendResponseCommand.convert2Command(1); + Assert.assertEquals(CommandType.ALERT_SEND_RESPONSE,command.getType()); + } +} diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java index 1624c7dbaa..68518f6b7a 100644 --- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java +++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java @@ -17,42 +17,136 @@ package org.apache.dolphinscheduler.service.alert; +import org.apache.dolphinscheduler.remote.NettyRemotingClient; +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; +import org.apache.dolphinscheduler.spi.alert.AlertResult; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * alert client service test */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({AlertClientService.class}) public class AlertClientServiceTest { private static final Logger logger = LoggerFactory.getLogger(AlertClientServiceTest.class); + private NettyRemotingClient client; + + private AlertClientService alertClient; + + @Before + public void before() throws Exception { + client = PowerMockito.mock(NettyRemotingClient.class); + PowerMockito.whenNew(NettyRemotingClient.class).withAnyArguments().thenReturn(client); + alertClient = new AlertClientService(); + } + @Test - public void testSendAlert() { - String host; + public void testSendAlert() throws Exception { + String host = "127.0.0.1"; int port = 50501; int groupId = 1; String title = "test-title"; String content = "test-content"; - AlertClientService alertClient = new AlertClientService(); - // alter server does not exist - host = "128.0.10.1"; + //1.alter server does not exist AlertSendResponseCommand alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); Assert.assertNull(alertSendResponseCommand); - host = "127.0.0.1"; + AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(); + Command reqCommand = alertSendRequestCommand.convert2Command(); + boolean sendResponseStatus; + List sendResponseResults = new ArrayList<>(); + + //2.alter instance does not exist + sendResponseStatus = false; + AlertResult alertResult = new AlertResult(); + String message = String.format("Alert GroupId %s send error : not found alert instance",groupId); + alertResult.setStatus("false"); + alertResult.setMessage(message); + sendResponseResults.add(alertResult); + AlertSendResponseCommand alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); + Command resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); + + PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); + alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); + Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); + alertSendResponseCommand.getAlertResults().forEach(result -> + logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); + + //3.alter plugin does not exist + sendResponseStatus = false; + String pluginInstanceName = "alert-mail"; + message = String.format("Alert Plugin %s send error : return value is null",pluginInstanceName); + alertResult.setStatus("false"); + alertResult.setMessage(message); + alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); + resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); + PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); + Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); + alertSendResponseCommand.getAlertResults().forEach(result -> + logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); + + //4.alter result is null + sendResponseStatus = false; + message = String.format("Alert Plugin %s send error : return result value is null",pluginInstanceName); + alertResult.setStatus("false"); + alertResult.setMessage(message); + alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); + resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); + PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); + alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); + Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); + alertSendResponseCommand.getAlertResults().forEach(result -> + logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); + + //5.abnormal information inside the alert plug-in code + sendResponseStatus = false; + alertResult.setStatus("false"); + alertResult.setMessage("Abnormal information inside the alert plug-in code"); + alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); + resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); + PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); + alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); + Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); + alertSendResponseCommand.getAlertResults().forEach(result -> + logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); + + //6.alert plugin send success + sendResponseStatus = true; + message = String.format("Alert Plugin %s send success",pluginInstanceName); + alertResult.setStatus("true"); + alertResult.setMessage(message); + alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); + resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); + PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); + alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); + Assert.assertTrue(alertSendResponseCommand.getAlertStatus()); + alertSendResponseCommand.getAlertResults().forEach(result -> + logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); if (Objects.nonNull(alertClient) && alertClient.isRunning()) { alertClient.close(); } } + } diff --git a/pom.xml b/pom.xml index 5b45dbce00..f6075a92bf 100644 --- a/pom.xml +++ b/pom.xml @@ -867,6 +867,8 @@ **/remote/NettyRemotingClientTest.java **/remote/NettyUtilTest.java **/remote/ResponseFutureTest.java + **/remote/command/alert/AlertSendRequestCommandTest.java + **/remote/command/alert/AlertSendResponseCommandTest.java **/server/log/LoggerServerTest.java **/server/entity/SQLTaskExecutionContextTest.java **/server/log/MasterLogFilterTest.java From 0fdb001319e1f6c6385e0cffab298d2d51a7859d Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Wed, 28 Oct 2020 10:36:25 +0800 Subject: [PATCH 16/44] update ut. --- dolphinscheduler-remote/pom.xml | 4 ---- .../alert/AlertSendResponseCommand.java | 18 ++---------------- .../alert/AlertSendRequestCommandTest.java | 5 +++++ 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/dolphinscheduler-remote/pom.xml b/dolphinscheduler-remote/pom.xml index bc71241076..4d398f3069 100644 --- a/dolphinscheduler-remote/pom.xml +++ b/dolphinscheduler-remote/pom.xml @@ -35,10 +35,6 @@ - - org.apache.dolphinscheduler - dolphinscheduler-spi - io.netty netty-all diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java index fbde4cfe51..e3cb1474a5 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java @@ -31,25 +31,11 @@ public class AlertSendResponseCommand implements Serializable { * true:All alert are successful, * false:As long as one alert fails */ - private boolean alertStatus; + private boolean resStatus; - private List alertResults; + private List resResults; - public boolean getAlertStatus() { - return alertStatus; - } - - public void setAlertStatus(boolean alertStatus) { - this.alertStatus = alertStatus; - } - public List getAlertResults() { - return alertResults; - } - - public void setAlertResults(List alertResults) { - this.alertResults = alertResults; - } public AlertSendResponseCommand() { diff --git a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java index 4d0e59c082..79d21316f8 100644 --- a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java +++ b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendRequestCommandTest.java @@ -33,5 +33,10 @@ public class AlertSendRequestCommandTest { AlertSendRequestCommand requestCommand = new AlertSendRequestCommand(groupId,title,content); Command command = requestCommand.convert2Command(); Assert.assertEquals(CommandType.ALERT_SEND_REQUEST,command.getType()); + AlertSendRequestCommand verifyCommand = new AlertSendRequestCommand(); + verifyCommand.setGroupId(groupId); + verifyCommand.setContent(content); + verifyCommand.setTitle(title); + } } From 54802bb531243f226c32b82c96899e54fd599488 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Wed, 28 Oct 2020 17:56:28 +0800 Subject: [PATCH 17/44] add test class. --- .../alert/runner/AlertSender.java | 35 ++-- .../alert/AlertServerTest.java | 85 +++++++++ .../processor/AlertRequestProcessorTest.java | 58 ++++++ .../alert/runner/AlertSenderTest.java | 180 ++++++++++++++++++ .../alert/AlertSendResponseCommand.java | 23 ++- .../alert/AlertSendResponseResult.java | 52 +++++ .../alert/AlertSendResponseCommandTest.java | 14 ++ .../service/alert/AlertClientService.java | 4 +- .../service/alert/AlertClientServiceTest.java | 38 ++-- pom.xml | 3 + 10 files changed, 449 insertions(+), 43 deletions(-) create mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java create mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java create mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java create mode 100644 dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseResult.java diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java index 89f4fb4fc2..2b8fec2f11 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java @@ -25,6 +25,7 @@ import org.apache.dolphinscheduler.dao.PluginDao; 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; @@ -81,7 +82,7 @@ public class AlertSender { for (AlertPluginInstance instance : alertInstanceList) { - AlertResult alertResult = getAlertResult(instance, alertData); + 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()); @@ -105,42 +106,44 @@ public class AlertSender { .setTitle(content); boolean sendResponseStatus = true; - List sendResponseResults = new ArrayList<>(); + List sendResponseResults = new ArrayList<>(); if (CollectionUtils.isEmpty(alertInstanceList)) { sendResponseStatus = false; - AlertResult alertResult = new AlertResult(); + AlertSendResponseResult alertSendResponseResult = new AlertSendResponseResult(); String message = String.format("Alert GroupId %s send error : not found alert instance",alertGroupId); - alertResult.setStatus("false"); - alertResult.setMessage(message); - sendResponseResults.add(alertResult); + alertSendResponseResult.setStatus(sendResponseStatus); + alertSendResponseResult.setMessage(message); + sendResponseResults.add(alertSendResponseResult); logger.error("Alert GroupId {} send error : not found alert instance", alertGroupId); + return new AlertSendResponseCommand(sendResponseStatus,sendResponseResults); } for (AlertPluginInstance instance : alertInstanceList) { - - AlertResult alertResult = getAlertResult(instance, alertData); - sendResponseStatus = sendResponseStatus && Boolean.parseBoolean(String.valueOf(alertResult.getStatus())); - sendResponseResults.add(alertResult); + AlertResult alertResult = this.alertResultHandler(instance, alertData); + AlertSendResponseResult alertSendResponseResult = new AlertSendResponseResult( + Boolean.parseBoolean(String.valueOf(alertResult.getStatus())),alertResult.getMessage()); + sendResponseStatus = sendResponseStatus && alertSendResponseResult.getStatus(); + sendResponseResults.add(alertSendResponseResult); } return new AlertSendResponseCommand(sendResponseStatus,sendResponseResults); } /** - * alert result expansion + * alert result handler * @param instance instance * @param alertData alertData * @return AlertResult */ - private AlertResult getAlertResult(AlertPluginInstance instance, AlertData alertData) { + private AlertResult alertResultHandler(AlertPluginInstance instance, AlertData alertData) { String pluginName = pluginDao.getPluginDefineById(instance.getPluginDefineId()).getPluginName(); AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); AlertResult alertResultExtend = new AlertResult(); String pluginInstanceName = instance.getInstanceName(); if (alertChannel == null) { String message = String.format("Alert Plugin %s send error : return value is null",pluginInstanceName); - alertResultExtend.setStatus("false"); + alertResultExtend.setStatus(String.valueOf(false)); alertResultExtend.setMessage(message); logger.error("Alert Plugin {} send error : not found plugin {}", pluginInstanceName, pluginName); return alertResultExtend; @@ -153,16 +156,16 @@ public class AlertSender { if (alertResult == null) { String message = String.format("Alert Plugin %s send error : return alertResult value is null",pluginInstanceName); - alertResultExtend.setStatus("false"); + alertResultExtend.setStatus(String.valueOf(false)); alertResultExtend.setMessage(message); logger.info("Alert Plugin {} send error : return alertResult value is null", pluginInstanceName); } else if (!Boolean.parseBoolean(String.valueOf(alertResult.getStatus()))) { - alertResultExtend.setStatus("false"); + alertResultExtend.setStatus(String.valueOf(false)); alertResultExtend.setMessage(alertResult.getMessage()); logger.info("Alert Plugin {} send error : {}", pluginInstanceName, alertResult.getMessage()); } else { String message = String.format("Alert Plugin %s send success",pluginInstanceName); - alertResultExtend.setStatus("true"); + alertResultExtend.setStatus(String.valueOf(true)); alertResultExtend.setMessage(message); logger.info("Alert Plugin {} send success", pluginInstanceName); } 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 new file mode 100644 index 0000000000..dd9c5bd472 --- /dev/null +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -0,0 +1,85 @@ +/* + * 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.alert.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.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +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); + + 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.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); + + AlertServer alertServer = AlertServer.getInstance(); + + 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/processor/AlertRequestProcessorTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java new file mode 100644 index 0000000000..8102caec17 --- /dev/null +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java @@ -0,0 +1,58 @@ +/* + * 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.processor; + +import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +import org.apache.dolphinscheduler.dao.AlertDao; +import org.apache.dolphinscheduler.dao.PluginDao; +import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; + +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 PluginDao pluginDao; + private AlertPluginManager alertPluginManager; + + private AlertRequestProcessor alertRequestProcessor; + + @Before + public void before() { + alertDao = PowerMockito.mock(AlertDao.class); + pluginDao = PowerMockito.mock(PluginDao.class); + alertPluginManager = PowerMockito.mock(AlertPluginManager.class); + alertRequestProcessor = new AlertRequestProcessor(alertDao,alertPluginManager,pluginDao); + } + + @Test + public void testProcess() { + Channel channel = PowerMockito.mock(Channel.class); + AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(1,"title","content"); + Command reqCommand = alertSendRequestCommand.convert2Command(); + alertRequestProcessor.process(channel,reqCommand); + } +} diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java new file mode 100644 index 0000000000..fbe172c2fb --- /dev/null +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java @@ -0,0 +1,180 @@ +/* + * 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.runner; + +import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +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 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; + private PluginDao pluginDao; + private AlertPluginManager alertPluginManager; + + private AlertSender alertSender; + + @Before + public void before() { + alertDao = PowerMockito.mock(AlertDao.class); + pluginDao = PowerMockito.mock(PluginDao.class); + alertPluginManager = PowerMockito.mock(AlertPluginManager.class); + + } + + @Test + public void testSyncHandler() { + + int alertGroupId = 1; + String title = "alert mail test title"; + String content = "alert mail test content"; + alertSender = new AlertSender(alertDao,alertPluginManager,pluginDao); + + //1.alert instance does not exist + PowerMockito.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())); + + //2.alert plugin does not exist + int pluginDefineId = 1; + String pluginInstanceParams = "alert-instance-mail-params"; + String pluginInstanceName = "alert-instance-mail"; + List alertInstanceList = new ArrayList<>(); + AlertPluginInstance alertPluginInstance = new AlertPluginInstance( + pluginDefineId,pluginInstanceParams,alertGroupId,pluginInstanceName); + alertInstanceList.add(alertPluginInstance); + PowerMockito.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); + + 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())); + + //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); + + 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())); + + //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); + + 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())); + + //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); + + 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())); + + } + + @Test + public void testRun() { + int alertGroupId = 1; + String title = "alert mail test title"; + String content = "alert mail test content"; + List alertList = new ArrayList<>(); + Alert alert = new Alert(); + alert.setAlertGroupId(alertGroupId); + alert.setTitle(title); + alert.setContent(content); + alertList.add(alert); + + alertSender = new AlertSender(alertList,alertDao,alertPluginManager,pluginDao); + + int pluginDefineId = 1; + String pluginInstanceParams = "alert-instance-mail-params"; + String pluginInstanceName = "alert-instance-mail"; + List alertInstanceList = new ArrayList<>(); + AlertPluginInstance alertPluginInstance = new AlertPluginInstance( + pluginDefineId,pluginInstanceParams,alertGroupId,pluginInstanceName); + alertInstanceList.add(alertPluginInstance); + PowerMockito.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); + + 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); + + alertSender.run(); + } + +} diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java index e3cb1474a5..984cc43c94 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommand.java @@ -20,7 +20,6 @@ package org.apache.dolphinscheduler.remote.command.alert; import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.CommandType; import org.apache.dolphinscheduler.remote.utils.JsonSerializer; -import org.apache.dolphinscheduler.spi.alert.AlertResult; import java.io.Serializable; import java.util.List; @@ -33,17 +32,31 @@ public class AlertSendResponseCommand implements Serializable { */ private boolean resStatus; - private List resResults; + private List resResults; + public boolean getResStatus() { + return resStatus; + } + + public void setResStatus(boolean resStatus) { + this.resStatus = resStatus; + } + public List getResResults() { + return resResults; + } + + public void setResResults(List resResults) { + this.resResults = resResults; + } public AlertSendResponseCommand() { } - public AlertSendResponseCommand(boolean alertStatus, List alertResults) { - this.alertStatus = alertStatus; - this.alertResults = alertResults; + public AlertSendResponseCommand(boolean resStatus, List resResults) { + this.resStatus = resStatus; + this.resResults = resResults; } /** diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseResult.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseResult.java new file mode 100644 index 0000000000..1263b83a73 --- /dev/null +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseResult.java @@ -0,0 +1,52 @@ +/* + * 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.remote.command.alert; + +import java.io.Serializable; + +public class AlertSendResponseResult implements Serializable { + + private boolean status; + + private String message; + + public boolean getStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public AlertSendResponseResult() { + + } + + public AlertSendResponseResult(boolean status, String message) { + this.status = status; + this.message = message; + } +} diff --git a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java index d55807f4b6..41265a5339 100644 --- a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java +++ b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/remote/command/alert/AlertSendResponseCommandTest.java @@ -20,6 +20,9 @@ package org.apache.dolphinscheduler.remote.command.alert; import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.CommandType; +import java.util.ArrayList; +import java.util.List; + import org.junit.Assert; import org.junit.Test; @@ -28,6 +31,17 @@ public class AlertSendResponseCommandTest { @Test public void testConvert2Command() { AlertSendResponseCommand alertSendResponseCommand = new AlertSendResponseCommand(); + alertSendResponseCommand.setResStatus(false); + List responseResults = new ArrayList<>(); + AlertSendResponseResult responseResult1 = new AlertSendResponseResult(); + responseResult1.setStatus(false); + responseResult1.setMessage("fail"); + responseResults.add(responseResult1); + + AlertSendResponseResult responseResult2 = new AlertSendResponseResult(true,"success"); + responseResults.add(responseResult2); + alertSendResponseCommand.setResResults(responseResults); + Command command = alertSendResponseCommand.convert2Command(1); Assert.assertEquals(CommandType.ALERT_SEND_RESPONSE,command.getType()); } diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java index 9581413c39..7839b4a460 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java @@ -78,9 +78,7 @@ public class AlertClientService { Command command = request.convert2Command(); Command response = this.client.sendSync(address, command, ALERT_REQUEST_TIMEOUT); if (response != null) { - AlertSendResponseCommand sendResponse = JsonSerializer.deserialize( - response.getBody(), AlertSendResponseCommand.class); - return sendResponse; + return JsonSerializer.deserialize(response.getBody(), AlertSendResponseCommand.class); } } catch (Exception e) { logger.error("sync alert send error", e); diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java index 68518f6b7a..ba44191b42 100644 --- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java +++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java @@ -21,7 +21,7 @@ import org.apache.dolphinscheduler.remote.NettyRemotingClient; import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; -import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult; import java.util.ArrayList; import java.util.List; @@ -70,16 +70,16 @@ public class AlertClientServiceTest { AlertSendResponseCommand alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); Assert.assertNull(alertSendResponseCommand); - AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(); + AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(groupId,title,content); Command reqCommand = alertSendRequestCommand.convert2Command(); boolean sendResponseStatus; - List sendResponseResults = new ArrayList<>(); + List sendResponseResults = new ArrayList<>(); //2.alter instance does not exist sendResponseStatus = false; - AlertResult alertResult = new AlertResult(); + AlertSendResponseResult alertResult = new AlertSendResponseResult(); String message = String.format("Alert GroupId %s send error : not found alert instance",groupId); - alertResult.setStatus("false"); + alertResult.setStatus(false); alertResult.setMessage(message); sendResponseResults.add(alertResult); AlertSendResponseCommand alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); @@ -87,60 +87,60 @@ public class AlertClientServiceTest { PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); - Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); - alertSendResponseCommand.getAlertResults().forEach(result -> + Assert.assertFalse(alertSendResponseCommand.getResStatus()); + alertSendResponseCommand.getResResults().forEach(result -> logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); //3.alter plugin does not exist sendResponseStatus = false; String pluginInstanceName = "alert-mail"; message = String.format("Alert Plugin %s send error : return value is null",pluginInstanceName); - alertResult.setStatus("false"); + alertResult.setStatus(false); alertResult.setMessage(message); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); - Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); - alertSendResponseCommand.getAlertResults().forEach(result -> + Assert.assertFalse(alertSendResponseCommand.getResStatus()); + alertSendResponseCommand.getResResults().forEach(result -> logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); //4.alter result is null sendResponseStatus = false; message = String.format("Alert Plugin %s send error : return result value is null",pluginInstanceName); - alertResult.setStatus("false"); + alertResult.setStatus(false); alertResult.setMessage(message); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); - Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); - alertSendResponseCommand.getAlertResults().forEach(result -> + Assert.assertFalse(alertSendResponseCommand.getResStatus()); + alertSendResponseCommand.getResResults().forEach(result -> logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); //5.abnormal information inside the alert plug-in code sendResponseStatus = false; - alertResult.setStatus("false"); + alertResult.setStatus(false); alertResult.setMessage("Abnormal information inside the alert plug-in code"); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); - Assert.assertFalse(alertSendResponseCommand.getAlertStatus()); - alertSendResponseCommand.getAlertResults().forEach(result -> + Assert.assertFalse(alertSendResponseCommand.getResStatus()); + alertSendResponseCommand.getResResults().forEach(result -> logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); //6.alert plugin send success sendResponseStatus = true; message = String.format("Alert Plugin %s send success",pluginInstanceName); - alertResult.setStatus("true"); + alertResult.setStatus(true); alertResult.setMessage(message); alertSendResponseCommandData = new AlertSendResponseCommand(sendResponseStatus, sendResponseResults); resCommand = alertSendResponseCommandData.convert2Command(reqCommand.getOpaque()); PowerMockito.when(client.sendSync(Mockito.any(), Mockito.any(), Mockito.anyLong())).thenReturn(resCommand); alertSendResponseCommand = alertClient.sendAlert(host, port, groupId, title, content); - Assert.assertTrue(alertSendResponseCommand.getAlertStatus()); - alertSendResponseCommand.getAlertResults().forEach(result -> + Assert.assertTrue(alertSendResponseCommand.getResStatus()); + alertSendResponseCommand.getResResults().forEach(result -> logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); if (Objects.nonNull(alertClient) && alertClient.isRunning()) { diff --git a/pom.xml b/pom.xml index f6075a92bf..f7ceef32e7 100644 --- a/pom.xml +++ b/pom.xml @@ -960,6 +960,9 @@ **/alert/utils/DingTalkUtilsTest.java **/alert/utils/EnterpriseWeChatUtilsTest.java **/alert/utils/FuncUtilsTest.java + **/alert/processor/AlertRequestProcessorTest.java + **/alert/runner/AlertSenderTest.java + **/alert/AlertServerTest.java From 72942ac32cc104d9842b54d9e395a06540708af9 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Wed, 28 Oct 2020 20:01:38 +0800 Subject: [PATCH 18/44] update test. --- .../java/org/apache/dolphinscheduler/alert/AlertServer.java | 1 - .../org/apache/dolphinscheduler/alert/AlertServerTest.java | 2 ++ .../alert/processor/AlertRequestProcessorTest.java | 3 +++ .../apache/dolphinscheduler/alert/runner/AlertSenderTest.java | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) 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 index 30b3d8eedf..54afc93442 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -158,7 +158,6 @@ public class AlertServer { } public static void main(String[] args) { - System.out.println(System.getProperty("user.dir")); AlertServer alertServer = AlertServer.getInstance(); alertServer.start(); Runtime.getRuntime().addShutdownHook(new Thread() { 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 index dd9c5bd472..37d54c8ef9 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -29,6 +29,7 @@ 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; @@ -71,6 +72,7 @@ public class AlertServerTest { PowerMockito.whenNew(AlertSender.class).withAnyArguments().thenReturn(alertSender); AlertServer alertServer = AlertServer.getInstance(); + Assert.assertNotNull(alertServer); new Thread(() -> { alertServer.start(); }) diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java index 8102caec17..0126eb3dae 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/processor/AlertRequestProcessorTest.java @@ -21,8 +21,10 @@ import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.PluginDao; import org.apache.dolphinscheduler.remote.command.Command; +import org.apache.dolphinscheduler.remote.command.CommandType; 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; @@ -53,6 +55,7 @@ public class AlertRequestProcessorTest { Channel channel = PowerMockito.mock(Channel.class); AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(1,"title","content"); Command reqCommand = alertSendRequestCommand.convert2Command(); + Assert.assertEquals(CommandType.ALERT_SEND_REQUEST,reqCommand.getType()); alertRequestProcessor.process(channel,reqCommand); } } diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java index fbe172c2fb..aa358f6380 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/runner/AlertSenderTest.java @@ -173,8 +173,9 @@ public class AlertSenderTest { ConcurrentHashMap alertChannelMap = new ConcurrentHashMap<>(); alertChannelMap.put(pluginName,alertChannelMock); PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); - + Assert.assertTrue(Boolean.parseBoolean(alertResult.getStatus())); alertSender.run(); + } } From 449cbbe21eaca0d2a886d90ce2731702347bf45a Mon Sep 17 00:00:00 2001 From: Kirs Date: Mon, 2 Nov 2020 10:08:28 +0800 Subject: [PATCH 19/44] [feature#3356] alert-spi support DingTalk&WeChat (#3869) * [feature-3665][ui]Add element-ui (#3666) * [feature-3665][ui]Add element-ui * add license * Add form-create plug-in and alarm group management add sample demo * Modify node version * fix * fix * [feature][ui]Alert plugin design (#3734) * [feature-3665][ui]Add element-ui (#3666) * [feature-3665][ui]Add element-ui * add license * Add form-create plug-in and alarm group management add sample demo * Modify node version * fix * fix * [Feature-3682][ui]Add form-create plug-in and alarm group management add sample demo (#3683) * Add form-create plug-in and alarm group management add sample demo * Modify node version * fix * fix * [feature][ui] Add alarm instance page * [feature-3665][ui]Add element-ui (#3666) * [feature-3665][ui]Add element-ui * add license * Add form-create plug-in and alarm group management add sample demo * Modify node version * fix * fix * [Feature-3189][alert,spi,dao,plugin-api] base code of dolphinscheduler spi and alert plugin implement (#3601) * DS SPI * Add DolphinScheduler SPI , and rebuilt the code of the Alert plug-in based on SPI * Add DolphinScheduler SPI , and rebuilt the code of the Alert plug-in based on SPI * add TODO * delete * compile * spi commit * Plugin Alert * fix some bug * add todo * change web ui from alpacajs to form-create * remove module * add plugin schema * add license header * update alert and spi module version * update the alert plugin sub module version * comment the maven.local.repository param * move utils from spi to common module * add license header * add license header and delete some chinese comment * update spi packages * delete no use alert_xx.properties * update mysql.connector.version back to 5.1.34 * delete no use comment in pom.xml * update email stmp password * add license * add semicolon to sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql file * format the code style * format new clase file with checkstyle * update plugin params to Builder model * move JSONUtils to SPI because plugin can not dependency common module * move JSONUtils to SPI because plugin can not dependency common module * delete collection dependency * replace PluginParamsTransfer to spi PluginParamsTransfer * update dolphinscheduler-maven-plugin to 1.0.0 * update license * update apache-rat-plugin add exclude '.iml' file * check license * ArtifactResolver only use in development and configPlugins is not empty * ArtifactResolver only use in development and configPlugins is not empty * ArtifactResolver only use in development and configPlugins is not empty * default datasource should be postgresql * add license files * add license files * postgresql port should be 5432 * postgresql test * mv show_type to spi add license header to AlertConstants * check style fix * copy check style file from branch dev * alert show_type set by plugin * alert show_type set by plugin * add PluginDefineMapper to dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java * add Bean to TaskCallbackServiceTestConfig * add Bean to TaskCallbackServiceTestConfig * fix check style * check style fix * [feature-3665][ui]Add element-ui (#3666) * [feature-3665][ui]Add element-ui * add license * fix check style * [Feature-3682][ui]Add form-create plug-in and alarm group management add sample demo (#3683) * Add form-create plug-in and alarm group management add sample demo * Modify node version * fix * fix * check style fix * rollback test change * rollback test change * rollback dao pom change * [feature-3665][ui]Add element-ui (#3666) * [feature-3665][ui]Add element-ui * add license * Add form-create plug-in and alarm group management add sample demo * Modify node version * fix * fix * add ut to pom.xml * add upgrade schema to global schema * fix ut failed * fix ut failed * fix ut failed * fix ut failed * add test EmailAlertPluginTest to pom.xml * fix ut failed * fix ut failed * fix check style * update license header to presto license header * presto license header not check * fix ut coverage * fix ut coverage * fix ut * fix ut * fix ut * fix ut coverage * fix ut coverage * fix ut coverage * fix ut coverage * fix ut coverage * fix ut coverage Co-authored-by: break60 <790061044@qq.com> * [feature#3356] alert-spi support DingTalk this closes # 3356 * add test * code style * we chat alert * support we chat alert * support we chat alert * support we chat alert,update ding talk alert * code style * add test * code style * clean old code * clean old code * code smell * code style * add test * simple config * code style * code style * code style * delete old file * fix log content error Co-authored-by: break60 <790061044@qq.com> Co-authored-by: gaojun2048 <32193458+gaojun2048@users.noreply.github.com> --- .../dolphinscheduler-alert-dingtalk/pom.xml | 46 +++ .../alert/dingtalk/DingTalkAlertChannel.java | 41 +++ .../dingtalk/DingTalkAlertChannelFactory.java | 89 +++++ .../alert/dingtalk/DingTalkAlertPlugin.java | 34 ++ .../dingtalk/DingTalkParamsConstants.java | 54 +++ .../plugin/alert/dingtalk/DingTalkSender.java | 204 +++++++++++ .../DingTalkAlertChannelFactoryTest.java | 48 +++ .../alert/dingtalk/DingTalkSenderTest.java | 57 +++ .../dolphinscheduler-alert-wechat/pom.xml | 42 +++ .../alert/wechat/WeChatAlertChannel.java | 41 +++ .../wechat/WeChatAlertChannelFactory.java | 94 +++++ .../alert/wechat/WeChatAlertConstants.java | 34 ++ .../wechat/WeChatAlertParamsConstants.java | 56 +++ .../alert/wechat/WeChatAlertPlugin.java | 34 ++ .../plugin/alert/wechat/WeChatSender.java | 328 ++++++++++++++++++ .../wechat/WeChatAlertChannelFactoryTest.java | 48 +++ .../plugin/alert/wechat/WeChatSenderTest.java | 89 +++++ .../alert/manager/DingTalkManager.java | 55 --- .../manager/EnterpriseWeChatManager.java | 63 ---- .../alert/utils/DingTalkUtils.java | 138 -------- .../alert/utils/EnterpriseWeChatUtils.java | 290 ---------------- .../alert/utils/DingTalkUtilsTest.java | 110 ------ .../utils/EnterpriseWeChatUtilsTest.java | 307 ---------------- dolphinscheduler-spi/pom.xml | 2 + .../dolphinscheduler/spi/utils/JSONUtils.java | 2 +- pom.xml | 10 +- 26 files changed, 1349 insertions(+), 967 deletions(-) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertPlugin.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertPlugin.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/DingTalkManager.java delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtils.java delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java delete mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtilsTest.java delete mode 100644 dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtilsTest.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml index 7a42257e00..8b47172394 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml @@ -29,4 +29,50 @@ dolphinscheduler-alert-dingtalk + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + 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 + + + \ 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-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java new file mode 100644 index 0000000000..7adfacce39 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java @@ -0,0 +1,41 @@ +/* + * 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.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.spi.params.PluginParamsTransfer; + +import java.util.Map; + +/** + * DingTalkAlertChannel + */ +public class DingTalkAlertChannel implements AlertChannel { + + @Override + public AlertResult process(AlertInfo alertInfo) { + + AlertData alertData = alertInfo.getAlertData(); + String alertParams = alertInfo.getAlertParams(); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + return new DingTalkSender(paramsMap).sendDingTalkMsg(alertData.getTitle(), alertData.getContent()); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java new file mode 100644 index 0000000000..0126de4db0 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.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.plugin.alert.dingtalk; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; +import org.apache.dolphinscheduler.spi.params.InputParam; +import org.apache.dolphinscheduler.spi.params.PasswordParam; +import org.apache.dolphinscheduler.spi.params.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; + +/** + * DingTalkAlertChannelFactory + */ +public class DingTalkAlertChannelFactory implements AlertChannelFactory { + @Override + public String getName() { + return "ding talk alert"; + } + + @Override + public List getParams() { + InputParam webHookParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_WEB_HOOK, DingTalkParamsConstants.DING_TALK_WEB_HOOK) + .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(); + RadioParam isEnableProxy = + RadioParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE) + .addParamsOptions(new ParamsOptions("YES", true, false)) + .addParamsOptions(new ParamsOptions("NO", false, false)) + .setValue(true) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + InputParam proxyParam = + InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PROXY, DingTalkParamsConstants.DING_TALK_PROXY) + .addValidate(Validate.newBuilder() + .setRequired(true).build()) + .build(); + + InputParam portParam = InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PORT, DingTalkParamsConstants.DING_TALK_PORT) + .addValidate(Validate.newBuilder() + .setRequired(true).build()) + .build(); + + InputParam userParam = + InputParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_USER, DingTalkParamsConstants.DING_TALK_USER) + .addValidate(Validate.newBuilder() + .setRequired(true).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(); + + return Arrays.asList(webHookParam, keywordParam, isEnableProxy, proxyParam, portParam, userParam, passwordParam); + } + + @Override + public AlertChannel create() { + return new DingTalkAlertChannel(); + } +} 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 new file mode 100644 index 0000000000..2d15f499c9 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertPlugin.java @@ -0,0 +1,34 @@ +/* + * 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-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java new file mode 100644 index 0000000000..6608e83be0 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java @@ -0,0 +1,54 @@ +/* + * 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; + +/** + * DingTalkParamsConstants + */ +public class DingTalkParamsConstants { + + + static final String DING_TALK_WEB_HOOK = "dingtalk.webhook"; + + static final String NAME_DING_TALK_WEB_HOOK = "dingTalkWebHook"; + + static final String DING_TALK_KEYWORD = "dingtalk.keyword"; + + static final String NAME_DING_TALK_KEYWORD = "dingTalkKeyword"; + + public static final String DING_TALK_PROXY_ENABLE = "dingtalk.isEnableProxy"; + + static final String NAME_DING_TALK_PROXY_ENABLE = "dingTalkIsEnableProxy"; + + static final String DING_TALK_PROXY = "dingtalk.proxy"; + + static final String NAME_DING_TALK_PROXY = "dingTalkProxy"; + + static final String DING_TALK_PORT = "dingtalk.port"; + + static final String NAME_DING_TALK_PORT = "dingTalkPort"; + + static final String DING_TALK_USER = "dingtalk.user"; + + static final String NAME_DING_TALK_USER = "dingTalkUser"; + + static final String DING_TALK_PASSWORD = "dingtalk.password"; + + static final String NAME_DING_TALK_PASSWORD = "dingTalkPassword"; + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java new file mode 100644 index 0000000000..e88d160036 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java @@ -0,0 +1,204 @@ +/* + * 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.alert.AlertResult; +import org.apache.dolphinscheduler.spi.utils.JSONUtils; + +import org.apache.commons.codec.binary.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +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; + + private String proxy; + + private Integer port; + + private String user; + + private String password; + + DingTalkSender(Map config) { + url = config.get(DingTalkParamsConstants.NAME_DING_TALK_WEB_HOOK); + keyword = config.get(DingTalkParamsConstants.NAME_DING_TALK_KEYWORD); + enableProxy = Boolean.valueOf(config.get(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE)); + if (Boolean.TRUE.equals(enableProxy)) { + port = Integer.parseInt(config.get(DingTalkParamsConstants.NAME_DING_TALK_PORT)); + proxy = config.get(DingTalkParamsConstants.NAME_DING_TALK_PROXY); + user = config.get(DingTalkParamsConstants.DING_TALK_USER); + password = config.get(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD); + } + + } + + public AlertResult sendDingTalkMsg(String msg, String charset) { + AlertResult alertResult; + try { + String resp = sendMsg(msg, charset); + return checkSendDingTalkSendMsgResult(resp); + } catch (Exception e) { + logger.info("send ding talk alert msg exception : {}", e.getMessage()); + alertResult = new AlertResult(); + alertResult.setStatus("false"); + alertResult.setMessage("send ding talk alert fail."); + } + return alertResult; + } + + private String sendMsg(String msg, String charset) throws IOException { + + String msgToJson = textToJsonString(msg + "#" + keyword); + HttpPost httpPost = constructHttpPost(url, msgToJson, charset); + + CloseableHttpClient httpClient; + if (Boolean.TRUE.equals(enableProxy)) { + httpClient = getProxyClient(proxy, port, user, password); + RequestConfig rcf = getProxyConfig(proxy, port); + httpPost.setConfig(rcf); + } else { + httpClient = getDefaultClient(); + } + + try { + CloseableHttpResponse response = httpClient.execute(httpPost); + String resp; + try { + HttpEntity entity = response.getEntity(); + resp = EntityUtils.toString(entity, charset); + EntityUtils.consume(entity); + } finally { + response.close(); + } + logger.info("Ding Talk send [%s], resp:{%s}", msg, resp); + return resp; + } finally { + httpClient.close(); + } + } + + private static HttpPost constructHttpPost(String url, String msg, String charset) { + HttpPost post = new HttpPost(url); + StringEntity entity = new StringEntity(msg, charset); + post.setEntity(entity); + post.addHeader("Content-Type", "application/json; charset=utf-8"); + return post; + } + + private static CloseableHttpClient getProxyClient(String proxy, int port, String user, String password) { + HttpHost httpProxy = new HttpHost(proxy, port); + CredentialsProvider provider = new BasicCredentialsProvider(); + provider.setCredentials(new AuthScope(httpProxy), new UsernamePasswordCredentials(user, password)); + return HttpClients.custom().setDefaultCredentialsProvider(provider).build(); + } + + private static CloseableHttpClient getDefaultClient() { + return HttpClients.createDefault(); + } + + private static RequestConfig getProxyConfig(String proxy, int port) { + HttpHost httpProxy = new HttpHost(proxy, port); + return RequestConfig.custom().setProxy(httpProxy).build(); + } + + private static String textToJsonString(String text) { + Map items = new HashMap<>(); + items.put("msgtype", "text"); + Map textContent = new HashMap<>(); + byte[] byt = StringUtils.getBytesUtf8(text); + String txt = StringUtils.newStringUtf8(byt); + textContent.put("content", txt); + items.put("text", textContent); + return JSONUtils.toJsonString(items); + } + + public static class DingTalkSendMsgResponse { + 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 checkSendDingTalkSendMsgResult(String result) { + AlertResult alertResult = new AlertResult(); + alertResult.setStatus("false"); + + if (null == result) { + alertResult.setMessage("send ding talk msg error"); + logger.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"); + return alertResult; + } + if (sendMsgResponse.errcode == 0) { + alertResult.setStatus("true"); + alertResult.setMessage("send ding talk msg success"); + 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()); + return alertResult; + } + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java new file mode 100644 index 0000000000..2a26daad63 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java @@ -0,0 +1,48 @@ +/* + * 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.alert.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.Test; + +/** + * DingTalkAlertChannelFactoryTest + */ +public class DingTalkAlertChannelFactoryTest { + + @Test + public void testGetParams() { + DingTalkAlertChannelFactory dingTalkAlertChannelFactory = new DingTalkAlertChannelFactory(); + List params = dingTalkAlertChannelFactory.getParams(); + JSONUtils.toJsonString(params); + Assert.assertEquals(7, params.size()); + } + + @Test + public void testCreate() { + DingTalkAlertChannelFactory dingTalkAlertChannelFactory = new DingTalkAlertChannelFactory(); + AlertChannel alertChannel = dingTalkAlertChannelFactory.create(); + Assert.assertNotNull(alertChannel); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java new file mode 100644 index 0000000000..4512402dc4 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java @@ -0,0 +1,57 @@ +/* + * 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.alert.AlertResult; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * DingTalkSenderTest + */ +public class DingTalkSenderTest { + + private static Map dingTalkConfig = new HashMap<>(); + + @Before + public void initDingTalkConfig() { + + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_KEYWORD, "keyWord"); + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_WEB_HOOK, "url"); + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, "false"); + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD, "password"); + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_PORT, "9988"); + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_USER, "user1,user2"); + } + + @Test + public void testSend() { + DingTalkSender dingTalkSender = new DingTalkSender(dingTalkConfig); + dingTalkSender.sendDingTalkMsg("keyWord+Welcome", "UTF-8"); + dingTalkConfig.put(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, "true"); + dingTalkSender = new DingTalkSender(dingTalkConfig); + AlertResult alertResult = dingTalkSender.sendDingTalkMsg("keyWord+Welcome", "UTF-8"); + Assert.assertEquals("false",alertResult.getStatus()); + } + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml index 62ac776660..1600170f1f 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml @@ -27,6 +27,48 @@ org.apache.dolphinscheduler dolphinscheduler-alert-wechat + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + 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 + + + \ 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-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java new file mode 100644 index 0000000000..4cdd4d375c --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannel.java @@ -0,0 +1,41 @@ +/* + * 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.AlertData; +import org.apache.dolphinscheduler.spi.alert.AlertInfo; +import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; + +import java.util.Map; + +/** + * WeChatAlertChannel + */ +public class WeChatAlertChannel implements AlertChannel { + + @Override + public AlertResult process(AlertInfo info) { + AlertData alertData = info.getAlertData(); + String alertParams = info.getAlertParams(); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + return new WeChatSender(paramsMap).sendEnterpriseWeChat(alertData.getTitle(), alertData.getContent()); + + } +} 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 new file mode 100644 index 0000000000..539add5616 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactory.java @@ -0,0 +1,94 @@ +/* + * 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.InputParam; +import org.apache.dolphinscheduler.spi.params.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 "we chat alert"; + } + + @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.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-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java new file mode 100644 index 0000000000..904060c3e0 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertConstants.java @@ -0,0 +1,34 @@ +/* + * 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; + +/** + * WeChatAlertConstants + */ +public class WeChatAlertConstants { + + static final String MARKDOWN_QUOTE = ">"; + + static final String MARKDOWN_ENTER = "\n"; + + static final String CHARSET = "UTF-8"; + + 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}"; +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java new file mode 100644 index 0000000000..600e31eea3 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertParamsConstants.java @@ -0,0 +1,56 @@ +/* + * 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; + +/** + * WeChatAlertParamsConstants + */ +public class WeChatAlertParamsConstants { + + + static final String ENTERPRISE_WE_CHAT_CORP_ID = "enterprise.wechat.corp.id"; + + static final String NAME_ENTERPRISE_WE_CHAT_CORP_ID = "enterpriseWeChatCorpId"; + + + static final String ENTERPRISE_WE_CHAT_SECRET = "enterprise.wechat.secret"; + + static final String NAME_ENTERPRISE_WE_CHAT_SECRET = "enterpriseWeChatSecret"; + + static final String ENTERPRISE_WE_CHAT_TEAM_SEND_MSG = "enterprise.wechat.team.send.msg"; + + static final String NAME_ENTERPRISE_WE_CHAT_TEAM_SEND_MSG = "enterpriseWeChatTeamSendMsg"; + + + static final String ENTERPRISE_WE_CHAT_USER_SEND_MSG = "enterprise.wechat.user.send.msg"; + + static final String NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG = "enterpriseWeChatUserSendMsg"; + + + static final String ENTERPRISE_WE_CHAT_AGENT_ID = "enterprise.wechat.agent.id"; + + static final String NAME_ENTERPRISE_WE_CHAT_AGENT_ID = "enterpriseWeChatAgentId"; + + + static final String ENTERPRISE_WE_CHAT_USERS = "enterprise.wechat.users"; + + + static final String NAME_ENTERPRISE_WE_CHAT_USERS = "enterpriseWeChatUsers"; + + +} 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 new file mode 100644 index 0000000000..56c3c01f20 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertPlugin.java @@ -0,0 +1,34 @@ +/* + * 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/WeChatSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java new file mode 100644 index 0000000000..52397f5870 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/main/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSender.java @@ -0,0 +1,328 @@ +/* + * 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 static java.util.Objects.requireNonNull; + +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.JSONUtils; +import org.apache.dolphinscheduler.spi.utils.StringUtils; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +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 weChatTeamSendMsg; + + private String weChatUserSendMsg; + + private String weChatTokenUrlReplace; + + private String weChatToken; + + private String showType; + + + private static final String agentIdRegExp = "{agentId}"; + private static final String msgRegExp = "{msg}"; + private static final String userRegExp = "{toUser}"; + private static final String corpIdRegex = "{corpId}"; + private static final String secretRegex = "{secret}"; + private static final String toPartyRegex = "{toParty}"; + private static final String toUserRegex = "{toUser}"; + private static final String tokenRegex = "{token}"; + + WeChatSender(Map config) { + weChatAgentId = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_AGENT_ID); + weChatUsers = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USERS); + String weChatCorpId = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_CORP_ID); + String weChatSecret = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET); + String weChatTokenUrl = WeChatAlertConstants.WE_CHAT_TOKEN_URL; + weChatTeamSendMsg = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_TEAM_SEND_MSG); + weChatUserSendMsg = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG); + showType = config.get(AlertConstants.SHOW_TYPE); + requireNonNull(showType, AlertConstants.SHOW_TYPE + " must not null"); + weChatTokenUrlReplace = weChatTokenUrl + .replace(corpIdRegex, weChatCorpId) + .replace(secretRegex, weChatSecret); + 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(userRegExp, listUser) + .replace(agentIdRegExp, agentId) + .replace(msgRegExp, msg); + } + + /** + * send Enterprise WeChat + * + * @return Enterprise WeChat resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""} + * @throws Exception the Exception + */ + public AlertResult sendEnterpriseWeChat(String title, String content) { + List userList = Arrays.asList(weChatUsers.split(",")); + String data = markdownByAlert(title, content); + String msg = makeUserSendMsg(userList, weChatAgentId, data); + String enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(tokenRegex, weChatToken); + AlertResult alertResult; + 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("false"); + } + return alertResult; + } + + private static String post(String url, String data) throws IOException { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpPost httpPost = new HttpPost(url); + httpPost.setEntity(new StringEntity(data, WeChatAlertConstants.CHARSET)); + CloseableHttpResponse response = httpClient.execute(httpPost); + String resp; + try { + HttpEntity entity = response.getEntity(); + resp = EntityUtils.toString(entity, WeChatAlertConstants.CHARSET); + EntityUtils.consume(entity); + } finally { + response.close(); + } + logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", + url, data, resp); + return resp; + } + } + + /** + * convert table to markdown style + * + * @param title the title + * @param content the content + * @return markdown table content + */ + 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 RuntimeException("itemsList is null"); + } + StringBuilder contents = new StringBuilder(200); + for (LinkedHashMap mapItems : mapItemsList) { + Set> entries = mapItems.entrySet(); + Iterator> iterator = entries.iterator(); + StringBuilder t = new StringBuilder(String.format("`%s`%s", title, WeChatAlertConstants.MARKDOWN_ENTER)); + + while (iterator.hasNext()) { + + Map.Entry entry = iterator.next(); + t.append(WeChatAlertConstants.MARKDOWN_QUOTE); + t.append(entry.getKey()).append(":").append(entry.getValue()); + t.append(WeChatAlertConstants.MARKDOWN_ENTER); + } + contents.append(t); + } + + return contents.toString(); + } + + /** + * convert text to markdown style + * + * @param title the title + * @param content the content + * @return markdown text + */ + private static String markdownText(String title, String content) { + if (StringUtils.isNotEmpty(content)) { + List mapItemsList = JSONUtils.toList(content, LinkedHashMap.class); + if (null == mapItemsList || mapItemsList.isEmpty()) { + logger.error("itemsList is null"); + throw new RuntimeException("itemsList is null"); + } + + StringBuilder contents = new StringBuilder(100); + contents.append(String.format("`%s`%n", title)); + for (LinkedHashMap mapItems : mapItemsList) { + + Set> entries = mapItems.entrySet(); + for (Entry entry : entries) { + contents.append(WeChatAlertConstants.MARKDOWN_QUOTE); + contents.append(entry.getKey()).append(":").append(entry.getValue()); + contents.append(WeChatAlertConstants.MARKDOWN_ENTER); + } + + } + return contents.toString(); + } + 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; + + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet httpGet = new HttpGet(url); + try (CloseableHttpResponse response = httpClient.execute(httpGet)) { + HttpEntity entity = response.getEntity(); + resp = EntityUtils.toString(entity, WeChatAlertConstants.CHARSET); + EntityUtils.consume(entity); + } + + HashMap map = JSONUtils.parseObject(resp, HashMap.class); + if (map != null) { + return map.get("access_token").toString(); + } else { + return null; + } + } + } + + private static String mkString(Iterable list) { + + if (null == list || StringUtils.isEmpty("|")) { + return null; + } + + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (String item : list) { + if (first) { + first = false; + } else { + sb.append("|"); + } + sb.append(item); + } + 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("false"); + + if (null == result) { + alertResult.setMessage("we chat send fail"); + logger.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"); + return alertResult; + } + if (sendMsgResponse.errcode == 0) { + alertResult.setStatus("true"); + alertResult.setMessage("we chat alert send success"); + return alertResult; + } + alertResult.setStatus("false"); + alertResult.setMessage(sendMsgResponse.getErrmsg()); + return alertResult; + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java new file mode 100644 index 0000000000..cc62d5aabf --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java @@ -0,0 +1,48 @@ +/* + * 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.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.utils.JSONUtils; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +/** + * WeChatAlertChannelFactoryTest + */ +public class WeChatAlertChannelFactoryTest { + + @Test + public void testGetParams() { + WeChatAlertChannelFactory weChatAlertChannelFactory = new WeChatAlertChannelFactory(); + List params = weChatAlertChannelFactory.getParams(); + JSONUtils.toJsonString(params); + Assert.assertEquals(6, params.size()); + } + + @Test + public void testCreate() { + WeChatAlertChannelFactory dingTalkAlertChannelFactory = new WeChatAlertChannelFactory(); + AlertChannel alertChannel = dingTalkAlertChannelFactory.create(); + Assert.assertNotNull(alertChannel); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.java new file mode 100644 index 0000000000..a6c4c4fee2 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/src/test/java/org/apache/dolphinscheduler/plugin/alert/wechat/WeChatSenderTest.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.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 java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * WeChatSenderTest + */ +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\"}]"; + + @Before + public void initDingTalkConfig() { + // Just for this test, I will delete these configurations before this PR is merged + weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_AGENT_ID, "1000002"); + weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_CORP_ID, "ww8cc690c06761eaa3"); + weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET, "MYL0_O91ICNrdjkAhgeXIOAj4gEKIirf0-xoYnA25vg"); + weChatConfig.put(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG, "{\"touser\":\"{toUser}\",\"agentid\":{agentId}" + + + ",\"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"); + weChatConfig.put(AlertConstants.SHOW_TYPE, ShowType.TABLE.getDescp()); + } + + @Test + public void testSendWeChatTableMsg() { + WeChatSender weChatSender = new WeChatSender(weChatConfig); + + AlertResult alertResult = weChatSender.sendEnterpriseWeChat("test", content); + Assert.assertEquals("true", alertResult.getStatus()); + } + + @Test + public void testSendWeChatTextMsg() { + weChatConfig.put(AlertConstants.SHOW_TYPE, ShowType.TEXT.getDescp()); + WeChatSender weChatSender = new WeChatSender(weChatConfig); + AlertResult alertResult = weChatSender.sendEnterpriseWeChat("test", content); + Assert.assertEquals("true", alertResult.getStatus()); + } + +} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/DingTalkManager.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/DingTalkManager.java deleted file mode 100644 index 07de6a05b5..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/DingTalkManager.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.manager; - -import org.apache.dolphinscheduler.alert.utils.Constants; -import org.apache.dolphinscheduler.alert.utils.DingTalkUtils; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Ding Talk Manager - */ -public class DingTalkManager { - private static final Logger logger = LoggerFactory.getLogger(EnterpriseWeChatManager.class); - - public Map send(AlertInfo alert) { - Map retMap = new HashMap<>(); - retMap.put(Constants.STATUS, false); - logger.info("send message {}", alert.getAlertData().getTitle()); - try { - String msg = buildMessage(alert); - DingTalkUtils.sendDingTalkMsg(msg, Constants.UTF_8); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - retMap.put(Constants.STATUS, true); - return retMap; - } - - private String buildMessage(AlertInfo alert) { - String msg = alert.getAlertData().getContent(); - return msg; - } -} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java deleted file mode 100644 index 0534d8004f..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java +++ /dev/null @@ -1,63 +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.manager; - -import org.apache.dolphinscheduler.alert.utils.Constants; -import org.apache.dolphinscheduler.alert.utils.EnterpriseWeChatUtils; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Enterprise WeChat Manager - */ -public class EnterpriseWeChatManager { - private static final Logger logger = LoggerFactory.getLogger(EnterpriseWeChatManager.class); - - /** - * Enterprise We Chat send - * - * @param alertInfo the alert info - * @param token the token - * @return the send result - */ - public Map send(AlertInfo alertInfo, String token) { - Map retMap = new HashMap<>(); - retMap.put(Constants.STATUS, false); - String agentId = EnterpriseWeChatUtils.ENTERPRISE_WE_CHAT_AGENT_ID; - String users = EnterpriseWeChatUtils.ENTERPRISE_WE_CHAT_USERS; - List userList = Arrays.asList(users.split(",")); - logger.info("send message {}", alertInfo.getAlertData().getTitle()); - String msg = EnterpriseWeChatUtils.makeUserSendMsg(userList, agentId, EnterpriseWeChatUtils.markdownByAlert(alertInfo)); - try { - EnterpriseWeChatUtils.sendEnterpriseWeChat(Constants.UTF_8, msg, token); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - retMap.put(Constants.STATUS, true); - return retMap; - } - -} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtils.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtils.java deleted file mode 100644 index abac8ae8b7..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtils.java +++ /dev/null @@ -1,138 +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; - -import org.apache.dolphinscheduler.common.utils.JSONUtils; - -import org.apache.commons.codec.binary.StringUtils; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * DingTalkUtils utils - * support send msg to ding talk by robot message push function. - * support proxy setting - */ -public class DingTalkUtils { - public static final Logger logger = LoggerFactory.getLogger(DingTalkUtils.class); - - public static final boolean isEnableDingTalk = PropertyUtils.getBoolean(Constants.DINGTALK_ENABLE); - private static final String dingTaskUrl = PropertyUtils.getString(Constants.DINGTALK_WEBHOOK); - private static final String keyword = PropertyUtils.getString(Constants.DINGTALK_KEYWORD); - private static final Boolean isEnableProxy = PropertyUtils.getBoolean(Constants.DINGTALK_PROXY_ENABLE); - private static final String proxy = PropertyUtils.getString(Constants.DINGTALK_PROXY); - private static final String user = PropertyUtils.getString(Constants.DINGTALK_USER); - private static final String passwd = PropertyUtils.getString(Constants.DINGTALK_PASSWORD); - private static final Integer port = PropertyUtils.getInt(Constants.DINGTALK_PORT); - - /** - * send message interface - * only support text message format now. - * - * @param msg message context to send - * @param charset charset type - * @return result of sending msg - * @throws IOException the IOException - */ - public static String sendDingTalkMsg(String msg, String charset) throws IOException { - String msgToJson = textToJsonString(msg + "#" + keyword); - HttpPost httpPost = constructHttpPost(msgToJson, charset); - - CloseableHttpClient httpClient; - if (isEnableProxy) { - httpClient = getProxyClient(); - RequestConfig rcf = getProxyConfig(); - httpPost.setConfig(rcf); - } else { - httpClient = getDefaultClient(); - } - - try { - CloseableHttpResponse response = httpClient.execute(httpPost); - String resp; - try { - HttpEntity entity = response.getEntity(); - resp = EntityUtils.toString(entity, charset); - EntityUtils.consume(entity); - } finally { - response.close(); - } - logger.info("Ding Talk send [{}], resp:{%s}", msg, resp); - return resp; - } finally { - httpClient.close(); - } - } - - public static HttpPost constructHttpPost(String msg, String charset) { - HttpPost post = new HttpPost(dingTaskUrl); - StringEntity entity = new StringEntity(msg, charset); - post.setEntity(entity); - post.addHeader("Content-Type", "application/json; charset=utf-8"); - return post; - } - - public static CloseableHttpClient getProxyClient() { - HttpHost httpProxy = new HttpHost(proxy, port); - CredentialsProvider provider = new BasicCredentialsProvider(); - provider.setCredentials(new AuthScope(httpProxy), new UsernamePasswordCredentials(user, passwd)); - CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(provider).build(); - return httpClient; - } - - public static CloseableHttpClient getDefaultClient() { - return HttpClients.createDefault(); - } - - public static RequestConfig getProxyConfig() { - HttpHost httpProxy = new HttpHost(proxy, port); - return RequestConfig.custom().setProxy(httpProxy).build(); - } - - public static String textToJsonString(String text) { - Map items = new HashMap(); - items.put("msgtype", "text"); - Map textContent = new HashMap(); - byte[] byt = StringUtils.getBytesUtf8(text); - String txt = StringUtils.newStringUtf8(byt); - textContent.put("content", txt); - items.put("text", textContent); - - return JSONUtils.toJsonString(items); - - } - -} diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java deleted file mode 100644 index 17a49e3277..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java +++ /dev/null @@ -1,290 +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; - -import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.common.utils.StringUtils; -import org.apache.dolphinscheduler.spi.alert.AlertConstants; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.ShowType; -import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; - -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; - -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Enterprise WeChat utils - */ -public class EnterpriseWeChatUtils { - - public static final Logger logger = LoggerFactory.getLogger(EnterpriseWeChatUtils.class); - public static final String ENTERPRISE_WE_CHAT_AGENT_ID = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_AGENT_ID); - public static final String ENTERPRISE_WE_CHAT_USERS = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USERS); - private static final String ENTERPRISE_WE_CHAT_CORP_ID = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_CORP_ID); - private static final String ENTERPRISE_WE_CHAT_SECRET = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_SECRET); - private static final String ENTERPRISE_WE_CHAT_TOKEN_URL = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TOKEN_URL); - private static final String ENTERPRISE_WE_CHAT_TOKEN_URL_REPLACE = ENTERPRISE_WE_CHAT_TOKEN_URL == null ? null : ENTERPRISE_WE_CHAT_TOKEN_URL - .replaceAll("\\{corpId}", ENTERPRISE_WE_CHAT_CORP_ID) - .replaceAll("\\{secret}", ENTERPRISE_WE_CHAT_SECRET); - private static final String ENTERPRISE_WE_CHAT_PUSH_URL = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_PUSH_URL); - private static final String ENTERPRISE_WE_CHAT_TEAM_SEND_MSG = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TEAM_SEND_MSG); - private static final String ENTERPRISE_WE_CHAT_USER_SEND_MSG = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USER_SEND_MSG); - - private static final String agentIdRegExp = "\\{agentId}"; - private static final String msgRegExp = "\\{msg}"; - private static final String userRegExp = "\\{toUser}"; - - /** - * get Enterprise WeChat is enable - * - * @return isEnable - */ - public static boolean isEnable() { - Boolean isEnable = null; - try { - isEnable = PropertyUtils.getBoolean(Constants.ENTERPRISE_WECHAT_ENABLE); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - if (isEnable == null) { - return false; - } - return isEnable; - } - - /** - * get Enterprise WeChat token info - * - * @return token string info - * @throws IOException the IOException - */ - public static String getToken() throws IOException { - String resp; - - CloseableHttpClient httpClient = HttpClients.createDefault(); - try { - HttpGet httpGet = new HttpGet(ENTERPRISE_WE_CHAT_TOKEN_URL_REPLACE); - CloseableHttpResponse response = httpClient.execute(httpGet); - try { - HttpEntity entity = response.getEntity(); - resp = EntityUtils.toString(entity, Constants.UTF_8); - EntityUtils.consume(entity); - } finally { - response.close(); - } - - Map map = JSONUtils.toMap(resp); - if (map != null) { - return map.get("access_token"); - } else { - return null; - } - } finally { - httpClient.close(); - } - } - - /** - * make team single Enterprise WeChat message - * - * @param toParty the toParty - * @param agentId the agentId - * @param msg the msg - * @return Enterprise WeChat send message - */ - public static String makeTeamSendMsg(String toParty, String agentId, String msg) { - return ENTERPRISE_WE_CHAT_TEAM_SEND_MSG.replaceAll("\\{toParty}", toParty) - .replaceAll(agentIdRegExp, agentId) - .replaceAll(msgRegExp, msg); - } - - /** - * make team multi Enterprise WeChat message - * - * @param toParty the toParty - * @param agentId the agentId - * @param msg the msg - * @return Enterprise WeChat send message - */ - public static String makeTeamSendMsg(Collection toParty, String agentId, String msg) { - String listParty = FuncUtils.mkString(toParty, "|"); - return ENTERPRISE_WE_CHAT_TEAM_SEND_MSG.replaceAll("\\{toParty}", listParty) - .replaceAll(agentIdRegExp, agentId) - .replaceAll(msgRegExp, msg); - } - - /** - * make team single user message - * - * @param toUser the toUser - * @param agentId the agentId - * @param msg the msg - * @return Enterprise WeChat send message - */ - public static String makeUserSendMsg(String toUser, String agentId, String msg) { - return ENTERPRISE_WE_CHAT_USER_SEND_MSG.replaceAll("\\{toUser}", toUser) - .replaceAll(agentIdRegExp, agentId) - .replaceAll(msgRegExp, msg); - } - - /** - * make team multi user message - * - * @param toUser the toUser - * @param agentId the agentId - * @param msg the msg - * @return Enterprise WeChat send message - */ - public static String makeUserSendMsg(Collection toUser, String agentId, String msg) { - String listUser = FuncUtils.mkString(toUser, "|"); - return ENTERPRISE_WE_CHAT_USER_SEND_MSG.replaceAll(userRegExp, listUser) - .replaceAll(agentIdRegExp, agentId) - .replaceAll(msgRegExp, msg); - } - - /** - * send Enterprise WeChat - * - * @param charset the charset - * @param data the data - * @param token the token - * @return Enterprise WeChat resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""} - * @throws IOException the IOException - */ - public static String sendEnterpriseWeChat(String charset, String data, String token) throws IOException { - String enterpriseWeChatPushUrlReplace = ENTERPRISE_WE_CHAT_PUSH_URL.replaceAll("\\{token}", token); - - CloseableHttpClient httpClient = HttpClients.createDefault(); - try { - HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace); - httpPost.setEntity(new StringEntity(data, charset)); - CloseableHttpResponse response = httpClient.execute(httpPost); - String resp; - try { - HttpEntity entity = response.getEntity(); - resp = EntityUtils.toString(entity, charset); - EntityUtils.consume(entity); - } finally { - response.close(); - } - logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", - ENTERPRISE_WE_CHAT_PUSH_URL, data, resp); - return resp; - } finally { - httpClient.close(); - } - } - - /** - * convert table to markdown style - * - * @param title the title - * @param content the content - * @return markdown table content - */ - public static String markdownTable(String title, String content) { - List mapItemsList = JSONUtils.toList(content, LinkedHashMap.class); - StringBuilder contents = new StringBuilder(200); - - if (null != mapItemsList) { - for (LinkedHashMap mapItems : mapItemsList) { - Set> entries = mapItems.entrySet(); - Iterator> iterator = entries.iterator(); - StringBuilder t = new StringBuilder(String.format("`%s`%s", title, Constants.MARKDOWN_ENTER)); - - while (iterator.hasNext()) { - - Map.Entry entry = iterator.next(); - t.append(Constants.MARKDOWN_QUOTE); - t.append(entry.getKey()).append(":").append(entry.getValue()); - t.append(Constants.MARKDOWN_ENTER); - } - contents.append(t); - } - } - return contents.toString(); - } - - /** - * convert text to markdown style - * - * @param title the title - * @param content the content - * @return markdown text - */ - public static String markdownText(String title, String content) { - if (StringUtils.isNotEmpty(content)) { - List mapItemsList = JSONUtils.toList(content, LinkedHashMap.class); - if (null != mapItemsList) { - StringBuilder contents = new StringBuilder(100); - contents.append(String.format("`%s`%n", title)); - for (LinkedHashMap mapItems : mapItemsList) { - - Set> entries = mapItems.entrySet(); - Iterator> iterator = entries.iterator(); - while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - contents.append(Constants.MARKDOWN_QUOTE); - contents.append(entry.getKey()).append(":").append(entry.getValue()); - contents.append(Constants.MARKDOWN_ENTER); - } - - } - return contents.toString(); - } - - } - return null; - } - - /** - * Determine the mardown style based on the show type of the alert - * - * @return the markdown alert table/text - */ - public static String markdownByAlert(AlertInfo alertInfo) { - String result = ""; - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertInfo.getAlertParams()); - String showType = paramsMap.get(AlertConstants.SHOW_TYPE); - if (showType.equals(ShowType.TABLE.getDescp())) { - result = markdownTable(alertInfo.getAlertData().getTitle(), alertInfo.getAlertData().getContent()); - } else if (showType.equals(ShowType.TEXT.getDescp())) { - result = markdownText(alertInfo.getAlertData().getTitle(), alertInfo.getAlertData().getContent()); - } - return result; - - } - -} diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtilsTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtilsTest.java deleted file mode 100644 index 27c481e11f..0000000000 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/DingTalkUtilsTest.java +++ /dev/null @@ -1,110 +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; - -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; - -import java.io.IOException; - -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.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@PrepareForTest(PropertyUtils.class) -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.net.ssl.*") -public class DingTalkUtilsTest { - Logger logger = LoggerFactory.getLogger(DingTalkUtilsTest.class); - - private static final String mockUrl = "https://oapi.dingtalk.com/robot/send?access_token=test"; - private static final String mockKeyWords = "onway"; - private static final String msg = "ding talk test"; - - @Before - public void init() { - PowerMockito.mockStatic(PropertyUtils.class); - Mockito.when(PropertyUtils.getString(Constants.DINGTALK_WEBHOOK)).thenReturn(mockUrl); - Mockito.when(PropertyUtils.getString(Constants.DINGTALK_KEYWORD)).thenReturn(mockKeyWords); - Mockito.when(PropertyUtils.getBoolean(Constants.DINGTALK_PROXY_ENABLE)).thenReturn(true); - Mockito.when(PropertyUtils.getString(Constants.DINGTALK_PROXY)).thenReturn("proxy.com.cn"); - Mockito.when(PropertyUtils.getString(Constants.DINGTALK_USER)).thenReturn("user"); - Mockito.when(PropertyUtils.getString(Constants.DINGTALK_PASSWORD)).thenReturn("pswd"); - Mockito.when(PropertyUtils.getInt(Constants.DINGTALK_PORT)).thenReturn(80); - } - - @Test - public void testCreateDefaultClient() { - CloseableHttpClient client = DingTalkUtils.getDefaultClient(); - try { - Assert.assertNotNull(client); - client.close(); - } catch (IOException ex) { - logger.info("close exception", ex.getMessage()); - new Throwable(); - } - } - - @Test - public void testCreateProxyClient() { - CloseableHttpClient client = DingTalkUtils.getProxyClient(); - try { - Assert.assertNotNull(client); - client.close(); - } catch (IOException ex) { - logger.info("close exception", ex.getMessage()); - new Throwable(); - } - - } - - @Test - public void testProxyConfig() { - RequestConfig rc = DingTalkUtils.getProxyConfig(); - Assert.assertEquals(rc.getProxy().getPort(), 80); - Assert.assertEquals(rc.getProxy().getHostName(), "proxy.com.cn"); - } - - @Test - public void testDingTalkMsgToJson() { - String jsonString = DingTalkUtils.textToJsonString("this is test"); - - logger.info(jsonString); - String expect = "{\"text\":{\"content\":\"this is test\"},\"msgtype\":\"text\"}"; - Assert.assertEquals(expect, jsonString); - } - - @Test - public void testDingTalkMsgUtf8() { - String msg = DingTalkUtils.textToJsonString("this is test:中文"); - - logger.info("test support utf8, actual:" + msg); - logger.info("test support utf8, actual:" + DingTalkUtils.isEnableDingTalk); - String expect = "{\"text\":{\"content\":\"this is test:中文\"},\"msgtype\":\"text\"}"; - Assert.assertEquals(expect, msg); - } - -} diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtilsTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtilsTest.java deleted file mode 100644 index d528d2cb84..0000000000 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtilsTest.java +++ /dev/null @@ -1,307 +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; - -import org.apache.dolphinscheduler.common.enums.AlertType; -import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.dao.entity.Alert; -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.ShowType; -import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; -import org.apache.dolphinscheduler.spi.params.RadioParam; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - -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; - -/** - * Please manually modify the configuration file before testing. - * file: alert.properties - * enterprise.wechat.corp.id - * enterprise.wechat.secret - * enterprise.wechat.token.url - * enterprise.wechat.push.url - * enterprise.wechat.send.msg - * enterprise.wechat.agent.id - * enterprise.wechat.users - */ - -@PrepareForTest(PropertyUtils.class) -@RunWith(PowerMockRunner.class) -public class EnterpriseWeChatUtilsTest { - - private static final String toParty = "wwc99134b6fc1edb6"; - private static final String enterpriseWechatSecret = "Uuv2KFrkdf7SeKOsTDCpsTkpawXBMNRhFy6VKX5FV"; - private static final String enterpriseWechatAgentId = "1000004"; - private static final String enterpriseWechatUsers = "LiGang,journey"; - private static final String msg = "hello world"; - - private static final String enterpriseWechatTeamSendMsg = "{\\\"toparty\\\":\\\"{toParty}\\\",\\\"agentid\\\":\\\"{agentId}\\\"" - + - ",\\\"msgtype\\\":\\\"text\\\",\\\"text\\\":{\\\"content\\\":\\\"{msg}\\\"},\\\"safe\\\":\\\"0\\\"}"; - private static final String enterpriseWechatUserSendMsg = "{\\\"touser\\\":\\\"{toUser}\\\",\\\"agentid\\\":\\\"{agentId}\\\"" - + - ",\\\"msgtype\\\":\\\"markdown\\\",\\\"markdown\\\":{\\\"content\\\":\\\"{msg}\\\"}}"; - - @Before - public void init() { - PowerMockito.mockStatic(PropertyUtils.class); - Mockito.when(PropertyUtils.getBoolean(Constants.ENTERPRISE_WECHAT_ENABLE)).thenReturn(true); - Mockito.when(PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USER_SEND_MSG)).thenReturn(enterpriseWechatUserSendMsg); - Mockito.when(PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TEAM_SEND_MSG)).thenReturn(enterpriseWechatTeamSendMsg); - } - - @Test - public void testIsEnable() { - Boolean weChartEnable = EnterpriseWeChatUtils.isEnable(); - Assert.assertTrue(weChartEnable); - } - - @Test - public void testMakeTeamSendMsg1() { - String sendMsg = EnterpriseWeChatUtils.makeTeamSendMsg(toParty, enterpriseWechatSecret, msg); - Assert.assertTrue(sendMsg.contains(toParty)); - Assert.assertTrue(sendMsg.contains(enterpriseWechatSecret)); - Assert.assertTrue(sendMsg.contains(msg)); - - } - - @Test - public void testMakeTeamSendMsg2() { - List parties = new ArrayList<>(); - parties.add(toParty); - parties.add("test1"); - - String sendMsg = EnterpriseWeChatUtils.makeTeamSendMsg(parties, enterpriseWechatSecret, msg); - Assert.assertTrue(sendMsg.contains(toParty)); - Assert.assertTrue(sendMsg.contains(enterpriseWechatSecret)); - Assert.assertTrue(sendMsg.contains(msg)); - } - - @Test - public void tesMakeUserSendMsg1() { - - String sendMsg = EnterpriseWeChatUtils.makeUserSendMsg(enterpriseWechatUsers, enterpriseWechatAgentId, msg); - Assert.assertTrue(sendMsg.contains(enterpriseWechatUsers)); - Assert.assertTrue(sendMsg.contains(enterpriseWechatAgentId)); - Assert.assertTrue(sendMsg.contains(msg)); - } - - @Test - public void tesMakeUserSendMsg2() { - List users = new ArrayList<>(); - users.add("user1"); - users.add("user2"); - - String sendMsg = EnterpriseWeChatUtils.makeUserSendMsg(users, enterpriseWechatAgentId, msg); - Assert.assertTrue(sendMsg.contains(users.get(0))); - Assert.assertTrue(sendMsg.contains(users.get(1))); - Assert.assertTrue(sendMsg.contains(enterpriseWechatAgentId)); - Assert.assertTrue(sendMsg.contains(msg)); - } - - @Test - public void testMarkdownByAlertForText() { - Alert alertForText = createAlertForText(); - AlertData alertData = new AlertData(); - AlertInfo alertInfo = new AlertInfo(); - //TODO: - List paramsList = new ArrayList<>(); - RadioParam showType = new RadioParam.Builder(AlertConstants.SHOW_TYPE, AlertConstants.SHOW_TYPE) - .setValue(ShowType.TEXT) - .build(); - paramsList.add(showType); - alertInfo.setAlertParams(PluginParamsTransfer.transferParamsToJson(paramsList)); - alertInfo.setAlertData(alertData); - alertData.setTitle(alertForText.getTitle()) - //.setShowType(alertForText.getShowType().getDescp()) - .setContent(alertForText.getContent()); - String result = EnterpriseWeChatUtils.markdownByAlert(alertInfo); - Assert.assertNotNull(result); - } - - @Test - public void testMarkdownByAlertForTable() { - Alert alertForText = createAlertForTable(); - AlertData alertData = new AlertData(); - AlertInfo alertInfo = new AlertInfo(); - //TODO: - List paramsList = new ArrayList<>(); - RadioParam showType = new RadioParam.Builder(AlertConstants.SHOW_TYPE, AlertConstants.SHOW_TYPE) - .setValue(ShowType.TABLE) - .build(); - paramsList.add(showType); - alertInfo.setAlertParams(PluginParamsTransfer.transferParamsToJson(paramsList)); - alertInfo.setAlertData(alertData); - alertData.setTitle(alertForText.getTitle()) - //.setShowType(alertForText.getShowType().getDescp()) - .setContent(alertForText.getContent()); - String result = EnterpriseWeChatUtils.markdownByAlert(alertInfo); - Assert.assertNotNull(result); - } - - private Alert createAlertForText() { - 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\"}]"; - - Alert alert = new Alert(); - alert.setTitle("Mysql Exception"); - //alert.setShowType(ShowType.TEXT); - alert.setContent(content); - alert.setAlertType(AlertType.EMAIL); - alert.setAlertGroupId(4); - - return alert; - } - - private String list2String() { - - LinkedHashMap map1 = new LinkedHashMap<>(); - map1.put("mysql service name", "mysql200"); - map1.put("mysql address", "192.168.xx.xx"); - map1.put("port", "3306"); - map1.put("no index of number", "80"); - map1.put("database client connections", "190"); - - LinkedHashMap map2 = new LinkedHashMap<>(); - map2.put("mysql service name", "mysql210"); - map2.put("mysql address", "192.168.xx.xx"); - map2.put("port", "3306"); - map2.put("no index of number", "10"); - map2.put("database client connections", "90"); - - List> maps = new ArrayList<>(); - maps.add(0, map1); - maps.add(1, map2); - String mapjson = JSONUtils.toJsonString(maps); - return mapjson; - } - - private Alert createAlertForTable() { - Alert alert = new Alert(); - alert.setTitle("Mysql Exception"); - //alert.setShowType(ShowType.TABLE.getDescp()); - String content = list2String(); - alert.setContent(content); - alert.setAlertType(AlertType.EMAIL); - alert.setAlertGroupId(1); - return alert; - } - - - // @Test - // public void testSendSingleTeamWeChat() { - // try { - // String token = EnterpriseWeChatUtils.getToken(); - // String msg = EnterpriseWeChatUtils.makeTeamSendMsg(partyId, agentId, "hello world"); - // String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); - // - // String errmsg = JSONUtils.parseObject(resp).getString("errmsg"); - // Assert.assertEquals("ok",errmsg); - // } catch (IOException e) { - // e.printStackTrace(); - // } - // } - // - // @Test - // public void testSendMultiTeamWeChat() { - // - // try { - // String token = EnterpriseWeChatUtils.getToken(); - // String msg = EnterpriseWeChatUtils.makeTeamSendMsg(listPartyId, agentId, "hello world"); - // String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); - // - // String errmsg = JSONUtils.parseObject(resp).getString("errmsg"); - // Assert.assertEquals("ok",errmsg); - // } catch (IOException e) { - // e.printStackTrace(); - // } - // } - // - // @Test - // public void testSendSingleUserWeChat() { - // try { - // String token = EnterpriseWeChatUtils.getToken(); - // String msg = EnterpriseWeChatUtils.makeUserSendMsg(listUserId.stream().findFirst().get(), agentId, "your meeting room has been booked and will be synced to the 'mailbox' later \n" + - // ">**matter details** \n" + - // ">matter:meeting
" + - // ">organizer:@miglioguan \n" + - // ">participant:@miglioguan、@kunliu、@jamdeezhou、@kanexiong、@kisonwang \n" + - // "> \n" + - // ">meeting room:Guangzhou TIT 1st Floor 301 \n" + - // ">date:May 18, 2018 \n" + - // ">time:9:00-11:00 am \n" + - // "> \n" + - // ">please attend the meeting on time\n" + - // "> \n" + - // ">to modify the meeting information, please click: [Modify Meeting Information](https://work.weixin.qq.com)\""); - // - // String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); - // - // String errmsg = JSONUtils.parseObject(resp).getString("errmsg"); - // Assert.assertEquals("ok",errmsg); - // } catch (IOException e) { - // e.printStackTrace(); - // } - // } - // - // @Test - // public void testSendMultiUserWeChat() { - // try { - // String token = EnterpriseWeChatUtils.getToken(); - // - // String msg = EnterpriseWeChatUtils.makeUserSendMsg(listUserId, agentId, "hello world"); - // String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); - // - // String errmsg = JSONUtils.parseObject(resp).getString("errmsg"); - // Assert.assertEquals("ok",errmsg); - // } catch (IOException e) { - // e.printStackTrace(); - // } - // } - -} diff --git a/dolphinscheduler-spi/pom.xml b/dolphinscheduler-spi/pom.xml index 50ed17e457..dd0bae81de 100644 --- a/dolphinscheduler-spi/pom.xml +++ b/dolphinscheduler-spi/pom.xml @@ -35,10 +35,12 @@ com.fasterxml.jackson.core jackson-annotations
+ com.fasterxml.jackson.core jackson-databind + com.fasterxml.jackson.core jackson-core 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 e48686e9f9..6542ef86a4 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 @@ -153,4 +153,4 @@ public class JSONUtils { throw new RuntimeException("Json deserialization exception.", e); } } -} +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index c2cb96e27a..80d3be5b96 100644 --- a/pom.xml +++ b/pom.xml @@ -687,9 +687,9 @@ dolphinscheduler-maven-plugin true - - - + + + @@ -950,6 +950,10 @@ **/plugin/alert/email/ExcelUtilsTest.java **/plugin/alert/email/MailUtilsTest.java **/plugin/alert/email/template/DefaultHTMLTemplateTest.java + **/plugin/alert/dingtalk/DingTalkSenderTest.java + **/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java + **/plugin/alert/wechat/WeChatSenderTest.java + **/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java **/spi/params/PluginParamsTransferTest.java **/alert/plugin/EmailAlertPluginTest.java **/alert/plugin/AlertPluginManagerTest.java From f4ef86c50bc25cb39d48565025651b775433b934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 11:16:05 +0800 Subject: [PATCH 20/44] [FEATURE#4029] alert spi support script alert this closes #4029 --- .../dolphinscheduler-alert-script/pom.xml | 75 +++++++++++++++++++ .../plugin/alert/script/OSUtils.java | 25 +++++++ .../plugin/alert/script/ProcessUtils.java | 57 ++++++++++++++ .../alert/script/ScriptAlertChannel.java | 40 ++++++++++ .../script/ScriptAlertChannelFactory.java | 69 +++++++++++++++++ .../alert/script/ScriptAlertPlugin.java | 35 +++++++++ .../alert/script/ScriptParamsConstants.java | 36 +++++++++ .../plugin/alert/script/ScriptSender.java | 75 +++++++++++++++++++ .../plugin/alert/script/ScriptType.java | 63 ++++++++++++++++ .../plugin/alert/script/StreamGobbler.java | 62 +++++++++++++++ .../script/ScriptAlertChannelFactoryTest.java | 49 ++++++++++++ .../src/test/script/shell/example.sh | 28 +++++++ dolphinscheduler-alert-plugin/pom.xml | 1 + 13 files changed, 615 insertions(+) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml new file mode 100644 index 0000000000..911e28d84d --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml @@ -0,0 +1,75 @@ + + + + + dolphinscheduler-alert-plugin + org.apache.dolphinscheduler + 1.3.2-SNAPSHOT + + 4.0.0 + + org.apache.dolphinscheduler + dolphinscheduler-alert-script + + + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + 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 + + + + \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java new file mode 100644 index 0000000000..88f6c3970b --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java @@ -0,0 +1,25 @@ +/* + * 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; + +public class OSUtils { + + public static Boolean isWindows() { + return System.getProperty("os.name").startsWith("Windows"); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java new file mode 100644 index 0000000000..d3e8fae3f5 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -0,0 +1,57 @@ +/* + * 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 java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +/** + * ProcessUtils + */ +public class ProcessUtils { + + + public static Integer executeScript(String... cmd) { + + int exitCode = -1; + ProcessBuilder processBuilder = new ProcessBuilder(cmd); + try { + Process process = processBuilder.start(); + + InputStream in = process.getErrorStream(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); + StringBuilder result = new StringBuilder(); + + StreamGobbler inputStreamGobbler = + new StreamGobbler(process.getInputStream()); + StreamGobbler errorStreamGobbler = + new StreamGobbler(process.getErrorStream()); + + inputStreamGobbler.start(); + errorStreamGobbler.start(); + return process.waitFor(); + + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + + return exitCode; + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java new file mode 100644 index 0000000000..2a0021277d --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java @@ -0,0 +1,40 @@ +/* + * 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.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.spi.params.PluginParamsTransfer; + +import java.util.Map; + +/** + * ScriptAlertChannel + */ +public class ScriptAlertChannel implements AlertChannel { + + @Override + public AlertResult process(AlertInfo alertinfo) { + AlertData alertData = alertinfo.getAlertData(); + String alertParams = alertinfo.getAlertParams(); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle()); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java new file mode 100644 index 0000000000..fc338625c1 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java @@ -0,0 +1,69 @@ +/* + * 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 java.util.Arrays; +import java.util.List; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; +import org.apache.dolphinscheduler.spi.params.InputParam; +import org.apache.dolphinscheduler.spi.params.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; + +/** + * ScriptAlertChannelFactory + */ +public class ScriptAlertChannelFactory implements AlertChannelFactory { + + @Override + public String getName() { + return "script alert"; + } + + @Override + public List getParams() { + + InputParam scriptUserParam = InputParam.newBuilder(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS, ScriptParamsConstants.SCRIPT_USER_PARAMS) + .addValidate(Validate.newBuilder() + .setRequired(false) + .build()) + .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()) + .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(); + + return Arrays.asList(scriptUserParam, scriptPathParam, scriptTypeParams); + } + + @Override + public AlertChannel create() { + return new ScriptAlertChannel(); + } +} 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 new file mode 100644 index 0000000000..f2ba0e87d0 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java @@ -0,0 +1,35 @@ +/* + * 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-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java new file mode 100644 index 0000000000..67193c853d --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java @@ -0,0 +1,36 @@ +/* + * 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; + +/** + * ScriptParamsConstants + */ +public class ScriptParamsConstants { + + static final String SCRIPT_TYPE = "script.type"; + + static final String NAME_SCRIPT_TYPE = "scriptType"; + + static final String SCRIPT_PATH = "script.path"; + + static final String NAME_SCRIPT_PATH = "scriptPath"; + + static final String SCRIPT_USER_PARAMS = "script.user.params"; + + static final String NAME_SCRIPT_USER_PARAMS = "scriptUserParams"; +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java new file mode 100644 index 0000000000..df99a4f1a9 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -0,0 +1,75 @@ +/* + * 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.alert.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 Integer scriptType; + + private String userParams; + + public ScriptSender(Map config) { + scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH); + scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE)); + userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS); + } + + + public AlertResult sendScriptAlert(String msg) { + AlertResult alertResult = new AlertResult(); + if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) { + executeShellScript(msg); + } + return alertResult; + } + + private AlertResult executeShellScript(String msg) { + AlertResult alertResult = new AlertResult(); + alertResult.setStatus("false"); + if (OSUtils.isWindows()) { + alertResult.setMessage("shell script not support windows os"); + return alertResult; + } + String[] cmd = {"/bin/sh", "-c", scriptPath + " " + msg + " " + userParams}; + int exitCode = ProcessUtils.executeScript(cmd); + + if (exitCode == 0) { + alertResult.setStatus("true"); + alertResult.setMessage("send script alert msg success"); + return alertResult; + } + alertResult.setMessage("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-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java new file mode 100644 index 0000000000..a7544cc46a --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java @@ -0,0 +1,63 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; + +/** + * ScriptType + */ +public enum ScriptType { + + + SHELL(0, "SHELL"), + ; + + ScriptType(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; + } + + private static final Map SCRIPT_TYPE_MAP = new HashMap<>(); + + static { + for (ScriptType scriptType : ScriptType.values()) { + SCRIPT_TYPE_MAP.put(scriptType.code, scriptType); + } + } + + + public static ScriptType of(Integer code) { + if (SCRIPT_TYPE_MAP.containsKey(code)) { + return SCRIPT_TYPE_MAP.get(code); + } + throw new IllegalArgumentException("invalid code : " + code); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java new file mode 100644 index 0000000000..13f8790cbc --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java @@ -0,0 +1,62 @@ +/* + * 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 java.io.BufferedReader; +import java.io.IOException; +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); + + InputStream inputStream; + + + StreamGobbler(InputStream inputStream) { + this.inputStream = inputStream; + } + + + public void run() { + InputStreamReader inputStreamReader = new InputStreamReader(inputStream); + BufferedReader inputBufferReader = new BufferedReader(inputStreamReader); + + try { + String line; + StringBuilder output = new StringBuilder(); + while ((line = inputBufferReader.readLine()) != null) { + output.append(line); + output.append(System.getProperty("line.separator")); + } + if (output.length() > 0) { + logger.info(output.toString()); + } + } catch (IOException e) { + logger.error("I/O error occurs %S", e.getMessage()); + } + } + +} \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java new file mode 100644 index 0000000000..53127f7cf5 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java @@ -0,0 +1,49 @@ +/* + * 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.alert.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.Test; + +/** + * ScriptAlertChannelFactoryTest + */ +public class ScriptAlertChannelFactoryTest { + + + @Test + public void testGetParams() { + ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); + List params = scriptAlertChannelFactory.getParams(); + JSONUtils.toJsonString(params); + Assert.assertEquals(3, params.size()); + } + + @Test + public void testCreate() { + ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); + AlertChannel alertChannel = scriptAlertChannelFactory.create(); + Assert.assertNotNull(alertChannel); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh new file mode 100644 index 0000000000..6f215b011a --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh @@ -0,0 +1,28 @@ +# +# 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. +# + +content=$1 + +msg=$2 + +# Write your specific logic here +echo $content + +echo $msg + +# Set the exit code according to your execution result, and alert needs to use it to judge the status of this alarm result +exit 888 diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index d2fbca305d..0f25f1f19b 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -33,6 +33,7 @@ dolphinscheduler-alert-email dolphinscheduler-alert-wechat dolphinscheduler-alert-dingtalk + dolphinscheduler-alert-script From 4c7743f3bd9639f6fba8470545ca40d61923bee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 11:59:00 +0800 Subject: [PATCH 21/44] code style --- .../plugin/alert/script/OSUtils.java | 3 +++ .../plugin/alert/script/ProcessUtils.java | 12 +++++++++++- .../alert/script/ScriptAlertChannelFactory.java | 6 +++--- .../plugin/alert/script/ScriptSender.java | 2 -- .../plugin/alert/script/ScriptType.java | 1 - .../plugin/alert/script/StreamGobbler.java | 2 -- .../src/test/script/shell/example.sh | 9 +++------ 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java index 88f6c3970b..57190e84b8 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java @@ -17,6 +17,9 @@ package org.apache.dolphinscheduler.plugin.alert.script; +/** + * OSUtils + */ public class OSUtils { public 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-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java index d3e8fae3f5..47d0d397e9 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -22,12 +22,22 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * ProcessUtils */ public class ProcessUtils { + private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); + /** + * executeScript + * + * @param cmd cmd params + * @return exit code + */ public static Integer executeScript(String... cmd) { int exitCode = -1; @@ -49,7 +59,7 @@ public class ProcessUtils { return process.waitFor(); } catch (IOException | InterruptedException e) { - e.printStackTrace(); + logger.error("execute alert script error", e.getMessage()); } return exitCode; diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java index fc338625c1..2b04531a98 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java @@ -17,9 +17,6 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import java.util.Arrays; -import java.util.List; - import org.apache.dolphinscheduler.spi.alert.AlertChannel; import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; import org.apache.dolphinscheduler.spi.params.InputParam; @@ -28,6 +25,9 @@ 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; + /** * ScriptAlertChannelFactory */ diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java index df99a4f1a9..f7613873b4 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -31,7 +31,6 @@ public class ScriptSender { private static final Logger logger = LoggerFactory.getLogger(ScriptSender.class); - private String scriptPath; private Integer scriptType; @@ -44,7 +43,6 @@ public class ScriptSender { userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS); } - public AlertResult sendScriptAlert(String msg) { AlertResult alertResult = new AlertResult(); if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) { diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java index a7544cc46a..59b17d0a58 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java @@ -53,7 +53,6 @@ public enum ScriptType { } } - public static ScriptType of(Integer code) { if (SCRIPT_TYPE_MAP.containsKey(code)) { return SCRIPT_TYPE_MAP.get(code); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java index 13f8790cbc..1d8a516f37 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java @@ -34,12 +34,10 @@ public class StreamGobbler extends Thread { InputStream inputStream; - StreamGobbler(InputStream inputStream) { this.inputStream = inputStream; } - public void run() { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader inputBufferReader = new BufferedReader(inputStreamReader); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh index 6f215b011a..708dcd004b 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh @@ -15,14 +15,11 @@ # limitations under the License. # -content=$1 -msg=$2 +msg=$1 +content=$2 # Write your specific logic here -echo $content - -echo $msg # Set the exit code according to your execution result, and alert needs to use it to judge the status of this alarm result -exit 888 +exit 0 From 05eabda3916faba01eb3e279b8fae6947bba23ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 12:10:40 +0800 Subject: [PATCH 22/44] code smell --- .../plugin/alert/script/OSUtils.java | 4 ++++ .../plugin/alert/script/ProcessUtils.java | 16 +++++----------- .../plugin/alert/script/ScriptSender.java | 1 + .../plugin/alert/script/StreamGobbler.java | 5 +++-- .../script/ScriptAlertChannelFactoryTest.java | 1 - 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java index 57190e84b8..d7e6d23a88 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java @@ -22,6 +22,10 @@ package org.apache.dolphinscheduler.plugin.alert.script; */ public class OSUtils { + public OSUtils() { + throw new UnsupportedOperationException("Construct OSUtils"); + } + public static Boolean isWindows() { return System.getProperty("os.name").startsWith("Windows"); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java index 47d0d397e9..11fc869761 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -17,10 +17,8 @@ package org.apache.dolphinscheduler.plugin.alert.script; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,25 +39,21 @@ public class ProcessUtils { public static Integer executeScript(String... cmd) { int exitCode = -1; + ProcessBuilder processBuilder = new ProcessBuilder(cmd); try { Process process = processBuilder.start(); - InputStream in = process.getErrorStream(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); - StringBuilder result = new StringBuilder(); - StreamGobbler inputStreamGobbler = - new StreamGobbler(process.getInputStream()); - StreamGobbler errorStreamGobbler = - new StreamGobbler(process.getErrorStream()); + StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream()); + StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream()); inputStreamGobbler.start(); errorStreamGobbler.start(); return process.waitFor(); - } catch (IOException | InterruptedException e) { - logger.error("execute alert script error", e.getMessage()); + logger.error("execute alert script error {}", e.getMessage()); + Thread.currentThread().interrupt(); } return exitCode; diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java index f7613873b4..0a14623b7f 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -67,6 +67,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); return alertResult; } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java index 1d8a516f37..cde0c7914d 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java @@ -38,6 +38,7 @@ public class StreamGobbler extends Thread { this.inputStream = inputStream; } + @Override public void run() { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader inputBufferReader = new BufferedReader(inputStreamReader); @@ -50,10 +51,10 @@ public class StreamGobbler extends Thread { output.append(System.getProperty("line.separator")); } if (output.length() > 0) { - logger.info(output.toString()); + logger.info("out put msg is{}",output.toString()); } } catch (IOException e) { - logger.error("I/O error occurs %S", e.getMessage()); + logger.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/ScriptAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java index 53127f7cf5..72f2197315 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java @@ -31,7 +31,6 @@ import org.junit.Test; */ public class ScriptAlertChannelFactoryTest { - @Test public void testGetParams() { ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); From e4641da58f89f40502a27c8c9a0e3bb1ff178b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 17:51:26 +0800 Subject: [PATCH 23/44] add test --- .../script/ScriptAlertChannelFactory.java | 2 + .../plugin/alert/script/ScriptSender.java | 2 +- .../plugin/alert/script/ProcessUtilsTest.java | 37 ++++++++++++ .../plugin/alert/script/ScriptSenderTest.java | 58 +++++++++++++++++++ .../src/test/script/shell/scriptTest.sh | 25 ++++++++ pom.xml | 3 + 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java create mode 100755 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java index 2b04531a98..0fcead2dee 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java @@ -45,12 +45,14 @@ public class ScriptAlertChannelFactory implements AlertChannelFactory { .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 alarm 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) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java index 0a14623b7f..f7a89d8859 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -46,7 +46,7 @@ public class ScriptSender { public AlertResult sendScriptAlert(String msg) { AlertResult alertResult = new AlertResult(); if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) { - executeShellScript(msg); + return executeShellScript(msg); } return alertResult; } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java new file mode 100644 index 0000000000..c49a7a45de --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java @@ -0,0 +1,37 @@ +/* + * 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.junit.Test; + +/** + * ProcessUtilsTest + */ +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/example.sh"; + + private String[] cmd={"/bin/sh", "-c", shellFilPath + " " + "testMsg" + " " + "userParams"}; + + @Test + public void testExecuteScript(){ + ProcessUtils.executeScript(cmd); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java new file mode 100644 index 0000000000..1cd74cfaba --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java @@ -0,0 +1,58 @@ +/* + * 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.alert.AlertResult; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * ScriptSenderTest + */ +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/scriptTest.sh"; + + @Before + public void initScriptConfig() { + + scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, String.valueOf(ScriptType.SHELL.getCode())); + scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS, "userParams"); + scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_PATH, shellFilPath); + } + + @Test + public void testScriptSenderTest() { + ScriptSender scriptSender = new ScriptSender(scriptConfig); + AlertResult alertResult; + alertResult = scriptSender.sendScriptAlert("success"); + Assert.assertEquals("true", alertResult.getStatus()); + alertResult = scriptSender.sendScriptAlert("errorMsg"); + Assert.assertEquals("false", alertResult.getStatus()); + } + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh new file mode 100755 index 0000000000..02eba48a81 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh @@ -0,0 +1,25 @@ +# +# 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. +# + +msg=$1 +content=$2 + +if [ $msg = errorMsg ] + then + exit 12 +fi +exit 0 \ No newline at end of file diff --git a/pom.xml b/pom.xml index c0c920d069..33c1dd35d2 100644 --- a/pom.xml +++ b/pom.xml @@ -957,6 +957,9 @@ **/plugin/alert/dingtalk/DingTalkAlertChannelFactoryTest.java **/plugin/alert/wechat/WeChatSenderTest.java **/plugin/alert/wechat/WeChatAlertChannelFactoryTest.java + **/plugin/alert/script/ProcessUtilsTest.java + **/plugin/alert/script/ScriptAlertChannelFactoryTest.java + **/plugin/alert/script/ScriptSenderTest.java **/spi/params/PluginParamsTransferTest.java **/alert/plugin/EmailAlertPluginTest.java **/alert/plugin/AlertPluginManagerTest.java From 03ed107664a1f358a8ce834981225cb773a723c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 18:02:32 +0800 Subject: [PATCH 24/44] code style --- .../plugin/alert/script/ProcessUtilsTest.java | 8 ++++---- .../src/test/script/shell/example.sh | 0 2 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java index c49a7a45de..1bf98d2019 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java @@ -24,14 +24,14 @@ import org.junit.Test; */ public class ProcessUtilsTest { - private static final String rootPath=System.getProperty("user.dir"); + 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/example.sh"; + private static final String shellFilPath = rootPath + "/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh"; - private String[] cmd={"/bin/sh", "-c", shellFilPath + " " + "testMsg" + " " + "userParams"}; + private String[] cmd = {"/bin/sh", "-c", shellFilPath + " " + "testMsg" + " " + "userParams"}; @Test - public void testExecuteScript(){ + public void testExecuteScript() { ProcessUtils.executeScript(cmd); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh old mode 100644 new mode 100755 From 5b14319cbc16fd1cf559425be6d543ec375daf47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 18:25:16 +0800 Subject: [PATCH 25/44] code smell --- .../dolphinscheduler/plugin/alert/script/OSUtils.java | 2 +- .../plugin/alert/script/ProcessUtils.java | 8 +++++--- .../plugin/alert/script/ScriptSender.java | 6 +++--- .../plugin/alert/script/StreamGobbler.java | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java index d7e6d23a88..acf3e310cc 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java @@ -26,7 +26,7 @@ public class OSUtils { throw new UnsupportedOperationException("Construct OSUtils"); } - public static Boolean isWindows() { + static Boolean isWindows() { return System.getProperty("os.name").startsWith("Windows"); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java index 11fc869761..500c2724cc 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -30,21 +30,23 @@ public class ProcessUtils { private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); + private ProcessUtils() { + throw new IllegalStateException("Utility class"); + } + /** * executeScript * * @param cmd cmd params * @return exit code */ - public static Integer executeScript(String... cmd) { + static Integer executeScript(String... cmd) { int exitCode = -1; ProcessBuilder processBuilder = new ProcessBuilder(cmd); try { Process process = processBuilder.start(); - InputStream in = process.getErrorStream(); - StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream()); StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream()); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java index f7a89d8859..377c318b8e 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -37,13 +37,13 @@ public class ScriptSender { private String userParams; - public ScriptSender(Map config) { + ScriptSender(Map config) { scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH); scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE)); userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS); } - public AlertResult sendScriptAlert(String msg) { + AlertResult sendScriptAlert(String msg) { AlertResult alertResult = new AlertResult(); if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) { return executeShellScript(msg); @@ -54,7 +54,7 @@ public class ScriptSender { private AlertResult executeShellScript(String msg) { AlertResult alertResult = new AlertResult(); alertResult.setStatus("false"); - if (OSUtils.isWindows()) { + if (Boolean.TRUE.equals(OSUtils.isWindows())) { alertResult.setMessage("shell script not support windows os"); return alertResult; } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java index cde0c7914d..2ec25280b4 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java @@ -32,7 +32,7 @@ public class StreamGobbler extends Thread { private static final Logger logger = LoggerFactory.getLogger(StreamGobbler.class); - InputStream inputStream; + private InputStream inputStream; StreamGobbler(InputStream inputStream) { this.inputStream = inputStream; From 66afe5afcc2f79acdae553f80f9fc2f29d927f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 18:39:37 +0800 Subject: [PATCH 26/44] code style --- .../dolphinscheduler/plugin/alert/script/ProcessUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java index 500c2724cc..d63a350051 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.plugin.alert.script; import java.io.IOException; -import java.io.InputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 63522adc6d1f176b6809f4b108d17822aeef14fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Sat, 14 Nov 2020 14:47:48 +0800 Subject: [PATCH 27/44] fix name error --- .../plugin/alert/script/ScriptAlertChannelFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java index 0fcead2dee..fe7f7adb00 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java @@ -52,12 +52,12 @@ public class ScriptAlertChannelFactory implements AlertChannelFactory { .addValidate(Validate.newBuilder() .setRequired(true) .build()) - .setPlaceholder("please upload the file to the disk directory of the alarm server, and ensure that the path is absolute and has the corresponding access rights") + .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()) + .addParamsOptions(new ParamsOptions(ScriptType.SHELL.getDescp(), ScriptType.SHELL.getCode(), false)) + .setValue(ScriptType.SHELL.getCode()) .addValidate(Validate.newBuilder().setRequired(true).build()) .build(); From 91eb42d449b70eefc98f30b4ef18613674561d8c Mon Sep 17 00:00:00 2001 From: samz406 Date: Thu, 19 Nov 2020 22:05:32 +0800 Subject: [PATCH 28/44] init sms plugin --- .../dolphinscheduler-alert-sms/pom.xml | 56 +++++++++++++++++++ .../plugin/alert/sms/SMSAlertChannel.java | 33 +++++++++++ .../alert/sms/SMSAlertChannelFactory.java | 44 +++++++++++++++ .../plugin/alert/sms/SMSAlertConstants.java | 21 +++++++ .../alert/sms/SMSAlertParamsConstants.java | 21 +++++++ .../plugin/alert/sms/SMSAlertPlugin.java | 33 +++++++++++ .../plugin/alert/sms/SMSSender.java | 34 +++++++++++ dolphinscheduler-alert-plugin/pom.xml | 1 + 8 files changed, 243 insertions(+) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml new file mode 100644 index 0000000000..40188e3969 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml @@ -0,0 +1,56 @@ + + + + dolphinscheduler-alert-plugin + org.apache.dolphinscheduler + 1.3.2-SNAPSHOT + + 4.0.0 + + dolphinscheduler-alert-sms + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + 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 + + + + \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java new file mode 100644 index 0000000000..2e0210b044 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java @@ -0,0 +1,33 @@ +/* + * 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.sms; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertInfo; +import org.apache.dolphinscheduler.spi.alert.AlertResult; + + +/** + * sms alert channel,use sms message to seed the alertInfo + */ +public class SMSAlertChannel implements AlertChannel { + @Override + public AlertResult process(AlertInfo info) { + return null; + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java new file mode 100644 index 0000000000..ac179ce591 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java @@ -0,0 +1,44 @@ +/* + * 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.sms; + +import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; + +import java.util.List; + +/** + * sms alert factory + */ +public class SMSAlertChannelFactory implements AlertChannelFactory { + @Override + public String getName() { + return null; + } + + @Override + public List getParams() { + return null; + } + + @Override + public AlertChannel create() { + return null; + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java new file mode 100644 index 0000000000..bf782a8e54 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java @@ -0,0 +1,21 @@ +/* + * 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.sms; + +public class SMSAlertConstants { +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java new file mode 100644 index 0000000000..c0713d9de9 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java @@ -0,0 +1,21 @@ +/* + * 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.sms; + +public class SMSAlertParamsConstants { +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java new file mode 100644 index 0000000000..55dae28981 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java @@ -0,0 +1,33 @@ +/* + * 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.sms; + +import com.google.common.collect.ImmutableList; +import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; + +/** + * sms alertPlugins + */ +public class SMSAlertPlugin implements DolphinSchedulerPlugin { + + @Override + public Iterable getAlertChannelFactorys() { + return ImmutableList.of(new SMSAlertChannelFactory()); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java new file mode 100644 index 0000000000..ccfc0597ed --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java @@ -0,0 +1,34 @@ +/* + * 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.sms; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * send message + */ +public class SMSSender { + + public static final Logger logger = LoggerFactory.getLogger(SMSSender.class); + + + public void send(){ + + } +} diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index d2fbca305d..cd2468e178 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -33,6 +33,7 @@ dolphinscheduler-alert-email dolphinscheduler-alert-wechat dolphinscheduler-alert-dingtalk + dolphinscheduler-alert-sms From 37c8f00e1ff3b4d215d4dd613cbc4b44abab20fa Mon Sep 17 00:00:00 2001 From: samz406 Date: Fri, 27 Nov 2020 18:01:27 +0800 Subject: [PATCH 29/44] modify http type --- .../pom.xml | 2 +- .../plugin/alert/http/HttpAlertChannel.java} | 19 +- .../alert/http/HttpAlertChannelFactory.java | 78 ++++++++ .../alert/http/HttpAlertConstants.java} | 19 +- .../plugin/alert/http/HttpAlertPlugin.java} | 8 +- .../plugin/alert/http/HttpSender.java | 170 ++++++++++++++++++ .../alert/sms/SMSAlertChannelFactory.java | 44 ----- .../plugin/alert/sms/SMSAlertConstants.java | 21 --- .../alert/sms/SMSAlertParamsConstants.java | 21 --- dolphinscheduler-alert-plugin/pom.xml | 2 +- 10 files changed, 277 insertions(+), 107 deletions(-) rename dolphinscheduler-alert-plugin/{dolphinscheduler-alert-sms => dolphinscheduler-alert-http}/pom.xml (96%) rename dolphinscheduler-alert-plugin/{dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java => dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java} (60%) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java rename dolphinscheduler-alert-plugin/{dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java => dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java} (68%) rename dolphinscheduler-alert-plugin/{dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java => dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java} (83%) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml similarity index 96% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml rename to dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml index 40188e3969..51cba27054 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - dolphinscheduler-alert-sms + dolphinscheduler-alert-http diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java similarity index 60% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java rename to dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java index 2e0210b044..9707d76e62 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java @@ -15,19 +15,28 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.plugin.alert.sms; +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.spi.params.PluginParamsTransfer; + +import java.util.Map; /** - * sms alert channel,use sms message to seed the alertInfo + * http alert channel,use sms message to seed the alertInfo */ -public class SMSAlertChannel implements AlertChannel { +public class HttpAlertChannel implements AlertChannel { @Override - public AlertResult process(AlertInfo info) { - return null; + public AlertResult process(AlertInfo alertInfo) { + + AlertData alertData = alertInfo.getAlertData(); + String alertParams = alertInfo.getAlertParams(); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + + return new HttpSender(paramsMap).send(alertData.getContent()); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java new file mode 100644 index 0000000000..2e78056225 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java @@ -0,0 +1,78 @@ +/* + * 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.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; +import org.apache.dolphinscheduler.spi.params.InputParam; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.params.base.Validate; + +import java.util.Arrays; +import java.util.List; + +/** + * http alert factory + */ +public class HttpAlertChannelFactory implements AlertChannelFactory { + @Override + public String getName() { + return "http alert"; + } + + @Override + public List getParams() { + + InputParam url = InputParam.newBuilder(HttpAlertConstants.URL, HttpAlertConstants.URL) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam headerParams = InputParam.newBuilder(HttpAlertConstants.HEADER_PARAMS, HttpAlertConstants.HEADER_PARAMS) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam bodyParams = InputParam.newBuilder(HttpAlertConstants.BODY_PARAMS, HttpAlertConstants.BODY_PARAMS) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam contentField = InputParam.newBuilder(HttpAlertConstants.CONTENT_FIELD, HttpAlertConstants.CONTENT_FIELD) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam requestType = InputParam.newBuilder(HttpAlertConstants.REQUEST_TYPE, HttpAlertConstants.REQUEST_TYPE) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + return Arrays.asList(url, requestType, headerParams, bodyParams, contentField); + } + + @Override + public AlertChannel create() { + return new HttpAlertChannel(); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java similarity index 68% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java rename to dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java index ccfc0597ed..5f3b1c2a42 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java @@ -15,20 +15,19 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.plugin.alert.sms; +package org.apache.dolphinscheduler.plugin.alert.http; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +public class HttpAlertConstants { -/** - * send message - */ -public class SMSSender { - public static final Logger logger = LoggerFactory.getLogger(SMSSender.class); + public static final String URL = "url"; + + public static final String HEADER_PARAMS = "headerParams"; + + public static final String BODY_PARAMS = "bodyParams"; + public static final String CONTENT_FIELD = "contentField"; - public void send(){ + public static final String REQUEST_TYPE = "requestType"; - } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java similarity index 83% rename from dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java rename to dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java index 55dae28981..c3ab1a1189 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java @@ -15,19 +15,19 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.plugin.alert.sms; +package org.apache.dolphinscheduler.plugin.alert.http; import com.google.common.collect.ImmutableList; import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; /** - * sms alertPlugins + * http alertPlugins */ -public class SMSAlertPlugin implements DolphinSchedulerPlugin { +public class HttpAlertPlugin implements DolphinSchedulerPlugin { @Override public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new SMSAlertChannelFactory()); + return ImmutableList.of(new HttpAlertChannelFactory()); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java new file mode 100644 index 0000000000..eb71ec3a26 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java @@ -0,0 +1,170 @@ +/* + * 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 com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.spi.utils.JSONUtils; +import org.apache.dolphinscheduler.spi.utils.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +/** + *http send message + */ +public class HttpSender { + + public static final Logger logger = LoggerFactory.getLogger(HttpSender.class); + + private String url; + + private String headerParams; + + private String bodyParams; + + private String contentField; + + private String requestType; + + private HttpRequestBase httpRequest; + + + 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"; + + public HttpSender(Map paramsMap){ + + url = paramsMap.get(HttpAlertConstants.URL); + headerParams = paramsMap.get(HttpAlertConstants.HEADER_PARAMS); + bodyParams = paramsMap.get(HttpAlertConstants.BODY_PARAMS); + contentField = paramsMap.get(HttpAlertConstants.CONTENT_FIELD); + requestType = paramsMap.get(HttpAlertConstants.REQUEST_TYPE); + } + + + public AlertResult send(String msg) { + + AlertResult alertResult = new AlertResult(); + + getHttpRequest(msg); + + if (httpRequest == null){ + alertResult.setStatus("false"); + alertResult.setMessage("Request types are not supported"); + return alertResult; + } + + try { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + CloseableHttpResponse response = httpClient.execute(httpRequest); + HttpEntity entity = response.getEntity(); + String resp = EntityUtils.toString(entity, DEFAULT_CHARSET); + alertResult.setStatus("true"); + alertResult.setMessage(resp); + }catch (Exception e) { + logger.error("send sms alert msg exception : {}", e.getMessage()); + alertResult.setStatus("false"); + alertResult.setMessage("send http request alert fail."); + } + + return alertResult; + } + + private void getHttpRequest(String msg){ + + if (REQUEST_TYPE_POST.equals(requestType)){ + httpRequest = new HttpPost(url); + //POST request add param in request body + setMsgInRequestBody(msg); + }else if (REQUEST_TYPE_GET.equals(requestType)){ + //GET request add param in url + setMsgInUrl(msg); + httpRequest = new HttpGet(url); + } + setHeader(); + } + + /** + * add msg param in url + * @param msg + */ + private void setMsgInUrl(String msg) { + + if (StringUtils.isNotBlank(contentField)){ + String type = "&"; + //check splice char is & or ? + if (!url.contains(URL_SPLICE_CHAR)){ + type = URL_SPLICE_CHAR; + } + url = String.format("%s%s%s=%s", url, type, contentField, msg); + } + } + + + /** + * set header params + */ + private void setHeader(){ + + if (httpRequest == null){ + return; + } + + HashMap map = JSONUtils.parseObject(headerParams, HashMap.class); + for (Map.Entry entry : map.entrySet()) { + httpRequest.setHeader(entry.getKey(), String.valueOf(entry.getValue())); + } + } + + /** + *set body params + * @param msg + * @return + */ + private String setMsgInRequestBody(String msg){ + ObjectNode objectNode = JSONUtils.parseObject(bodyParams); + //set msg content field + objectNode.put(contentField,msg); + return objectNode.toString(); + } + + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java deleted file mode 100644 index ac179ce591..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java +++ /dev/null @@ -1,44 +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.sms; - -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; - -import java.util.List; - -/** - * sms alert factory - */ -public class SMSAlertChannelFactory implements AlertChannelFactory { - @Override - public String getName() { - return null; - } - - @Override - public List getParams() { - return null; - } - - @Override - public AlertChannel create() { - return null; - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java deleted file mode 100644 index bf782a8e54..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java +++ /dev/null @@ -1,21 +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.sms; - -public class SMSAlertConstants { -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java deleted file mode 100644 index c0713d9de9..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java +++ /dev/null @@ -1,21 +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.sms; - -public class SMSAlertParamsConstants { -} diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index 9713198ce7..707f0ceafb 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -34,7 +34,7 @@ dolphinscheduler-alert-wechat dolphinscheduler-alert-dingtalk dolphinscheduler-alert-script - dolphinscheduler-alert-sms + dolphinscheduler-alert-http From b21a158273b57d2ceb161dd1f7ec4ad9d75beb87 Mon Sep 17 00:00:00 2001 From: gaojun2048 <540957506@qq.com> Date: Tue, 1 Dec 2020 11:04:04 +0800 Subject: [PATCH 30/44] delete dolphinscheduler-alert-sms plugin --- .../dolphinscheduler-alert-sms/pom.xml | 56 ------------------- .../plugin/alert/sms/SMSAlertChannel.java | 33 ----------- .../alert/sms/SMSAlertChannelFactory.java | 44 --------------- .../plugin/alert/sms/SMSAlertConstants.java | 21 ------- .../alert/sms/SMSAlertParamsConstants.java | 21 ------- .../plugin/alert/sms/SMSAlertPlugin.java | 33 ----------- .../plugin/alert/sms/SMSSender.java | 34 ----------- dolphinscheduler-alert-plugin/pom.xml | 1 - pom.xml | 2 +- 9 files changed, 1 insertion(+), 244 deletions(-) delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml deleted file mode 100644 index 40188e3969..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - dolphinscheduler-alert-plugin - org.apache.dolphinscheduler - 1.3.2-SNAPSHOT - - 4.0.0 - - dolphinscheduler-alert-sms - - - - org.apache.dolphinscheduler - dolphinscheduler-spi - provided - - - - 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 - - - - \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.java deleted file mode 100644 index 2e0210b044..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannel.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.sms; - -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertInfo; -import org.apache.dolphinscheduler.spi.alert.AlertResult; - - -/** - * sms alert channel,use sms message to seed the alertInfo - */ -public class SMSAlertChannel implements AlertChannel { - @Override - public AlertResult process(AlertInfo info) { - return null; - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java deleted file mode 100644 index ac179ce591..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertChannelFactory.java +++ /dev/null @@ -1,44 +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.sms; - -import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; - -import java.util.List; - -/** - * sms alert factory - */ -public class SMSAlertChannelFactory implements AlertChannelFactory { - @Override - public String getName() { - return null; - } - - @Override - public List getParams() { - return null; - } - - @Override - public AlertChannel create() { - return null; - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java deleted file mode 100644 index bf782a8e54..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java +++ /dev/null @@ -1,21 +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.sms; - -public class SMSAlertConstants { -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java deleted file mode 100644 index c0713d9de9..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java +++ /dev/null @@ -1,21 +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.sms; - -public class SMSAlertParamsConstants { -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.java deleted file mode 100644 index 55dae28981..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertPlugin.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.sms; - -import com.google.common.collect.ImmutableList; -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -/** - * sms alertPlugins - */ -public class SMSAlertPlugin implements DolphinSchedulerPlugin { - - @Override - public Iterable getAlertChannelFactorys() { - return ImmutableList.of(new SMSAlertChannelFactory()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.java deleted file mode 100644 index ccfc0597ed..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender.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.sms; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * send message - */ -public class SMSSender { - - public static final Logger logger = LoggerFactory.getLogger(SMSSender.class); - - - public void send(){ - - } -} diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index 9713198ce7..0f25f1f19b 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -34,7 +34,6 @@ dolphinscheduler-alert-wechat dolphinscheduler-alert-dingtalk dolphinscheduler-alert-script - dolphinscheduler-alert-sms diff --git a/pom.xml b/pom.xml index 33c1dd35d2..83681556ce 100644 --- a/pom.xml +++ b/pom.xml @@ -961,7 +961,7 @@ **/plugin/alert/script/ScriptAlertChannelFactoryTest.java **/plugin/alert/script/ScriptSenderTest.java **/spi/params/PluginParamsTransferTest.java - **/alert/plugin/EmailAlertPluginTest.java + **/alert/plugin/AlertPluginManagerTest.java **/alert/plugin/DolphinPluginLoaderTest.java **/alert/utils/DingTalkUtilsTest.java From 44d5cceb99b4c7d332993d8f6929fabd3654abaa Mon Sep 17 00:00:00 2001 From: gaojun2048 <540957506@qq.com> Date: Tue, 1 Dec 2020 11:04:44 +0800 Subject: [PATCH 31/44] dolphinscheduler plugin need add dolphinscheduler-plugin in the pom.xml file --- .../dolphinscheduler-alert-dingtalk/pom.xml | 2 +- .../dolphinscheduler-alert-script/pom.xml | 2 +- .../dolphinscheduler-alert-wechat/pom.xml | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml index 8b47172394..7ccd69aa01 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml @@ -27,7 +27,7 @@ org.apache.dolphinscheduler dolphinscheduler-alert-dingtalk - + dolphinscheduler-plugin diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml index 911e28d84d..c1ba5aa260 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml @@ -27,7 +27,7 @@ org.apache.dolphinscheduler dolphinscheduler-alert-script - + dolphinscheduler-plugin diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml index 1600170f1f..1362e1a651 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml @@ -27,6 +27,7 @@ org.apache.dolphinscheduler dolphinscheduler-alert-wechat + dolphinscheduler-plugin From 3f85a4c1d4aa638c65f3261a7fd04f147e5532a3 Mon Sep 17 00:00:00 2001 From: Kirs Date: Fri, 4 Dec 2020 11:29:33 +0800 Subject: [PATCH 32/44] delete alert http plugin (#4152) delete alert http plugin (#4152) This part of the code was merged by mistake, so I need to delete it --- .../dolphinscheduler-alert-http/pom.xml | 56 ------ .../plugin/alert/http/HttpAlertChannel.java | 42 ----- .../alert/http/HttpAlertChannelFactory.java | 78 -------- .../plugin/alert/http/HttpAlertConstants.java | 33 ---- .../plugin/alert/http/HttpAlertPlugin.java | 33 ---- .../plugin/alert/http/HttpSender.java | 170 ------------------ dolphinscheduler-alert-plugin/pom.xml | 1 - 7 files changed, 413 deletions(-) delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java delete mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.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/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml deleted file mode 100644 index 51cba27054..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - dolphinscheduler-alert-plugin - org.apache.dolphinscheduler - 1.3.2-SNAPSHOT - - 4.0.0 - - dolphinscheduler-alert-http - - - - org.apache.dolphinscheduler - dolphinscheduler-spi - provided - - - - 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 - - - - \ 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-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java deleted file mode 100644 index 9707d76e62..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java +++ /dev/null @@ -1,42 +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.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.spi.params.PluginParamsTransfer; - -import java.util.Map; - - -/** - * http alert channel,use sms message to seed the alertInfo - */ -public class HttpAlertChannel implements AlertChannel { - @Override - public AlertResult process(AlertInfo alertInfo) { - - AlertData alertData = alertInfo.getAlertData(); - String alertParams = alertInfo.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); - - return new HttpSender(paramsMap).send(alertData.getContent()); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java deleted file mode 100644 index 2e78056225..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java +++ /dev/null @@ -1,78 +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.AlertChannel; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; -import org.apache.dolphinscheduler.spi.params.InputParam; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; -import org.apache.dolphinscheduler.spi.params.base.Validate; - -import java.util.Arrays; -import java.util.List; - -/** - * http alert factory - */ -public class HttpAlertChannelFactory implements AlertChannelFactory { - @Override - public String getName() { - return "http alert"; - } - - @Override - public List getParams() { - - InputParam url = InputParam.newBuilder(HttpAlertConstants.URL, HttpAlertConstants.URL) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam headerParams = InputParam.newBuilder(HttpAlertConstants.HEADER_PARAMS, HttpAlertConstants.HEADER_PARAMS) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam bodyParams = InputParam.newBuilder(HttpAlertConstants.BODY_PARAMS, HttpAlertConstants.BODY_PARAMS) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam contentField = InputParam.newBuilder(HttpAlertConstants.CONTENT_FIELD, HttpAlertConstants.CONTENT_FIELD) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - InputParam requestType = InputParam.newBuilder(HttpAlertConstants.REQUEST_TYPE, HttpAlertConstants.REQUEST_TYPE) - .addValidate(Validate.newBuilder() - .setRequired(true) - .build()) - .build(); - - return Arrays.asList(url, requestType, headerParams, bodyParams, contentField); - } - - @Override - public AlertChannel create() { - return new HttpAlertChannel(); - } -} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java deleted file mode 100644 index 5f3b1c2a42..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.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.http; - -public class HttpAlertConstants { - - - public static final String URL = "url"; - - public static final String HEADER_PARAMS = "headerParams"; - - public static final String BODY_PARAMS = "bodyParams"; - - public static final String CONTENT_FIELD = "contentField"; - - public static final String REQUEST_TYPE = "requestType"; - -} 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 c3ab1a1189..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.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.http; - -import com.google.common.collect.ImmutableList; -import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; -import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; - -/** - * 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/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java deleted file mode 100644 index eb71ec3a26..0000000000 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java +++ /dev/null @@ -1,170 +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 com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.dolphinscheduler.spi.alert.AlertResult; -import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import org.apache.dolphinscheduler.spi.utils.StringUtils; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; - -/** - *http send message - */ -public class HttpSender { - - public static final Logger logger = LoggerFactory.getLogger(HttpSender.class); - - private String url; - - private String headerParams; - - private String bodyParams; - - private String contentField; - - private String requestType; - - private HttpRequestBase httpRequest; - - - 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"; - - public HttpSender(Map paramsMap){ - - url = paramsMap.get(HttpAlertConstants.URL); - headerParams = paramsMap.get(HttpAlertConstants.HEADER_PARAMS); - bodyParams = paramsMap.get(HttpAlertConstants.BODY_PARAMS); - contentField = paramsMap.get(HttpAlertConstants.CONTENT_FIELD); - requestType = paramsMap.get(HttpAlertConstants.REQUEST_TYPE); - } - - - public AlertResult send(String msg) { - - AlertResult alertResult = new AlertResult(); - - getHttpRequest(msg); - - if (httpRequest == null){ - alertResult.setStatus("false"); - alertResult.setMessage("Request types are not supported"); - return alertResult; - } - - try { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - CloseableHttpResponse response = httpClient.execute(httpRequest); - HttpEntity entity = response.getEntity(); - String resp = EntityUtils.toString(entity, DEFAULT_CHARSET); - alertResult.setStatus("true"); - alertResult.setMessage(resp); - }catch (Exception e) { - logger.error("send sms alert msg exception : {}", e.getMessage()); - alertResult.setStatus("false"); - alertResult.setMessage("send http request alert fail."); - } - - return alertResult; - } - - private void getHttpRequest(String msg){ - - if (REQUEST_TYPE_POST.equals(requestType)){ - httpRequest = new HttpPost(url); - //POST request add param in request body - setMsgInRequestBody(msg); - }else if (REQUEST_TYPE_GET.equals(requestType)){ - //GET request add param in url - setMsgInUrl(msg); - httpRequest = new HttpGet(url); - } - setHeader(); - } - - /** - * add msg param in url - * @param msg - */ - private void setMsgInUrl(String msg) { - - if (StringUtils.isNotBlank(contentField)){ - String type = "&"; - //check splice char is & or ? - if (!url.contains(URL_SPLICE_CHAR)){ - type = URL_SPLICE_CHAR; - } - url = String.format("%s%s%s=%s", url, type, contentField, msg); - } - } - - - /** - * set header params - */ - private void setHeader(){ - - if (httpRequest == null){ - return; - } - - HashMap map = JSONUtils.parseObject(headerParams, HashMap.class); - for (Map.Entry entry : map.entrySet()) { - httpRequest.setHeader(entry.getKey(), String.valueOf(entry.getValue())); - } - } - - /** - *set body params - * @param msg - * @return - */ - private String setMsgInRequestBody(String msg){ - ObjectNode objectNode = JSONUtils.parseObject(bodyParams); - //set msg content field - objectNode.put(contentField,msg); - return objectNode.toString(); - } - - -} diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index 707f0ceafb..0f25f1f19b 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -34,7 +34,6 @@ dolphinscheduler-alert-wechat dolphinscheduler-alert-dingtalk dolphinscheduler-alert-script - dolphinscheduler-alert-http From 169a4ace7757952bf2fc4492ec3e03905dbaa8e5 Mon Sep 17 00:00:00 2001 From: zhuangchong <37063904+zhuangchong@users.noreply.github.com> Date: Thu, 10 Dec 2020 22:41:11 +0800 Subject: [PATCH 33/44] [Feature-3749][Alert-SPI] SqlTask should send notifications by alert server api (#4080) * add sqltask send sync alert server. * update alert-sms license. * update AlertServer test. * remote EmailAlertPluginTest. * update sqltask. * update test class. --- .../alert/AlertServerTest.java | 4 + .../alert/plugin/EmailAlertPluginTest.java | 2 + .../common/task/sql/SqlParameters.java | 67 +++++------ .../server/worker/WorkerServer.java | 23 +++- .../server/worker/config/WorkerConfig.java | 19 ++- .../processor/TaskExecuteProcessor.java | 27 +++-- .../worker/runner/TaskExecuteThread.java | 29 +++-- .../server/worker/task/TaskManager.java | 6 +- .../server/worker/task/sql/SqlTask.java | 67 ++--------- .../src/main/resources/worker.properties | 3 + .../worker/runner/TaskExecuteThreadTest.java | 11 +- .../server/worker/task/TaskManagerTest.java | 27 +++-- .../server/worker/task/sql/SqlTaskTest.java | 111 ++++++++++++++++++ .../service/alert/AlertClientService.java | 26 ++++ .../pages/dag/_source/formModel/tasks/sql.vue | 64 ++++------ .../src/js/module/i18n/locale/en_US.js | 3 + .../src/js/module/i18n/locale/zh_CN.js | 3 + install.sh | 2 + pom.xml | 2 +- 19 files changed, 318 insertions(+), 178 deletions(-) create mode 100644 dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTaskTest.java 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 index 37d54c8ef9..a8ead79be9 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.alert; import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; +import org.apache.dolphinscheduler.alert.plugin.DolphinPluginLoader; import org.apache.dolphinscheduler.alert.plugin.DolphinPluginManagerConfig; import org.apache.dolphinscheduler.alert.runner.AlertSender; import org.apache.dolphinscheduler.alert.utils.Constants; @@ -71,6 +72,9 @@ public class AlertServerTest { 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); diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java index 6558419160..a6bd51c7f6 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java @@ -49,6 +49,7 @@ import java.util.LinkedHashMap; import java.util.List; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import com.google.common.collect.ImmutableList; @@ -62,6 +63,7 @@ public class EmailAlertPluginTest { PluginDao pluginDao = DaoFactory.getDaoInstance(PluginDao.class); @Test + @Ignore public void testRunSend() throws Exception { //create alert group diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/sql/SqlParameters.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/sql/SqlParameters.java index 4604234e8f..3b5d39f274 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/sql/SqlParameters.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/sql/SqlParameters.java @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.common.task.sql; import org.apache.dolphinscheduler.common.process.ResourceInfo; import org.apache.dolphinscheduler.common.task.AbstractParameters; -import org.apache.commons.lang.StringUtils; +import org.apache.dolphinscheduler.common.utils.StringUtils; import java.util.ArrayList; import java.util.List; @@ -75,19 +76,13 @@ public class SqlParameters extends AbstractParameters { private List postStatements; /** - * title - */ - private String title; - - /** - * receivers + * groupId */ - private String receivers; - + private int groupId; /** - * receivers cc + * title */ - private String receiversCc; + private String title; public String getType() { return type; @@ -153,21 +148,6 @@ public class SqlParameters extends AbstractParameters { this.title = title; } - public String getReceivers() { - return receivers; - } - - public void setReceivers(String receivers) { - this.receivers = receivers; - } - - public String getReceiversCc() { - return receiversCc; - } - - public void setReceiversCc(String receiversCc) { - this.receiversCc = receiversCc; - } public List getPreStatements() { return preStatements; } @@ -184,6 +164,14 @@ public class SqlParameters extends AbstractParameters { this.postStatements = postStatements; } + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + @Override public boolean checkParameters() { return datasource != 0 && StringUtils.isNotEmpty(type) && StringUtils.isNotEmpty(sql); @@ -196,19 +184,18 @@ public class SqlParameters extends AbstractParameters { @Override public String toString() { - return "SqlParameters{" + - "type='" + type + '\'' + - ", datasource=" + datasource + - ", sql='" + sql + '\'' + - ", sqlType=" + sqlType + - ", udfs='" + udfs + '\'' + - ", showType='" + showType + '\'' + - ", connParams='" + connParams + '\'' + - ", title='" + title + '\'' + - ", receivers='" + receivers + '\'' + - ", receiversCc='" + receiversCc + '\'' + - ", preStatements=" + preStatements + - ", postStatements=" + postStatements + - '}'; + return "SqlParameters{" + + "type='" + type + '\'' + + ", datasource=" + datasource + + ", sql='" + sql + '\'' + + ", sqlType=" + sqlType + + ", udfs='" + udfs + '\'' + + ", showType='" + showType + '\'' + + ", connParams='" + connParams + '\'' + + ", groupId='" + groupId + '\'' + + ", title='" + title + '\'' + + ", preStatements=" + preStatements + + ", postStatements=" + postStatements + + '}'; } } diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java index f0833cb7e0..072e76aaeb 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.server.worker; import org.apache.dolphinscheduler.common.Constants; @@ -25,7 +26,11 @@ import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; import org.apache.dolphinscheduler.server.worker.processor.TaskExecuteProcessor; import org.apache.dolphinscheduler.server.worker.processor.TaskKillProcessor; import org.apache.dolphinscheduler.server.worker.registry.WorkerRegistry; +import org.apache.dolphinscheduler.service.alert.AlertClientService; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; + +import javax.annotation.PostConstruct; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,8 +38,6 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.ComponentScan; -import javax.annotation.PostConstruct; - /** * worker server */ @@ -70,6 +73,11 @@ public class WorkerServer { @Autowired private SpringApplicationContext springApplicationContext; + /** + * alert model netty remote server + */ + private AlertClientService alertClientService; + /** * worker server startup * @@ -86,7 +94,7 @@ public class WorkerServer { * worker server run */ @PostConstruct - public void run(){ + public void run() { logger.info("start worker server..."); //init remoting server @@ -100,6 +108,9 @@ public class WorkerServer { // worker registry this.workerRegistry.registry(); + //alert-server client registry + alertClientService = new AlertClientService(workerConfig.getAlertListenHost(),Constants.ALERT_RPC_PORT); + /** * register hooks, which are called before the process exits */ @@ -115,7 +126,7 @@ public class WorkerServer { try { //execute only once - if(Stopper.isStopped()){ + if (Stopper.isStopped()) { return; } @@ -127,13 +138,15 @@ public class WorkerServer { try { //thread sleep 3 seconds for thread quitely stop Thread.sleep(3000L); - }catch (Exception e){ + } catch (Exception e) { logger.warn("thread sleep exception", e); } this.nettyRemotingServer.close(); this.workerRegistry.unRegistry(); + this.alertClientService.close(); + } catch (Exception e) { logger.error("worker server stop exception ", e); System.exit(-1); diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/config/WorkerConfig.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/config/WorkerConfig.java index fa97403527..a32d4c8ff3 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/config/WorkerConfig.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/config/WorkerConfig.java @@ -1,4 +1,3 @@ - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -15,11 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.server.worker.config; +import org.apache.dolphinscheduler.common.Constants; + import java.util.Set; -import org.apache.dolphinscheduler.common.Constants; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; @@ -52,6 +53,9 @@ public class WorkerConfig { @Value("${worker.weight:100}") private int weight; + @Value("${alert.listen.host:localhost}") + private String alertListenHost; + public int getListenPort() { return listenPort; } @@ -101,7 +105,7 @@ public class WorkerConfig { } public int getWorkerMaxCpuloadAvg() { - if (workerMaxCpuloadAvg == -1){ + if (workerMaxCpuloadAvg == -1) { return Constants.DEFAULT_WORKER_CPU_LOAD; } return workerMaxCpuloadAvg; @@ -111,7 +115,6 @@ public class WorkerConfig { this.workerMaxCpuloadAvg = workerMaxCpuloadAvg; } - public int getWeight() { return weight; } @@ -119,4 +122,12 @@ public class WorkerConfig { public void setWeight(int weight) { this.weight = weight; } + + public String getAlertListenHost() { + return alertListenHost; + } + + public void setAlertListenHost(String alertListenHost) { + this.alertListenHost = alertListenHost; + } } \ No newline at end of file diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/processor/TaskExecuteProcessor.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/processor/TaskExecuteProcessor.java index 3717ce37ae..adef703e1d 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/processor/TaskExecuteProcessor.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/processor/TaskExecuteProcessor.java @@ -37,6 +37,7 @@ import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; import org.apache.dolphinscheduler.server.utils.LogUtils; import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; import org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread; +import org.apache.dolphinscheduler.service.alert.AlertClientService; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import java.util.Date; @@ -73,12 +74,24 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { */ private final TaskCallbackService taskCallbackService; - public TaskExecuteProcessor(){ + /** + * alert client service + */ + private AlertClientService alertClientService; + + public TaskExecuteProcessor() { this.taskCallbackService = SpringApplicationContext.getBean(TaskCallbackService.class); this.workerConfig = SpringApplicationContext.getBean(WorkerConfig.class); this.workerExecService = ThreadUtils.newDaemonFixedThreadExecutor("Worker-Execute-Thread", workerConfig.getWorkerExecThreads()); } + public TaskExecuteProcessor(AlertClientService alertClientService) { + this.taskCallbackService = SpringApplicationContext.getBean(TaskCallbackService.class); + this.workerConfig = SpringApplicationContext.getBean(WorkerConfig.class); + this.workerExecService = ThreadUtils.newDaemonFixedThreadExecutor("Worker-Execute-Thread", workerConfig.getWorkerExecThreads()); + this.alertClientService = alertClientService; + } + @Override public void process(Channel channel, Command command) { Preconditions.checkArgument(CommandType.TASK_EXECUTE_REQUEST == command.getType(), @@ -89,7 +102,7 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { logger.info("received command : {}", taskRequestCommand); - if(taskRequestCommand == null){ + if (taskRequestCommand == null) { logger.error("task execute request command is null"); return; } @@ -97,7 +110,7 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { String contextJson = taskRequestCommand.getTaskExecutionContext(); TaskExecutionContext taskExecutionContext = JSONUtils.parseObject(contextJson, TaskExecutionContext.class); - if(taskExecutionContext == null){ + if (taskExecutionContext == null) { logger.error("task execution context is null"); return; } @@ -144,7 +157,7 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { return Boolean.TRUE; }); // submit task - workerExecService.submit(new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger)); + workerExecService.submit(new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger, alertClientService)); } catch (ExecutionException | RetryException e) { logger.error(e.getMessage(), e); } @@ -162,9 +175,9 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { ackCommand.setLogPath(LogUtils.getTaskLogPath(taskExecutionContext)); ackCommand.setHost(taskExecutionContext.getHost()); ackCommand.setStartTime(taskExecutionContext.getStartTime()); - if(taskExecutionContext.getTaskType().equals(TaskType.SQL.name()) || taskExecutionContext.getTaskType().equals(TaskType.PROCEDURE.name())){ + if (taskExecutionContext.getTaskType().equals(TaskType.SQL.name()) || taskExecutionContext.getTaskType().equals(TaskType.PROCEDURE.name())) { ackCommand.setExecutePath(null); - }else{ + } else { ackCommand.setExecutePath(taskExecutionContext.getExecutePath()); } taskExecutionContext.setLogPath(ackCommand.getLogPath()); @@ -176,7 +189,7 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { * @param taskExecutionContext taskExecutionContext * @return execute local path */ - private String getExecLocalPath(TaskExecutionContext taskExecutionContext){ + private String getExecLocalPath(TaskExecutionContext taskExecutionContext) { return FileUtils.getProcessExecDir(taskExecutionContext.getProjectId(), taskExecutionContext.getProcessDefineId(), taskExecutionContext.getProcessInstanceId(), diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java index 58f743303c..39046e96eb 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.server.worker.runner; import org.apache.dolphinscheduler.common.Constants; @@ -37,6 +38,7 @@ import org.apache.dolphinscheduler.server.worker.cache.impl.TaskExecutionContext import org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService; import org.apache.dolphinscheduler.server.worker.task.AbstractTask; import org.apache.dolphinscheduler.server.worker.task.TaskManager; +import org.apache.dolphinscheduler.service.alert.AlertClientService; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import org.apache.commons.collections.MapUtils; @@ -55,7 +57,6 @@ import org.slf4j.LoggerFactory; import com.github.rholder.retry.RetryException; - /** * task scheduler thread */ @@ -91,6 +92,11 @@ public class TaskExecuteThread implements Runnable { */ private Logger taskLogger; + /** + * alert client server + */ + private AlertClientService alertClientService; + /** * constructor * @param taskExecutionContext taskExecutionContext @@ -98,11 +104,12 @@ public class TaskExecuteThread implements Runnable { */ public TaskExecuteThread(TaskExecutionContext taskExecutionContext , TaskCallbackService taskCallbackService - , Logger taskLogger) { + , Logger taskLogger, AlertClientService alertClientService) { this.taskExecutionContext = taskExecutionContext; this.taskCallbackService = taskCallbackService; this.taskExecutionContextCacheManager = SpringApplicationContext.getBean(TaskExecutionContextCacheManagerImpl.class); this.taskLogger = taskLogger; + this.alertClientService = alertClientService; } @Override @@ -140,7 +147,7 @@ public class TaskExecuteThread implements Runnable { taskExecutionContext.getProcessInstanceId(), taskExecutionContext.getTaskInstanceId())); - task = TaskManager.newTask(taskExecutionContext, taskLogger); + task = TaskManager.newTask(taskExecutionContext, taskLogger, alertClientService); // task init task.init(); @@ -201,10 +208,10 @@ public class TaskExecuteThread implements Runnable { // the default timeout is the maximum value of the integer taskExecutionContext.setTaskTimeout(Integer.MAX_VALUE); TaskTimeoutParameter taskTimeoutParameter = taskNode.getTaskTimeoutParameter(); - if (taskTimeoutParameter.getEnable()){ + if (taskTimeoutParameter.getEnable()) { // get timeout strategy taskExecutionContext.setTaskTimeoutStrategy(taskTimeoutParameter.getStrategy().getCode()); - switch (taskTimeoutParameter.getStrategy()){ + switch (taskTimeoutParameter.getStrategy()) { case WARN: break; case FAILED: @@ -225,21 +232,19 @@ public class TaskExecuteThread implements Runnable { } } - /** * kill task */ - public void kill(){ - if (task != null){ + public void kill() { + if (task != null) { try { task.cancelApplication(true); - }catch (Exception e){ + } catch (Exception e) { logger.error(e.getMessage(),e); } } } - /** * download resource file * @@ -250,7 +255,7 @@ public class TaskExecuteThread implements Runnable { private void downloadResource(String execLocalPath, Map projectRes, Logger logger) throws Exception { - if (MapUtils.isEmpty(projectRes)){ + if (MapUtils.isEmpty(projectRes)) { return; } @@ -267,7 +272,7 @@ public class TaskExecuteThread implements Runnable { logger.info("get resource file from hdfs :{}", resHdfsPath); HadoopUtils.getInstance().copyHdfsToLocal(resHdfsPath, execLocalPath + File.separator + fullName, false, true); - }catch (Exception e){ + } catch (Exception e) { logger.error(e.getMessage(),e); throw new RuntimeException(e.getMessage()); } diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/TaskManager.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/TaskManager.java index a9463336b4..b89c8d4ca6 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/TaskManager.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/TaskManager.java @@ -30,6 +30,8 @@ import org.apache.dolphinscheduler.server.worker.task.shell.ShellTask; import org.apache.dolphinscheduler.server.worker.task.spark.SparkTask; import org.apache.dolphinscheduler.server.worker.task.sql.SqlTask; import org.apache.dolphinscheduler.server.worker.task.sqoop.SqoopTask; +import org.apache.dolphinscheduler.service.alert.AlertClientService; + import org.slf4j.Logger; /** @@ -44,7 +46,7 @@ public class TaskManager { * @return AbstractTask * @throws IllegalArgumentException illegal argument exception */ - public static AbstractTask newTask(TaskExecutionContext taskExecutionContext, Logger logger) throws IllegalArgumentException { + public static AbstractTask newTask(TaskExecutionContext taskExecutionContext, Logger logger, AlertClientService alertClientService) throws IllegalArgumentException { TaskType anEnum = EnumUtils.getEnum(TaskType.class, taskExecutionContext.getTaskType()); if (anEnum == null) { logger.error("not support task type: {}", taskExecutionContext.getTaskType()); @@ -57,7 +59,7 @@ public class TaskManager { case PROCEDURE: return new ProcedureTask(taskExecutionContext, logger); case SQL: - return new SqlTask(taskExecutionContext, logger); + return new SqlTask(taskExecutionContext, logger, alertClientService); case MR: return new MapReduceTask(taskExecutionContext, logger); case SPARK: diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java index cba7a488c1..8686e9a660 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java @@ -17,7 +17,6 @@ package org.apache.dolphinscheduler.server.worker.task.sql; -import static org.apache.dolphinscheduler.common.Constants.COMMA; import static org.apache.dolphinscheduler.common.Constants.HIVE_CONF; import static org.apache.dolphinscheduler.common.Constants.PASSWORD; import static org.apache.dolphinscheduler.common.Constants.SEMICOLON; @@ -38,16 +37,15 @@ import org.apache.dolphinscheduler.common.utils.CommonUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; -import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.datasource.BaseDataSource; import org.apache.dolphinscheduler.dao.datasource.DataSourceFactory; -import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand; import org.apache.dolphinscheduler.server.entity.SQLTaskExecutionContext; import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; import org.apache.dolphinscheduler.server.utils.ParamUtils; import org.apache.dolphinscheduler.server.utils.UDFUtils; import org.apache.dolphinscheduler.server.worker.task.AbstractTask; -import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; +import org.apache.dolphinscheduler.service.alert.AlertClientService; import java.sql.Connection; import java.sql.DriverManager; @@ -80,10 +78,7 @@ public class SqlTask extends AbstractTask { * sql parameters */ private SqlParameters sqlParameters; - /** - * alert dao - */ - private AlertDao alertDao; + /** * base datasource */ @@ -99,7 +94,10 @@ public class SqlTask extends AbstractTask { */ private static final int LIMIT = 10000; - public SqlTask(TaskExecutionContext taskExecutionContext, Logger logger) { + + private AlertClientService alertClientService; + + public SqlTask(TaskExecutionContext taskExecutionContext, Logger logger, AlertClientService alertClientService) { super(taskExecutionContext, logger); this.taskExecutionContext = taskExecutionContext; @@ -111,7 +109,7 @@ public class SqlTask extends AbstractTask { throw new RuntimeException("sql task params is not valid"); } - this.alertDao = SpringApplicationContext.getBean(AlertDao.class); + this.alertClientService = alertClientService; } @Override @@ -291,9 +289,7 @@ public class SqlTask extends AbstractTask { String result = JSONUtils.toJsonString(resultJSONArray); logger.debug("execute sql : {}", result); - sendAttachment(StringUtils.isNotEmpty(sqlParameters.getTitle()) - ? sqlParameters.getTitle() : taskExecutionContext.getTaskName() - + " query result sets", + sendAttachment(sqlParameters.getGroupId(), StringUtils.isNotEmpty(sqlParameters.getTitle()) ? sqlParameters.getTitle() : taskExecutionContext.getTaskName() + " query result sets", JSONUtils.toJsonString(resultJSONArray)); } @@ -444,48 +440,11 @@ public class SqlTask extends AbstractTask { * @param title title * @param content content */ - public void sendAttachment(String title, String content) { - - List users = alertDao.queryUserByAlertGroupId(taskExecutionContext.getSqlTaskExecutionContext().getWarningGroupId()); - - // receiving group list - List receiversList = new ArrayList<>(); - for (User user : users) { - receiversList.add(user.getEmail().trim()); + public void sendAttachment(int groupId, String title, String content) { + AlertSendResponseCommand alertSendResponseCommand = alertClientService.sendAlert(groupId, title, content); + if (!alertSendResponseCommand.getResStatus()) { + throw new RuntimeException("send mail failed!"); } - // custom receiver - String receivers = sqlParameters.getReceivers(); - if (StringUtils.isNotEmpty(receivers)) { - String[] splits = receivers.split(COMMA); - for (String receiver : splits) { - receiversList.add(receiver.trim()); - } - } - - // copy list - List receiversCcList = new ArrayList<>(); - // Custom Copier - String receiversCc = sqlParameters.getReceiversCc(); - if (StringUtils.isNotEmpty(receiversCc)) { - String[] splits = receiversCc.split(COMMA); - for (String receiverCc : splits) { - receiversCcList.add(receiverCc.trim()); - } - } - - String showTypeName = sqlParameters.getShowType().replace(COMMA, "").trim(); - /* - if(EnumUtils.isValidEnum(ShowType.class,showTypeName)){ - Map mailResult = MailUtils.sendMails(receviersList, - receviersCcList, title, content, ShowType.valueOf(showTypeName).getDescp()); - if(!(boolean) mailResult.get(STATUS)){ - throw new RuntimeException("send mail failed!"); - } - //TODO AlertServer should provide a grpc interface, which is called when other services need to send alerts - }else{ - logger.error("showType: {} is not valid " ,showTypeName); - throw new RuntimeException(String.format("showType: %s is not valid ",showTypeName)); - }*/ } /** diff --git a/dolphinscheduler-server/src/main/resources/worker.properties b/dolphinscheduler-server/src/main/resources/worker.properties index 9fba30c147..cea1b4ea6c 100644 --- a/dolphinscheduler-server/src/main/resources/worker.properties +++ b/dolphinscheduler-server/src/main/resources/worker.properties @@ -35,3 +35,6 @@ # default worker weight #work.weight=100 + +# alert server listener host +alert.listen.host=localhost diff --git a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java index 2e7e531f30..27c10db13d 100644 --- a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java +++ b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java @@ -31,6 +31,7 @@ import org.apache.dolphinscheduler.server.worker.cache.impl.TaskExecutionContext import org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService; import org.apache.dolphinscheduler.server.worker.task.AbstractTask; import org.apache.dolphinscheduler.server.worker.task.TaskManager; +import org.apache.dolphinscheduler.service.alert.AlertClientService; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import java.util.Date; @@ -64,6 +65,8 @@ public class TaskExecuteThreadTest { private TaskExecutionContextCacheManagerImpl taskExecutionContextCacheManager; + private AlertClientService alertClientService; + @Before public void before() { // init task execution context, logger @@ -100,8 +103,10 @@ public class TaskExecuteThreadTest { PowerMockito.when(SpringApplicationContext.getBean(TaskExecutionContextCacheManagerImpl.class)) .thenReturn(taskExecutionContextCacheManager); + alertClientService = PowerMockito.mock(AlertClientService.class); + PowerMockito.mockStatic(TaskManager.class); - PowerMockito.when(TaskManager.newTask(taskExecutionContext, taskLogger)) + PowerMockito.when(TaskManager.newTask(taskExecutionContext, taskLogger, alertClientService)) .thenReturn(new SimpleTask(taskExecutionContext, taskLogger)); PowerMockito.mockStatic(JSONUtils.class); @@ -117,7 +122,7 @@ public class TaskExecuteThreadTest { taskExecutionContext.setTaskType("SQL"); taskExecutionContext.setStartTime(new Date()); taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); - TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger); + TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger, alertClientService); taskExecuteThread.run(); Assert.assertEquals(ExecutionStatus.SUCCESS, taskExecutionContext.getCurrentExecutionStatus()); @@ -129,7 +134,7 @@ public class TaskExecuteThreadTest { taskExecutionContext.setStartTime(null); taskExecutionContext.setDelayTime(1); taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.DELAY_EXECUTION); - TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger); + TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger, alertClientService); taskExecuteThread.run(); Assert.assertEquals(ExecutionStatus.SUCCESS, taskExecutionContext.getCurrentExecutionStatus()); diff --git a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/TaskManagerTest.java b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/TaskManagerTest.java index eb0383979c..6acfd180c2 100644 --- a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/TaskManagerTest.java +++ b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/TaskManagerTest.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.server.worker.task; import org.apache.dolphinscheduler.common.utils.LoggerUtils; import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; import org.apache.dolphinscheduler.server.worker.cache.impl.TaskExecutionContextCacheManagerImpl; +import org.apache.dolphinscheduler.service.alert.AlertClientService; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import java.util.Date; @@ -46,6 +47,8 @@ public class TaskManagerTest { private TaskExecutionContextCacheManagerImpl taskExecutionContextCacheManager; + private AlertClientService alertClientService; + @Before public void before() { // init task execution context, logger @@ -74,41 +77,43 @@ public class TaskManagerTest { PowerMockito.mockStatic(SpringApplicationContext.class); PowerMockito.when(SpringApplicationContext.getBean(TaskExecutionContextCacheManagerImpl.class)) .thenReturn(taskExecutionContextCacheManager); + + alertClientService = PowerMockito.mock(AlertClientService.class); } @Test public void testNewTask() { taskExecutionContext.setTaskType("SHELL"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("WATERDROP"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("HTTP"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("MR"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("SPARK"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("FLINK"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("PYTHON"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("DATAX"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); taskExecutionContext.setTaskType("SQOOP"); - Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); + Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService)); } @Test(expected = IllegalArgumentException.class) public void testNewTaskIsNull() { taskExecutionContext.setTaskType(null); - TaskManager.newTask(taskExecutionContext,taskLogger); + TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService); } @Test(expected = IllegalArgumentException.class) public void testNewTaskIsNotExists() { taskExecutionContext.setTaskType("XXX"); - TaskManager.newTask(taskExecutionContext,taskLogger); + TaskManager.newTask(taskExecutionContext,taskLogger,alertClientService); } } diff --git a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTaskTest.java b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTaskTest.java new file mode 100644 index 0000000000..64db568916 --- /dev/null +++ b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTaskTest.java @@ -0,0 +1,111 @@ +/* + * 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.server.worker.task.sql; + +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.utils.ParameterUtils; +import org.apache.dolphinscheduler.server.entity.SQLTaskExecutionContext; +import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; +import org.apache.dolphinscheduler.server.worker.task.TaskProps; +import org.apache.dolphinscheduler.service.alert.AlertClientService; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.util.Date; + +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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * sql task test + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(value = {SqlTask.class, DriverManager.class}) +public class SqlTaskTest { + + private static final Logger logger = LoggerFactory.getLogger(SqlTaskTest.class); + + private static final String CONNECTION_PARAMS = "{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:mysql://127.0.0.1:3306\"," + + "\"database\":\"test\",\"jdbcUrl\":\"jdbc:mysql://127.0.0.1:3306/test\"}"; + + private SqlTask sqlTask; + + private TaskExecutionContext taskExecutionContext; + + private AlertClientService alertClientService; + @Before + public void before() throws Exception { + taskExecutionContext = new TaskExecutionContext(); + + TaskProps props = new TaskProps(); + props.setExecutePath("/tmp"); + props.setTaskAppId(String.valueOf(System.currentTimeMillis())); + props.setTaskInstanceId(1); + props.setTenantCode("1"); + props.setEnvFile(".dolphinscheduler_env.sh"); + props.setTaskStartTime(new Date()); + props.setTaskTimeout(0); + props.setTaskParams( + "{\"localParams\":[],\"type\":\"POSTGRESQL\",\"datasource\":1,\"sql\":\"insert into tb_1 values('1','2')\",\"sqlType\":1}"); + + taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class); + PowerMockito.when(taskExecutionContext.getTaskParams()).thenReturn(props.getTaskParams()); + PowerMockito.when(taskExecutionContext.getExecutePath()).thenReturn("/tmp"); + PowerMockito.when(taskExecutionContext.getTaskAppId()).thenReturn("1"); + PowerMockito.when(taskExecutionContext.getTenantCode()).thenReturn("root"); + PowerMockito.when(taskExecutionContext.getStartTime()).thenReturn(new Date()); + PowerMockito.when(taskExecutionContext.getTaskTimeout()).thenReturn(10000); + PowerMockito.when(taskExecutionContext.getLogPath()).thenReturn("/tmp/dx"); + + SQLTaskExecutionContext sqlTaskExecutionContext = new SQLTaskExecutionContext(); + sqlTaskExecutionContext.setConnectionParams(CONNECTION_PARAMS); + PowerMockito.when(taskExecutionContext.getSqlTaskExecutionContext()).thenReturn(sqlTaskExecutionContext); + + alertClientService = PowerMockito.mock(AlertClientService.class); + sqlTask = new SqlTask(taskExecutionContext, logger, alertClientService); + sqlTask.init(); + } + + @Test + public void testGetParameters() { + Assert.assertNotNull(sqlTask.getParameters()); + } + + @Test(expected = Exception.class) + public void testHandle() throws Exception { + Connection connection = PowerMockito.mock(Connection.class); + PowerMockito.mockStatic(DriverManager.class); + PowerMockito.when(DriverManager.getConnection(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(connection); + PreparedStatement preparedStatement = PowerMockito.mock(PreparedStatement.class); + PowerMockito.when(connection.prepareStatement(Mockito.any())).thenReturn(preparedStatement); + PowerMockito.mockStatic(ParameterUtils.class); + PowerMockito.when(ParameterUtils.replaceScheduleTime(Mockito.any(), Mockito.any())).thenReturn("insert into tb_1 values('1','2')"); + + sqlTask.handle(); + Assert.assertEquals(Constants.EXIT_CODE_SUCCESS,sqlTask.getExitStatusCode()); + } +} diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java index 7839b4a460..49977fa969 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java @@ -38,6 +38,10 @@ public class AlertClientService { private volatile boolean isRunning; + private String host; + + private int port; + /** * request time out */ @@ -52,6 +56,17 @@ public class AlertClientService { this.isRunning = true; } + /** + * alert client + */ + public AlertClientService(String host, int port) { + this.clientConfig = new NettyClientConfig(); + this.client = new NettyRemotingClient(clientConfig); + this.isRunning = true; + this.host = host; + this.port = port; + } + /** * close */ @@ -61,6 +76,17 @@ public class AlertClientService { logger.info("alter client closed"); } + /** + * alert sync send data + * @param groupId + * @param title + * @param content + * @return + */ + public AlertSendResponseCommand sendAlert(int groupId, String title, String content) { + return this.sendAlert(this.host,this.port,groupId,title,content); + } + /** * alert sync send data * @param host host diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue index 94ddaf8c5d..8e892ab247 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue @@ -35,12 +35,14 @@ :sql-type="sqlType"> + @@ -174,6 +176,8 @@ sqlType: '0', // Email title title: '', + // Alert groupId + groupId: '', // Form/attachment showType: ['TABLE'], // Sql parameter @@ -181,11 +185,7 @@ // Pre statements preStatements: [], // Post statements - postStatements: [], - // recipients - receivers: [], - // copy to - receiversCc: [] + postStatements: [] } }, mixins: [disabledState], @@ -275,24 +275,18 @@ if (!this.$refs.refDs._verifDatasource()) { return false } + /* if (this.sqlType==0 && !this.showType.length) { this.$message.warning(`${i18n.$t('One form or attachment must be selected')}`) return false } + */ if (this.sqlType==0 && !this.title) { - this.$message.warning(`${i18n.$t('Mail subject required')}`) - return false - } - if (this.sqlType==0 && !this.receivers.length) { - this.$message.warning(`${i18n.$t('Recipient required')}`) + this.$message.warning(`${i18n.$t('Please enter the title of alert')}`) return false } - // receivers Subcomponent verification - if (this.sqlType==0 && !this.$refs.refEmail._manualEmail()) { - return false - } - // receiversCc Subcomponent verification - if (this.sqlType==0 && !this.$refs.refCc._manualEmail()) { + if (this.sqlType==0 && !this.groupId) { + this.$message.warning(`${i18n.$t('Please select the alert group')}`) return false } // udfs Subcomponent verification Verification only if the data type is HIVE @@ -325,8 +319,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, - receivers: this.receivers.join(','), - receiversCc: this.receiversCc.join(','), + groupId: this.groupId, showType: (() => { /** * Special processing return order TABLE,ATTACHMENT @@ -387,10 +380,7 @@ } else { param.processInstanceId = current.params.id } - this.store.dispatch('dag/getReceiver', param).then(res => { - this.receivers = res.receivers && res.receivers.split(',') || [] - this.receiversCc = res.receiversCc && res.receiversCc.split(',') || [] - }) + }, _cacheParams () { this.$emit('on-cache-params', { @@ -400,8 +390,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, - receivers: this.receivers.join(','), - receiversCc: this.receiversCc.join(','), + groupId: this.groupId, showType: (() => { let showType = this.showType @@ -433,8 +422,7 @@ } if (val != 0) { this.title = '' - this.receivers = [] - this.receiversCc = [] + this.groupId = '' } }, // Listening data source @@ -469,8 +457,7 @@ this.preStatements = o.params.preStatements || [] this.postStatements = o.params.postStatements || [] this.title = o.params.title || '' - this.receivers = o.params.receivers && o.params.receivers.split(',') || [] - this.receiversCc = o.params.receiversCc && o.params.receiversCc.split(',') || [] + this.groupId = o.params.groupId || '' } // read tasks from cache if (!_.some(this.store.state.dag.cacheTasks, { id: this.createNodeId }) && @@ -501,8 +488,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, - receivers: this.receivers.join(','), - receiversCc: this.receiversCc.join(','), + groupId: this.groupId, showType: (() => { let showType = this.showType diff --git a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js index f1295da677..00d6757d62 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js @@ -122,6 +122,9 @@ export default { 'SQL Type': 'SQL Type', Title: 'Title', 'Please enter the title of email': 'Please enter the title of email', + 'Please enter the title of alert': 'Please enter the title of alert', + 'AlertGroup': 'AlertGroup', + 'Please select the alert group': 'Please select the alert group', Table: 'Table', TableMode: 'Table', Attachment: 'Attachment', diff --git a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js index 148bc33f0a..e936400d25 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js @@ -122,6 +122,9 @@ export default { 'SQL Type': 'sql类型', Title: '主题', 'Please enter the title of email': '请输入邮件主题', + 'Please enter the title of alert': '请输入告警主题', + 'AlertGroup': '告警组', + 'Please select the alert group': '请选择告警组', Table: '表名', TableMode: '表格', Attachment: '附件', diff --git a/install.sh b/install.sh index da21085d14..7991275a01 100755 --- a/install.sh +++ b/install.sh @@ -64,6 +64,8 @@ sed -i ${txt} "s#mail.smtp.starttls.enable.*#mail.smtp.starttls.enable=${starttl sed -i ${txt} "s#mail.smtp.ssl.trust.*#mail.smtp.ssl.trust=${sslTrust}#g" conf/alert.properties sed -i ${txt} "s#mail.smtp.ssl.enable.*#mail.smtp.ssl.enable=${sslEnable}#g" conf/alert.properties +sed -i ${txt} "s#alert.listen.host.*#alert.listen.host=${alertServer}#g" conf/worker.properties + # 2.create directory echo "2.create directory" diff --git a/pom.xml b/pom.xml index 83681556ce..5f498241ae 100644 --- a/pom.xml +++ b/pom.xml @@ -904,6 +904,7 @@ **/server/worker/registry/WorkerRegistryTest.java **/server/worker/shell/ShellCommandExecutorTest.java **/server/worker/sql/SqlExecutorTest.java + **/server/worker/task/sql/SqlTaskTest.java **/server/worker/task/spark/SparkTaskTest.java **/server/worker/task/EnvFileTest.java **/server/worker/task/spark/SparkTaskTest.java @@ -920,7 +921,6 @@ **/service/zk/CuratorZookeeperClientTest.java **/service/queue/TaskUpdateQueueTest.java **/service/alert/AlertClientServiceTest.java - **/dao/mapper/DataSourceUserMapperTest.java **/dao/mapper/ProcessDefinitionMapperTest.java From 9da6d58d2ece8be0819c4356d56a4e170e83f848 Mon Sep 17 00:00:00 2001 From: samz406 Date: Mon, 14 Dec 2020 15:47:32 +0800 Subject: [PATCH 34/44] [Alert plugin design] add http alert plugin (#4165) * add http alert plugin --- .../dolphinscheduler-alert-http/pom.xml | 72 ++++++++ .../plugin/alert/http/HttpAlertChannel.java | 41 +++++ .../alert/http/HttpAlertChannelFactory.java | 78 ++++++++ .../plugin/alert/http/HttpAlertConstants.java | 35 ++++ .../plugin/alert/http/HttpAlertPlugin.java | 34 ++++ .../plugin/alert/http/HttpSender.java | 166 ++++++++++++++++++ .../http/HttpAlertChannelFactoryTest.java | 54 ++++++ .../alert/http/HttpAlertChannelTest.java | 104 +++++++++++ .../alert/http/HttpAlertPluginTest.java | 38 ++++ .../plugin/alert/http/HttpSenderTest.java | 46 +++++ dolphinscheduler-alert-plugin/pom.xml | 1 + pom.xml | 4 + 12 files changed, 673 insertions(+) create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPluginTest.java create mode 100644 dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml new file mode 100644 index 0000000000..21440d86ed --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml @@ -0,0 +1,72 @@ + + + + + dolphinscheduler-alert-plugin + org.apache.dolphinscheduler + 1.3.2-SNAPSHOT + + 4.0.0 + + dolphinscheduler-alert-http + dolphinscheduler-plugin + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + 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 + + + + \ 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-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java new file mode 100644 index 0000000000..27bc1903d8 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java @@ -0,0 +1,41 @@ +/* + * 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.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.spi.params.PluginParamsTransfer; + +import java.util.Map; + +/** + * http alert channel,use sms message to seed the alertInfo + */ +public class HttpAlertChannel implements AlertChannel { + @Override + public AlertResult process(AlertInfo alertInfo) { + + AlertData alertData = alertInfo.getAlertData(); + String alertParams = alertInfo.getAlertParams(); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + + return new HttpSender(paramsMap).send(alertData.getContent()); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java new file mode 100644 index 0000000000..805c9b38e7 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java @@ -0,0 +1,78 @@ +/* + * 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.AlertChannel; +import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory; +import org.apache.dolphinscheduler.spi.params.InputParam; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.params.base.Validate; + +import java.util.Arrays; +import java.util.List; + +/** + * http alert factory + */ +public class HttpAlertChannelFactory implements AlertChannelFactory { + @Override + public String getName() { + return "http alert"; + } + + @Override + public List getParams() { + + InputParam url = InputParam.newBuilder(HttpAlertConstants.URL, HttpAlertConstants.URL) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam headerParams = InputParam.newBuilder(HttpAlertConstants.HEADER_PARAMS, HttpAlertConstants.HEADER_PARAMS) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam bodyParams = InputParam.newBuilder(HttpAlertConstants.BODY_PARAMS, HttpAlertConstants.BODY_PARAMS) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam contentField = InputParam.newBuilder(HttpAlertConstants.CONTENT_FIELD, HttpAlertConstants.CONTENT_FIELD) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + InputParam requestType = InputParam.newBuilder(HttpAlertConstants.REQUEST_TYPE, HttpAlertConstants.REQUEST_TYPE) + .addValidate(Validate.newBuilder() + .setRequired(true) + .build()) + .build(); + + return Arrays.asList(url, requestType, headerParams, bodyParams, contentField); + } + + @Override + public AlertChannel create() { + return new HttpAlertChannel(); + } +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java new file mode 100644 index 0000000000..965860d868 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java @@ -0,0 +1,35 @@ +/* + * 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; + +public class HttpAlertConstants { + + private HttpAlertConstants() { + } + + public static final String URL = "url"; + + public static final String HEADER_PARAMS = "headerParams"; + + public static final String BODY_PARAMS = "bodyParams"; + + public static final String CONTENT_FIELD = "contentField"; + + public static final String REQUEST_TYPE = "requestType"; + +} 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 new file mode 100644 index 0000000000..973f1617a6 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java @@ -0,0 +1,34 @@ +/* + * 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/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java new file mode 100644 index 0000000000..32d3cdb52f --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java @@ -0,0 +1,166 @@ +/* + * 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.AlertResult; +import org.apache.dolphinscheduler.spi.utils.JSONUtils; +import org.apache.dolphinscheduler.spi.utils.StringUtils; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; + +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; + + + 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"; + + public HttpSender(Map paramsMap) { + + url = paramsMap.get(HttpAlertConstants.URL); + headerParams = paramsMap.get(HttpAlertConstants.HEADER_PARAMS); + bodyParams = paramsMap.get(HttpAlertConstants.BODY_PARAMS); + contentField = paramsMap.get(HttpAlertConstants.CONTENT_FIELD); + requestType = paramsMap.get(HttpAlertConstants.REQUEST_TYPE); + } + + public AlertResult send(String msg) { + + AlertResult alertResult = new AlertResult(); + + createHttpRequest(msg); + + if (httpRequest == null) { + alertResult.setStatus("false"); + alertResult.setMessage("Request types are not supported"); + return alertResult; + } + + try { + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + CloseableHttpResponse response = httpClient.execute(httpRequest); + HttpEntity entity = response.getEntity(); + String resp = EntityUtils.toString(entity, DEFAULT_CHARSET); + alertResult.setStatus("true"); + alertResult.setMessage(resp); + } catch (Exception e) { + logger.error("send http alert msg exception : {}", e.getMessage()); + alertResult.setStatus("false"); + alertResult.setMessage("send http request alert fail."); + } + + return alertResult; + } + + private void createHttpRequest(String msg) { + + if (REQUEST_TYPE_POST.equals(requestType)) { + httpRequest = new HttpPost(url); + //POST request add param in request body + setMsgInRequestBody(msg); + } else if (REQUEST_TYPE_GET.equals(requestType)) { + //GET request add param in url + setMsgInUrl(msg); + httpRequest = new HttpGet(url); + } + setHeader(); + } + + /** + * add msg param in url + */ + private void setMsgInUrl(String msg) { + + if (StringUtils.isNotBlank(contentField)) { + String type = "&"; + //check splice char is & or ? + if (!url.contains(URL_SPLICE_CHAR)) { + type = URL_SPLICE_CHAR; + } + url = String.format("%s%s%s=%s", url, type, contentField, msg); + } + } + + /** + * set header params + */ + private void setHeader() { + + if (httpRequest == null) { + return; + } + + HashMap map = JSONUtils.parseObject(headerParams, HashMap.class); + for (Map.Entry entry : map.entrySet()) { + httpRequest.setHeader(entry.getKey(), String.valueOf(entry.getValue())); + } + } + + /** + * set body params + */ + private String setMsgInRequestBody(String msg) { + ObjectNode objectNode = JSONUtils.parseObject(bodyParams); + //set msg content field + objectNode.put(contentField, msg); + return objectNode.toString(); + } + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java new file mode 100644 index 0000000000..25181ebd26 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactoryTest.java @@ -0,0 +1,54 @@ +/* + * 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.AlertChannel; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * HttpAlertChannelFactory UT + */ +public class HttpAlertChannelFactoryTest { + + private HttpAlertChannelFactory httpAlertChannelFactory; + + @Before + public void init() { + httpAlertChannelFactory = new HttpAlertChannelFactory(); + } + + @Test + public void getParamsTest() { + + List pluginParamsList = httpAlertChannelFactory.getParams(); + Assert.assertEquals(5, pluginParamsList.size()); + } + + @Test + public void createTest() { + AlertChannel alertChannel = httpAlertChannelFactory.create(); + Assert.assertNotNull(alertChannel); + } + +} diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java new file mode 100644 index 0000000000..31a438b4fc --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelTest.java @@ -0,0 +1,104 @@ +/* + * 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.AlertData; +import org.apache.dolphinscheduler.spi.alert.AlertInfo; +import org.apache.dolphinscheduler.spi.alert.AlertResult; +import org.apache.dolphinscheduler.spi.params.InputParam; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.dolphinscheduler.spi.params.base.Validate; +import org.apache.dolphinscheduler.spi.utils.JSONUtils; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +/** + * HttpAlertChannel UT + */ +public class HttpAlertChannelTest { + + @Test + public void processTest() { + + HttpAlertChannel alertChannel = new HttpAlertChannel(); + AlertInfo alertInfo = new AlertInfo(); + AlertData alertData = new AlertData(); + alertData.setContent("Fault tolerance warning"); + alertInfo.setAlertData(alertData); + AlertResult alertResult = alertChannel.process(alertInfo); + Assert.assertEquals("Request types are not supported", alertResult.getMessage()); + } + + @Test + public void processTest2() { + + HttpAlertChannel alertChannel = new HttpAlertChannel(); + AlertInfo alertInfo = new AlertInfo(); + AlertData alertData = new AlertData(); + alertData.setContent("Fault tolerance warning"); + alertInfo.setAlertData(alertData); + alertInfo.setAlertParams(getParams()); + AlertResult alertResult = alertChannel.process(alertInfo); + Assert.assertEquals("true", alertResult.getStatus()); + } + + /** + * create params + */ + private String getParams() { + + List paramsList = new ArrayList<>(); + InputParam urlParam = InputParam.newBuilder("url", "url") + .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(); + + InputParam bodyParams = InputParam.newBuilder("bodyParams", "bodyParams") + .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(); + + InputParam requestType = InputParam.newBuilder("requestType", "requestType") + .setValue("POST") + .addValidate(Validate.newBuilder().setRequired(true).build()) + .build(); + + paramsList.add(urlParam); + paramsList.add(headerParams); + paramsList.add(bodyParams); + paramsList.add(content); + paramsList.add(requestType); + + return JSONUtils.toJsonString(paramsList); + } + +} 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 new file mode 100644 index 0000000000..7dac686e88 --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPluginTest.java @@ -0,0 +1,38 @@ +/* + * 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-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java new file mode 100644 index 0000000000..d59c4d47bb --- /dev/null +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java @@ -0,0 +1,46 @@ +/* + * 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.AlertResult; + +import java.util.HashMap; +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.URL, "http://www.baidu.com"); + paramsMap.put(HttpAlertConstants.REQUEST_TYPE, "POST"); + paramsMap.put(HttpAlertConstants.HEADER_PARAMS, "{\"Content-Type\":\"application/json\"}"); + paramsMap.put(HttpAlertConstants.BODY_PARAMS, "{\"number\":\"13457654323\"}"); + paramsMap.put(HttpAlertConstants.CONTENT_FIELD, "content"); + HttpSender httpSender = new HttpSender(paramsMap); + AlertResult alertResult = httpSender.send("Fault tolerance warning"); + Assert.assertEquals("true", alertResult.getStatus()); + } +} diff --git a/dolphinscheduler-alert-plugin/pom.xml b/dolphinscheduler-alert-plugin/pom.xml index 0f25f1f19b..707f0ceafb 100644 --- a/dolphinscheduler-alert-plugin/pom.xml +++ b/dolphinscheduler-alert-plugin/pom.xml @@ -34,6 +34,7 @@ dolphinscheduler-alert-wechat dolphinscheduler-alert-dingtalk dolphinscheduler-alert-script + dolphinscheduler-alert-http diff --git a/pom.xml b/pom.xml index 5f498241ae..9c154bd7f2 100644 --- a/pom.xml +++ b/pom.xml @@ -960,6 +960,10 @@ **/plugin/alert/script/ProcessUtilsTest.java **/plugin/alert/script/ScriptAlertChannelFactoryTest.java **/plugin/alert/script/ScriptSenderTest.java + **/plugin/alert/http/HttpAlertChannelFactoryTest.java + **/plugin/alert/http/HttpAlertChannelTest.java + **/plugin/alert/http/HttpAlertPluginTest.java + **/plugin/alert/http/HttpSenderTest.java **/spi/params/PluginParamsTransferTest.java **/alert/plugin/AlertPluginManagerTest.java From cb25810668a6dba8fad69932927306d87f708f3b Mon Sep 17 00:00:00 2001 From: Yichao Yang <1048262223@qq.com> Date: Wed, 23 Dec 2020 09:35:10 +0800 Subject: [PATCH 35/44] [Feature-3311] Add alert plugin instance function (#4038) --- .../AlertPluginInstanceController.java | 147 ++++++ .../dolphinscheduler/api/enums/Status.java | 5 + .../service/AlertPluginInstanceService.java | 65 +++ .../impl/AlertPluginInstanceServiceImpl.java | 122 +++++ .../main/resources/i18n/messages.properties | 9 +- .../resources/i18n/messages_en_US.properties | 9 +- .../resources/i18n/messages_zh_CN.properties | 489 +++++++++--------- 7 files changed, 600 insertions(+), 246 deletions(-) create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java new file mode 100644 index 0000000000..8797cc6ffb --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java @@ -0,0 +1,147 @@ +/* + * 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.api.controller; + +import static org.apache.dolphinscheduler.api.enums.Status.CREATE_ALERT_PLUGIN_INSTANCE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.DELETE_ALERT_PLUGIN_INSTANCE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.GET_ALERT_PLUGIN_INSTANCE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_PLUGIN_INSTANCE_ERROR; + +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import springfox.documentation.annotations.ApiIgnore; + +/** + * alert plugin instance controller + */ +@Api(tags = "ALERT_PLUGIN_INSTANCE_TAG", position = 1) +@RestController +@RequestMapping("alert-plugin-instance") +public class AlertPluginInstanceController extends BaseController { + + private static final Logger logger = LoggerFactory.getLogger(AlertPluginInstanceController.class); + + @Autowired + private AlertPluginInstanceService alertPluginInstanceService; + + + /** + * create alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alertPluginInstance + * @return create result code + */ + @ApiOperation(value = "createAlertPluginInstance", notes = "CREATE_ALERT_PLUGIN_INSTANCE_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), + @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") + }) + @PostMapping(value = "/create") + @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_ALERT_PLUGIN_INSTANCE_ERROR) + public Result createAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestBody AlertPluginInstance alertPluginInstance) { + logger.info("loginUser user {}, create alert plugin instance, groupName: " + , loginUser.getUserName()); + Map result = alertPluginInstanceService.create(loginUser, alertPluginInstance); + return returnDataList(result); + } + + /** + * updateAlertPluginInstance + * + * @param loginUser login user + * @param alertPluginInstance alertPluginInstance + * @return result + */ + @ApiOperation(value = "update", notes = "UPDATE_ALERT_PLUGIN_INSTANCE_NOTES") + @GetMapping(value = "/update") + @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_ALERT_PLUGIN_INSTANCE_ERROR) + public Result updateAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestBody AlertPluginInstance alertPluginInstance) { + logger.info("login user {}, update alert plugin instance id {}", + loginUser.getUserName(), alertPluginInstance.getId()); + Map result = alertPluginInstanceService.update(loginUser, alertPluginInstance); + return returnDataList(result); + } + + /** + * deleteAlertPluginInstance + * + * @param loginUser login user + * @param alertPluginInstance alertPluginInstance + * @return result + */ + @ApiOperation(value = "delete", notes = "DELETE_ALERT_PLUGIN_INSTANCE_NOTES") + @GetMapping(value = "/delete") + @ResponseStatus(HttpStatus.OK) + @ApiException(DELETE_ALERT_PLUGIN_INSTANCE_ERROR) + public Result deleteAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestBody AlertPluginInstance alertPluginInstance) { + logger.info("login user {}, delete alert plugin instance id {}", loginUser.getUserName(), alertPluginInstance.getId()); + + Map result = alertPluginInstanceService.delete(loginUser, alertPluginInstance); + return returnDataListPaging(result); + } + + /** + * getAlertPluginInstance + * + * @param loginUser login user + * @param id alert plugin instance id + * @return result + */ + @ApiOperation(value = "get", notes = "GET_ALERT_PLUGIN_INSTANCE_NOTES") + @PostMapping(value = "/get") + @ResponseStatus(HttpStatus.OK) + @ApiException(GET_ALERT_PLUGIN_INSTANCE_ERROR) + public Result getAlertPluginInstance(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "id") int id) { + logger.info("login user {}, get alert plugin instance, id {}", + loginUser.getUserName(), id); + Map result = alertPluginInstanceService.get(loginUser, id); + return returnDataList(result); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 4fda99c37d..a890e5c1ed 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -196,6 +196,11 @@ public enum Status { DELETE_PROCESS_DEFINITION_BY_ID_FAIL(10162, "delete process definition by id fail, for there are {0} process instances in executing using it", "删除工作流定义失败,有[{0}]个运行中的工作流实例正在使用"), CHECK_TENANT_CODE_ERROR(10163, "Please enter the English tenant code", "请输入英文租户编码"), + CREATE_ALERT_PLUGIN_INSTANCE_ERROR(10164, "create alert plugin instance error", "创建告警组和告警组插件实例错误"), + UPDATE_ALERT_PLUGIN_INSTANCE_ERROR(10165, "update alert plugin instance error", "更新告警组和告警组插件实例错误"), + DELETE_ALERT_PLUGIN_INSTANCE_ERROR(10166, "delete alert plugin instance error", "删除告警组和告警组插件实例错误"), + GET_ALERT_PLUGIN_INSTANCE_ERROR(10167, "get alert plugin instance error", "获取告警组和告警组插件实例错误"), + UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found", "UDF函数不存在"), UDF_FUNCTION_EXISTS(20002, "UDF function already exists", "UDF函数已存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java new file mode 100644 index 0000000000..bf6d59ffb3 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java @@ -0,0 +1,65 @@ +/* + * 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.api.service; + +import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Map; + +/** + * alert plugin instance service + */ +public interface AlertPluginInstanceService { + + /** + * creat alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alert plugin instance + * @return result + */ + Map create(User loginUser, AlertPluginInstance alertPluginInstance); + + /** + * update alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alert plugin instance + * @return result + */ + Map update(User loginUser, AlertPluginInstance alertPluginInstance); + + /** + * delete alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alert plugin instance + * @return result + */ + Map delete(User loginUser, AlertPluginInstance alertPluginInstance); + + /** + * get alert plugin instance + * + * @param loginUser login user + * @param id get id + * @return alert plugin + */ + Map get(User loginUser, int id); +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java new file mode 100644 index 0000000000..7fa964b60e --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java @@ -0,0 +1,122 @@ +/* + * 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.api.service.impl; + +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService; +import org.apache.dolphinscheduler.api.service.BaseService; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; +import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; + +/** + * alert plugin instance service impl + */ +@Service +@Lazy +public class AlertPluginInstanceServiceImpl extends BaseService implements AlertPluginInstanceService { + + @Autowired + private AlertPluginInstanceMapper alertPluginInstanceMapper; + + /** + * creat alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alert plugin instance + * @return result + */ + @Override + public Map create(User loginUser, AlertPluginInstance alertPluginInstance) { + + Map result = new HashMap<>(); + + int i = alertPluginInstanceMapper.insert(alertPluginInstance); + + if (i > 0) { + putMsg(result, Status.SUCCESS); + } + return result; + } + + /** + * update alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alert plugin instance + * @return result + */ + @Override + public Map update(User loginUser, AlertPluginInstance alertPluginInstance) { + + Map result = new HashMap<>(); + int i = alertPluginInstanceMapper.updateById(alertPluginInstance); + + if (i > 0) { + putMsg(result, Status.SUCCESS); + } + + return result; + } + + /** + * delete alert plugin instance + * + * @param loginUser login user + * @param alertPluginInstance alert plugin instance + * @return result + */ + @Override + public Map delete(User loginUser, AlertPluginInstance alertPluginInstance) { + Map result = new HashMap<>(); + int i = alertPluginInstanceMapper.deleteById(alertPluginInstance.getId()); + if (i > 0) { + putMsg(result, Status.SUCCESS); + } + + return result; + } + + /** + * get alert plugin instance + * + * @param loginUser login user + * @param id get id + * @return alert plugin + */ + @Override + public Map get(User loginUser, int id) { + Map result = new HashMap<>(); + AlertPluginInstance alertPluginInstance = alertPluginInstanceMapper.selectById(id); + + if (null != alertPluginInstance) { + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, alertPluginInstance); + } + + return result; + } +} diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages.properties b/dolphinscheduler-api/src/main/resources/i18n/messages.properties index d1da3e94a8..c426dedd15 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages.properties @@ -19,7 +19,7 @@ QUERY_SCHEDULE_LIST_NOTES=query schedule list EXECUTE_PROCESS_TAG=execute process related operation PROCESS_INSTANCE_EXECUTOR_TAG=process instance executor related operation RUN_PROCESS_INSTANCE_NOTES=run process instance -START_NODE_LIST=start node list(node name) +START_NODE_LIST=start node list\uFF08node name\uFF09 TASK_DEPEND_TYPE=task depend type COMMAND_TYPE=command type RUN_MODE=run mode @@ -38,6 +38,11 @@ VERIFY_ALERT_GROUP_NAME_NOTES=verify alert group name, check alert group exist o GRANT_ALERT_GROUP_NOTES=grant alert group USER_IDS=user id list ALERT_GROUP_TAG=alert group related operation +ALERT_PLUGIN_INSTANCE_TAG=alert plugin instance related operation +UPDATE_ALERT_PLUGIN_INSTANCE_NOTES=update alert plugin instance operation +CREATE_ALERT_PLUGIN_INSTANCE_NOTES=create alert plugin instance operation +DELETE_ALERT_PLUGIN_INSTANCE_NOTES=delete alert plugin instance operation +GET_ALERT_PLUGIN_INSTANCE_NOTES=get alert plugin instance operation CREATE_ALERT_GROUP_NOTES=create alert group WORKER_GROUP_TAG=worker group related operation SAVE_WORKER_GROUP_NOTES=create worker group @@ -134,7 +139,7 @@ QUERY_ALL_PROJECT_LIST_NOTES=query all project list QUERY_AUTHORIZED_PROJECT_NOTES=query authorized project TASK_RECORD_TAG=task record related operation QUERY_TASK_RECORD_LIST_PAGING_NOTES=query task record list paging -CREATE_TOKEN_NOTES=create token ,note: please login first +CREATE_TOKEN_NOTES=create token \uFF0Cnote: please login first QUERY_ACCESS_TOKEN_LIST_NOTES=query access token list paging SCHEDULE=schedule WARNING_TYPE=warning type(sending strategy) diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties index 267f93b14d..976237aa26 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties @@ -19,7 +19,7 @@ QUERY_SCHEDULE_LIST_NOTES=query schedule list EXECUTE_PROCESS_TAG=execute process related operation PROCESS_INSTANCE_EXECUTOR_TAG=process instance executor related operation RUN_PROCESS_INSTANCE_NOTES=run process instance -START_NODE_LIST=start node list(node name) +START_NODE_LIST=start node list\uFF08node name\uFF09 TASK_DEPEND_TYPE=task depend type COMMAND_TYPE=command type RUN_MODE=run mode @@ -38,6 +38,11 @@ VERIFY_ALERT_GROUP_NAME_NOTES=verify alert group name, check alert group exist o GRANT_ALERT_GROUP_NOTES=grant alert group USER_IDS=user id list ALERT_GROUP_TAG=alert group related operation +ALERT_PLUGIN_INSTANCE_TAG=alert plugin instance related operation +UPDATE_ALERT_PLUGIN_INSTANCE_NOTES=update alert plugin instance operation +CREATE_ALERT_PLUGIN_INSTANCE_NOTES=create alert plugin instance operation +DELETE_ALERT_PLUGIN_INSTANCE_NOTES=delete alert plugin instance operation +GET_ALERT_PLUGIN_INSTANCE_NOTES=get alert plugin instance operation CREATE_ALERT_GROUP_NOTES=create alert group WORKER_GROUP_TAG=worker group related operation SAVE_WORKER_GROUP_NOTES=create worker group @@ -134,7 +139,7 @@ QUERY_UNAUTHORIZED_PROJECT_NOTES=query unauthorized project QUERY_AUTHORIZED_PROJECT_NOTES=query authorized project TASK_RECORD_TAG=task record related operation QUERY_TASK_RECORD_LIST_PAGING_NOTES=query task record list paging -CREATE_TOKEN_NOTES=create token ,note: please login first +CREATE_TOKEN_NOTES=create token \uFF0Cnote: please login first QUERY_ACCESS_TOKEN_LIST_NOTES=query access token list paging SCHEDULE=schedule WARNING_TYPE=warning type(sending strategy) diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties index 16262e6bbc..23395fe428 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties @@ -15,248 +15,253 @@ # limitations under the License. # -QUERY_SCHEDULE_LIST_NOTES=查询定时列表 -PROCESS_INSTANCE_EXECUTOR_TAG=流程实例执行相关操作 -RUN_PROCESS_INSTANCE_NOTES=运行流程实例 -START_NODE_LIST=开始节点列表(节点name) -TASK_DEPEND_TYPE=任务依赖类型 -COMMAND_TYPE=指令类型 -RUN_MODE=运行模式 -TIMEOUT=超时时间 -EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES=执行流程实例的各种操作(暂停、停止、重跑、恢复等) -EXECUTE_TYPE=执行类型 -START_CHECK_PROCESS_DEFINITION_NOTES=检查流程定义 -DESC=备注(描述) -GROUP_NAME=组名称 -GROUP_TYPE=组类型 -QUERY_ALERT_GROUP_LIST_NOTES=告警组列表\ +QUERY_SCHEDULE_LIST_NOTES=\u67E5\u8BE2\u5B9A\u65F6\u5217\u8868 +PROCESS_INSTANCE_EXECUTOR_TAG=\u6D41\u7A0B\u5B9E\u4F8B\u6267\u884C\u76F8\u5173\u64CD\u4F5C +RUN_PROCESS_INSTANCE_NOTES=\u8FD0\u884C\u6D41\u7A0B\u5B9E\u4F8B +START_NODE_LIST=\u5F00\u59CB\u8282\u70B9\u5217\u8868(\u8282\u70B9name) +TASK_DEPEND_TYPE=\u4EFB\u52A1\u4F9D\u8D56\u7C7B\u578B +COMMAND_TYPE=\u6307\u4EE4\u7C7B\u578B +RUN_MODE=\u8FD0\u884C\u6A21\u5F0F +TIMEOUT=\u8D85\u65F6\u65F6\u95F4 +EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES=\u6267\u884C\u6D41\u7A0B\u5B9E\u4F8B\u7684\u5404\u79CD\u64CD\u4F5C(\u6682\u505C\u3001\u505C\u6B62\u3001\u91CD\u8DD1\u3001\u6062\u590D\u7B49) +EXECUTE_TYPE=\u6267\u884C\u7C7B\u578B +START_CHECK_PROCESS_DEFINITION_NOTES=\u68C0\u67E5\u6D41\u7A0B\u5B9A\u4E49 +DESC=\u5907\u6CE8(\u63CF\u8FF0) +GROUP_NAME=\u7EC4\u540D\u79F0 +GROUP_TYPE=\u7EC4\u7C7B\u578B +QUERY_ALERT_GROUP_LIST_NOTES=\u544A\u8B66\u7EC4\u5217\u8868\ -UPDATE_ALERT_GROUP_NOTES=编辑(更新)告警组 -DELETE_ALERT_GROUP_BY_ID_NOTES=删除告警组通过ID -VERIFY_ALERT_GROUP_NAME_NOTES=检查告警组是否存在 -GRANT_ALERT_GROUP_NOTES=授权告警组 -USER_IDS=用户ID列表 -ALERT_GROUP_TAG=告警组相关操作 -WORKER_GROUP_TAG=Worker分组管理 -SAVE_WORKER_GROUP_NOTES=创建Worker分组\ +UPDATE_ALERT_GROUP_NOTES=\u7F16\u8F91(\u66F4\u65B0)\u544A\u8B66\u7EC4 +DELETE_ALERT_GROUP_BY_ID_NOTES=\u5220\u9664\u544A\u8B66\u7EC4\u901A\u8FC7ID +VERIFY_ALERT_GROUP_NAME_NOTES=\u68C0\u67E5\u544A\u8B66\u7EC4\u662F\u5426\u5B58\u5728 +GRANT_ALERT_GROUP_NOTES=\u6388\u6743\u544A\u8B66\u7EC4 +USER_IDS=\u7528\u6237ID\u5217\u8868 +ALERT_GROUP_TAG=\u544A\u8B66\u7EC4\u76F8\u5173\u64CD\u4F5C +ALERT_PLUGIN_INSTANCE_TAG=\u544A\u8B66\u7EC4\u548C\u544A\u8B66\u63D2\u4EF6\u76F8\u5173\u64CD\u4F5C +UPDATE_ALERT_PLUGIN_INSTANCE_NOTES=\u66F4\u65B0\u544A\u8B66\u7EC4\u63D2\u4EF6\u5B9E\u4F8B +CREATE_ALERT_PLUGIN_INSTANCE_NOTES=\u521B\u5EFA\u544A\u8B66\u7EC4\u63D2\u4EF6\u5B9E\u4F8B +DELETE_ALERT_PLUGIN_INSTANCE_NOTES=\u5220\u9664\u544A\u8B66\u7EC4\u63D2\u4EF6\u5B9E\u4F8B +GET_ALERT_PLUGIN_INSTANCE_NOTES=\u83B7\u53D6\u544A\u8B66\u7EC4\u63D2\u4EF6\u5B9E\u4F8B +WORKER_GROUP_TAG=Worker\u5206\u7EC4\u7BA1\u7406 +SAVE_WORKER_GROUP_NOTES=\u521B\u5EFAWorker\u5206\u7EC4\ -WORKER_GROUP_NAME=Worker分组名称 -WORKER_IP_LIST=Worker ip列表,注意:多个IP地址以逗号分割\ +WORKER_GROUP_NAME=Worker\u5206\u7EC4\u540D\u79F0 +WORKER_IP_LIST=Worker ip\u5217\u8868\uFF0C\u6CE8\u610F\uFF1A\u591A\u4E2AIP\u5730\u5740\u4EE5\u9017\u53F7\u5206\u5272\ -QUERY_WORKER_GROUP_PAGING_NOTES=Worker分组管理 -QUERY_WORKER_GROUP_LIST_NOTES=查询worker group分组 -DELETE_WORKER_GROUP_BY_ID_NOTES=删除worker group通过ID -DATA_ANALYSIS_TAG=任务状态分析相关操作 -COUNT_TASK_STATE_NOTES=任务状态统计 -COUNT_PROCESS_INSTANCE_NOTES=统计流程实例状态 -COUNT_PROCESS_DEFINITION_BY_USER_NOTES=统计用户创建的流程定义 -COUNT_COMMAND_STATE_NOTES=统计命令状态 -COUNT_QUEUE_STATE_NOTES=统计队列里任务状态 -ACCESS_TOKEN_TAG=access token相关操作,需要先登录 -MONITOR_TAG=监控相关操作 -MASTER_LIST_NOTES=master服务列表 -WORKER_LIST_NOTES=worker服务列表 -QUERY_DATABASE_STATE_NOTES=查询数据库状态 -QUERY_ZOOKEEPER_STATE_NOTES=查询Zookeeper状态 -TASK_STATE=任务实例状态 -SOURCE_TABLE=源表 -DEST_TABLE=目标表 -TASK_DATE=任务时间 -QUERY_HISTORY_TASK_RECORD_LIST_PAGING_NOTES=分页查询历史任务记录列表 -DATA_SOURCE_TAG=数据源相关操作 -CREATE_DATA_SOURCE_NOTES=创建数据源 -DATA_SOURCE_NAME=数据源名称 -DATA_SOURCE_NOTE=数据源描述 -DB_TYPE=数据源类型 -DATA_SOURCE_HOST=IP主机名 -DATA_SOURCE_PORT=数据源端口 -DATABASE_NAME=数据库名 -QUEUE_TAG=队列相关操作 -QUERY_QUEUE_LIST_NOTES=查询队列列表 -QUERY_QUEUE_LIST_PAGING_NOTES=分页查询队列列表 -CREATE_QUEUE_NOTES=创建队列 -YARN_QUEUE_NAME=hadoop yarn队列名 -QUEUE_ID=队列ID -TENANT_DESC=租户描述 -QUERY_TENANT_LIST_PAGING_NOTES=分页查询租户列表 -QUERY_TENANT_LIST_NOTES=查询租户列表 -UPDATE_TENANT_NOTES=更新租户 -DELETE_TENANT_NOTES=删除租户 -RESOURCES_TAG=资源中心相关操作 -CREATE_RESOURCE_NOTES=创建资源 -RESOURCE_TYPE=资源文件类型 -RESOURCE_NAME=资源文件名称 -RESOURCE_DESC=资源文件描述 -RESOURCE_FILE=资源文件 -RESOURCE_ID=资源ID -QUERY_RESOURCE_LIST_NOTES=查询资源列表 -DELETE_RESOURCE_BY_ID_NOTES=删除资源通过ID -VIEW_RESOURCE_BY_ID_NOTES=浏览资源通通过ID -ONLINE_CREATE_RESOURCE_NOTES=在线创建资源 -SUFFIX=资源文件后缀 -CONTENT=资源文件内容 -UPDATE_RESOURCE_NOTES=在线更新资源文件 -DOWNLOAD_RESOURCE_NOTES=下载资源文件 -CREATE_UDF_FUNCTION_NOTES=创建UDF函数 -UDF_TYPE=UDF类型 -FUNC_NAME=函数名称 -CLASS_NAME=包名类名 -ARG_TYPES=参数 -UDF_DESC=udf描述,使用说明 -VIEW_UDF_FUNCTION_NOTES=查看udf函数 -UPDATE_UDF_FUNCTION_NOTES=更新udf函数 -QUERY_UDF_FUNCTION_LIST_PAGING_NOTES=分页查询udf函数列表 -VERIFY_UDF_FUNCTION_NAME_NOTES=验证udf函数名 -DELETE_UDF_FUNCTION_NOTES=删除UDF函数 -AUTHORIZED_FILE_NOTES=授权文件 -UNAUTHORIZED_FILE_NOTES=取消授权文件 -AUTHORIZED_UDF_FUNC_NOTES=授权udf函数 -UNAUTHORIZED_UDF_FUNC_NOTES=取消udf函数授权 -VERIFY_QUEUE_NOTES=验证队列 -TENANT_TAG=租户相关操作 -CREATE_TENANT_NOTES=创建租户 -TENANT_CODE=租户编码 -TENANT_NAME=租户名称 -QUEUE_NAME=队列名 -PASSWORD=密码 -DATA_SOURCE_OTHER=jdbc连接参数,格式为:{"key1":"value1",...} -PROJECT_TAG=项目相关操作 -CREATE_PROJECT_NOTES=创建项目 -PROJECT_DESC=项目描述 -UPDATE_PROJECT_NOTES=更新项目 -PROJECT_ID=项目ID -QUERY_PROJECT_BY_ID_NOTES=通过项目ID查询项目信息 -QUERY_PROJECT_LIST_PAGING_NOTES=分页查询项目列表 -QUERY_ALL_PROJECT_LIST_NOTES=查询所有项目 -DELETE_PROJECT_BY_ID_NOTES=删除项目通过ID -QUERY_UNAUTHORIZED_PROJECT_NOTES=查询未授权的项目 -QUERY_AUTHORIZED_PROJECT_NOTES=查询授权项目 -TASK_RECORD_TAG=任务记录相关操作 -QUERY_TASK_RECORD_LIST_PAGING_NOTES=分页查询任务记录列表 -CREATE_TOKEN_NOTES=创建token,注意需要先登录 -QUERY_ACCESS_TOKEN_LIST_NOTES=分页查询access token列表 -SCHEDULE=定时 -WARNING_TYPE=发送策略 -WARNING_GROUP_ID=发送组ID -FAILURE_STRATEGY=失败策略 -RECEIVERS=收件人 -RECEIVERS_CC=收件人(抄送) -WORKER_GROUP_ID=Worker Server分组ID -PROCESS_INSTANCE_PRIORITY=流程实例优先级 -UPDATE_SCHEDULE_NOTES=更新定时 -SCHEDULE_ID=定时ID -ONLINE_SCHEDULE_NOTES=定时上线 -OFFLINE_SCHEDULE_NOTES=定时下线 -QUERY_SCHEDULE_NOTES=查询定时 -QUERY_SCHEDULE_LIST_PAGING_NOTES=分页查询定时 -LOGIN_TAG=用户登录相关操作 -USER_NAME=用户名 -PROJECT_NAME=项目名称 -CREATE_PROCESS_DEFINITION_NOTES=创建流程定义 -PROCESS_DEFINITION_NAME=流程定义名称 -PROCESS_DEFINITION_JSON=流程定义详细信息(json格式) -PROCESS_DEFINITION_LOCATIONS=流程定义节点坐标位置信息(json格式) -PROCESS_INSTANCE_LOCATIONS=流程实例节点坐标位置信息(json格式) -PROCESS_DEFINITION_CONNECTS=流程定义节点图标连接信息(json格式) -PROCESS_INSTANCE_CONNECTS=流程实例节点图标连接信息(json格式) -PROCESS_DEFINITION_DESC=流程定义描述信息 -PROCESS_DEFINITION_TAG=流程定义相关操作 -SIGNOUT_NOTES=退出登录 -USER_PASSWORD=用户密码 -UPDATE_PROCESS_INSTANCE_NOTES=更新流程实例 -QUERY_PROCESS_INSTANCE_LIST_NOTES=查询流程实例列表 -VERIFY_PROCESS_DEFINITION_NAME_NOTES=验证流程定义名字 -LOGIN_NOTES=用户登录 -UPDATE_PROCESS_DEFINITION_NOTES=更新流程定义 -PROCESS_DEFINITION_ID=流程定义ID -RELEASE_PROCESS_DEFINITION_NOTES=发布流程定义 -QUERY_PROCESS_DEFINITION_BY_ID_NOTES=查询流程定义通过流程定义ID -QUERY_PROCESS_DEFINITION_LIST_NOTES=查询流程定义列表 -QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES=分页查询流程定义列表 -QUERY_ALL_DEFINITION_LIST_NOTES=查询所有流程定义 -PAGE_NO=页码号 -PROCESS_INSTANCE_ID=流程实例ID -PROCESS_INSTANCE_IDS=流程实例ID集合 -PROCESS_INSTANCE_JSON=流程实例信息(json格式) -SCHEDULE_TIME=定时时间 -SYNC_DEFINE=更新流程实例的信息是否同步到流程定义 -RECOVERY_PROCESS_INSTANCE_FLAG=是否恢复流程实例 -SEARCH_VAL=搜索值 -USER_ID=用户ID -PAGE_SIZE=页大小 -LIMIT=显示多少条 -VIEW_TREE_NOTES=树状图 -GET_NODE_LIST_BY_DEFINITION_ID_NOTES=获得任务节点列表通过流程定义ID -PROCESS_DEFINITION_ID_LIST=流程定义id列表 -QUERY_PROCESS_DEFINITION_All_BY_PROJECT_ID_NOTES=查询流程定义通过项目ID -BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES=批量删除流程定义通过流程定义ID集合 -DELETE_PROCESS_DEFINITION_BY_ID_NOTES=删除流程定义通过流程定义ID -QUERY_PROCESS_INSTANCE_BY_ID_NOTES=查询流程实例通过流程实例ID -DELETE_PROCESS_INSTANCE_BY_ID_NOTES=删除流程实例通过流程实例ID -TASK_ID=任务实例ID -SKIP_LINE_NUM=忽略行数 -QUERY_TASK_INSTANCE_LOG_NOTES=查询任务实例日志 -DOWNLOAD_TASK_INSTANCE_LOG_NOTES=下载任务实例日志 -USERS_TAG=用户相关操作 -SCHEDULER_TAG=定时相关操作 -CREATE_SCHEDULE_NOTES=创建定时 -CREATE_USER_NOTES=创建用户 -TENANT_ID=租户ID -QUEUE=使用的队列 -EMAIL=邮箱 -PHONE=手机号 -QUERY_USER_LIST_NOTES=查询用户列表 -UPDATE_USER_NOTES=更新用户 -DELETE_USER_BY_ID_NOTES=删除用户通过ID -GRANT_PROJECT_NOTES=授权项目 -PROJECT_IDS=项目IDS(字符串格式,多个项目以","分割) -GRANT_RESOURCE_NOTES=授权资源文件 -RESOURCE_IDS=资源ID列表(字符串格式,多个资源ID以","分割) -GET_USER_INFO_NOTES=获取用户信息 -LIST_USER_NOTES=用户列表 -VERIFY_USER_NAME_NOTES=验证用户名 -UNAUTHORIZED_USER_NOTES=取消授权 -ALERT_GROUP_ID=报警组ID -AUTHORIZED_USER_NOTES=授权用户 -GRANT_UDF_FUNC_NOTES=授权udf函数 -UDF_IDS=udf函数id列表(字符串格式,多个udf函数ID以","分割) -GRANT_DATASOURCE_NOTES=授权数据源 -DATASOURCE_IDS=数据源ID列表(字符串格式,多个数据源ID以","分割) -QUERY_SUBPROCESS_INSTANCE_BY_TASK_ID_NOTES=查询子流程实例通过任务实例ID -QUERY_PARENT_PROCESS_INSTANCE_BY_SUB_PROCESS_INSTANCE_ID_NOTES=查询父流程实例信息通过子流程实例ID -QUERY_PROCESS_INSTANCE_GLOBAL_VARIABLES_AND_LOCAL_VARIABLES_NOTES=查询流程实例全局变量和局部变量 -VIEW_GANTT_NOTES=浏览Gantt图 -SUB_PROCESS_INSTANCE_ID=子流程是咧ID -TASK_NAME=任务实例名 -TASK_INSTANCE_TAG=任务实例相关操作 -LOGGER_TAG=日志相关操作 -PROCESS_INSTANCE_TAG=流程实例相关操作 -EXECUTION_STATUS=工作流和任务节点的运行状态 -HOST=运行任务的主机IP地址 -START_DATE=开始时间 -END_DATE=结束时间 -QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_NOTES=通过流程实例ID查询任务列表 -UPDATE_DATA_SOURCE_NOTES=更新数据源 -DATA_SOURCE_ID=数据源ID -QUERY_DATA_SOURCE_NOTES=查询数据源通过ID -QUERY_DATA_SOURCE_LIST_BY_TYPE_NOTES=查询数据源列表通过数据源类型 -QUERY_DATA_SOURCE_LIST_PAGING_NOTES=分页查询数据源列表 -CONNECT_DATA_SOURCE_NOTES=连接数据源 -CONNECT_DATA_SOURCE_TEST_NOTES=连接数据源测试 -DELETE_DATA_SOURCE_NOTES=删除数据源 -VERIFY_DATA_SOURCE_NOTES=验证数据源 -UNAUTHORIZED_DATA_SOURCE_NOTES=未授权的数据源 -AUTHORIZED_DATA_SOURCE_NOTES=授权的数据源 -DELETE_SCHEDULER_BY_ID_NOTES=根据定时id删除定时数据 -QUERY_ALERT_GROUP_LIST_PAGING_NOTES=分页查询告警组列表 -EXPORT_PROCESS_DEFINITION_BY_ID_NOTES=通过工作流ID导出工作流定义 -BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES=批量导出工作流定义 -QUERY_USER_CREATED_PROJECT_NOTES= 查询用户创建的项目 -COPY_PROCESS_DEFINITION_NOTES= 复制工作流定义 -MOVE_PROCESS_DEFINITION_NOTES= 移动工作流定义 -TARGET_PROJECT_ID= 目标项目ID -IS_COPY = 是否复制 -DELETE_PROCESS_DEFINITION_VERSION_NOTES=删除流程历史版本 -QUERY_PROCESS_DEFINITION_VERSIONS_NOTES=查询流程历史版本信息 -SWITCH_PROCESS_DEFINITION_VERSION_NOTES=切换流程版本 -VERSION=版本号 +QUERY_WORKER_GROUP_PAGING_NOTES=Worker\u5206\u7EC4\u7BA1\u7406 +QUERY_WORKER_GROUP_LIST_NOTES=\u67E5\u8BE2worker group\u5206\u7EC4 +DELETE_WORKER_GROUP_BY_ID_NOTES=\u5220\u9664worker group\u901A\u8FC7ID +DATA_ANALYSIS_TAG=\u4EFB\u52A1\u72B6\u6001\u5206\u6790\u76F8\u5173\u64CD\u4F5C +COUNT_TASK_STATE_NOTES=\u4EFB\u52A1\u72B6\u6001\u7EDF\u8BA1 +COUNT_PROCESS_INSTANCE_NOTES=\u7EDF\u8BA1\u6D41\u7A0B\u5B9E\u4F8B\u72B6\u6001 +COUNT_PROCESS_DEFINITION_BY_USER_NOTES=\u7EDF\u8BA1\u7528\u6237\u521B\u5EFA\u7684\u6D41\u7A0B\u5B9A\u4E49 +COUNT_COMMAND_STATE_NOTES=\u7EDF\u8BA1\u547D\u4EE4\u72B6\u6001 +COUNT_QUEUE_STATE_NOTES=\u7EDF\u8BA1\u961F\u5217\u91CC\u4EFB\u52A1\u72B6\u6001 +ACCESS_TOKEN_TAG=access token\u76F8\u5173\u64CD\u4F5C\uFF0C\u9700\u8981\u5148\u767B\u5F55 +MONITOR_TAG=\u76D1\u63A7\u76F8\u5173\u64CD\u4F5C +MASTER_LIST_NOTES=master\u670D\u52A1\u5217\u8868 +WORKER_LIST_NOTES=worker\u670D\u52A1\u5217\u8868 +QUERY_DATABASE_STATE_NOTES=\u67E5\u8BE2\u6570\u636E\u5E93\u72B6\u6001 +QUERY_ZOOKEEPER_STATE_NOTES=\u67E5\u8BE2Zookeeper\u72B6\u6001 +TASK_STATE=\u4EFB\u52A1\u5B9E\u4F8B\u72B6\u6001 +SOURCE_TABLE=\u6E90\u8868 +DEST_TABLE=\u76EE\u6807\u8868 +TASK_DATE=\u4EFB\u52A1\u65F6\u95F4 +QUERY_HISTORY_TASK_RECORD_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u5386\u53F2\u4EFB\u52A1\u8BB0\u5F55\u5217\u8868 +DATA_SOURCE_TAG=\u6570\u636E\u6E90\u76F8\u5173\u64CD\u4F5C +CREATE_DATA_SOURCE_NOTES=\u521B\u5EFA\u6570\u636E\u6E90 +DATA_SOURCE_NAME=\u6570\u636E\u6E90\u540D\u79F0 +DATA_SOURCE_NOTE=\u6570\u636E\u6E90\u63CF\u8FF0 +DB_TYPE=\u6570\u636E\u6E90\u7C7B\u578B +DATA_SOURCE_HOST=IP\u4E3B\u673A\u540D +DATA_SOURCE_PORT=\u6570\u636E\u6E90\u7AEF\u53E3 +DATABASE_NAME=\u6570\u636E\u5E93\u540D +QUEUE_TAG=\u961F\u5217\u76F8\u5173\u64CD\u4F5C +QUERY_QUEUE_LIST_NOTES=\u67E5\u8BE2\u961F\u5217\u5217\u8868 +QUERY_QUEUE_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u961F\u5217\u5217\u8868 +CREATE_QUEUE_NOTES=\u521B\u5EFA\u961F\u5217 +YARN_QUEUE_NAME=hadoop yarn\u961F\u5217\u540D +QUEUE_ID=\u961F\u5217ID +TENANT_DESC=\u79DF\u6237\u63CF\u8FF0 +QUERY_TENANT_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u79DF\u6237\u5217\u8868 +QUERY_TENANT_LIST_NOTES=\u67E5\u8BE2\u79DF\u6237\u5217\u8868 +UPDATE_TENANT_NOTES=\u66F4\u65B0\u79DF\u6237 +DELETE_TENANT_NOTES=\u5220\u9664\u79DF\u6237 +RESOURCES_TAG=\u8D44\u6E90\u4E2D\u5FC3\u76F8\u5173\u64CD\u4F5C +CREATE_RESOURCE_NOTES=\u521B\u5EFA\u8D44\u6E90 +RESOURCE_TYPE=\u8D44\u6E90\u6587\u4EF6\u7C7B\u578B +RESOURCE_NAME=\u8D44\u6E90\u6587\u4EF6\u540D\u79F0 +RESOURCE_DESC=\u8D44\u6E90\u6587\u4EF6\u63CF\u8FF0 +RESOURCE_FILE=\u8D44\u6E90\u6587\u4EF6 +RESOURCE_ID=\u8D44\u6E90ID +QUERY_RESOURCE_LIST_NOTES=\u67E5\u8BE2\u8D44\u6E90\u5217\u8868 +DELETE_RESOURCE_BY_ID_NOTES=\u5220\u9664\u8D44\u6E90\u901A\u8FC7ID +VIEW_RESOURCE_BY_ID_NOTES=\u6D4F\u89C8\u8D44\u6E90\u901A\u901A\u8FC7ID +ONLINE_CREATE_RESOURCE_NOTES=\u5728\u7EBF\u521B\u5EFA\u8D44\u6E90 +SUFFIX=\u8D44\u6E90\u6587\u4EF6\u540E\u7F00 +CONTENT=\u8D44\u6E90\u6587\u4EF6\u5185\u5BB9 +UPDATE_RESOURCE_NOTES=\u5728\u7EBF\u66F4\u65B0\u8D44\u6E90\u6587\u4EF6 +DOWNLOAD_RESOURCE_NOTES=\u4E0B\u8F7D\u8D44\u6E90\u6587\u4EF6 +CREATE_UDF_FUNCTION_NOTES=\u521B\u5EFAUDF\u51FD\u6570 +UDF_TYPE=UDF\u7C7B\u578B +FUNC_NAME=\u51FD\u6570\u540D\u79F0 +CLASS_NAME=\u5305\u540D\u7C7B\u540D +ARG_TYPES=\u53C2\u6570 +UDF_DESC=udf\u63CF\u8FF0\uFF0C\u4F7F\u7528\u8BF4\u660E +VIEW_UDF_FUNCTION_NOTES=\u67E5\u770Budf\u51FD\u6570 +UPDATE_UDF_FUNCTION_NOTES=\u66F4\u65B0udf\u51FD\u6570 +QUERY_UDF_FUNCTION_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2udf\u51FD\u6570\u5217\u8868 +VERIFY_UDF_FUNCTION_NAME_NOTES=\u9A8C\u8BC1udf\u51FD\u6570\u540D +DELETE_UDF_FUNCTION_NOTES=\u5220\u9664UDF\u51FD\u6570 +AUTHORIZED_FILE_NOTES=\u6388\u6743\u6587\u4EF6 +UNAUTHORIZED_FILE_NOTES=\u53D6\u6D88\u6388\u6743\u6587\u4EF6 +AUTHORIZED_UDF_FUNC_NOTES=\u6388\u6743udf\u51FD\u6570 +UNAUTHORIZED_UDF_FUNC_NOTES=\u53D6\u6D88udf\u51FD\u6570\u6388\u6743 +VERIFY_QUEUE_NOTES=\u9A8C\u8BC1\u961F\u5217 +TENANT_TAG=\u79DF\u6237\u76F8\u5173\u64CD\u4F5C +CREATE_TENANT_NOTES=\u521B\u5EFA\u79DF\u6237 +TENANT_CODE=\u79DF\u6237\u7F16\u7801 +TENANT_NAME=\u79DF\u6237\u540D\u79F0 +QUEUE_NAME=\u961F\u5217\u540D +PASSWORD=\u5BC6\u7801 +DATA_SOURCE_OTHER=jdbc\u8FDE\u63A5\u53C2\u6570\uFF0C\u683C\u5F0F\u4E3A:{"key1":"value1",...} +PROJECT_TAG=\u9879\u76EE\u76F8\u5173\u64CD\u4F5C +CREATE_PROJECT_NOTES=\u521B\u5EFA\u9879\u76EE +PROJECT_DESC=\u9879\u76EE\u63CF\u8FF0 +UPDATE_PROJECT_NOTES=\u66F4\u65B0\u9879\u76EE +PROJECT_ID=\u9879\u76EEID +QUERY_PROJECT_BY_ID_NOTES=\u901A\u8FC7\u9879\u76EEID\u67E5\u8BE2\u9879\u76EE\u4FE1\u606F +QUERY_PROJECT_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u9879\u76EE\u5217\u8868 +QUERY_ALL_PROJECT_LIST_NOTES=\u67E5\u8BE2\u6240\u6709\u9879\u76EE +DELETE_PROJECT_BY_ID_NOTES=\u5220\u9664\u9879\u76EE\u901A\u8FC7ID +QUERY_UNAUTHORIZED_PROJECT_NOTES=\u67E5\u8BE2\u672A\u6388\u6743\u7684\u9879\u76EE +QUERY_AUTHORIZED_PROJECT_NOTES=\u67E5\u8BE2\u6388\u6743\u9879\u76EE +TASK_RECORD_TAG=\u4EFB\u52A1\u8BB0\u5F55\u76F8\u5173\u64CD\u4F5C +QUERY_TASK_RECORD_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u4EFB\u52A1\u8BB0\u5F55\u5217\u8868 +CREATE_TOKEN_NOTES=\u521B\u5EFAtoken\uFF0C\u6CE8\u610F\u9700\u8981\u5148\u767B\u5F55 +QUERY_ACCESS_TOKEN_LIST_NOTES=\u5206\u9875\u67E5\u8BE2access token\u5217\u8868 +SCHEDULE=\u5B9A\u65F6 +WARNING_TYPE=\u53D1\u9001\u7B56\u7565 +WARNING_GROUP_ID=\u53D1\u9001\u7EC4ID +FAILURE_STRATEGY=\u5931\u8D25\u7B56\u7565 +RECEIVERS=\u6536\u4EF6\u4EBA +RECEIVERS_CC=\u6536\u4EF6\u4EBA(\u6284\u9001) +WORKER_GROUP_ID=Worker Server\u5206\u7EC4ID +PROCESS_INSTANCE_PRIORITY=\u6D41\u7A0B\u5B9E\u4F8B\u4F18\u5148\u7EA7 +UPDATE_SCHEDULE_NOTES=\u66F4\u65B0\u5B9A\u65F6 +SCHEDULE_ID=\u5B9A\u65F6ID +ONLINE_SCHEDULE_NOTES=\u5B9A\u65F6\u4E0A\u7EBF +OFFLINE_SCHEDULE_NOTES=\u5B9A\u65F6\u4E0B\u7EBF +QUERY_SCHEDULE_NOTES=\u67E5\u8BE2\u5B9A\u65F6 +QUERY_SCHEDULE_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u5B9A\u65F6 +LOGIN_TAG=\u7528\u6237\u767B\u5F55\u76F8\u5173\u64CD\u4F5C +USER_NAME=\u7528\u6237\u540D +PROJECT_NAME=\u9879\u76EE\u540D\u79F0 +CREATE_PROCESS_DEFINITION_NOTES=\u521B\u5EFA\u6D41\u7A0B\u5B9A\u4E49 +PROCESS_DEFINITION_NAME=\u6D41\u7A0B\u5B9A\u4E49\u540D\u79F0 +PROCESS_DEFINITION_JSON=\u6D41\u7A0B\u5B9A\u4E49\u8BE6\u7EC6\u4FE1\u606F(json\u683C\u5F0F) +PROCESS_DEFINITION_LOCATIONS=\u6D41\u7A0B\u5B9A\u4E49\u8282\u70B9\u5750\u6807\u4F4D\u7F6E\u4FE1\u606F(json\u683C\u5F0F) +PROCESS_INSTANCE_LOCATIONS=\u6D41\u7A0B\u5B9E\u4F8B\u8282\u70B9\u5750\u6807\u4F4D\u7F6E\u4FE1\u606F(json\u683C\u5F0F) +PROCESS_DEFINITION_CONNECTS=\u6D41\u7A0B\u5B9A\u4E49\u8282\u70B9\u56FE\u6807\u8FDE\u63A5\u4FE1\u606F(json\u683C\u5F0F) +PROCESS_INSTANCE_CONNECTS=\u6D41\u7A0B\u5B9E\u4F8B\u8282\u70B9\u56FE\u6807\u8FDE\u63A5\u4FE1\u606F(json\u683C\u5F0F) +PROCESS_DEFINITION_DESC=\u6D41\u7A0B\u5B9A\u4E49\u63CF\u8FF0\u4FE1\u606F +PROCESS_DEFINITION_TAG=\u6D41\u7A0B\u5B9A\u4E49\u76F8\u5173\u64CD\u4F5C +SIGNOUT_NOTES=\u9000\u51FA\u767B\u5F55 +USER_PASSWORD=\u7528\u6237\u5BC6\u7801 +UPDATE_PROCESS_INSTANCE_NOTES=\u66F4\u65B0\u6D41\u7A0B\u5B9E\u4F8B +QUERY_PROCESS_INSTANCE_LIST_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9E\u4F8B\u5217\u8868 +VERIFY_PROCESS_DEFINITION_NAME_NOTES=\u9A8C\u8BC1\u6D41\u7A0B\u5B9A\u4E49\u540D\u5B57 +LOGIN_NOTES=\u7528\u6237\u767B\u5F55 +UPDATE_PROCESS_DEFINITION_NOTES=\u66F4\u65B0\u6D41\u7A0B\u5B9A\u4E49 +PROCESS_DEFINITION_ID=\u6D41\u7A0B\u5B9A\u4E49ID +RELEASE_PROCESS_DEFINITION_NOTES=\u53D1\u5E03\u6D41\u7A0B\u5B9A\u4E49 +QUERY_PROCESS_DEFINITION_BY_ID_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9A\u4E49\u901A\u8FC7\u6D41\u7A0B\u5B9A\u4E49ID +QUERY_PROCESS_DEFINITION_LIST_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9A\u4E49\u5217\u8868 +QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u6D41\u7A0B\u5B9A\u4E49\u5217\u8868 +QUERY_ALL_DEFINITION_LIST_NOTES=\u67E5\u8BE2\u6240\u6709\u6D41\u7A0B\u5B9A\u4E49 +PAGE_NO=\u9875\u7801\u53F7 +PROCESS_INSTANCE_ID=\u6D41\u7A0B\u5B9E\u4F8BID +PROCESS_INSTANCE_IDS=\u6D41\u7A0B\u5B9E\u4F8BID\u96C6\u5408 +PROCESS_INSTANCE_JSON=\u6D41\u7A0B\u5B9E\u4F8B\u4FE1\u606F(json\u683C\u5F0F) +SCHEDULE_TIME=\u5B9A\u65F6\u65F6\u95F4 +SYNC_DEFINE=\u66F4\u65B0\u6D41\u7A0B\u5B9E\u4F8B\u7684\u4FE1\u606F\u662F\u5426\u540C\u6B65\u5230\u6D41\u7A0B\u5B9A\u4E49 +RECOVERY_PROCESS_INSTANCE_FLAG=\u662F\u5426\u6062\u590D\u6D41\u7A0B\u5B9E\u4F8B +SEARCH_VAL=\u641C\u7D22\u503C +USER_ID=\u7528\u6237ID +PAGE_SIZE=\u9875\u5927\u5C0F +LIMIT=\u663E\u793A\u591A\u5C11\u6761 +VIEW_TREE_NOTES=\u6811\u72B6\u56FE +GET_NODE_LIST_BY_DEFINITION_ID_NOTES=\u83B7\u5F97\u4EFB\u52A1\u8282\u70B9\u5217\u8868\u901A\u8FC7\u6D41\u7A0B\u5B9A\u4E49ID +PROCESS_DEFINITION_ID_LIST=\u6D41\u7A0B\u5B9A\u4E49id\u5217\u8868 +QUERY_PROCESS_DEFINITION_All_BY_PROJECT_ID_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9A\u4E49\u901A\u8FC7\u9879\u76EEID +BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES=\u6279\u91CF\u5220\u9664\u6D41\u7A0B\u5B9A\u4E49\u901A\u8FC7\u6D41\u7A0B\u5B9A\u4E49ID\u96C6\u5408 +DELETE_PROCESS_DEFINITION_BY_ID_NOTES=\u5220\u9664\u6D41\u7A0B\u5B9A\u4E49\u901A\u8FC7\u6D41\u7A0B\u5B9A\u4E49ID +QUERY_PROCESS_INSTANCE_BY_ID_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9E\u4F8B\u901A\u8FC7\u6D41\u7A0B\u5B9E\u4F8BID +DELETE_PROCESS_INSTANCE_BY_ID_NOTES=\u5220\u9664\u6D41\u7A0B\u5B9E\u4F8B\u901A\u8FC7\u6D41\u7A0B\u5B9E\u4F8BID +TASK_ID=\u4EFB\u52A1\u5B9E\u4F8BID +SKIP_LINE_NUM=\u5FFD\u7565\u884C\u6570 +QUERY_TASK_INSTANCE_LOG_NOTES=\u67E5\u8BE2\u4EFB\u52A1\u5B9E\u4F8B\u65E5\u5FD7 +DOWNLOAD_TASK_INSTANCE_LOG_NOTES=\u4E0B\u8F7D\u4EFB\u52A1\u5B9E\u4F8B\u65E5\u5FD7 +USERS_TAG=\u7528\u6237\u76F8\u5173\u64CD\u4F5C +SCHEDULER_TAG=\u5B9A\u65F6\u76F8\u5173\u64CD\u4F5C +CREATE_SCHEDULE_NOTES=\u521B\u5EFA\u5B9A\u65F6 +CREATE_USER_NOTES=\u521B\u5EFA\u7528\u6237 +TENANT_ID=\u79DF\u6237ID +QUEUE=\u4F7F\u7528\u7684\u961F\u5217 +EMAIL=\u90AE\u7BB1 +PHONE=\u624B\u673A\u53F7 +QUERY_USER_LIST_NOTES=\u67E5\u8BE2\u7528\u6237\u5217\u8868 +UPDATE_USER_NOTES=\u66F4\u65B0\u7528\u6237 +DELETE_USER_BY_ID_NOTES=\u5220\u9664\u7528\u6237\u901A\u8FC7ID +GRANT_PROJECT_NOTES=\u6388\u6743\u9879\u76EE +PROJECT_IDS=\u9879\u76EEIDS(\u5B57\u7B26\u4E32\u683C\u5F0F\uFF0C\u591A\u4E2A\u9879\u76EE\u4EE5","\u5206\u5272) +GRANT_RESOURCE_NOTES=\u6388\u6743\u8D44\u6E90\u6587\u4EF6 +RESOURCE_IDS=\u8D44\u6E90ID\u5217\u8868(\u5B57\u7B26\u4E32\u683C\u5F0F\uFF0C\u591A\u4E2A\u8D44\u6E90ID\u4EE5","\u5206\u5272) +GET_USER_INFO_NOTES=\u83B7\u53D6\u7528\u6237\u4FE1\u606F +LIST_USER_NOTES=\u7528\u6237\u5217\u8868 +VERIFY_USER_NAME_NOTES=\u9A8C\u8BC1\u7528\u6237\u540D +UNAUTHORIZED_USER_NOTES=\u53D6\u6D88\u6388\u6743 +ALERT_GROUP_ID=\u62A5\u8B66\u7EC4ID +AUTHORIZED_USER_NOTES=\u6388\u6743\u7528\u6237 +GRANT_UDF_FUNC_NOTES=\u6388\u6743udf\u51FD\u6570 +UDF_IDS=udf\u51FD\u6570id\u5217\u8868(\u5B57\u7B26\u4E32\u683C\u5F0F\uFF0C\u591A\u4E2Audf\u51FD\u6570ID\u4EE5","\u5206\u5272) +GRANT_DATASOURCE_NOTES=\u6388\u6743\u6570\u636E\u6E90 +DATASOURCE_IDS=\u6570\u636E\u6E90ID\u5217\u8868(\u5B57\u7B26\u4E32\u683C\u5F0F\uFF0C\u591A\u4E2A\u6570\u636E\u6E90ID\u4EE5","\u5206\u5272) +QUERY_SUBPROCESS_INSTANCE_BY_TASK_ID_NOTES=\u67E5\u8BE2\u5B50\u6D41\u7A0B\u5B9E\u4F8B\u901A\u8FC7\u4EFB\u52A1\u5B9E\u4F8BID +QUERY_PARENT_PROCESS_INSTANCE_BY_SUB_PROCESS_INSTANCE_ID_NOTES=\u67E5\u8BE2\u7236\u6D41\u7A0B\u5B9E\u4F8B\u4FE1\u606F\u901A\u8FC7\u5B50\u6D41\u7A0B\u5B9E\u4F8BID +QUERY_PROCESS_INSTANCE_GLOBAL_VARIABLES_AND_LOCAL_VARIABLES_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5B9E\u4F8B\u5168\u5C40\u53D8\u91CF\u548C\u5C40\u90E8\u53D8\u91CF +VIEW_GANTT_NOTES=\u6D4F\u89C8Gantt\u56FE +SUB_PROCESS_INSTANCE_ID=\u5B50\u6D41\u7A0B\u662F\u54A7ID +TASK_NAME=\u4EFB\u52A1\u5B9E\u4F8B\u540D +TASK_INSTANCE_TAG=\u4EFB\u52A1\u5B9E\u4F8B\u76F8\u5173\u64CD\u4F5C +LOGGER_TAG=\u65E5\u5FD7\u76F8\u5173\u64CD\u4F5C +PROCESS_INSTANCE_TAG=\u6D41\u7A0B\u5B9E\u4F8B\u76F8\u5173\u64CD\u4F5C +EXECUTION_STATUS=\u5DE5\u4F5C\u6D41\u548C\u4EFB\u52A1\u8282\u70B9\u7684\u8FD0\u884C\u72B6\u6001 +HOST=\u8FD0\u884C\u4EFB\u52A1\u7684\u4E3B\u673AIP\u5730\u5740 +START_DATE=\u5F00\u59CB\u65F6\u95F4 +END_DATE=\u7ED3\u675F\u65F6\u95F4 +QUERY_TASK_LIST_BY_PROCESS_INSTANCE_ID_NOTES=\u901A\u8FC7\u6D41\u7A0B\u5B9E\u4F8BID\u67E5\u8BE2\u4EFB\u52A1\u5217\u8868 +UPDATE_DATA_SOURCE_NOTES=\u66F4\u65B0\u6570\u636E\u6E90 +DATA_SOURCE_ID=\u6570\u636E\u6E90ID +QUERY_DATA_SOURCE_NOTES=\u67E5\u8BE2\u6570\u636E\u6E90\u901A\u8FC7ID +QUERY_DATA_SOURCE_LIST_BY_TYPE_NOTES=\u67E5\u8BE2\u6570\u636E\u6E90\u5217\u8868\u901A\u8FC7\u6570\u636E\u6E90\u7C7B\u578B +QUERY_DATA_SOURCE_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u6570\u636E\u6E90\u5217\u8868 +CONNECT_DATA_SOURCE_NOTES=\u8FDE\u63A5\u6570\u636E\u6E90 +CONNECT_DATA_SOURCE_TEST_NOTES=\u8FDE\u63A5\u6570\u636E\u6E90\u6D4B\u8BD5 +DELETE_DATA_SOURCE_NOTES=\u5220\u9664\u6570\u636E\u6E90 +VERIFY_DATA_SOURCE_NOTES=\u9A8C\u8BC1\u6570\u636E\u6E90 +UNAUTHORIZED_DATA_SOURCE_NOTES=\u672A\u6388\u6743\u7684\u6570\u636E\u6E90 +AUTHORIZED_DATA_SOURCE_NOTES=\u6388\u6743\u7684\u6570\u636E\u6E90 +DELETE_SCHEDULER_BY_ID_NOTES=\u6839\u636E\u5B9A\u65F6id\u5220\u9664\u5B9A\u65F6\u6570\u636E +QUERY_ALERT_GROUP_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u544A\u8B66\u7EC4\u5217\u8868 +EXPORT_PROCESS_DEFINITION_BY_ID_NOTES=\u901A\u8FC7\u5DE5\u4F5C\u6D41ID\u5BFC\u51FA\u5DE5\u4F5C\u6D41\u5B9A\u4E49 +BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES=\u6279\u91CF\u5BFC\u51FA\u5DE5\u4F5C\u6D41\u5B9A\u4E49 +QUERY_USER_CREATED_PROJECT_NOTES= \u67E5\u8BE2\u7528\u6237\u521B\u5EFA\u7684\u9879\u76EE +COPY_PROCESS_DEFINITION_NOTES= \u590D\u5236\u5DE5\u4F5C\u6D41\u5B9A\u4E49 +MOVE_PROCESS_DEFINITION_NOTES= \u79FB\u52A8\u5DE5\u4F5C\u6D41\u5B9A\u4E49 +TARGET_PROJECT_ID= \u76EE\u6807\u9879\u76EEID +IS_COPY = \u662F\u5426\u590D\u5236 +DELETE_PROCESS_DEFINITION_VERSION_NOTES=\u5220\u9664\u6D41\u7A0B\u5386\u53F2\u7248\u672C +QUERY_PROCESS_DEFINITION_VERSIONS_NOTES=\u67E5\u8BE2\u6D41\u7A0B\u5386\u53F2\u7248\u672C\u4FE1\u606F +SWITCH_PROCESS_DEFINITION_VERSION_NOTES=\u5207\u6362\u6D41\u7A0B\u7248\u672C +VERSION=\u7248\u672C\u53F7 From 0f31152aeedf56e3a16883ded012952dbcacfc6b Mon Sep 17 00:00:00 2001 From: Kirs Date: Wed, 23 Dec 2020 13:45:40 +0800 Subject: [PATCH 36/44] [Feature-#3252][build]plugins need put in plugins dir when install (#4259) Update maven build, put the alert plugins in the ${install_dir}/lib/plugin/alert/${plugin_module_name} directory (assembly build and rpm build). Note: When adding a new plug-in, it must be reflected in provisio/dolphinscheduler.xml. this closes #3252 --- .../dolphinscheduler-alert-dingtalk/pom.xml | 4 ++ .../dolphinscheduler-alert-email/pom.xml | 4 ++ .../dolphinscheduler-alert-http/pom.xml | 4 ++ .../dolphinscheduler-alert-script/pom.xml | 4 ++ .../dolphinscheduler-alert-wechat/pom.xml | 3 + dolphinscheduler-dist/pom.xml | 2 +- .../src/main/provisio/dolphinscheduler.xml | 67 +++++++++++++++++++ pom.xml | 2 + 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml index 7ccd69aa01..1f9c46e5f8 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/pom.xml @@ -75,4 +75,8 @@ + + dolphinscheduler-alert-dingtalk-${project.version} + + \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml index 61b8371be8..fcc1469dde 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/pom.xml @@ -121,4 +121,8 @@ + + dolphinscheduler-alert-email-${project.version} + + \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml index 21440d86ed..ce2e0c0478 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml @@ -69,4 +69,8 @@
+ + dolphinscheduler-alert-http-${project.version} + + \ No newline at end of file diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml index c1ba5aa260..6b3277fe61 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml @@ -72,4 +72,8 @@
+ + dolphinscheduler-alert-script-${project.version} + + \ 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 index 1362e1a651..2e729ba09d 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-wechat/pom.xml @@ -72,4 +72,7 @@ + + dolphinscheduler-alert-wechat-${project.version} + \ No newline at end of file diff --git a/dolphinscheduler-dist/pom.xml b/dolphinscheduler-dist/pom.xml index b193dd85c8..e5f3d54a75 100644 --- a/dolphinscheduler-dist/pom.xml +++ b/dolphinscheduler-dist/pom.xml @@ -25,7 +25,7 @@ 4.0.0 dolphinscheduler-dist - pom + provisio ${project.artifactId} true diff --git a/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml b/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml new file mode 100644 index 0000000000..615965cf9a --- /dev/null +++ b/dolphinscheduler-dist/src/main/provisio/dolphinscheduler.xml @@ -0,0 +1,67 @@ + + + + + + + + DISCLAIMER + install.sh + LICENSE + NOTICE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9c154bd7f2..a2aed2974e 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,8 @@ 1.9.3 2.9.2 2.0.0 + 0.184 + ${dep.airlift.version} From 17d44216a4795d9b5a93a35b1457a2ead1f2b2c8 Mon Sep 17 00:00:00 2001 From: Kirs Date: Mon, 28 Dec 2020 11:25:00 +0800 Subject: [PATCH 37/44] [Feature#4310][Alert-SPI] Plug-ins containing UI components provide display pages (#4311) * [Feature#4310][Alert-SPI] Plug-ins containing UI components provide display pages *Some plugins (such as alert plugin) need to provide UI interfaces to users. *We use from-creat to dynamically generate UI interfaces. Related parameters are mainly provided by pluginParams. *From-create can generate dynamic ui based on this parameter. this closes #4310 * add license head * rename * add ut * add license * add query plugin detail interface * fix error --- .../alert/plugin/AlertPluginManager.java | 3 +- .../api/controller/UiPluginController.java | 93 +++++++++++++++++++ .../dolphinscheduler/api/enums/Status.java | 14 ++- .../api/service/UiPluginService.java | 33 +++++++ .../api/service/impl/UiPluginServiceImpl.java | 74 +++++++++++++++ .../api/service/UiPluginServiceTest.java | 86 +++++++++++++++++ .../common/enums/PluginType.java | 70 ++++++++++++++ .../dao/mapper/PluginDefineMapper.java | 8 ++ .../dao/mapper/PluginDefineMapper.xml | 9 +- pom.xml | 1 + 10 files changed, 385 insertions(+), 6 deletions(-) create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UiPluginService.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UiPluginServiceImpl.java create mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UiPluginServiceTest.java create mode 100644 dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/PluginType.java 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 index d9e1906028..a660087c89 100644 --- 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 @@ -22,6 +22,7 @@ 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.dao.entity.PluginDefine; import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; import org.apache.dolphinscheduler.spi.alert.AlertChannel; @@ -91,7 +92,7 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { String nameEn = alertChannelFactory.getName(); String paramsJson = PluginParamsTransfer.transferParamsToJson(params); - PluginDefine pluginDefine = new PluginDefine(nameEn, "alert", paramsJson); + PluginDefine pluginDefine = new PluginDefine(nameEn, PluginType.ALERT.getDesc(), paramsJson); pluginDao.addOrUpdatePluginDefine(pluginDefine); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.java new file mode 100644 index 0000000000..0d159333ee --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UiPluginController.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.api.controller; + +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PLUGINS_ERROR; + +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.service.UiPluginService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.enums.PluginType; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import springfox.documentation.annotations.ApiIgnore; + +/** + * UiPluginController + * Some plugins (such as alert plugin) need to provide UI interfaces to users. + * We use from-creat to dynamically generate UI interfaces. Related parameters are mainly provided by pluginParams. + * From-create can generate dynamic ui based on this parameter. + */ +@Api(tags = "UI_PLUGINS", position = 1) +@RestController +@RequestMapping("ui-plugins") +public class UiPluginController extends BaseController { + + private static final Logger logger = LoggerFactory.getLogger(UiPluginController.class); + + @Autowired + UiPluginService uiPluginService; + + @ApiOperation(value = "queryUiPluginsByType", notes = "QUERY_UI_PLUGINS_BY_TYPE") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pluginType", value = "pluginType", required = true, dataType = "PluginType"), + }) + @PostMapping(value = "/queryUiPluginsByType") + @ResponseStatus(HttpStatus.CREATED) + @ApiException(QUERY_PLUGINS_ERROR) + public Result queryUiPluginsByType(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam(value = "pluginType") PluginType pluginType) { + + logger.info("query plugins by type , pluginType: {}", pluginType); + Map result = uiPluginService.queryUiPluginsByType(pluginType); + return returnDataList(result); + } + + @ApiOperation(value = "queryUiPluginDetailById", notes = "QUERY_UI_PLUGIN_DETAIL_BY_ID") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "PluginType"), + }) + @PostMapping(value = "/queryUiPluginsByID") + @ResponseStatus(HttpStatus.CREATED) + @ApiException(QUERY_PLUGINS_ERROR) + public Result queryUiPluginDetailById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestParam("pluginId") Integer pluginId) { + + logger.info("query plugin detail by id , pluginId: {}", pluginId); + Map result = uiPluginService.queryUiPluginDetailById(pluginId); + return returnDataList(result); + } +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index a890e5c1ed..ca85d60829 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -180,12 +180,12 @@ public enum Status { MOVE_PROCESS_DEFINITION_ERROR(10150, "move process definition from {0} to {1} error : {2}", "从{0}移动工作流到{1}错误 : {2}"), SWITCH_PROCESS_DEFINITION_VERSION_ERROR(10151, "Switch process definition version error", "切换工作流版本出错"), SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_ERROR(10152 - , "Switch process definition version error: not exists process definition, [process definition id {0}]", "切换工作流版本出错:工作流不存在,[工作流id {0}]"), + , "Switch process definition version error: not exists process definition, [process definition id {0}]", "切换工作流版本出错:工作流不存在,[工作流id {0}]"), SWITCH_PROCESS_DEFINITION_VERSION_NOT_EXIST_PROCESS_DEFINITION_VERSION_ERROR(10153 - , "Switch process definition version error: not exists process definition version, [process definition id {0}] [version number {1}]", "切换工作流版本出错:工作流版本信息不存在,[工作流id {0}] [版本号 {1}]"), + , "Switch process definition version error: not exists process definition version, [process definition id {0}] [version number {1}]", "切换工作流版本出错:工作流版本信息不存在,[工作流id {0}] [版本号 {1}]"), QUERY_PROCESS_DEFINITION_VERSIONS_ERROR(10154, "query process definition versions error", "查询工作流历史版本信息出错"), QUERY_PROCESS_DEFINITION_VERSIONS_PAGE_NO_OR_PAGE_SIZE_LESS_THAN_1_ERROR(10155 - , "query process definition versions error: [page number:{0}] < 1 or [page size:{1}] < 1", "查询工作流历史版本出错:[pageNo:{0}] < 1 或 [pageSize:{1}] < 1"), + , "query process definition versions error: [page number:{0}] < 1 or [page size:{1}] < 1", "查询工作流历史版本出错:[pageNo:{0}] < 1 或 [pageSize:{1}] < 1"), DELETE_PROCESS_DEFINITION_VERSION_ERROR(10156, "delete process definition version error", "删除工作流历史版本出错"), QUERY_USER_CREATED_PROJECT_ERROR(10157, "query user created project error error", "查询用户创建的项目错误"), @@ -278,13 +278,19 @@ public enum Status { QUEUE_COUNT_ERROR(90001, "queue count error", "查询队列数据错误"), KERBEROS_STARTUP_STATE(100001, "get kerberos startup state error", "获取kerberos启动状态错误"), + + //plugin + PLUGIN_NOT_A_UI_COMPONENT(110001, "query plugin error, this plugin has no UI component", "查询插件错误,此插件无UI组件"), + QUERY_PLUGINS_RESULT_IS_NULL(110002, "query plugins result is null", "查询插件为空"), + QUERY_PLUGINS_ERROR(110003, "query plugins error", "查询插件错误"), + QUERY_PLUGIN_DETAIL_RESULT_IS_NULL(110004, "query plugin detail result is null", "查询插件详情结果为空"), ; private final int code; private final String enMsg; private final String zhMsg; - private Status(int code, String enMsg, String zhMsg) { + Status(int code, String enMsg, String zhMsg) { this.code = code; this.enMsg = enMsg; this.zhMsg = zhMsg; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UiPluginService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UiPluginService.java new file mode 100644 index 0000000000..102d927673 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UiPluginService.java @@ -0,0 +1,33 @@ +/* + * 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.api.service; + +import org.apache.dolphinscheduler.common.enums.PluginType; + +import java.util.Map; + +/** + * UiPluginService + */ +public interface UiPluginService { + + Map queryUiPluginsByType(PluginType pluginType); + + Map queryUiPluginDetailById(int id); + +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UiPluginServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UiPluginServiceImpl.java new file mode 100644 index 0000000000..983551d8d2 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UiPluginServiceImpl.java @@ -0,0 +1,74 @@ +/* + * 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.api.service.impl; + +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.service.BaseService; +import org.apache.dolphinscheduler.api.service.UiPluginService; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.enums.PluginType; +import org.apache.dolphinscheduler.common.utils.CollectionUtils; +import org.apache.dolphinscheduler.dao.entity.PluginDefine; +import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * UiPluginServiceImpl + */ +@Service +public class UiPluginServiceImpl extends BaseService implements UiPluginService { + + @Autowired + PluginDefineMapper pluginDefineMapper; + + @Override + public Map queryUiPluginsByType(PluginType pluginType) { + Map result = new HashMap<>(); + if (!pluginType.getHasUi()) { + putMsg(result, Status.PLUGIN_NOT_A_UI_COMPONENT); + return result; + } + List pluginDefines = pluginDefineMapper.queryByPluginType(pluginType.getDesc()); + if (CollectionUtils.isEmpty(pluginDefines)) { + putMsg(result, Status.QUERY_PLUGINS_RESULT_IS_NULL); + return result; + } + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, pluginDefines); + return result; + } + + @Override + public Map queryUiPluginDetailById(int id) { + Map result = new HashMap<>(); + PluginDefine pluginDefine = pluginDefineMapper.queryDetailById(id); + if (null == pluginDefine) { + putMsg(result, Status.QUERY_PLUGIN_DETAIL_RESULT_IS_NULL); + return result; + } + putMsg(result, Status.SUCCESS); + result.put(Constants.DATA_LIST, pluginDefine); + return result; + } +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UiPluginServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UiPluginServiceTest.java new file mode 100644 index 0000000000..95e38b2ab9 --- /dev/null +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UiPluginServiceTest.java @@ -0,0 +1,86 @@ +/* + * 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.api.service; + +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.service.impl.UiPluginServiceImpl; +import org.apache.dolphinscheduler.common.enums.PluginType; +import org.apache.dolphinscheduler.dao.entity.PluginDefine; +import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; + +import java.util.Collections; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * UiPluginServiceTest + */ +@RunWith(MockitoJUnitRunner.class) +public class UiPluginServiceTest { + + @InjectMocks + UiPluginServiceImpl uiPluginService; + + @Mock + PluginDefineMapper pluginDefineMapper; + + private PluginDefine pluginDefine; + + @Before + public void before() { + String pluginParams = "[{\"field\":\"receivers\",\"props\":null,\"type\"}]"; + pluginDefine = new PluginDefine("email-alert", "alert", pluginParams); + } + + @Test + public void testQueryPlugins1() { + Map result = uiPluginService.queryUiPluginsByType(PluginType.REGISTER); + Assert.assertEquals(Status.PLUGIN_NOT_A_UI_COMPONENT, result.get("status")); + } + + @Test + public void testQueryPlugins2() { + Map result = uiPluginService.queryUiPluginsByType(PluginType.ALERT); + Mockito.when(pluginDefineMapper.queryByPluginType(PluginType.ALERT.getDesc())).thenReturn(null); + Assert.assertEquals(Status.QUERY_PLUGINS_RESULT_IS_NULL, result.get("status")); + + Mockito.when(pluginDefineMapper.queryByPluginType(PluginType.ALERT.getDesc())).thenReturn(Collections.singletonList(pluginDefine)); + result = uiPluginService.queryUiPluginsByType(PluginType.ALERT); + Assert.assertEquals(Status.SUCCESS, result.get("status")); + } + + @Test + public void testQueryPluginDetailById() { + Mockito.when(pluginDefineMapper.queryDetailById(1)).thenReturn(null); + Map result = uiPluginService.queryUiPluginDetailById(1); + Assert.assertEquals(Status.QUERY_PLUGIN_DETAIL_RESULT_IS_NULL, result.get("status")); + + Mockito.when(pluginDefineMapper.queryDetailById(1)).thenReturn(pluginDefine); + result = uiPluginService.queryUiPluginDetailById(1); + Assert.assertEquals(Status.SUCCESS, result.get("status")); + } + +} diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/PluginType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/PluginType.java new file mode 100644 index 0000000000..958e4852d8 --- /dev/null +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/PluginType.java @@ -0,0 +1,70 @@ +/* + * 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.common.enums; + +import java.util.HashMap; + +import com.baomidou.mybatisplus.annotation.EnumValue; + +/** + * PluginType + */ +public enum PluginType { + + ALERT(1, "alert", true), + REGISTER(2, "register", false); + + PluginType(int code, String desc, boolean hasUi) { + this.code = code; + this.desc = desc; + this.hasUi = hasUi; + } + + @EnumValue + private final int code; + private final String desc; + private final boolean hasUi; + + public int getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + public boolean getHasUi() { + return hasUi; + } + + + private static HashMap PLUGIN_TYPE_MAP = new HashMap<>(); + + static { + for (PluginType pluginType : PluginType.values()) { + PLUGIN_TYPE_MAP.put(pluginType.getCode(), pluginType); + } + } + + public static PluginType of(int type) { + if (PLUGIN_TYPE_MAP.containsKey(type)) { + return PLUGIN_TYPE_MAP.get(type); + } + throw new IllegalArgumentException("invalid type : " + type); + } +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java index 14e4681c43..e2d08b5222 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java @@ -42,6 +42,14 @@ public interface PluginDefineMapper extends BaseMapper { */ List queryByPluginType(@Param("pluginType") String pluginType); + /** + * query detail by id + * + * @param id id + * @return PluginDefineDetail + */ + PluginDefine queryDetailById(@Param("id") int id); + /** * query by name and type * diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml index f4a6f137d9..49abe7cb2d 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml @@ -25,7 +25,7 @@ @@ -35,4 +35,11 @@ from t_ds_plugin_define where plugin_name = #{pluginName} and plugin_type = #{pluginType} + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index a2aed2974e..d37492efb6 100644 --- a/pom.xml +++ b/pom.xml @@ -801,6 +801,7 @@ **/api/service/TaskInstanceServiceTest.java **/api/service/TenantServiceTest.java **/api/service/UdfFuncServiceTest.java + **/api/service/UiPluginServiceTest.java **/api/service/UserAlertGroupServiceTest.java **/api/service/UsersServiceTest.java **/api/service/WorkerGroupServiceTest.java From 14785f4e390e3f2dcbfa223bd33dbc1907f280d3 Mon Sep 17 00:00:00 2001 From: Kirs Date: Thu, 31 Dec 2020 10:18:53 +0800 Subject: [PATCH 38/44] =?UTF-8?q?[Feature-#3828][server]=20Delete=20recipi?= =?UTF-8?q?ents=20and=20CCs=20in=20the=20process=20defi=E2=80=A6=20(#4303)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Feature-#3828][server] Delete recipients and CCs in the process definition and select the associated alert group instead * The specific alarm instance associated with the alert group * The process definition only associates the alert group, and does not care about the specific alarm instance. this closes #3828 * remove test cc * remove test cc * fix test error * add sql upgrade script delete alert column(show_type、alert_type、re、cc) * code style * update test Note the statement to delete the column, and provide related instructions * delete AlertGroup field(alert_type) * fix ut error * fix ut error * fix ut error * code style * delete api-doc receiverCC * delete UserAlertGroupMapper * delete UserAlertGroup * delete UserAlertGroupApi * alert group add coulmn user_id * alter user_id to create_user_id * userinfo remove alert group info --- .../alert/plugin/EmailAlertPluginTest.java | 3 - .../api/controller/AlertGroupController.java | 91 +-- .../api/controller/ExecutorController.java | 116 ++- .../api/service/AlertGroupService.java | 94 +-- .../api/service/ExecutorService.java | 47 +- .../api/service/ProcessInstanceService.java | 3 +- .../api/service/SchedulerService.java | 7 +- .../api/service/UserAlertGroupService.java | 38 - .../api/service/UsersService.java | 178 ++-- .../impl/ProcessDefinitionServiceImpl.java | 32 +- .../ProcessDefinitionVersionServiceImpl.java | 23 +- .../controller/ExecutorControllerTest.java | 100 +-- .../api/service/AlertGroupServiceTest.java | 129 ++- .../api/service/ExecutorService2Test.java | 126 ++- .../ProcessDefinitionVersionServiceTest.java | 23 +- .../service/UserAlertGroupServiceTest.java | 53 -- .../apache/dolphinscheduler/dao/AlertDao.java | 85 +- .../dolphinscheduler/dao/entity/Alert.java | 85 +- .../dao/entity/AlertGroup.java | 58 +- .../dao/entity/ProcessDefinition.java | 93 +-- .../dao/entity/ProcessDefinitionVersion.java | 88 +- .../dao/entity/UserAlertGroup.java | 142 ---- .../dao/mapper/AlertGroupMapper.java | 8 - .../dao/mapper/UserAlertGroupMapper.java | 45 - .../dao/mapper/AlertGroupMapper.xml | 8 +- .../dao/mapper/ProcessDefinitionMapper.xml | 12 +- .../dao/mapper/UserAlertGroupMapper.xml | 31 - .../dolphinscheduler/dao/AlertDaoTest.java | 7 +- .../dao/mapper/AlertGroupMapperTest.java | 189 ++--- .../dao/mapper/AlertMapperTest.java | 5 - .../mapper/AlertPluginInstanceMapperTest.java | 2 - .../mapper/ProcessDefinitionMapperTest.java | 4 - .../ProcessDefinitionVersionMapperTest.java | 4 - .../dao/mapper/UserAlertGroupMapperTest.java | 196 ----- .../dao/mapper/UserMapperTest.java | 122 +-- .../master/runner/MasterTaskExecThread.java | 77 +- .../server/utils/AlertManager.java | 12 - .../server/registry/DependencyConfig.java | 7 - .../TaskCallbackServiceTestConfig.java | 8 - .../service/process/ProcessService.java | 766 ++++++++++-------- pom.xml | 1 - sql/dolphinscheduler-postgre.sql | 63 +- sql/dolphinscheduler_mysql.sql | 66 +- .../mysql/dolphinscheduler_ddl.sql | 42 +- .../postgresql/dolphinscheduler_ddl.sql | 40 +- 45 files changed, 1189 insertions(+), 2140 deletions(-) delete mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UserAlertGroupService.java delete mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UserAlertGroupServiceTest.java delete mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/UserAlertGroup.java delete mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.java delete mode 100644 dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.xml delete mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapperTest.java diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java index a6bd51c7f6..183a805f39 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java @@ -22,7 +22,6 @@ import org.apache.dolphinscheduler.alert.runner.AlertSender; import org.apache.dolphinscheduler.alert.utils.Constants; import org.apache.dolphinscheduler.alert.utils.PropertyUtils; import org.apache.dolphinscheduler.common.enums.AlertStatus; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.DaoFactory; @@ -70,8 +69,6 @@ public class EmailAlertPluginTest { AlertGroup alertGroup = new AlertGroup(); alertGroup.setDescription("test alert group 1"); alertGroup.setGroupName("testalertg1"); - //TODO AlertType is neet delete from AlertGroup - alertGroup.setGroupType(AlertType.EMAIL); alertDao.getAlertGroupMapper().insert(alertGroup); //add alert diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java index 35bbc2af2f..b3a3ee55e9 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java @@ -14,8 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.controller; +import static org.apache.dolphinscheduler.api.enums.Status.CREATE_ALERT_GROUP_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.DELETE_ALERT_GROUP_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.LIST_PAGING_ALERT_GROUP_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_ALERTGROUP_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_GROUP_ERROR; + +import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.AlertGroupService; import org.apache.dolphinscheduler.api.utils.Result; @@ -23,22 +31,27 @@ import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.dao.entity.User; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import org.apache.dolphinscheduler.api.enums.Status; + +import java.util.HashMap; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import springfox.documentation.annotations.ApiIgnore; - -import java.util.HashMap; -import java.util.Map; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; -import static org.apache.dolphinscheduler.api.enums.Status.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import springfox.documentation.annotations.ApiIgnore; /** * alert group controller @@ -65,9 +78,9 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "createAlertgroup", notes = "CREATE_ALERT_GROUP_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), - @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") + @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), + @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") }) @PostMapping(value = "/create") @ResponseStatus(HttpStatus.CREATED) @@ -77,7 +90,7 @@ public class AlertGroupController extends BaseController { @RequestParam(value = "groupType") AlertType groupType, @RequestParam(value = "description", required = false) String description) { logger.info("loginUser user {}, create alertgroup, groupName: {}, groupType: {}, desc: {}", - loginUser.getUserName(), groupName, groupType, description); + loginUser.getUserName(), groupName, groupType, description); Map result = alertGroupService.createAlertgroup(loginUser, groupName, groupType, description); return returnDataList(result); } @@ -94,7 +107,7 @@ public class AlertGroupController extends BaseController { @ApiException(QUERY_ALL_ALERTGROUP_ERROR) public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { logger.info("login user {}, query all alertGroup", - loginUser.getUserName()); + loginUser.getUserName()); HashMap result = alertGroupService.queryAlertgroup(); return returnDataList(result); } @@ -110,9 +123,9 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "queryAlertGroupListPaging", notes = "QUERY_ALERT_GROUP_LIST_PAGING_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), - @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") + @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"), + @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", dataType = "Int", example = "20") }) @GetMapping(value = "/list-paging") @ResponseStatus(HttpStatus.OK) @@ -122,7 +135,7 @@ public class AlertGroupController extends BaseController { @RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam("pageSize") Integer pageSize) { logger.info("login user {}, list paging, pageNo: {}, searchVal: {}, pageSize: {}", - loginUser.getUserName(), pageNo, searchVal, pageSize); + loginUser.getUserName(), pageNo, searchVal, pageSize); Map result = checkPageParams(pageNo, pageSize); if (result.get(Constants.STATUS) != Status.SUCCESS) { return returnDataListPaging(result); @@ -145,10 +158,10 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "updateAlertgroup", notes = "UPDATE_ALERT_GROUP_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), - @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), - @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") + @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "groupType", value = "GROUP_TYPE", required = true, dataType = "AlertType"), + @ApiImplicitParam(name = "description", value = "DESC", dataType = "String") }) @PostMapping(value = "/update") @ResponseStatus(HttpStatus.OK) @@ -159,7 +172,7 @@ public class AlertGroupController extends BaseController { @RequestParam(value = "groupType") AlertType groupType, @RequestParam(value = "description", required = false) String description) { logger.info("login user {}, updateProcessInstance alertgroup, groupName: {}, groupType: {}, desc: {}", - loginUser.getUserName(), groupName, groupType, description); + loginUser.getUserName(), groupName, groupType, description); Map result = alertGroupService.updateAlertgroup(loginUser, id, groupName, groupType, description); return returnDataList(result); } @@ -173,7 +186,7 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "delAlertgroupById", notes = "DELETE_ALERT_GROUP_BY_ID_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100") }) @PostMapping(value = "/delete") @ResponseStatus(HttpStatus.OK) @@ -195,7 +208,7 @@ public class AlertGroupController extends BaseController { */ @ApiOperation(value = "verifyGroupName", notes = "VERIFY_ALERT_GROUP_NAME_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), + @ApiImplicitParam(name = "groupName", value = "GROUP_NAME", required = true, dataType = "String"), }) @GetMapping(value = "/verify-group-name") @ResponseStatus(HttpStatus.OK) @@ -215,28 +228,4 @@ public class AlertGroupController extends BaseController { } return result; } - - /** - * grant user - * - * @param loginUser login user - * @param userIds user ids in the group - * @param alertgroupId alert group id - * @return grant result code - */ - @ApiOperation(value = "grantUser", notes = "GRANT_ALERT_GROUP_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "ALERT_GROUP_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "userIds", value = "USER_IDS", required = true, dataType = "String") - }) - @PostMapping(value = "/grant-user") - @ResponseStatus(HttpStatus.OK) - @ApiException(ALERT_GROUP_GRANT_USER_ERROR) - public Result grantUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "alertgroupId") int alertgroupId, - @RequestParam(value = "userIds") String userIds) { - logger.info("login user {}, grant user, alertGroupId: {},userIds : {}", loginUser.getUserName(), alertgroupId, userIds); - Map result = alertGroupService.grantUser(loginUser, alertgroupId, userIds); - return returnDataList(result); - } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java index 20f4285ffa..b908b05116 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java @@ -14,30 +14,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.controller; +import static org.apache.dolphinscheduler.api.enums.Status.CHECK_PROCESS_DEFINITION_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.EXECUTE_PROCESS_INSTANCE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.START_PROCESS_INSTANCE_ERROR; import org.apache.dolphinscheduler.api.enums.ExecuteType; import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.service.ExecutorService; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.enums.CommandType; +import org.apache.dolphinscheduler.common.enums.FailureStrategy; +import org.apache.dolphinscheduler.common.enums.Priority; +import org.apache.dolphinscheduler.common.enums.RunMode; +import org.apache.dolphinscheduler.common.enums.TaskDependType; +import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.dao.entity.User; -import io.swagger.annotations.*; -import org.apache.dolphinscheduler.common.enums.*; + +import java.text.ParseException; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import springfox.documentation.annotations.ApiIgnore; -import java.text.ParseException; -import java.util.Map; - -import static org.apache.dolphinscheduler.api.enums.Status.*; - - /** * execute process controller */ @@ -64,8 +82,6 @@ public class ExecutorController extends BaseController { * @param execType execute type * @param warningType warning type * @param warningGroupId warning group id - * @param receivers receivers - * @param receiversCc receivers cc * @param runMode run mode * @param processInstancePriority process instance priority * @param workerGroup worker group @@ -74,20 +90,18 @@ public class ExecutorController extends BaseController { */ @ApiOperation(value = "startProcessInstance", notes = "RUN_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"), - @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"), - @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"), - @ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType = "TaskDependType"), - @ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType = "CommandType"), - @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", required = true, dataType = "WarningType"), - @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "receivers", value = "RECEIVERS", dataType = "String"), - @ApiImplicitParam(name = "receiversCc", value = "RECEIVERS_CC", dataType = "String"), - @ApiImplicitParam(name = "runMode", value = "RUN_MODE", dataType = "RunMode"), - @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority"), - @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String", example = "default"), - @ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int", example = "100"), + @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "scheduleTime", value = "SCHEDULE_TIME", required = true, dataType = "String"), + @ApiImplicitParam(name = "failureStrategy", value = "FAILURE_STRATEGY", required = true, dataType = "FailureStrategy"), + @ApiImplicitParam(name = "startNodeList", value = "START_NODE_LIST", dataType = "String"), + @ApiImplicitParam(name = "taskDependType", value = "TASK_DEPEND_TYPE", dataType = "TaskDependType"), + @ApiImplicitParam(name = "execType", value = "COMMAND_TYPE", dataType = "CommandType"), + @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", required = true, dataType = "WarningType"), + @ApiImplicitParam(name = "warningGroupId", value = "WARNING_GROUP_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "runMode", value = "RUN_MODE", dataType = "RunMode"), + @ApiImplicitParam(name = "processInstancePriority", value = "PROCESS_INSTANCE_PRIORITY", required = true, dataType = "Priority"), + @ApiImplicitParam(name = "workerGroup", value = "WORKER_GROUP", dataType = "String", example = "default"), + @ApiImplicitParam(name = "timeout", value = "TIMEOUT", dataType = "Int", example = "100"), }) @PostMapping(value = "start-process-instance") @ResponseStatus(HttpStatus.OK) @@ -102,26 +116,24 @@ public class ExecutorController extends BaseController { @RequestParam(value = "execType", required = false) CommandType execType, @RequestParam(value = "warningType", required = true) WarningType warningType, @RequestParam(value = "warningGroupId", required = false) int warningGroupId, - @RequestParam(value = "receivers", required = false) String receivers, - @RequestParam(value = "receiversCc", required = false) String receiversCc, @RequestParam(value = "runMode", required = false) RunMode runMode, @RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority, @RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup, @RequestParam(value = "timeout", required = false) Integer timeout) throws ParseException { logger.info("login user {}, start process instance, project name: {}, process definition id: {}, schedule time: {}, " - + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " - + "notify group id: {},receivers:{},receiversCc:{}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}", - loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, - failureStrategy, startNodeList, taskDependType, warningType, workerGroup, receivers, receiversCc, runMode, processInstancePriority, - workerGroup, timeout); + + "failure policy: {}, node name: {}, node dep: {}, notify type: {}, " + + "notify group id: {}, run mode: {},process instance priority:{}, workerGroup: {}, timeout: {}", + loginUser.getUserName(), projectName, processDefinitionId, scheduleTime, + failureStrategy, startNodeList, taskDependType, warningType, workerGroup, runMode, processInstancePriority, + workerGroup, timeout); if (timeout == null) { timeout = Constants.MAX_TASK_TIMEOUT; } Map result = execService.execProcessInstance(loginUser, projectName, processDefinitionId, scheduleTime, execType, failureStrategy, - startNodeList, taskDependType, warningType, - warningGroupId, receivers, receiversCc, runMode, processInstancePriority, workerGroup, timeout); + startNodeList, taskDependType, warningType, + warningGroupId, runMode, processInstancePriority, workerGroup, timeout); return returnDataList(result); } @@ -137,8 +149,8 @@ public class ExecutorController extends BaseController { */ @ApiOperation(value = "execute", notes = "EXECUTE_ACTION_TO_PROCESS_INSTANCE_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType") + @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100"), + @ApiImplicitParam(name = "executeType", value = "EXECUTE_TYPE", required = true, dataType = "ExecuteType") }) @PostMapping(value = "/execute") @ResponseStatus(HttpStatus.OK) @@ -149,7 +161,7 @@ public class ExecutorController extends BaseController { @RequestParam("executeType") ExecuteType executeType ) { logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}", - loginUser.getUserName(), projectName, processInstanceId, executeType); + loginUser.getUserName(), projectName, processInstanceId, executeType); Map result = execService.execute(loginUser, projectName, processInstanceId, executeType); return returnDataList(result); } @@ -163,7 +175,7 @@ public class ExecutorController extends BaseController { */ @ApiOperation(value = "startCheckProcessDefinition", notes = "START_CHECK_PROCESS_DEFINITION_NOTES") @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") + @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100") }) @PostMapping(value = "/start-check") @ResponseStatus(HttpStatus.OK) @@ -174,32 +186,4 @@ public class ExecutorController extends BaseController { Map result = execService.startCheckByProcessDefinedId(processDefinitionId); return returnDataList(result); } - - /** - * query recipients and copyers by process definition ID - * - * @param loginUser login user - * @param processDefinitionId process definition id - * @param processInstanceId process instance id - * @return receivers cc list - */ - @ApiIgnore - @ApiOperation(value = "getReceiverCc", notes = "GET_RECEIVER_CC_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), - @ApiImplicitParam(name = "processInstanceId", value = "PROCESS_INSTANCE_ID", required = true, dataType = "Int", example = "100") - - }) - @GetMapping(value = "/get-receiver-cc") - @ResponseStatus(HttpStatus.OK) - @ApiException(QUERY_RECIPIENTS_AND_COPYERS_BY_PROCESS_DEFINITION_ERROR) - public Result getReceiverCc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "processDefinitionId", required = false) Integer processDefinitionId, - @RequestParam(value = "processInstanceId", required = false) Integer processInstanceId) { - logger.info("login user {}, get process definition receiver and cc", loginUser.getUserName()); - Map result = execService.getReceiverCc(processDefinitionId, processInstanceId); - return returnDataList(result); - } - - } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java index 72cbd50833..d4602d3a40 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.service; -import java.util.*; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.common.Constants; @@ -25,29 +25,33 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.entity.UserAlertGroup; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + /** * alert group service */ @Service -public class AlertGroupService extends BaseService{ +public class AlertGroupService extends BaseService { private static final Logger logger = LoggerFactory.getLogger(AlertGroupService.class); @Autowired private AlertGroupMapper alertGroupMapper; - @Autowired - private UserAlertGroupService userAlertGroupService; /** * query alert group list * @@ -68,8 +72,8 @@ public class AlertGroupService extends BaseService{ * * @param loginUser login user * @param searchVal search value - * @param pageNo page number - * @param pageSize page size + * @param pageNo page number + * @param pageSize page size * @return alert group list page */ public Map listPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { @@ -81,9 +85,9 @@ public class AlertGroupService extends BaseService{ Page page = new Page(pageNo, pageSize); IPage alertGroupIPage = alertGroupMapper.queryAlertGroupPage( - page, searchVal); + page, searchVal); PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - pageInfo.setTotalCount((int)alertGroupIPage.getTotal()); + pageInfo.setTotalCount((int) alertGroupIPage.getTotal()); pageInfo.setLists(alertGroupIPage.getRecords()); result.put(Constants.DATA_LIST, pageInfo); putMsg(result, Status.SUCCESS); @@ -97,13 +101,13 @@ public class AlertGroupService extends BaseService{ * @param loginUser login user * @param groupName group name * @param groupType group type - * @param desc description + * @param desc description * @return create result code */ public Map createAlertgroup(User loginUser, String groupName, AlertType groupType, String desc) { Map result = new HashMap<>(); //only admin can operate - if (checkAdmin(loginUser, result)){ + if (checkAdmin(loginUser, result)) { return result; } @@ -111,10 +115,10 @@ public class AlertGroupService extends BaseService{ Date now = new Date(); alertGroup.setGroupName(groupName); - alertGroup.setGroupType(groupType); alertGroup.setDescription(desc); alertGroup.setCreateTime(now); alertGroup.setUpdateTime(now); + alertGroup.setCreateUserId(loginUser.getId()); // insert int insert = alertGroupMapper.insert(alertGroup); @@ -131,20 +135,19 @@ public class AlertGroupService extends BaseService{ * updateProcessInstance alert group * * @param loginUser login user - * @param id alert group id + * @param id alert group id * @param groupName group name * @param groupType group type - * @param desc description + * @param desc description * @return update result code */ public Map updateAlertgroup(User loginUser, int id, String groupName, AlertType groupType, String desc) { Map result = new HashMap<>(); - if (checkAdmin(loginUser, result)){ + if (checkAdmin(loginUser, result)) { return result; } - AlertGroup alertGroup = alertGroupMapper.selectById(id); if (alertGroup == null) { @@ -158,12 +161,9 @@ public class AlertGroupService extends BaseService{ if (StringUtils.isNotEmpty(groupName)) { alertGroup.setGroupName(groupName); } - - if (groupType != null) { - alertGroup.setGroupType(groupType); - } alertGroup.setDescription(desc); alertGroup.setUpdateTime(now); + alertGroup.setCreateUserId(loginUser.getId()); // updateProcessInstance alertGroupMapper.updateById(alertGroup); putMsg(result, Status.SUCCESS); @@ -174,7 +174,7 @@ public class AlertGroupService extends BaseService{ * delete alert group by id * * @param loginUser login user - * @param id alert group id + * @param id alert group id * @return delete result code */ @Transactional(rollbackFor = RuntimeException.class) @@ -183,7 +183,7 @@ public class AlertGroupService extends BaseService{ result.put(Constants.STATUS, false); //only admin can operate - if (checkAdmin(loginUser, result)){ + if (checkAdmin(loginUser, result)) { return result; } //check exist @@ -192,57 +192,11 @@ public class AlertGroupService extends BaseService{ putMsg(result, Status.ALERT_GROUP_NOT_EXIST); return result; } - - userAlertGroupService.deleteByAlertGroupId(id); alertGroupMapper.deleteById(id); putMsg(result, Status.SUCCESS); return result; } - - /** - * grant user - * - * @param loginUser login user - * @param alertgroupId alert group id - * @param userIds user id list - * @return grant result code - */ - public Map grantUser(User loginUser, int alertgroupId, String userIds) { - Map result = new HashMap<>(); - result.put(Constants.STATUS, false); - - //only admin can operate - if (checkAdmin(loginUser, result)){ - return result; - } - - userAlertGroupService.deleteByAlertGroupId(alertgroupId); - if (StringUtils.isEmpty(userIds)) { - putMsg(result, Status.SUCCESS); - return result; - } - - String[] userIdsArr = userIds.split(","); - Date now = new Date(); - List alertGroups = new ArrayList<>(userIds.length()); - for (String userId : userIdsArr) { - UserAlertGroup userAlertGroup = new UserAlertGroup(); - userAlertGroup.setAlertgroupId(alertgroupId); - userAlertGroup.setUserId(Integer.parseInt(userId)); - userAlertGroup.setCreateTime(now); - userAlertGroup.setUpdateTime(now); - alertGroups.add(userAlertGroup); - } - - if (CollectionUtils.isNotEmpty(alertGroups)) { - userAlertGroupService.saveBatch(alertGroups); - } - - putMsg(result, Status.SUCCESS); - return result; - } - /** * verify group name exists * diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java index fb735ecf19..e5e1513460 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java @@ -83,8 +83,6 @@ public class ExecutorService extends BaseService{ * @param taskDependType node dependency type * @param warningType warning type * @param warningGroupId notify group id - * @param receivers receivers - * @param receiversCc receivers cc * @param processInstancePriority process instance priority * @param workerGroup worker group name * @param runMode run mode @@ -96,7 +94,7 @@ public class ExecutorService extends BaseService{ int processDefinitionId, String cronTime, CommandType commandType, FailureStrategy failureStrategy, String startNodeList, TaskDependType taskDependType, WarningType warningType, int warningGroupId, - String receivers, String receiversCc, RunMode runMode, + RunMode runMode, Priority processInstancePriority, String workerGroup, Integer timeout) throws ParseException { Map result = new HashMap<>(); // timeout is invalid @@ -137,11 +135,7 @@ public class ExecutorService extends BaseService{ taskDependType, failureStrategy, startNodeList, cronTime, warningType, loginUser.getId(), warningGroupId, runMode,processInstancePriority, workerGroup); if(create > 0 ){ - /** - * according to the process definition ID updateProcessInstance and CC recipient - */ - processDefinition.setReceivers(receivers); - processDefinition.setReceiversCc(receiversCc); + processDefinition.setWarningGroupId(warningGroupId); processDefinitionMapper.updateById(processDefinition); putMsg(result, Status.SUCCESS); } else { @@ -424,43 +418,6 @@ public class ExecutorService extends BaseService{ return result; } - /** - * query recipients and copyers by process definition id or processInstanceId - * - * @param processDefineId process definition id - * @param processInstanceId process instance id - * @return receivers cc list - */ - public Map getReceiverCc(Integer processDefineId,Integer processInstanceId) { - Map result = new HashMap<>(); - logger.info("processInstanceId {}",processInstanceId); - if(processDefineId == null && processInstanceId == null){ - throw new RuntimeException("You must set values for parameters processDefineId or processInstanceId"); - } - if(processDefineId == null && processInstanceId != null) { - ProcessInstance processInstance = processInstanceMapper.selectById(processInstanceId); - if (processInstance == null) { - throw new RuntimeException("processInstanceId is not exists"); - } - processDefineId = processInstance.getProcessDefinitionId(); - } - ProcessDefinition processDefinition = processDefinitionMapper.selectById(processDefineId); - if (processDefinition == null){ - throw new RuntimeException(String.format("processDefineId %d is not exists",processDefineId)); - } - - String receivers = processDefinition.getReceivers(); - String receiversCc = processDefinition.getReceiversCc(); - Map dataMap = new HashMap<>(); - dataMap.put(Constants.RECEIVERS,receivers); - dataMap.put(Constants.RECEIVERS_CC,receiversCc); - - result.put(Constants.DATA_LIST, dataMap); - putMsg(result, Status.SUCCESS); - return result; - } - - /** * create command * @param commandType commandType diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java index c8d3c74da0..24fa87170c 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java @@ -187,8 +187,7 @@ public class ProcessInstanceService extends BaseService { ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId); ProcessDefinition processDefinition = processService.findProcessDefineById(processInstance.getProcessDefinitionId()); - processInstance.setReceivers(processDefinition.getReceivers()); - processInstance.setReceiversCc(processDefinition.getReceiversCc()); + processInstance.setWarningGroupId(processDefinition.getWarningGroupId()); result.put(DATA_LIST, processInstance); putMsg(result, Status.SUCCESS); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java index 93fa14872a..09ad58c2d2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java @@ -161,8 +161,7 @@ public class SchedulerService extends BaseService { /** * updateProcessInstance receivers and cc by process definition id */ - processDefinition.setReceivers(receivers); - processDefinition.setReceiversCc(receiversCc); + processDefinition.setWarningGroupId(warningGroupId); processDefinitionMapper.updateById(processDefinition); // return scheduler object with ID @@ -275,8 +274,8 @@ public class SchedulerService extends BaseService { /** * updateProcessInstance recipients and cc by process definition ID */ - processDefinition.setReceivers(receivers); - processDefinition.setReceiversCc(receiversCc); + processDefinition.setWarningGroupId(warningGroupId); + processDefinitionMapper.updateById(processDefinition); putMsg(result, Status.SUCCESS); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UserAlertGroupService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UserAlertGroupService.java deleted file mode 100644 index 502185709f..0000000000 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UserAlertGroupService.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.api.service; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.apache.dolphinscheduler.dao.entity.UserAlertGroup; -import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * - */ -@Service -public class UserAlertGroupService extends ServiceImpl { - - @Autowired - private UserAlertGroupMapper userAlertGroupMapper; - - boolean deleteByAlertGroupId(Integer groupId) { - return userAlertGroupMapper.deleteByAlertgroupId(groupId) >= 1; - } - -} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java index 89038ad09f..92137be589 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java @@ -14,10 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent; import org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor; import org.apache.dolphinscheduler.api.enums.Status; @@ -33,6 +35,7 @@ import org.apache.dolphinscheduler.common.utils.*; import org.apache.dolphinscheduler.dao.entity.*; import org.apache.dolphinscheduler.dao.mapper.*; import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -83,13 +86,13 @@ public class UsersService extends BaseService { /** * create user, only system admin have permission * - * @param loginUser login user - * @param userName user name + * @param loginUser login user + * @param userName user name * @param userPassword user password - * @param email email - * @param tenantId tenant id - * @param phone phone - * @param queue queue + * @param email email + * @param tenantId tenant id + * @param phone phone + * @param queue queue * @return create result code * @throws Exception exception */ @@ -109,7 +112,7 @@ public class UsersService extends BaseService { String msg = this.checkUserParams(userName, userPassword, email, phone); if (!StringUtils.isEmpty(msg)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,msg); + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg); return result; } if (!isAdmin(loginUser)) { @@ -126,12 +129,12 @@ public class UsersService extends BaseService { Tenant tenant = tenantMapper.queryById(tenantId); // resource upload startup - if (PropertyUtils.getResUploadStartupState()){ + if (PropertyUtils.getResUploadStartupState()) { // if tenant not exists - if (!HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(tenant.getTenantCode()))){ + if (!HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(tenant.getTenantCode()))) { createTenantDirIfNotExists(tenant.getTenantCode()); } - String userPath = HadoopUtils.getHdfsUserDir(tenant.getTenantCode(),user.getId()); + String userPath = HadoopUtils.getHdfsUserDir(tenant.getTenantCode(), user.getId()); HadoopUtils.getInstance().mkdir(userPath); } @@ -142,12 +145,12 @@ public class UsersService extends BaseService { @Transactional(rollbackFor = RuntimeException.class) public User createUser(String userName, - String userPassword, - String email, - int tenantId, - String phone, - String queue, - int state) { + String userPassword, + String email, + int tenantId, + String phone, + String queue, + int state) { User user = new User(); Date now = new Date(); @@ -161,7 +164,7 @@ public class UsersService extends BaseService { user.setUserType(UserType.GENERAL_USER); user.setCreateTime(now); user.setUpdateTime(now); - if (StringUtils.isEmpty(queue)){ + if (StringUtils.isEmpty(queue)) { queue = ""; } user.setQueue(queue); @@ -173,6 +176,7 @@ public class UsersService extends BaseService { /** * query user by id + * * @param id id * @return user info */ @@ -182,6 +186,7 @@ public class UsersService extends BaseService { /** * query user + * * @param name name * @return user info */ @@ -192,7 +197,7 @@ public class UsersService extends BaseService { /** * query user * - * @param name name + * @param name name * @param password password * @return user info */ @@ -203,6 +208,7 @@ public class UsersService extends BaseService { /** * get user id by user name + * * @param name user name * @return if name empty 0, user not exists -1, user exist user id */ @@ -225,9 +231,9 @@ public class UsersService extends BaseService { * query user list * * @param loginUser login user - * @param pageNo page number + * @param pageNo page number * @param searchVal search avlue - * @param pageSize page size + * @param pageSize page size * @return user list page */ public Map queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { @@ -242,7 +248,7 @@ public class UsersService extends BaseService { IPage scheduleList = userMapper.queryUserPaging(page, searchVal); PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - pageInfo.setTotalCount((int)scheduleList.getTotal()); + pageInfo.setTotalCount((int) scheduleList.getTotal()); pageInfo.setLists(scheduleList.getRecords()); result.put(Constants.DATA_LIST, pageInfo); putMsg(result, Status.SUCCESS); @@ -253,13 +259,13 @@ public class UsersService extends BaseService { /** * updateProcessInstance user * - * @param userId user id - * @param userName user name + * @param userId user id + * @param userName user name * @param userPassword user password - * @param email email - * @param tenantId tennat id - * @param phone phone - * @param queue queue + * @param email email + * @param tenantId tennat id + * @param phone phone + * @param queue queue * @return update result code * @throws Exception exception */ @@ -283,8 +289,8 @@ public class UsersService extends BaseService { if (StringUtils.isNotEmpty(userName)) { - if (!CheckUtils.checkUserName(userName)){ - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,userName); + if (!CheckUtils.checkUserName(userName)) { + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName); return result; } @@ -297,23 +303,23 @@ public class UsersService extends BaseService { } if (StringUtils.isNotEmpty(userPassword)) { - if (!CheckUtils.checkPassword(userPassword)){ - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,userPassword); + if (!CheckUtils.checkPassword(userPassword)) { + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userPassword); return result; } user.setUserPassword(EncryptionUtils.getMd5(userPassword)); } if (StringUtils.isNotEmpty(email)) { - if (!CheckUtils.checkEmail(email)){ - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,email); + if (!CheckUtils.checkEmail(email)) { + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, email); return result; } user.setEmail(email); } if (StringUtils.isNotEmpty(phone) && !CheckUtils.checkPhone(phone)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,phone); + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, phone); return result; } user.setPhone(phone); @@ -329,19 +335,19 @@ public class UsersService extends BaseService { Tenant newTenant = tenantMapper.queryById(tenantId); if (newTenant != null) { // if hdfs startup - if (PropertyUtils.getResUploadStartupState() && oldTenant != null){ + if (PropertyUtils.getResUploadStartupState() && oldTenant != null) { String newTenantCode = newTenant.getTenantCode(); String oldResourcePath = HadoopUtils.getHdfsResDir(oldTenant.getTenantCode()); String oldUdfsPath = HadoopUtils.getHdfsUdfDir(oldTenant.getTenantCode()); // if old tenant dir exists - if (HadoopUtils.getInstance().exists(oldResourcePath)){ + if (HadoopUtils.getInstance().exists(oldResourcePath)) { String newResourcePath = HadoopUtils.getHdfsResDir(newTenantCode); String newUdfsPath = HadoopUtils.getHdfsUdfDir(newTenantCode); //file resources list List fileResourcesList = resourceMapper.queryResourceList( - null, userId, ResourceType.FILE.ordinal()); + null, userId, ResourceType.FILE.ordinal()); if (CollectionUtils.isNotEmpty(fileResourcesList)) { ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(fileResourcesList); ResourceComponent resourceComponent = resourceTreeVisitor.visit(); @@ -350,7 +356,7 @@ public class UsersService extends BaseService { //udf resources List udfResourceList = resourceMapper.queryResourceList( - null, userId, ResourceType.UDF.ordinal()); + null, userId, ResourceType.UDF.ordinal()); if (CollectionUtils.isNotEmpty(udfResourceList)) { ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(udfResourceList); ResourceComponent resourceComponent = resourceTreeVisitor.visit(); @@ -358,18 +364,18 @@ public class UsersService extends BaseService { } //Delete the user from the old tenant directory - String oldUserPath = HadoopUtils.getHdfsUserDir(oldTenant.getTenantCode(),userId); + String oldUserPath = HadoopUtils.getHdfsUserDir(oldTenant.getTenantCode(), userId); HadoopUtils.getInstance().delete(oldUserPath, true); - }else { + } else { // if old tenant dir not exists , create createTenantDirIfNotExists(oldTenant.getTenantCode()); } - if (HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(newTenant.getTenantCode()))){ + if (HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(newTenant.getTenantCode()))) { //create user in the new tenant directory - String newUserPath = HadoopUtils.getHdfsUserDir(newTenant.getTenantCode(),user.getId()); + String newUserPath = HadoopUtils.getHdfsUserDir(newTenant.getTenantCode(), user.getId()); HadoopUtils.getInstance().mkdir(newUserPath); - }else { + } else { // if new tenant dir not exists , create createTenantDirIfNotExists(newTenant.getTenantCode()); } @@ -389,7 +395,7 @@ public class UsersService extends BaseService { * delete user * * @param loginUser login user - * @param id user id + * @param id user id * @return delete result code * @throws Exception exception when operate hdfs */ @@ -411,7 +417,7 @@ public class UsersService extends BaseService { if (user != null) { if (PropertyUtils.getResUploadStartupState()) { - String userPath = HadoopUtils.getHdfsUserDir(user.getTenantCode(),id); + String userPath = HadoopUtils.getHdfsUserDir(user.getTenantCode(), id); if (HadoopUtils.getInstance().exists(userPath)) { HadoopUtils.getInstance().delete(userPath, true); } @@ -427,8 +433,8 @@ public class UsersService extends BaseService { /** * grant project * - * @param loginUser login user - * @param userId user id + * @param loginUser login user + * @param userId user id * @param projectIds project id array * @return grant result code */ @@ -477,8 +483,8 @@ public class UsersService extends BaseService { /** * grant resource * - * @param loginUser login user - * @param userId user id + * @param loginUser login user + * @param userId user id * @param resourceIds resource id array * @return grant result code */ @@ -490,7 +496,7 @@ public class UsersService extends BaseService { return result; } User user = userMapper.selectById(userId); - if(user == null){ + if (user == null) { putMsg(result, Status.USER_NOT_EXIST, userId); return result; } @@ -501,7 +507,7 @@ public class UsersService extends BaseService { // need authorize resource id set for (String resourceFullId : resourceFullIdArr) { String[] resourceIdArr = resourceFullId.split("-"); - for (int i=0;i<=resourceIdArr.length-1;i++) { + for (int i = 0; i <= resourceIdArr.length - 1; i++) { int resourceIdValue = Integer.parseInt(resourceIdArr[i]); needAuthorizeResIds.add(resourceIdValue); } @@ -528,7 +534,7 @@ public class UsersService extends BaseService { if (CollectionUtils.isNotEmpty(resourceIdSet)) { logger.error("can't be deleted,because it is used of process definition"); for (Integer resId : resourceIdSet) { - logger.error("resource id:{} is used of process definition {}",resId,resourceProcessMap.get(resId)); + logger.error("resource id:{} is used of process definition {}", resId, resourceProcessMap.get(resId)); } putMsg(result, Status.RESOURCE_IS_USED); return result; @@ -555,7 +561,7 @@ public class UsersService extends BaseService { resourcesUser.setResourcesId(resourceIdValue); if (resource.isDirectory()) { resourcesUser.setPerm(Constants.AUTHORIZE_READABLE_PERM); - }else{ + } else { resourcesUser.setPerm(Constants.AUTHORIZE_WRITABLE_PERM); } @@ -575,8 +581,8 @@ public class UsersService extends BaseService { * grant udf function * * @param loginUser login user - * @param userId user id - * @param udfIds udf id array + * @param userId user id + * @param udfIds udf id array * @return grant result code */ @Transactional(rollbackFor = RuntimeException.class) @@ -588,7 +594,7 @@ public class UsersService extends BaseService { return result; } User user = userMapper.selectById(userId); - if(user == null){ + if (user == null) { putMsg(result, Status.USER_NOT_EXIST, userId); return result; } @@ -621,9 +627,9 @@ public class UsersService extends BaseService { /** * grant datasource * - * @param loginUser login user - * @param userId user id - * @param datasourceIds data source id array + * @param loginUser login user + * @param userId user id + * @param datasourceIds data source id array * @return grant result code */ @Transactional(rollbackFor = RuntimeException.class) @@ -636,7 +642,7 @@ public class UsersService extends BaseService { return result; } User user = userMapper.selectById(userId); - if(user == null){ + if (user == null) { putMsg(result, Status.USER_NOT_EXIST, userId); return result; } @@ -676,23 +682,11 @@ public class UsersService extends BaseService { Map result = new HashMap<>(); - User user = null; + User user; if (loginUser.getUserType() == UserType.ADMIN_USER) { user = loginUser; } else { user = userMapper.queryDetailsById(loginUser.getId()); - - List alertGroups = alertGroupMapper.queryByUserId(loginUser.getId()); - - StringBuilder sb = new StringBuilder(); - - if (alertGroups != null && alertGroups.size() > 0) { - for (int i = 0; i < alertGroups.size() - 1; i++) { - sb.append(alertGroups.get(i).getGroupName() + ","); - } - sb.append(alertGroups.get(alertGroups.size() - 1)); - user.setAlertGroup(sb.toString()); - } } result.put(Constants.DATA_LIST, user); @@ -735,7 +729,7 @@ public class UsersService extends BaseService { return result; } - List userList = userMapper.selectList(null ); + List userList = userMapper.selectList(null); result.put(Constants.DATA_LIST, userList); putMsg(result, Status.SUCCESS); @@ -767,7 +761,7 @@ public class UsersService extends BaseService { /** * unauthorized user * - * @param loginUser login user + * @param loginUser login user * @param alertgroupId alert group id * @return unauthorize result code */ @@ -779,7 +773,7 @@ public class UsersService extends BaseService { return result; } - List userList = userMapper.selectList(null ); + List userList = userMapper.selectList(null); List resultUsers = new ArrayList<>(); Set userSet = null; if (userList != null && userList.size() > 0) { @@ -804,7 +798,7 @@ public class UsersService extends BaseService { /** * authorized user * - * @param loginUser login user + * @param loginUser login user * @param alertgroupId alert group id * @return authorized result code */ @@ -824,8 +818,8 @@ public class UsersService extends BaseService { /** * check * - * @param result result - * @param bool bool + * @param result result + * @param bool bool * @param userNoOperationPerm status * @return check result */ @@ -848,7 +842,6 @@ public class UsersService extends BaseService { } /** - * * @param userName * @param password * @param email @@ -877,35 +870,36 @@ public class UsersService extends BaseService { /** * copy resource files + * * @param resourceComponent resource component * @param srcBasePath src base path * @param dstBasePath dst base path - * @throws IOException io exception + * @throws IOException io exception */ private void copyResourceFiles(ResourceComponent resourceComponent, String srcBasePath, String dstBasePath) throws IOException { List components = resourceComponent.getChildren(); if (CollectionUtils.isNotEmpty(components)) { - for (ResourceComponent component:components) { + for (ResourceComponent component : components) { // verify whether exist - if (!HadoopUtils.getInstance().exists(String.format("%s/%s",srcBasePath,component.getFullName()))){ - logger.error("resource file: {} not exist,copy error",component.getFullName()); + if (!HadoopUtils.getInstance().exists(String.format("%s/%s", srcBasePath, component.getFullName()))) { + logger.error("resource file: {} not exist,copy error", component.getFullName()); throw new ServiceException(Status.RESOURCE_NOT_EXIST); } if (!component.isDirctory()) { // copy it to dst - HadoopUtils.getInstance().copy(String.format("%s/%s",srcBasePath,component.getFullName()),String.format("%s/%s",dstBasePath,component.getFullName()),false,true); + HadoopUtils.getInstance().copy(String.format("%s/%s", srcBasePath, component.getFullName()), String.format("%s/%s", dstBasePath, component.getFullName()), false, true); continue; } - if(CollectionUtils.isEmpty(component.getChildren())) { + if (CollectionUtils.isEmpty(component.getChildren())) { // if not exist,need create it - if (!HadoopUtils.getInstance().exists(String.format("%s/%s",dstBasePath,component.getFullName()))) { - HadoopUtils.getInstance().mkdir(String.format("%s/%s",dstBasePath,component.getFullName())); + if (!HadoopUtils.getInstance().exists(String.format("%s/%s", dstBasePath, component.getFullName()))) { + HadoopUtils.getInstance().mkdir(String.format("%s/%s", dstBasePath, component.getFullName())); } - }else{ - copyResourceFiles(component,srcBasePath,dstBasePath); + } else { + copyResourceFiles(component, srcBasePath, dstBasePath); } } } @@ -929,7 +923,7 @@ public class UsersService extends BaseService { String msg = this.checkUserParams(userName, userPassword, email, ""); if (!StringUtils.isEmpty(msg)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR,msg); + putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg); return result; } @@ -959,7 +953,7 @@ public class UsersService extends BaseService { return result; } - if (!CheckUtils.checkUserName(userName)){ + if (!CheckUtils.checkUserName(userName)) { putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName); return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index 7b68003440..9046f51881 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -158,7 +158,6 @@ public class ProcessDefinitionServiceImpl extends BaseService implements * @param locations locations for nodes * @param connects connects for nodes * @return create result code - * @throws JsonProcessingException JsonProcessingException */ public Map createProcessDefinition(User loginUser, String projectName, @@ -166,7 +165,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements String processDefinitionJson, String desc, String locations, - String connects) throws JsonProcessingException { + String connects) { Map result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); @@ -836,19 +835,14 @@ public class ProcessDefinitionServiceImpl extends BaseService implements String processDefinitionName, String importProcessParam) { Map createProcessResult = null; - try { - createProcessResult = createProcessDefinition(loginUser - , currentProjectName, - processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp(), - importProcessParam, - processMeta.getProcessDefinitionDescription(), - processMeta.getProcessDefinitionLocations(), - processMeta.getProcessDefinitionConnects()); - putMsg(result, Status.SUCCESS); - } catch (JsonProcessingException e) { - logger.error("import process meta json data: {}", e.getMessage(), e); - putMsg(result, Status.IMPORT_PROCESS_DEFINE_ERROR); - } + createProcessResult = createProcessDefinition(loginUser + , currentProjectName, + processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp(), + importProcessParam, + processMeta.getProcessDefinitionDescription(), + processMeta.getProcessDefinitionLocations(), + processMeta.getProcessDefinitionConnects()); + putMsg(result, Status.SUCCESS); return createProcessResult; } @@ -1056,8 +1050,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements processDefine.setCreateTime(now); processDefine.setUpdateTime(now); processDefine.setFlag(subProcess.getFlag()); - processDefine.setReceivers(subProcess.getReceivers()); - processDefine.setReceiversCc(subProcess.getReceiversCc()); + processDefine.setWarningGroupId(subProcess.getWarningGroupId()); processDefineMapper.insert(processDefine); logger.info("create sub process, project: {}, process name: {}", targetProject.getName(), processDefine.getName()); @@ -1330,7 +1323,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements } runningNodeMap.remove(nodeName); } - if (waitingRunningNodeMap == null || waitingRunningNodeMap.size() == 0) { + if (waitingRunningNodeMap.size() == 0) { break; } else { runningNodeMap.putAll(waitingRunningNodeMap); @@ -1580,8 +1573,7 @@ public class ProcessDefinitionServiceImpl extends BaseService implements processDefinition.setTimeout(processDefinitionVersion.getTimeout()); processDefinition.setGlobalParams(processDefinitionVersion.getGlobalParams()); processDefinition.setUpdateTime(new Date()); - processDefinition.setReceivers(processDefinitionVersion.getReceivers()); - processDefinition.setReceiversCc(processDefinitionVersion.getReceiversCc()); + processDefinition.setWarningGroupId(processDefinitionVersion.getWarningGroupId()); processDefinition.setResourceIds(processDefinitionVersion.getResourceIds()); if (processDefineMapper.updateById(processDefinition) > 0) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java index 6364242190..08cedfee15 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionVersionServiceImpl.java @@ -66,18 +66,17 @@ public class ProcessDefinitionVersionServiceImpl extends BaseService implements long version = this.queryMaxVersionByProcessDefinitionId(processDefinition.getId()) + 1; ProcessDefinitionVersion processDefinitionVersion = ProcessDefinitionVersion - .newBuilder() - .processDefinitionId(processDefinition.getId()) - .version(version) - .processDefinitionJson(processDefinition.getProcessDefinitionJson()) - .description(processDefinition.getDescription()) - .locations(processDefinition.getLocations()) - .connects(processDefinition.getConnects()) - .timeout(processDefinition.getTimeout()) - .globalParams(processDefinition.getGlobalParams()) - .createTime(processDefinition.getUpdateTime()) - .receivers(processDefinition.getReceivers()) - .receiversCc(processDefinition.getReceiversCc()) + .newBuilder() + .processDefinitionId(processDefinition.getId()) + .version(version) + .processDefinitionJson(processDefinition.getProcessDefinitionJson()) + .description(processDefinition.getDescription()) + .locations(processDefinition.getLocations()) + .connects(processDefinition.getConnects()) + .timeout(processDefinition.getTimeout()) + .globalParams(processDefinition.getGlobalParams()) + .createTime(processDefinition.getUpdateTime()) + .warningGroupId(processDefinition.getWarningGroupId()) .resourceIds(processDefinition.getResourceIds()) .build(); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecutorControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecutorControllerTest.java index 77d8f38df0..f0bd948766 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecutorControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecutorControllerTest.java @@ -14,14 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.controller; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import org.apache.dolphinscheduler.api.enums.ExecuteType; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.enums.FailureStrategy; import org.apache.dolphinscheduler.common.enums.WarningType; -import org.apache.dolphinscheduler.common.utils.*; +import org.apache.dolphinscheduler.common.utils.JSONUtils; + import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -32,44 +38,39 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - /** * executor controller test */ -public class ExecutorControllerTest extends AbstractControllerTest{ +public class ExecutorControllerTest extends AbstractControllerTest { private static Logger logger = LoggerFactory.getLogger(ExecutorControllerTest.class); @Ignore @Test public void testStartProcessInstance() throws Exception { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processDefinitionId","40"); - paramsMap.add("scheduleTime",""); + paramsMap.add("processDefinitionId", "40"); + paramsMap.add("scheduleTime", ""); paramsMap.add("failureStrategy", String.valueOf(FailureStrategy.CONTINUE)); - paramsMap.add("startNodeList",""); - paramsMap.add("taskDependType",""); - paramsMap.add("execType",""); + paramsMap.add("startNodeList", ""); + paramsMap.add("taskDependType", ""); + paramsMap.add("execType", ""); paramsMap.add("warningType", String.valueOf(WarningType.NONE)); - paramsMap.add("warningGroupId",""); - paramsMap.add("receivers",""); - paramsMap.add("receiversCc",""); - paramsMap.add("runMode",""); - paramsMap.add("processInstancePriority",""); - paramsMap.add("workerGroupId",""); - paramsMap.add("timeout",""); + paramsMap.add("warningGroupId", ""); + paramsMap.add("receivers", ""); + paramsMap.add("receiversCc", ""); + paramsMap.add("runMode", ""); + paramsMap.add("processInstancePriority", ""); + paramsMap.add("workerGroupId", ""); + paramsMap.add("timeout", ""); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-process-instance","cxc_1113") - .header("sessionId", sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-process-instance", "cxc_1113") + .header("sessionId", sessionId) + .params(paramsMap)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } @@ -77,47 +78,32 @@ public class ExecutorControllerTest extends AbstractControllerTest{ @Test public void testExecute() throws Exception { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processInstanceId","40"); - paramsMap.add("executeType",String.valueOf(ExecuteType.NONE)); + paramsMap.add("processInstanceId", "40"); + paramsMap.add("executeType", String.valueOf(ExecuteType.NONE)); - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/execute","cxc_1113") - .header("sessionId", sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/execute", "cxc_1113") + .header("sessionId", sessionId) + .params(paramsMap)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } - @Test public void testStartCheckProcessDefinition() throws Exception { - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-check","cxc_1113") - .header(SESSION_ID, sessionId) - .param("processDefinitionId","40")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/executors/start-check", "cxc_1113") + .header(SESSION_ID, sessionId) + .param("processDefinitionId", "40")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); + Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); logger.info(mvcResult.getResponse().getContentAsString()); } - @Test - public void testGetReceiverCc() throws Exception { - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("processInstanceId","13"); - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/executors/get-receiver-cc","cxc_1113") - .header(SESSION_ID, sessionId) - .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andReturn(); - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); - Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); - logger.info(mvcResult.getResponse().getContentAsString()); - } } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java index 1b93e86773..a4b7cb32fb 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java @@ -14,14 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.service; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; + import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.common.Constants; @@ -31,15 +29,15 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; -import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; -import org.junit.After; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.Assert; -import static org.junit.Assert.assertEquals; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import static org.mockito.ArgumentMatchers.*; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -47,6 +45,9 @@ import org.mockito.junit.MockitoJUnitRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + @RunWith(MockitoJUnitRunner.class) public class AlertGroupServiceTest { @@ -56,128 +57,97 @@ public class AlertGroupServiceTest { private AlertGroupService alertGroupService; @Mock private AlertGroupMapper alertGroupMapper; - @Mock - private UserAlertGroupMapper userAlertGroupMapper; - @Mock - UserAlertGroupService userAlertGroupService; private String groupName = "AlertGroupServiceTest"; - @Before - public void setUp() { - } - - - @After - public void after(){ - - } - - - @Test - public void testQueryAlertGroup(){ + public void testQueryAlertGroup() { Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList()); - HashMap result= alertGroupService.queryAlertgroup(); + HashMap result = alertGroupService.queryAlertgroup(); logger.info(result.toString()); List alertGroups = (List) result.get(Constants.DATA_LIST); Assert.assertTrue(CollectionUtils.isNotEmpty(alertGroups)); } + @Test - public void testListPaging(){ - IPage page = new Page<>(1,10); + public void testListPaging() { + IPage page = new Page<>(1, 10); page.setTotal(1L); page.setRecords(getList()); - Mockito.when(alertGroupMapper.queryAlertGroupPage(any(Page.class),eq(groupName))).thenReturn(page); + Mockito.when(alertGroupMapper.queryAlertGroupPage(any(Page.class), eq(groupName))).thenReturn(page); User user = new User(); // no operate - Map result = alertGroupService.listPaging(user,groupName,1,10); + Map result = alertGroupService.listPaging(user, groupName, 1, 10); logger.info(result.toString()); - Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); + Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); //success user.setUserType(UserType.ADMIN_USER); - result = alertGroupService.listPaging(user,groupName,1,10); + result = alertGroupService.listPaging(user, groupName, 1, 10); logger.info(result.toString()); PageInfo pageInfo = (PageInfo) result.get(Constants.DATA_LIST); Assert.assertTrue(CollectionUtils.isNotEmpty(pageInfo.getLists())); } - @Test - public void testCreateAlertgroup(){ + @Test + public void testCreateAlertgroup() { Mockito.when(alertGroupMapper.insert(any(AlertGroup.class))).thenReturn(2); User user = new User(); //no operate - Map result = alertGroupService.createAlertgroup(user,groupName, AlertType.EMAIL,groupName); + Map result = alertGroupService.createAlertgroup(user, groupName, AlertType.EMAIL, groupName); logger.info(result.toString()); - Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); + Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); user.setUserType(UserType.ADMIN_USER); //success - result = alertGroupService.createAlertgroup(user,groupName, AlertType.EMAIL,groupName); + result = alertGroupService.createAlertgroup(user, groupName, AlertType.EMAIL, groupName); logger.info(result.toString()); - Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } + @Test - public void testUpdateAlertgroup(){ + public void testUpdateAlertgroup() { User user = new User(); // no operate - Map result = alertGroupService.updateAlertgroup(user,1,groupName, AlertType.SMS,groupName); + Map result = alertGroupService.updateAlertgroup(user, 1, groupName, AlertType.SMS, groupName); logger.info(result.toString()); - Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); + Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); user.setUserType(UserType.ADMIN_USER); // not exist - result = alertGroupService.updateAlertgroup(user,1,groupName, AlertType.SMS,groupName); + result = alertGroupService.updateAlertgroup(user, 1, groupName, AlertType.SMS, groupName); logger.info(result.toString()); - Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST,result.get(Constants.STATUS)); + Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST, result.get(Constants.STATUS)); //success Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity()); - result = alertGroupService.updateAlertgroup(user,2,groupName, AlertType.SMS,groupName); + result = alertGroupService.updateAlertgroup(user, 2, groupName, AlertType.SMS, groupName); logger.info(result.toString()); - Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } + @Test - public void testDelAlertgroupById(){ + public void testDelAlertgroupById() { User user = new User(); // no operate - Map result = alertGroupService.delAlertgroupById(user,1); + Map result = alertGroupService.delAlertgroupById(user, 1); logger.info(result.toString()); - Assert.assertEquals(Status.USER_NO_OPERATION_PERM,result.get(Constants.STATUS)); + Assert.assertEquals(Status.USER_NO_OPERATION_PERM, result.get(Constants.STATUS)); user.setUserType(UserType.ADMIN_USER); // not exist - result = alertGroupService.delAlertgroupById(user,2); + result = alertGroupService.delAlertgroupById(user, 2); logger.info(result.toString()); - Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST,result.get(Constants.STATUS)); + Assert.assertEquals(Status.ALERT_GROUP_NOT_EXIST, result.get(Constants.STATUS)); //success Mockito.when(alertGroupMapper.selectById(2)).thenReturn(getEntity()); - result = alertGroupService.delAlertgroupById(user,2); + result = alertGroupService.delAlertgroupById(user, 2); logger.info(result.toString()); - Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); - + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } - @Test - public void testGrantUser() { - - Integer groupId = 1; - - ArgumentCaptor groupArgument = ArgumentCaptor.forClass(Integer.class); - - Mockito.when(userAlertGroupService.deleteByAlertGroupId(anyInt())).thenReturn(true); - - Map result = alertGroupService.grantUser(getLoginUser(), groupId, "123,321"); - Mockito.verify(userAlertGroupService).deleteByAlertGroupId(groupArgument.capture()); - - logger.info(result.toString()); - assertEquals(groupArgument.getValue(), groupId); - assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - @Test public void testVerifyGroupName() { //group name not exist @@ -190,12 +160,12 @@ public class AlertGroupServiceTest { Assert.assertTrue(result); } - /** * create admin user + * * @return */ - private User getLoginUser(){ + private User getLoginUser() { User loginUser = new User(); loginUser.setUserType(UserType.ADMIN_USER); @@ -205,9 +175,10 @@ public class AlertGroupServiceTest { /** * get list + * * @return */ - private List getList(){ + private List getList() { List alertGroups = new ArrayList<>(); alertGroups.add(getEntity()); return alertGroups; @@ -215,13 +186,13 @@ public class AlertGroupServiceTest { /** * get entity + * * @return */ - private AlertGroup getEntity(){ + private AlertGroup getEntity() { AlertGroup alertGroup = new AlertGroup(); alertGroup.setId(1); alertGroup.setGroupName(groupName); - alertGroup.setGroupType(AlertType.EMAIL); return alertGroup; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java index a4c0c6bfe7..4c874340aa 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorService2Test.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.api.service; import static org.mockito.ArgumentMatchers.any; @@ -126,18 +127,17 @@ public class ExecutorService2Test { */ @Test public void testNoComplement() throws ParseException { - try { - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.START_PROCESS, - null, null, - null, null, 0, - "", "", RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(1)).createCommand(any(Command.class)); - } catch (Exception e) { - } + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectName, + processDefinitionId, cronTime, CommandType.START_PROCESS, + null, null, + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(1)).createCommand(any(Command.class)); + } /** @@ -145,18 +145,16 @@ public class ExecutorService2Test { */ @Test public void testDateError() throws ParseException { - try { - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, "2020-01-31 23:00:00,2020-01-01 00:00:00", CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - "", "", RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); - Assert.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); - verify(processService, times(0)).createCommand(any(Command.class)); - } catch (Exception e) { - } + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectName, + processDefinitionId, "2020-01-31 23:00:00,2020-01-01 00:00:00", CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); + Assert.assertEquals(Status.START_PROCESS_INSTANCE_ERROR, result.get(Constants.STATUS)); + verify(processService, times(0)).createCommand(any(Command.class)); } /** @@ -164,18 +162,16 @@ public class ExecutorService2Test { */ @Test public void testSerial() throws ParseException { - try { - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - "", "", RunMode.RUN_MODE_SERIAL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(1)).createCommand(any(Command.class)); - } catch (Exception e) { - } + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectName, + processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_SERIAL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(1)).createCommand(any(Command.class)); } /** @@ -183,18 +179,17 @@ public class ExecutorService2Test { */ @Test public void testParallelWithOutSchedule() throws ParseException { - try { - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - "", "", RunMode.RUN_MODE_PARALLEL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(31)).createCommand(any(Command.class)); - } catch (Exception e) { - } + + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(zeroSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectName, + processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_PARALLEL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(31)).createCommand(any(Command.class)); + } /** @@ -202,31 +197,28 @@ public class ExecutorService2Test { */ @Test public void testParallelWithSchedule() throws ParseException { - try { - Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(oneSchedulerList()); - Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - "", "", RunMode.RUN_MODE_PARALLEL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - verify(processService, times(15)).createCommand(any(Command.class)); - } catch (Exception e) { - } - } + Mockito.when(processService.queryReleaseSchedulerListByProcessDefinitionId(processDefinitionId)).thenReturn(oneSchedulerList()); + Map result = executorService.execProcessInstance(loginUser, projectName, + processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_PARALLEL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + verify(processService, times(15)).createCommand(any(Command.class)); + } @Test - public void testNoMsterServers() throws ParseException { + public void testNoMasterServers() throws ParseException { Mockito.when(monitorService.getServerListFromZK(true)).thenReturn(new ArrayList()); Map result = executorService.execProcessInstance(loginUser, projectName, - processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, - null, null, - null, null, 0, - "", "", RunMode.RUN_MODE_PARALLEL, - Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); + processDefinitionId, cronTime, CommandType.COMPLEMENT_DATA, + null, null, + null, null, 0, + RunMode.RUN_MODE_PARALLEL, + Priority.LOW, Constants.DEFAULT_WORKER_GROUP, 110); Assert.assertEquals(result.get(Constants.STATUS), Status.MASTER_NOT_EXISTS); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java index 169ef2bcfe..5a8d09fdc5 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionVersionServiceTest.java @@ -216,18 +216,17 @@ public class ProcessDefinitionVersionServiceTest { */ private ProcessDefinitionVersion getProcessDefinitionVersion(ProcessDefinition processDefinition) { return ProcessDefinitionVersion - .newBuilder() - .processDefinitionId(processDefinition.getId()) - .version(1) - .processDefinitionJson(processDefinition.getProcessDefinitionJson()) - .description(processDefinition.getDescription()) - .locations(processDefinition.getLocations()) - .connects(processDefinition.getConnects()) - .timeout(processDefinition.getTimeout()) - .globalParams(processDefinition.getGlobalParams()) - .createTime(processDefinition.getUpdateTime()) - .receivers(processDefinition.getReceivers()) - .receiversCc(processDefinition.getReceiversCc()) + .newBuilder() + .processDefinitionId(processDefinition.getId()) + .version(1) + .processDefinitionJson(processDefinition.getProcessDefinitionJson()) + .description(processDefinition.getDescription()) + .locations(processDefinition.getLocations()) + .connects(processDefinition.getConnects()) + .timeout(processDefinition.getTimeout()) + .globalParams(processDefinition.getGlobalParams()) + .createTime(processDefinition.getUpdateTime()) + .warningGroupId(processDefinition.getWarningGroupId()) .resourceIds(processDefinition.getResourceIds()) .build(); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UserAlertGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UserAlertGroupServiceTest.java deleted file mode 100644 index 24b1d5a98b..0000000000 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UserAlertGroupServiceTest.java +++ /dev/null @@ -1,53 +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.api.service; - -import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; - -/** - * - */ -@RunWith(MockitoJUnitRunner.class) -public class UserAlertGroupServiceTest { - - @InjectMocks - UserAlertGroupService userAlertGroupService; - - @Mock - UserAlertGroupMapper userAlertGroupMapper; - - @Test - public void deleteByAlertGroupId() { - - Integer groupId = 1; - userAlertGroupService.deleteByAlertGroupId(groupId); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Integer.class); - - Mockito.verify(userAlertGroupMapper).deleteByAlertgroupId(argumentCaptor.capture()); - assertEquals(argumentCaptor.getValue(), groupId); - - } - -} \ No newline at end of file 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 4a5c7be8a3..d03b7c5be3 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 @@ -19,10 +19,8 @@ package org.apache.dolphinscheduler.dao; import org.apache.dolphinscheduler.common.enums.AlertEvent; import org.apache.dolphinscheduler.common.enums.AlertStatus; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.AlertWarnLevel; import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory; import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; @@ -30,11 +28,9 @@ import org.apache.dolphinscheduler.dao.entity.ProcessAlertContent; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ServerAlertContent; -import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.AlertMapper; import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper; -import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; import java.util.ArrayList; import java.util.Date; @@ -53,9 +49,6 @@ public class AlertDao extends AbstractBaseDao { @Autowired private AlertMapper alertMapper; - @Autowired - private UserAlertGroupMapper userAlertGroupMapper; - @Autowired private AlertPluginInstanceMapper alertPluginInstanceMapper; @@ -65,7 +58,6 @@ public class AlertDao extends AbstractBaseDao { @Override protected void init() { alertMapper = ConnectionFactory.getInstance().getMapper(AlertMapper.class); - userAlertGroupMapper = ConnectionFactory.getInstance().getMapper(UserAlertGroupMapper.class); alertPluginInstanceMapper = ConnectionFactory.getInstance().getMapper(AlertPluginInstanceMapper.class); alertGroupMapper = ConnectionFactory.getInstance().getMapper(AlertGroupMapper.class); } @@ -96,34 +88,23 @@ public class AlertDao extends AbstractBaseDao { return alertMapper.updateById(alert); } - /** - * query user list by alert group id - * - * @param alerGroupId alerGroupId - * @return user list - */ - public List queryUserByAlertGroupId(int alerGroupId) { - - return userAlertGroupMapper.listUserByAlertgroupId(alerGroupId); - } - /** * MasterServer or WorkerServer stoped * - * @param alertgroupId alertgroupId + * @param alertGroupId alertGroupId * @param host host * @param serverType serverType */ - public void sendServerStopedAlert(int alertgroupId, String host, String serverType) { + public void sendServerStopedAlert(int alertGroupId, String host, String serverType) { Alert alert = new Alert(); List serverAlertContents = new ArrayList<>(1); ServerAlertContent serverStopAlertContent = ServerAlertContent.newBuilder(). - type(serverType).host(host).event(AlertEvent.SERVER_DOWN).warningLevel(AlertWarnLevel.SERIOUS). - build(); + type(serverType).host(host).event(AlertEvent.SERVER_DOWN).warningLevel(AlertWarnLevel.SERIOUS). + build(); serverAlertContents.add(serverStopAlertContent); String content = JSONUtils.toJsonString(serverAlertContents); alert.setTitle("Fault tolerance warning"); - saveTaskTimeoutAlert(alert, content, alertgroupId, null, null); + saveTaskTimeoutAlert(alert, content, alertGroupId); } /** @@ -133,34 +114,24 @@ public class AlertDao extends AbstractBaseDao { * @param processDefinition processDefinition */ public void sendProcessTimeoutAlert(ProcessInstance processInstance, ProcessDefinition processDefinition) { - int alertgroupId = processInstance.getWarningGroupId(); - String receivers = processDefinition.getReceivers(); - String receiversCc = processDefinition.getReceiversCc(); + int alertGroupId = processInstance.getWarningGroupId(); Alert alert = new Alert(); List processAlertContentList = new ArrayList<>(1); ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder() .processId(processInstance.getId()) - .processName(processInstance.getName()) - .event(AlertEvent.TIME_OUT) - .warningLevel(AlertWarnLevel.MIDDLE) - .build(); + .processName(processInstance.getName()) + .event(AlertEvent.TIME_OUT) + .warningLevel(AlertWarnLevel.MIDDLE) + .build(); processAlertContentList.add(processAlertContent); String content = JSONUtils.toJsonString(processAlertContentList); alert.setTitle("Process Timeout Warn"); - saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); + saveTaskTimeoutAlert(alert, content, alertGroupId); } - private void saveTaskTimeoutAlert(Alert alert, String content, int alertgroupId, String receivers, String receiversCc) { - //alert.setShowType(ShowType.TABLE); + private void saveTaskTimeoutAlert(Alert alert, String content, int alertGroupId) { + alert.setAlertGroupId(alertGroupId); alert.setContent(content); - alert.setAlertType(AlertType.EMAIL); - alert.setAlertGroupId(alertgroupId); - if (StringUtils.isNotEmpty(receivers)) { - alert.setReceivers(receivers); - } - if (StringUtils.isNotEmpty(receiversCc)) { - alert.setReceiversCc(receiversCc); - } alert.setCreateTime(new Date()); alert.setUpdateTime(new Date()); alertMapper.insert(alert); @@ -169,30 +140,28 @@ public class AlertDao extends AbstractBaseDao { /** * task timeout warn * - * @param alertgroupId alertgroupId - * @param receivers receivers - * @param receiversCc receiversCc + * @param alertGroupId alertGroupId * @param processInstanceId processInstanceId * @param processInstanceName processInstanceName * @param taskId taskId * @param taskName taskName */ - public void sendTaskTimeoutAlert(int alertgroupId, String receivers, String receiversCc, int processInstanceId, + public void sendTaskTimeoutAlert(int alertGroupId, int processInstanceId, String processInstanceName, int taskId, String taskName) { Alert alert = new Alert(); List processAlertContentList = new ArrayList<>(1); ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder() - .processId(processInstanceId) - .processName(processInstanceName) - .taskId(taskId) - .taskName(taskName) - .event(AlertEvent.TIME_OUT) - .warningLevel(AlertWarnLevel.MIDDLE) + .processId(processInstanceId) + .processName(processInstanceName) + .taskId(taskId) + .taskName(taskName) + .event(AlertEvent.TIME_OUT) + .warningLevel(AlertWarnLevel.MIDDLE) .build(); processAlertContentList.add(processAlertContent); String content = JSONUtils.toJsonString(processAlertContentList); alert.setTitle("Task Timeout Warn"); - saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); + saveTaskTimeoutAlert(alert, content, alertGroupId); } /** @@ -204,16 +173,6 @@ public class AlertDao extends AbstractBaseDao { return alertMapper.listAlertByStatus(AlertStatus.WAIT_EXECUTION); } - /** - * list user information by alert group id - * - * @param alertgroupId alertgroupId - * @return user list - */ - public List listUserByAlertgroupId(int alertgroupId) { - return userAlertGroupMapper.listUserByAlertgroupId(alertgroupId); - } - /** * for test * diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java index 5f0796c19d..752ab9d8f9 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java @@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.dao.entity; import org.apache.dolphinscheduler.common.enums.AlertStatus; -import org.apache.dolphinscheduler.common.enums.AlertType; import java.util.Date; import java.util.HashMap; @@ -41,23 +40,13 @@ public class Alert { */ @TableField(value = "title") private String title; - /** - * show_type - */ - //TODO ShowType should be delete from Alert, Because showType is move to the plugin params - @TableField(value = "show_type") - private String showType; + /** * content */ @TableField(value = "content") private String content; - /** - * alert_type - */ - //TODO alertType should be delete from Alert, because alert type is decide by the AlertPlugin instance - @TableField(value = "alert_type") - private AlertType alertType; + /** * alert_status */ @@ -73,18 +62,7 @@ public class Alert { */ @TableField("alertgroup_id") private int alertGroupId; - /** - * receivers - */ - //TODO receivers should be delete from Alert, because only email alert need receivers . And receivers is move to Email Alert Plugin params. - @TableField("receivers") - private String receivers; - /** - * receivers_cc - */ - //TODO receivers_cc should be delete from Alert, because only email alert need receivers_cc . And receivers_cc is move to Email Alert Plugin params. - @TableField("receivers_cc") - private String receiversCc; + /** * create_time */ @@ -117,14 +95,6 @@ public class Alert { this.title = title; } - // public String getShowType() { - // return showType; - // } - // - // public void setShowType(String showType) { - // this.showType = showType; - // } - public String getContent() { return content; } @@ -133,14 +103,6 @@ public class Alert { this.content = content; } - public AlertType getAlertType() { - return alertType; - } - - public void setAlertType(AlertType alertType) { - this.alertType = alertType; - } - public AlertStatus getAlertStatus() { return alertStatus; } @@ -165,22 +127,6 @@ public class Alert { this.alertGroupId = alertGroupId; } - public String getReceivers() { - return receivers; - } - - public void setReceivers(String receivers) { - this.receivers = receivers; - } - - public String getReceiversCc() { - return receiversCc; - } - - public void setReceiversCc(String receiversCc) { - this.receiversCc = receiversCc; - } - public Date getCreateTime() { return createTime; } @@ -225,27 +171,15 @@ public class Alert { if (!title.equals(alert.title)) { return false; } - if (showType != alert.showType) { - return false; - } if (!content.equals(alert.content)) { return false; } - if (alertType != alert.alertType) { - return false; - } if (alertStatus != alert.alertStatus) { return false; } if (!log.equals(alert.log)) { return false; } - if (!receivers.equals(alert.receivers)) { - return false; - } - if (!receiversCc.equals(alert.receiversCc)) { - return false; - } if (!createTime.equals(alert.createTime)) { return false; } @@ -257,14 +191,10 @@ public class Alert { public int hashCode() { int result = id; result = 31 * result + title.hashCode(); - result = 31 * result + showType.hashCode(); result = 31 * result + content.hashCode(); - result = 31 * result + alertType.hashCode(); result = 31 * result + alertStatus.hashCode(); result = 31 * result + log.hashCode(); result = 31 * result + alertGroupId; - result = 31 * result + receivers.hashCode(); - result = 31 * result + receiversCc.hashCode(); result = 31 * result + createTime.hashCode(); result = 31 * result + updateTime.hashCode(); result = 31 * result + info.hashCode(); @@ -278,13 +208,9 @@ public class Alert { + id + ", title='" + title + '\'' - + ", showType=" - + showType + ", content='" + content + '\'' - + ", alertType=" - + alertType + ", alertStatus=" + alertStatus + ", log='" @@ -292,11 +218,6 @@ public class Alert { + '\'' + ", alertGroupId=" + alertGroupId - + ", receivers='" - + receivers - + '\'' - + ", receiversCc='" - + receiversCc + '\'' + ", createTime=" + createTime diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java index e35e2f759c..93eedf6b1d 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.dao.entity; -import com.baomidou.mybatisplus.annotation.TableField; -import org.apache.dolphinscheduler.common.enums.AlertType; +import java.util.Date; + import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.util.Date; - @TableName("t_ds_alertgroup") public class AlertGroup { /** @@ -36,11 +36,7 @@ public class AlertGroup { */ @TableField(value = "group_name") private String groupName; - /** - * group_type - */ - @TableField(value = "group_type") - private AlertType groupType; + /** * description */ @@ -57,6 +53,12 @@ public class AlertGroup { @TableField(value = "update_time") private Date updateTime; + /** + * create_user_id + */ + @TableField(value = "create_user_id") + private int createUserId; + public int getId() { return id; } @@ -73,14 +75,6 @@ public class AlertGroup { this.groupName = groupName; } - public AlertType getGroupType() { - return groupType; - } - - public void setGroupType(AlertType groupType) { - this.groupType = groupType; - } - public Date getCreateTime() { return createTime; } @@ -105,6 +99,14 @@ public class AlertGroup { this.description = description; } + public int getCreateUserId() { + return createUserId; + } + + public void setCreateUserId(int createUserId) { + this.createUserId = createUserId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -119,10 +121,10 @@ public class AlertGroup { if (id != that.id) { return false; } - if (groupName != null ? !groupName.equals(that.groupName) : that.groupName != null) { + if (createUserId != that.createUserId) { return false; } - if (groupType != that.groupType) { + if (groupName != null ? !groupName.equals(that.groupName) : that.groupName != null) { return false; } if (description != null ? !description.equals(that.description) : that.description != null) { @@ -135,8 +137,8 @@ public class AlertGroup { @Override public int hashCode() { int result = id; + result = 31 * result + createUserId; result = 31 * result + (groupName != null ? groupName.hashCode() : 0); - result = 31 * result + (groupType != null ? groupType.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (createTime != null ? createTime.hashCode() : 0); result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0); @@ -145,13 +147,13 @@ public class AlertGroup { @Override public String toString() { - return "AlertGroup{" + - "id=" + id + - ", groupName='" + groupName + '\'' + - ", groupType=" + groupType + - ", description='" + description + '\'' + - ", createTime=" + createTime + - ", updateTime=" + updateTime + - '}'; + return "AlertGroup{" + + "id=" + id + + "createUserId=" + createUserId + + ", groupName='" + groupName + '\'' + + ", description='" + description + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + '}'; } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java index 56f6cfe905..0c2b844fd1 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java @@ -139,16 +139,6 @@ public class ProcessDefinition { */ private String connects; - /** - * receivers - */ - private String receivers; - - /** - * receivers cc - */ - private String receiversCc; - /** * schedule release state : online/offline */ @@ -175,6 +165,11 @@ public class ProcessDefinition { */ private String resourceIds; + /** + * warningGroupId + */ + @TableField(exist = false) + private int warningGroupId; public String getName() { return name; @@ -272,7 +267,6 @@ public class ProcessDefinition { this.projectName = projectName; } - public String getGlobalParams() { return globalParams; } @@ -324,22 +318,6 @@ public class ProcessDefinition { this.connects = connects; } - public String getReceivers() { - return receivers; - } - - public void setReceivers(String receivers) { - this.receivers = receivers; - } - - public String getReceiversCc() { - return receiversCc; - } - - public void setReceiversCc(String receiversCc) { - this.receiversCc = receiversCc; - } - public ReleaseState getScheduleReleaseState() { return scheduleReleaseState; } @@ -388,35 +366,42 @@ public class ProcessDefinition { this.modifyBy = modifyBy; } + public int getWarningGroupId() { + return warningGroupId; + } + + public void setWarningGroupId(int warningGroupId) { + this.warningGroupId = warningGroupId; + } + @Override public String toString() { - return "ProcessDefinition{" + - "id=" + id + - ", name='" + name + '\'' + - ", version=" + version + - ", releaseState=" + releaseState + - ", projectId=" + projectId + - ", processDefinitionJson='" + processDefinitionJson + '\'' + - ", description='" + description + '\'' + - ", globalParams='" + globalParams + '\'' + - ", globalParamList=" + globalParamList + - ", globalParamMap=" + globalParamMap + - ", createTime=" + createTime + - ", updateTime=" + updateTime + - ", flag=" + flag + - ", userId=" + userId + - ", userName='" + userName + '\'' + - ", projectName='" + projectName + '\'' + - ", locations='" + locations + '\'' + - ", connects='" + connects + '\'' + - ", receivers='" + receivers + '\'' + - ", receiversCc='" + receiversCc + '\'' + - ", scheduleReleaseState=" + scheduleReleaseState + - ", timeout=" + timeout + - ", tenantId=" + tenantId + - ", modifyBy='" + modifyBy + '\'' + - ", resourceIds='" + resourceIds + '\'' + - '}'; + return "ProcessDefinition{" + + "id=" + id + + ", name='" + name + '\'' + + ", version=" + version + + ", releaseState=" + releaseState + + ", projectId=" + projectId + + ", processDefinitionJson='" + processDefinitionJson + '\'' + + ", description='" + description + '\'' + + ", globalParams='" + globalParams + '\'' + + ", globalParamList=" + globalParamList + + ", globalParamMap=" + globalParamMap + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", flag=" + flag + + ", userId=" + userId + + ", userName='" + userName + '\'' + + ", projectName='" + projectName + '\'' + + ", locations='" + locations + '\'' + + ", connects='" + connects + '\'' + + ", scheduleReleaseState=" + scheduleReleaseState + + ", timeout=" + timeout + + ", warningGroupId=" + warningGroupId + + ", tenantId=" + tenantId + + ", modifyBy='" + modifyBy + '\'' + + ", resourceIds='" + resourceIds + '\'' + + '}'; } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java index 26779ba925..1c4d979415 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.dao.entity; import java.util.Date; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; @@ -57,16 +58,6 @@ public class ProcessDefinitionVersion { */ private String description; - /** - * receivers - */ - private String receivers; - - /** - * receivers cc - */ - private String receiversCc; - /** * process warning time out. unit: minute */ @@ -98,6 +89,13 @@ public class ProcessDefinitionVersion { */ private String connects; + + /** + * warningGroupId + */ + @TableField(exist = false) + private int warningGroupId; + public String getGlobalParams() { return globalParams; } @@ -170,22 +168,6 @@ public class ProcessDefinitionVersion { this.connects = connects; } - public String getReceivers() { - return receivers; - } - - public void setReceivers(String receivers) { - this.receivers = receivers; - } - - public String getReceiversCc() { - return receiversCc; - } - - public void setReceiversCc(String receiversCc) { - this.receiversCc = receiversCc; - } - public int getTimeout() { return timeout; } @@ -202,23 +184,30 @@ public class ProcessDefinitionVersion { this.resourceIds = resourceIds; } + public int getWarningGroupId() { + return warningGroupId; + } + + public void setWarningGroupId(int warningGroupId) { + this.warningGroupId = warningGroupId; + } + @Override public String toString() { return "ProcessDefinitionVersion{" - + "id=" + id - + ", processDefinitionId=" + processDefinitionId - + ", version=" + version - + ", processDefinitionJson='" + processDefinitionJson + '\'' - + ", description='" + description + '\'' - + ", globalParams='" + globalParams + '\'' - + ", createTime=" + createTime - + ", locations='" + locations + '\'' - + ", connects='" + connects + '\'' - + ", receivers='" + receivers + '\'' - + ", receiversCc='" + receiversCc + '\'' - + ", timeout=" + timeout - + ", resourceIds='" + resourceIds + '\'' - + '}'; + + "id=" + id + + ", processDefinitionId=" + processDefinitionId + + ", version=" + version + + ", processDefinitionJson='" + processDefinitionJson + '\'' + + ", description='" + description + '\'' + + ", globalParams='" + globalParams + '\'' + + ", createTime=" + createTime + + ", locations='" + locations + '\'' + + ", connects='" + connects + '\'' + + ", timeout=" + timeout + + ", warningGroupId=" + warningGroupId + + ", resourceIds='" + resourceIds + '\'' + + '}'; } public static Builder newBuilder() { @@ -235,9 +224,8 @@ public class ProcessDefinitionVersion { private Date createTime; private String locations; private String connects; - private String receivers; - private String receiversCc; private int timeout; + private int warningGroupId; private String resourceIds; private Builder() { @@ -288,18 +276,13 @@ public class ProcessDefinitionVersion { return this; } - public Builder receivers(String receivers) { - this.receivers = receivers; - return this; - } - - public Builder receiversCc(String receiversCc) { - this.receiversCc = receiversCc; + public Builder timeout(int timeout) { + this.timeout = timeout; return this; } - public Builder timeout(int timeout) { - this.timeout = timeout; + public Builder warningGroupId(int warningGroupId) { + this.warningGroupId = warningGroupId; return this; } @@ -319,9 +302,8 @@ public class ProcessDefinitionVersion { processDefinitionVersion.setCreateTime(createTime); processDefinitionVersion.setLocations(locations); processDefinitionVersion.setConnects(connects); - processDefinitionVersion.setReceivers(receivers); - processDefinitionVersion.setReceiversCc(receiversCc); processDefinitionVersion.setTimeout(timeout); + processDefinitionVersion.setWarningGroupId(warningGroupId); processDefinitionVersion.setResourceIds(resourceIds); return processDefinitionVersion; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/UserAlertGroup.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/UserAlertGroup.java deleted file mode 100644 index 902196d186..0000000000 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/UserAlertGroup.java +++ /dev/null @@ -1,142 +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.dao.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.fasterxml.jackson.annotation.JsonFormat; - -import java.util.Date; - -/** - * user alert group - */ -@TableName("t_ds_relation_user_alertgroup") -public class UserAlertGroup { - - /** - * id - */ - @TableId(value="id", type=IdType.AUTO) - private int id; - - /** - * id - */ - @TableField("alertgroup_id") - private int alertgroupId; - - /** - * alert group name - */ - @TableField(exist = false) - private String alertgroupName; - - /** - * user id - */ - private int userId; - - /** - * user name - */ - @TableField(exist = false) - private String userName; - - /** - * create time - */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") - private Date createTime; - - /** - * update time - */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") - private Date updateTime; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getAlertgroupId() { - return alertgroupId; - } - - public void setAlertgroupId(int alertgroupId) { - this.alertgroupId = alertgroupId; - } - - public int getUserId() { - return userId; - } - - public void setUserId(int userId) { - this.userId = userId; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - - public String getAlertgroupName() { - return alertgroupName; - } - - public void setAlertgroupName(String alertgroupName) { - this.alertgroupName = alertgroupName; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - @Override - public String toString() { - return "UserAlertGroup{" + - "id=" + id + - ", alertgroupId=" + alertgroupId + - ", alertgroupName='" + alertgroupName + '\'' + - ", userId=" + userId + - ", userName='" + userName + '\'' + - ", createTime=" + createTime + - ", updateTime=" + updateTime + - '}'; - } -} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java index 0fd26b9f79..e337ab6409 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java @@ -55,14 +55,6 @@ public interface AlertGroupMapper extends BaseMapper { */ List queryByUserId(@Param("userId") int userId); - - /** - * query by alert type - * @param alertType alertType - * @return alertgroup list - */ - List queryByAlertType(@Param("alertType") AlertType alertType); - /** * query all group list * @return alertgroup list diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.java deleted file mode 100644 index f374c202cd..0000000000 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.java +++ /dev/null @@ -1,45 +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.dao.mapper; - -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.entity.UserAlertGroup; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -/** - * user alertgroup relation mapper interface - */ -public interface UserAlertGroupMapper extends BaseMapper { - - /** - * delete user alertgroup relation by alertgroupId - * @param alertgroupId alertgroupId - * @return delete result - */ - int deleteByAlertgroupId(@Param("alertgroupId") int alertgroupId); - - /** - * list user by alertgroupId - * @param alertgroupId alertgroupId - * @return user list - */ - List listUserByAlertgroupId(@Param("alertgroupId") int alertgroupId); - -} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml index 8ee335b6ff..d68d4597f4 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml @@ -31,14 +31,10 @@ where group_name=#{groupName} - + - SELECT u.* - FROM t_ds_relation_user_alertgroup g_u - JOIN t_ds_user u on g_u.user_id = u.id - WHERE g_u.alertgroup_id = #{alertgroupId} - - \ No newline at end of file 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 0b5c516dee..0137bd5639 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 @@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.dao; import org.apache.dolphinscheduler.common.enums.AlertStatus; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.dao.entity.Alert; import java.util.List; @@ -33,10 +32,8 @@ public class AlertDaoTest { AlertDao alertDao = DaoFactory.getDaoInstance(AlertDao.class); Alert alert = new Alert(); alert.setTitle("Mysql Exception"); - //alert.setShowType(ShowType.TEXT); - alert.setContent("[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", " + - "\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]"); - alert.setAlertType(AlertType.EMAIL); + alert.setContent("[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", " + + "\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]"); alert.setAlertGroupId(1); alert.setAlertStatus(AlertStatus.WAIT_EXECUTION); alertDao.addAlert(alert); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapperTest.java index c8d0953bc6..db42a2f57b 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapperTest.java @@ -14,38 +14,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.dao.mapper; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.utils.DateUtils; -import org.apache.dolphinscheduler.dao.entity.AccessToken; import org.apache.dolphinscheduler.dao.entity.AlertGroup; -import org.apache.dolphinscheduler.dao.entity.UserAlertGroup; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; /** - * AlertGroup mapper test + * AlertGroup mapper test */ @RunWith(SpringRunner.class) @SpringBootTest @@ -53,22 +51,17 @@ import static org.junit.Assert.*; @Rollback(true) public class AlertGroupMapperTest { - @Autowired AlertGroupMapper alertGroupMapper; - @Autowired - UserAlertGroupMapper userAlertGroupMapper; - - /** * test insert */ @Test - public void testInsert(){ + public void testInsert() { AlertGroup alertGroup = createAlertGroup(); assertNotNull(alertGroup); - assertThat(alertGroup.getId(),greaterThan(0)); + assertThat(alertGroup.getId(), greaterThan(0)); } @@ -99,7 +92,7 @@ public class AlertGroupMapperTest { Integer offset = 2; Integer size = 2; - Map alertGroupMap = createAlertGroups(count,groupName); + Map alertGroupMap = createAlertGroups(count, groupName); Page page = new Page(offset, size); @@ -109,25 +102,23 @@ public class AlertGroupMapperTest { assertEquals(alertGroupList.size(), size.intValue()); - for (AlertGroup alertGroup : alertGroupList){ + for (AlertGroup alertGroup : alertGroupList) { AlertGroup resultAlertGroup = alertGroupMap.get(alertGroup.getId()); - if (resultAlertGroup != null){ - assertEquals(alertGroup,resultAlertGroup); + if (resultAlertGroup != null) { + assertEquals(alertGroup, resultAlertGroup); } } - } /** * test update */ @Test - public void testUpdate(){ + public void testUpdate() { AlertGroup alertGroup = createAlertGroup(); alertGroup.setGroupName("modify GroupName"); - alertGroup.setGroupType(AlertType.SMS); alertGroup.setDescription("modify GroupName"); alertGroup.setUpdateTime(DateUtils.getCurrentDate()); @@ -135,16 +126,15 @@ public class AlertGroupMapperTest { AlertGroup resultAlertGroup = alertGroupMapper.selectById(alertGroup.getId()); - assertEquals(alertGroup,resultAlertGroup); + assertEquals(alertGroup, resultAlertGroup); } - /** * test delete */ @Test - public void testDelete(){ + public void testDelete() { AlertGroup alertGroup = createAlertGroup(); @@ -156,7 +146,6 @@ public class AlertGroupMapperTest { } - /** * test query by groupname */ @@ -169,42 +158,9 @@ public class AlertGroupMapperTest { List alertGroupList = alertGroupMapper.queryByGroupName("testGroup"); - compareAlertGroups(alertGroupMap, alertGroupList); } - /** - * test query by userId - */ - @Test - public void testQueryByUserId() { - Integer count = 4; - Integer userId = 1; - - Map alertGroupMap = - createAlertGroups(count, userId); - - List alertGroupList = - alertGroupMapper.queryByUserId(userId); - - compareAlertGroups(alertGroupMap,alertGroupList); - - } - - /** - * test query by alert type - */ - @Test - public void testQueryByAlertType() { - Integer count = 4; - - Map alertGroupMap = createAlertGroups(count); - List alertGroupList = alertGroupMapper.queryByAlertType(AlertType.EMAIL); - - compareAlertGroups(alertGroupMap,alertGroupList); - - } - /** * test query all group list */ @@ -215,37 +171,38 @@ public class AlertGroupMapperTest { List alertGroupList = alertGroupMapper.queryAllGroupList(); - compareAlertGroups(alertGroupMap,alertGroupList); + compareAlertGroups(alertGroupMap, alertGroupList); } - /** * compare AlertGruops - * @param alertGroupMap alertGroupMap + * + * @param alertGroupMap alertGroupMap * @param alertGroupList alertGroupList */ - private void compareAlertGroups(Map alertGroupMap, - List alertGroupList){ + private void compareAlertGroups(Map alertGroupMap, + List alertGroupList) { // greaterThanOrEqualTo,beacuse maybe db have already exists - assertThat(alertGroupList.size(),greaterThanOrEqualTo(alertGroupMap.size())); + assertThat(alertGroupList.size(), greaterThanOrEqualTo(alertGroupMap.size())); - for (AlertGroup alertGroup : alertGroupList){ + for (AlertGroup alertGroup : alertGroupList) { AlertGroup resultAlertGroup = alertGroupMap.get(alertGroup.getId()); - if (resultAlertGroup != null){ - assertEquals(alertGroup,resultAlertGroup); + if (resultAlertGroup != null) { + assertEquals(alertGroup, resultAlertGroup); } } } + /** * insert + * * @return AlertGroup */ - private AlertGroup createAlertGroup(String groupName){ + private AlertGroup createAlertGroup(String groupName) { AlertGroup alertGroup = new AlertGroup(); alertGroup.setGroupName(groupName); alertGroup.setDescription("alert group 1"); - alertGroup.setGroupType(AlertType.EMAIL); alertGroup.setCreateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate()); @@ -257,13 +214,13 @@ public class AlertGroupMapperTest { /** * insert + * * @return AlertGroup */ - private AlertGroup createAlertGroup(){ + private AlertGroup createAlertGroup() { AlertGroup alertGroup = new AlertGroup(); alertGroup.setGroupName("testGroup"); alertGroup.setDescription("testGroup"); - alertGroup.setGroupType(AlertType.EMAIL); alertGroup.setCreateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate()); @@ -275,81 +232,41 @@ public class AlertGroupMapperTest { /** * create AlertGroups - * @param count create AlertGroup count + * + * @param count create AlertGroup count * @param groupName groupName * @return AlertGroup map */ - private Map createAlertGroups( - Integer count,String groupName){ - Map alertGroupMap = new HashMap<>(); + private Map createAlertGroups( + Integer count, String groupName) { + Map alertGroupMap = new HashMap<>(); - AlertGroup alertGroup = null; - for (int i = 0 ; i < count; i++){ + AlertGroup alertGroup = null; + for (int i = 0; i < count; i++) { alertGroup = createAlertGroup(groupName); - alertGroupMap.put(alertGroup.getId(),alertGroup); - } - - return alertGroupMap; - } - - - /** - * create AlertGroups - * @param count create AlertGroup count - * @return AlertGroup map - */ - private Map createAlertGroups( - Integer count){ - Map alertGroupMap = new HashMap<>(); - - AlertGroup alertGroup = null; - for (int i = 0 ; i < count; i++){ - alertGroup = createAlertGroup(); - alertGroupMap.put(alertGroup.getId(),alertGroup); + alertGroupMap.put(alertGroup.getId(), alertGroup); } return alertGroupMap; } - /** * create AlertGroups + * * @param count create AlertGroup count * @return AlertGroup map */ - private Map createAlertGroups( - Integer count,Integer userId){ - Map alertGroupMap = new HashMap<>(); + private Map createAlertGroups( + Integer count) { + Map alertGroupMap = new HashMap<>(); - AlertGroup alertGroup = null; - for (int i = 0 ; i < count; i++){ + AlertGroup alertGroup = null; + for (int i = 0; i < count; i++) { alertGroup = createAlertGroup(); - - createUserAlertGroup(userId,alertGroup.getId()); - - alertGroupMap.put(alertGroup.getId(),alertGroup); + alertGroupMap.put(alertGroup.getId(), alertGroup); } return alertGroupMap; } - /** - * create AlertGroup - * @param userId userId - * @param alertgroupId alertgroupId - * @return UserAlertGroup - */ - private UserAlertGroup createUserAlertGroup( - Integer userId,Integer alertgroupId){ - UserAlertGroup userAlertGroup = new UserAlertGroup(); - userAlertGroup.setAlertgroupId(alertgroupId); - userAlertGroup.setUserId(userId); - userAlertGroup.setCreateTime(DateUtils.getCurrentDate()); - userAlertGroup.setUpdateTime(DateUtils.getCurrentDate()); - - userAlertGroupMapper.insert(userAlertGroup); - - return userAlertGroup; - } - } \ No newline at end of file diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java index 24b9719a3e..63fcca2973 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import org.apache.dolphinscheduler.common.enums.AlertStatus; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.Alert; @@ -162,14 +161,10 @@ public class AlertMapperTest { */ private Alert createAlert(AlertStatus alertStatus) { Alert alert = new Alert(); - //alert.setShowType(ShowType.TABLE); alert.setTitle("test alert"); alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server down','warning level':'serious'}]"); - alert.setAlertType(AlertType.EMAIL); alert.setAlertStatus(alertStatus); alert.setLog("success"); - alert.setReceivers("aa@aa.com"); - alert.setReceiversCc("bb@aa.com"); alert.setCreateTime(DateUtils.getCurrentDate()); alert.setUpdateTime(DateUtils.getCurrentDate()); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java index 3fa5fcc56e..f2f39c6b96 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java @@ -17,7 +17,6 @@ package org.apache.dolphinscheduler.dao.mapper; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.AlertGroup; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; @@ -106,7 +105,6 @@ public class AlertPluginInstanceMapperTest { AlertGroup alertGroup = new AlertGroup(); alertGroup.setGroupName(groupName); alertGroup.setDescription("alert group 1"); - alertGroup.setGroupType(AlertType.EMAIL); alertGroup.setCreateTime(DateUtils.getCurrentDate()); alertGroup.setUpdateTime(DateUtils.getCurrentDate()); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java index c58c92b3bb..636a9ca958 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java @@ -77,8 +77,6 @@ public class ProcessDefinitionMapperTest { processDefinition.setUserId(101); processDefinition.setUpdateTime(new Date()); processDefinition.setCreateTime(new Date()); -// processDefinition.setGlobalParams("[{\"prop\":\"selenium_global_parameters_1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"selenium_global_parameters_value_1\"}]"); - processDefinitionMapper.insert(processDefinition); return processDefinition; } @@ -170,8 +168,6 @@ public class ProcessDefinitionMapperTest { processDefinition.setCreateTime(new Date()); processDefinition.setTenantId(tenant.getId()); processDefinition.setUserId(user.getId()); -// processDefinition.setGlobalParams("[{\"prop\":\"selenium_global_parameters_1\",\"direct\":\"IN\",\"type\":\"VARCHAR\",\"value\":\"selenium_global_parameters_value_1\"}]"); -// processDefinitionMapper.insert(processDefinition); ProcessDefinition processDefinition1 = processDefinitionMapper.queryByDefineName(project.getId(), "def 1"); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapperTest.java index e825e33847..938e26dd6c 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapperTest.java @@ -76,8 +76,6 @@ public class ProcessDefinitionVersionMapperTest { processDefinitionVersion.setCreateTime(new Date()); processDefinitionVersion.setLocations(StringUtils.EMPTY); processDefinitionVersion.setConnects(StringUtils.EMPTY); - processDefinitionVersion.setReceivers(StringUtils.EMPTY); - processDefinitionVersion.setReceiversCc(StringUtils.EMPTY); processDefinitionVersion.setTimeout(10); processDefinitionVersion.setResourceIds("1,2"); processDefinitionVersionMapper.insert(processDefinitionVersion); @@ -101,8 +99,6 @@ public class ProcessDefinitionVersionMapperTest { processDefinitionVersion.setCreateTime(new Date()); processDefinitionVersion.setLocations(StringUtils.EMPTY); processDefinitionVersion.setConnects(StringUtils.EMPTY); - processDefinitionVersion.setReceivers(StringUtils.EMPTY); - processDefinitionVersion.setReceiversCc(StringUtils.EMPTY); processDefinitionVersion.setTimeout(10); processDefinitionVersion.setResourceIds("1,2"); processDefinitionVersionMapper.insert(processDefinitionVersion); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapperTest.java deleted file mode 100644 index 2c5024f2ee..0000000000 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapperTest.java +++ /dev/null @@ -1,196 +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.dao.mapper; - - -import org.apache.dolphinscheduler.common.enums.AlertType; -import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.dao.entity.AlertGroup; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.entity.UserAlertGroup; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Date; -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest -@Transactional -@Rollback(true) -public class UserAlertGroupMapperTest { - - @Autowired - private UserMapper userMapper; - - @Autowired - AlertGroupMapper alertGroupMapper; - - @Autowired - private UserAlertGroupMapper userAlertGroupMapper; - - /** - * insert one UserAlertGroup - * @param user user - * @param alertGroup alertGroup - * @return UserAlertGroup - */ - private UserAlertGroup insertOne(User user,AlertGroup alertGroup){ - UserAlertGroup userAlertGroup = new UserAlertGroup(); - userAlertGroup.setAlertgroupName(alertGroup.getGroupName()); - userAlertGroup.setAlertgroupId(alertGroup.getId()); - userAlertGroup.setUserId(user.getId()); - userAlertGroup.setCreateTime(new Date()); - userAlertGroup.setUpdateTime(new Date()); - userAlertGroupMapper.insert(userAlertGroup); - return userAlertGroup; - } - - /** - * insert one UserAlertGroup - * @return UserAlertGroup - */ - private UserAlertGroup insertOne(){ - UserAlertGroup userAlertGroup = new UserAlertGroup(); - userAlertGroup.setAlertgroupName("dolphin_alert_group"); - userAlertGroup.setAlertgroupId(10); - userAlertGroup.setUserId(4); - userAlertGroup.setCreateTime(new Date()); - userAlertGroup.setUpdateTime(new Date()); - userAlertGroupMapper.insert(userAlertGroup); - return userAlertGroup; - } - - /** - * insert one user - * @return User - */ - private User insertOneUser(){ - User user = new User(); - user.setUserName("user1"); - user.setUserPassword("1"); - user.setEmail("xx@123.com"); - user.setUserType(UserType.GENERAL_USER); - user.setCreateTime(new Date()); - user.setTenantId(1); - user.setQueue("dolphin"); - user.setUpdateTime(new Date()); - userMapper.insert(user); - return user; - } - - /** - * insert one AlertGroup - * @return AlertGroup - */ - private AlertGroup insertOneAlertGroup(){ - //insertOne - AlertGroup alertGroup = new AlertGroup(); - alertGroup.setGroupName("alert group 1"); - alertGroup.setDescription("alert test1"); - alertGroup.setGroupType(AlertType.EMAIL); - - alertGroup.setCreateTime(new Date()); - alertGroup.setUpdateTime(new Date()); - alertGroupMapper.insert(alertGroup); - return alertGroup; - } - - /** - * test update - */ - @Test - public void testUpdate(){ - //insertOneUser - User user = insertOneUser(); - //insertOneAlertGroup - AlertGroup alertGroup = insertOneAlertGroup(); - - //insertOne - UserAlertGroup userAlertGroup = insertOne(); - //update - userAlertGroup.setUserId(user.getId()); - userAlertGroup.setAlertgroupId(alertGroup.getId()); - userAlertGroup.setUpdateTime(new Date()); - - int update = userAlertGroupMapper.updateById(userAlertGroup); - Assert.assertEquals(update, 1); - } - - /** - * test delete - */ - @Test - public void testDelete(){ - //insertOne - UserAlertGroup userAlertGroup = insertOne(); - //delete - int delete = userAlertGroupMapper.deleteById(userAlertGroup.getId()); - Assert.assertEquals(delete, 1); - } - - /** - * test query - */ - @Test - public void testQuery() { - //insertOne - UserAlertGroup userAlertGroup = insertOne(); - //query - List userAlertGroupList = userAlertGroupMapper.selectList(null); - Assert.assertNotEquals(userAlertGroupList.size(), 0); - } - - /** - * test delete by alertgroupId - */ - @Test - public void testDeleteByAlertgroupId() { - //insertOneUser - User user = insertOneUser(); - //insertOneAlertGroup - AlertGroup alertGroup = insertOneAlertGroup(); - - //insertOne - UserAlertGroup userAlertGroup = insertOne(user,alertGroup); - int delete = userAlertGroupMapper.deleteByAlertgroupId(alertGroup.getId()); - Assert.assertEquals(delete, 1); - } - - /** - * test list user by alertgroupId - */ - @Test - public void testListUserByAlertgroupId() { - //insertOneUser - User user = insertOneUser(); - //insertOneAlertGroup - AlertGroup alertGroup = insertOneAlertGroup(); - - //insertOne - UserAlertGroup userAlertGroup = insertOne(user,alertGroup); - List userList = userAlertGroupMapper.listUserByAlertgroupId(alertGroup.getId()); - Assert.assertNotEquals(userList.size(), 0); - - } -} \ No newline at end of file diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java index 7b1849ef4d..d037c441b4 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java @@ -14,14 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.dao.mapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.utils.DateUtils; -import org.apache.dolphinscheduler.dao.entity.*; +import org.apache.dolphinscheduler.dao.entity.AccessToken; +import org.apache.dolphinscheduler.dao.entity.AlertGroup; +import org.apache.dolphinscheduler.dao.entity.Queue; +import org.apache.dolphinscheduler.dao.entity.Tenant; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Date; +import java.util.List; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,8 +37,8 @@ import org.springframework.test.annotation.Rollback; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; -import java.util.List; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @RunWith(SpringRunner.class) @SpringBootTest @@ -45,9 +51,6 @@ public class UserMapperTest { @Autowired AlertGroupMapper alertGroupMapper; - @Autowired - private UserAlertGroupMapper userAlertGroupMapper; - @Autowired AccessTokenMapper accessTokenMapper; @@ -59,9 +62,10 @@ public class UserMapperTest { /** * insert one user + * * @return User */ - private User insertOne(){ + private User insertOne() { User user = new User(); user.setUserName("user1"); user.setUserPassword("1"); @@ -76,10 +80,11 @@ public class UserMapperTest { /** * insert one user + * * @param tenant tenant * @return User */ - private User insertOne(Tenant tenant){ + private User insertOne(Tenant tenant) { User user = new User(); user.setUserName("user1"); user.setUserPassword("1"); @@ -94,11 +99,12 @@ public class UserMapperTest { /** * insert one user - * @param queue queue + * + * @param queue queue * @param tenant tenant * @return User */ - private User insertOne(Queue queue,Tenant tenant){ + private User insertOne(Queue queue, Tenant tenant) { User user = new User(); user.setUserName("user1"); user.setUserPassword("1"); @@ -114,14 +120,14 @@ public class UserMapperTest { /** * insert one AlertGroup + * * @return AlertGroup */ - private AlertGroup insertOneAlertGroup(){ + private AlertGroup insertOneAlertGroup() { //insertOne AlertGroup alertGroup = new AlertGroup(); alertGroup.setGroupName("alert group 1"); alertGroup.setDescription("alert test1"); - alertGroup.setGroupType(AlertType.EMAIL); alertGroup.setCreateTime(new Date()); alertGroup.setUpdateTime(new Date()); @@ -129,45 +135,30 @@ public class UserMapperTest { return alertGroup; } - /** - * insert one UserAlertGroup - * @param user user - * @param alertGroup alertGroup - * @return UserAlertGroup - */ - private UserAlertGroup insertOneUserAlertGroup(User user,AlertGroup alertGroup){ - UserAlertGroup userAlertGroup = new UserAlertGroup(); - userAlertGroup.setAlertgroupName(alertGroup.getGroupName()); - userAlertGroup.setAlertgroupId(alertGroup.getId()); - userAlertGroup.setUserId(user.getId()); - userAlertGroup.setCreateTime(new Date()); - userAlertGroup.setUpdateTime(new Date()); - userAlertGroupMapper.insert(userAlertGroup); - return userAlertGroup; - } - /** * insert one AccessToken + * * @param user user * @return AccessToken */ - private AccessToken insertOneAccessToken(User user){ + private AccessToken insertOneAccessToken(User user) { //insertOne AccessToken accessToken = new AccessToken(); accessToken.setUserId(user.getId()); accessToken.setToken("secrettoken"); accessToken.setCreateTime(new Date()); accessToken.setUpdateTime(new Date()); - accessToken.setExpireTime(DateUtils.getSomeHourOfDay(new Date(),1)); + accessToken.setExpireTime(DateUtils.getSomeHourOfDay(new Date(), 1)); accessTokenMapper.insert(accessToken); return accessToken; } /** * insert one Tenant + * * @return Tenant */ - private Tenant insertOneTenant(){ + private Tenant insertOneTenant() { Tenant tenant = new Tenant(); tenant.setTenantCode("dolphin"); tenant.setTenantName("dolphin test"); @@ -181,9 +172,10 @@ public class UserMapperTest { /** * insert one Tenant + * * @return Tenant */ - private Tenant insertOneTenant(Queue queue){ + private Tenant insertOneTenant(Queue queue) { Tenant tenant = new Tenant(); tenant.setTenantCode("dolphin"); tenant.setTenantName("dolphin test"); @@ -198,9 +190,10 @@ public class UserMapperTest { /** * insert one Queue + * * @return Queue */ - private Queue insertOneQueue(){ + private Queue insertOneQueue() { Queue queue = new Queue(); queue.setQueue("dolphin"); queue.setQueueName("dolphin queue"); @@ -214,7 +207,7 @@ public class UserMapperTest { * test update */ @Test - public void testUpdate(){ + public void testUpdate() { //insertOne User user = insertOne(); //update @@ -229,7 +222,7 @@ public class UserMapperTest { * test delete */ @Test - public void testDelete(){ + public void testDelete() { //insertOne User user = insertOne(); //delete @@ -261,30 +254,6 @@ public class UserMapperTest { Assert.assertNotEquals(userList.size(), 0); } -// /** -// * test query by username -// */ -// @Test -// public void testQueryByUserNameAccurately() { -// //insertOne -// User user = insertOne(); -// //queryByUserNameAccurately -// User queryUser = userMapper.queryByUserNameAccurately(user.getUserName()); -// Assert.assertEquals(queryUser.getUserName(), user.getUserName()); -// } - -// /** -// * test query by username and password -// */ -// @Test -// public void testQueryUserByNamePassword() { -// //insertOne -// User user = insertOne(); -// //queryUserByNamePassword -// User queryUser = userMapper.queryUserByNamePassword(user.getUserName(),user.getUserPassword()); -// Assert.assertEquals(queryUser.getUserName(),user.getUserName()); -// Assert.assertEquals(queryUser.getUserPassword(), user.getUserPassword()); -// } /** * test page @@ -296,9 +265,9 @@ public class UserMapperTest { //insertOneTenant Tenant tenant = insertOneTenant(); //insertOne - User user = insertOne(queue,tenant); + User user = insertOne(queue, tenant); //queryUserPaging - Page page = new Page(1,3); + Page page = new Page(1, 3); IPage userIPage = userMapper.queryUserPaging(page, user.getUserName()); Assert.assertNotEquals(userIPage.getTotal(), 0); } @@ -311,29 +280,12 @@ public class UserMapperTest { //insertOneQueue and insertOneTenant Queue queue = insertOneQueue(); Tenant tenant = insertOneTenant(queue); - User user = insertOne(queue,tenant); + User user = insertOne(queue, tenant); //queryDetailsById User queryUser = userMapper.queryDetailsById(user.getId()); Assert.assertEquals(user.getUserName(), queryUser.getUserName()); } - /** - * test query user list by alertgroupId - */ - @Test - public void testQueryUserListByAlertGroupId() { - //insertOne - User user = insertOne(); - //insertOneAlertGroup - AlertGroup alertGroup = insertOneAlertGroup(); - //insertOneUserAlertGroup - UserAlertGroup userAlertGroup = insertOneUserAlertGroup(user, alertGroup); - //queryUserListByAlertGroupId - List userList = userMapper.queryUserListByAlertGroupId(userAlertGroup.getAlertgroupId()); - Assert.assertNotEquals(userList.size(), 0); - - } - /** * test query tenant code by userId */ @@ -345,7 +297,7 @@ public class UserMapperTest { User user = insertOne(tenant); //queryTenantCodeByUserId User queryUser = userMapper.queryTenantCodeByUserId(user.getId()); - Assert.assertEquals(queryUser,user); + Assert.assertEquals(queryUser, user); } /** @@ -359,7 +311,7 @@ public class UserMapperTest { AccessToken accessToken = insertOneAccessToken(user); //queryUserByToken User userToken = userMapper.queryUserByToken(accessToken.getToken()); - Assert.assertEquals(userToken,user); + Assert.assertEquals(userToken, user); } } diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java index 72ee0fcb89..b55ecbb762 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dolphinscheduler.server.master.runner; +package org.apache.dolphinscheduler.server.master.runner; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.ExecutionStatus; @@ -42,7 +42,6 @@ import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import java.util.Date; import java.util.Set; - /** * master task exec thread */ @@ -64,9 +63,10 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { /** * constructor of MasterTaskExecThread - * @param taskInstance task instance + * + * @param taskInstance task instance */ - public MasterTaskExecThread(TaskInstance taskInstance){ + public MasterTaskExecThread(TaskInstance taskInstance) { super(taskInstance); this.taskInstanceCacheManager = SpringApplicationContext.getBean(TaskInstanceCacheManagerImpl.class); this.nettyExecutorManager = SpringApplicationContext.getBean(NettyExecutorManager.class); @@ -75,10 +75,11 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { /** * get task instance + * * @return TaskInstance */ @Override - public TaskInstance getTaskInstance(){ + public TaskInstance getTaskInstance() { return this.taskInstance; } @@ -96,70 +97,70 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { public Boolean submitWaitComplete() { Boolean result = false; this.taskInstance = submit(); - if(this.taskInstance == null){ + if (this.taskInstance == null) { logger.error("submit task instance to mysql and queue failed , please check and fix it"); return result; } - if(!this.taskInstance.getState().typeIsFinished()) { + if (!this.taskInstance.getState().typeIsFinished()) { result = waitTaskQuit(); } taskInstance.setEndTime(new Date()); processService.updateTaskInstance(taskInstance); logger.info("task :{} id:{}, process id:{}, exec thread completed ", - this.taskInstance.getName(),taskInstance.getId(), processInstance.getId() ); + this.taskInstance.getName(), taskInstance.getId(), processInstance.getId()); return result; } /** * polling db - * + *

* wait task quit + * * @return true if task quit success */ - public Boolean waitTaskQuit(){ + public Boolean waitTaskQuit() { // query new state taskInstance = processService.findTaskInstanceById(taskInstance.getId()); logger.info("wait task: process id: {}, task id:{}, task name:{} complete", - this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName()); + this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName()); // task time out boolean checkTimeout = false; TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter(); - if(taskTimeoutParameter.getEnable()){ + if (taskTimeoutParameter.getEnable()) { TaskTimeoutStrategy strategy = taskTimeoutParameter.getStrategy(); - if(strategy == TaskTimeoutStrategy.WARN || strategy == TaskTimeoutStrategy.WARNFAILED){ + if (strategy == TaskTimeoutStrategy.WARN || strategy == TaskTimeoutStrategy.WARNFAILED) { checkTimeout = true; } } - while (Stopper.isRunning()){ + while (Stopper.isRunning()) { try { - if(this.processInstance == null){ + if (this.processInstance == null) { logger.error("process instance not exists , master task exec thread exit"); return true; } // task instance add queue , waiting worker to kill - if(this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP){ + if (this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP) { cancelTaskInstance(); } - if(processInstance.getState() == ExecutionStatus.READY_PAUSE){ + if (processInstance.getState() == ExecutionStatus.READY_PAUSE) { pauseTask(); } // task instance finished - if (taskInstance.getState().typeIsFinished()){ + if (taskInstance.getState().typeIsFinished()) { // if task is final result , then remove taskInstance from cache taskInstanceCacheManager.removeByTaskInstanceId(taskInstance.getId()); break; } - if(checkTimeout){ + if (checkTimeout) { long remainTime = DateUtils.getRemainTime(taskInstance.getStartTime(), taskTimeoutParameter.getInterval() * 60L); if (remainTime < 0) { - logger.warn("task id: {} execution time out",taskInstance.getId()); + logger.warn("task id: {} execution time out", taskInstance.getId()); // process define ProcessDefinition processDefine = processService.findProcessDefineById(processInstance.getProcessDefinitionId()); // send warn mail - alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(),processDefine.getReceivers(), - processDefine.getReceiversCc(), processInstance.getId(), processInstance.getName(), - taskInstance.getId(),taskInstance.getName()); + alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(), processInstance.getId(), processInstance.getName(), + taskInstance.getId(), taskInstance.getName()); checkTimeout = false; } } @@ -168,10 +169,10 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { processInstance = processService.findProcessInstanceById(processInstance.getId()); Thread.sleep(Constants.SLEEP_TIME_MILLIS); } catch (Exception e) { - logger.error("exception",e); + logger.error("exception", e); if (processInstance != null) { logger.error("wait task quit failed, instance id:{}, task id:{}", - processInstance.getId(), taskInstance.getId()); + processInstance.getId(), taskInstance.getId()); } } } @@ -180,31 +181,29 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { /** * pause task if task have not been dispatched to worker, do not dispatch anymore. - * */ public void pauseTask() { taskInstance = processService.findTaskInstanceById(taskInstance.getId()); - if(taskInstance == null){ + if (taskInstance == null) { return; } - if(StringUtils.isBlank(taskInstance.getHost())){ + if (StringUtils.isBlank(taskInstance.getHost())) { taskInstance.setState(ExecutionStatus.PAUSE); taskInstance.setEndTime(new Date()); processService.updateTaskInstance(taskInstance); } } - /** - * task instance add queue , waiting worker to kill + * task instance add queue , waiting worker to kill */ - private void cancelTaskInstance() throws Exception{ - if(alreadyKilled){ + private void cancelTaskInstance() throws Exception { + if (alreadyKilled) { return; } alreadyKilled = true; taskInstance = processService.findTaskInstanceById(taskInstance.getId()); - if(StringUtils.isBlank(taskInstance.getHost())){ + if (StringUtils.isBlank(taskInstance.getHost())) { taskInstance.setState(ExecutionStatus.KILL); taskInstance.setEndTime(new Date()); processService.updateTaskInstance(taskInstance); @@ -222,23 +221,24 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { nettyExecutorManager.executeDirectly(executionContext); logger.info("master kill taskInstance name :{} taskInstance id:{}", - taskInstance.getName(), taskInstance.getId() ); + taskInstance.getName(), taskInstance.getId()); } /** * whether exists valid worker group + * * @param taskInstanceWorkerGroup taskInstanceWorkerGroup * @return whether exists */ - public Boolean existsValidWorkerGroup(String taskInstanceWorkerGroup){ + public Boolean existsValidWorkerGroup(String taskInstanceWorkerGroup) { Set workerGroups = zookeeperRegistryCenter.getWorkerGroupDirectly(); // not worker group - if (CollectionUtils.isEmpty(workerGroups)){ + if (CollectionUtils.isEmpty(workerGroups)) { return false; } // has worker group , but not taskInstance assigned worker group - if (!workerGroups.contains(taskInstanceWorkerGroup)){ + if (!workerGroups.contains(taskInstanceWorkerGroup)) { return false; } Set workers = zookeeperRegistryCenter.getWorkerGroupNodesDirectly(taskInstanceWorkerGroup); @@ -250,9 +250,10 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread { /** * get task timeout parameter + * * @return TaskTimeoutParameter */ - private TaskTimeoutParameter getTaskTimeoutParameter(){ + private TaskTimeoutParameter getTaskTimeoutParameter() { String taskJson = taskInstance.getTaskJson(); TaskNode taskNode = JSONUtils.parseObject(taskJson, TaskNode.class); return taskNode.getTaskTimeoutParameter(); diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/AlertManager.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/AlertManager.java index 073c0750b2..f1d351de15 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/AlertManager.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/AlertManager.java @@ -17,7 +17,6 @@ package org.apache.dolphinscheduler.server.utils; -import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -28,7 +27,6 @@ import org.apache.dolphinscheduler.dao.entity.ProcessAlertContent; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance; -import org.apache.dolphinscheduler.spi.alert.ShowType; import java.util.ArrayList; import java.util.Date; @@ -171,14 +169,10 @@ public class AlertManager { try { Alert alert = new Alert(); alert.setTitle("worker fault tolerance"); - //alert.setShowType(ShowType.TABLE); String content = getWorkerToleranceContent(processInstance, toleranceTaskList); alert.setContent(content); - alert.setAlertType(AlertType.EMAIL); alert.setCreateTime(new Date()); alert.setAlertGroupId(processInstance.getWarningGroupId() == null ? 1 : processInstance.getWarningGroupId()); - alert.setReceivers(processInstance.getProcessDefinition().getReceivers()); - alert.setReceiversCc(processInstance.getProcessDefinition().getReceiversCc()); alertDao.addAlert(alert); logger.info("add alert to db , alert : {}", alert.toString()); @@ -225,16 +219,10 @@ public class AlertManager { String cmdName = getCommandCnName(processInstance.getCommandType()); String success = processInstance.getState().typeIsSuccess() ? "success" : "failed"; alert.setTitle(cmdName + " " + success); - ShowType showType = processInstance.getState().typeIsSuccess() ? ShowType.TEXT : ShowType.TABLE; - //alert.setShowType(showType); String content = getContentProcessInstance(processInstance, taskInstances); alert.setContent(content); - alert.setAlertType(AlertType.EMAIL); alert.setAlertGroupId(processInstance.getWarningGroupId()); alert.setCreateTime(new Date()); - alert.setReceivers(processInstance.getProcessDefinition().getReceivers()); - alert.setReceiversCc(processInstance.getProcessDefinition().getReceiversCc()); - alertDao.addAlert(alert); logger.info("add alert to db , alert: {}", alert.toString()); } diff --git a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java index 4d7b50f9ca..d51d64d68d 100644 --- a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java +++ b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/registry/DependencyConfig.java @@ -34,7 +34,6 @@ import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; -import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl; import org.apache.dolphinscheduler.server.master.config.MasterConfig; @@ -66,11 +65,6 @@ public class DependencyConfig { return Mockito.mock(AlertMapper.class); } - @Bean - public UserAlertGroupMapper userAlertGroupMapper() { - return Mockito.mock(UserAlertGroupMapper.class); - } - @Bean public TaskInstanceCacheManagerImpl taskInstanceCacheManagerImpl() { return Mockito.mock(TaskInstanceCacheManagerImpl.class); @@ -136,7 +130,6 @@ public class DependencyConfig { return Mockito.mock(ResourceMapper.class); } - @Bean public ErrorCommandMapper errorCommandMapper() { return Mockito.mock(ErrorCommandMapper.class); diff --git a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskCallbackServiceTestConfig.java b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskCallbackServiceTestConfig.java index 8bdc07bae2..224764c882 100644 --- a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskCallbackServiceTestConfig.java +++ b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskCallbackServiceTestConfig.java @@ -34,7 +34,6 @@ import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; -import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheManagerImpl; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -49,7 +48,6 @@ import org.springframework.context.annotation.Configuration; @Configuration public class TaskCallbackServiceTestConfig { - @Bean public AlertDao alertDao() { return new AlertDao(); @@ -60,11 +58,6 @@ public class TaskCallbackServiceTestConfig { return Mockito.mock(AlertMapper.class); } - @Bean - public UserAlertGroupMapper userAlertGroupMapper() { - return Mockito.mock(UserAlertGroupMapper.class); - } - @Bean public TaskInstanceCacheManagerImpl taskInstanceCacheManagerImpl() { return Mockito.mock(TaskInstanceCacheManagerImpl.class); @@ -125,7 +118,6 @@ public class TaskCallbackServiceTestConfig { return Mockito.mock(ResourceMapper.class); } - @Bean public ErrorCommandMapper errorCommandMapper() { return Mockito.mock(ErrorCommandMapper.class); diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index 7fca37470d..5dde6d8ce7 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.service.process; import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_COMPLEMENT_DATA_END_DATE; @@ -108,11 +109,11 @@ public class ProcessService { private final Logger logger = LoggerFactory.getLogger(getClass()); - private final int[] stateArray = new int[]{ExecutionStatus.SUBMITTED_SUCCESS.ordinal(), - ExecutionStatus.RUNNING_EXECUTION.ordinal(), - ExecutionStatus.DELAY_EXECUTION.ordinal(), - ExecutionStatus.READY_PAUSE.ordinal(), - ExecutionStatus.READY_STOP.ordinal()}; + private final int[] stateArray = new int[] {ExecutionStatus.SUBMITTED_SUCCESS.ordinal(), + ExecutionStatus.RUNNING_EXECUTION.ordinal(), + ExecutionStatus.DELAY_EXECUTION.ordinal(), + ExecutionStatus.READY_PAUSE.ordinal(), + ExecutionStatus.READY_STOP.ordinal()}; @Autowired private UserMapper userMapper; @@ -145,7 +146,6 @@ public class ProcessService { private ResourceMapper resourceMapper; - @Autowired private ErrorCommandMapper errorCommandMapper; @@ -153,26 +153,27 @@ public class ProcessService { private TenantMapper tenantMapper; @Autowired - private ProjectMapper projectMapper; + private ProjectMapper projectMapper; /** * handle Command (construct ProcessInstance from Command) , wrapped in transaction - * @param logger logger - * @param host host + * + * @param logger logger + * @param host host * @param validThreadNum validThreadNum - * @param command found command + * @param command found command * @return process instance */ @Transactional(rollbackFor = RuntimeException.class) public ProcessInstance handleCommand(Logger logger, String host, int validThreadNum, Command command) { ProcessInstance processInstance = constructProcessInstance(command, host); //cannot construct process instance, return null; - if(processInstance == null){ + if (processInstance == null) { logger.error("scan command, command parameter is error: {}", command); moveToErrorCommand(command, "process instance is null"); return null; } - if(!checkThreadNum(command, validThreadNum)){ + if (!checkThreadNum(command, validThreadNum)) { logger.info("there is not enough thread for this command: {}", command); return setWaitingThreadProcess(command, processInstance); } @@ -186,6 +187,7 @@ public class ProcessService { /** * save error command, and delete original command + * * @param command command * @param message message */ @@ -198,13 +200,14 @@ public class ProcessService { /** * set process waiting thread - * @param command command + * + * @param command command * @param processInstance processInstance * @return process instance */ private ProcessInstance setWaitingThreadProcess(Command command, ProcessInstance processInstance) { processInstance.setState(ExecutionStatus.WAITTING_THREAD); - if(command.getCommandType() != CommandType.RECOVER_WAITTING_THREAD){ + if (command.getCommandType() != CommandType.RECOVER_WAITTING_THREAD) { processInstance.addHistoryCmd(command.getCommandType()); } saveProcessInstance(processInstance); @@ -215,7 +218,8 @@ public class ProcessService { /** * check thread num - * @param command command + * + * @param command command * @param validThreadNum validThreadNum * @return if thread is enough */ @@ -226,12 +230,13 @@ public class ProcessService { /** * insert one command + * * @param command command * @return create result */ public int createCommand(Command command) { int result = 0; - if (command != null){ + if (command != null) { result = commandMapper.insert(command); } return result; @@ -239,59 +244,63 @@ public class ProcessService { /** * find one command from queue list + * * @return command */ - public Command findOneCommand(){ + public Command findOneCommand() { return commandMapper.getOneToRun(); } /** * check the input command exists in queue list + * * @param command command * @return create command result */ - public Boolean verifyIsNeedCreateCommand(Command command){ + public Boolean verifyIsNeedCreateCommand(Command command) { Boolean isNeedCreate = true; - Map cmdTypeMap = new HashMap(); - cmdTypeMap.put(CommandType.REPEAT_RUNNING,1); - cmdTypeMap.put(CommandType.RECOVER_SUSPENDED_PROCESS,1); - cmdTypeMap.put(CommandType.START_FAILURE_TASK_PROCESS,1); + Map cmdTypeMap = new HashMap(); + cmdTypeMap.put(CommandType.REPEAT_RUNNING, 1); + cmdTypeMap.put(CommandType.RECOVER_SUSPENDED_PROCESS, 1); + cmdTypeMap.put(CommandType.START_FAILURE_TASK_PROCESS, 1); CommandType commandType = command.getCommandType(); - if(cmdTypeMap.containsKey(commandType)){ + if (cmdTypeMap.containsKey(commandType)) { ObjectNode cmdParamObj = JSONUtils.parseObject(command.getCommandParam()); int processInstanceId = cmdParamObj.path(CMDPARAM_RECOVER_PROCESS_ID_STRING).asInt(); List commands = commandMapper.selectList(null); // for all commands - for (Command tmpCommand:commands){ - if(cmdTypeMap.containsKey(tmpCommand.getCommandType())){ + for (Command tmpCommand : commands) { + if (cmdTypeMap.containsKey(tmpCommand.getCommandType())) { ObjectNode tempObj = JSONUtils.parseObject(tmpCommand.getCommandParam()); - if(tempObj != null && processInstanceId == tempObj.path(CMDPARAM_RECOVER_PROCESS_ID_STRING).asInt()){ + if (tempObj != null && processInstanceId == tempObj.path(CMDPARAM_RECOVER_PROCESS_ID_STRING).asInt()) { isNeedCreate = false; break; } } } } - return isNeedCreate; + return isNeedCreate; } /** * find process instance detail by id + * * @param processId processId * @return process instance */ - public ProcessInstance findProcessInstanceDetailById(int processId){ + public ProcessInstance findProcessInstanceDetailById(int processId) { return processInstanceMapper.queryDetailById(processId); } /** * get task node list by definitionId + * * @param defineId * @return */ - public List getTaskNodeListByDefinitionId(Integer defineId){ + public List getTaskNodeListByDefinitionId(Integer defineId) { ProcessDefinition processDefinition = processDefineMapper.selectById(defineId); if (processDefinition == null) { logger.info("process define not exists"); @@ -312,15 +321,17 @@ public class ProcessService { /** * find process instance by id + * * @param processId processId * @return process instance */ - public ProcessInstance findProcessInstanceById(int processId){ + public ProcessInstance findProcessInstanceById(int processId) { return processInstanceMapper.selectById(processId); } /** * find process define by id. + * * @param processDefinitionId processDefinitionId * @return process definition */ @@ -330,23 +341,25 @@ public class ProcessService { /** * delete work process instance by id + * * @param processInstanceId processInstanceId * @return delete process instance result */ - public int deleteWorkProcessInstanceById(int processInstanceId){ + public int deleteWorkProcessInstanceById(int processInstanceId) { return processInstanceMapper.deleteById(processInstanceId); } /** * delete all sub process by parent instance id + * * @param processInstanceId processInstanceId * @return delete all sub process instance result */ - public int deleteAllSubWorkProcessByParentId(int processInstanceId){ + public int deleteAllSubWorkProcessByParentId(int processInstanceId) { List subProcessIdList = processInstanceMapMapper.querySubIdListByParentId(processInstanceId); - for(Integer subId : subProcessIdList){ + for (Integer subId : subProcessIdList) { deleteAllSubWorkProcessByParentId(subId); deleteWorkProcessMapByParentId(subId); removeTaskLogFile(subId); @@ -355,59 +368,58 @@ public class ProcessService { return 1; } - /** * remove task log file + * * @param processInstanceId processInstanceId */ - public void removeTaskLogFile(Integer processInstanceId){ + public void removeTaskLogFile(Integer processInstanceId) { LogClientService logClient = new LogClientService(); List taskInstanceList = findValidTaskListByProcessId(processInstanceId); - if (CollectionUtils.isEmpty(taskInstanceList)){ + if (CollectionUtils.isEmpty(taskInstanceList)) { return; } - for (TaskInstance taskInstance : taskInstanceList){ + for (TaskInstance taskInstance : taskInstanceList) { String taskLogPath = taskInstance.getLogPath(); - if (StringUtils.isEmpty(taskInstance.getHost())){ + if (StringUtils.isEmpty(taskInstance.getHost())) { continue; } int port = Constants.RPC_PORT; String ip = ""; try { ip = Host.of(taskInstance.getHost()).getIp(); - }catch (Exception e){ + } catch (Exception e) { // compatible old version ip = taskInstance.getHost(); } - - // remove task log from loggerserver - logClient.removeTaskLog(ip,port,taskLogPath); + logClient.removeTaskLog(ip, port, taskLogPath); } } - /** * calculate sub process number in the process define. + * * @param processDefinitionId processDefinitionId * @return process thread num count */ - private Integer workProcessThreadNumCount(Integer processDefinitionId){ + private Integer workProcessThreadNumCount(Integer processDefinitionId) { List ids = new ArrayList<>(); recurseFindSubProcessId(processDefinitionId, ids); - return ids.size()+1; + return ids.size() + 1; } /** * recursive query sub process definition id by parent id. + * * @param parentId parentId - * @param ids ids + * @param ids ids */ - public void recurseFindSubProcessId(int parentId, List ids){ + public void recurseFindSubProcessId(int parentId, List ids) { ProcessDefinition processDefinition = processDefineMapper.selectById(parentId); String processDefinitionJson = processDefinition.getProcessDefinitionJson(); @@ -415,15 +427,15 @@ public class ProcessService { List taskNodeList = processData.getTasks(); - if (taskNodeList != null && taskNodeList.size() > 0){ + if (taskNodeList != null && taskNodeList.size() > 0) { - for (TaskNode taskNode : taskNodeList){ + for (TaskNode taskNode : taskNodeList) { String parameter = taskNode.getParams(); ObjectNode parameterJson = JSONUtils.parseObject(parameter); - if (parameterJson.get(CMDPARAM_SUB_PROCESS_DEFINE_ID) != null){ + if (parameterJson.get(CMDPARAM_SUB_PROCESS_DEFINE_ID) != null) { SubProcessParameters subProcessParam = JSONUtils.parseObject(parameter, SubProcessParameters.class); ids.add(subProcessParam.getProcessDefinitionId()); - recurseFindSubProcessId(subProcessParam.getProcessDefinitionId(),ids); + recurseFindSubProcessId(subProcessParam.getProcessDefinitionId(), ids); } } @@ -435,14 +447,15 @@ public class ProcessService { * sub work process instance need not to create recovery command. * create recovery waiting thread command and delete origin command at the same time. * if the recovery command is exists, only update the field update_time - * @param originCommand originCommand + * + * @param originCommand originCommand * @param processInstance processInstance */ public void createRecoveryWaitingThreadCommand(Command originCommand, ProcessInstance processInstance) { // sub process doesnot need to create wait command - if(processInstance.getIsSubProcess() == Flag.YES){ - if(originCommand != null){ + if (processInstance.getIsSubProcess() == Flag.YES) { + if (originCommand != null) { commandMapper.deleteById(originCommand.getId()); } return; @@ -450,28 +463,28 @@ public class ProcessService { Map cmdParam = new HashMap<>(); cmdParam.put(Constants.CMDPARAM_RECOVERY_WAITTING_THREAD, String.valueOf(processInstance.getId())); // process instance quit by "waiting thread" state - if(originCommand == null){ + if (originCommand == null) { Command command = new Command( - CommandType.RECOVER_WAITTING_THREAD, - processInstance.getTaskDependType(), - processInstance.getFailureStrategy(), - processInstance.getExecutorId(), - processInstance.getProcessDefinitionId(), - JSONUtils.toJsonString(cmdParam), - processInstance.getWarningType(), - processInstance.getWarningGroupId(), - processInstance.getScheduleTime(), - processInstance.getProcessInstancePriority() + CommandType.RECOVER_WAITTING_THREAD, + processInstance.getTaskDependType(), + processInstance.getFailureStrategy(), + processInstance.getExecutorId(), + processInstance.getProcessDefinitionId(), + JSONUtils.toJsonString(cmdParam), + processInstance.getWarningType(), + processInstance.getWarningGroupId(), + processInstance.getScheduleTime(), + processInstance.getProcessInstancePriority() ); saveCommand(command); - return ; + return; } // update the command time if current command if recover from waiting - if(originCommand.getCommandType() == CommandType.RECOVER_WAITTING_THREAD){ + if (originCommand.getCommandType() == CommandType.RECOVER_WAITTING_THREAD) { originCommand.setUpdateTime(new Date()); saveCommand(originCommand); - }else{ + } else { // delete old command and create new waiting thread command commandMapper.deleteById(originCommand.getId()); originCommand.setId(0); @@ -485,14 +498,15 @@ public class ProcessService { /** * get schedule time from command - * @param command command + * + * @param command command * @param cmdParam cmdParam map * @return date */ - private Date getScheduleTime(Command command, Map cmdParam){ + private Date getScheduleTime(Command command, Map cmdParam) { Date scheduleTime = command.getScheduleTime(); - if(scheduleTime == null){ - if(cmdParam != null && cmdParam.containsKey(CMDPARAM_COMPLEMENT_DATA_START_DATE)){ + if (scheduleTime == null) { + if (cmdParam != null && cmdParam.containsKey(CMDPARAM_COMPLEMENT_DATA_START_DATE)) { scheduleTime = DateUtils.stringToDate(cmdParam.get(CMDPARAM_COMPLEMENT_DATA_START_DATE)); } } @@ -501,14 +515,15 @@ public class ProcessService { /** * generate a new work process instance from command. + * * @param processDefinition processDefinition - * @param command command - * @param cmdParam cmdParam map + * @param command command + * @param cmdParam cmdParam map * @return process instance */ private ProcessInstance generateNewProcessInstance(ProcessDefinition processDefinition, Command command, - Map cmdParam){ + Map cmdParam) { ProcessInstance processInstance = new ProcessInstance(processDefinition); processInstance.setState(ExecutionStatus.RUNNING_EXECUTION); processInstance.setRecovery(Flag.NO); @@ -529,7 +544,7 @@ public class ProcessService { // schedule time Date scheduleTime = getScheduleTime(command, cmdParam); - if(scheduleTime != null){ + if (scheduleTime != null) { processInstance.setScheduleTime(scheduleTime); } processInstance.setCommandStartTime(command.getStartTime()); @@ -537,10 +552,10 @@ public class ProcessService { processInstance.setConnects(processDefinition.getConnects()); // curing global params processInstance.setGlobalParams(ParameterUtils.curingGlobalParams( - processDefinition.getGlobalParamMap(), - processDefinition.getGlobalParamList(), - getCommandTypeIfComplement(processInstance, command), - processInstance.getScheduleTime())); + processDefinition.getGlobalParamMap(), + processDefinition.getGlobalParamList(), + getCommandTypeIfComplement(processInstance, command), + processInstance.getScheduleTime())); //copy process define json to process instance processInstance.setProcessInstanceJson(processDefinition.getProcessDefinitionJson()); @@ -558,21 +573,22 @@ public class ProcessService { * there is tenant id in definition, use the tenant of the definition. * if there is not tenant id in the definiton or the tenant not exist * use definition creator's tenant. + * * @param tenantId tenantId - * @param userId userId + * @param userId userId * @return tenant */ - public Tenant getTenantForProcess(int tenantId, int userId){ + public Tenant getTenantForProcess(int tenantId, int userId) { Tenant tenant = null; - if(tenantId >= 0){ + if (tenantId >= 0) { tenant = tenantMapper.queryById(tenantId); } - if (userId == 0){ + if (userId == 0) { return null; } - if(tenant == null){ + if (tenant == null) { User user = userMapper.selectById(userId); tenant = tenantMapper.queryById(user.getTenantId()); } @@ -581,15 +597,16 @@ public class ProcessService { /** * check command parameters is valid - * @param command command + * + * @param command command * @param cmdParam cmdParam map * @return whether command param is valid */ - private Boolean checkCmdParam(Command command, Map cmdParam){ - if(command.getTaskDependType() == TaskDependType.TASK_ONLY || command.getTaskDependType()== TaskDependType.TASK_PRE){ - if(cmdParam == null - || !cmdParam.containsKey(Constants.CMDPARAM_START_NODE_NAMES) - || cmdParam.get(Constants.CMDPARAM_START_NODE_NAMES).isEmpty()){ + private Boolean checkCmdParam(Command command, Map cmdParam) { + if (command.getTaskDependType() == TaskDependType.TASK_ONLY || command.getTaskDependType() == TaskDependType.TASK_PRE) { + if (cmdParam == null + || !cmdParam.containsKey(Constants.CMDPARAM_START_NODE_NAMES) + || cmdParam.get(Constants.CMDPARAM_START_NODE_NAMES).isEmpty()) { logger.error("command node depend type is {}, but start nodes is null ", command.getTaskDependType()); return false; } @@ -599,82 +616,83 @@ public class ProcessService { /** * construct process instance according to one command. + * * @param command command - * @param host host + * @param host host * @return process instance */ - private ProcessInstance constructProcessInstance(Command command, String host){ + private ProcessInstance constructProcessInstance(Command command, String host) { ProcessInstance processInstance = null; CommandType commandType = command.getCommandType(); Map cmdParam = JSONUtils.toMap(command.getCommandParam()); ProcessDefinition processDefinition = null; - if(command.getProcessDefinitionId() != 0){ + if (command.getProcessDefinitionId() != 0) { processDefinition = processDefineMapper.selectById(command.getProcessDefinitionId()); - if(processDefinition == null){ + if (processDefinition == null) { logger.error("cannot find the work process define! define id : {}", command.getProcessDefinitionId()); return null; } } - if(cmdParam != null ){ + if (cmdParam != null) { Integer processInstanceId = 0; // recover from failure or pause tasks - if(cmdParam.containsKey(Constants.CMDPARAM_RECOVER_PROCESS_ID_STRING)) { + if (cmdParam.containsKey(Constants.CMDPARAM_RECOVER_PROCESS_ID_STRING)) { String processId = cmdParam.get(Constants.CMDPARAM_RECOVER_PROCESS_ID_STRING); processInstanceId = Integer.parseInt(processId); if (processInstanceId == 0) { logger.error("command parameter is error, [ ProcessInstanceId ] is 0"); return null; } - }else if(cmdParam.containsKey(Constants.CMDPARAM_SUB_PROCESS)){ + } else if (cmdParam.containsKey(Constants.CMDPARAM_SUB_PROCESS)) { // sub process map String pId = cmdParam.get(Constants.CMDPARAM_SUB_PROCESS); processInstanceId = Integer.parseInt(pId); - }else if(cmdParam.containsKey(Constants.CMDPARAM_RECOVERY_WAITTING_THREAD)){ + } else if (cmdParam.containsKey(Constants.CMDPARAM_RECOVERY_WAITTING_THREAD)) { // waiting thread command String pId = cmdParam.get(Constants.CMDPARAM_RECOVERY_WAITTING_THREAD); processInstanceId = Integer.parseInt(pId); } - if(processInstanceId ==0){ + if (processInstanceId == 0) { processInstance = generateNewProcessInstance(processDefinition, command, cmdParam); - }else{ + } else { processInstance = this.findProcessInstanceDetailById(processInstanceId); } processDefinition = processDefineMapper.selectById(processInstance.getProcessDefinitionId()); processInstance.setProcessDefinition(processDefinition); //reset command parameter - if(processInstance.getCommandParam() != null){ + if (processInstance.getCommandParam() != null) { Map processCmdParam = JSONUtils.toMap(processInstance.getCommandParam()); - for(Map.Entry entry: processCmdParam.entrySet()) { - if(!cmdParam.containsKey(entry.getKey())){ + for (Map.Entry entry : processCmdParam.entrySet()) { + if (!cmdParam.containsKey(entry.getKey())) { cmdParam.put(entry.getKey(), entry.getValue()); } } } // reset command parameter if sub process - if(cmdParam.containsKey(Constants.CMDPARAM_SUB_PROCESS)){ + if (cmdParam.containsKey(Constants.CMDPARAM_SUB_PROCESS)) { processInstance.setCommandParam(command.getCommandParam()); } - }else{ + } else { // generate one new process instance processInstance = generateNewProcessInstance(processDefinition, command, cmdParam); } - if(!checkCmdParam(command, cmdParam)){ + if (!checkCmdParam(command, cmdParam)) { logger.error("command parameter check failed!"); return null; } - if(command.getScheduleTime() != null){ + if (command.getScheduleTime() != null) { processInstance.setScheduleTime(command.getScheduleTime()); } processInstance.setHost(host); ExecutionStatus runStatus = ExecutionStatus.RUNNING_EXECUTION; int runTime = processInstance.getRunTimes(); - switch (commandType){ + switch (commandType) { case START_PROCESS: break; case START_FAILURE_TASK_PROCESS: @@ -686,13 +704,13 @@ public class ProcessService { failedList.addAll(killedList); failedList.addAll(toleranceList); - for(Integer taskId : failedList){ + for (Integer taskId : failedList) { initTaskInstance(this.findTaskInstanceById(taskId)); } cmdParam.put(Constants.CMDPARAM_RECOVERY_START_NODE_STRING, - String.join(Constants.COMMA, convertIntListToString(failedList))); + String.join(Constants.COMMA, convertIntListToString(failedList))); processInstance.setCommandParam(JSONUtils.toJsonString(cmdParam)); - processInstance.setRunTimes(runTime +1 ); + processInstance.setRunTimes(runTime + 1); break; case START_CURRENT_TASK_PROCESS: break; @@ -703,15 +721,15 @@ public class ProcessService { cmdParam.remove(Constants.CMDPARAM_RECOVERY_START_NODE_STRING); List suspendedNodeList = this.findTaskIdByInstanceState(processInstance.getId(), ExecutionStatus.PAUSE); List stopNodeList = findTaskIdByInstanceState(processInstance.getId(), - ExecutionStatus.KILL); + ExecutionStatus.KILL); suspendedNodeList.addAll(stopNodeList); - for(Integer taskId : suspendedNodeList){ + for (Integer taskId : suspendedNodeList) { // initialize the pause state initTaskInstance(this.findTaskInstanceById(taskId)); } cmdParam.put(Constants.CMDPARAM_RECOVERY_START_NODE_STRING, String.join(",", convertIntListToString(suspendedNodeList))); processInstance.setCommandParam(JSONUtils.toJsonString(cmdParam)); - processInstance.setRunTimes(runTime +1); + processInstance.setRunTimes(runTime + 1); break; case RECOVER_TOLERANCE_FAULT_PROCESS: // recover tolerance fault process @@ -721,7 +739,7 @@ public class ProcessService { case COMPLEMENT_DATA: // delete all the valid tasks when complement data List taskInstanceList = this.findValidTaskListByProcessId(processInstance.getId()); - for(TaskInstance taskInstance : taskInstanceList){ + for (TaskInstance taskInstance : taskInstanceList) { taskInstance.setFlag(Flag.NO); this.updateTaskInstance(taskInstance); } @@ -729,19 +747,19 @@ public class ProcessService { break; case REPEAT_RUNNING: // delete the recover task names from command parameter - if(cmdParam.containsKey(Constants.CMDPARAM_RECOVERY_START_NODE_STRING)){ + if (cmdParam.containsKey(Constants.CMDPARAM_RECOVERY_START_NODE_STRING)) { cmdParam.remove(Constants.CMDPARAM_RECOVERY_START_NODE_STRING); processInstance.setCommandParam(JSONUtils.toJsonString(cmdParam)); } // delete all the valid tasks when repeat running List validTaskList = findValidTaskListByProcessId(processInstance.getId()); - for(TaskInstance taskInstance : validTaskList){ + for (TaskInstance taskInstance : validTaskList) { taskInstance.setFlag(Flag.NO); updateTaskInstance(taskInstance); } processInstance.setStartTime(new Date()); processInstance.setEndTime(null); - processInstance.setRunTimes(runTime +1); + processInstance.setRunTimes(runTime + 1); initComplementDataParam(processDefinition, processInstance, cmdParam); break; case SCHEDULER: @@ -755,60 +773,62 @@ public class ProcessService { /** * return complement data if the process start with complement data + * * @param processInstance processInstance - * @param command command + * @param command command * @return command type */ - private CommandType getCommandTypeIfComplement(ProcessInstance processInstance, Command command){ - if(CommandType.COMPLEMENT_DATA == processInstance.getCmdTypeIfComplement()){ + private CommandType getCommandTypeIfComplement(ProcessInstance processInstance, Command command) { + if (CommandType.COMPLEMENT_DATA == processInstance.getCmdTypeIfComplement()) { return CommandType.COMPLEMENT_DATA; - }else{ + } else { return command.getCommandType(); } } /** * initialize complement data parameters + * * @param processDefinition processDefinition - * @param processInstance processInstance - * @param cmdParam cmdParam + * @param processInstance processInstance + * @param cmdParam cmdParam */ private void initComplementDataParam(ProcessDefinition processDefinition, ProcessInstance processInstance, Map cmdParam) { - if(!processInstance.isComplementData()){ + if (!processInstance.isComplementData()) { return; } Date startComplementTime = DateUtils.parse(cmdParam.get(CMDPARAM_COMPLEMENT_DATA_START_DATE), - YYYY_MM_DD_HH_MM_SS); - if(Flag.NO == processInstance.getIsSubProcess()) { + YYYY_MM_DD_HH_MM_SS); + if (Flag.NO == processInstance.getIsSubProcess()) { processInstance.setScheduleTime(startComplementTime); } processInstance.setGlobalParams(ParameterUtils.curingGlobalParams( - processDefinition.getGlobalParamMap(), - processDefinition.getGlobalParamList(), - CommandType.COMPLEMENT_DATA, processInstance.getScheduleTime())); + processDefinition.getGlobalParamMap(), + processDefinition.getGlobalParamList(), + CommandType.COMPLEMENT_DATA, processInstance.getScheduleTime())); } - /** * set sub work process parameters. * handle sub work process instance, update relation table and command parameters * set sub work process flag, extends parent work process command parameters + * * @param subProcessInstance subProcessInstance * @return process instance */ - public ProcessInstance setSubProcessParam(ProcessInstance subProcessInstance){ + public ProcessInstance setSubProcessParam(ProcessInstance subProcessInstance) { String cmdParam = subProcessInstance.getCommandParam(); - if(StringUtils.isEmpty(cmdParam)){ + if (StringUtils.isEmpty(cmdParam)) { return subProcessInstance; } Map paramMap = JSONUtils.toMap(cmdParam); // write sub process id into cmd param. - if(paramMap.containsKey(CMDPARAM_SUB_PROCESS) - && CMDPARAM_EMPTY_SUB_PROCESS.equals(paramMap.get(CMDPARAM_SUB_PROCESS))){ + if (paramMap.containsKey(CMDPARAM_SUB_PROCESS) + && CMDPARAM_EMPTY_SUB_PROCESS.equals(paramMap.get(CMDPARAM_SUB_PROCESS))) { paramMap.remove(CMDPARAM_SUB_PROCESS); paramMap.put(CMDPARAM_SUB_PROCESS, String.valueOf(subProcessInstance.getId())); subProcessInstance.setCommandParam(JSONUtils.toJsonString(paramMap)); @@ -817,18 +837,18 @@ public class ProcessService { } // copy parent instance user def params to sub process.. String parentInstanceId = paramMap.get(CMDPARAM_SUB_PROCESS_PARENT_INSTANCE_ID); - if(StringUtils.isNotEmpty(parentInstanceId)){ + if (StringUtils.isNotEmpty(parentInstanceId)) { ProcessInstance parentInstance = findProcessInstanceDetailById(Integer.parseInt(parentInstanceId)); - if(parentInstance != null){ + if (parentInstance != null) { subProcessInstance.setGlobalParams( - joinGlobalParams(parentInstance.getGlobalParams(), subProcessInstance.getGlobalParams())); + joinGlobalParams(parentInstance.getGlobalParams(), subProcessInstance.getGlobalParams())); this.saveProcessInstance(subProcessInstance); - }else{ + } else { logger.error("sub process command params error, cannot find parent instance: {} ", cmdParam); } } ProcessInstanceMap processInstanceMap = JSONUtils.parseObject(cmdParam, ProcessInstanceMap.class); - if(processInstanceMap == null || processInstanceMap.getParentProcessInstanceId() == 0){ + if (processInstanceMap == null || processInstanceMap.getParentProcessInstanceId() == 0) { return subProcessInstance; } // update sub process id to process map table @@ -841,19 +861,20 @@ public class ProcessService { /** * join parent global params into sub process. * only the keys doesn't in sub process global would be joined. + * * @param parentGlobalParams parentGlobalParams - * @param subGlobalParams subGlobalParams + * @param subGlobalParams subGlobalParams * @return global params join */ - private String joinGlobalParams(String parentGlobalParams, String subGlobalParams){ + private String joinGlobalParams(String parentGlobalParams, String subGlobalParams) { List parentPropertyList = JSONUtils.toList(parentGlobalParams, Property.class); List subPropertyList = JSONUtils.toList(subGlobalParams, Property.class); - Map subMap = subPropertyList.stream().collect(Collectors.toMap(Property::getProp, Property::getValue)); + Map subMap = subPropertyList.stream().collect(Collectors.toMap(Property::getProp, Property::getValue)); - for(Property parent : parentPropertyList){ - if(!subMap.containsKey(parent.getProp())){ + for (Property parent : parentPropertyList) { + if (!subMap.containsKey(parent.getProp())) { subPropertyList.add(parent); } } @@ -862,12 +883,13 @@ public class ProcessService { /** * initialize task instance + * * @param taskInstance taskInstance */ - private void initTaskInstance(TaskInstance taskInstance){ + private void initTaskInstance(TaskInstance taskInstance) { - if(!taskInstance.isSubProcess()){ - if(taskInstance.getState().typeIsCancel() || taskInstance.getState().typeIsFailure()){ + if (!taskInstance.isSubProcess()) { + if (taskInstance.getState().typeIsCancel() || taskInstance.getState().typeIsFailure()) { taskInstance.setFlag(Flag.NO); updateTaskInstance(taskInstance); return; @@ -880,27 +902,28 @@ public class ProcessService { /** * submit task to db * submit sub process to command + * * @param taskInstance taskInstance * @return task instance */ @Transactional(rollbackFor = RuntimeException.class) - public TaskInstance submitTask(TaskInstance taskInstance){ + public TaskInstance submitTask(TaskInstance taskInstance) { ProcessInstance processInstance = this.findProcessInstanceDetailById(taskInstance.getProcessInstanceId()); logger.info("start submit task : {}, instance id:{}, state: {}", - taskInstance.getName(), taskInstance.getProcessInstanceId(), processInstance.getState()); + taskInstance.getName(), taskInstance.getProcessInstanceId(), processInstance.getState()); //submit to db TaskInstance task = submitTaskInstanceToDB(taskInstance, processInstance); - if(task == null){ + if (task == null) { logger.error("end submit task to db error, task name:{}, process id:{} state: {} ", - taskInstance.getName(), taskInstance.getProcessInstance(), processInstance.getState()); + taskInstance.getName(), taskInstance.getProcessInstance(), processInstance.getState()); return task; } - if(!task.getState().typeIsFinished()){ + if (!task.getState().typeIsFinished()) { createSubWorkProcess(processInstance, task); } logger.info("end submit task to db successfully:{} state:{} complete, instance id:{} state: {} ", - taskInstance.getName(), task.getState(), processInstance.getId(), processInstance.getState()); + taskInstance.getName(), task.getState(), processInstance.getId(), processInstance.getState()); return task; } @@ -909,11 +932,12 @@ public class ProcessService { * consider o * repeat running does not generate new sub process instance * set map {parent instance id, task instance id, 0(child instance id)} + * * @param parentInstance parentInstance - * @param parentTask parentTask + * @param parentTask parentTask * @return process instance map */ - private ProcessInstanceMap setProcessInstanceMap(ProcessInstance parentInstance, TaskInstance parentTask){ + private ProcessInstanceMap setProcessInstanceMap(ProcessInstance parentInstance, TaskInstance parentTask) { ProcessInstanceMap processMap = findWorkProcessMapByParent(parentInstance.getId(), parentTask.getId()); if (processMap != null) { return processMap; @@ -937,8 +961,9 @@ public class ProcessService { /** * find previous task work process map. + * * @param parentProcessInstance parentProcessInstance - * @param parentTask parentTask + * @param parentTask parentTask * @return process instance map */ private ProcessInstanceMap findPreviousTaskProcessMap(ProcessInstance parentProcessInstance, @@ -956,7 +981,7 @@ public class ProcessService { } } logger.info("sub process instance is not found,parent task:{},parent instance:{}", - parentTask.getId(), parentProcessInstance.getId()); + parentTask.getId(), parentProcessInstance.getId()); return null; } @@ -990,6 +1015,7 @@ public class ProcessService { /** * complement data needs transform parent parameter to child. + * * @param instanceMap * @param parentProcessInstance * @return @@ -1011,6 +1037,7 @@ public class ProcessService { /** * create sub work process command + * * @param parentProcessInstance * @param childInstance * @param instanceMap @@ -1027,22 +1054,23 @@ public class ProcessService { String processParam = getSubWorkFlowParam(instanceMap, parentProcessInstance); return new Command( - commandType, - TaskDependType.TASK_POST, - parentProcessInstance.getFailureStrategy(), - parentProcessInstance.getExecutorId(), - childDefineId, - processParam, - parentProcessInstance.getWarningType(), - parentProcessInstance.getWarningGroupId(), - parentProcessInstance.getScheduleTime(), - parentProcessInstance.getProcessInstancePriority() + commandType, + TaskDependType.TASK_POST, + parentProcessInstance.getFailureStrategy(), + parentProcessInstance.getExecutorId(), + childDefineId, + processParam, + parentProcessInstance.getWarningType(), + parentProcessInstance.getWarningGroupId(), + parentProcessInstance.getScheduleTime(), + parentProcessInstance.getProcessInstancePriority() ); } /** * initialize sub work flow state * child instance state would be initialized when 'recovery from pause/stop/failure' + * * @param childInstance */ private void initSubInstanceState(ProcessInstance childInstance) { @@ -1070,42 +1098,43 @@ public class ProcessService { } /** - * update sub process definition + * update sub process definition todo + * * @param parentProcessInstance parentProcessInstance - * @param childDefinitionId childDefinitionId + * @param childDefinitionId childDefinitionId */ private void updateSubProcessDefinitionByParent(ProcessInstance parentProcessInstance, int childDefinitionId) { ProcessDefinition fatherDefinition = this.findProcessDefineById(parentProcessInstance.getProcessDefinitionId()); ProcessDefinition childDefinition = this.findProcessDefineById(childDefinitionId); - if(childDefinition != null && fatherDefinition != null){ - childDefinition.setReceivers(fatherDefinition.getReceivers()); - childDefinition.setReceiversCc(fatherDefinition.getReceiversCc()); + if (childDefinition != null && fatherDefinition != null) { + childDefinition.setWarningGroupId(fatherDefinition.getWarningGroupId()); processDefineMapper.updateById(childDefinition); } } /** * submit task to mysql - * @param taskInstance taskInstance + * + * @param taskInstance taskInstance * @param processInstance processInstance * @return task instance */ - public TaskInstance submitTaskInstanceToDB(TaskInstance taskInstance, ProcessInstance processInstance){ + public TaskInstance submitTaskInstanceToDB(TaskInstance taskInstance, ProcessInstance processInstance) { ExecutionStatus processInstanceState = processInstance.getState(); - if(taskInstance.getState().typeIsFailure()){ - if(taskInstance.isSubProcess()){ - taskInstance.setRetryTimes(taskInstance.getRetryTimes() + 1 ); - }else { + if (taskInstance.getState().typeIsFailure()) { + if (taskInstance.isSubProcess()) { + taskInstance.setRetryTimes(taskInstance.getRetryTimes() + 1); + } else { - if( processInstanceState != ExecutionStatus.READY_STOP - && processInstanceState != ExecutionStatus.READY_PAUSE){ + if (processInstanceState != ExecutionStatus.READY_STOP + && processInstanceState != ExecutionStatus.READY_PAUSE) { // failure task set invalid taskInstance.setFlag(Flag.NO); updateTaskInstance(taskInstance); // crate new task instance - if(taskInstance.getState() != ExecutionStatus.NEED_FAULT_TOLERANCE){ - taskInstance.setRetryTimes(taskInstance.getRetryTimes() + 1 ); + if (taskInstance.getState() != ExecutionStatus.NEED_FAULT_TOLERANCE) { + taskInstance.setRetryTimes(taskInstance.getRetryTimes() + 1); } taskInstance.setSubmitTime(null); taskInstance.setStartTime(null); @@ -1126,16 +1155,16 @@ public class ProcessService { taskInstance.setFirstSubmitTime(taskInstance.getSubmitTime()); } boolean saveResult = saveTaskInstance(taskInstance); - if(!saveResult){ + if (!saveResult) { return null; } return taskInstance; } - /** * ${processInstancePriority}_${processInstanceId}_${taskInstancePriority}_${taskInstanceId}_${task executed by ip1},${ip2}... * The tasks with the highest priority are selected by comparing the priorities of the above four levels from high to low. + * * @param taskInstance taskInstance * @return task zk queue str */ @@ -1143,7 +1172,7 @@ public class ProcessService { String taskWorkerGroup = getTaskWorkerGroup(taskInstance); ProcessInstance processInstance = this.findProcessInstanceById(taskInstance.getProcessInstanceId()); - if(processInstance == null){ + if (processInstance == null) { logger.error("process instance is null. please check the task info, task id: " + taskInstance.getId()); return ""; } @@ -1151,12 +1180,12 @@ public class ProcessService { StringBuilder sb = new StringBuilder(100); sb.append(processInstance.getProcessInstancePriority().ordinal()).append(Constants.UNDERLINE) - .append(taskInstance.getProcessInstanceId()).append(Constants.UNDERLINE) - .append(taskInstance.getTaskInstancePriority().ordinal()).append(Constants.UNDERLINE) - .append(taskInstance.getId()).append(Constants.UNDERLINE) - .append(taskInstance.getWorkerGroup()); + .append(taskInstance.getProcessInstanceId()).append(Constants.UNDERLINE) + .append(taskInstance.getTaskInstancePriority().ordinal()).append(Constants.UNDERLINE) + .append(taskInstance.getId()).append(Constants.UNDERLINE) + .append(taskInstance.getWorkerGroup()); - return sb.toString(); + return sb.toString(); } /** @@ -1167,51 +1196,52 @@ public class ProcessService { * return stop if work process state is ready stop * if all of above are not satisfied, return submit success * - * @param taskInstance taskInstance + * @param taskInstance taskInstance * @param processInstanceState processInstanceState * @return process instance state */ - public ExecutionStatus getSubmitTaskState(TaskInstance taskInstance, ExecutionStatus processInstanceState){ + public ExecutionStatus getSubmitTaskState(TaskInstance taskInstance, ExecutionStatus processInstanceState) { ExecutionStatus state = taskInstance.getState(); - if( - // running, delayed or killed - // the task already exists in task queue - // return state - state == ExecutionStatus.RUNNING_EXECUTION - || state == ExecutionStatus.DELAY_EXECUTION - || state == ExecutionStatus.KILL - || checkTaskExistsInTaskQueue(taskInstance) - ){ + if ( + // running, delayed or killed + // the task already exists in task queue + // return state + state == ExecutionStatus.RUNNING_EXECUTION + || state == ExecutionStatus.DELAY_EXECUTION + || state == ExecutionStatus.KILL + || checkTaskExistsInTaskQueue(taskInstance) + ) { return state; } //return pasue /stop if process instance state is ready pause / stop // or return submit success - if( processInstanceState == ExecutionStatus.READY_PAUSE){ + if (processInstanceState == ExecutionStatus.READY_PAUSE) { state = ExecutionStatus.PAUSE; - }else if(processInstanceState == ExecutionStatus.READY_STOP - || !checkProcessStrategy(taskInstance)) { + } else if (processInstanceState == ExecutionStatus.READY_STOP + || !checkProcessStrategy(taskInstance)) { state = ExecutionStatus.KILL; - }else{ + } else { state = ExecutionStatus.SUBMITTED_SUCCESS; } return state; } /** - * check process instance strategy + * check process instance strategy + * * @param taskInstance taskInstance * @return check strategy result */ - private boolean checkProcessStrategy(TaskInstance taskInstance){ + private boolean checkProcessStrategy(TaskInstance taskInstance) { ProcessInstance processInstance = this.findProcessInstanceById(taskInstance.getProcessInstanceId()); FailureStrategy failureStrategy = processInstance.getFailureStrategy(); - if(failureStrategy == FailureStrategy.CONTINUE){ + if (failureStrategy == FailureStrategy.CONTINUE) { return true; } List taskInstances = this.findValidTaskListByProcessId(taskInstance.getProcessInstanceId()); - for(TaskInstance task : taskInstances){ - if(task.getState() == ExecutionStatus.FAILURE){ + for (TaskInstance task : taskInstances) { + if (task.getState() == ExecutionStatus.FAILURE) { return false; } } @@ -1220,11 +1250,12 @@ public class ProcessService { /** * check the task instance existing in queue + * * @param taskInstance taskInstance * @return whether taskinstance exists queue */ - public boolean checkTaskExistsInTaskQueue(TaskInstance taskInstance){ - if(taskInstance.isSubProcess()){ + public boolean checkTaskExistsInTaskQueue(TaskInstance taskInstance) { + if (taskInstance.isSubProcess()) { return false; } @@ -1235,60 +1266,65 @@ public class ProcessService { /** * create a new process instance + * * @param processInstance processInstance */ - public void createProcessInstance(ProcessInstance processInstance){ + public void createProcessInstance(ProcessInstance processInstance) { - if (processInstance != null){ + if (processInstance != null) { processInstanceMapper.insert(processInstance); } } /** * insert or update work process instance to data base + * * @param processInstance processInstance */ - public void saveProcessInstance(ProcessInstance processInstance){ + public void saveProcessInstance(ProcessInstance processInstance) { - if (processInstance == null){ + if (processInstance == null) { logger.error("save error, process instance is null!"); - return ; + return; } - if(processInstance.getId() != 0){ + if (processInstance.getId() != 0) { processInstanceMapper.updateById(processInstance); - }else{ + } else { createProcessInstance(processInstance); } } /** * insert or update command + * * @param command command * @return save command result */ - public int saveCommand(Command command){ - if(command.getId() != 0){ + public int saveCommand(Command command) { + if (command.getId() != 0) { return commandMapper.updateById(command); - }else{ + } else { return commandMapper.insert(command); } } /** - * insert or update task instance + * insert or update task instance + * * @param taskInstance taskInstance * @return save task instance result */ - public boolean saveTaskInstance(TaskInstance taskInstance){ - if(taskInstance.getId() != 0){ + public boolean saveTaskInstance(TaskInstance taskInstance) { + if (taskInstance.getId() != 0) { return updateTaskInstance(taskInstance); - }else{ + } else { return createTaskInstance(taskInstance); } } /** * insert task instance + * * @param taskInstance taskInstance * @return create task instance result */ @@ -1299,16 +1335,19 @@ public class ProcessService { /** * update task instance + * * @param taskInstance taskInstance * @return update task instance result */ - public boolean updateTaskInstance(TaskInstance taskInstance){ + public boolean updateTaskInstance(TaskInstance taskInstance) { int count = taskInstanceMapper.updateById(taskInstance); return count > 0; } + /** * delete a command by id - * @param id id + * + * @param id id */ public void delCommandByid(int id) { commandMapper.deleteById(id); @@ -1316,23 +1355,24 @@ public class ProcessService { /** * find task instance by id + * * @param taskId task id * @return task intance */ - public TaskInstance findTaskInstanceById(Integer taskId){ + public TaskInstance findTaskInstanceById(Integer taskId) { return taskInstanceMapper.selectById(taskId); } - /** * package task instance,associate processInstance and processDefine + * * @param taskInstId taskInstId * @return task instance */ - public TaskInstance getTaskInstanceDetailByTaskId(int taskInstId){ + public TaskInstance getTaskInstanceDetailByTaskId(int taskInstId) { // get task instance TaskInstance taskInstance = findTaskInstanceById(taskInstId); - if(taskInstance == null){ + if (taskInstance == null) { return taskInstance; } // get process instance @@ -1345,88 +1385,94 @@ public class ProcessService { return taskInstance; } - /** * get id list by task state + * * @param instanceId instanceId - * @param state state + * @param state state * @return task instance states */ - public List findTaskIdByInstanceState(int instanceId, ExecutionStatus state){ + public List findTaskIdByInstanceState(int instanceId, ExecutionStatus state) { return taskInstanceMapper.queryTaskByProcessIdAndState(instanceId, state.ordinal()); } /** * find valid task list by process definition id + * * @param processInstanceId processInstanceId * @return task instance list */ - public List findValidTaskListByProcessId(Integer processInstanceId){ - return taskInstanceMapper.findValidTaskListByProcessId(processInstanceId, Flag.YES); + public List findValidTaskListByProcessId(Integer processInstanceId) { + return taskInstanceMapper.findValidTaskListByProcessId(processInstanceId, Flag.YES); } /** * find previous task list by work process id + * * @param processInstanceId processInstanceId * @return task instance list */ - public List findPreviousTaskListByWorkProcessId(Integer processInstanceId){ + public List findPreviousTaskListByWorkProcessId(Integer processInstanceId) { return taskInstanceMapper.findValidTaskListByProcessId(processInstanceId, Flag.NO); } /** * update work process instance map + * * @param processInstanceMap processInstanceMap * @return update process instance result */ - public int updateWorkProcessInstanceMap(ProcessInstanceMap processInstanceMap){ + public int updateWorkProcessInstanceMap(ProcessInstanceMap processInstanceMap) { return processInstanceMapMapper.updateById(processInstanceMap); } - /** * create work process instance map + * * @param processInstanceMap processInstanceMap * @return create process instance result */ - public int createWorkProcessInstanceMap(ProcessInstanceMap processInstanceMap){ + public int createWorkProcessInstanceMap(ProcessInstanceMap processInstanceMap) { Integer count = 0; - if(processInstanceMap !=null){ - return processInstanceMapMapper.insert(processInstanceMap); + if (processInstanceMap != null) { + return processInstanceMapMapper.insert(processInstanceMap); } return count; } /** * find work process map by parent process id and parent task id. + * * @param parentWorkProcessId parentWorkProcessId - * @param parentTaskId parentTaskId + * @param parentTaskId parentTaskId * @return process instance map */ - public ProcessInstanceMap findWorkProcessMapByParent(Integer parentWorkProcessId, Integer parentTaskId){ + public ProcessInstanceMap findWorkProcessMapByParent(Integer parentWorkProcessId, Integer parentTaskId) { return processInstanceMapMapper.queryByParentId(parentWorkProcessId, parentTaskId); } /** * delete work process map by parent process id + * * @param parentWorkProcessId parentWorkProcessId * @return delete process map result */ - public int deleteWorkProcessMapByParentId(int parentWorkProcessId){ + public int deleteWorkProcessMapByParentId(int parentWorkProcessId) { return processInstanceMapMapper.deleteByParentProcessId(parentWorkProcessId); } /** * find sub process instance + * * @param parentProcessId parentProcessId - * @param parentTaskId parentTaskId + * @param parentTaskId parentTaskId * @return process instance */ - public ProcessInstance findSubProcessInstance(Integer parentProcessId, Integer parentTaskId){ + public ProcessInstance findSubProcessInstance(Integer parentProcessId, Integer parentTaskId) { ProcessInstance processInstance = null; ProcessInstanceMap processInstanceMap = processInstanceMapMapper.queryByParentId(parentProcessId, parentTaskId); - if(processInstanceMap == null || processInstanceMap.getProcessInstanceId() == 0){ + if (processInstanceMap == null || processInstanceMap.getProcessInstanceId() == 0) { return processInstance; } processInstance = findProcessInstanceById(processInstanceMap.getProcessInstanceId()); @@ -1435,28 +1481,29 @@ public class ProcessService { /** * find parent process instance + * * @param subProcessId subProcessId * @return process instance */ public ProcessInstance findParentProcessInstance(Integer subProcessId) { ProcessInstance processInstance = null; ProcessInstanceMap processInstanceMap = processInstanceMapMapper.queryBySubProcessId(subProcessId); - if(processInstanceMap == null || processInstanceMap.getProcessInstanceId() == 0){ + if (processInstanceMap == null || processInstanceMap.getProcessInstanceId() == 0) { return processInstance; } processInstance = findProcessInstanceById(processInstanceMap.getParentProcessInstanceId()); return processInstance; } - /** * change task state - * @param state state - * @param startTime startTime - * @param host host + * + * @param state state + * @param startTime startTime + * @param host host * @param executePath executePath - * @param logPath logPath - * @param taskInstId taskInstId + * @param logPath logPath + * @param taskInstId taskInstId */ public void changeTaskState(ExecutionStatus state, Date startTime, String host, String executePath, @@ -1473,29 +1520,31 @@ public class ProcessService { /** * update process instance + * * @param processInstance processInstance * @return update process instance result */ - public int updateProcessInstance(ProcessInstance processInstance){ + public int updateProcessInstance(ProcessInstance processInstance) { return processInstanceMapper.updateById(processInstance); } /** * update the process instance + * * @param processInstanceId processInstanceId - * @param processJson processJson - * @param globalParams globalParams - * @param scheduleTime scheduleTime - * @param flag flag - * @param locations locations - * @param connects connects + * @param processJson processJson + * @param globalParams globalParams + * @param scheduleTime scheduleTime + * @param flag flag + * @param locations locations + * @param connects connects * @return update process instance result */ public int updateProcessInstance(Integer processInstanceId, String processJson, String globalParams, Date scheduleTime, Flag flag, - String locations, String connects){ + String locations, String connects) { ProcessInstance processInstance = processInstanceMapper.queryDetailById(processInstanceId); - if(processInstance!= null){ + if (processInstance != null) { processInstance.setProcessInstanceJson(processJson); processInstance.setGlobalParams(globalParams); processInstance.setScheduleTime(scheduleTime); @@ -1508,10 +1557,11 @@ public class ProcessService { /** * change task state - * @param state state - * @param endTime endTime + * + * @param state state + * @param endTime endTime * @param taskInstId taskInstId - * @param varPool varPool + * @param varPool varPool */ public void changeTaskState(ExecutionStatus state, Date endTime, @@ -1530,15 +1580,16 @@ public class ProcessService { /** * convert integer list to string list + * * @param intList intList * @return string list */ - public List convertIntListToString(List intList){ - if(intList == null){ + public List convertIntListToString(List intList) { + if (intList == null) { return new ArrayList<>(); } List result = new ArrayList(intList.size()); - for(Integer intVar : intList){ + for (Integer intVar : intList) { result.add(String.valueOf(intVar)); } return result; @@ -1546,6 +1597,7 @@ public class ProcessService { /** * query schedule by id + * * @param id id * @return schedule */ @@ -1555,6 +1607,7 @@ public class ProcessService { /** * query Schedule by processDefinitionId + * * @param processDefinitionId processDefinitionId * @see Schedule */ @@ -1564,20 +1617,22 @@ public class ProcessService { /** * query need failover process instance + * * @param host host * @return process instance list */ - public List queryNeedFailoverProcessInstances(String host){ + public List queryNeedFailoverProcessInstances(String host) { return processInstanceMapper.queryByHostAndStatus(host, stateArray); } /** * process need failover process instance + * * @param processInstance processInstance */ @Transactional(rollbackFor = RuntimeException.class) - public void processNeedFailoverProcessInstances(ProcessInstance processInstance){ + public void processNeedFailoverProcessInstances(ProcessInstance processInstance) { //1 update processInstance host is null processInstance.setHost(Constants.NULL); processInstanceMapper.updateById(processInstance); @@ -1593,28 +1648,30 @@ public class ProcessService { /** * query all need failover task instances by host + * * @param host host * @return task instance list */ - public List queryNeedFailoverTaskInstances(String host){ + public List queryNeedFailoverTaskInstances(String host) { return taskInstanceMapper.queryByHostAndStatus(host, - stateArray); + stateArray); } /** * find data source by id + * * @param id id * @return datasource */ - public DataSource findDataSourceById(int id){ + public DataSource findDataSourceById(int id) { return dataSourceMapper.selectById(id); } - /** * update process instance state by id + * * @param processInstanceId processInstanceId - * @param executionStatus executionStatus + * @param executionStatus executionStatus * @return update process result */ public int updateProcessInstanceState(Integer processInstanceId, ExecutionStatus executionStatus) { @@ -1626,12 +1683,13 @@ public class ProcessService { /** * find process instance by the task id + * * @param taskId taskId * @return process instance */ - public ProcessInstance findProcessInstanceByTaskId(int taskId){ + public ProcessInstance findProcessInstanceByTaskId(int taskId) { TaskInstance taskInstance = taskInstanceMapper.selectById(taskId); - if(taskInstance!= null){ + if (taskInstance != null) { return processInstanceMapper.selectById(taskInstance.getProcessInstanceId()); } return null; @@ -1639,97 +1697,101 @@ public class ProcessService { /** * find udf function list by id list string + * * @param ids ids * @return udf function list */ - public List queryUdfFunListByids(int[] ids){ + public List queryUdfFunListByids(int[] ids) { return udfFuncMapper.queryUdfByIdStr(ids, null); } /** * find tenant code by resource name - * @param resName resource name + * + * @param resName resource name * @param resourceType resource type * @return tenant code */ - public String queryTenantCodeByResName(String resName,ResourceType resourceType){ + public String queryTenantCodeByResName(String resName, ResourceType resourceType) { return resourceMapper.queryTenantCodeByResourceName(resName, resourceType.ordinal()); } /** * find schedule list by process define id. + * * @param ids ids * @return schedule list */ - public List selectAllByProcessDefineId(int[] ids){ + public List selectAllByProcessDefineId(int[] ids) { return scheduleMapper.selectAllByProcessDefineArray( - ids); + ids); } /** * get dependency cycle by work process define id and scheduler fire time - * @param masterId masterId + * + * @param masterId masterId * @param processDefinitionId processDefinitionId - * @param scheduledFireTime the time the task schedule is expected to trigger + * @param scheduledFireTime the time the task schedule is expected to trigger * @return CycleDependency * @throws Exception if error throws Exception */ public CycleDependency getCycleDependency(int masterId, int processDefinitionId, Date scheduledFireTime) throws Exception { - List list = getCycleDependencies(masterId,new int[]{processDefinitionId},scheduledFireTime); - return list.size()>0 ? list.get(0) : null; + List list = getCycleDependencies(masterId, new int[] {processDefinitionId}, scheduledFireTime); + return list.size() > 0 ? list.get(0) : null; } /** * get dependency cycle list by work process define id list and scheduler fire time - * @param masterId masterId - * @param ids ids + * + * @param masterId masterId + * @param ids ids * @param scheduledFireTime the time the task schedule is expected to trigger * @return CycleDependency list * @throws Exception if error throws Exception */ - public List getCycleDependencies(int masterId,int[] ids,Date scheduledFireTime) throws Exception { - List cycleDependencyList = new ArrayList(); + public List getCycleDependencies(int masterId, int[] ids, Date scheduledFireTime) throws Exception { + List cycleDependencyList = new ArrayList(); if (ids == null || ids.length == 0) { logger.warn("ids[] is empty!is invalid!"); return cycleDependencyList; } - if(scheduledFireTime == null){ + if (scheduledFireTime == null) { logger.warn("scheduledFireTime is null!is invalid!"); return cycleDependencyList; } - String strCrontab = ""; CronExpression depCronExpression; Cron depCron; List list; List schedules = this.selectAllByProcessDefineId(ids); // for all scheduling information - for(Schedule depSchedule:schedules){ + for (Schedule depSchedule : schedules) { strCrontab = depSchedule.getCrontab(); depCronExpression = CronUtils.parse2CronExpression(strCrontab); depCron = CronUtils.parse2Cron(strCrontab); CycleEnum cycleEnum = CronUtils.getMiniCycle(depCron); - if(cycleEnum == null){ - logger.error("{} is not valid",strCrontab); + if (cycleEnum == null) { + logger.error("{} is not valid", strCrontab); continue; } Calendar calendar = Calendar.getInstance(); - switch (cycleEnum){ + switch (cycleEnum) { /*case MINUTE: calendar.add(Calendar.MINUTE,-61);*/ case HOUR: - calendar.add(Calendar.HOUR,-25); + calendar.add(Calendar.HOUR, -25); break; case DAY: - calendar.add(Calendar.DATE,-32); + calendar.add(Calendar.DATE, -32); break; case WEEK: - calendar.add(Calendar.DATE,-32); + calendar.add(Calendar.DATE, -32); break; case MONTH: - calendar.add(Calendar.MONTH,-13); + calendar.add(Calendar.MONTH, -13); break; default: logger.warn("Dependent process definition's cycleEnum is {},not support!!", cycleEnum.name()); @@ -1737,14 +1799,14 @@ public class ProcessService { } Date start = calendar.getTime(); - if(depSchedule.getProcessDefinitionId() == masterId){ + if (depSchedule.getProcessDefinitionId() == masterId) { list = CronUtils.getSelfFireDateList(start, scheduledFireTime, depCronExpression); - }else { + } else { list = CronUtils.getFireDateList(start, scheduledFireTime, depCronExpression); } - if(list.size()>=1){ - start = list.get(list.size()-1); - CycleDependency dependency = new CycleDependency(depSchedule.getProcessDefinitionId(),start, CronUtils.getExpirationTime(start, cycleEnum), cycleEnum); + if (list.size() >= 1) { + start = list.get(list.size() - 1); + CycleDependency dependency = new CycleDependency(depSchedule.getProcessDefinitionId(), start, CronUtils.getExpirationTime(start, cycleEnum), cycleEnum); cycleDependencyList.add(dependency); } @@ -1754,78 +1816,80 @@ public class ProcessService { /** * find last scheduler process instance in the date interval + * * @param definitionId definitionId * @param dateInterval dateInterval * @return process instance */ public ProcessInstance findLastSchedulerProcessInterval(int definitionId, DateInterval dateInterval) { return processInstanceMapper.queryLastSchedulerProcess(definitionId, - dateInterval.getStartTime(), - dateInterval.getEndTime()); + dateInterval.getStartTime(), + dateInterval.getEndTime()); } /** * find last manual process instance interval + * * @param definitionId process definition id * @param dateInterval dateInterval * @return process instance */ public ProcessInstance findLastManualProcessInterval(int definitionId, DateInterval dateInterval) { return processInstanceMapper.queryLastManualProcess(definitionId, - dateInterval.getStartTime(), - dateInterval.getEndTime()); + dateInterval.getStartTime(), + dateInterval.getEndTime()); } /** * find last running process instance - * @param definitionId process definition id - * @param startTime start time - * @param endTime end time + * + * @param definitionId process definition id + * @param startTime start time + * @param endTime end time * @return process instance */ public ProcessInstance findLastRunningProcess(int definitionId, Date startTime, Date endTime) { return processInstanceMapper.queryLastRunningProcess(definitionId, - startTime, - endTime, - stateArray); + startTime, + endTime, + stateArray); } /** * query user queue by process instance id + * * @param processInstanceId processInstanceId * @return queue */ - public String queryUserQueueByProcessInstanceId(int processInstanceId){ + public String queryUserQueueByProcessInstanceId(int processInstanceId) { String queue = ""; ProcessInstance processInstance = processInstanceMapper.selectById(processInstanceId); - if(processInstance == null){ + if (processInstance == null) { return queue; } User executor = userMapper.selectById(processInstance.getExecutorId()); - if(executor != null){ + if (executor != null) { queue = executor.getQueue(); } return queue; } - - /** * get task worker group + * * @param taskInstance taskInstance * @return workerGroupId */ public String getTaskWorkerGroup(TaskInstance taskInstance) { String workerGroup = taskInstance.getWorkerGroup(); - - if(StringUtils.isNotBlank(workerGroup)){ + if (StringUtils.isNotBlank(workerGroup)) { return workerGroup; } int processInstanceId = taskInstance.getProcessInstanceId(); ProcessInstance processInstance = findProcessInstanceById(processInstanceId); - if(processInstance != null){ + if (processInstance != null) { return processInstance.getWorkerGroup(); } logger.info("task : {} will use default worker group", taskInstance.getId()); @@ -1834,18 +1898,19 @@ public class ProcessService { /** * get have perm project list + * * @param userId userId * @return project list */ - public List getProjectListHavePerm(int userId){ + public List getProjectListHavePerm(int userId) { List createProjects = projectMapper.queryProjectCreatedByUser(userId); List authedProjects = projectMapper.queryAuthedProjectListByUserId(userId); - if(createProjects == null){ + if (createProjects == null) { createProjects = new ArrayList<>(); } - if(authedProjects != null){ + if (authedProjects != null) { createProjects.addAll(authedProjects); } return createProjects; @@ -1853,13 +1918,14 @@ public class ProcessService { /** * get have perm project ids + * * @param userId userId * @return project ids */ - public List getProjectIdListHavePerm(int userId){ + public List getProjectIdListHavePerm(int userId) { List projectIdList = new ArrayList<>(); - for(Project project : getProjectListHavePerm(userId)){ + for (Project project : getProjectListHavePerm(userId)) { projectIdList.add(project.getId()); } return projectIdList; @@ -1867,17 +1933,18 @@ public class ProcessService { /** * list unauthorized udf function - * @param userId user id - * @param needChecks data source id array + * + * @param userId user id + * @param needChecks data source id array * @return unauthorized udf function list */ - public List listUnauthorized(int userId,T[] needChecks,AuthorizationType authorizationType){ + public List listUnauthorized(int userId, T[] needChecks, AuthorizationType authorizationType) { List resultList = new ArrayList(); if (Objects.nonNull(needChecks) && needChecks.length > 0) { Set originResSet = new HashSet(Arrays.asList(needChecks)); - switch (authorizationType){ + switch (authorizationType) { case RESOURCE_FILE_ID: Set authorizedResourceFiles = resourceMapper.listAuthorizedResourceById(userId, needChecks).stream().map(t -> t.getId()).collect(toSet()); originResSet.removeAll(authorizedResourceFiles); @@ -1891,13 +1958,15 @@ public class ProcessService { originResSet.removeAll(authorizedUdfFiles); break; case DATASOURCE: - Set authorizedDatasources = dataSourceMapper.listAuthorizedDataSource(userId,needChecks).stream().map(t -> t.getId()).collect(toSet()); + Set authorizedDatasources = dataSourceMapper.listAuthorizedDataSource(userId, needChecks).stream().map(t -> t.getId()).collect(toSet()); originResSet.removeAll(authorizedDatasources); break; case UDF: Set authorizedUdfs = udfFuncMapper.listAuthorizedUdfFunc(userId, needChecks).stream().map(t -> t.getId()).collect(toSet()); originResSet.removeAll(authorizedUdfs); break; + default: + break; } resultList.addAll(originResSet); @@ -1908,48 +1977,51 @@ public class ProcessService { /** * get user by user id + * * @param userId user id * @return User */ - public User getUserById(int userId){ + public User getUserById(int userId) { return userMapper.selectById(userId); } /** * get resource by resoruce id + * * @param resoruceId resource id * @return Resource */ - public Resource getResourceById(int resoruceId){ + public Resource getResourceById(int resoruceId) { return resourceMapper.selectById(resoruceId); } - /** * list resources by ids + * * @param resIds resIds * @return resource list */ - public List listResourceByIds(Integer[] resIds){ + public List listResourceByIds(Integer[] resIds) { return resourceMapper.listResourceByIds(resIds); } /** * format task app id in task instance + * * @param taskInstance * @return */ - public String formatTaskAppId(TaskInstance taskInstance){ + public String formatTaskAppId(TaskInstance taskInstance) { ProcessDefinition definition = this.findProcessDefineById(taskInstance.getProcessDefinitionId()); ProcessInstance processInstanceById = this.findProcessInstanceById(taskInstance.getProcessInstanceId()); - if(definition == null || processInstanceById == null){ + if (definition == null || processInstanceById == null) { return ""; } return String.format("%s_%s_%s", - definition.getId(), - processInstanceById.getId(), - taskInstance.getId()); + definition.getId(), + processInstanceById.getId(), + taskInstance.getId()); } } diff --git a/pom.xml b/pom.xml index d37492efb6..cd281ba988 100644 --- a/pom.xml +++ b/pom.xml @@ -940,7 +940,6 @@ **/dao/mapper/TenantMapperTest.java **/dao/mapper/UdfFuncMapperTest.java **/dao/mapper/UDFUserMapperTest.java - **/dao/mapper/UserAlertGroupMapperTest.java **/dao/mapper/UserMapperTest.java **/dao/mapper/AlertPluginInstanceMapperTest.java **/dao/mapper/PluginDefineTest.java diff --git a/sql/dolphinscheduler-postgre.sql b/sql/dolphinscheduler-postgre.sql index 2149b6c67c..078ff7e14c 100644 --- a/sql/dolphinscheduler-postgre.sql +++ b/sql/dolphinscheduler-postgre.sql @@ -187,14 +187,10 @@ DROP TABLE IF EXISTS t_ds_alert; CREATE TABLE t_ds_alert ( id int NOT NULL , title varchar(64) DEFAULT NULL , - show_type int DEFAULT NULL , content text , - alert_type int DEFAULT NULL , alert_status int DEFAULT '0' , log text , alertgroup_id int DEFAULT NULL , - receivers text , - receivers_cc text , create_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL , PRIMARY KEY (id) @@ -204,14 +200,14 @@ CREATE TABLE t_ds_alert ( -- DROP TABLE IF EXISTS t_ds_alertgroup; -CREATE TABLE t_ds_alertgroup ( - id int NOT NULL , - group_name varchar(255) DEFAULT NULL , - group_type int DEFAULT NULL , - description varchar(255) DEFAULT NULL , - create_time timestamp DEFAULT NULL , - update_time timestamp DEFAULT NULL , - PRIMARY KEY (id) +CREATE TABLE t_ds_alertgroup( + id int NOT NULL, + create_user_id int4 DEFAULT NULL, + group_name varchar(255) DEFAULT NULL, + description varchar(255) DEFAULT NULL, + create_time timestamp DEFAULT NULL, + update_time timestamp DEFAULT NULL, + PRIMARY KEY (id) ) ; -- @@ -301,8 +297,7 @@ CREATE TABLE t_ds_process_definition ( flag int DEFAULT NULL , locations text , connects text , - receivers text , - receivers_cc text , + warning_group_id int4 DEFAULT NULL , create_time timestamp DEFAULT NULL , timeout int DEFAULT '0' , tenant_id int NOT NULL DEFAULT '-1' , @@ -329,8 +324,7 @@ CREATE TABLE t_ds_process_definition_version ( global_params text , locations text , connects text , - receivers text , - receivers_cc text , + warning_group_id int4 DEFAULT NULL, create_time timestamp DEFAULT NULL , timeout int DEFAULT '0' , resource_ids varchar(64), @@ -492,20 +486,6 @@ CREATE TABLE t_ds_relation_udfs_user ( ) ; ; --- --- Table structure for table t_ds_relation_user_alertgroup --- - -DROP TABLE IF EXISTS t_ds_relation_user_alertgroup; -CREATE TABLE t_ds_relation_user_alertgroup ( - id int NOT NULL, - alertgroup_id int DEFAULT NULL, - user_id int DEFAULT NULL, - create_time timestamp DEFAULT NULL, - update_time timestamp DEFAULT NULL, - PRIMARY KEY (id) -); - -- -- Table structure for table t_ds_resources -- @@ -748,9 +728,6 @@ ALTER TABLE t_ds_relation_resources_user ALTER COLUMN id SET DEFAULT NEXTVAL('t_ DROP SEQUENCE IF EXISTS t_ds_relation_udfs_user_id_sequence; CREATE SEQUENCE t_ds_relation_udfs_user_id_sequence; ALTER TABLE t_ds_relation_udfs_user ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_udfs_user_id_sequence'); -DROP SEQUENCE IF EXISTS t_ds_relation_user_alertgroup_id_sequence; -CREATE SEQUENCE t_ds_relation_user_alertgroup_id_sequence; -ALTER TABLE t_ds_relation_user_alertgroup ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_user_alertgroup_id_sequence'); DROP SEQUENCE IF EXISTS t_ds_resources_id_sequence; CREATE SEQUENCE t_ds_resources_id_sequence; @@ -777,21 +754,27 @@ ALTER TABLE t_ds_version ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_version_id_se DROP SEQUENCE IF EXISTS t_ds_worker_group_id_sequence; CREATE SEQUENCE t_ds_worker_group_id_sequence; -ALTER TABLE t_ds_worker_group ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_group_id_sequence'); +ALTER TABLE t_ds_worker_group + ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_group_id_sequence'); DROP SEQUENCE IF EXISTS t_ds_worker_server_id_sequence; -CREATE SEQUENCE t_ds_worker_server_id_sequence; -ALTER TABLE t_ds_worker_server ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_server_id_sequence'); +CREATE SEQUENCE t_ds_worker_server_id_sequence; +ALTER TABLE t_ds_worker_server + ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_server_id_sequence'); -- Records of t_ds_user?user : admin , password : dolphinscheduler123 -INSERT INTO t_ds_user(user_name,user_password,user_type,email,phone,tenant_id,state,create_time,update_time) VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22'); +INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time) +VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', + '2018-10-24 17:40:22'); -- Records of t_ds_alertgroup,dolphinscheduler warning group -INSERT INTO t_ds_alertgroup(group_name,group_type,description,create_time,update_time) VALUES ('dolphinscheduler warning group', '0', 'dolphinscheduler warning group','2018-11-29 10:20:39', '2018-11-29 10:20:39'); -INSERT INTO t_ds_relation_user_alertgroup(alertgroup_id,user_id,create_time,update_time) VALUES ( '1', '1', '2018-11-29 10:22:33', '2018-11-29 10:22:33'); +INSERT INTO t_ds_alertgroup(id, create_user_id, group_name, description, create_time, update_time) +VALUES (1, 'dolphinscheduler warning group', 'dolphinscheduler warning group', '2018-11-29 10:20:39', + '2018-11-29 10:20:39'); -- Records of t_ds_queue,default queue name : default -INSERT INTO t_ds_queue(queue_name,queue,create_time,update_time) VALUES ('default', 'default','2018-11-29 10:22:33', '2018-11-29 10:22:33'); +INSERT INTO t_ds_queue(queue_name, queue, create_time, update_time) +VALUES ('default', 'default', '2018-11-29 10:22:33', '2018-11-29 10:22:33'); -- Records of t_ds_queue,default queue name : default INSERT INTO t_ds_version(version) VALUES ('1.3.0'); diff --git a/sql/dolphinscheduler_mysql.sql b/sql/dolphinscheduler_mysql.sql index 7abdd39613..986df1f668 100644 --- a/sql/dolphinscheduler_mysql.sql +++ b/sql/dolphinscheduler_mysql.sql @@ -279,14 +279,10 @@ DROP TABLE IF EXISTS `t_ds_alert`; CREATE TABLE `t_ds_alert` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', `title` varchar(64) DEFAULT NULL COMMENT 'title', - `show_type` tinyint(4) DEFAULT NULL COMMENT 'send email type,0:TABLE,1:TEXT', `content` text COMMENT 'Message content (can be email, can be SMS. Mail is stored in JSON map, and SMS is string)', - `alert_type` tinyint(4) DEFAULT NULL COMMENT '0:email,1:sms', `alert_status` tinyint(4) DEFAULT '0' COMMENT '0:wait running,1:success,2:failed', `log` text COMMENT 'log', `alertgroup_id` int(11) DEFAULT NULL COMMENT 'alert group id', - `receivers` text COMMENT 'receivers', - `receivers_cc` text COMMENT 'cc', `create_time` datetime DEFAULT NULL COMMENT 'create time', `update_time` datetime DEFAULT NULL COMMENT 'update time', PRIMARY KEY (`id`) @@ -300,14 +296,14 @@ CREATE TABLE `t_ds_alert` ( -- Table structure for t_ds_alertgroup -- ---------------------------- DROP TABLE IF EXISTS `t_ds_alertgroup`; -CREATE TABLE `t_ds_alertgroup` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', - `group_name` varchar(255) DEFAULT NULL COMMENT 'group name', - `group_type` tinyint(4) DEFAULT NULL COMMENT 'Group type (message 0, SMS 1...)', - `description` varchar(255) DEFAULT NULL, - `create_time` datetime DEFAULT NULL COMMENT 'create time', - `update_time` datetime DEFAULT NULL COMMENT 'update time', - PRIMARY KEY (`id`) +CREATE TABLE `t_ds_alertgroup`( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', + `create_user_id` int(11) DEFAULT NULL COMMENT 'create user id', + `group_name` varchar(255) DEFAULT NULL COMMENT 'group name', + `description` varchar(255) DEFAULT NULL, + `create_time` datetime DEFAULT NULL COMMENT 'create time', + `update_time` datetime DEFAULT NULL COMMENT 'update time', + PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; -- ---------------------------- @@ -406,8 +402,7 @@ CREATE TABLE `t_ds_process_definition` ( `flag` tinyint(4) DEFAULT NULL COMMENT '0 not available, 1 available', `locations` text COMMENT 'Node location information', `connects` text COMMENT 'Node connection information', - `receivers` text COMMENT 'receivers', - `receivers_cc` text COMMENT 'cc', + `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `create_time` datetime DEFAULT NULL COMMENT 'create time', `timeout` int(11) DEFAULT '0' COMMENT 'time out', `tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id', @@ -436,8 +431,7 @@ CREATE TABLE `t_ds_process_definition_version` ( `global_params` text COMMENT 'global parameters', `locations` text COMMENT 'Node location information', `connects` text COMMENT 'Node connection information', - `receivers` text COMMENT 'receivers', - `receivers_cc` text COMMENT 'cc', + `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id', `create_time` datetime DEFAULT NULL COMMENT 'create time', `timeout` int(11) DEFAULT '0' COMMENT 'time out', `resource_ids` varchar(255) DEFAULT NULL COMMENT 'resource ids', @@ -620,27 +614,6 @@ CREATE TABLE `t_ds_relation_udfs_user` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; --- ---------------------------- --- Records of t_ds_relation_udfs_user --- ---------------------------- - --- ---------------------------- --- Table structure for t_ds_relation_user_alertgroup --- ---------------------------- -DROP TABLE IF EXISTS `t_ds_relation_user_alertgroup`; -CREATE TABLE `t_ds_relation_user_alertgroup` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', - `alertgroup_id` int(11) DEFAULT NULL COMMENT 'alert group id', - `user_id` int(11) DEFAULT NULL COMMENT 'user id', - `create_time` datetime DEFAULT NULL COMMENT 'create time', - `update_time` datetime DEFAULT NULL COMMENT 'update time', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; - --- ---------------------------- --- Records of t_ds_relation_user_alertgroup --- ---------------------------- - -- ---------------------------- -- Table structure for t_ds_resources -- ---------------------------- @@ -831,28 +804,29 @@ CREATE TABLE `t_ds_version` ( -- ---------------------------- -- Records of t_ds_version -- ---------------------------- -INSERT INTO `t_ds_version` VALUES ('1', '1.3.0'); +INSERT INTO `t_ds_version` +VALUES ('1', '1.3.0'); -- ---------------------------- -- Records of t_ds_alertgroup -- ---------------------------- -INSERT INTO `t_ds_alertgroup` VALUES ('1', 'default admin warning group', '0', 'default admin warning group', '2018-11-29 10:20:39', '2018-11-29 10:20:39'); - --- ---------------------------- --- Records of t_ds_relation_user_alertgroup --- ---------------------------- -INSERT INTO `t_ds_relation_user_alertgroup` VALUES ('1', '1', '1', '2018-11-29 10:22:33', '2018-11-29 10:22:33'); +INSERT INTO `t_ds_alertgroup` +VALUES (1, 1, 'default admin warning group', 'default admin warning group', '2018-11-29 10:20:39', + '2018-11-29 10:20:39'); -- ---------------------------- -- Records of t_ds_user -- ---------------------------- -INSERT INTO `t_ds_user` VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50', '2018-10-24 17:40:22', null, 1); +INSERT INTO `t_ds_user` +VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50', + '2018-10-24 17:40:22', null, 1); -- ---------------------------- -- Table structure for t_ds_plugin_define -- ---------------------------- -SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); +SET +sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); DROP TABLE IF EXISTS `t_ds_plugin_define`; CREATE TABLE `t_ds_plugin_define` ( `id` int NOT NULL AUTO_INCREMENT, diff --git a/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql b/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql index 42e62fba17..a0315ddeb0 100644 --- a/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql +++ b/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql @@ -30,14 +30,40 @@ CREATE TABLE `t_ds_plugin_define` ( DROP TABLE IF EXISTS `t_ds_alert_plugin_instance`; CREATE TABLE `t_ds_alert_plugin_instance` ( - `id` int NOT NULL AUTO_INCREMENT, - `plugin_define_id` int NOT NULL, - `plugin_instance_params` text COMMENT 'plugin instance params. Also contain the params value which user input in web ui.', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `alert_group_id` int DEFAULT NULL, - `instance_name` varchar(200) DEFAULT NULL COMMENT 'alert instance name', - PRIMARY KEY (`id`) + `id` int NOT NULL AUTO_INCREMENT, + `plugin_define_id` int NOT NULL, + `plugin_instance_params` text COMMENT 'plugin instance params. Also contain the params value which user input in web ui.', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `alert_group_id` int DEFAULT NULL, + `instance_name` varchar(200) DEFAULT NULL COMMENT 'alert instance name', + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE t_ds_process_definition + ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + +ALTER TABLE t_ds_process_definition_version + ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + +ALTER TABLE t_ds_alertgroup + ADD COLUMN `create_user_id` int(11) DEFAULT NULL COMMENT 'create user id' AFTER `id`; + + +-- ---------------------------- +-- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below +-- ---------------------------- +/* +ALTER TABLE t_ds_process_definition DROP receivers, DROP receivers_cc; + +ALTER TABLE t_ds_process_definition_version DROP receivers, DROP receivers_cc; + +ALTER TABLE t_ds_alert DROP show_type,DROP alert_type,DROP receivers,DROP receivers_cc; + +ALTER TABLE t_ds_alertgroup DROP group_type; + +DROP TABLE IF EXISTS t_ds_relation_user_alertgroup; +*/ + + diff --git a/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql b/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql index 90de08ff8e..788347b765 100644 --- a/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql +++ b/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -29,12 +29,36 @@ CREATE TABLE t_ds_plugin_define ( DROP TABLE IF EXISTS t_ds_alert_plugin_instance; CREATE TABLE t_ds_alert_plugin_instance ( - id serial NOT NULL, - plugin_define_id int4 NOT NULL, - plugin_instance_params text NULL, - create_time timestamp NULL, - update_time timestamp NULL, - alert_group_id int4 NOT NULL, - instance_name varchar(200) NULL, - CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id) + id serial NOT NULL, + plugin_define_id int4 NOT NULL, + plugin_instance_params text NULL, + create_time timestamp NULL, + update_time timestamp NULL, + alert_group_id int4 NOT NULL, + instance_name varchar(200) NULL, + CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id) ); + +ALTER TABLE t_ds_process_definition + ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + +ALTER TABLE t_ds_process_definition_version + ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + +ALTER TABLE t_ds_alertgroup + ADD COLUMN `create_user_id` int4 DEFAULT NULL COMMENT 'create user id' AFTER `id`; + +-- ---------------------------- +-- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below +-- ---------------------------- +/* +ALTER TABLE t_ds_process_definition DROP COLUMN "receivers", DROP COLUMN "receivers_cc"; + +ALTER TABLE t_ds_process_definition_version DROP COLUMN "receivers", DROP COLUMN "receivers_cc"; + +ALTER TABLE t_ds_alert DROP COLUMN "show_type",DROP COLUMN "alert_type",DROP COLUMN "receivers",DROP COLUMN "receivers_cc"; + +ALTER TABLE t_ds_alertgroup DROP COLUMN "group_type"; + +DROP TABLE IF EXISTS t_ds_relation_user_alertgroup; +*/ From 5808a0a8b1ad0f4ba77116a2fb61e97d8cc7c55d Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Thu, 31 Dec 2020 16:45:47 +0800 Subject: [PATCH 39/44] Replace the front-end code of the plugin branch with the front-end code of the dev branch (#4353) * Replace the front-end code of the plugin branch with the front-end code of the dev branch --- dolphinscheduler-ui/.babelrc | 10 +- dolphinscheduler-ui/.eslintignore | 7 + dolphinscheduler-ui/.eslintrc.yml | 12 +- dolphinscheduler-ui/build/config.js | 12 +- .../build/webpack.config.dev.js | 43 +- .../build/webpack.config.prod.js | 7 +- dolphinscheduler-ui/package.json | 28 +- dolphinscheduler-ui/pom.xml | 5 +- .../src/components/Counter.vue | 46 +- .../src/components/Message.vue | 14 +- dolphinscheduler-ui/src/js/conf/home/App.vue | 23 +- dolphinscheduler-ui/src/js/conf/home/index.js | 15 +- .../js/conf/home/pages/dag/_source/config.js | 38 +- .../src/js/conf/home/pages/dag/_source/dag.js | 43 +- .../js/conf/home/pages/dag/_source/dag.scss | 4 +- .../js/conf/home/pages/dag/_source/dag.vue | 705 +++++++++--------- .../formModel/_source/dependentTimeout.vue | 68 +- .../_source/formModel/_source/selectInput.vue | 39 +- .../formModel/_source/timeoutAlarm.vue | 16 +- .../formModel/_source/workerGroups.vue | 20 +- .../dag/_source/formModel/formLineModel.vue | 78 +- .../dag/_source/formModel/formModel.scss | 58 +- .../pages/dag/_source/formModel/formModel.vue | 261 +++---- .../home/pages/dag/_source/formModel/log.vue | 71 +- .../formModel/tasks/_source/datasource.vue | 24 +- .../tasks/_source/dependItemList.vue | 67 +- .../formModel/tasks/_source/httpParams.vue | 58 +- .../formModel/tasks/_source/jsonBox.vue | 116 +++ .../formModel/tasks/_source/list4Box.vue | 68 ++ .../formModel/tasks/_source/listBox.vue | 2 - .../formModel/tasks/_source/localParams.vue | 58 +- .../formModel/tasks/_source/nodeStatus.vue | 36 +- .../formModel/tasks/_source/resources.vue | 9 +- .../formModel/tasks/_source/scriptBox.vue | 19 +- .../formModel/tasks/_source/sqlType.vue | 18 +- .../formModel/tasks/_source/statementList.vue | 13 +- .../_source/formModel/tasks/_source/udfs.vue | 13 +- .../_source/formModel/tasks/conditions.vue | 24 +- .../dag/_source/formModel/tasks/datax.vue | 161 ++-- .../dag/_source/formModel/tasks/dependent.vue | 19 +- .../dag/_source/formModel/tasks/flink.vue | 461 ++++++------ .../dag/_source/formModel/tasks/http.vue | 99 ++- .../pages/dag/_source/formModel/tasks/mr.vue | 296 ++++---- .../dag/_source/formModel/tasks/pre_tasks.vue | 23 +- .../dag/_source/formModel/tasks/procedure.vue | 21 +- .../dag/_source/formModel/tasks/python.vue | 200 +++-- .../dag/_source/formModel/tasks/shell.vue | 228 +++--- .../dag/_source/formModel/tasks/spark.vue | 483 ++++++------ .../pages/dag/_source/formModel/tasks/sql.vue | 163 ++-- .../dag/_source/formModel/tasks/sqoop.vue | 670 ++++++++--------- .../_source/formModel/tasks/sub_process.vue | 25 +- .../dag/_source/formModel/tasks/waterdrop.vue | 333 ++++----- .../pages/dag/_source/jumpAffirm/index.js | 43 +- .../pages/dag/_source/plugIn/jsPlumbHandle.js | 83 +-- .../home/pages/dag/_source/plugIn/util.js | 12 +- .../pages/dag/_source/startingParam/index.vue | 15 +- .../dag/_source/udp/_source/selectTenant.vue | 34 +- .../conf/home/pages/dag/_source/udp/udp.vue | 33 +- .../home/pages/dag/_source/variable/index.vue | 2 +- .../dag/_source/variable/variablesView.vue | 16 +- .../conf/home/pages/dag/definitionDetails.vue | 6 +- .../src/js/conf/home/pages/dag/index.vue | 6 +- .../conf/home/pages/dag/instanceDetails.vue | 6 +- .../pages/list/_source/createDataSource.vue | 168 ++--- .../datasource/pages/list/_source/list.vue | 141 ++-- .../pages/datasource/pages/list/index.vue | 66 +- .../src/js/conf/home/pages/home/index.vue | 17 +- .../src/js/conf/home/pages/monitor/index.vue | 6 +- .../servers/_source/zookeeperDirectories.vue | 23 +- .../pages/servers/_source/zookeeperList.vue | 114 +-- .../pages/monitor/pages/servers/apiserver.vue | 6 - .../home/pages/monitor/pages/servers/db.vue | 85 +-- .../pages/monitor/pages/servers/master.vue | 5 +- .../monitor/pages/servers/statistics.vue | 26 +- .../pages/monitor/pages/servers/worker.vue | 28 +- .../pages/_source/conditions/index.vue | 24 + .../instance}/common.js | 0 .../instance/processInstance.vue} | 63 +- .../conditions/instance/taskInstance.vue | 124 +++ .../taskRecordList/_source/conditions.vue | 80 +- .../_source/taskRecordList/_source/list.vue | 98 +-- .../pages/_source/taskRecordList/index.vue | 14 +- .../pages/definition/pages/create/index.vue | 3 +- .../pages/definition/pages/details/index.vue | 3 +- .../definition/pages/list/_source/email.vue | 66 +- .../definition/pages/list/_source/list.vue | 628 +++++++--------- .../pages/list/_source/relatedItems.vue | 45 +- .../definition/pages/list/_source/start.vue | 114 ++- .../definition/pages/list/_source/timing.vue | 218 +++--- .../pages/list/_source/versions.vue | 175 ++--- .../pages/definition/pages/list/index.vue | 32 +- .../pages/definition/pages/tree/index.vue | 34 +- .../pages/definition/timing/_source/list.vue | 240 +++--- .../pages/definition/timing/index.vue | 13 +- .../pages/index/_source/commandStateCount.vue | 4 +- .../pages/index/_source/defineUserCount.vue | 6 +- .../pages/index/_source/processStateCount.vue | 26 +- .../pages/index/_source/queueCount.vue | 6 +- .../pages/index/_source/taskCtatusCount.vue | 145 ---- .../pages/index/_source/taskStatusCount.vue | 8 +- .../home/pages/projects/pages/index/index.vue | 34 +- .../pages/projects/pages/instance/index.vue | 2 +- .../pages/instance/pages/details/index.vue | 5 +- .../pages/instance/pages/gantt/index.vue | 6 +- .../instance/pages/list/_source/list.vue | 487 +++++------- .../pages/instance/pages/list/index.vue | 33 +- .../pages/kinship/_source/graphGrid.vue | 12 +- .../pages/kinship/_source/graphGridOption.js | 53 +- .../pages/projects/pages/kinship/index.vue | 72 +- .../pages/list/_source/createProject.vue | 50 +- .../projects/pages/list/_source/list.vue | 150 ++-- .../home/pages/projects/pages/list/index.vue | 58 +- .../pages/taskInstance/_source/list.vue | 200 ++--- .../projects/pages/taskInstance/index.vue | 40 +- .../pages/projects/pages/timing/index.vue | 2 +- .../src/js/conf/home/pages/resource/index.vue | 5 +- .../home/pages/resource/pages/file/index.vue | 5 +- .../pages/file/pages/create/index.vue | 35 +- .../pages/file/pages/createFolder/index.vue | 44 +- .../file/pages/createUdfFolder/index.vue | 32 +- .../pages/file/pages/details/index.vue | 20 +- .../resource/pages/file/pages/edit/index.vue | 10 +- .../pages/file/pages/list/_source/list.vue | 223 +++--- .../pages/file/pages/list/_source/rename.vue | 32 +- .../resource/pages/file/pages/list/index.vue | 32 +- .../pages/file/pages/subFile/index.vue | 34 +- .../pages/file/pages/subFileFolder/index.vue | 43 +- .../file/pages/subdirectory/_source/list.vue | 221 ++---- .../pages/subdirectory/_source/rename.vue | 32 +- .../pages/file/pages/subdirectory/index.vue | 49 +- .../pages/udf/pages/createUdfFolder/index.vue | 30 +- .../udf/pages/function/_source/createUdf.vue | 84 +-- .../pages/udf/pages/function/_source/list.vue | 196 ++--- .../pages/udf/pages/function/index.vue | 67 +- .../pages/udf/pages/resource/_source/list.vue | 218 +++--- .../udf/pages/resource/_source/rename.vue | 32 +- .../pages/udf/pages/resource/index.vue | 28 +- .../pages/subUdfDirectory/_source/list.vue | 207 ++--- .../pages/subUdfDirectory/_source/rename.vue | 29 +- .../pages/udf/pages/subUdfDirectory/index.vue | 45 +- .../pages/udf/pages/subUdfFolder/index.vue | 29 +- .../src/js/conf/home/pages/security/index.vue | 3 +- .../_source/createWarning.vue | 145 ---- .../pages/alarmPluginExample/_source/list.vue | 224 ------ .../pages/alarmPluginExample/index.vue | 161 ---- .../pages/queue/_source/createQueue.vue | 42 +- .../security/pages/queue/_source/list.vue | 96 +-- .../home/pages/security/pages/queue/index.vue | 69 +- .../pages/tenement/_source/createTenement.vue | 74 +- .../security/pages/tenement/_source/list.vue | 20 +- .../pages/security/pages/tenement/index.vue | 58 +- .../home/pages/security/pages/token/index.vue | 3 +- .../pages/users/_source/createUser.vue | 93 +-- .../security/pages/users/_source/list.vue | 464 +++++------- .../home/pages/security/pages/users/index.vue | 70 +- .../warningGroups/_source/createWarning.vue | 42 +- .../pages/warningGroups/_source/list.vue | 223 ++---- .../security/pages/warningGroups/index.vue | 70 +- .../workerGroups/_source/createWorker.vue | 34 +- .../pages/workerGroups/_source/list.vue | 68 +- .../security/pages/workerGroups/index.vue | 43 +- .../src/js/conf/home/pages/user/index.vue | 5 +- .../pages/user/pages/account/_source/info.vue | 58 +- .../home/pages/user/pages/account/index.vue | 5 +- .../user/pages/password/_source/info.vue | 14 +- .../home/pages/user/pages/password/index.vue | 5 +- .../user/pages/token/_source/createToken.vue | 55 +- .../pages/user/pages/token/_source/list.vue | 112 +-- .../home/pages/user/pages/token/index.vue | 71 +- .../src/js/conf/home/router/index.js | 8 - .../src/js/conf/home/store/dag/actions.js | 18 +- .../src/js/conf/home/store/dag/mutations.js | 4 +- .../src/js/conf/home/store/kinship/actions.js | 26 +- .../js/conf/home/store/projects/mutations.js | 6 + .../src/js/conf/home/store/projects/state.js | 2 +- .../js/conf/home/store/security/actions.js | 2 +- dolphinscheduler-ui/src/js/conf/login/App.vue | 34 +- .../src/js/conf/login/index.js | 10 +- .../src/js/module/axios/jsonp.js | 20 +- .../src/js/module/axios/querystring.js | 14 +- .../components/conditions/conditions.vue | 10 +- .../crontab/source/_source/input-number.vue | 9 +- .../components/crontab/source/_times/day.vue | 136 ++-- .../components/crontab/source/_times/hour.vue | 38 +- .../crontab/source/_times/minute.vue | 38 +- .../crontab/source/_times/month.vue | 38 +- .../crontab/source/_times/second.vue | 38 +- .../components/crontab/source/_times/year.vue | 40 +- .../module/components/crontab/source/app.vue | 14 +- .../components/crontab/source/index.scss | 2 +- .../components/crontab/source/util/index.js | 2 +- .../fileUpdate/definitionUpdate.vue | 42 +- .../fileUpdate/fileChildReUpdate.vue | 333 +++++++++ .../components/fileUpdate/fileChildUpdate.vue | 53 +- .../components/fileUpdate/fileReUpload.vue | 332 +++++++++ .../components/fileUpdate/fileUpdate.vue | 52 +- .../fileUpdate/resourceChildUpdate.vue | 53 +- .../components/fileUpdate/udfUpdate.vue | 26 +- .../js/module/components/layout/layout.vue | 6 +- .../listConstruction/listConstruction.vue | 1 + .../src/js/module/components/nav/nav.vue | 355 +++++---- .../src/js/module/components/popup/popup.vue | 1 - .../module/components/priority/priority.vue | 52 +- .../components/secondaryMenu/_source/menu.js | 41 +- .../secondaryMenu/secondaryMenu.vue | 12 +- .../components/tooltipsJSON/tooltipsJSON.vue | 10 +- .../module/components/transfer/resource.vue | 183 ++--- .../module/components/transfer/transfer.vue | 71 +- .../src/js/module/download/index.js | 4 +- .../src/js/module/filter/filter.js | 28 +- .../src/js/module/filter/filterNull.js | 24 + .../src/js/module/i18n/locale/en_US.js | 110 +-- .../src/js/module/i18n/locale/zh_CN.js | 106 +-- dolphinscheduler-ui/src/js/module/io/index.js | 2 +- .../src/js/module/permissions/index.js | 1 + .../src/js/module/util/localStorage.js | 6 +- .../src/js/module/visibility/index.js | 70 ++ .../src/sass/common/_table.scss | 6 + .../src/sass/common/index.scss | 6 +- .../src/sass/conf/login/index.scss | 2 +- .../data/project/CreateProjectData.java | 26 + .../data/project/CreateWorkflowData.java | 77 ++ .../locator/project/CreateProjectLocator.java | 47 ++ .../project/CreateWorkflowLocator.java | 183 +++++ .../locator/security/TenantManageLocator.java | 8 +- .../page/project/CreateProjectPage.java | 74 ++ .../page/project/CreateWorkflowPage.java | 201 +++++ .../page/security/TenantManagePage.java | 3 +- .../deleteData/DeleteProjectTest.java | 39 + .../testcase/deleteData/DeleteTenantTest.java | 38 + .../testcase/deleteData/DeleteUserTest.java | 42 ++ .../deleteData/DeleteWorkflowTest.java | 43 ++ .../resources/testData/security_zh_cn.yml | 1 - e2e/testng.xml | 8 +- 234 files changed, 8445 insertions(+), 8595 deletions(-) create mode 100644 dolphinscheduler-ui/.eslintignore create mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/jsonBox.vue create mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/list4Box.vue create mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/_source/conditions/index.vue rename dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/_source/{instanceConditions => conditions/instance}/common.js (100%) rename dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/_source/{instanceConditions/index.vue => conditions/instance/processInstance.vue} (55%) create mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/_source/conditions/instance/taskInstance.vue delete mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/taskCtatusCount.vue delete mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/security/pages/alarmPluginExample/_source/createWarning.vue delete mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/security/pages/alarmPluginExample/_source/list.vue delete mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/security/pages/alarmPluginExample/index.vue create mode 100644 dolphinscheduler-ui/src/js/module/components/fileUpdate/fileChildReUpdate.vue create mode 100644 dolphinscheduler-ui/src/js/module/components/fileUpdate/fileReUpload.vue create mode 100644 dolphinscheduler-ui/src/js/module/filter/filterNull.js create mode 100644 dolphinscheduler-ui/src/js/module/visibility/index.js create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateProjectData.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateWorkflowData.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateProjectLocator.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateWorkflowLocator.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateProjectPage.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateWorkflowPage.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteProjectTest.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteTenantTest.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteUserTest.java create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteWorkflowTest.java diff --git a/dolphinscheduler-ui/.babelrc b/dolphinscheduler-ui/.babelrc index aeb5ba2059..5fe8580fed 100644 --- a/dolphinscheduler-ui/.babelrc +++ b/dolphinscheduler-ui/.babelrc @@ -5,7 +5,15 @@ "debug": false, "useBuiltIns": true, "targets": { - "browsers": [ "ie > 8", "last 2 version", "safari >= 9" ] + "browsers": [ + "> 1%", + "last 2 versions", + "ie >= 9", + "edge >= 12", + "firefox >= 28", + "chrome >= 29", + "opera >= 17" + ] }, "production": { "plugins": ["transform-remove-console"] diff --git a/dolphinscheduler-ui/.eslintignore b/dolphinscheduler-ui/.eslintignore new file mode 100644 index 0000000000..cd1b8213b3 --- /dev/null +++ b/dolphinscheduler-ui/.eslintignore @@ -0,0 +1,7 @@ +/_test_/ +/build/ +/dist/ +/node/ +/node_modules/ +/target/ +/*.js diff --git a/dolphinscheduler-ui/.eslintrc.yml b/dolphinscheduler-ui/.eslintrc.yml index 8d4020f7c4..64c83e6ac0 100644 --- a/dolphinscheduler-ui/.eslintrc.yml +++ b/dolphinscheduler-ui/.eslintrc.yml @@ -26,9 +26,19 @@ globals: Atomics: readonly SharedArrayBuffer: readonly PUBLIC_PATH: readonly + $t: readonly parserOptions: ecmaVersion: 2018 sourceType: module plugins: - vue -rules: {} +rules: + vue/script-indent: ['error', 2, { 'baseIndent': 1, 'switchCase': 1 }] + prefer-promise-reject-errors: 'off' + no-prototype-builtins: 'off' + no-mixed-operators: 'off' + no-extend-native: 'off' + prefer-const: 'off' + no-var: 'error' +overrides: + - { 'files': ['*.vue'], 'rules': { 'indent': 'off' }} diff --git a/dolphinscheduler-ui/build/config.js b/dolphinscheduler-ui/build/config.js index 11bbec550f..1186066e7f 100644 --- a/dolphinscheduler-ui/build/config.js +++ b/dolphinscheduler-ui/build/config.js @@ -47,7 +47,7 @@ const jsEntry = (() => { parts.shift() let modules = parts.join('/') let entry = moduleName(modules) - obj[entry] = val + obj[entry] = ['babel-polyfill', val] }) return obj })() @@ -125,6 +125,16 @@ const baseConfig = { }, module: { rules: [ + { + test: /\.(js|vue)$/, + loader: 'eslint-loader', + enforce: 'pre', + include: [resolve('src')], + options: { + formatter: require('eslint-friendly-formatter'), + emitWarning: true + } + }, { test: /\.vue$/, loader: 'vue-loader', diff --git a/dolphinscheduler-ui/build/webpack.config.dev.js b/dolphinscheduler-ui/build/webpack.config.dev.js index d443bf8366..ea250330ad 100644 --- a/dolphinscheduler-ui/build/webpack.config.dev.js +++ b/dolphinscheduler-ui/build/webpack.config.dev.js @@ -19,6 +19,8 @@ const merge = require('webpack-merge') const { assetsDir, baseConfig } = require('./config') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const ProgressPlugin = require('progress-bar-webpack-plugin') +const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') +const portfinder = require('portfinder') const getEnv = require('env-parse').getEnv const config = merge.smart(baseConfig, { @@ -33,6 +35,7 @@ const config = merge.smart(baseConfig, { port: getEnv('DEV_PORT', 8888), host: getEnv('DEV_HOST', 'localhost'), noInfo: false, + overlay: { warnings: false, errors: true }, historyApiFallback: true, disableHostCheck: true, proxy: { @@ -42,12 +45,12 @@ const config = merge.smart(baseConfig, { changeOrigin: true } }, - progress: false, - quiet: false, + progress: true, + quiet: true, stats: { colors: true }, - clientLogLevel: 'none' + clientLogLevel: 'warning' }, plugins: [ new ProgressPlugin(), @@ -57,4 +60,36 @@ const config = merge.smart(baseConfig, { mode: 'development' }) -module.exports = config +module.exports = new Promise((resolve, reject) => { + portfinder.basePort = process.env.PORT || config.devServer.port + portfinder.getPort((err, port) => { + if (err) { + reject(err) + } else { + // publish the new Port, necessary for e2e tests + process.env.PORT = port + // add port to devServer config + config.devServer.port = port + // Add FriendlyErrorsPlugin + config.plugins.push(new FriendlyErrorsPlugin({ + compilationSuccessInfo: { + messages: [`Your application is running here: http://${config.devServer.host}:${port}`], + }, + onErrors: () => { + const notifier = require('node-notifier') + return (severity, errors) => { + if (severity !== 'error') return + const error = errors[0] + const filename = error.file && error.file.split('!').pop() + notifier.notify({ + title: packageConfig.name, + message: severity + ': ' + error.name, + subtitle: filename || '' + }) + } + } + })) + resolve(config) + } + }) +}) diff --git a/dolphinscheduler-ui/build/webpack.config.prod.js b/dolphinscheduler-ui/build/webpack.config.prod.js index 4bb90d54d1..1024ac6724 100644 --- a/dolphinscheduler-ui/build/webpack.config.prod.js +++ b/dolphinscheduler-ui/build/webpack.config.prod.js @@ -51,12 +51,7 @@ const config = merge.smart(baseConfig, { minimizer: [ new TerserPlugin({ terserOptions: { - compress: { - warnings: false, - drop_console: true, - drop_debugger: true, - pure_funcs: ['console.log'] - } + compress: {} }, cache: true, parallel: true, diff --git a/dolphinscheduler-ui/package.json b/dolphinscheduler-ui/package.json index af0ac54b0c..609dd1043a 100644 --- a/dolphinscheduler-ui/package.json +++ b/dolphinscheduler-ui/package.json @@ -8,13 +8,12 @@ "dev": "cross-env NODE_ENV=development webpack-dev-server --config ./build/webpack.config.dev.js", "clean": "rimraf dist", "start": "npm run dev", - "lint": "eslint ./src --fix", + "lint": "eslint --ext .js,.vue ./src", + "lint:fix": "eslint --ext .js,.vue --fix ./src", "build:release": "npm run clean && cross-env NODE_ENV=production PUBLIC_PATH=/dolphinscheduler/ui webpack --config ./build/webpack.config.release.js" }, "dependencies": { - "@form-create/element-ui": "^1.0.18", "@riophae/vue-treeselect": "^0.4.0", - "ans-ui": "1.1.9", "axios": "^0.16.2", "bootstrap": "3.3.7", "canvg": "1.5.1", @@ -25,6 +24,7 @@ "dayjs": "^1.7.8", "echarts": "4.1.0", "element-ui": "2.13.2", + "font-awesome": "^4.7.0", "html2canvas": "^0.5.0-beta4", "jquery": "3.3.1", "jquery-ui": "^1.12.1", @@ -33,7 +33,7 @@ "lodash": "^4.17.11", "normalize.css": "^8.0.1", "vue": "^2.5.17", - "vue-router": "^2.7.0", + "vue-router": "^3.0.0", "vuex": "^3.0.0", "vuex-router-sync": "^5.0.0" }, @@ -48,6 +48,7 @@ "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-vue-jsx": "^3.5.0", + "babel-polyfill": "^6.26.0", "babel-preset-env": "^1.6.1", "copy-webpack-plugin": "^4.5.2", "cross-env": "^5.2.0", @@ -56,17 +57,23 @@ "env-parse": "^1.0.5", "eslint": "^6.8.0", "eslint-config-standard": "^14.1.1", + "eslint-friendly-formatter": "^4.0.1", + "eslint-loader": "^4.0.2", "eslint-plugin-import": "^2.20.2", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", - "eslint-plugin-vue": "^6.2.2", + "eslint-plugin-vue": "^7.2.0", "file-loader": "^5.0.2", + "friendly-errors-webpack-plugin": "^1.7.0", "globby": "^8.0.1", "html-loader": "^0.5.5", "html-webpack-plugin": "^3.2.0", "mini-css-extract-plugin": "^0.8.2", + "node-notifier": "^8.0.0", "node-sass": "^4.14.1", + "pack": "^2.2.0", + "portfinder": "^1.0.28", "postcss-loader": "^3.0.0", "progress-bar-webpack-plugin": "^1.12.1", "rimraf": "^2.6.2", @@ -80,5 +87,14 @@ "webpack-cli": "^3.3.10", "webpack-dev-server": "^3.9.0", "webpack-merge": "^4.2.2" - } + }, + "browserslist": [ + "> 1%", + "last 2 versions", + "ie >= 9", + "edge >= 12", + "firefox >= 28", + "chrome >= 29", + "opera >= 17" + ] } diff --git a/dolphinscheduler-ui/pom.xml b/dolphinscheduler-ui/pom.xml index 13644bad91..1263502cc3 100644 --- a/dolphinscheduler-ui/pom.xml +++ b/dolphinscheduler-ui/pom.xml @@ -20,7 +20,7 @@ dolphinscheduler org.apache.dolphinscheduler - 1.3.2-SNAPSHOT + 1.3.4-SNAPSHOT 4.0.0 @@ -203,5 +203,4 @@ - - + \ No newline at end of file diff --git a/dolphinscheduler-ui/src/components/Counter.vue b/dolphinscheduler-ui/src/components/Counter.vue index 6fafb5a54e..74dbfcd8de 100644 --- a/dolphinscheduler-ui/src/components/Counter.vue +++ b/dolphinscheduler-ui/src/components/Counter.vue @@ -24,30 +24,30 @@ \ No newline at end of file + diff --git a/dolphinscheduler-ui/src/components/Message.vue b/dolphinscheduler-ui/src/components/Message.vue index 95f5236b6e..aba5ea6a56 100644 --- a/dolphinscheduler-ui/src/components/Message.vue +++ b/dolphinscheduler-ui/src/components/Message.vue @@ -19,10 +19,10 @@ \ No newline at end of file + export default { + name: 'message', + props: [ + 'msg' + ] + } + diff --git a/dolphinscheduler-ui/src/js/conf/home/App.vue b/dolphinscheduler-ui/src/js/conf/home/App.vue index 97110e580c..2d7a5f3328 100644 --- a/dolphinscheduler-ui/src/js/conf/home/App.vue +++ b/dolphinscheduler-ui/src/js/conf/home/App.vue @@ -17,15 +17,36 @@ diff --git a/dolphinscheduler-ui/src/js/conf/home/index.js b/dolphinscheduler-ui/src/js/conf/home/index.js index 381e2030b7..8db055a36a 100644 --- a/dolphinscheduler-ui/src/js/conf/home/index.js +++ b/dolphinscheduler-ui/src/js/conf/home/index.js @@ -17,6 +17,7 @@ // The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. +import 'babel-polyfill' import Vue from 'vue' import ElementUI from 'element-ui' import locale from 'element-ui/lib/locale/lang/en' @@ -28,29 +29,23 @@ import i18n from '@/module/i18n' import { sync } from 'vuex-router-sync' import Chart from '@/module/ana-charts' import '@/module/filter/formatDate' +import '@/module/filter/filterNull' import themeData from '@/module/echarts/themeData.json' import Permissions from '@/module/permissions' -import 'ans-ui/lib/ans-ui.min.css' -import ans from 'ans-ui/lib/ans-ui.min' -import en_US from 'ans-ui/lib/locale/en' // eslint-disable-line import 'sass/conf/home/index.scss' import 'bootstrap/dist/css/bootstrap.min.css' import 'bootstrap/dist/js/bootstrap.min.js' import 'canvg/dist/browser/canvg.min.js' - -import formCreate, {maker} from '@form-create/element-ui' +import 'font-awesome/css/font-awesome.min.css' // Component internationalization -const useOpt = i18n.globalScope.LOCALE === 'en_US' ? { locale: en_US } : {} +const useOpt = i18n.globalScope.LOCALE === 'en_US' ? { locale: locale } : {} i18n.globalScope.LOCALE === 'en_US' ? Vue.use(ElementUI, { locale }) : Vue.use(ElementUI) - // Vue.use(ans) -Vue.use(ans, useOpt) - -Vue.use(formCreate, {maker}) +Vue.use(useOpt) sync(store, router) diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/config.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/config.js index 18fbd94341..566896a2ff 100755 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/config.js +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/config.js @@ -29,31 +29,31 @@ const toolOper = (dagThis) => { return [ { code: 'pointer', - icon: 'ans-icon-pointer', + icon: 'el-icon-thumb', disable: disabled, desc: `${i18n.$t('Drag Nodes and Selected Items')}` }, { code: 'line', - icon: 'ans-icon-slash', + icon: 'el-icon-top-right', disable: disabled, desc: `${i18n.$t('Select Line Connection')}` }, { code: 'remove', - icon: 'ans-icon-trash', + icon: 'el-icon-delete', disable: disabled, desc: `${i18n.$t('Delete selected lines or nodes')}` }, { code: 'download', - icon: 'ans-icon-download', + icon: 'el-icon-download', disable: !dagThis.type, desc: `${i18n.$t('Download')}` }, { code: 'screen', - icon: 'ans-icon-max', + icon: 'el-icon-full-screen', disable: false, desc: `${i18n.$t('Full Screen')}` } @@ -150,98 +150,98 @@ const tasksState = { id: 0, desc: `${i18n.$t('Submitted successfully')}`, color: '#A9A9A9', - icoUnicode: 'ans-icon-dot-circle', + icoUnicode: 'fa fa-dot-circle-o', isSpin: false }, RUNNING_EXECUTION: { id: 1, desc: `${i18n.$t('Executing')}`, color: '#0097e0', - icoUnicode: 'ans-icon-gear', + icoUnicode: 'el-icon-s-tools', isSpin: true }, READY_PAUSE: { id: 2, desc: `${i18n.$t('Ready to pause')}`, color: '#07b1a3', - icoUnicode: 'ans-icon-pause-solid', + icoUnicode: 'fa-pause-circle', isSpin: false }, PAUSE: { id: 3, desc: `${i18n.$t('Pause')}`, color: '#057c72', - icoUnicode: 'ans-icon-pause', + icoUnicode: 'el-icon-video-pause', isSpin: false }, READY_STOP: { id: 4, desc: `${i18n.$t('Ready to stop')}`, color: '#FE0402', - icoUnicode: 'ans-icon-coin', + icoUnicode: 'fa-stop-circle-o', isSpin: false }, STOP: { id: 5, desc: `${i18n.$t('Stop')}`, color: '#e90101', - icoUnicode: 'ans-icon-stop', + icoUnicode: 'fa-stop-circle', isSpin: false }, FAILURE: { id: 6, desc: `${i18n.$t('failed')}`, color: '#000000', - icoUnicode: 'ans-icon-fail-empty', + icoUnicode: 'el-icon-circle-close', isSpin: false }, SUCCESS: { id: 7, desc: `${i18n.$t('success')}`, color: '#33cc00', - icoUnicode: 'ans-icon-success-empty', + icoUnicode: 'el-icon-circle-check', isSpin: false }, NEED_FAULT_TOLERANCE: { id: 8, desc: `${i18n.$t('Need fault tolerance')}`, color: '#FF8C00', - icoUnicode: 'ans-icon-pen', + icoUnicode: 'el-icon-edit', isSpin: false }, KILL: { id: 9, desc: `${i18n.$t('kill')}`, color: '#a70202', - icoUnicode: 'ans-icon-minus-circle-empty', + icoUnicode: 'el-icon-remove-outline', isSpin: false }, WAITTING_THREAD: { id: 10, desc: `${i18n.$t('Waiting for thread')}`, color: '#912eed', - icoUnicode: 'ans-icon-sand-clock', + icoUnicode: 'fa-hourglass-end', isSpin: false }, WAITTING_DEPEND: { id: 11, desc: `${i18n.$t('Waiting for dependence')}`, color: '#5101be', - icoUnicode: 'ans-icon-dependence', + icoUnicode: 'fa-window-restore', isSpin: false }, DELAY_EXECUTION: { id: 12, desc: `${i18n.$t('Delay execution')}`, color: '#5102ce', - icoUnicode: 'ans-icon-coin', + icoUnicode: 'fa-stop-circle-o', isSpin: false }, FORCED_SUCCESS: { id: 13, desc: `${i18n.$t('Forced success')}`, color: '#5102ce', - icoUnicode: 'ans-icon-success-solid', + icoUnicode: 'el-icon-success', isSpin: false } } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js index d7f2f78a0c..e98cda22fd 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.js @@ -15,14 +15,13 @@ * limitations under the License. */ import Vue from 'vue' -let v = new Vue() import _ from 'lodash' import i18n from '@/module/i18n' import { jsPlumb } from 'jsplumb' import JSP from './plugIn/jsPlumbHandle' import DownChart from './plugIn/downChart' import store from '@/conf/home/store' -import dagre from "dagre" +import dagre from 'dagre' /** * Prototype method @@ -53,7 +52,9 @@ Dag.prototype.setConfig = function (o) { */ Dag.prototype.create = function () { const self = this - jsPlumb.ready(() => { + const plumbIns = jsPlumb.getInstance() + plumbIns.reset() + plumbIns.ready(() => { JSP.init({ dag: this.dag, instance: this.instance, @@ -76,7 +77,7 @@ Dag.prototype.create = function () { * Action event on the right side of the toolbar */ Dag.prototype.toolbarEvent = function ({ item, code, is }) { - let self = this + const self = this switch (code) { case 'pointer': JSP.handleEventPointer(is) @@ -91,21 +92,15 @@ Dag.prototype.toolbarEvent = function ({ item, code, is }) { JSP.handleEventScreen({ item, is }) break case 'download': - v.$modal.dialog({ - width: 350, - closable: false, - showMask: true, - maskClosable: true, - title: i18n.$t('Download'), - content: i18n.$t('Please confirm whether the workflow has been saved before downloading'), - ok: { - handle (e) { - DownChart.download({ - dagThis: self.dag - }) - } - }, - cancel: {} + Vue.prototype.$confirm(`${i18n.$t('Please confirm whether the workflow has been saved before downloading')}`, `${i18n.$t('Download')}`, { + confirmButtonText: `${i18n.$t('Confirm')}`, + cancelButtonText: `${i18n.$t('Cancel')}`, + type: 'warning' + }).then(() => { + DownChart.download({ + dagThis: self.dag + }) + }).catch(() => { }) break } @@ -128,17 +123,19 @@ Dag.prototype.backfill = function (arg) { for (const i in store.state.dag.connects) { const connect = store.state.dag.connects[i] - g.setEdge(connect['endPointSourceId'], connect['endPointTargetId']) + g.setEdge(connect.endPointSourceId, connect.endPointTargetId) } dagre.layout(g) const dataObject = {} g.nodes().forEach(function (v) { const node = g.node(v) + const location = store.state.dag.locations[node.label] const obj = {} - obj.name = node.label + obj.name = location.name obj.x = node.x + marginX obj.y = node.y + obj.targetarr = location.targetarr dataObject[node.label] = obj }) jsPlumb.ready(() => { @@ -162,7 +159,9 @@ Dag.prototype.backfill = function (arg) { }) }) } else { - jsPlumb.ready(() => { + const plumbIns = jsPlumb.getInstance() + plumbIns.reset() + plumbIns.ready(() => { JSP.init({ dag: this.dag, instance: this.instance, diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss index 88f2d11c8f..41a44bc17a 100755 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.scss @@ -207,7 +207,6 @@ .operation { overflow: hidden; display: inline-block; - margin-right: 10px; a { float: left; width: 28px; @@ -277,8 +276,9 @@ svg path:hover { background: #fff; border-radius: 3px; box-shadow: 0 2px 4px 1px rgba(0, 0, 0, 0.1); - padding: 4px 0; + padding: 4px 4px; visibility:hidden; + z-index: 10000; a { height: 30px; line-height: 28px; diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue index 1880adc51b..a61d289d3d 100755 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/dag.vue @@ -34,31 +34,33 @@

- - - - + @click="_toggleView" + icon="el-icon-c-scale-to-original"> + + + + + {{name}}   - +
@@ -68,71 +70,75 @@ :id="item.code" :key="$index" @click="_ckOperation(item,$event)"> - +
- - - - - + + + + + + {{$t('Return_1')}} - - - {{$t('Close')}} - - + + + {{$t('Close')}} + + + {{spinnerLoading ? 'Loading...' : $t('Save')}} - - - {{spinnerLoading ? 'Loading...' : $t('Version Info')}} - + + + + {{spinnerLoading ? 'Loading...' : $t('Version Info')}} + +
@@ -140,6 +146,44 @@
+ + + + + + + + + + + + + + + + + + @@ -158,6 +202,7 @@ import { findComponentDownward } from '@/module/util/' import disabledState from '@/module/mixin/disabledState' import { mapActions, mapState, mapMutations } from 'vuex' + import mStart from '../../projects/pages/definition/pages/list/_source/start' import mVersions from '../../projects/pages/definition/pages/list/_source/versions' let eventModel @@ -179,7 +224,39 @@ isLoading: false, taskId: null, arg: false, - + versionData: { + processDefinition: { + id: null, + version: '', + state: '' + }, + processDefinitionVersions: [], + total: null, + pageNo: null, + pageSize: null + }, + drawer: false, + nodeData: { + id: null, + taskType: '', + self: {}, + preNode: [], + rearList: [], + instanceId: null + }, + nodeDrawer: false, + lineData: { + id: null, + sourceId: '', + targetId: '' + }, + lineDrawer: false, + udpDrawer: false, + dialogVisible: false, + startDialog: false, + startData: {}, + startNodeList: '', + sourceType: '' } }, mixins: [disabledState], @@ -190,43 +267,54 @@ methods: { ...mapActions('dag', ['saveDAGchart', 'updateInstance', 'updateDefinition', 'getTaskState', 'switchProcessDefinitionVersion', 'getProcessDefinitionVersionsPage', 'deleteProcessDefinitionVersion']), ...mapMutations('dag', ['addTasks', 'cacheTasks', 'resetParams', 'setIsEditDag', 'setName', 'addConnects']), - + startRunning (item, startNodeList, sourceType) { + this.startData = item + this.startNodeList = startNodeList + this.sourceType = sourceType + this.startDialog = true + }, + onUpdateStart () { + this.startDialog = false + }, + closeStart () { + this.startDialog = false + }, // DAG automatic layout - dagAutomaticLayout() { - if(this.store.state.dag.isEditDag) { + dagAutomaticLayout () { + if (this.store.state.dag.isEditDag) { this.$message.warning(`${i18n.$t('Please save the DAG before formatting')}`) return false } $('#canvas').html('') - // Destroy round robin + // Destroy round robin Dag.init({ - dag: this, - instance: jsPlumb.getInstance({ - Endpoint: [ - 'Dot', { radius: 1, cssClass: 'dot-style' } - ], - Connector: 'Bezier', - PaintStyle: { lineWidth: 2, stroke: '#456' }, // Connection style - ConnectionOverlays: [ - [ - 'Arrow', - { - location: 1, - id: 'arrow', - length: 12, - foldback: 0.8 - } + dag: this, + instance: jsPlumb.getInstance({ + Endpoint: [ + 'Dot', { radius: 1, cssClass: 'dot-style' } ], - ['Label', { + Connector: 'Bezier', + PaintStyle: { lineWidth: 2, stroke: '#456' }, // Connection style + ConnectionOverlays: [ + [ + 'Arrow', + { + location: 1, + id: 'arrow', + length: 12, + foldback: 0.8 + } + ], + ['Label', { location: 0.5, id: 'label' - }] - ], - Container: 'canvas', - ConnectionsDetachable: true + }] + ], + Container: 'canvas', + ConnectionsDetachable: true + }) }) - }) if (this.tasks.length) { Dag.backfill(true) if (this.type === 'instance') { @@ -255,8 +343,8 @@ /** * copy name */ - _copyName(){ - let clipboard = new Clipboard(`.copy-name`) + _copyName () { + let clipboard = new Clipboard('.copy-name') clipboard.on('success', e => { this.$message.success(`${i18n.$t('Copy success')}`) // Free memory @@ -294,8 +382,8 @@ let dom = $(`#${v2.id}`) let state = dom.find('.state-p') let depState = '' - taskList.forEach(item=>{ - if(item.name==v1.name) { + taskList.forEach(item => { + if (item.name === v1.name) { depState = item.state } }) @@ -371,7 +459,7 @@ this.spinnerLoading = true // Storage store Dag.saveStore().then(res => { - if(this._verifConditions(res.tasks)) { + if (this._verifConditions(res.tasks)) { if (this.urlParam.id) { /** * Edit @@ -379,7 +467,12 @@ * @param saveEditDAGChart => Process definition editing */ this[this.type === 'instance' ? 'updateInstance' : 'updateDefinition'](this.urlParam.id).then(res => { - this.$message.success(res.msg) + // this.$message.success(res.msg) + this.$message({ + message: res.msg, + type: 'success', + offset: 80 + }) this.spinnerLoading = false // Jump process definition if (this.type === 'instance') { @@ -415,57 +508,36 @@ }) }) }, - _closeDAG(){ + _closeDAG () { let $name = this.$route.name - if($name && $name.indexOf("definition") != -1){ - this.$router.push({ name: 'projects-definition-list'}) - }else{ - this.$router.push({ name: 'projects-instance-list'}) + if ($name && $name.indexOf('definition') !== -1) { + this.$router.push({ name: 'projects-definition-list' }) + } else { + this.$router.push({ name: 'projects-instance-list' }) } }, _verifConditions (value) { let tasks = value let bool = true - tasks.map(v=>{ - if(v.type == 'CONDITIONS' && (v.conditionResult.successNode[0] =='' || v.conditionResult.successNode[0] == null || v.conditionResult.failedNode[0] =='' || v.conditionResult.failedNode[0] == null)) { + tasks.map(v => { + if (v.type === 'CONDITIONS' && (v.conditionResult.successNode[0] === '' || v.conditionResult.successNode[0] === null || v.conditionResult.failedNode[0] === '' || v.conditionResult.failedNode[0] === null)) { bool = false return false } }) - if(!bool) { + if (!bool) { this.$message.warning(`${i18n.$t('Successful branch flow and failed branch flow are required')}`) this.spinnerLoading = false return false } return true }, - /** - * Global parameter - * @param Promise - */ - _udpTopFloorPop () { - return new Promise((resolve, reject) => { - let modal = this.$modal.dialog({ - closable: false, - showMask: true, - escClose: true, - className: 'v-modal-custom', - transitionName: 'opacityp', - render (h) { - return h(mUdp, { - on: { - onUdp () { - modal.remove() - resolve() - }, - close () { - modal.remove() - } - } - }) - } - }) - }) + onUdpDialog () { + this._save() + this.dialogVisible = false + }, + closeDialog () { + this.dialogVisible = false }, /** * Save chart @@ -476,11 +548,7 @@ this.$message.warning(`${i18n.$t('Failed to create node to save')}`) return } - - // Global parameters (optional) - this._udpTopFloorPop().then(() => { - return this._save() - }) + this.dialogVisible = true }, /** * Return to the previous child node @@ -531,63 +599,75 @@ * View variables */ _toggleView () { - findComponentDownward(this.$root, `assist-dag-index`)._toggleView() + findComponentDownward(this.$root, 'assist-dag-index')._toggleView() }, /** * Starting parameters */ _toggleParam () { - findComponentDownward(this.$root, `starting-params-dag-index`)._toggleParam() + findComponentDownward(this.$root, 'starting-params-dag-index')._toggleParam() + }, + addLineInfo ({ item, fromThis }) { + this.addConnects(item) + this.lineDrawer = false }, + cancel ({ fromThis }) { + this.lineDrawer = false + }, + /** * Create a node popup layer * @param Object id */ - _createLineLabel({id, sourceId, targetId}) { - // $('#jsPlumb_2_50').text('111') - let self = this - self.$modal.destroy() - const removeNodesEvent = (fromThis) => { - // Manually destroy events inside the component - fromThis.$destroy() - // Close the popup - eventModel.remove() - } - eventModel = this.$drawer({ - className: 'dagMask', - render (h) { - return h(mFormLineModel,{ - on: { - addLineInfo ({ item, fromThis }) { - self.addConnects(item) - setTimeout(() => { - removeNodesEvent(fromThis) - }, 100) - }, - cancel ({fromThis}) { - removeNodesEvent(fromThis) - } - }, - props: { - id: id, - sourceId: sourceId, - targetId: targetId - } - }) + _createLineLabel ({ id, sourceId, targetId }) { + this.lineData.id = id + this.lineData.sourceId = sourceId + this.lineData.targetId = targetId + this.lineDrawer = true + }, + + seeHistory (taskName) { + this.nodeData.self.$router.push({ + name: 'task-instance', + query: { + processInstanceId: this.nodeData.self.$route.params.id, + taskName: taskName } }) }, + + addTaskInfo ({ item, fromThis }) { + this.addTasks(item) + this.nodeDrawer = false + }, + + cacheTaskInfo ({ item, fromThis }) { + this.cacheTasks(item) + }, + + close ({ item, flag, fromThis }) { + this.addTasks(item) + // Edit status does not allow deletion of nodes + if (flag) { + jsPlumb.remove(this.nodeData.id) + } + this.nodeDrawer = false + }, + onSubProcess ({ subProcessId, fromThis }) { + this._subProcessHandle(subProcessId) + }, + _createNodes ({ id, type }) { let self = this let preNode = [] let rearNode = [] let rearList = [] - $('div[data-targetarr*="' + id + '"]').each(function(){ - rearNode.push($(this).attr("id")) + $('div[data-targetarr*="' + id + '"]').each(function () { + rearNode.push($(this).attr('id')) }) - if (rearNode.length>0) { + if (rearNode.length > 0) { rearNode.forEach(v => { let rearobj = {} rearobj.value = $(`#${v}`).find('.name-p').text() @@ -609,78 +689,96 @@ } else { preNode = [] } - if (eventModel) { - // Close the popup - eventModel.remove() - } - - const removeNodesEvent = (fromThis) => { - // Manually destroy events inside the component - fromThis.$destroy() - // Close the popup - eventModel.remove() - } this.taskId = id type = type || self.dagBarId - eventModel = this.$drawer({ - closable: false, - direction: 'right', - escClose: true, - className: 'dagMask', - render: h => h(mFormModel, { - on: { - addTaskInfo ({ item, fromThis }) { - self.addTasks(item) - setTimeout(() => { - removeNodesEvent(fromThis) - }, 100) - }, - /** - * Cache the item - * @param item - * @param fromThis - */ - cacheTaskInfo({item, fromThis}) { - self.cacheTasks(item) - }, - close ({ item,flag, fromThis }) { - self.addTasks(item) - // Edit status does not allow deletion of nodes - if (flag) { - jsPlumb.remove(id) - } + this.nodeData.id = id + this.nodeData.taskType = type + this.nodeData.self = self + this.nodeData.preNode = preNode + this.nodeData.rearList = rearList + this.nodeData.instanceId = this.$route.params.id - removeNodesEvent(fromThis) - }, - onSubProcess ({ subProcessId, fromThis }) { - removeNodesEvent(fromThis) - self._subProcessHandle(subProcessId) - } - }, - props: { - id: id, - taskType: type, - self: self, - preNode: preNode, - rearList: rearList, - instanceId: this.$route.params.id - } - }) - }) + this.nodeDrawer = true }, removeEventModelById ($id) { - if(eventModel && this.taskId == $id){ + if (eventModel && this.taskId === $id) { eventModel.remove() } }, + /** + * switch version in process definition version list + * + * @param version the version user want to change + * @param processDefinitionId the process definition id + * @param fromThis fromThis + */ + mVersionSwitchProcessDefinitionVersion ({ version, processDefinitionId, fromThis }) { + this.$store.state.dag.isSwitchVersion = true + this.switchProcessDefinitionVersion({ + version: version, + processDefinitionId: processDefinitionId + }).then(res => { + this.$message.success($t('Switch Version Successfully')) + this.$router.push({ path: `/projects/definition/list/${processDefinitionId}?_t=${new Date().getTime()}` }) + }).catch(e => { + this.$store.state.dag.isSwitchVersion = false + this.$message.error(e.msg || '') + }) + }, + + /** + * Paging event of process definition versions + * + * @param pageNo page number + * @param pageSize page size + * @param processDefinitionId the process definition id of page version + * @param fromThis fromThis + */ + mVersionGetProcessDefinitionVersionsPage ({ pageNo, pageSize, processDefinitionId, fromThis }) { + this.getProcessDefinitionVersionsPage({ + pageNo: pageNo, + pageSize: pageSize, + processDefinitionId: processDefinitionId + }).then(res => { + this.versionData.processDefinitionVersions = res.data.lists + this.versionData.total = res.data.totalCount + this.versionData.pageSize = res.data.pageSize + this.versionData.pageNo = res.data.currentPage + }).catch(e => { + this.$message.error(e.msg || '') + }) + }, + + /** + * delete one version of process definition + * + * @param version the version need to delete + * @param processDefinitionId the process definition id user want to delete + * @param fromThis fromThis + */ + mVersionDeleteProcessDefinitionVersion ({ version, processDefinitionId, fromThis }) { + this.deleteProcessDefinitionVersion({ + version: version, + processDefinitionId: processDefinitionId + }).then(res => { + this.$message.success(res.msg || '') + this.mVersionGetProcessDefinitionVersionsPage({ + pageNo: 1, + pageSize: 10, + processDefinitionId: processDefinitionId, + fromThis: fromThis + }) + }).catch(e => { + this.$message.error(e.msg || '') + }) + }, /** * query the process definition pagination version */ _version (item) { - let self = this this.getProcessDefinitionVersionsPage({ pageNo: 1, pageSize: 10, @@ -690,127 +788,27 @@ let total = res.data.totalCount let pageSize = res.data.pageSize let pageNo = res.data.currentPage - if (this.versionsModel) { - this.versionsModel.remove() - } - this.versionsModel = this.$drawer({ - direction: 'right', - closable: true, - showMask: true, - escClose: true, - render (h) { - return h(mVersions, { - on: { - /** - * switch version in process definition version list - * - * @param version the version user want to change - * @param processDefinitionId the process definition id - * @param fromThis fromThis - */ - mVersionSwitchProcessDefinitionVersion ({ version, processDefinitionId, fromThis }) { - - self.$store.state.dag.isSwitchVersion = true - - self.switchProcessDefinitionVersion({ - version: version, - processDefinitionId: processDefinitionId - }).then(res => { - self.$message.success($t('Switch Version Successfully')) - setTimeout(() => { - fromThis.$destroy() - self.versionsModel.remove() - }, 0) - self.$router.push({ path: `/projects/definition/list/${processDefinitionId}?_t=${new Date().getTime()}` }) - }).catch(e => { - self.$store.state.dag.isSwitchVersion = false - self.$message.error(e.msg || '') - }) - }, - - /** - * Paging event of process definition versions - * - * @param pageNo page number - * @param pageSize page size - * @param processDefinitionId the process definition id of page version - * @param fromThis fromThis - */ - mVersionGetProcessDefinitionVersionsPage ({ pageNo, pageSize, processDefinitionId, fromThis }) { - self.getProcessDefinitionVersionsPage({ - pageNo: pageNo, - pageSize: pageSize, - processDefinitionId: processDefinitionId - }).then(res => { - fromThis.processDefinitionVersions = res.data.lists - fromThis.total = res.data.totalCount - fromThis.pageSize = res.data.pageSize - fromThis.pageNo = res.data.currentPage - }).catch(e => { - self.$message.error(e.msg || '') - }) - }, - - /** - * delete one version of process definition - * - * @param version the version need to delete - * @param processDefinitionId the process definition id user want to delete - * @param fromThis fromThis - */ - mVersionDeleteProcessDefinitionVersion ({ version, processDefinitionId, fromThis }) { - self.deleteProcessDefinitionVersion({ - version: version, - processDefinitionId: processDefinitionId - }).then(res => { - self.$message.success(res.msg || '') - fromThis.$emit('mVersionGetProcessDefinitionVersionsPage', { - pageNo: 1, - pageSize: 10, - processDefinitionId: processDefinitionId, - fromThis: fromThis - }) - }).catch(e => { - self.$message.error(e.msg || '') - }) - }, - - /** - * remove this drawer - * - * @param fromThis - */ - close ({ fromThis }) { - setTimeout(() => { - fromThis.$destroy() - self.versionsModel.remove() - }, 0) - } - }, - props: { - processDefinition: { - id: self.urlParam.id, - version: self.$store.state.dag.version, - state: self.releaseState - }, - processDefinitionVersions: processDefinitionVersions, - total: total, - pageNo: pageNo, - pageSize: pageSize - } - }) - } - }) + this.versionData.processDefinition.id = this.urlParam.id + this.versionData.processDefinition.version = this.$store.state.dag.version + this.versionData.processDefinition.state = this.releaseState + this.versionData.processDefinitionVersions = processDefinitionVersions + this.versionData.total = total + this.versionData.pageNo = pageNo + this.versionData.pageSize = pageSize + this.drawer = true }).catch(e => { this.$message.error(e.msg || '') }) + }, + + closeVersion () { + this.drawer = false } }, watch: { - 'tasks': { + tasks: { deep: true, handler (o) { - // Edit state does not allow deletion of node a... this.setIsEditDag(true) } @@ -843,8 +841,8 @@ } ], ['Label', { - location: 0.5, - id: 'label' + location: 0.5, + id: 'label' }] ], Container: 'canvas', @@ -869,10 +867,13 @@ computed: { ...mapState('dag', ['tasks', 'locations', 'connects', 'isEditDag', 'name']) }, - components: {} + components: { mVersions, mFormModel, mFormLineModel, mUdp, mStart } } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/dependentTimeout.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/dependentTimeout.vue index 2b2ed78ccc..8d8f13cfee 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/dependentTimeout.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/dependentTimeout.vue @@ -23,7 +23,7 @@
@@ -35,7 +35,7 @@
@@ -46,22 +46,22 @@ {{$t('Timeout period')}} - + {{$t('Minute')}} - + {{$t('Check interval')}} - + {{$t('Minute')}} - + {{$t('Timeout strategy')}}
- - {{$t('Timeout failure')}} - + + {{$t('Timeout failure')}} +
@@ -73,7 +73,7 @@
@@ -84,17 +84,17 @@ {{$t('Timeout period')}} - + {{$t('Minute')}} - + {{$t('Timeout strategy')}}
- - {{$t('Timeout alarm')}} - {{$t('Timeout failure')}} - + + {{$t('Timeout alarm')}} + {{$t('Timeout failure')}} +
@@ -143,21 +143,21 @@ if (p === 2 || p === 0) { this.waitCompleteTimeout.strategy = is ? ['WARN'] : [] this.waitCompleteTimeout.interval = is ? 30 : null - } + } }, _verification () { // Verification timeout policy - if (this.enable - && (this.waitCompleteTimeout.enable && !this.waitCompleteTimeout.strategy.length) - || (this.waitStartTimeout.enable && !this.waitStartTimeout.strategy.length)) { + if (this.enable && + (this.waitCompleteTimeout.enable && !this.waitCompleteTimeout.strategy.length) || + (this.waitStartTimeout.enable && !this.waitStartTimeout.strategy.length)) { this.$message.warning(`${this.$t('Timeout strategy must be selected')}`) return false } // Verify timeout duration Non 0 positive integer const reg = /^[1-9]\d*$/ - if (this.enable - && (this.waitCompleteTimeout.enable && !reg.test(this.waitCompleteTimeout.interval)) - || (this.waitStartTimeout.enable && (!reg.test(this.waitStartTimeout.interval || !reg.test(this.waitStartTimeout.checkInterval))))) { + if (this.enable && + (this.waitCompleteTimeout.enable && !reg.test(this.waitCompleteTimeout.interval)) || + (this.waitStartTimeout.enable && (!reg.test(this.waitStartTimeout.interval || !reg.test(this.waitStartTimeout.checkInterval))))) { this.$message.warning(`${this.$t('Timeout must be a positive integer')}`) return false } @@ -175,16 +175,16 @@ }, waitCompleteTimeout: { strategy: (() => { - // Handling checkout sequence - let strategy = this.waitCompleteTimeout.strategy - if (strategy.length === 2 && strategy[0] === 'FAILED') { - return [strategy[1], strategy[0]].join(',') - } else { - return strategy.join(',') - } - })(), - interval: parseInt(this.waitCompleteTimeout.interval), - enable: this.waitCompleteTimeout.enable + // Handling checkout sequence + let strategy = this.waitCompleteTimeout.strategy + if (strategy.length === 2 && strategy[0] === 'FAILED') { + return [strategy[1], strategy[0]].join(',') + } else { + return strategy.join(',') + } + })(), + interval: parseInt(this.waitCompleteTimeout.interval), + enable: this.waitCompleteTimeout.enable } }) return true @@ -215,4 +215,4 @@ }, components: {} } - \ No newline at end of file + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/selectInput.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/selectInput.vue index 1d3902c83b..160db6e320 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/selectInput.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/selectInput.vue @@ -15,33 +15,34 @@ * limitations under the License. */ \ No newline at end of file + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/timeoutAlarm.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/timeoutAlarm.vue index 0dcab3e901..2fece25675 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/timeoutAlarm.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/timeoutAlarm.vue @@ -23,7 +23,7 @@
@@ -35,10 +35,10 @@
@@ -49,9 +49,9 @@
@@ -127,4 +127,4 @@ }, components: {} } - \ No newline at end of file + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/workerGroups.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/workerGroups.vue index 8efe5c2860..de2b2c73c2 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/workerGroups.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/_source/workerGroups.vue @@ -15,18 +15,19 @@ * limitations under the License. */ diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue index 7874b53885..502adc767f 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/log.vue @@ -29,16 +29,16 @@ {{$t('View log')}} @@ -48,7 +48,7 @@
- {{$t('Close')}} + {{$t('Close')}}
@@ -67,7 +67,7 @@ */ const handerTextareaSize = (isH = 0) => { $('body').find('.tooltip.fade.top.in').remove() - return $('.textarea-ft').css({ 'height': `${$('.content-log-box').height() - isH}px` }) + return $('.textarea-ft').css({ height: `${$('.content-log-box').height() - isH}px` }) } let content = '' @@ -89,7 +89,7 @@ props: { item: { type: Object, - default: {} + default: Object }, source: { type: String, @@ -118,8 +118,8 @@ }, _ckLog () { this.isLog = true + this.store.dispatch('dag/getLog', this._rtParam).then(res => { - this.$message.destroy() if (!res.data) { this.isData = false setTimeout(() => { @@ -138,7 +138,6 @@ }, 800) } }).catch(e => { - this.$message.destroy() this.$message.error(e.msg || '') }) }, @@ -169,7 +168,7 @@ * Download log */ _downloadLog () { - downloadFile('/dolphinscheduler/log/download-log', { + downloadFile('/log/download-log', { taskInstanceId: this.stateId || this.logId }) }, @@ -180,8 +179,8 @@ this.loadingIndex = this.loadingIndex - 1 this._ckLog() }, 1000, { - 'leading': false, - 'trailing': true + leading: false, + trailing: true }), /** * down @@ -190,8 +189,8 @@ this.loadingIndex = this.loadingIndex + 1 this._ckLog() }, 1000, { - 'leading': false, - 'trailing': true + leading: false, + trailing: true }), /** * Monitor scroll bar @@ -203,11 +202,7 @@ // Listen for scrollbar events if (($this.scrollTop() + $this.height()) === $this.height()) { if (self.loadingIndex > 0) { - self.$message.loading({ - content: `${i18n.$t('Loading Log...')}`, - duration: 0, - closable: false - }) + self.$message.info(`${i18n.$t('Loading Log...')}`) self._onUp() } } @@ -215,11 +210,7 @@ if ($this.get(0).scrollHeight === ($this.height() + $this.scrollTop())) { // No data is not requested if (self.isData) { - self.$message.loading({ - content: `${i18n.$t('Loading Log...')}`, - duration: 0, - closable: false - }) + self.$message.info(`${i18n.$t('Loading Log...')}`) self._onDown() } } @@ -240,11 +231,7 @@ created () { // Source is a task instance if (this.source === 'list') { - this.$message.loading({ - content: `${i18n.$t('Loading Log...')}`, - duration: 0, - closable: false - }) + this.$message.info(`${i18n.$t('Loading Log...')}`) this._ckLog() } }, @@ -301,27 +288,30 @@ top: 12px; a{ color: #0097e0; - font-size: 12px; margin-left: 10px; - i { + em { + font-size: 17px; + font-weight: 400; + text-decoration: none !important; vertical-align: middle; } } .clock { - >i { + >em { font-size: 20px; vertical-align: middle; transform: scale(1); } } .refresh-log { - >i { + >em { + text-decoration: none; font-size: 20px; vertical-align: middle; transform: scale(1); } &.active { - >i { + >em { -webkit-transition-property: -webkit-transform; -webkit-transition-duration: 1s; -moz-transition-property: -moz-transform; @@ -368,5 +358,16 @@ } } } - + @-webkit-keyframes rotateloading{from{-webkit-transform: rotate(0deg)} + to{-webkit-transform: rotate(360deg)} + } + @-moz-keyframes rotateloading{from{-moz-transform: rotate(0deg)} + to{-moz-transform: rotate(359deg)} + } + @-o-keyframes rotateloading{from{-o-transform: rotate(0deg)} + to{-o-transform: rotate(359deg)} + } + @keyframes rotateloading{from{transform: rotate(0deg)} + to{transform: rotate(359deg)} + } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/datasource.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/datasource.vue index 05e248f518..0a3f17b059 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/datasource.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/datasource.vue @@ -17,28 +17,30 @@ @@ -101,7 +103,7 @@ /** * Brush type */ - _handleTypeChanged ({ value }) { + _handleTypeChanged (value) { this.type = value this._getDatasourceData().then(res => { this.datasource = this.datasourceList.length && this.datasourceList[0].id || '' @@ -126,7 +128,7 @@ this.$emit('on-dsData', { type: this.type, datasource: val - }); + }) } }, created () { diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/dependItemList.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/dependItemList.vue index abec923af5..abadc2c36b 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/dependItemList.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/dependItemList.vue @@ -17,39 +17,39 @@ - \ No newline at end of file diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/shell.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/shell.vue index da94162989..55b9aca071 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/shell.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/shell.vue @@ -26,7 +26,7 @@ style="opacity: 0"> - + @@ -39,17 +39,6 @@ -
{{$t('Custom Parameters')}}
@@ -61,6 +50,12 @@
+ + + - diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/spark.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/spark.vue index 0948c9735f..efeb7e9e36 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/spark.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/spark.vue @@ -19,45 +19,47 @@
{{$t('Program Type')}}
- - - - + +
{{$t('Spark Version')}}
- - - - + +
{{$t('Main class')}}
- - + +
@@ -71,99 +73,93 @@
{{$t('Deploy Mode')}}
- - - - - + + + + +
-
-
- {{$t('Driver core number')}} - - - - - {{$t('Driver memory use')}} - - - - + +
{{$t('Driver cores')}}
+
+ + +
+
{{$t('Driver memory')}}
+
+ + +
+
+ +
{{$t('Executor Number')}}
+
+ +
-
- {{$t('Number of Executors')}} - - - - - {{$t('Executor memory')}} - - - - +
{{$t('Executor memory')}}
+
+ +
-
- {{$t('Executor core number')}} - - - - + + +
{{$t('Executor cores')}}
+
+ +
-
+
{{$t('Command-line parameters')}}
- - + +
{{$t('Other parameters')}}
- - + +
@@ -174,17 +170,6 @@
-
{{$t('Custom Parameters')}}
@@ -203,7 +188,7 @@ import i18n from '@/module/i18n' import mLocalParams from './_source/localParams' import mListBox from './_source/listBox' - import mResources from './_source/resources' + import mList4Box from './_source/list4Box' import Treeselect from '@riophae/vue-treeselect' import '@riophae/vue-treeselect/dist/vue-treeselect.css' import disabledState from '@/module/mixin/disabledState' @@ -250,7 +235,7 @@ sparkVersion: 'SPARK2', // Spark version(LIst) sparkVersionList: [{ code: 'SPARK2' }, { code: 'SPARK1' }], - normalizer(node) { + normalizer (node) { return { label: node.name } @@ -267,10 +252,10 @@ /** * getResourceId */ - marjarId(name) { - this.store.dispatch('dag/getResourceId',{ + marjarId (name) { + this.store.dispatch('dag/getResourceId', { type: 'FILE', - fullName: '/'+name + fullName: '/' + name }).then(res => { this.mainJar = res.id }).catch(e => { @@ -295,55 +280,55 @@ _onCacheResourcesData (a) { this.cacheResourceList = a }, - diGuiTree(item) { // Recursive convenience tree structure + diGuiTree (item) { // Recursive convenience tree structure item.forEach(item => { - item.children === '' || item.children === undefined || item.children === null || item.children.length === 0?         - this.operationTree(item) : this.diGuiTree(item.children); + item.children === '' || item.children === undefined || item.children === null || item.children.length === 0 + ? this.operationTree(item) : this.diGuiTree(item.children) }) }, - operationTree(item) { - if(item.dirctory) { - item.isDisabled =true + operationTree (item) { + if (item.dirctory) { + item.isDisabled = true } delete item.children }, - searchTree(element, id) { + searchTree (element, id) { // 根据id查找节点 - if (element.id == id) { - return element; - } else if (element.children != null) { - var i; - var result = null; - for (i = 0; result == null && i < element.children.length; i++) { - result = this.searchTree(element.children[i], id); + if (element.id === id) { + return element + } else if (element.children !== null) { + let i + let result = null + for (i = 0; result === null && i < element.children.length; i++) { + result = this.searchTree(element.children[i], id) } - return result; + return result } - return null; + return null }, - dataProcess(backResource) { + dataProcess (backResource) { let isResourceId = [] let resourceIdArr = [] - if(this.resourceList.length>0) { - this.resourceList.forEach(v=>{ - this.mainJarList.forEach(v1=>{ - if(this.searchTree(v1,v)) { - isResourceId.push(this.searchTree(v1,v)) + if (this.resourceList.length > 0) { + this.resourceList.forEach(v => { + this.mainJarList.forEach(v1 => { + if (this.searchTree(v1, v)) { + isResourceId.push(this.searchTree(v1, v)) } }) }) - resourceIdArr = isResourceId.map(item=>{ + resourceIdArr = isResourceId.map(item => { return item.id }) - Array.prototype.diff = function(a) { - return this.filter(function(i) {return a.indexOf(i) < 0;}); - }; - let diffSet = this.resourceList.diff(resourceIdArr); + Array.prototype.diff = function (a) { + return this.filter(function (i) { return a.indexOf(i) < 0 }) + } + let diffSet = this.resourceList.diff(resourceIdArr) let optionsCmp = [] - if(diffSet.length>0) { - diffSet.forEach(item=>{ - backResource.forEach(item1=>{ - if(item==item1.id || item==item1.res) { + if (diffSet.length > 0) { + diffSet.forEach(item => { + backResource.forEach(item1 => { + if (item === item1.id || item === item1.res) { optionsCmp.push(item1) } }) @@ -352,15 +337,15 @@ let noResources = [{ id: -1, name: $t('Unauthorized or deleted resources'), - fullName: '/'+$t('Unauthorized or deleted resources'), + fullName: '/' + $t('Unauthorized or deleted resources'), children: [] }] - if(optionsCmp.length>0) { + if (optionsCmp.length > 0) { this.allNoResources = optionsCmp - optionsCmp = optionsCmp.map(item=>{ - return {id: item.id,name: item.name,fullName: item.res} + optionsCmp = optionsCmp.map(item => { + return { id: item.id, name: item.name, fullName: item.res } }) - optionsCmp.forEach(item=>{ + optionsCmp.forEach(item => { item.isNew = true }) noResources[0].children = optionsCmp @@ -383,28 +368,28 @@ } if (!this.numExecutors) { - this.$message.warning(`${i18n.$t('Please enter the number of Executor')}`) + this.$message.warning(`${i18n.$t('Please enter Executor number')}`) return false } // noRes - if (this.noRes.length>0) { + if (this.noRes.length > 0) { this.$message.warning(`${i18n.$t('Please delete all non-existent resources')}`) return false } if (!Number.isInteger(parseInt(this.numExecutors))) { - this.$message.warning(`${i18n.$t('The number of Executors should be a positive integer')}`) + this.$message.warning(`${i18n.$t('The Executor Number should be a positive integer')}`) return false } if (!this.executorMemory) { - this.$message.warning(`${i18n.$t('Please enter the Executor memory')}`) + this.$message.warning(`${i18n.$t('Please enter Executor memory')}`) return false } if (!this.executorMemory) { - this.$message.warning(`${i18n.$t('Please enter the Executor memory')}`) + this.$message.warning(`${i18n.$t('Please enter Executor memory')}`) return false } @@ -414,7 +399,7 @@ } if (!this.executorCores) { - this.$message.warning(`${i18n.$t('Please enter ExecutorPlease enter Executor core number')}`) + this.$message.warning(`${i18n.$t('Please enter Executor cores')}`) return false } @@ -427,7 +412,7 @@ return false } // Process resourcelist - let dataProcessing= _.map(this.resourceList, v => { + let dataProcessing = _.map(this.resourceList, v => { return { id: v } @@ -462,44 +447,49 @@ this.mainClass = '' } }, - //Watch the cacheParams + // Watch the cacheParams cacheParams (val) { this.$emit('on-cache-params', val) + }, + resourceIdArr (arr) { + let result = [] + arr.forEach(item => { + this.allNoResources.forEach(item1 => { + if (item.id === item1.id) { + // resultBool = true + result.push(item1) + } + }) + }) + this.noRes = result } }, computed: { - cacheParams () { + resourceIdArr () { let isResourceId = [] let resourceIdArr = [] - if(this.resourceList.length>0) { - this.resourceList.forEach(v=>{ - this.mainJarList.forEach(v1=>{ - if(this.searchTree(v1,v)) { - isResourceId.push(this.searchTree(v1,v)) + if (this.resourceList.length > 0) { + this.resourceList.forEach(v => { + this.mainJarList.forEach(v1 => { + if (this.searchTree(v1, v)) { + isResourceId.push(this.searchTree(v1, v)) } }) }) - resourceIdArr = isResourceId.map(item=>{ - return {id: item.id,name: item.name,res: item.fullName} + resourceIdArr = isResourceId.map(item => { + return { id: item.id, name: item.name, res: item.fullName } }) } - let result = [] - resourceIdArr.forEach(item=>{ - this.allNoResources.forEach(item1=>{ - if(item.id==item1.id) { - // resultBool = true - result.push(item1) - } - }) - }) - this.noRes = result + return resourceIdArr + }, + cacheParams () { return { mainClass: this.mainClass, mainJar: { id: this.mainJar }, deployMode: this.deployMode, - resourceList: resourceIdArr, + resourceList: this.resourceIdArr, localParams: this.localParams, driverCores: this.driverCores, driverMemory: this.driverMemory, @@ -514,104 +504,69 @@ } }, created () { - let item = this.store.state.dag.resourcesListS - let items = this.store.state.dag.resourcesListJar - this.diGuiTree(item) - this.diGuiTree(items) - this.mainJarList = item - this.mainJarLists = items - let o = this.backfillItem + let item = this.store.state.dag.resourcesListS + let items = this.store.state.dag.resourcesListJar + this.diGuiTree(item) + this.diGuiTree(items) + this.mainJarList = item + this.mainJarLists = items + let o = this.backfillItem - // Non-null objects represent backfill - if (!_.isEmpty(o)) { - this.mainClass = o.params.mainClass || '' - if(o.params.mainJar.res) { - this.marjarId(o.params.mainJar.res) - } else if(o.params.mainJar.res=='') { - this.mainJar = '' - } else { - this.mainJar = o.params.mainJar.id || '' - } - this.deployMode = o.params.deployMode || '' - this.driverCores = o.params.driverCores || 1 - this.driverMemory = o.params.driverMemory || '512M' - this.numExecutors = o.params.numExecutors || 2 - this.executorMemory = o.params.executorMemory || '2G' - this.executorCores = o.params.executorCores || 2 - this.mainArgs = o.params.mainArgs || '' - this.others = o.params.others - this.programType = o.params.programType || 'SCALA' - this.sparkVersion = o.params.sparkVersion || 'SPARK2' + // Non-null objects represent backfill + if (!_.isEmpty(o)) { + this.mainClass = o.params.mainClass || '' + if (o.params.mainJar.res) { + this.marjarId(o.params.mainJar.res) + } else if (o.params.mainJar.res === '') { + this.mainJar = '' + } else { + this.mainJar = o.params.mainJar.id || '' + } + this.deployMode = o.params.deployMode || '' + this.driverCores = o.params.driverCores || 1 + this.driverMemory = o.params.driverMemory || '512M' + this.numExecutors = o.params.numExecutors || 2 + this.executorMemory = o.params.executorMemory || '2G' + this.executorCores = o.params.executorCores || 2 + this.mainArgs = o.params.mainArgs || '' + this.others = o.params.others + this.programType = o.params.programType || 'SCALA' + this.sparkVersion = o.params.sparkVersion || 'SPARK2' - // backfill resourceList - let backResource = o.params.resourceList || [] - let resourceList = o.params.resourceList || [] - if (resourceList.length) { - _.map(resourceList, v => { - if(!v.id) { - this.store.dispatch('dag/getResourceId',{ - type: 'FILE', - fullName: '/'+v.res - }).then(res => { - this.resourceList.push(res.id) - this.dataProcess(backResource) - }).catch(e => { - this.resourceList.push(v.res) - this.dataProcess(backResource) - }) - } else { - this.resourceList.push(v.id) + // backfill resourceList + let backResource = o.params.resourceList || [] + let resourceList = o.params.resourceList || [] + if (resourceList.length) { + _.map(resourceList, v => { + if (!v.id) { + this.store.dispatch('dag/getResourceId', { + type: 'FILE', + fullName: '/' + v.res + }).then(res => { + this.resourceList.push(res.id) this.dataProcess(backResource) - } - }) - this.cacheResourceList = resourceList - } + }).catch(e => { + this.resourceList.push(v.res) + this.dataProcess(backResource) + }) + } else { + this.resourceList.push(v.id) + this.dataProcess(backResource) + } + }) + this.cacheResourceList = resourceList + } - // backfill localParams - let localParams = o.params.localParams || [] - if (localParams.length) { - this.localParams = localParams - } + // backfill localParams + let localParams = o.params.localParams || [] + if (localParams.length) { + this.localParams = localParams } + } }, mounted () { }, - components: { mLocalParams, mListBox, mResources, Treeselect } + components: { mLocalParams, mListBox, mList4Box, Treeselect } } - - diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue index 8e892ab247..7e3ae465c8 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sql.vue @@ -35,51 +35,49 @@ :sql-type="sqlType">
-
{{$t('SQL Parameter')}}
- - + :placeholder="$t('Please enter format') + ' key1=value1;key2=value2...'"> +
@@ -92,7 +90,7 @@ style="opacity: 0;"> - +
@@ -138,6 +136,12 @@
+ + + - - diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sqoop.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sqoop.vue index c852f7f75f..7647e67ab4 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sqoop.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sqoop.vue @@ -20,23 +20,14 @@
{{$t('Custom Job')}}
- - +
{{$t('Custom Script')}}
- +
@@ -44,29 +35,25 @@
{{$t('Sqoop Job Name')}}
- - +
{{$t('Direct')}}
- - + - - + +
@@ -100,18 +87,19 @@
{{$t('Type')}}
- - + - - + +
@@ -134,10 +122,10 @@
{{$t('ModelType')}}
- - {{$t('Form')}} - SQL - + + {{$t('Form')}} + SQL +
@@ -146,34 +134,36 @@
{{$t('Table')}}
- - +
{{$t('ColumnType')}}
- - {{$t('All Columns')}} - {{$t('Some Columns')}} - + + {{$t('All Columns')}} + {{$t('Some Columns')}} +
{{$t('Column')}}
- - +
@@ -184,45 +174,49 @@
{{$t('Database')}}
- - +
{{$t('Table')}}
- - +
{{$t('Hive partition Keys')}}
- - +
{{$t('Hive partition Values')}}
- - +
@@ -231,12 +225,13 @@
{{$t('Export Dir')}}
- - +
@@ -251,7 +246,7 @@ style="opacity: 0;"> - + @@ -290,91 +285,97 @@
{{$t('Type')}}
- - - - + +
{{$t('Database')}}
- - +
{{$t('Table')}}
- - +
{{$t('CreateHiveTable')}}
- +
{{$t('DropDelimiter')}}
- +
{{$t('OverWriteSrc')}}
- +
{{$t('ReplaceDelimiter')}}
- - +
{{$t('Hive partition Keys')}}
- - +
{{$t('Hive partition Values')}}
- - +
@@ -382,62 +383,65 @@
{{$t('Target Dir')}}
- - +
{{$t('DeleteTargetDir')}}
- +
{{$t('CompressionCodec')}}
- - snappy - lzo - gzip - no - + + snappy + lzo + gzip + no +
{{$t('FileType')}}
- - avro - sequence - text - parquet - + + avro + sequence + text + parquet +
{{$t('FieldsTerminated')}}
- - +
{{$t('LinesTerminated')}}
- - +
@@ -458,71 +462,76 @@
{{$t('Table')}}
- - +
{{$t('Column')}}
- - +
{{$t('FieldsTerminated')}}
- - +
{{$t('LinesTerminated')}}
- - +
{{$t('IsUpdate')}}
- +
{{$t('UpdateKey')}}
- - +
{{$t('UpdateMode')}}
- - {{$t('OnlyUpdate')}} - {{$t('AllowInsert')}} - + + {{$t('OnlyUpdate')}} + {{$t('AllowInsert')}} +
@@ -530,13 +539,13 @@
{{$t('Concurrency')}}
- - - +
@@ -551,6 +560,12 @@
+ + + - - diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sub_process.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sub_process.vue index e96d409c2c..23fe4ceb42 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sub_process.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/sub_process.vue @@ -22,19 +22,20 @@
- - - - + @change="_handleWdiChanged"> + + +
@@ -77,7 +78,7 @@ * The selected process defines the upper component name padding */ _handleWdiChanged (o) { - this.$emit('on-set-process-name', this._handleName(o.value)) + this.$emit('on-set-process-name', this._handleName(o)) }, /** * Return the name according to the process definition id @@ -96,7 +97,7 @@ created () { let processListS = _.cloneDeep(this.store.state.dag.processListS) let id = null - if(this.router.history.current.name==='projects-instance-details') { + if (this.router.history.current.name === 'projects-instance-details') { id = this.router.history.current.query.id || null } else { id = this.router.history.current.params.id || null @@ -118,7 +119,7 @@ this.wdiCurr = o.params.processDefinitionId } else { if (this.processDefinitionList.length) { - this.wdiCurr = this.processDefinitionList[0]['id'] + this.wdiCurr = this.processDefinitionList[0].id this.$emit('on-set-process-name', this._handleName(this.wdiCurr)) } } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/waterdrop.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/waterdrop.vue index f67ec6dde8..bdf2e337e7 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/waterdrop.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/waterdrop.vue @@ -17,58 +17,56 @@ + - diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/jumpAffirm/index.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/jumpAffirm/index.js index c1f77f6876..9f55265e33 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/jumpAffirm/index.js +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/jumpAffirm/index.js @@ -14,10 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import Vue from 'vue' -import mAffirm from './jumpAffirm' import store from '@/conf/home/store' +import i18n from '@/module/i18n' import router from '@/conf/home/router' import { uuid, findComponentDownward } from '@/module/util/' @@ -81,34 +80,18 @@ Affirm.paramVerification = (name) => { * Pop-up judgment */ Affirm.isPop = (fn) => { - Vue.$modal.dialog({ - closable: false, - showMask: true, - escClose: true, - className: 'v-modal-custom', - transitionName: 'opacityp', - render (h) { - return h(mAffirm, { - on: { - ok () { - // save - findComponentDownward($root, 'dag-chart')._save('affirm').then(() => { - fn() - Vue.$modal.destroy() - }).catch(() => { - fn() - Vue.$modal.destroy() - }) - }, - close () { - fn() - Vue.$modal.destroy() - } - }, - props: { - } - }) - } + Vue.prototype.$confirm(`${i18n.$t('Whether to save the DAG graph')}`, '', { + confirmButtonText: `${i18n.$t('Save')}`, + cancelButtonText: `${i18n.$t('Cancel')}`, + type: 'warning' + }).then(() => { + findComponentDownward($root, 'dag-chart')._save('affirm').then(() => { + fn() + }).catch(() => { + fn() + }) + }).catch(() => { + fn() }) } diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/jsPlumbHandle.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/jsPlumbHandle.js index 03c3d2dcbf..0037af68b6 100755 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/jsPlumbHandle.js +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/jsPlumbHandle.js @@ -17,7 +17,6 @@ import 'jquery-ui/ui/widgets/draggable' import 'jquery-ui/ui/widgets/droppable' import 'jquery-ui/ui/widgets/resizable' -import Vue from 'vue' import _ from 'lodash' import i18n from '@/module/i18n' import { jsPlumb } from 'jsplumb' @@ -34,7 +33,6 @@ import { rtTargetarrArr, computeScale } from './util' -import mStart from '@/conf/home/pages/projects/pages/definition/pages/list/_source/start' import multiDrag from './multiDrag' const JSP = function () { @@ -88,7 +86,7 @@ JSP.prototype.init = function ({ dag, instance, options }) { if (this.config.isClick) { this.connectClick(e) } else { - findComponentDownward(this.dag.$root, 'dag-chart')._createLineLabel({id: e._jsPlumb.overlays.label.canvas.id, sourceId: e.sourceId, targetId: e.targetId}) + findComponentDownward(this.dag.$root, 'dag-chart')._createLineLabel({ id: e._jsPlumb.overlays.label.canvas.id, sourceId: e.sourceId, targetId: e.targetId }) } }) @@ -208,8 +206,8 @@ JSP.prototype.jsonHandle = function ({ largeJson, locations }) { taskType: v.type, runFlag: v.runFlag, nodenumber: locations[v.id].nodenumber, - successNode: v.conditionResult === undefined? '' : v.conditionResult.successNode[0], - failedNode: v.conditionResult === undefined? '' : v.conditionResult.failedNode[0] + successNode: v.conditionResult === undefined ? '' : v.conditionResult.successNode[0], + failedNode: v.conditionResult === undefined ? '' : v.conditionResult.failedNode[0] })) // contextmenu event @@ -280,10 +278,10 @@ JSP.prototype.tasksContextmenu = function (event) { const isTwo = store.state.dag.isDetails const html = [ - `${i18n.$t('Start')}`, - `${i18n.$t('Edit')}`, - `${i18n.$t('Copy')}`, - `${i18n.$t('Delete')}` + `${i18n.$t('Start')}`, + `${i18n.$t('Edit')}`, + `${i18n.$t('Copy')}`, + `${i18n.$t('Delete')}` ] const operationHtml = () => { @@ -310,35 +308,7 @@ JSP.prototype.tasksContextmenu = function (event) { const name = store.state.dag.name const id = router.history.current.params.id store.dispatch('dag/getStartCheck', { processDefinitionId: id }).then(res => { - const modal = Vue.$modal.dialog({ - closable: false, - showMask: true, - escClose: true, - className: 'v-modal-custom', - transitionName: 'opacityp', - render (h) { - return h(mStart, { - on: { - onUpdate () { - modal.remove() - }, - close () { - modal.remove() - } - }, - props: { - item: { - id: id, - name: name - }, - startNodeList: $name, - sourceType: 'contextmenu' - } - }) - } - }) - }).catch(e => { - Vue.$message.error(e.msg || '') + this.dag.startRunning({ id: id, name: name }, $name, 'contextmenu') }) }) } @@ -370,7 +340,6 @@ JSP.prototype.tasksDblclick = function (e) { // Untie event if (this.config.isDblclick) { const id = $(e.currentTarget.offsetParent).attr('id') - findComponentDownward(this.dag.$root, 'dag-chart')._createNodes({ id: id, type: $(`#${id}`).attr('data-tasks-type') @@ -499,7 +468,7 @@ JSP.prototype.removeNodes = function ($id) { // callback onRemoveNodes event this.options && this.options.onRemoveNodes && this.options.onRemoveNodes($id) - let connects = [] + const connects = [] _.map(this.JspInstance.getConnections(), v => { connects.push({ endPointSourceId: v.sourceId, @@ -604,10 +573,10 @@ JSP.prototype.copyNodes = function ($id) { JSP.prototype.handleEventScreen = function ({ item, is }) { let screenOpen = true if (is) { - item.icon = 'ans-icon-min' + item.icon = 'el-icon-minus' screenOpen = true } else { - item.icon = 'ans-icon-max' + item.icon = 'el-icon-full-screen' screenOpen = false } const $mainLayoutModel = $('.main-layout-model') @@ -658,7 +627,7 @@ JSP.prototype.saveStore = function () { tasks.push(tasksParam) } }) - if(store.state.dag.connects.length ===this.JspInstance.getConnections().length) { + if (store.state.dag.connects.length === this.JspInstance.getConnections().length) { _.map(store.state.dag.connects, u => { connects.push({ endPointSourceId: u.endPointSourceId, @@ -666,7 +635,7 @@ JSP.prototype.saveStore = function () { label: u.label }) }) - } else if(store.state.dag.connects.length>0 && store.state.dag.connects.length < this.JspInstance.getConnections().length) { + } else if (store.state.dag.connects.length > 0 && store.state.dag.connects.length < this.JspInstance.getConnections().length) { _.map(this.JspInstance.getConnections(), v => { connects.push({ endPointSourceId: v.sourceId, @@ -676,12 +645,12 @@ JSP.prototype.saveStore = function () { }) _.map(store.state.dag.connects, u => { _.map(connects, v => { - if(u.label && u.endPointSourceId === v.endPointSourceId && u.endPointTargetId===v.endPointTargetId) { + if (u.label && u.endPointSourceId === v.endPointSourceId && u.endPointTargetId === v.endPointTargetId) { v.label = u.label } }) }) - } else if(store.state.dag.connects.length===0) { + } else if (store.state.dag.connects.length === 0) { _.map(this.JspInstance.getConnections(), v => { connects.push({ endPointSourceId: v.sourceId, @@ -690,7 +659,7 @@ JSP.prototype.saveStore = function () { }) }) } - + _.map(tasksAll(), v => { locations[v.id] = { name: v.name, @@ -783,7 +752,7 @@ JSP.prototype.jspBackfill = function ({ connects, locations, largeJson }) { _.map(connects, v => { let sourceId = v.endPointSourceId.split('-') let targetId = v.endPointTargetId.split('-') - let labels = v.label + const labels = v.label if (sourceId.length === 4 && targetId.length === 4) { sourceId = `${sourceId[0]}-${sourceId[1]}-${sourceId[2]}` targetId = `${targetId[0]}-${targetId[1]}-${targetId[2]}` @@ -791,24 +760,24 @@ JSP.prototype.jspBackfill = function ({ connects, locations, largeJson }) { sourceId = v.endPointSourceId targetId = v.endPointTargetId } - - if($(`#${sourceId}`).attr('data-tasks-type') === 'CONDITIONS' && $(`#${sourceId}`).attr('data-successnode') === $(`#${targetId}`).find('.name-p').text()) { + + if ($(`#${sourceId}`).attr('data-tasks-type') === 'CONDITIONS' && $(`#${sourceId}`).attr('data-successnode') === $(`#${targetId}`).find('.name-p').text()) { this.JspInstance.connect({ source: sourceId, target: targetId, type: 'basic', paintStyle: { strokeWidth: 2, stroke: '#4caf50' }, - HoverPaintStyle: {stroke: '#ccc', strokeWidth: 3}, - overlays:[["Label", { label: labels} ]] + HoverPaintStyle: { stroke: '#ccc', strokeWidth: 3 }, + overlays: [['Label', { label: labels }]] }) - } else if($(`#${sourceId}`).attr('data-tasks-type') === 'CONDITIONS' && $(`#${sourceId}`).attr('data-failednode') === $(`#${targetId}`).find('.name-p').text()) { + } else if ($(`#${sourceId}`).attr('data-tasks-type') === 'CONDITIONS' && $(`#${sourceId}`).attr('data-failednode') === $(`#${targetId}`).find('.name-p').text()) { this.JspInstance.connect({ source: sourceId, target: targetId, type: 'basic', paintStyle: { strokeWidth: 2, stroke: '#252d39' }, - HoverPaintStyle: {stroke: '#ccc', strokeWidth: 3}, - overlays:[["Label", { label: labels} ]] + HoverPaintStyle: { stroke: '#ccc', strokeWidth: 3 }, + overlays: [['Label', { label: labels }]] }) } else { this.JspInstance.connect({ @@ -816,8 +785,8 @@ JSP.prototype.jspBackfill = function ({ connects, locations, largeJson }) { target: targetId, type: 'basic', paintStyle: { strokeWidth: 2, stroke: '#2d8cf0' }, - HoverPaintStyle: {stroke: '#ccc', strokeWidth: 3}, - overlays:[["Label", { label: labels} ]] + HoverPaintStyle: { stroke: '#ccc', strokeWidth: 3 }, + overlays: [['Label', { label: labels }]] }) } }) diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/util.js b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/util.js index f5aacf294f..176f852e83 100755 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/util.js +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/plugIn/util.js @@ -37,7 +37,7 @@ const saveTargetarr = (valId, domId) => { } const rtBantpl = () => { - return `` + return `` } /** @@ -100,13 +100,13 @@ const setSvgColor = (e, color) => { // Traverse clear all colors $('.jtk-connector').each((i, o) => { _.map($(o)[0].childNodes, v => { - if($(v).attr('fill') ==='#ccc') { + if ($(v).attr('fill') === '#ccc') { $(v).attr('fill', '#2d8cf0') } - if($(v).attr('fill') ==='#4caf50') { - $(v).attr('fill','#4caf50').attr('stroke', '#4caf50').attr('stroke-width', 2) + if ($(v).attr('fill') === '#4caf50') { + $(v).attr('fill', '#4caf50').attr('stroke', '#4caf50').attr('stroke-width', 2) $(v).prev().attr('stroke', '#4caf50').attr('stroke-width', 2) - } else if($(v).attr('fill') ==='#252d39') { + } else if ($(v).attr('fill') === '#252d39') { $(v).attr('stroke', '#252d39').attr('stroke-width', 2) $(v).prev().attr('stroke', '#252d39').attr('stroke-width', 2) } else { @@ -117,7 +117,7 @@ const setSvgColor = (e, color) => { // Add color to the selection _.map($(e.canvas)[0].childNodes, (v, i) => { - if($(v).attr('fill') ==='#2d8cf0') { + if ($(v).attr('fill') === '#2d8cf0') { $(v).attr('fill', '#ccc') } $(v).attr('stroke', '#ccc') diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/startingParam/index.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/startingParam/index.vue index 516f03bc2f..9520386b8d 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/startingParam/index.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/startingParam/index.vue @@ -18,7 +18,7 @@
diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/index.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/index.vue index 33be9e096f..9f6ed83d4a 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/index.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/index.vue @@ -37,7 +37,7 @@ } }, watch: { - '$route': { + $route: { deep: true, handler () { this.isActive = false diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/variablesView.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/variablesView.vue index 7209c4daff..23e4bdca05 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/variablesView.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/variable/variablesView.vue @@ -18,23 +18,23 @@