From ffdda00a3b5e999c2553b52dfebd95228ab2ae4c Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Thu, 28 Jan 2021 15:10:25 +0800 Subject: [PATCH 01/24] [Feature-3826]sql node adds alarm group field --- .../formModel/tasks/_source/warningGroups.vue | 76 +++++++++++++++++++ .../pages/dag/_source/formModel/tasks/sql.vue | 26 +++++-- .../pages/dag/_source/startingParam/index.vue | 2 +- .../conf/home/pages/dag/definitionDetails.vue | 4 +- .../src/js/conf/home/pages/dag/index.vue | 4 +- .../conf/home/pages/dag/instanceDetails.vue | 4 +- .../definition/pages/list/_source/list.vue | 1 + .../definition/pages/list/_source/start.vue | 6 +- .../js/conf/home/store/security/actions.js | 13 ++++ .../src/js/conf/home/store/security/state.js | 1 + .../src/js/module/i18n/locale/en_US.js | 2 + .../src/js/module/i18n/locale/zh_CN.js | 2 + 12 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/warningGroups.vue diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/warningGroups.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/warningGroups.vue new file mode 100644 index 0000000000..30bcc522fb --- /dev/null +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/warningGroups.vue @@ -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. + */ + + 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 706edcda6a..169ebf87de 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 @@ -51,10 +51,17 @@ type="input" size="small" v-model="title" + :disabled="isDetails" :placeholder="$t('Please enter the title of email')"> + +
*{{$t('Alarm group')}}
+
+ +
+
{{$t('SQL Parameter')}}
@@ -142,6 +149,7 @@ import mDatasource from './_source/datasource' import mLocalParams from './_source/localParams' import mStatementList from './_source/statementList' + import mWarningGroups from './_source/warningGroups' import disabledState from '@/module/mixin/disabledState' import codemirror from '@/conf/home/pages/resource/pages/file/pages/_source/codemirror' @@ -176,7 +184,8 @@ // Post statements postStatements: [], item: '', - scriptBoxDialog: false + scriptBoxDialog: false, + groupId: null } }, mixins: [disabledState], @@ -245,16 +254,16 @@ if (!this.$refs.refDs._verifDatasource()) { return false } - if (this.sqlType === 0 && !this.showType.length) { + 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) { + 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')}`) + if (this.sqlType === '0' && (this.groupId === '' || this.groupId === null)) { + this.$message.warning(`${i18n.$t('Alarm group required')}`) return false } // udfs Subcomponent verification Verification only if the data type is HIVE @@ -287,6 +296,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, + groupId: this.groupId, showType: (() => { /** * Special processing return order TABLE,ATTACHMENT @@ -347,6 +357,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, + groupId: this.groupId, showType: (() => { let showType = this.showType if (showType.length === 2 && showType[0] === 'ATTACHMENT') { @@ -377,6 +388,7 @@ } if (val !== 0) { this.title = '' + this.groupId = null } }, // Listening data source @@ -411,6 +423,7 @@ this.preStatements = o.params.preStatements || [] this.postStatements = o.params.postStatements || [] this.title = o.params.title || '' + this.groupId = o.params.groupId } }, mounted () { @@ -436,6 +449,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, + groupId: this.groupId, showType: (() => { let showType = this.showType if (showType.length === 2 && showType[0] === 'ATTACHMENT') { @@ -451,6 +465,6 @@ } } }, - components: { mListBox, mDatasource, mLocalParams, mUdfs, mSqlType, mStatementList, mScriptBox } + components: { mListBox, mDatasource, mLocalParams, mUdfs, mSqlType, mStatementList, mScriptBox, mWarningGroups } } 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 bcc91524ff..de42199a1a 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 @@ -26,7 +26,7 @@
  • {{$t('Process priority')}}:{{startupParam.processInstancePriority}}
  • {{$t('Worker group')}}:{{startupParam.workerGroup}}
  • {{$t('Notification strategy')}}:{{_rtWarningType(startupParam.warningType)}}
  • -
  • {{$t('Notification group')}}:{{_rtNotifyGroupName(startupParam.warningGroupId)}}
  • +
  • {{$t('Alarm group')}}:{{_rtNotifyGroupName(startupParam.warningGroupId)}}
  • diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue index d9acb38453..65510bf69b 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue @@ -42,7 +42,7 @@ methods: { ...mapMutations('dag', ['resetParams', 'setIsDetails']), ...mapActions('dag', ['getProcessList', 'getProjectList', 'getResourcesList', 'getProcessDetails', 'getResourcesListJar']), - ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll']), + ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll', 'getAlarmGroupsAll']), /** * init */ @@ -64,6 +64,8 @@ this.getResourcesListJar(), // get worker group list this.getWorkerGroupsAll(), + // get alarm group list + this.getAlarmGroupsAll(), this.getTenantList() ]).then((data) => { let item = data[0] diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue index d232e2dd86..81d129a47e 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue @@ -41,7 +41,7 @@ methods: { ...mapMutations('dag', ['resetParams']), ...mapActions('dag', ['getProcessList', 'getProjectList', 'getResourcesList', 'getResourcesListJar', 'getResourcesListJar']), - ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll']), + ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll', 'getAlarmGroupsAll']), /** * init */ @@ -63,6 +63,8 @@ this.getResourcesListJar(), // get worker group list this.getWorkerGroupsAll(), + // get alarm group list + this.getAlarmGroupsAll(), this.getTenantList() ]).then((data) => { this.isLoading = false diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue index 0727d12eed..f9561bd52c 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue @@ -44,7 +44,7 @@ methods: { ...mapMutations('dag', ['setIsDetails', 'resetParams']), ...mapActions('dag', ['getProcessList', 'getProjectList', 'getResourcesList', 'getInstancedetail', 'getResourcesListJar']), - ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll']), + ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll', 'getAlarmGroupsAll']), /** * init */ @@ -66,6 +66,8 @@ this.getResourcesListJar(), // get worker group list this.getWorkerGroupsAll(), + // get alarm group list + this.getAlarmGroupsAll(), this.getTenantList() ]).then((data) => { let item = data[0] diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue index 64c3f880b5..32612213ac 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue @@ -129,6 +129,7 @@ diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue index e2ab711528..e9f615d340 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue @@ -78,15 +78,16 @@
    - {{$t('Notification group')}} + {{$t('Alarm group')}}
    - + @@ -263,7 +264,6 @@ }) }, _getGlobalParams () { - this.setIsDetails(true) this.store.dispatch('dag/getProcessDetails', this.startData.id).then(res => { this.definitionGlobalParams = _.cloneDeep(this.store.state.dag.globalParams) this.udpList = _.cloneDeep(this.store.state.dag.globalParams) diff --git a/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js b/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js index 9405d264a4..97df05d7bc 100644 --- a/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js +++ b/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js @@ -600,6 +600,19 @@ export default { }) }) }, + /** + * get alarm groups all + */ + getAlarmGroupsAll ({ state }, payload) { + return new Promise((resolve, reject) => { + io.get('alert-group/list', payload, res => { + state.alarmGroupsListAll = res.data + resolve(res) + }).catch(e => { + reject(e) + }) + }) + }, saveWorkerGroups ({ state }, payload) { return new Promise((resolve, reject) => { io.post('worker-group/save', payload, res => { diff --git a/dolphinscheduler-ui/src/js/conf/home/store/security/state.js b/dolphinscheduler-ui/src/js/conf/home/store/security/state.js index f3533265a9..a959d9431f 100644 --- a/dolphinscheduler-ui/src/js/conf/home/store/security/state.js +++ b/dolphinscheduler-ui/src/js/conf/home/store/security/state.js @@ -16,5 +16,6 @@ */ export default { workerGroupsListAll: [], + alarmGroupsListAll: [], tenantAllList: [] } 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 168258a9f6..34145e7132 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js @@ -207,6 +207,8 @@ export default { 'UDF resources': 'UDF resources', 'UDF resources directory': 'UDF resources directory', 'Please select UDF resources directory': 'Please select UDF resources directory', + 'Alarm group': 'Alarm group', + 'Alarm group required': 'Alarm group required', 'Edit alarm group': 'Edit alarm group', 'Create alarm group': 'Create alarm group', 'Create Alarm Instance': 'Create Alarm Instance', 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 fb3bd3fb5b..7cafa9dec1 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js @@ -207,6 +207,8 @@ export default { 'UDF resources': 'UDF资源', 'UDF resources directory': 'UDF资源目录', 'Please select UDF resources directory': '请选择UDF资源目录', + 'Alarm group': '告警组', + 'Alarm group required': '告警组必填', 'Edit alarm group': '编辑告警组', 'Create alarm group': '创建告警组', 'Create Alarm Instance': '创建告警实例', From 243ad386d0b9a30879f43fa06f55276911cfbbd6 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 00:26:19 +0800 Subject: [PATCH 02/24] [Improvement][alert-spi]plugin instance only saves the main information plugin instance only saves the main information when users need to display all the complete information (usually UI display), then do the conversion. --- .../alert/dingtalk/DingTalkAlertChannel.java | 7 ++- .../plugin/alert/email/EmailAlertChannel.java | 6 +- .../plugin/alert/http/HttpAlertChannel.java | 6 +- .../alert/script/ScriptAlertChannel.java | 7 ++- .../script/ScriptAlertChannelFactoryTest.java | 12 +++- .../alert/wechat/WeChatAlertChannel.java | 6 +- .../impl/AlertPluginInstanceServiceImpl.java | 62 +++++++++++++++++-- .../spi/alert/AlertResult.java | 8 +++ .../spi/params/base/PluginParams.java | 4 ++ 9 files changed, 104 insertions(+), 14 deletions(-) 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 index 7adfacce39..a2815c1736 100644 --- 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 @@ -21,7 +21,7 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -35,7 +35,10 @@ public class DingTalkAlertChannel implements AlertChannel { AlertData alertData = alertInfo.getAlertData(); String alertParams = alertInfo.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); + if(null==paramsMap){ + return new AlertResult("false","ding talk params is null"); + } return new DingTalkSender(paramsMap).sendDingTalkMsg(alertData.getTitle(), alertData.getContent()); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java index c793af5710..843266fd18 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java @@ -22,6 +22,7 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -39,7 +40,10 @@ public class EmailAlertChannel implements AlertChannel { AlertData alert = info.getAlertData(); String alertParams = info.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); + if(null==paramsMap){ + return new AlertResult("false","mail params is null"); + } MailSender mailSender = new MailSender(paramsMap); AlertResult alertResult = mailSender.sendMails(alert.getTitle(), alert.getContent()); 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 index 27bc1903d8..b4d1aa30a1 100644 --- 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 @@ -22,6 +22,7 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -34,7 +35,10 @@ public class HttpAlertChannel implements AlertChannel { AlertData alertData = alertInfo.getAlertData(); String alertParams = alertInfo.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); + if(null==paramsMap){ + return new AlertResult("false","http params is null"); + } return new HttpSender(paramsMap).send(alertData.getContent()); } 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 index 2a0021277d..bebb18dc04 100644 --- 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 @@ -21,7 +21,7 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -34,7 +34,10 @@ public class ScriptAlertChannel implements AlertChannel { public AlertResult process(AlertInfo alertinfo) { AlertData alertData = alertinfo.getAlertData(); String alertParams = alertinfo.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); + if(null==paramsMap){ + return new AlertResult("false","ding talk params is null"); + } return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle()); } } 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 72f2197315..c8ffce5469 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 @@ -18,9 +18,11 @@ package org.apache.dolphinscheduler.plugin.alert.script; import org.apache.dolphinscheduler.spi.alert.AlertChannel; +import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.utils.JSONUtils; +import java.util.HashMap; import java.util.List; import org.junit.Assert; @@ -35,8 +37,16 @@ public class ScriptAlertChannelFactoryTest { public void testGetParams() { ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); List params = scriptAlertChannelFactory.getParams(); - JSONUtils.toJsonString(params); + + String pluginParamsMapString= JSONUtils.toJsonString(PluginParamsTransfer.getPluginParamsMap(JSONUtils.toJsonString(params))); + HashMap paramsMap= JSONUtils.parseObject(pluginParamsMapString,HashMap.class); + System.out.println(paramsMap.get("path")); Assert.assertEquals(3, params.size()); + List paramss= JSONUtils.toList(JSONUtils.toJsonString(params),PluginParams.class); + + System.out.println(PluginParamsTransfer.getPluginParamsMap(JSONUtils.toJsonString(params))); + System.out.println(paramss.get(0).getName()); + System.out.println(paramss.get(0).getName()); } @Test 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 index 4cdd4d375c..299b0dda8c 100644 --- 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 @@ -22,6 +22,7 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -34,7 +35,10 @@ public class WeChatAlertChannel implements AlertChannel { public AlertResult process(AlertInfo info) { AlertData alertData = info.getAlertData(); String alertParams = info.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); + if(null==paramsMap){ + return new AlertResult("false","we chat params is null"); + } return new WeChatSender(paramsMap).sendEnterpriseWeChat(alertData.getTitle(), alertData.getContent()); } 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 index 8004a90fae..7e0b2578b7 100644 --- 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 @@ -24,16 +24,20 @@ import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.vo.AlertPluginInstanceVO; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.CollectionUtils; +import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; import org.apache.dolphinscheduler.dao.entity.PluginDefine; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; +import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; +import org.apache.dolphinscheduler.spi.params.base.PluginParams; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; @@ -67,7 +71,8 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert @Override public Map create(User loginUser, int pluginDefineId, String instanceName, String pluginInstanceParams) { AlertPluginInstance alertPluginInstance = new AlertPluginInstance(); - alertPluginInstance.setPluginInstanceParams(pluginInstanceParams); + String paramsMapJson = parsePluginParamsMap(pluginInstanceParams); + alertPluginInstance.setPluginInstanceParams(paramsMapJson); alertPluginInstance.setInstanceName(instanceName); alertPluginInstance.setPluginDefineId(pluginDefineId); @@ -82,7 +87,9 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert if (i > 0) { putMsg(result, Status.SUCCESS); + return result; } + putMsg(result, Status.SAVE_ERROR); return result; } @@ -98,7 +105,8 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert public Map update(User loginUser, int pluginInstanceId, String instanceName, String pluginInstanceParams) { AlertPluginInstance alertPluginInstance = new AlertPluginInstance(); - alertPluginInstance.setPluginInstanceParams(pluginInstanceParams); + String paramsMapJson = parsePluginParamsMap(pluginInstanceParams); + alertPluginInstance.setPluginInstanceParams(paramsMapJson); alertPluginInstance.setInstanceName(instanceName); alertPluginInstance.setId(pluginInstanceId); Map result = new HashMap<>(); @@ -106,8 +114,9 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert if (i > 0) { putMsg(result, Status.SUCCESS); + return result; } - + putMsg(result, Status.SAVE_ERROR); return result; } @@ -188,21 +197,62 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert if (CollectionUtils.isEmpty(pluginDefineList)) { return null; } - Map pluginDefineMap = pluginDefineList.stream().collect(Collectors.toMap(PluginDefine::getId, PluginDefine::getPluginName)); + Map pluginDefineMap = pluginDefineList.stream().collect(Collectors.toMap(PluginDefine::getId, Function.identity())); List alertPluginInstanceVOS = new ArrayList<>(); alertPluginInstances.forEach(alertPluginInstance -> { AlertPluginInstanceVO alertPluginInstanceVO = new AlertPluginInstanceVO(); - alertPluginInstanceVO.setAlertPluginName(pluginDefineMap.get(alertPluginInstance.getPluginDefineId())); + alertPluginInstanceVO.setCreateTime(alertPluginInstance.getCreateTime()); alertPluginInstanceVO.setUpdateTime(alertPluginInstance.getUpdateTime()); alertPluginInstanceVO.setPluginDefineId(alertPluginInstance.getPluginDefineId()); alertPluginInstanceVO.setInstanceName(alertPluginInstance.getInstanceName()); alertPluginInstanceVO.setId(alertPluginInstance.getId()); + PluginDefine pluginDefine = pluginDefineMap.get(alertPluginInstance.getPluginDefineId()); + //FIXME When the user removes the plug-in, this will happen. At this time, maybe we should add a new field to indicate that the plug-in has expired? + if (null == pluginDefine) { + return; + } + alertPluginInstanceVO.setAlertPluginName(pluginDefine.getPluginName()); //todo List pages do not recommend returning this parameter - alertPluginInstanceVO.setPluginInstanceParams(alertPluginInstance.getPluginInstanceParams()); + String pluginParamsMapString = alertPluginInstance.getPluginInstanceParams(); + String uiPluginParams=parseToPluginUiParams(pluginParamsMapString,pluginDefine.getPluginParams()); + alertPluginInstanceVO.setPluginInstanceParams(uiPluginParams); alertPluginInstanceVOS.add(alertPluginInstanceVO); }); return alertPluginInstanceVOS; } + + /** + * Get the parameters actually needed by the plugin + * + * @param pluginParams Complete parameters(include ui) + * @return k, v(json string) + */ + private String parsePluginParamsMap(String pluginParams) { + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(pluginParams); + return JSONUtils.toJsonString(paramsMap); + } + + /** + * parseToPluginUiParams + * + * @param pluginParamsMapString k-v data + * @param pluginUiParams Complete parameters(include ui) + * @return Complete parameters list(include ui) + */ + private String parseToPluginUiParams(String pluginParamsMapString, String pluginUiParams) { + //todo npe + HashMap paramsMap = JSONUtils.parseObject(pluginParamsMapString, HashMap.class); + assert paramsMap != null; + List pluginParamsList = JSONUtils.toList(pluginUiParams, PluginParams.class); + List newPluginParamsList = new ArrayList<>(pluginParamsList.size()); + pluginParamsList.forEach(pluginParams -> { + pluginParams.setValue(paramsMap.get(pluginParams.getName())); + newPluginParamsList.add(pluginParams); + + }); + + return JSONUtils.toJsonString(newPluginParamsList); + } } 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..6ce5425f7f 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,12 @@ public class AlertResult { public void setMessage(String message) { this.message = message; } + + public AlertResult(String status, String message) { + this.status = status; + this.message = message; + } + + public AlertResult() { + } } diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java index 1fdf0e0792..34d60a26c4 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java @@ -165,6 +165,10 @@ public class PluginParams { public List getValidateList() { return validateList; } + + public void setValue(Object value) { + this.value = value; + } } From 5f23ca5deea4203367beda954a3823fecfe65528 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 09:50:23 +0800 Subject: [PATCH 03/24] [Improvement][alert-spi]plugin instance only saves the main information plugin instance only saves the main information when users need to display all the complete information (usually UI display), then do the conversion. --- .../alert/dingtalk/DingTalkAlertChannel.java | 3 +-- .../plugin/alert/email/EmailAlertChannel.java | 9 +++----- .../email/EmailAlertChannelFactoryTest.java | 23 ++----------------- .../alert/email/EmailAlertChannelTest.java | 6 ++++- .../plugin/alert/http/HttpAlertChannel.java | 9 +++----- .../alert/http/HttpAlertChannelTest.java | 7 ++++-- .../alert/script/ScriptAlertChannel.java | 8 +++---- .../script/ScriptAlertChannelFactoryTest.java | 12 ---------- .../alert/wechat/WeChatAlertChannel.java | 9 +++----- .../alert/runner/AlertSender.java | 15 +++++++----- .../impl/AlertPluginInstanceServiceImpl.java | 11 +++++---- .../dolphinscheduler/spi/alert/AlertInfo.java | 8 ++++--- 12 files changed, 46 insertions(+), 74 deletions(-) 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 index a2815c1736..db83e396bf 100644 --- 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 @@ -34,8 +34,7 @@ public class DingTalkAlertChannel implements AlertChannel { public AlertResult process(AlertInfo alertInfo) { AlertData alertData = alertInfo.getAlertData(); - String alertParams = alertInfo.getAlertParams(); - Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); + Map paramsMap = alertInfo.getAlertParams(); if(null==paramsMap){ return new AlertResult("false","ding talk params is null"); } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java index 843266fd18..3dbf0b8fb9 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannel.java @@ -21,8 +21,6 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -39,10 +37,9 @@ public class EmailAlertChannel implements AlertChannel { public AlertResult process(AlertInfo info) { AlertData alert = info.getAlertData(); - String alertParams = info.getAlertParams(); - Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); - if(null==paramsMap){ - return new AlertResult("false","mail params is null"); + Map paramsMap = info.getAlertParams(); + if (null == paramsMap) { + return new AlertResult("false", "mail params is null"); } MailSender mailSender = new MailSender(paramsMap); AlertResult alertResult = mailSender.sendMails(alert.getTitle(), alert.getContent()); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java index 977cd8fefc..37a11e47fb 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactoryTest.java @@ -19,13 +19,10 @@ package org.apache.dolphinscheduler.plugin.alert.email; 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.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; /** @@ -36,29 +33,13 @@ import org.junit.Test; */ public class EmailAlertChannelFactoryTest { - @Before - public void before() throws Exception { - } - - @After - public void after() throws Exception { - } - - /** - * Method: getName() - */ - @Test - public void testGetName() throws Exception { - } - /** * Method: getParams() */ @Test - public void testGetParams() throws Exception { + public void testGetParams() { EmailAlertChannelFactory emailAlertChannelFactory = new EmailAlertChannelFactory(); List params = emailAlertChannelFactory.getParams(); - System.out.println(JSONUtils.toJsonString(params)); Assert.assertEquals(12, params.size()); } @@ -66,7 +47,7 @@ public class EmailAlertChannelFactoryTest { * Method: create() */ @Test - public void testCreate() throws Exception { + public void testCreate() { EmailAlertChannelFactory emailAlertChannelFactory = new EmailAlertChannelFactory(); AlertChannel alertChannel = emailAlertChannelFactory.create(); Assert.assertNotNull(alertChannel); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java index 97a1013399..fc28df272c 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java @@ -24,6 +24,7 @@ import org.apache.dolphinscheduler.spi.alert.AlertResult; import org.apache.dolphinscheduler.spi.alert.ShowType; import org.apache.dolphinscheduler.spi.params.InputParam; import org.apache.dolphinscheduler.spi.params.PasswordParam; +import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.RadioParam; import org.apache.dolphinscheduler.spi.params.base.DataType; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; @@ -34,6 +35,7 @@ import org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.junit.Assert; import org.junit.Test; @@ -66,7 +68,9 @@ public class EmailAlertChannelTest { .setTitle("test"); AlertInfo alertInfo = new AlertInfo(); alertInfo.setAlertData(alertData); - alertInfo.setAlertParams(getEmailAlertParams()); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(getEmailAlertParams()); + + alertInfo.setAlertParams(paramsMap); AlertResult alertResult = emailAlertChannel.process(alertInfo); Assert.assertNotNull(alertResult); Assert.assertEquals("false", alertResult.getStatus()); 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 index b4d1aa30a1..cb550b7541 100644 --- 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 @@ -21,8 +21,6 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -34,10 +32,9 @@ public class HttpAlertChannel implements AlertChannel { public AlertResult process(AlertInfo alertInfo) { AlertData alertData = alertInfo.getAlertData(); - String alertParams = alertInfo.getAlertParams(); - Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); - if(null==paramsMap){ - return new AlertResult("false","http params is null"); + Map paramsMap = alertInfo.getAlertParams(); + if (null == paramsMap) { + return new AlertResult("false", "http params is null"); } return new HttpSender(paramsMap).send(alertData.getContent()); 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 index 31a438b4fc..4d385e8a54 100644 --- 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 @@ -21,12 +21,14 @@ 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.PluginParamsTransfer; 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 java.util.Map; import org.junit.Assert; import org.junit.Test; @@ -45,7 +47,7 @@ public class HttpAlertChannelTest { alertData.setContent("Fault tolerance warning"); alertInfo.setAlertData(alertData); AlertResult alertResult = alertChannel.process(alertInfo); - Assert.assertEquals("Request types are not supported", alertResult.getMessage()); + Assert.assertEquals("http params is null", alertResult.getMessage()); } @Test @@ -56,7 +58,8 @@ public class HttpAlertChannelTest { AlertData alertData = new AlertData(); alertData.setContent("Fault tolerance warning"); alertInfo.setAlertData(alertData); - alertInfo.setAlertParams(getParams()); + Map paramsMap = PluginParamsTransfer.getPluginParamsMap(getParams()); + alertInfo.setAlertParams(paramsMap); AlertResult alertResult = alertChannel.process(alertInfo); Assert.assertEquals("true", alertResult.getStatus()); } 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 index bebb18dc04..dc6aa27e25 100644 --- 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 @@ -21,7 +21,6 @@ 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.utils.JSONUtils; import java.util.Map; @@ -33,10 +32,9 @@ public class ScriptAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo alertinfo) { AlertData alertData = alertinfo.getAlertData(); - String alertParams = alertinfo.getAlertParams(); - Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); - if(null==paramsMap){ - return new AlertResult("false","ding talk params is null"); + Map paramsMap = alertinfo.getAlertParams(); + if (null == paramsMap) { + return new AlertResult("false", "ding talk params is null"); } return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle()); } 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 c8ffce5469..8cedc2c38e 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 @@ -18,11 +18,8 @@ package org.apache.dolphinscheduler.plugin.alert.script; import org.apache.dolphinscheduler.spi.alert.AlertChannel; -import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; -import org.apache.dolphinscheduler.spi.utils.JSONUtils; -import java.util.HashMap; import java.util.List; import org.junit.Assert; @@ -37,16 +34,7 @@ public class ScriptAlertChannelFactoryTest { public void testGetParams() { ScriptAlertChannelFactory scriptAlertChannelFactory = new ScriptAlertChannelFactory(); List params = scriptAlertChannelFactory.getParams(); - - String pluginParamsMapString= JSONUtils.toJsonString(PluginParamsTransfer.getPluginParamsMap(JSONUtils.toJsonString(params))); - HashMap paramsMap= JSONUtils.parseObject(pluginParamsMapString,HashMap.class); - System.out.println(paramsMap.get("path")); Assert.assertEquals(3, params.size()); - List paramss= JSONUtils.toList(JSONUtils.toJsonString(params),PluginParams.class); - - System.out.println(PluginParamsTransfer.getPluginParamsMap(JSONUtils.toJsonString(params))); - System.out.println(paramss.get(0).getName()); - System.out.println(paramss.get(0).getName()); } @Test 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 index 299b0dda8c..36cce09ff3 100644 --- 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 @@ -21,8 +21,6 @@ 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 org.apache.dolphinscheduler.spi.utils.JSONUtils; import java.util.Map; @@ -34,10 +32,9 @@ public class WeChatAlertChannel implements AlertChannel { @Override public AlertResult process(AlertInfo info) { AlertData alertData = info.getAlertData(); - String alertParams = info.getAlertParams(); - Map paramsMap = JSONUtils.parseObject(alertParams,Map.class); - if(null==paramsMap){ - return new AlertResult("false","we chat params is null"); + Map paramsMap = info.getAlertParams(); + if (null == paramsMap) { + return new AlertResult("false", "we chat params is null"); } return new WeChatSender(paramsMap).sendEnterpriseWeChat(alertData.getTitle(), alertData.getContent()); 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 e8c6880f55..f0c96bb518 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 @@ -20,6 +20,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.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.PluginDao; import org.apache.dolphinscheduler.dao.entity.Alert; @@ -33,6 +34,7 @@ import org.apache.dolphinscheduler.spi.alert.AlertResult; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -79,9 +81,9 @@ public class AlertSender { } AlertData alertData = new AlertData(); alertData.setId(alert.getId()) - .setContent(alert.getContent()) - .setLog(alert.getLog()) - .setTitle(alert.getTitle()); + .setContent(alert.getContent()) + .setLog(alert.getLog()) + .setTitle(alert.getTitle()); for (AlertPluginInstance instance : alertInstanceList) { @@ -107,7 +109,7 @@ public class AlertSender { List alertInstanceList = alertDao.listInstanceByAlertGroupId(alertGroupId); AlertData alertData = new AlertData(); alertData.setContent(content) - .setTitle(title); + .setTitle(title); boolean sendResponseStatus = true; List sendResponseResults = new ArrayList<>(); @@ -126,7 +128,7 @@ public class AlertSender { for (AlertPluginInstance instance : alertInstanceList) { AlertResult alertResult = this.alertResultHandler(instance, alertData); AlertSendResponseResult alertSendResponseResult = new AlertSendResponseResult( - Boolean.parseBoolean(String.valueOf(alertResult.getStatus())), alertResult.getMessage()); + Boolean.parseBoolean(String.valueOf(alertResult.getStatus())), alertResult.getMessage()); sendResponseStatus = sendResponseStatus && alertSendResponseResult.getStatus(); sendResponseResults.add(alertSendResponseResult); } @@ -156,7 +158,8 @@ public class AlertSender { AlertInfo alertInfo = new AlertInfo(); alertInfo.setAlertData(alertData); - alertInfo.setAlertParams(instance.getPluginInstanceParams()); + Map paramsMap = JSONUtils.toMap(instance.getPluginInstanceParams()); + alertInfo.setAlertParams(paramsMap); AlertResult alertResult = alertChannel.process(alertInfo); if (alertResult == null) { 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 index 7e0b2578b7..6b0c358db9 100644 --- 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 @@ -33,6 +33,8 @@ import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import org.apache.commons.collections4.MapUtils; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -215,7 +217,7 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert alertPluginInstanceVO.setAlertPluginName(pluginDefine.getPluginName()); //todo List pages do not recommend returning this parameter String pluginParamsMapString = alertPluginInstance.getPluginInstanceParams(); - String uiPluginParams=parseToPluginUiParams(pluginParamsMapString,pluginDefine.getPluginParams()); + String uiPluginParams = parseToPluginUiParams(pluginParamsMapString, pluginDefine.getPluginParams()); alertPluginInstanceVO.setPluginInstanceParams(uiPluginParams); alertPluginInstanceVOS.add(alertPluginInstanceVO); }); @@ -242,9 +244,10 @@ public class AlertPluginInstanceServiceImpl extends BaseService implements Alert * @return Complete parameters list(include ui) */ private String parseToPluginUiParams(String pluginParamsMapString, String pluginUiParams) { - //todo npe - HashMap paramsMap = JSONUtils.parseObject(pluginParamsMapString, HashMap.class); - assert paramsMap != null; + Map paramsMap = JSONUtils.toMap(pluginParamsMapString); + if (MapUtils.isEmpty(paramsMap)) { + return null; + } List pluginParamsList = JSONUtils.toList(pluginUiParams, PluginParams.class); List newPluginParamsList = new ArrayList<>(pluginParamsList.size()); pluginParamsList.forEach(pluginParams -> { diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java index c91428ce12..d6e54561e7 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java @@ -17,6 +17,8 @@ package org.apache.dolphinscheduler.spi.alert; +import java.util.Map; + /** * AlertInfo */ @@ -25,18 +27,18 @@ public class AlertInfo { /** * all params this plugin need is in alertProps */ - private String alertParams; + private Map alertParams; /** * the alert content */ private AlertData alertData; - public String getAlertParams() { + public Map getAlertParams() { return alertParams; } - public void setAlertParams(String alertParams) { + public void setAlertParams(Map alertParams) { this.alertParams = alertParams; } From 82340b311cc1055ae4e5c58a03d0445709927dc8 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 09:54:58 +0800 Subject: [PATCH 04/24] code style --- .../plugin/alert/dingtalk/DingTalkAlertChannel.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 index db83e396bf..6b13f24d86 100644 --- 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 @@ -21,7 +21,6 @@ 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.utils.JSONUtils; import java.util.Map; @@ -35,8 +34,8 @@ public class DingTalkAlertChannel implements AlertChannel { AlertData alertData = alertInfo.getAlertData(); Map paramsMap = alertInfo.getAlertParams(); - if(null==paramsMap){ - return new AlertResult("false","ding talk params is null"); + if (null == paramsMap) { + return new AlertResult("false", "ding talk params is null"); } return new DingTalkSender(paramsMap).sendDingTalkMsg(alertData.getTitle(), alertData.getContent()); } From 81e2b82788d635c4085fad9723ad427b0f65e689 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 10:39:28 +0800 Subject: [PATCH 05/24] Store plug-in information when loading plug-in, query database when removing alert --- .../alert/plugin/AlertPluginManager.java | 9 ++++++++- .../alert/runner/AlertSender.java | 2 +- .../apache/dolphinscheduler/dao/PluginDao.java | 18 +++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) 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 a660087c89..7b26a821c3 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 @@ -31,6 +31,7 @@ import org.apache.dolphinscheduler.spi.classloader.ThreadContextClassLoader; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -47,6 +48,11 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { private final Map alertChannelFactoryMap = new ConcurrentHashMap<>(); private final Map alertChannelMap = new ConcurrentHashMap<>(); + /** + * k->pluginDefineId v->pluginDefineName + */ + public static Map pluginDefineMap = new HashMap<>(); + public void addAlertChannelFactory(AlertChannelFactory alertChannelFactory) { requireNonNull(alertChannelFactory, "alertChannelFactory is null"); @@ -93,7 +99,8 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { String paramsJson = PluginParamsTransfer.transferParamsToJson(params); PluginDefine pluginDefine = new PluginDefine(nameEn, PluginType.ALERT.getDesc(), paramsJson); - pluginDao.addOrUpdatePluginDefine(pluginDefine); + int id = pluginDao.addOrUpdatePluginDefine(pluginDefine); + pluginDefineMap.put(id, pluginDefine.getPluginName()); } } } 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 f0c96bb518..7042a0dd37 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 @@ -144,7 +144,7 @@ public class AlertSender { * @return AlertResult */ private AlertResult alertResultHandler(AlertPluginInstance instance, AlertData alertData) { - String pluginName = pluginDao.getPluginDefineById(instance.getPluginDefineId()).getPluginName(); + String pluginName = AlertPluginManager.pluginDefineMap.get(instance.getPluginDefineId()); AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); AlertResult alertResultExtend = new AlertResult(); String pluginInstanceName = instance.getInstanceName(); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java index ab82997bc2..93df36aadc 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java @@ -58,22 +58,22 @@ public class PluginDao extends AbstractBaseDao { * * @param pluginDefine new pluginDefine */ - public void addOrUpdatePluginDefine(PluginDefine pluginDefine) { + public int addOrUpdatePluginDefine(PluginDefine pluginDefine) { requireNonNull(pluginDefine, "pluginDefine is null"); requireNonNull(pluginDefine.getPluginName(), "pluginName is null"); requireNonNull(pluginDefine.getPluginType(), "pluginType is null"); List pluginDefineList = pluginDefineMapper.queryByNameAndType(pluginDefine.getPluginName(), pluginDefine.getPluginType()); if (pluginDefineList == null || pluginDefineList.size() == 0) { - pluginDefineMapper.insert(pluginDefine); - } else { - PluginDefine currPluginDefine = pluginDefineList.get(0); - if (!currPluginDefine.getPluginParams().equals(pluginDefine.getPluginParams())) { - currPluginDefine.setUpdateTime(pluginDefine.getUpdateTime()); - currPluginDefine.setPluginParams(pluginDefine.getPluginParams()); - pluginDefineMapper.updateById(currPluginDefine); - } + return pluginDefineMapper.insert(pluginDefine); } + PluginDefine currPluginDefine = pluginDefineList.get(0); + if (!currPluginDefine.getPluginParams().equals(pluginDefine.getPluginParams())) { + currPluginDefine.setUpdateTime(pluginDefine.getUpdateTime()); + currPluginDefine.setPluginParams(pluginDefine.getPluginParams()); + pluginDefineMapper.updateById(currPluginDefine); + } + return currPluginDefine.getId(); } /** From 40e3795becfa45cd5b8c320acae412770d664be8 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 11:18:52 +0800 Subject: [PATCH 06/24] Store plug-in information when loading plug-in, query database when removing alert Delete unused class --- .../AlertPluginDefineCache.java} | 31 ++++++----- .../alert/manager/EmailManager.java | 55 ------------------- .../alert/plugin/AlertPluginManager.java | 9 +-- .../alert/runner/AlertSender.java | 3 +- 4 files changed, 20 insertions(+), 78 deletions(-) rename dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/{manager/MsgManager.java => cache/AlertPluginDefineCache.java} (60%) delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EmailManager.java diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/MsgManager.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java similarity index 60% rename from dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/MsgManager.java rename to dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java index e7fb161162..5648ef2ad2 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/MsgManager.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java @@ -15,26 +15,27 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.alert.manager; +package org.apache.dolphinscheduler.alert.cache; -import org.apache.dolphinscheduler.dao.entity.Alert; +import java.util.HashMap; +import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +public class AlertPluginDefineCache { -/** - * SMS send manager - */ -public class MsgManager { - - private static final Logger logger = LoggerFactory.getLogger(MsgManager.class); + public AlertPluginDefineCache() { + throw new IllegalStateException("Utility class"); + } /** - * SMS send - * - * @param alert the alert + * k->pluginDefineId v->pluginDefineName */ - public void send(Alert alert) { - logger.info("send message {}", alert); + private static Map pluginDefineMap = new HashMap<>(); + + public static void addPlugin(int id, String name) { + pluginDefineMap.put(id, name); + } + + public static String getNameById(int id) { + return pluginDefineMap.get(id); } } diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EmailManager.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EmailManager.java deleted file mode 100644 index 874b866759..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EmailManager.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.MailUtils; -// -//import java.util.List; -//import java.util.Map; -// -///** -// * email send manager -// */ -//public class EmailManager { -// /** -// * email send -// * @param receiversList the receiver list -// * @param receiversCcList the cc List -// * @param title the title -// * @param content the content -// * @param showType the showType -// * @return the send result -// */ -// public Map send(List receiversList,List receiversCcList,String title,String content,String showType){ -// -// return MailUtils.sendMails(receiversList, receiversCcList, title, content, showType); -// } -// -// /** -// * msg send -// * @param receiversList the receiver list -// * @param title the title -// * @param content the content -// * @param showType the showType -// * @return the send result -// */ -// public Map send(List receiversList,String title,String content,String showType){ -// -// return MailUtils.sendMails(receiversList,title, content, showType); -// } -// -//} 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 7b26a821c3..498fd757e9 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.alert.cache.AlertPluginDefineCache; import org.apache.dolphinscheduler.common.enums.PluginType; import org.apache.dolphinscheduler.dao.entity.PluginDefine; import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; @@ -31,7 +32,6 @@ import org.apache.dolphinscheduler.spi.classloader.ThreadContextClassLoader; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -48,11 +48,6 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { private final Map alertChannelFactoryMap = new ConcurrentHashMap<>(); private final Map alertChannelMap = new ConcurrentHashMap<>(); - /** - * k->pluginDefineId v->pluginDefineName - */ - public static Map pluginDefineMap = new HashMap<>(); - public void addAlertChannelFactory(AlertChannelFactory alertChannelFactory) { requireNonNull(alertChannelFactory, "alertChannelFactory is null"); @@ -100,7 +95,7 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { PluginDefine pluginDefine = new PluginDefine(nameEn, PluginType.ALERT.getDesc(), paramsJson); int id = pluginDao.addOrUpdatePluginDefine(pluginDefine); - pluginDefineMap.put(id, pluginDefine.getPluginName()); + AlertPluginDefineCache.addPlugin(id, pluginDefine.getPluginName()); } } } 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 fa260ba94d..0fc8dd07e1 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 @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.alert.runner; +import org.apache.dolphinscheduler.alert.cache.AlertPluginDefineCache; import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.utils.CollectionUtils; @@ -145,7 +146,7 @@ public class AlertSender { * @return AlertResult */ private AlertResult alertResultHandler(AlertPluginInstance instance, AlertData alertData) { - String pluginName = AlertPluginManager.pluginDefineMap.get(instance.getPluginDefineId()); + String pluginName = AlertPluginDefineCache.getNameById(instance.getPluginDefineId()); AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); AlertResult alertResultExtend = new AlertResult(); String pluginInstanceName = instance.getInstanceName(); From a0725e93ee460d12e93d40e24b5c9ff72db1aede Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 11:57:39 +0800 Subject: [PATCH 07/24] fix ut error --- .../alert/cache/AlertPluginDefineCache.java | 41 ------------------- .../alert/plugin/AlertPluginManager.java | 13 +++++- .../alert/runner/AlertSender.java | 3 +- .../alert/AlertServerTest.java | 2 + 4 files changed, 14 insertions(+), 45 deletions(-) delete mode 100644 dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java deleted file mode 100644 index 5648ef2ad2..0000000000 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/cache/AlertPluginDefineCache.java +++ /dev/null @@ -1,41 +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.cache; - -import java.util.HashMap; -import java.util.Map; - -public class AlertPluginDefineCache { - - public AlertPluginDefineCache() { - throw new IllegalStateException("Utility class"); - } - - /** - * k->pluginDefineId v->pluginDefineName - */ - private static Map pluginDefineMap = new HashMap<>(); - - public static void addPlugin(int id, String name) { - pluginDefineMap.put(id, name); - } - - public static String getNameById(int id) { - return pluginDefineMap.get(id); - } -} 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 498fd757e9..d795e71d52 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,7 +22,6 @@ import static java.util.Objects.requireNonNull; import static com.google.common.base.Preconditions.checkState; -import org.apache.dolphinscheduler.alert.cache.AlertPluginDefineCache; import org.apache.dolphinscheduler.common.enums.PluginType; import org.apache.dolphinscheduler.dao.entity.PluginDefine; import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; @@ -32,6 +31,7 @@ import org.apache.dolphinscheduler.spi.classloader.ThreadContextClassLoader; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -48,6 +48,11 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { private final Map alertChannelFactoryMap = new ConcurrentHashMap<>(); private final Map alertChannelMap = new ConcurrentHashMap<>(); + /** + * k->pluginDefineId v->pluginDefineName + */ + private final Map pluginDefineMap = new HashMap<>(); + public void addAlertChannelFactory(AlertChannelFactory alertChannelFactory) { requireNonNull(alertChannelFactory, "alertChannelFactory is null"); @@ -84,6 +89,10 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { return alertChannelMap; } + public String getPluginNameById(int id) { + return pluginDefineMap.get(id); + } + @Override public void installPlugin(DolphinSchedulerPlugin dolphinSchedulerPlugin) { for (AlertChannelFactory alertChannelFactory : dolphinSchedulerPlugin.getAlertChannelFactorys()) { @@ -95,7 +104,7 @@ public class AlertPluginManager extends AbstractDolphinPluginManager { PluginDefine pluginDefine = new PluginDefine(nameEn, PluginType.ALERT.getDesc(), paramsJson); int id = pluginDao.addOrUpdatePluginDefine(pluginDefine); - AlertPluginDefineCache.addPlugin(id, pluginDefine.getPluginName()); + pluginDefineMap.put(id, pluginDefine.getPluginName()); } } } 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 0fc8dd07e1..44a1047613 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 @@ -17,7 +17,6 @@ package org.apache.dolphinscheduler.alert.runner; -import org.apache.dolphinscheduler.alert.cache.AlertPluginDefineCache; import org.apache.dolphinscheduler.alert.plugin.AlertPluginManager; import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.utils.CollectionUtils; @@ -146,7 +145,7 @@ public class AlertSender { * @return AlertResult */ private AlertResult alertResultHandler(AlertPluginInstance instance, AlertData alertData) { - String pluginName = AlertPluginDefineCache.getNameById(instance.getPluginDefineId()); + String pluginName = alertPluginManager.getPluginNameById(instance.getPluginDefineId()); AlertChannel alertChannel = alertPluginManager.getAlertChannelMap().get(pluginName); AlertResult alertResultExtend = new AlertResult(); String pluginInstanceName = instance.getInstanceName(); 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 a8ead79be9..7293b485d6 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 @@ -34,6 +34,7 @@ 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; @@ -62,6 +63,7 @@ public class AlertServerTest { PowerMockito.whenNew(AlertPluginManager.class).withNoArguments().thenReturn(alertPluginManager); ConcurrentHashMap alertChannelMap = new ConcurrentHashMap<>(); alertChannelMap.put("pluginName",alertChannelMock); + PowerMockito.when(alertPluginManager.getPluginNameById(Mockito.anyInt())).thenReturn("pluginName"); PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); DolphinPluginManagerConfig alertPluginManagerConfig = PowerMockito.mock(DolphinPluginManagerConfig.class); From 65779f0912c479c70b0e89a21888c0282a08d157 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 12:29:34 +0800 Subject: [PATCH 08/24] fix ut error --- .../apache/dolphinscheduler/alert/runner/AlertSenderTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 2664bdcd29..e9fd5ac323 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 @@ -102,6 +102,7 @@ public class AlertSenderTest { Map alertChannelMap = new ConcurrentHashMap<>(); alertChannelMap.put(pluginName,alertChannelMock); PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); + PowerMockito.when(alertPluginManager.getPluginNameById(Mockito.anyInt())).thenReturn("alert-plugin-mail"); alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); @@ -164,6 +165,7 @@ public class AlertSenderTest { String pluginName = "alert-plugin-mail"; PluginDefine pluginDefine = new PluginDefine(pluginName,"1",null); PowerMockito.when(pluginDao.getPluginDefineById(pluginDefineId)).thenReturn(pluginDefine); + PowerMockito.when(alertPluginManager.getPluginNameById(1)).thenReturn("alert-instance-mail"); AlertResult alertResult = new AlertResult(); alertResult.setStatus(String.valueOf(true)); From 68770737779766b670e198714d739050a6d30e07 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 13:38:44 +0800 Subject: [PATCH 09/24] add ut --- .../dolphinscheduler/alert/AlertServer.java | 2 +- .../processor/AlertRequestProcessor.java | 4 +- .../alert/runner/AlertSender.java | 7 +- .../alert/AlertServerTest.java | 7 +- .../alert/plugin/EmailAlertPluginTest.java | 2 +- .../alert/runner/AlertSenderTest.java | 34 +++--- .../AlertPluginInstanceServiceTest.java | 109 +++++++++++++++++- 7 files changed, 134 insertions(+), 31 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 54afc93442..0e6cab6c9c 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 @@ -133,7 +133,7 @@ public class AlertServer { logger.warn("No Alert Plugin . Can not send alert info. "); } else { List alerts = alertDao.listWaitExecutionAlert(); - alertSender = new AlertSender(alerts, alertDao, alertPluginManager, pluginDao); + alertSender = new AlertSender(alerts, alertDao, alertPluginManager); alertSender.run(); } } 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 index 5e8a8f89d6..e88778e3df 100644 --- 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 @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; import io.netty.channel.Channel; /** - * alert request processor + * alert request processor */ public class AlertRequestProcessor implements NettyRequestProcessor { @@ -59,7 +59,7 @@ public class AlertRequestProcessor implements NettyRequestProcessor { command.getBody(), AlertSendRequestCommand.class); logger.info("received command : {}", alertSendRequestCommand); - AlertSender alertSender = new AlertSender(alertDao, alertPluginManager, pluginDao); + AlertSender alertSender = new AlertSender(alertDao, alertPluginManager); 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 44a1047613..304756efc6 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 @@ -48,25 +48,22 @@ public class AlertSender { private List alertList; private AlertDao alertDao; - private PluginDao pluginDao; private AlertPluginManager alertPluginManager; public AlertSender(AlertPluginManager alertPluginManager) { this.alertPluginManager = alertPluginManager; } - public AlertSender(AlertDao alertDao, AlertPluginManager alertPluginManager, PluginDao pluginDao) { + public AlertSender(AlertDao alertDao, AlertPluginManager alertPluginManager) { super(); this.alertDao = alertDao; - this.pluginDao = pluginDao; this.alertPluginManager = alertPluginManager; } - public AlertSender(List alertList, AlertDao alertDao, AlertPluginManager alertPluginManager, PluginDao pluginDao) { + public AlertSender(List alertList, AlertDao alertDao, AlertPluginManager alertPluginManager) { super(); this.alertList = alertList; this.alertDao = alertDao; - this.pluginDao = pluginDao; this.alertPluginManager = alertPluginManager; } 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 7293b485d6..cdc779e35e 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 @@ -40,7 +40,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({AlertServer.class,DaoFactory.class}) +@PrepareForTest({AlertServer.class, DaoFactory.class}) public class AlertServerTest { @Before @@ -62,7 +62,7 @@ public class AlertServerTest { AlertPluginManager alertPluginManager = PowerMockito.mock(AlertPluginManager.class); PowerMockito.whenNew(AlertPluginManager.class).withNoArguments().thenReturn(alertPluginManager); ConcurrentHashMap alertChannelMap = new ConcurrentHashMap<>(); - alertChannelMap.put("pluginName",alertChannelMock); + alertChannelMap.put("pluginName", alertChannelMock); PowerMockito.when(alertPluginManager.getPluginNameById(Mockito.anyInt())).thenReturn("pluginName"); PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); @@ -81,7 +81,8 @@ public class AlertServerTest { Assert.assertNotNull(alertServer); new Thread(() -> { - alertServer.start(); }) + alertServer.start(); + }) .start(); Thread.sleep(5 * Constants.ALERT_SCAN_INTERVAL); 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 3983545140..4f428d4667 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 @@ -136,7 +136,7 @@ public class EmailAlertPluginTest { alertPluginInstance.setPluginInstanceParams(getEmailAlertParams()); alertDao.getAlertPluginInstanceMapper().insert(alertPluginInstance); - AlertSender alertSender = new AlertSender(alertList, alertDao, alertPluginManager, pluginDao); + AlertSender alertSender = new AlertSender(alertList, alertDao, alertPluginManager); alertSender.run(); Alert alertResult = alertDao.getAlertMapper().selectById(alert1.getId()); 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 e9fd5ac323..3b84bdbe67 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 @@ -67,7 +67,7 @@ public class AlertSenderTest { int alertGroupId = 1; String title = "alert mail test title"; String content = "alert mail test content"; - alertSender = new AlertSender(alertDao,alertPluginManager,pluginDao); + alertSender = new AlertSender(alertDao, alertPluginManager); //1.alert instance does not exist PowerMockito.when(alertDao.listInstanceByAlertGroupId(alertGroupId)).thenReturn(null); @@ -75,7 +75,7 @@ public class AlertSenderTest { AlertSendResponseCommand alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); //2.alert plugin does not exist int pluginDefineId = 1; @@ -83,31 +83,31 @@ public class AlertSenderTest { String pluginInstanceName = "alert-instance-mail"; List alertInstanceList = new ArrayList<>(); AlertPluginInstance alertPluginInstance = new AlertPluginInstance( - pluginDefineId,pluginInstanceParams,pluginInstanceName); + pluginDefineId, pluginInstanceParams, pluginInstanceName); alertInstanceList.add(alertPluginInstance); PowerMockito.when(alertDao.listInstanceByAlertGroupId(1)).thenReturn(alertInstanceList); String pluginName = "alert-plugin-mail"; - PluginDefine pluginDefine = new PluginDefine(pluginName,"1",null); + 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())); + 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); + alertChannelMap.put(pluginName, alertChannelMock); PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); PowerMockito.when(alertPluginManager.getPluginNameById(Mockito.anyInt())).thenReturn("alert-plugin-mail"); alertSendResponseCommand = alertSender.syncHandler(alertGroupId, title, content); Assert.assertFalse(alertSendResponseCommand.getResStatus()); alertSendResponseCommand.getResResults().forEach(result -> - logger.info("alert send response result, status:{}, message:{}",result.getStatus(),result.getMessage())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); //4.abnormal information inside the alert plug-in code AlertResult alertResult = new AlertResult(); @@ -115,27 +115,27 @@ public class AlertSenderTest { 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); + 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())); + 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)); + 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); + 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())); + logger.info("alert send response result, status:{}, message:{}", result.getStatus(), result.getMessage())); } @@ -151,29 +151,29 @@ public class AlertSenderTest { alert.setContent(content); alertList.add(alert); - alertSender = new AlertSender(alertList,alertDao,alertPluginManager,pluginDao); + alertSender = new AlertSender(alertList, alertDao, alertPluginManager); int pluginDefineId = 1; String pluginInstanceParams = "alert-instance-mail-params"; String pluginInstanceName = "alert-instance-mail"; List alertInstanceList = new ArrayList<>(); AlertPluginInstance alertPluginInstance = new AlertPluginInstance( - pluginDefineId,pluginInstanceParams,pluginInstanceName); + pluginDefineId, pluginInstanceParams, pluginInstanceName); alertInstanceList.add(alertPluginInstance); PowerMockito.when(alertDao.listInstanceByAlertGroupId(alertGroupId)).thenReturn(alertInstanceList); String pluginName = "alert-plugin-mail"; - PluginDefine pluginDefine = new PluginDefine(pluginName,"1",null); + PluginDefine pluginDefine = new PluginDefine(pluginName, "1", null); PowerMockito.when(pluginDao.getPluginDefineById(pluginDefineId)).thenReturn(pluginDefine); PowerMockito.when(alertPluginManager.getPluginNameById(1)).thenReturn("alert-instance-mail"); AlertResult alertResult = new AlertResult(); alertResult.setStatus(String.valueOf(true)); - alertResult.setMessage(String.format("Alert Plugin %s send success",pluginInstanceName)); + 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); + alertChannelMap.put(pluginName, alertChannelMock); PowerMockito.when(alertPluginManager.getAlertChannelMap()).thenReturn(alertChannelMap); Assert.assertTrue(Boolean.parseBoolean(alertResult.getStatus())); alertSender.run(); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java index 7d25fb5e6a..49593ad275 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java @@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.api.service.impl.AlertPluginInstanceServiceIm import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; +import org.apache.dolphinscheduler.dao.entity.PluginDefine; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper; import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper; @@ -29,6 +30,7 @@ import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -60,6 +62,82 @@ public class AlertPluginInstanceServiceTest { private User user; + private String uiParams="[\n" + + " {\n" + + " \"field\":\"userParams\",\n" + + " \"name\":\"user.params\",\n" + + " \"props\":{\n" + + " \"placeholder\":\"please enter your custom parameters, which will be passed to you when calling your script\",\n" + + " \"size\":\"small\"\n" + + " },\n" + + " \"type\":\"input\",\n" + + " \"title\":\"user.params\",\n" + + " \"value\":\"userParams\",\n" + + " \"validate\":[\n" + + " {\n" + + " \"required\":false,\n" + + " \"message\":null,\n" + + " \"type\":\"string\",\n" + + " \"trigger\":\"blur\",\n" + + " \"min\":null,\n" + + " \"max\":null\n" + + " }\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"field\":\"path\",\n" + + " \"name\":\"path\",\n" + + " \"props\":{\n" + + " \"placeholder\":\"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\",\n" + + " \"size\":\"small\"\n" + + " },\n" + + " \"type\":\"input\",\n" + + " \"title\":\"path\",\n" + + " \"value\":\"/kris/script/path\",\n" + + " \"validate\":[\n" + + " {\n" + + " \"required\":true,\n" + + " \"message\":null,\n" + + " \"type\":\"string\",\n" + + " \"trigger\":\"blur\",\n" + + " \"min\":null,\n" + + " \"max\":null\n" + + " }\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"field\":\"type\",\n" + + " \"name\":\"type\",\n" + + " \"props\":{\n" + + " \"placeholder\":null,\n" + + " \"size\":\"small\"\n" + + " },\n" + + " \"type\":\"radio\",\n" + + " \"title\":\"type\",\n" + + " \"value\":0,\n" + + " \"validate\":[\n" + + " {\n" + + " \"required\":true,\n" + + " \"message\":null,\n" + + " \"type\":\"string\",\n" + + " \"trigger\":\"blur\",\n" + + " \"min\":null,\n" + + " \"max\":null\n" + + " }\n" + + " ],\n" + + " \"options\":[\n" + + " {\n" + + " \"label\":\"SHELL\",\n" + + " \"value\":0,\n" + + " \"disabled\":false\n" + + " }\n" + + " ]\n" + + " }\n" + + "]\n" + + "\n"; + + private String paramsMap="{\"path\":\"/kris/script/path\",\"userParams\":\"userParams\",\"type\":\"0\"}"; + @Before public void before() { user = new User(); @@ -77,10 +155,10 @@ public class AlertPluginInstanceServiceTest { @Test public void testCreate() { Mockito.when(alertPluginInstanceMapper.queryByInstanceName("test")).thenReturn(alertPluginInstances); - Map result = alertPluginInstanceService.create(user, 1, "test", "test params"); + Map result = alertPluginInstanceService.create(user, 1, "test", uiParams); Assert.assertEquals(Status.PLUGIN_INSTANCE_ALREADY_EXIT, result.get(Constants.STATUS)); Mockito.when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(1); - result = alertPluginInstanceService.create(user, 1, "test1", "test params"); + result = alertPluginInstanceService.create(user, 1, "test1", uiParams); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } @@ -96,4 +174,31 @@ public class AlertPluginInstanceServiceTest { } + @Test + public void testUpdate(){ + Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0); + Map result= alertPluginInstanceService.update(user,1,"testUpdate",uiParams); + Assert.assertEquals(Status.SAVE_ERROR, result.get(Constants.STATUS)); + Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(1); + result= alertPluginInstanceService.update(user,1,"testUpdate",uiParams); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + } + + @Test + public void testQueryAll(){ + AlertPluginInstance alertPluginInstance=new AlertPluginInstance(); + alertPluginInstance.setId(1); + alertPluginInstance.setPluginDefineId(1); + alertPluginInstance.setPluginInstanceParams(paramsMap); + alertPluginInstance.setInstanceName("test"); + PluginDefine pluginDefine=new PluginDefine("script","script",uiParams); + pluginDefine.setId(1); + List pluginDefines= Collections.singletonList(pluginDefine); + List pluginInstanceList= Collections.singletonList(alertPluginInstance); + Mockito.when(alertPluginInstanceMapper.queryAllAlertPluginInstanceList()).thenReturn(pluginInstanceList); + Mockito.when(pluginDefineMapper.queryAllPluginDefineList()).thenReturn(pluginDefines); + Map result = alertPluginInstanceService.queryAll(); + Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); + } + } From 8300444f23d9b4e23cbe919ebd3436410fe3937a Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 13:43:14 +0800 Subject: [PATCH 10/24] code style --- .../AlertPluginInstanceServiceTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java index 49593ad275..fb58070304 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceServiceTest.java @@ -62,7 +62,7 @@ public class AlertPluginInstanceServiceTest { private User user; - private String uiParams="[\n" + private String uiParams = "[\n" + " {\n" + " \"field\":\"userParams\",\n" + " \"name\":\"user.params\",\n" @@ -136,7 +136,7 @@ public class AlertPluginInstanceServiceTest { + "]\n" + "\n"; - private String paramsMap="{\"path\":\"/kris/script/path\",\"userParams\":\"userParams\",\"type\":\"0\"}"; + private String paramsMap = "{\"path\":\"/kris/script/path\",\"userParams\":\"userParams\",\"type\":\"0\"}"; @Before public void before() { @@ -175,26 +175,26 @@ public class AlertPluginInstanceServiceTest { } @Test - public void testUpdate(){ + public void testUpdate() { Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(0); - Map result= alertPluginInstanceService.update(user,1,"testUpdate",uiParams); + Map result = alertPluginInstanceService.update(user, 1, "testUpdate", uiParams); Assert.assertEquals(Status.SAVE_ERROR, result.get(Constants.STATUS)); Mockito.when(alertPluginInstanceMapper.updateById(Mockito.any())).thenReturn(1); - result= alertPluginInstanceService.update(user,1,"testUpdate",uiParams); + result = alertPluginInstanceService.update(user, 1, "testUpdate", uiParams); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } @Test - public void testQueryAll(){ - AlertPluginInstance alertPluginInstance=new AlertPluginInstance(); + public void testQueryAll() { + AlertPluginInstance alertPluginInstance = new AlertPluginInstance(); alertPluginInstance.setId(1); alertPluginInstance.setPluginDefineId(1); alertPluginInstance.setPluginInstanceParams(paramsMap); alertPluginInstance.setInstanceName("test"); - PluginDefine pluginDefine=new PluginDefine("script","script",uiParams); + PluginDefine pluginDefine = new PluginDefine("script", "script", uiParams); pluginDefine.setId(1); - List pluginDefines= Collections.singletonList(pluginDefine); - List pluginInstanceList= Collections.singletonList(alertPluginInstance); + List pluginDefines = Collections.singletonList(pluginDefine); + List pluginInstanceList = Collections.singletonList(alertPluginInstance); Mockito.when(alertPluginInstanceMapper.queryAllAlertPluginInstanceList()).thenReturn(pluginInstanceList); Mockito.when(pluginDefineMapper.queryAllPluginDefineList()).thenReturn(pluginDefines); Map result = alertPluginInstanceService.queryAll(); From 9072e88e27d51bb4fc5ccbe121d8cd531f416626 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Fri, 29 Jan 2021 14:03:37 +0800 Subject: [PATCH 11/24] removed unused fields --- .../apache/dolphinscheduler/alert/AlertServer.java | 5 +---- .../alert/processor/AlertRequestProcessor.java | 5 +---- .../dolphinscheduler/alert/runner/AlertSender.java | 1 - .../alert/processor/AlertRequestProcessorTest.java | 11 ++++------- 4 files changed, 6 insertions(+), 16 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 0e6cab6c9c..b25cd57f4c 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 @@ -29,7 +29,6 @@ import org.apache.dolphinscheduler.alert.utils.PropertyUtils; import org.apache.dolphinscheduler.common.thread.Stopper; 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; @@ -53,8 +52,6 @@ public class AlertServer { */ private AlertDao alertDao = DaoFactory.getDaoInstance(AlertDao.class); - private PluginDao pluginDao = DaoFactory.getDaoInstance(PluginDao.class); - private AlertSender alertSender; private static AlertServer instance; @@ -114,7 +111,7 @@ public class AlertServer { NettyServerConfig serverConfig = new NettyServerConfig(); serverConfig.setListenPort(ALERT_RPC_PORT); this.server = new NettyRemotingServer(serverConfig); - this.server.registerProcessor(CommandType.ALERT_SEND_REQUEST, new AlertRequestProcessor(alertDao, alertPluginManager, pluginDao)); + this.server.registerProcessor(CommandType.ALERT_SEND_REQUEST, new AlertRequestProcessor(alertDao, alertPluginManager)); this.server.start(); } 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 index e88778e3df..ec716d9878 100644 --- 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 @@ -21,7 +21,6 @@ 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; @@ -41,12 +40,10 @@ 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) { + public AlertRequestProcessor(AlertDao alertDao, AlertPluginManager alertPluginManager) { this.alertDao = alertDao; - this.pluginDao = pluginDao; this.alertPluginManager = alertPluginManager; } 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 304756efc6..7ab29e1001 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 @@ -22,7 +22,6 @@ import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; 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; 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 0126eb3dae..052d2f3d55 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 @@ -19,7 +19,6 @@ 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.CommandType; import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand; @@ -37,7 +36,6 @@ import io.netty.channel.Channel; public class AlertRequestProcessorTest { private AlertDao alertDao; - private PluginDao pluginDao; private AlertPluginManager alertPluginManager; private AlertRequestProcessor alertRequestProcessor; @@ -45,17 +43,16 @@ public class AlertRequestProcessorTest { @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); + alertRequestProcessor = new AlertRequestProcessor(alertDao, alertPluginManager); } @Test public void testProcess() { Channel channel = PowerMockito.mock(Channel.class); - AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(1,"title","content"); + AlertSendRequestCommand alertSendRequestCommand = new AlertSendRequestCommand(1, "title", "content"); Command reqCommand = alertSendRequestCommand.convert2Command(); - Assert.assertEquals(CommandType.ALERT_SEND_REQUEST,reqCommand.getType()); - alertRequestProcessor.process(channel,reqCommand); + Assert.assertEquals(CommandType.ALERT_SEND_REQUEST, reqCommand.getType()); + alertRequestProcessor.process(channel, reqCommand); } } From fbb77c5cfd9150101a512a5bc342aa8727d2d3d8 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Sat, 30 Jan 2021 13:30:33 +0800 Subject: [PATCH 12/24] merge current --- .../plugin/alert/feishu/FeiShuAlertChannel.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java index 8a195e08f8..3bbdaa9997 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannel.java @@ -21,7 +21,6 @@ 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; @@ -30,8 +29,10 @@ public class FeiShuAlertChannel implements AlertChannel { public AlertResult process(AlertInfo alertInfo) { AlertData alertData = alertInfo.getAlertData(); - String alertParams = alertInfo.getAlertParams(); - Map paramsMap = PluginParamsTransfer.getPluginParamsMap(alertParams); + Map paramsMap = alertInfo.getAlertParams(); + if (null == paramsMap) { + return new AlertResult("false", "fei shu params is null"); + } return new FeiShuSender(paramsMap).sendFeiShuMsg(alertData); } } From a3bbfdb652d2404130901b3631ad280430141ed3 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Sat, 30 Jan 2021 22:41:48 +0800 Subject: [PATCH 13/24] Capture when the alarm is abnormal --- .../dolphinscheduler/alert/runner/AlertSender.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 7ab29e1001..114d01a845 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 @@ -157,7 +157,14 @@ public class AlertSender { alertInfo.setAlertData(alertData); Map paramsMap = JSONUtils.toMap(instance.getPluginInstanceParams()); alertInfo.setAlertParams(paramsMap); - AlertResult alertResult = alertChannel.process(alertInfo); + AlertResult alertResult; + try { + alertResult = alertChannel.process(alertInfo); + } catch (Exception e) { + alertResult = new AlertResult("false", e.getMessage()); + logger.error("send alert error alert data id :{},", alertData.getId(), e); + } + if (alertResult == null) { String message = String.format("Alert Plugin %s send error : return alertResult value is null", pluginInstanceName); From e05d93aa335d872730fb55ece75e093c051ea600 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Sun, 31 Jan 2021 21:04:03 +0800 Subject: [PATCH 14/24] fix ui warningInstance title support internationalization. --- .../warningInstance/_source/createWarningInstance.vue | 10 +++++----- .../pages/security/pages/warningInstance/index.vue | 6 +++--- dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js | 2 ++ dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningInstance/_source/createWarningInstance.vue b/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningInstance/_source/createWarningInstance.vue index c41af3db42..b46e477803 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningInstance/_source/createWarningInstance.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningInstance/_source/createWarningInstance.vue @@ -39,7 +39,7 @@ @@ -86,7 +86,7 @@ isADMIN: store.state.user.userInfo.userType === 'ADMIN_USER', createWarningDialog: false, item: {}, - pulginInstance: [] + pluginInstance: [] } }, mixins: [listUrlParamHandle], @@ -114,7 +114,7 @@ }, _create (item) { this.getPlugins({ pluginType: 'ALERT' }).then(res => { - this.pulginInstance = res + this.pluginInstance = res }).catch(e => { this.$message.error(e.msg) }) 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 168258a9f6..9038e21fa7 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js @@ -400,6 +400,8 @@ export default { 'Please select a notification group': 'Please select a notification group', Recipient: 'Recipient', Cc: 'Cc', + receivers: 'receivers', + receiverCcs: 'receiverCcs', 'Whether it is a complement process?': 'Whether it is a complement process?', 'Schedule date': 'Schedule date', 'Mode of execution': 'Mode of execution', 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 fb3bd3fb5b..61174ae867 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js @@ -400,6 +400,8 @@ export default { 'Please select a notification group': '请选择通知组', Recipient: '收件人', Cc: '抄送人', + receivers: '收件人', + receiverCcs: '抄送人', 'Whether it is a complement process?': '是否补数', 'Schedule date': '调度日期', 'Mode of execution': '执行方式', From b912c98b1b5a352eefdbd7c921b468eacc015c4a Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Mon, 1 Feb 2021 10:34:09 +0800 Subject: [PATCH 15/24] fix --- .../pages/dag/_source/formModel/tasks/sql.vue | 62 +------------------ 1 file changed, 1 insertion(+), 61 deletions(-) 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 169ebf87de..dff7f3f97d 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 @@ -30,16 +30,7 @@
    {{$t('SQL Type')}}
    - - -
    -
    - - {{$t('TableMode')}} - {{$t('Attachment')}} - +
    @@ -175,8 +166,6 @@ sqlType: '0', // Email title title: '', - // Form/attachment - showType: ['TABLE'], // Sql parameter connParams: '', // Pre statements @@ -201,15 +190,6 @@ getSriptBoxValue (val) { editor.setValue(val) }, - /** - * return sqlType - */ - _onSqlType (a) { - this.sqlType = a - if (a === 0) { - this.showType = ['TABLE'] - } - }, /** * return udfs */ @@ -254,10 +234,6 @@ 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 @@ -297,18 +273,6 @@ sqlType: this.sqlType, title: this.title, groupId: this.groupId, - showType: (() => { - /** - * Special processing return order TABLE,ATTACHMENT - * Handling checkout sequence - */ - let showType = this.showType - if (showType.length === 2 && showType[0] === 'ATTACHMENT') { - return [showType[1], showType[0]].join(',') - } else { - return showType.join(',') - } - })(), localParams: this.localParams, connParams: this.connParams, preStatements: this.preStatements, @@ -358,14 +322,6 @@ sqlType: this.sqlType, title: this.title, groupId: this.groupId, - showType: (() => { - let showType = this.showType - if (showType.length === 2 && showType[0] === 'ATTACHMENT') { - return [showType[1], showType[0]].join(',') - } else { - return showType.join(',') - } - })(), localParams: this.localParams, connParams: this.connParams, preStatements: this.preStatements, @@ -383,9 +339,6 @@ watch: { // Listening to sqlType sqlType (val) { - if (val === 0) { - this.showType = [] - } if (val !== 0) { this.title = '' this.groupId = null @@ -415,11 +368,6 @@ this.sqlType = o.params.sqlType this.connParams = o.params.connParams || '' this.localParams = o.params.localParams || [] - if (o.params.showType === '') { - this.showType = [] - } else { - this.showType = o.params.showType.split(',') || [] - } this.preStatements = o.params.preStatements || [] this.postStatements = o.params.postStatements || [] this.title = o.params.title || '' @@ -450,14 +398,6 @@ sqlType: this.sqlType, title: this.title, groupId: this.groupId, - showType: (() => { - let showType = this.showType - if (showType.length === 2 && showType[0] === 'ATTACHMENT') { - return [showType[1], showType[0]].join(',') - } else { - return showType.join(',') - } - })(), localParams: this.localParams, connParams: this.connParams, preStatements: this.preStatements, From 54c0ec09b027b9bce8f0943744e13960cee01356 Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Mon, 1 Feb 2021 10:40:05 +0800 Subject: [PATCH 16/24] fix --- .../conf/home/pages/dag/_source/formModel/tasks/sql.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 dff7f3f97d..5f58d29021 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 @@ -30,7 +30,7 @@
    {{$t('SQL Type')}}
    - +
    @@ -190,6 +190,12 @@ getSriptBoxValue (val) { editor.setValue(val) }, + /** + * return sqlType + */ + _onSqlType (a) { + this.sqlType = a + }, /** * return udfs */ From 7db8ca239365abaccfcf83b677b639f8003efd57 Mon Sep 17 00:00:00 2001 From: zhuangchong Date: Mon, 1 Feb 2021 13:08:35 +0800 Subject: [PATCH 17/24] imp ui alert groups description add filter null. --- .../pages/security/pages/warningGroups/_source/list.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 c3c0a9e343..914c46b66a 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 @@ -20,7 +20,11 @@ - + + +
    {{$t('SQL Parameter')}}
    @@ -142,6 +140,7 @@ import mDatasource from './_source/datasource' import mLocalParams from './_source/localParams' import mStatementList from './_source/statementList' + import mWarningGroups from './_source/warningGroups' import disabledState from '@/module/mixin/disabledState' import codemirror from '@/conf/home/pages/resource/pages/file/pages/_source/codemirror' @@ -167,8 +166,6 @@ sqlType: '0', // Email title title: '', - // Form/attachment - showType: ['TABLE'], // Sql parameter connParams: '', // Pre statements @@ -176,7 +173,8 @@ // Post statements postStatements: [], item: '', - scriptBoxDialog: false + scriptBoxDialog: false, + groupId: null } }, mixins: [disabledState], @@ -197,9 +195,6 @@ */ _onSqlType (a) { this.sqlType = a - if (a === 0) { - this.showType = ['TABLE'] - } }, /** * return udfs @@ -245,16 +240,12 @@ 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) { + 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')}`) + if (this.sqlType === '0' && (this.groupId === '' || this.groupId === null)) { + this.$message.warning(`${i18n.$t('Alarm group required')}`) return false } // udfs Subcomponent verification Verification only if the data type is HIVE @@ -287,18 +278,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, - showType: (() => { - /** - * Special processing return order TABLE,ATTACHMENT - * Handling checkout sequence - */ - let showType = this.showType - if (showType.length === 2 && showType[0] === 'ATTACHMENT') { - return [showType[1], showType[0]].join(',') - } else { - return showType.join(',') - } - })(), + groupId: this.groupId, localParams: this.localParams, connParams: this.connParams, preStatements: this.preStatements, @@ -347,14 +327,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, - showType: (() => { - let showType = this.showType - if (showType.length === 2 && showType[0] === 'ATTACHMENT') { - return [showType[1], showType[0]].join(',') - } else { - return showType.join(',') - } - })(), + groupId: this.groupId, localParams: this.localParams, connParams: this.connParams, preStatements: this.preStatements, @@ -372,11 +345,9 @@ watch: { // Listening to sqlType sqlType (val) { - if (val === 0) { - this.showType = [] - } if (val !== 0) { this.title = '' + this.groupId = null } }, // Listening data source @@ -403,14 +374,10 @@ this.sqlType = o.params.sqlType this.connParams = o.params.connParams || '' this.localParams = o.params.localParams || [] - if (o.params.showType === '') { - this.showType = [] - } else { - this.showType = o.params.showType.split(',') || [] - } this.preStatements = o.params.preStatements || [] this.postStatements = o.params.postStatements || [] this.title = o.params.title || '' + this.groupId = o.params.groupId } }, mounted () { @@ -436,14 +403,7 @@ udfs: this.udfs, sqlType: this.sqlType, title: this.title, - showType: (() => { - let showType = this.showType - if (showType.length === 2 && showType[0] === 'ATTACHMENT') { - return [showType[1], showType[0]].join(',') - } else { - return showType.join(',') - } - })(), + groupId: this.groupId, localParams: this.localParams, connParams: this.connParams, preStatements: this.preStatements, @@ -451,6 +411,6 @@ } } }, - components: { mListBox, mDatasource, mLocalParams, mUdfs, mSqlType, mStatementList, mScriptBox } + components: { mListBox, mDatasource, mLocalParams, mUdfs, mSqlType, mStatementList, mScriptBox, mWarningGroups } } 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 bcc91524ff..de42199a1a 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 @@ -26,7 +26,7 @@
  • {{$t('Process priority')}}:{{startupParam.processInstancePriority}}
  • {{$t('Worker group')}}:{{startupParam.workerGroup}}
  • {{$t('Notification strategy')}}:{{_rtWarningType(startupParam.warningType)}}
  • -
  • {{$t('Notification group')}}:{{_rtNotifyGroupName(startupParam.warningGroupId)}}
  • +
  • {{$t('Alarm group')}}:{{_rtNotifyGroupName(startupParam.warningGroupId)}}
  • diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue index d9acb38453..65510bf69b 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/definitionDetails.vue @@ -42,7 +42,7 @@ methods: { ...mapMutations('dag', ['resetParams', 'setIsDetails']), ...mapActions('dag', ['getProcessList', 'getProjectList', 'getResourcesList', 'getProcessDetails', 'getResourcesListJar']), - ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll']), + ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll', 'getAlarmGroupsAll']), /** * init */ @@ -64,6 +64,8 @@ this.getResourcesListJar(), // get worker group list this.getWorkerGroupsAll(), + // get alarm group list + this.getAlarmGroupsAll(), this.getTenantList() ]).then((data) => { let item = data[0] diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue index d232e2dd86..81d129a47e 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/index.vue @@ -41,7 +41,7 @@ methods: { ...mapMutations('dag', ['resetParams']), ...mapActions('dag', ['getProcessList', 'getProjectList', 'getResourcesList', 'getResourcesListJar', 'getResourcesListJar']), - ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll']), + ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll', 'getAlarmGroupsAll']), /** * init */ @@ -63,6 +63,8 @@ this.getResourcesListJar(), // get worker group list this.getWorkerGroupsAll(), + // get alarm group list + this.getAlarmGroupsAll(), this.getTenantList() ]).then((data) => { this.isLoading = false diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue index 0727d12eed..f9561bd52c 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/instanceDetails.vue @@ -44,7 +44,7 @@ methods: { ...mapMutations('dag', ['setIsDetails', 'resetParams']), ...mapActions('dag', ['getProcessList', 'getProjectList', 'getResourcesList', 'getInstancedetail', 'getResourcesListJar']), - ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll']), + ...mapActions('security', ['getTenantList', 'getWorkerGroupsAll', 'getAlarmGroupsAll']), /** * init */ @@ -66,6 +66,8 @@ this.getResourcesListJar(), // get worker group list this.getWorkerGroupsAll(), + // get alarm group list + this.getAlarmGroupsAll(), this.getTenantList() ]).then((data) => { let item = data[0] diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue index 64c3f880b5..32612213ac 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue @@ -129,6 +129,7 @@ diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue index e2ab711528..e9f615d340 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/start.vue @@ -78,15 +78,16 @@
    - {{$t('Notification group')}} + {{$t('Alarm group')}}
    - + @@ -263,7 +264,6 @@ }) }, _getGlobalParams () { - this.setIsDetails(true) this.store.dispatch('dag/getProcessDetails', this.startData.id).then(res => { this.definitionGlobalParams = _.cloneDeep(this.store.state.dag.globalParams) this.udpList = _.cloneDeep(this.store.state.dag.globalParams) diff --git a/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js b/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js index 9405d264a4..97df05d7bc 100644 --- a/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js +++ b/dolphinscheduler-ui/src/js/conf/home/store/security/actions.js @@ -600,6 +600,19 @@ export default { }) }) }, + /** + * get alarm groups all + */ + getAlarmGroupsAll ({ state }, payload) { + return new Promise((resolve, reject) => { + io.get('alert-group/list', payload, res => { + state.alarmGroupsListAll = res.data + resolve(res) + }).catch(e => { + reject(e) + }) + }) + }, saveWorkerGroups ({ state }, payload) { return new Promise((resolve, reject) => { io.post('worker-group/save', payload, res => { diff --git a/dolphinscheduler-ui/src/js/conf/home/store/security/state.js b/dolphinscheduler-ui/src/js/conf/home/store/security/state.js index f3533265a9..a959d9431f 100644 --- a/dolphinscheduler-ui/src/js/conf/home/store/security/state.js +++ b/dolphinscheduler-ui/src/js/conf/home/store/security/state.js @@ -16,5 +16,6 @@ */ export default { workerGroupsListAll: [], + alarmGroupsListAll: [], tenantAllList: [] } 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 168258a9f6..34145e7132 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js @@ -207,6 +207,8 @@ export default { 'UDF resources': 'UDF resources', 'UDF resources directory': 'UDF resources directory', 'Please select UDF resources directory': 'Please select UDF resources directory', + 'Alarm group': 'Alarm group', + 'Alarm group required': 'Alarm group required', 'Edit alarm group': 'Edit alarm group', 'Create alarm group': 'Create alarm group', 'Create Alarm Instance': 'Create Alarm Instance', 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 fb3bd3fb5b..7cafa9dec1 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js @@ -207,6 +207,8 @@ export default { 'UDF resources': 'UDF资源', 'UDF resources directory': 'UDF资源目录', 'Please select UDF resources directory': '请选择UDF资源目录', + 'Alarm group': '告警组', + 'Alarm group required': '告警组必填', 'Edit alarm group': '编辑告警组', 'Create alarm group': '创建告警组', 'Create Alarm Instance': '创建告警实例', From 5acf718384dac161e077ed9d138f70c2ef045a14 Mon Sep 17 00:00:00 2001 From: break60 <790061044@qq.com> Date: Mon, 1 Feb 2021 13:34:40 +0800 Subject: [PATCH 19/24] [Improvement-3878][ui] Fixed the problem that custom parameters could not be edited and zk displayed abnormally when the workflow started --- .../dag/_source/formModel/tasks/_source/localParams.vue | 2 +- .../pages/servers/_source/zookeeperDirectories.vue | 8 ++------ .../js/conf/home/pages/monitor/pages/servers/worker.vue | 2 +- .../pages/definition/pages/list/_source/timing.vue | 7 ++++--- .../home/pages/projects/pages/definition/timing/index.vue | 4 +++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/localParams.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/localParams.vue index 3f8c6e889c..c8a600b699 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/localParams.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/_source/localParams.vue @@ -79,7 +79,7 @@
    - + diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperDirectories.vue b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperDirectories.vue index ca4f6ad728..088063b01e 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperDirectories.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperDirectories.vue @@ -15,13 +15,9 @@ * limitations under the License. */