Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
906ffa09
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 接近 2 年
通知
707
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,发现更多精彩内容 >>
提交
906ffa09
编写于
4月 29, 2020
作者:
H
hgaol
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve code checks
上级
3c6d8136
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
367 addition
and
143 deletion
+367
-143
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
...n/java/org/apache/dolphinscheduler/alert/AlertServer.java
+4
-10
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EmailManager.java
...g/apache/dolphinscheduler/alert/manager/EmailManager.java
+0
-1
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
...org/apache/dolphinscheduler/alert/runner/AlertSender.java
+4
-16
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
...e/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
+5
-4
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java
...e/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java
+6
-4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/plugin/FilePluginManager.java
...che/dolphinscheduler/common/plugin/FilePluginManager.java
+20
-2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/plugin/PluginClassLoader.java
...che/dolphinscheduler/common/plugin/PluginClassLoader.java
+7
-3
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/plugin/FilePluginManagerTest.java
...dolphinscheduler/common/plugin/FilePluginManagerTest.java
+72
-0
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/plugin/PluginClassLoaderTest.java
...dolphinscheduler/common/plugin/PluginClassLoaderTest.java
+61
-0
dolphinscheduler-plugin-api/src/main/java/org/apache/dolphinscheduler/plugin/model/AlertData.java
...a/org/apache/dolphinscheduler/plugin/model/AlertData.java
+0
-12
dolphinscheduler-plugin-api/src/main/java/org/apache/dolphinscheduler/plugin/utils/PropertyUtils.java
...g/apache/dolphinscheduler/plugin/utils/PropertyUtils.java
+44
-86
dolphinscheduler-plugin-api/src/test/java/org/apache/dolphinscheduler/plugin/model/AlertDataTest.java
...g/apache/dolphinscheduler/plugin/model/AlertDataTest.java
+80
-0
dolphinscheduler-plugin-api/src/test/java/org/apache/dolphinscheduler/plugin/model/AlertInfoTest.java
...g/apache/dolphinscheduler/plugin/model/AlertInfoTest.java
+54
-0
dolphinscheduler-plugin-api/src/test/java/org/apache/dolphinscheduler/plugin/utils/PropertyUtilsTest.java
...ache/dolphinscheduler/plugin/utils/PropertyUtilsTest.java
+2
-2
pom.xml
pom.xml
+8
-3
未找到文件。
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
浏览文件 @
906ffa09
...
...
@@ -28,7 +28,6 @@ import org.apache.dolphinscheduler.dao.entity.Alert;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.net.MalformedURLException
;
import
java.util.List
;
/**
...
...
@@ -56,15 +55,10 @@ public class AlertServer {
};
public
AlertServer
()
{
try
{
alertPluginManager
=
new
FilePluginManager
(
PropertyUtils
.
getString
(
Constants
.
PLUGIN_DIR
),
whitePrefixes
,
excludePrefixes
);
// add default alert plugins
alertPluginManager
.
addPlugin
(
new
EmailAlertPlugin
());
}
catch
(
MalformedURLException
e
)
{
logger
.
error
(
"Failed to start alert server"
,
e
);
System
.
exit
(
1
);
}
alertPluginManager
=
new
FilePluginManager
(
PropertyUtils
.
getString
(
Constants
.
PLUGIN_DIR
),
whitePrefixes
,
excludePrefixes
);
// add default alert plugins
alertPluginManager
.
addPlugin
(
new
EmailAlertPlugin
());
}
public
synchronized
static
AlertServer
getInstance
()
{
...
...
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EmailManager.java
浏览文件 @
906ffa09
...
...
@@ -17,7 +17,6 @@
package
org.apache.dolphinscheduler.alert.manager
;
import
org.apache.dolphinscheduler.alert.utils.MailUtils
;
import
org.apache.dolphinscheduler.common.enums.ShowType
;
import
java.util.List
;
import
java.util.Map
;
...
...
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
浏览文件 @
906ffa09
...
...
@@ -54,9 +54,7 @@ public class AlertSender {
}
public
void
run
()
{
List
<
User
>
users
;
Map
<
String
,
Object
>
retMaps
=
null
;
for
(
Alert
alert
:
alertList
)
{
users
=
alertDao
.
listUserByAlertgroupId
(
alert
.
getAlertGroupId
());
...
...
@@ -85,7 +83,10 @@ public class AlertSender {
AlertPlugin
emailPlugin
=
pluginManager
.
findOne
(
Constants
.
PLUGIN_DEFAULT_EMAIL
);
retMaps
=
emailPlugin
.
process
(
alertInfo
);
if
(
retMaps
==
null
||
!
Boolean
.
parseBoolean
(
String
.
valueOf
(
retMaps
.
get
(
Constants
.
STATUS
))))
{
if
(
retMaps
==
null
)
{
alertDao
.
updateAlert
(
AlertStatus
.
EXECUTION_FAILURE
,
"alert send error"
,
alert
.
getId
());
logger
.
info
(
"alert send error : return value is null"
);
}
else
if
(!
Boolean
.
parseBoolean
(
String
.
valueOf
(
retMaps
.
get
(
Constants
.
STATUS
))))
{
alertDao
.
updateAlert
(
AlertStatus
.
EXECUTION_FAILURE
,
String
.
valueOf
(
retMaps
.
get
(
Constants
.
MESSAGE
)),
alert
.
getId
());
logger
.
info
(
"alert send error : {}"
,
retMaps
.
get
(
Constants
.
MESSAGE
));
}
else
{
...
...
@@ -96,17 +97,4 @@ public class AlertSender {
}
/**
* get a list of SMS users
*
* @param users
* @return
*/
private
List
<
String
>
getReciversForSMS
(
List
<
User
>
users
)
{
List
<
String
>
list
=
new
ArrayList
<>();
for
(
User
user
:
users
)
{
list
.
add
(
user
.
getPhone
());
}
return
list
;
}
}
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
浏览文件 @
906ffa09
...
...
@@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.alert.utils;
import
org.apache.dolphinscheduler.common.enums.ShowType
;
import
org.apache.dolphinscheduler.common.utils.StringUtils
;
import
org.apache.dolphinscheduler.dao.entity.Alert
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.reflect.TypeToken
;
...
...
@@ -67,15 +66,17 @@ public class EnterpriseWeChatUtils {
* get Enterprise WeChat is enable
* @return isEnable
*/
public
static
B
oolean
isEnable
(){
Boolean
isEnable
=
false
;
public
static
b
oolean
isEnable
(){
Boolean
isEnable
=
null
;
try
{
isEnable
=
PropertyUtils
.
getBoolean
(
Constants
.
ENTERPRISE_WECHAT_ENABLE
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
if
(
isEnable
==
null
)
{
return
false
;
}
return
isEnable
;
}
/**
...
...
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/plugin/EmailAlertPluginTest.java
浏览文件 @
906ffa09
...
...
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.*;
...
...
@@ -65,14 +66,15 @@ public class EmailAlertPluginTest {
.
setContent
(
"[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", "
+
"\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]"
)
.
setLog
(
"test log"
)
.
setReceivers
(
"
bitace@163
.com"
)
.
setReceiversCc
(
"
bitace@163
.com"
)
.
setReceivers
(
"
xx@xx
.com"
)
.
setReceiversCc
(
"
xx@xx
.com"
)
.
setShowType
(
ShowType
.
TEXT
.
getDescp
())
.
setTitle
(
"test title"
);
alertInfo
.
setAlertData
(
alertData
);
List
<
String
>
list
=
new
ArrayList
<
String
>(){{
add
(
"
bitace@163
.com"
);
}};
List
<
String
>
list
=
new
ArrayList
<
String
>(){{
add
(
"
xx@xx
.com"
);
}};
alertInfo
.
addProp
(
"receivers"
,
list
);
plugin
.
process
(
alertInfo
);
Map
<
String
,
Object
>
ret
=
plugin
.
process
(
alertInfo
);
assertFalse
(
Boolean
.
parseBoolean
(
String
.
valueOf
(
ret
.
get
(
Constants
.
STATUS
))));
}
}
\ No newline at end of file
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/plugin/FilePluginManager.java
浏览文件 @
906ffa09
...
...
@@ -42,12 +42,30 @@ public class FilePluginManager implements PluginManager {
private
Map
<
String
,
PluginClassLoader
>
classLoaderMap
=
new
ConcurrentHashMap
<>();
public
FilePluginManager
(
String
dirPath
,
String
[]
whitePrefixes
,
String
[]
excludePrefixes
)
throws
MalformedURLException
{
private
String
[]
whitePrefixes
;
private
String
[]
excludePrefixes
;
public
FilePluginManager
(
String
dirPath
,
String
[]
whitePrefixes
,
String
[]
excludePrefixes
)
{
this
.
whitePrefixes
=
whitePrefixes
;
this
.
excludePrefixes
=
excludePrefixes
;
try
{
load
(
dirPath
);
}
catch
(
MalformedURLException
e
)
{
logger
.
error
(
"load plugins failed."
,
e
);
}
}
private
void
load
(
String
dirPath
)
throws
MalformedURLException
{
logger
.
info
(
"start to load jar files in {}"
,
dirPath
);
if
(
dirPath
==
null
)
{
logger
.
error
(
"not a valid path - {}"
,
dirPath
);
return
;
}
File
[]
files
=
new
File
(
dirPath
).
listFiles
();
if
(
files
==
null
)
{
logger
.
error
(
"not a valid path - {}"
,
dirPath
);
System
.
exit
(
1
)
;
return
;
}
for
(
File
file
:
files
)
{
if
(
file
.
isDirectory
()
&&
!
file
.
getPath
().
endsWith
(
Constants
.
PLUGIN_JAR_SUFFIX
))
{
...
...
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/plugin/PluginClassLoader.java
浏览文件 @
906ffa09
...
...
@@ -85,6 +85,9 @@ public class PluginClassLoader extends URLClassLoader {
}
private
boolean
fromWhitePrefix
(
String
name
)
{
if
(
this
.
whitePrefixes
==
null
)
{
return
false
;
}
for
(
String
whitePrefix
:
this
.
whitePrefixes
)
{
if
(
name
.
startsWith
(
whitePrefix
))
{
return
true
;
...
...
@@ -94,6 +97,9 @@ public class PluginClassLoader extends URLClassLoader {
}
private
boolean
fromExcludePrefix
(
String
name
)
{
if
(
this
.
excludePrefixes
==
null
)
{
return
false
;
}
for
(
String
excludePrefix
:
this
.
excludePrefixes
)
{
if
(
name
.
startsWith
(
excludePrefix
))
{
return
true
;
...
...
@@ -139,9 +145,7 @@ public class PluginClassLoader extends URLClassLoader {
public
URL
getResource
(
String
name
)
{
URL
res
=
null
;
if
(
res
==
null
)
{
res
=
findResource
(
name
);
}
res
=
findResource
(
name
);
if
(
res
==
null
)
{
res
=
super
.
getResource
(
name
);
}
...
...
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/plugin/FilePluginManagerTest.java
0 → 100644
浏览文件 @
906ffa09
/*
* 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.common.plugin
;
import
org.apache.dolphinscheduler.plugin.api.AlertPlugin
;
import
org.apache.dolphinscheduler.plugin.model.AlertInfo
;
import
org.apache.dolphinscheduler.plugin.model.PluginName
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.*;
public
class
FilePluginManagerTest
{
private
FilePluginManager
filePluginManager
;
private
AlertPlugin
alertPlugin
;
@Before
public
void
before
()
{
filePluginManager
=
new
FilePluginManager
(
null
,
null
,
null
);
alertPlugin
=
new
AlertPlugin
()
{
@Override
public
String
getId
()
{
return
"test"
;
}
@Override
public
PluginName
getName
()
{
return
new
PluginName
().
setChinese
(
"ch"
).
setEnglish
(
"en"
);
}
@Override
public
Map
<
String
,
Object
>
process
(
AlertInfo
info
)
{
return
new
HashMap
<>();
}
};
}
@Test
public
void
findOne
()
{
filePluginManager
.
addPlugin
(
alertPlugin
);
assertEquals
(
alertPlugin
,
filePluginManager
.
findOne
(
alertPlugin
.
getId
()));
}
@Test
public
void
findAll
()
{
assertNotNull
(
filePluginManager
.
findAll
());
}
@Test
public
void
addPlugin
()
{
filePluginManager
.
addPlugin
(
alertPlugin
);
assertNotNull
(
filePluginManager
.
findAll
());
}
}
\ No newline at end of file
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/plugin/PluginClassLoaderTest.java
0 → 100644
浏览文件 @
906ffa09
/*
* 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.common.plugin
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.net.URL
;
import
static
org
.
junit
.
Assert
.*;
public
class
PluginClassLoaderTest
{
private
PluginClassLoader
pluginClassLoader
;
private
ClassLoader
parent
;
@Before
public
void
setUp
()
{
parent
=
Thread
.
currentThread
().
getContextClassLoader
();
pluginClassLoader
=
new
PluginClassLoader
(
new
URL
[]{},
parent
,
null
,
null
);
}
@Test
public
void
loadClassNull
()
{
Class
clazz
=
null
;
try
{
clazz
=
pluginClassLoader
.
loadClass
(
"java.lang.Object"
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
assertEquals
(
null
,
clazz
.
getClassLoader
());
}
@Test
public
void
loadClassApp
()
{
Class
clazz
=
null
;
try
{
clazz
=
pluginClassLoader
.
loadClass
(
"org.apache.dolphinscheduler.common.Constants"
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
assertEquals
(
parent
,
clazz
.
getClassLoader
());
}
}
\ No newline at end of file
dolphinscheduler-plugin-api/src/main/java/org/apache/dolphinscheduler/plugin/model/AlertData.java
浏览文件 @
906ffa09
...
...
@@ -54,9 +54,6 @@ public class AlertData {
*/
private
String
receiversCc
;
public
AlertData
()
{
}
public
int
getId
()
{
return
id
;
}
...
...
@@ -129,13 +126,4 @@ public class AlertData {
return
this
;
}
public
AlertData
(
int
id
,
String
title
,
String
content
,
String
log
,
int
alertGroupId
,
String
receivers
,
String
receiversCc
)
{
this
.
id
=
id
;
this
.
title
=
title
;
this
.
content
=
content
;
this
.
log
=
log
;
this
.
alertGroupId
=
alertGroupId
;
this
.
receivers
=
receivers
;
this
.
receiversCc
=
receiversCc
;
}
}
dolphinscheduler-plugin-api/src/main/java/org/apache/dolphinscheduler/plugin/utils/PropertyUtils.java
浏览文件 @
906ffa09
...
...
@@ -22,8 +22,6 @@ import org.slf4j.LoggerFactory;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
/**
...
...
@@ -32,9 +30,6 @@ import java.util.Properties;
*/
public
class
PropertyUtils
{
/**
* logger
*/
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PropertyUtils
.
class
);
private
static
final
Properties
properties
=
new
Properties
();
...
...
@@ -44,76 +39,72 @@ public class PropertyUtils {
}
static
{
String
[]
propertyFiles
=
new
String
[]{
"/plugin.properties"
};
for
(
String
fileName
:
propertyFiles
)
{
InputStream
fis
=
null
;
try
{
fis
=
PropertyUtils
.
class
.
getResourceAsStream
(
fileName
);
properties
.
load
(
fis
);
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
if
(
fis
!=
null
)
{
IOUtils
.
closeQuietly
(
fis
);
}
System
.
exit
(
1
);
}
finally
{
String
propertyFiles
=
"/plugin.properties"
;
InputStream
fis
=
null
;
try
{
fis
=
PropertyUtils
.
class
.
getResourceAsStream
(
propertyFiles
);
properties
.
load
(
fis
);
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
if
(
fis
!=
null
)
{
IOUtils
.
closeQuietly
(
fis
);
}
}
finally
{
IOUtils
.
closeQuietly
(
fis
);
}
}
/**
* get property value
*
* @param key property name
* @param key property name
* @param defaultVal default value
* @return property value
*/
public
static
String
getString
(
String
key
)
{
if
(
key
==
null
)
{
return
null
;
}
return
properties
.
getProperty
(
key
.
trim
());
public
static
String
getString
(
String
key
,
String
defaultVal
)
{
String
val
=
properties
.
getProperty
(
key
.
trim
());
return
val
==
null
?
defaultVal
:
val
;
}
/**
* get property value
*
* @param key property name
* @param defaultVal default value
* @return property value
*/
public
static
String
getString
(
String
key
,
String
defaultVal
)
{
String
val
=
properties
.
getProperty
(
key
.
trim
());
return
val
==
null
?
defaultVal
:
val
;
public
static
String
getString
(
String
key
)
{
if
(
key
==
null
)
{
return
null
;
}
return
properties
.
getProperty
(
key
.
trim
());
}
/**
* get property value
*
* @param key property name
* @return
get property int value , if key == null, then return -1
* @return get property int value , if key == null, then return -1
*/
public
static
int
getInt
(
String
key
)
{
return
getInt
(
key
,
-
1
);
}
/**
* get int
*
* @param key key
* @param key
key
* @param defaultValue default value
* @return property value
*/
public
static
int
getInt
(
String
key
,
int
defaultValue
)
{
String
value
=
getString
(
key
);
String
value
=
properties
.
getProperty
(
key
.
trim
()
);
if
(
value
==
null
)
{
return
defaultValue
;
}
try
{
return
Integer
.
parseInt
(
value
);
}
catch
(
NumberFormatException
e
)
{
logger
.
info
(
e
.
getMessage
(),
e
);
logger
.
info
(
e
.
getMessage
(),
e
);
}
return
defaultValue
;
}
...
...
@@ -126,32 +117,33 @@ public class PropertyUtils {
*/
public
static
boolean
getBoolean
(
String
key
)
{
String
value
=
properties
.
getProperty
(
key
.
trim
());
if
(
null
!=
value
)
{
return
Boolean
.
parseBoolean
(
value
)
;
if
(
value
==
null
)
{
return
false
;
}
return
false
;
return
Boolean
.
parseBoolean
(
value
)
;
}
/**
* get property value
*
* @param key property name
* @param key
property name
* @param defaultValue default value
* @return property value
*/
public
static
Boolean
getBoolean
(
String
key
,
boolean
defaultValue
)
{
String
value
=
properties
.
getProperty
(
key
.
trim
());
if
(
null
!=
value
)
{
return
Boolean
.
parseBoolean
(
value
)
;
if
(
value
==
null
)
{
return
defaultValue
;
}
return
defaultValue
;
return
Boolean
.
parseBoolean
(
value
)
;
}
/**
* get property long value
* @param key key
*
* @param key key
* @param defaultVal default value
* @return property value
*/
...
...
@@ -161,72 +153,38 @@ public class PropertyUtils {
}
/**
* get long
*
* @param key key
* @return property value
*/
public
static
long
getLong
(
String
key
)
{
return
getLong
(
key
,-
1
);
return
getLong
(
key
,
-
1
);
}
/**
* get double
*
* @param key key
* @param key
key
* @param defaultVal default value
* @return property value
*/
public
static
double
getDouble
(
String
key
,
double
defaultVal
)
{
String
val
=
getString
(
key
);
String
val
=
properties
.
getProperty
(
key
.
trim
()
);
return
val
==
null
?
defaultVal
:
Double
.
parseDouble
(
val
);
}
/**
* get array
* @param key property name
* @param splitStr separator
* @return property value through array
*/
public
static
String
[]
getArray
(
String
key
,
String
splitStr
)
{
String
value
=
getString
(
key
);
if
(
value
==
null
)
{
return
new
String
[
0
];
}
try
{
String
[]
propertyArray
=
value
.
split
(
splitStr
);
return
propertyArray
;
}
catch
(
NumberFormatException
e
)
{
logger
.
info
(
e
.
getMessage
(),
e
);
}
return
new
String
[
0
];
}
/**
*
* @param key key
* @param type type
* @param key key
* @param type type
* @param defaultValue default value
* @param <T> T
* @return
get enum value
* @param <T>
T
* @return get enum value
*/
public
<
T
extends
Enum
<
T
>>
T
getEnum
(
String
key
,
Class
<
T
>
type
,
T
defaultValue
)
{
String
val
=
getString
(
key
);
String
val
=
properties
.
getProperty
(
key
.
trim
()
);
return
val
==
null
?
defaultValue
:
Enum
.
valueOf
(
type
,
val
);
}
/**
* get all properties with specified prefix, like: fs.
* @param prefix prefix to search
* @return all properties with specified prefix
*/
public
static
Map
<
String
,
String
>
getPrefixedProperties
(
String
prefix
)
{
Map
<
String
,
String
>
matchedProperties
=
new
HashMap
<>();
for
(
String
propName
:
properties
.
stringPropertyNames
())
{
if
(
propName
.
startsWith
(
prefix
))
{
matchedProperties
.
put
(
propName
,
properties
.
getProperty
(
propName
));
}
}
return
matchedProperties
;
}
}
dolphinscheduler-plugin-api/src/test/java/org/apache/dolphinscheduler/plugin/model/AlertDataTest.java
0 → 100644
浏览文件 @
906ffa09
/*
* 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.model
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
class
AlertDataTest
{
private
AlertData
alertData
;
@Before
public
void
before
()
{
alertData
=
new
AlertData
();
alertData
.
setId
(
1
)
.
setContent
(
"content"
)
.
setShowType
(
"email"
)
.
setTitle
(
"title"
)
.
setReceivers
(
"receivers"
)
.
setReceiversCc
(
"cc"
)
.
setLog
(
"log"
)
.
setAlertGroupId
(
1
);
}
@Test
public
void
getId
()
{
assertEquals
(
1
,
alertData
.
getId
());
}
@Test
public
void
getTitle
()
{
assertEquals
(
"title"
,
alertData
.
getTitle
());
}
@Test
public
void
getContent
()
{
assertEquals
(
"content"
,
alertData
.
getContent
());
}
@Test
public
void
getLog
()
{
assertEquals
(
"log"
,
alertData
.
getLog
());
}
@Test
public
void
getAlertGroupId
()
{
assertEquals
(
1
,
alertData
.
getAlertGroupId
());
}
@Test
public
void
getReceivers
()
{
assertEquals
(
"receivers"
,
alertData
.
getReceivers
());
}
@Test
public
void
getReceiversCc
()
{
assertEquals
(
"cc"
,
alertData
.
getReceiversCc
());
}
@Test
public
void
getShowType
()
{
assertEquals
(
"email"
,
alertData
.
getShowType
());
}
}
\ No newline at end of file
dolphinscheduler-plugin-api/src/test/java/org/apache/dolphinscheduler/plugin/model/AlertInfoTest.java
0 → 100644
浏览文件 @
906ffa09
/*
* 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.model
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.*;
public
class
AlertInfoTest
{
private
AlertInfo
alertInfo
;
@Before
public
void
before
()
{
alertInfo
=
new
AlertInfo
();
}
@Test
public
void
getAlertProps
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
alertInfo
.
setAlertProps
(
map
);
assertNotNull
(
alertInfo
.
getAlertProps
());
}
@Test
public
void
getProp
()
{
alertInfo
.
addProp
(
"k"
,
"v"
);
assertEquals
(
"v"
,
alertInfo
.
getProp
(
"k"
));
}
@Test
public
void
getAlertData
()
{
alertInfo
.
setAlertData
(
new
AlertData
());
assertNotNull
(
alertInfo
.
getAlertData
());
}
}
\ No newline at end of file
dolphinscheduler-plugin-api/src/test/java/org/apache/dolphinscheduler/plugin/utils/PropertyUtilsTest.java
浏览文件 @
906ffa09
...
...
@@ -63,7 +63,7 @@ public class PropertyUtilsTest {
@Test
public
void
testGetLong
()
{
long
result
=
PropertyUtils
.
getLong
(
"test.long"
);
assertSame
(
result
,
100L
);
assertSame
(
100L
,
result
);
}
/**
...
...
@@ -74,7 +74,7 @@ public class PropertyUtilsTest {
//If key is undefine in alert.properties, and there is a defaultval, then return defaultval
double
result
=
PropertyUtils
.
getDouble
(
"abc"
,
5.0
);
assertEquals
(
result
,
5.0
,
0
);
assertEquals
(
5.0
,
result
,
0
);
result
=
PropertyUtils
.
getDouble
(
"cba"
,
5.0
);
assertEquals
(
3.1
,
result
,
0.01
);
...
...
pom.xml
浏览文件 @
906ffa09
...
...
@@ -350,7 +350,7 @@
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
${mysql.connector.version}
</version>
<
!-- <scope>test</scope>--
>
<
scope>
test
</scope
>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
...
...
@@ -694,6 +694,7 @@
<include>
**/alert/utils/FuncUtilsTest.java
</include>
<include>
**/alert/utils/JSONUtilsTest.java
</include>
<include>
**/alert/utils/MailUtilsTest.java
</include>
<include>
**/alert/plugin/EmailAlertPluginTest.java
</include>
<include>
**/api/dto/resources/filter/ResourceFilterTest.java
</include>
<include>
**/api/dto/resources/visitor/ResourceTreeVisitorTest.java
</include>
<include>
**/api/enums/testGetEnum.java
</include>
...
...
@@ -769,6 +770,8 @@
<include>
**/common/utils/HttpUtilsTest.java
</include>
<include>
**/common/ConstantsTest.java
</include>
<include>
**/common/utils/HadoopUtils.java
</include>
<include>
**/common/plugin/FilePluginManagerTest
</include>
<include>
**/common/plugin/PluginClassLoaderTest
</include>
<include>
**/dao/mapper/AccessTokenMapperTest.java
</include>
<include>
**/dao/mapper/AlertGroupMapperTest.java
</include>
<include>
**/dao/mapper/CommandMapperTest.java
</include>
...
...
@@ -835,6 +838,9 @@
<include>
**/dao/mapper/UserMapperTest.java
</include>
<include>
**/dao/utils/DagHelperTest.java
</include>
<include>
**/dao/AlertDaoTest.java
</include>
<include>
**/plugin/model/AlertDataTest.java
</include>
<include>
**/plugin/model/AlertInfoTest.java
</include>
<include>
**/plugin/utils/PropertyUtilsTest.java
</include>
</includes>
<!-- <skip>true</skip> -->
</configuration>
...
...
@@ -980,5 +986,4 @@
<module>
dolphinscheduler-service
</module>
<module>
dolphinscheduler-plugin-api
</module>
</modules>
</project>
\ No newline at end of file
</project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录