You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2022/01/12 06:12:38 UTC
[dolphinscheduler] branch dev updated: [Fix-7288] Not allow to delete the default alarm group. (#7932)
This is an automated email from the ASF dual-hosted git repository.
kerwin pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 8cac0d8 [Fix-7288] Not allow to delete the default alarm group. (#7932)
8cac0d8 is described below
commit 8cac0d8f94491e82a69f599b6688d593951351d3
Author: calvin <ji...@163.com>
AuthorDate: Wed Jan 12 14:12:30 2022 +0800
[Fix-7288] Not allow to delete the default alarm group. (#7932)
---
.../apache/dolphinscheduler/api/enums/Status.java | 1 +
.../api/service/impl/AlertGroupServiceImpl.java | 8 +++
.../api/controller/AlertGroupControllerTest.java | 15 ++++++
.../security/pages/warningGroups/_source/list.vue | 60 ++++++++++++++++++++--
4 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
index 49d01a2..5f5294c 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
@@ -367,6 +367,7 @@ public enum Status {
"您不能修改工作组选项,因为该工作组 [{0}] 和 该环境 [{1}] 已经被用在任务 [{2}] 中"),
TASK_GROUP_QUEUE_ALREADY_START(130017, "task group queue already start", "节点已经获取任务组资源"),
NOT_ALLOW_TO_DISABLE_OWN_ACCOUNT(130020, "Not allow to disable your own account", "不能停用自己的账号"),
+ NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP(130030, "Not allow to delete the default alarm group ", "不能删除默认告警组"),
;
private final int code;
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
index 1cad66a..2e31920 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
@@ -228,12 +228,20 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
if (isNotAdmin(loginUser, result)) {
return result;
}
+
+ // Not allow to delete the default alarm group ,because the module of service need to use it.
+ if (id == 1) {
+ putMsg(result, Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP);
+ return result;
+ }
+
//check exist
AlertGroup alertGroup = alertGroupMapper.selectById(id);
if (alertGroup == null) {
putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
return result;
}
+
alertGroupMapper.deleteById(id);
putMsg(result, Status.SUCCESS);
return result;
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
index 256eab1..7eb1c84 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
@@ -35,6 +35,7 @@ import java.util.Date;
import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -202,4 +203,18 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
+
+ @Test
+ public void test090DelAlertGroupById() throws Exception {
+ MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
+ MvcResult mvcResult = mockMvc.perform(delete("/alert-groups/1")
+ .header("sessionId", sessionId)
+ .params(paramsMap))
+ .andExpect(status().isOk())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON))
+ .andReturn();
+ Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
+ Assert.assertEquals(Status.NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP.getCode(), result.getCode().intValue());
+ logger.info(mvcResult.getResponse().getContentAsString());
+ }
}
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 0946c12..2517160 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,6 +20,18 @@
<el-table :data="list" size="mini" style="width: 100%">
<el-table-column type="index" :label="$t('#')" width="50"></el-table-column>
<el-table-column prop="groupName" :label="$t('Group Name')"></el-table-column>
+ <el-table-column :label="$t('Alarm plugin instance')">
+ <template slot-scope="scope">
+ <el-tag
+ style="margin: 0 2px 0 0"
+ v-for="item in scope.row.instanceNames"
+ :key="item"
+ size="mini"
+ effect="light">
+ {{ item }}
+ </el-tag>
+ </template>
+ </el-table-column>
<el-table-column prop="description" :label="$t('Remarks')" width="200">
<template slot-scope="scope">
<span>{{scope.row.description | filterNull}}</span>
@@ -49,7 +61,7 @@
:title="$t('Delete?')"
@onConfirm="_delete(scope.row,scope.row.id)"
>
- <el-button type="danger" size="mini" icon="el-icon-delete" circle slot="reference"></el-button>
+ <el-button v-if="scope.row.id !== 1" type="danger" size="mini" icon="el-icon-delete" circle slot="reference"></el-button>
</el-popconfirm>
</el-tooltip>
</template>
@@ -60,6 +72,7 @@
</template>
<script>
import { mapActions } from 'vuex'
+ import _ from 'lodash'
export default {
name: 'user-list',
@@ -67,7 +80,8 @@
return {
list: [],
transferDialog: false,
- item: {}
+ item: {},
+ allAlertPluginInstance: []
}
},
props: {
@@ -76,7 +90,7 @@
pageSize: Number
},
methods: {
- ...mapActions('security', ['deleteAlertgrou', 'grantAuthorization']),
+ ...mapActions('security', ['deleteAlertgrou', 'grantAuthorization', 'queryAllAlertPluginInstance']),
_delete (item, i) {
this.deleteAlertgrou({
id: item.id
@@ -116,12 +130,48 @@
alertgroupList (a) {
this.list = []
setTimeout(() => {
- this.list = a
+ this.queryAllAlertPluginInstance().then(res => {
+ const alertPluginInstanceMapping = {}
+ res.forEach(instance => {
+ alertPluginInstanceMapping[instance.id] = instance.instanceName
+ })
+ if (a) {
+ a.forEach(item => {
+ let alertInstanceArray = _.split(item.alertInstanceIds, ',')
+ let instanceNames = []
+ alertInstanceArray.forEach(id => {
+ instanceNames.push(alertPluginInstanceMapping[id])
+ })
+ item.instanceNames = instanceNames
+ })
+ }
+ this.list = a
+ }).catch(e => {
+ this.$message.error(e.msg)
+ })
})
}
},
created () {
- this.list = this.alertgroupList
+ this.queryAllAlertPluginInstance().then(res => {
+ const alertPluginInstanceMapping = {}
+ res.forEach(instance => {
+ alertPluginInstanceMapping[instance.id] = instance.instanceName
+ })
+ if (this.alertgroupList) {
+ this.alertgroupList.forEach(item => {
+ let alertInstanceArray = _.split(item.alertInstanceIds, ',')
+ let instanceNames = []
+ alertInstanceArray.forEach(id => {
+ instanceNames.push(alertPluginInstanceMapping[id])
+ })
+ item.instanceNames = instanceNames
+ })
+ }
+ this.list = this.alertgroupList
+ }).catch(e => {
+ this.$message.error(e.msg)
+ })
},
mounted () {
},