Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
37c8f00e
DolphinScheduler
项目概览
pentaLiker
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
1
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
37c8f00e
编写于
11月 27, 2020
作者:
一子三木
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify http type
上级
183725db
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
277 addition
and
63 deletion
+277
-63
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml
...cheduler-alert-plugin/dolphinscheduler-alert-http/pom.xml
+1
-1
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannel.java
.../dolphinscheduler/plugin/alert/http/HttpAlertChannel.java
+14
-5
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertChannelFactory.java
...nscheduler/plugin/alert/http/HttpAlertChannelFactory.java
+78
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants.java
...olphinscheduler/plugin/alert/http/HttpAlertConstants.java
+9
-10
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java
...e/dolphinscheduler/plugin/alert/http/HttpAlertPlugin.java
+4
-4
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
...apache/dolphinscheduler/plugin/alert/http/HttpSender.java
+170
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java
.../dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java
+0
-21
dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java
...inscheduler/plugin/alert/sms/SMSAlertParamsConstants.java
+0
-21
dolphinscheduler-alert-plugin/pom.xml
dolphinscheduler-alert-plugin/pom.xml
+1
-1
未找到文件。
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
sms
/pom.xml
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
http
/pom.xml
浏览文件 @
37c8f00e
...
...
@@ -9,7 +9,7 @@
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
dolphinscheduler-alert-
sms
</artifactId>
<artifactId>
dolphinscheduler-alert-
http
</artifactId>
<dependencies>
<dependency>
...
...
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMS
AlertChannel.java
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/Http
AlertChannel.java
浏览文件 @
37c8f00e
...
...
@@ -15,19 +15,28 @@
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.
sms
;
package
org.apache.dolphinscheduler.plugin.alert.
http
;
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
;
/**
*
sms
alert channel,use sms message to seed the alertInfo
*
http
alert channel,use sms message to seed the alertInfo
*/
public
class
SMS
AlertChannel
implements
AlertChannel
{
public
class
Http
AlertChannel
implements
AlertChannel
{
@Override
public
AlertResult
process
(
AlertInfo
info
)
{
return
null
;
public
AlertResult
process
(
AlertInfo
alertInfo
)
{
AlertData
alertData
=
alertInfo
.
getAlertData
();
String
alertParams
=
alertInfo
.
getAlertParams
();
Map
<
String
,
String
>
paramsMap
=
PluginParamsTransfer
.
getPluginParamsMap
(
alertParams
);
return
new
HttpSender
(
paramsMap
).
send
(
alertData
.
getContent
());
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMS
AlertChannelFactory.java
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/Http
AlertChannelFactory.java
浏览文件 @
37c8f00e
...
...
@@ -15,30 +15,64 @@
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.
sms
;
package
org.apache.dolphinscheduler.plugin.alert.
http
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannel
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannelFactory
;
import
org.apache.dolphinscheduler.spi.params.InputParam
;
import
org.apache.dolphinscheduler.spi.params.base.PluginParams
;
import
org.apache.dolphinscheduler.spi.params.base.Validate
;
import
java.util.Arrays
;
import
java.util.List
;
/**
*
sms
alert factory
*
http
alert factory
*/
public
class
SMS
AlertChannelFactory
implements
AlertChannelFactory
{
public
class
Http
AlertChannelFactory
implements
AlertChannelFactory
{
@Override
public
String
getName
()
{
return
null
;
return
"http alert"
;
}
@Override
public
List
<
PluginParams
>
getParams
()
{
return
null
;
InputParam
url
=
InputParam
.
newBuilder
(
HttpAlertConstants
.
URL
,
HttpAlertConstants
.
URL
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
true
)
.
build
())
.
build
();
InputParam
headerParams
=
InputParam
.
newBuilder
(
HttpAlertConstants
.
HEADER_PARAMS
,
HttpAlertConstants
.
HEADER_PARAMS
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
true
)
.
build
())
.
build
();
InputParam
bodyParams
=
InputParam
.
newBuilder
(
HttpAlertConstants
.
BODY_PARAMS
,
HttpAlertConstants
.
BODY_PARAMS
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
true
)
.
build
())
.
build
();
InputParam
contentField
=
InputParam
.
newBuilder
(
HttpAlertConstants
.
CONTENT_FIELD
,
HttpAlertConstants
.
CONTENT_FIELD
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
true
)
.
build
())
.
build
();
InputParam
requestType
=
InputParam
.
newBuilder
(
HttpAlertConstants
.
REQUEST_TYPE
,
HttpAlertConstants
.
REQUEST_TYPE
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
true
)
.
build
())
.
build
();
return
Arrays
.
asList
(
url
,
requestType
,
headerParams
,
bodyParams
,
contentField
);
}
@Override
public
AlertChannel
create
()
{
return
null
;
return
new
HttpAlertChannel
()
;
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSSender
.java
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpAlertConstants
.java
浏览文件 @
37c8f00e
...
...
@@ -15,20 +15,19 @@
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.
sms
;
package
org.apache.dolphinscheduler.plugin.alert.
http
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
HttpAlertConstants
{
/**
* send message
*/
public
class
SMSSender
{
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SMSSender
.
class
);
public
static
final
String
URL
=
"url"
;
public
static
final
String
HEADER_PARAMS
=
"headerParams"
;
public
static
final
String
BODY_PARAMS
=
"bodyParams"
;
public
static
final
String
CONTENT_FIELD
=
"contentField"
;
public
void
send
(){
public
static
final
String
REQUEST_TYPE
=
"requestType"
;
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMS
AlertPlugin.java
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-
http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/Http
AlertPlugin.java
浏览文件 @
37c8f00e
...
...
@@ -15,19 +15,19 @@
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.
sms
;
package
org.apache.dolphinscheduler.plugin.alert.
http
;
import
com.google.common.collect.ImmutableList
;
import
org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannelFactory
;
/**
*
sms
alertPlugins
*
http
alertPlugins
*/
public
class
SMS
AlertPlugin
implements
DolphinSchedulerPlugin
{
public
class
Http
AlertPlugin
implements
DolphinSchedulerPlugin
{
@Override
public
Iterable
<
AlertChannelFactory
>
getAlertChannelFactorys
()
{
return
ImmutableList
.
of
(
new
SMS
AlertChannelFactory
());
return
ImmutableList
.
of
(
new
Http
AlertChannelFactory
());
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
0 → 100644
浏览文件 @
37c8f00e
/*
* 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.plugin.alert.http
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.dolphinscheduler.spi.alert.AlertResult
;
import
org.apache.dolphinscheduler.spi.utils.JSONUtils
;
import
org.apache.dolphinscheduler.spi.utils.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpRequestBase
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
*http send message
*/
public
class
HttpSender
{
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpSender
.
class
);
private
String
url
;
private
String
headerParams
;
private
String
bodyParams
;
private
String
contentField
;
private
String
requestType
;
private
HttpRequestBase
httpRequest
;
private
static
final
String
URL_SPLICE_CHAR
=
"?"
;
/**
* request type post
*/
private
static
final
String
REQUEST_TYPE_POST
=
"POST"
;
/**
* request type get
*/
private
static
final
String
REQUEST_TYPE_GET
=
"GET"
;
private
static
final
String
DEFAULT_CHARSET
=
"utf-8"
;
public
HttpSender
(
Map
<
String
,
String
>
paramsMap
){
url
=
paramsMap
.
get
(
HttpAlertConstants
.
URL
);
headerParams
=
paramsMap
.
get
(
HttpAlertConstants
.
HEADER_PARAMS
);
bodyParams
=
paramsMap
.
get
(
HttpAlertConstants
.
BODY_PARAMS
);
contentField
=
paramsMap
.
get
(
HttpAlertConstants
.
CONTENT_FIELD
);
requestType
=
paramsMap
.
get
(
HttpAlertConstants
.
REQUEST_TYPE
);
}
public
AlertResult
send
(
String
msg
)
{
AlertResult
alertResult
=
new
AlertResult
();
getHttpRequest
(
msg
);
if
(
httpRequest
==
null
){
alertResult
.
setStatus
(
"false"
);
alertResult
.
setMessage
(
"Request types are not supported"
);
return
alertResult
;
}
try
{
CloseableHttpClient
httpClient
=
HttpClientBuilder
.
create
().
build
();
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpRequest
);
HttpEntity
entity
=
response
.
getEntity
();
String
resp
=
EntityUtils
.
toString
(
entity
,
DEFAULT_CHARSET
);
alertResult
.
setStatus
(
"true"
);
alertResult
.
setMessage
(
resp
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"send sms alert msg exception : {}"
,
e
.
getMessage
());
alertResult
.
setStatus
(
"false"
);
alertResult
.
setMessage
(
"send http request alert fail."
);
}
return
alertResult
;
}
private
void
getHttpRequest
(
String
msg
){
if
(
REQUEST_TYPE_POST
.
equals
(
requestType
)){
httpRequest
=
new
HttpPost
(
url
);
//POST request add param in request body
setMsgInRequestBody
(
msg
);
}
else
if
(
REQUEST_TYPE_GET
.
equals
(
requestType
)){
//GET request add param in url
setMsgInUrl
(
msg
);
httpRequest
=
new
HttpGet
(
url
);
}
setHeader
();
}
/**
* add msg param in url
* @param msg
*/
private
void
setMsgInUrl
(
String
msg
)
{
if
(
StringUtils
.
isNotBlank
(
contentField
)){
String
type
=
"&"
;
//check splice char is & or ?
if
(!
url
.
contains
(
URL_SPLICE_CHAR
)){
type
=
URL_SPLICE_CHAR
;
}
url
=
String
.
format
(
"%s%s%s=%s"
,
url
,
type
,
contentField
,
msg
);
}
}
/**
* set header params
*/
private
void
setHeader
(){
if
(
httpRequest
==
null
){
return
;
}
HashMap
<
String
,
Object
>
map
=
JSONUtils
.
parseObject
(
headerParams
,
HashMap
.
class
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
map
.
entrySet
())
{
httpRequest
.
setHeader
(
entry
.
getKey
(),
String
.
valueOf
(
entry
.
getValue
()));
}
}
/**
*set body params
* @param msg
* @return
*/
private
String
setMsgInRequestBody
(
String
msg
){
ObjectNode
objectNode
=
JSONUtils
.
parseObject
(
bodyParams
);
//set msg content field
objectNode
.
put
(
contentField
,
msg
);
return
objectNode
.
toString
();
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertConstants.java
已删除
100644 → 0
浏览文件 @
183725db
/*
* 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.plugin.alert.sms
;
public
class
SMSAlertConstants
{
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-sms/src/main/java/org/apache/dolphinscheduler/plugin/alert/sms/SMSAlertParamsConstants.java
已删除
100644 → 0
浏览文件 @
183725db
/*
* 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.plugin.alert.sms
;
public
class
SMSAlertParamsConstants
{
}
dolphinscheduler-alert-plugin/pom.xml
浏览文件 @
37c8f00e
...
...
@@ -34,7 +34,7 @@
<module>
dolphinscheduler-alert-wechat
</module>
<module>
dolphinscheduler-alert-dingtalk
</module>
<module>
dolphinscheduler-alert-script
</module>
<module>
dolphinscheduler-alert-
sms
</module>
<module>
dolphinscheduler-alert-
http
</module>
</modules>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录