Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
75f15df3
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
704
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
75f15df3
编写于
8月 24, 2021
作者:
S
Shukun Zhang
提交者:
GitHub
8月 24, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Improvement][Api Module]split alert group list-paging interface (#5941)
* [Improvement][Api Module]split alert group list-paging interface
上级
42b912a5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
180 addition
and
30 deletion
+180
-30
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
...dolphinscheduler/api/controller/AlertGroupController.java
+23
-0
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
...in/java/org/apache/dolphinscheduler/api/enums/Status.java
+1
-0
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
...pache/dolphinscheduler/api/service/AlertGroupService.java
+8
-0
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
...phinscheduler/api/service/impl/AlertGroupServiceImpl.java
+35
-6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
...hinscheduler/api/controller/AlertGroupControllerTest.java
+19
-19
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
...e/dolphinscheduler/api/service/AlertGroupServiceTest.java
+24
-4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java
.../apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java
+10
-0
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java
...java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java
+50
-0
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml
...g/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml
+10
-1
未找到文件。
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
浏览文件 @
75f15df3
...
...
@@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.controller;
import
static
org
.
apache
.
dolphinscheduler
.
api
.
enums
.
Status
.
CREATE_ALERT_GROUP_ERROR
;
import
static
org
.
apache
.
dolphinscheduler
.
api
.
enums
.
Status
.
DELETE_ALERT_GROUP_ERROR
;
import
static
org
.
apache
.
dolphinscheduler
.
api
.
enums
.
Status
.
LIST_PAGING_ALERT_GROUP_ERROR
;
import
static
org
.
apache
.
dolphinscheduler
.
api
.
enums
.
Status
.
QUERY_ALERT_GROUP_ERROR
;
import
static
org
.
apache
.
dolphinscheduler
.
api
.
enums
.
Status
.
QUERY_ALL_ALERTGROUP_ERROR
;
import
static
org
.
apache
.
dolphinscheduler
.
api
.
enums
.
Status
.
UPDATE_ALERT_GROUP_ERROR
;
...
...
@@ -139,6 +140,28 @@ public class AlertGroupController extends BaseController {
searchVal
=
ParameterUtils
.
handleEscapes
(
searchVal
);
return
alertGroupService
.
listPaging
(
loginUser
,
searchVal
,
pageNo
,
pageSize
);
}
/**
* check alarm group detail by Id
*
* @param loginUser login user
* @param id alert group id
* @return one alert group
*/
@ApiOperation
(
value
=
"queryAlertGroupById"
,
notes
=
"QUERY_ALERT_GROUP_BY_ID_NOTES"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"ALERT_GROUP_ID"
,
dataType
=
"Int"
,
example
=
"1"
)
})
@PostMapping
(
value
=
"/query"
)
@ResponseStatus
(
HttpStatus
.
OK
)
@ApiException
(
QUERY_ALERT_GROUP_ERROR
)
@AccessLogAnnotation
(
ignoreRequestArgs
=
"loginUser"
)
public
Result
queryAlertGroupById
(
@ApiIgnore
@RequestAttribute
(
value
=
Constants
.
SESSION_USER
)
User
loginUser
,
@RequestParam
(
"id"
)
Integer
id
)
{
Map
<
String
,
Object
>
result
=
alertGroupService
.
queryAlertGroupById
(
loginUser
,
id
);
return
returnDataList
(
result
);
}
/**
* updateProcessInstance alert group
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
浏览文件 @
75f15df3
...
...
@@ -211,6 +211,7 @@ public enum Status {
WORKER_ADDRESS_INVALID
(
10177
,
"worker address {0} invalid"
,
"worker地址[{0}]无效"
),
QUERY_WORKER_ADDRESS_LIST_FAIL
(
10178
,
"query worker address list fail "
,
"查询worker地址列表失败"
),
TRANSFORM_PROJECT_OWNERSHIP
(
10179
,
"Please transform project ownership [{0}]"
,
"请先转移项目所有权[{0}]"
),
QUERY_ALERT_GROUP_ERROR
(
10180
,
"query alert group error"
,
"查询告警组错误"
),
UDF_FUNCTION_NOT_EXIST
(
20001
,
"UDF function not found"
,
"UDF函数不存在"
),
UDF_FUNCTION_EXISTS
(
20002
,
"UDF function already exists"
,
"UDF函数已存在"
),
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
浏览文件 @
75f15df3
...
...
@@ -34,6 +34,14 @@ public interface AlertGroupService {
*/
Map
<
String
,
Object
>
queryAlertgroup
();
/**
* query alert group by id
*
* @param loginUser login user
* @param id alert group id
* @return one alert group
*/
Map
<
String
,
Object
>
queryAlertGroupById
(
User
loginUser
,
Integer
id
);
/**
* paging query alarm group list
*
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
浏览文件 @
75f15df3
...
...
@@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.common.utils.StringUtils;
import
org.apache.dolphinscheduler.dao.entity.AlertGroup
;
import
org.apache.dolphinscheduler.dao.entity.User
;
import
org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper
;
import
org.apache.dolphinscheduler.dao.vo.AlertGroupVo
;
import
java.util.Date
;
import
java.util.HashMap
;
...
...
@@ -70,6 +71,33 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
return
result
;
}
/**
* query alert group by id
*
* @param loginUser login user
* @param id alert group id
* @return one alert group
*/
@Override
public
Map
<
String
,
Object
>
queryAlertGroupById
(
User
loginUser
,
Integer
id
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
Constants
.
STATUS
,
false
);
//only admin can operate
if
(
isNotAdmin
(
loginUser
,
result
))
{
return
result
;
}
//check if exist
AlertGroup
alertGroup
=
alertGroupMapper
.
selectById
(
id
);
if
(
alertGroup
==
null
)
{
putMsg
(
result
,
Status
.
ALERT_GROUP_NOT_EXIST
);
return
result
;
}
result
.
put
(
"data"
,
alertGroup
);
putMsg
(
result
,
Status
.
SUCCESS
);
return
result
;
}
/**
* paging query alarm group list
*
...
...
@@ -88,13 +116,14 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
return
result
;
}
Page
<
AlertGroup
>
page
=
new
Page
<>(
pageNo
,
pageSize
);
IPage
<
AlertGroup
>
alertGroupIPage
=
alertGroupMapper
.
queryAlertGroupPage
(
page
,
searchVal
);
PageInfo
<
AlertGroup
>
pageInfo
=
new
PageInfo
<>(
pageNo
,
pageSize
);
pageInfo
.
setTotal
((
int
)
alertGroupIPage
.
getTotal
());
pageInfo
.
setTotalList
(
alertGroupIPage
.
getRecords
());
Page
<
AlertGroup
Vo
>
page
=
new
Page
<>(
pageNo
,
pageSize
);
IPage
<
AlertGroup
Vo
>
alertGroupVoIPage
=
alertGroupMapper
.
queryAlertGroupVo
(
page
,
searchVal
);
PageInfo
<
AlertGroupVo
>
pageInfo
=
new
PageInfo
<>(
pageNo
,
pageSize
);
pageInfo
.
setTotal
((
int
)
alertGroup
Vo
IPage
.
getTotal
());
pageInfo
.
setTotalList
(
alertGroup
Vo
IPage
.
getRecords
());
result
.
setData
(
pageInfo
);
putMsg
(
result
,
Status
.
SUCCESS
);
return
result
;
}
...
...
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java
浏览文件 @
75f15df3
...
...
@@ -49,6 +49,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
paramsMap
.
add
(
"groupName"
,
"cxc test group name"
);
paramsMap
.
add
(
"groupType"
,
AlertType
.
EMAIL
.
toString
());
paramsMap
.
add
(
"description"
,
"cxc junit 测试告警描述"
);
paramsMap
.
add
(
"alertInstanceIds"
,
""
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
post
(
"/alert-group/create"
)
.
header
(
"sessionId"
,
sessionId
)
.
params
(
paramsMap
))
...
...
@@ -93,40 +94,41 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
}
@Test
public
void
test
UpdateAlertgroup
()
throws
Exception
{
public
void
test
QueryAlertGroupById
()
throws
Exception
{
MultiValueMap
<
String
,
String
>
paramsMap
=
new
LinkedMultiValueMap
<>();
paramsMap
.
add
(
"id"
,
"22"
);
paramsMap
.
add
(
"groupName"
,
"hd test group name"
);
paramsMap
.
add
(
"groupType"
,
AlertType
.
EMAIL
.
toString
());
paramsMap
.
add
(
"description"
,
"update alter group"
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
post
(
"/alert-group/update"
)
MvcResult
mvcResult
=
mockMvc
.
perform
(
post
(
"/alert-group/query"
)
.
header
(
"sessionId"
,
sessionId
)
.
params
(
paramsMap
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andReturn
();
Result
result
=
JSONUtils
.
parseObject
(
mvcResult
.
getResponse
().
getContentAsString
(),
Result
.
class
);
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
uccess
(
));
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
tatus
(
Status
.
ALERT_GROUP_NOT_EXIST
));
logger
.
info
(
mvcResult
.
getResponse
().
getContentAsString
());
}
@Test
public
void
test
VerifyGroupName
()
throws
Exception
{
public
void
test
UpdateAlertgroup
()
throws
Exception
{
MultiValueMap
<
String
,
String
>
paramsMap
=
new
LinkedMultiValueMap
<>();
paramsMap
.
add
(
"groupName"
,
"hd test group name"
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
get
(
"/alert-group/verify-group-name"
)
paramsMap
.
add
(
"id"
,
"22"
);
paramsMap
.
add
(
"groupName"
,
"cxc test group name"
);
paramsMap
.
add
(
"groupType"
,
AlertType
.
EMAIL
.
toString
());
paramsMap
.
add
(
"description"
,
"update alter group"
);
paramsMap
.
add
(
"alertInstanceIds"
,
""
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
post
(
"/alert-group/update"
)
.
header
(
"sessionId"
,
sessionId
)
.
params
(
paramsMap
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andReturn
();
Result
result
=
JSONUtils
.
parseObject
(
mvcResult
.
getResponse
().
getContentAsString
(),
Result
.
class
);
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isStatus
(
Status
.
ALERT_GROUP_EXIST
));
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isStatus
(
Status
.
ALERT_GROUP_
NOT_
EXIST
));
logger
.
info
(
mvcResult
.
getResponse
().
getContentAsString
());
}
@Test
public
void
testVerifyGroupName
NotExit
()
throws
Exception
{
public
void
testVerifyGroupName
()
throws
Exception
{
MultiValueMap
<
String
,
String
>
paramsMap
=
new
LinkedMultiValueMap
<>();
paramsMap
.
add
(
"groupName"
,
"cxc test group name"
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
get
(
"/alert-group/verify-group-name"
)
...
...
@@ -136,24 +138,22 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andReturn
();
Result
result
=
JSONUtils
.
parseObject
(
mvcResult
.
getResponse
().
getContentAsString
(),
Result
.
class
);
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
uccess
(
));
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
tatus
(
Status
.
ALERT_GROUP_EXIST
));
logger
.
info
(
mvcResult
.
getResponse
().
getContentAsString
());
}
@Test
public
void
test
GrantUser
()
throws
Exception
{
public
void
test
VerifyGroupNameNotExit
()
throws
Exception
{
MultiValueMap
<
String
,
String
>
paramsMap
=
new
LinkedMultiValueMap
<>();
paramsMap
.
add
(
"alertgroupId"
,
"2"
);
paramsMap
.
add
(
"userIds"
,
"2"
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
post
(
"/alert-group/grant-user"
)
paramsMap
.
add
(
"groupName"
,
"cxc test group name"
);
MvcResult
mvcResult
=
mockMvc
.
perform
(
get
(
"/alert-group/verify-group-name"
)
.
header
(
"sessionId"
,
sessionId
)
.
params
(
paramsMap
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andReturn
();
Result
result
=
JSONUtils
.
parseObject
(
mvcResult
.
getResponse
().
getContentAsString
(),
Result
.
class
);
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
uccess
(
));
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
tatus
(
Status
.
ALERT_GROUP_EXIST
));
logger
.
info
(
mvcResult
.
getResponse
().
getContentAsString
());
}
...
...
@@ -168,7 +168,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andReturn
();
Result
result
=
JSONUtils
.
parseObject
(
mvcResult
.
getResponse
().
getContentAsString
(),
Result
.
class
);
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
uccess
(
));
Assert
.
assertTrue
(
result
!=
null
&&
result
.
isS
tatus
(
Status
.
ALERT_GROUP_NOT_EXIST
));
logger
.
info
(
mvcResult
.
getResponse
().
getContentAsString
());
}
}
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
浏览文件 @
75f15df3
...
...
@@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import
org.apache.dolphinscheduler.dao.entity.AlertGroup
;
import
org.apache.dolphinscheduler.dao.entity.User
;
import
org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper
;
import
org.apache.dolphinscheduler.dao.vo.AlertGroupVo
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -77,10 +78,10 @@ public class AlertGroupServiceTest {
@Test
public
void
testListPaging
()
{
IPage
<
AlertGroup
>
page
=
new
Page
<>(
1
,
10
);
IPage
<
AlertGroup
Vo
>
page
=
new
Page
<>(
1
,
10
);
page
.
setTotal
(
1L
);
page
.
setRecords
(
getList
());
Mockito
.
when
(
alertGroupMapper
.
queryAlertGroup
Page
(
any
(
Page
.
class
),
eq
(
groupName
))).
thenReturn
(
page
);
page
.
setRecords
(
get
AlertGroupVo
List
());
Mockito
.
when
(
alertGroupMapper
.
queryAlertGroup
Vo
(
any
(
Page
.
class
),
eq
(
groupName
))).
thenReturn
(
page
);
User
user
=
new
User
();
// no operate
Result
result
=
alertGroupService
.
listPaging
(
user
,
groupName
,
1
,
10
);
...
...
@@ -90,7 +91,7 @@ public class AlertGroupServiceTest {
user
.
setUserType
(
UserType
.
ADMIN_USER
);
result
=
alertGroupService
.
listPaging
(
user
,
groupName
,
1
,
10
);
logger
.
info
(
result
.
toString
());
PageInfo
<
AlertGroup
>
pageInfo
=
(
PageInfo
<
AlertGroup
>)
result
.
getData
();
PageInfo
<
AlertGroup
Vo
>
pageInfo
=
(
PageInfo
<
AlertGroupVo
>)
result
.
getData
();
Assert
.
assertTrue
(
CollectionUtils
.
isNotEmpty
(
pageInfo
.
getTotalList
()));
}
...
...
@@ -216,4 +217,23 @@ public class AlertGroupServiceTest {
return
alertGroup
;
}
/**
* get AlertGroupVo list
*/
private
List
<
AlertGroupVo
>
getAlertGroupVoList
()
{
List
<
AlertGroupVo
>
alertGroupVos
=
new
ArrayList
<>();
alertGroupVos
.
add
(
getAlertGroupVoEntity
());
return
alertGroupVos
;
}
/**
* get AlertGroupVo entity
*/
private
AlertGroupVo
getAlertGroupVoEntity
()
{
AlertGroupVo
alertGroupVo
=
new
AlertGroupVo
();
alertGroupVo
.
setId
(
1
);
alertGroupVo
.
setGroupName
(
groupName
);
return
alertGroupVo
;
}
}
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.java
浏览文件 @
75f15df3
...
...
@@ -18,6 +18,7 @@
package
org.apache.dolphinscheduler.dao.mapper
;
import
org.apache.dolphinscheduler.dao.entity.AlertGroup
;
import
org.apache.dolphinscheduler.dao.vo.AlertGroupVo
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -82,4 +83,13 @@ public interface AlertGroupMapper extends BaseMapper<AlertGroup> {
* @return
*/
String
queryAlertGroupInstanceIdsById
(
@Param
(
"alertGroupId"
)
int
alertGroupId
);
/**
* query alertGroupVo page list
* @param page page
* @param groupName groupName
* @return IPage<AlertGroupVo>: include alert group id and group_name
*/
IPage
<
AlertGroupVo
>
queryAlertGroupVo
(
Page
<
AlertGroupVo
>
page
,
@Param
(
"groupName"
)
String
groupName
);
}
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/vo/AlertGroupVo.java
0 → 100644
浏览文件 @
75f15df3
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.dao.vo
;
/**
* AlertGroupVo
*/
public
class
AlertGroupVo
{
/**
* primary key
*/
private
int
id
;
/**
* group_name
*/
private
String
groupName
;
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getGroupName
()
{
return
groupName
;
}
public
void
setGroupName
(
String
groupName
)
{
this
.
groupName
=
groupName
;
}
}
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml
浏览文件 @
75f15df3
...
...
@@ -32,6 +32,15 @@
</if>
order by update_time desc
</select>
<select
id=
"queryAlertGroupVo"
resultType=
"org.apache.dolphinscheduler.dao.vo.AlertGroupVo"
>
select id, group_name
from t_ds_alertgroup
where 1 = 1
<if
test=
"groupName != null and groupName != ''"
>
and group_name like concat('%', #{groupName}, '%')
</if>
order by update_time desc
</select>
<select
id=
"queryByGroupName"
resultType=
"org.apache.dolphinscheduler.dao.entity.AlertGroup"
>
select
<include
refid=
"baseSql"
/>
...
...
@@ -70,4 +79,4 @@
select alert_instance_ids from t_ds_alertgroup
where id = #{alertGroupId}
</select>
</mapper>
\ No newline at end of file
</mapper>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录