Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
f5c814f2
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 搜索 >>
未验证
提交
f5c814f2
编写于
10月 25, 2022
作者:
P
pandong
提交者:
GitHub
10月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[fix#12439] [Alert] fix send script alert NPE (#12495)
* [fix#12439] [Alert] fix send script alert NPE
上级
4aa9d606
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
6 deletion
+48
-6
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
...phinscheduler/plugin/alert/script/ScriptAlertChannel.java
+4
-2
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
...he/dolphinscheduler/plugin/alert/script/ScriptSender.java
+15
-3
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
...olphinscheduler/plugin/alert/script/ScriptSenderTest.java
+27
-0
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
...org/apache/dolphinscheduler/alert/AlertSenderService.java
+2
-1
未找到文件。
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
浏览文件 @
f5c814f2
...
...
@@ -22,6 +22,8 @@ import org.apache.dolphinscheduler.alert.api.AlertData;
import
org.apache.dolphinscheduler.alert.api.AlertInfo
;
import
org.apache.dolphinscheduler.alert.api.AlertResult
;
import
org.apache.commons.collections.MapUtils
;
import
java.util.Map
;
public
final
class
ScriptAlertChannel
implements
AlertChannel
{
...
...
@@ -30,8 +32,8 @@ public final class ScriptAlertChannel implements AlertChannel {
public
AlertResult
process
(
AlertInfo
alertinfo
)
{
AlertData
alertData
=
alertinfo
.
getAlertData
();
Map
<
String
,
String
>
paramsMap
=
alertinfo
.
getAlertParams
();
if
(
null
==
paramsMap
)
{
return
new
AlertResult
(
"false"
,
"script params is
null
"
);
if
(
MapUtils
.
isEmpty
(
paramsMap
)
)
{
return
new
AlertResult
(
"false"
,
"script params is
empty
"
);
}
return
new
ScriptSender
(
paramsMap
).
sendScriptAlert
(
alertData
.
getTitle
(),
alertData
.
getContent
());
}
...
...
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
浏览文件 @
f5c814f2
...
...
@@ -18,6 +18,7 @@
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
org.apache.dolphinscheduler.alert.api.AlertResult
;
import
org.apache.dolphinscheduler.spi.utils.StringUtils
;
import
java.io.File
;
import
java.util.Map
;
...
...
@@ -36,9 +37,15 @@ public final class ScriptSender {
private
final
String
userParams
;
ScriptSender
(
Map
<
String
,
String
>
config
)
{
scriptPath
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
);
scriptType
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
);
userParams
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
);
scriptPath
=
StringUtils
.
isNotBlank
(
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
))
?
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
)
:
""
;
scriptType
=
StringUtils
.
isNotBlank
(
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
))
?
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
)
:
""
;
userParams
=
StringUtils
.
isNotBlank
(
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
))
?
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
)
:
""
;
}
AlertResult
sendScriptAlert
(
String
title
,
String
content
)
{
...
...
@@ -46,6 +53,11 @@ public final class ScriptSender {
if
(
ScriptType
.
SHELL
.
getDescp
().
equals
(
scriptType
))
{
return
executeShellScript
(
title
,
content
);
}
// If it is another type of alarm script can be added here, such as python
alertResult
.
setStatus
(
"false"
);
logger
.
error
(
"script type error: {}"
,
scriptType
);
alertResult
.
setMessage
(
"script type error : "
+
scriptType
);
return
alertResult
;
}
...
...
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
浏览文件 @
f5c814f2
...
...
@@ -61,4 +61,31 @@ public class ScriptSenderTest {
Assertions
.
assertEquals
(
"false"
,
alertResult
.
getStatus
());
}
@Test
public
void
testUserParamsNPE
()
{
scriptConfig
.
put
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
,
null
);
ScriptSender
scriptSender
=
new
ScriptSender
(
scriptConfig
);
AlertResult
alertResult
;
alertResult
=
scriptSender
.
sendScriptAlert
(
"test user params NPE"
,
"test content"
);
Assertions
.
assertEquals
(
"true"
,
alertResult
.
getStatus
());
}
@Test
public
void
testPathNPE
()
{
scriptConfig
.
put
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
,
null
);
ScriptSender
scriptSender
=
new
ScriptSender
(
scriptConfig
);
AlertResult
alertResult
;
alertResult
=
scriptSender
.
sendScriptAlert
(
"test path NPE"
,
"test content"
);
Assertions
.
assertEquals
(
"false"
,
alertResult
.
getStatus
());
}
@Test
public
void
testTypeIsError
()
{
scriptConfig
.
put
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
,
null
);
ScriptSender
scriptSender
=
new
ScriptSender
(
scriptConfig
);
AlertResult
alertResult
;
alertResult
=
scriptSender
.
sendScriptAlert
(
"test type is error"
,
"test content"
);
Assertions
.
assertEquals
(
"false"
,
alertResult
.
getStatus
());
}
}
dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
浏览文件 @
f5c814f2
...
...
@@ -37,6 +37,7 @@ import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand
import
org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
java.util.ArrayList
;
import
java.util.Date
;
...
...
@@ -223,7 +224,7 @@ public final class AlertSenderService extends Thread {
Map
<
String
,
String
>
paramsMap
=
JSONUtils
.
toMap
(
instance
.
getPluginInstanceParams
());
String
instanceWarnType
=
WarningType
.
ALL
.
getDescp
();
if
(
paramsMap
!=
null
)
{
if
(
MapUtils
.
isNotEmpty
(
paramsMap
)
)
{
instanceWarnType
=
paramsMap
.
getOrDefault
(
AlertConstants
.
NAME_WARNING_TYPE
,
WarningType
.
ALL
.
getDescp
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录