Browse Source

[Fix-7288] Not allow to delete the default alarm group. (#7932)

3.0.0/version-upgrade
calvin 3 years ago committed by GitHub
parent
commit
8cac0d8f94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  2. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
  3. 15
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
  4. 60
      dolphinscheduler-ui/src/js/conf/home/pages/security/pages/warningGroups/_source/list.vue

1
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;

8
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;

15
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());
}
}

60
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 () {
},

Loading…
Cancel
Save