break60
5 years ago
39 changed files with 1861 additions and 288 deletions
@ -0,0 +1,133 @@
|
||||
/* |
||||
* 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.alert.plugin; |
||||
|
||||
import org.apache.dolphinscheduler.alert.manager.EmailManager; |
||||
import org.apache.dolphinscheduler.alert.manager.EnterpriseWeChatManager; |
||||
import org.apache.dolphinscheduler.alert.utils.Constants; |
||||
import org.apache.dolphinscheduler.alert.utils.EnterpriseWeChatUtils; |
||||
import org.apache.dolphinscheduler.common.utils.CollectionUtils; |
||||
import org.apache.dolphinscheduler.common.utils.StringUtils; |
||||
import org.apache.dolphinscheduler.plugin.api.AlertPlugin; |
||||
import org.apache.dolphinscheduler.plugin.model.AlertData; |
||||
import org.apache.dolphinscheduler.plugin.model.AlertInfo; |
||||
import org.apache.dolphinscheduler.plugin.model.PluginName; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.*; |
||||
|
||||
/** |
||||
* EmailAlertPlugin |
||||
* |
||||
* This plugin is a default plugin, and mix up email and enterprise wechat, because adapt with former alert behavior |
||||
*/ |
||||
public class EmailAlertPlugin implements AlertPlugin { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EmailAlertPlugin.class); |
||||
|
||||
private PluginName pluginName; |
||||
|
||||
private static final EmailManager emailManager = new EmailManager(); |
||||
private static final EnterpriseWeChatManager weChatManager = new EnterpriseWeChatManager(); |
||||
|
||||
public EmailAlertPlugin() { |
||||
this.pluginName = new PluginName(); |
||||
this.pluginName.setEnglish(Constants.PLUGIN_DEFAULT_EMAIL_EN); |
||||
this.pluginName.setChinese(Constants.PLUGIN_DEFAULT_EMAIL_CH); |
||||
} |
||||
|
||||
@Override |
||||
public String getId() { |
||||
return Constants.PLUGIN_DEFAULT_EMAIL; |
||||
} |
||||
|
||||
@Override |
||||
public PluginName getName() { |
||||
return pluginName; |
||||
} |
||||
|
||||
@Override |
||||
@SuppressWarnings("unchecked") |
||||
public Map<String, Object> process(AlertInfo info) { |
||||
Map<String, Object> retMaps = new HashMap<>(); |
||||
|
||||
AlertData alert = info.getAlertData(); |
||||
|
||||
List<String> receviersList = (List<String>) info.getProp(Constants.PLUGIN_DEFAULT_EMAIL_RECEIVERS); |
||||
|
||||
// receiving group list
|
||||
// custom receiver
|
||||
String receivers = alert.getReceivers(); |
||||
if (StringUtils.isNotEmpty(receivers)) { |
||||
String[] splits = receivers.split(","); |
||||
receviersList.addAll(Arrays.asList(splits)); |
||||
} |
||||
|
||||
List<String> receviersCcList = new ArrayList<>(); |
||||
// Custom Copier
|
||||
String receiversCc = alert.getReceiversCc(); |
||||
if (StringUtils.isNotEmpty(receiversCc)) { |
||||
String[] splits = receiversCc.split(","); |
||||
receviersCcList.addAll(Arrays.asList(splits)); |
||||
} |
||||
|
||||
if (CollectionUtils.isEmpty(receviersList) && CollectionUtils.isEmpty(receviersCcList)) { |
||||
logger.warn("alert send error : At least one receiver address required"); |
||||
retMaps.put(Constants.STATUS, "false"); |
||||
retMaps.put(Constants.MESSAGE, "execution failure,At least one receiver address required."); |
||||
return retMaps; |
||||
} |
||||
|
||||
retMaps = emailManager.send(receviersList, receviersCcList, alert.getTitle(), alert.getContent(), |
||||
alert.getShowType()); |
||||
|
||||
//send flag
|
||||
boolean flag = false; |
||||
|
||||
if (retMaps == null) { |
||||
retMaps = new HashMap<>(); |
||||
retMaps.put(Constants.MESSAGE, "alert send error."); |
||||
retMaps.put(Constants.STATUS, "false"); |
||||
logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE)); |
||||
return retMaps; |
||||
} |
||||
|
||||
flag = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS))); |
||||
|
||||
if (flag) { |
||||
logger.info("alert send success"); |
||||
retMaps.put(Constants.MESSAGE, "email send success."); |
||||
if (EnterpriseWeChatUtils.isEnable()) { |
||||
logger.info("Enterprise WeChat is enable!"); |
||||
try { |
||||
String token = EnterpriseWeChatUtils.getToken(); |
||||
weChatManager.send(info, token); |
||||
} catch (Exception e) { |
||||
logger.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
} else { |
||||
retMaps.put(Constants.MESSAGE, "alert send error."); |
||||
logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE)); |
||||
} |
||||
|
||||
return retMaps; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,80 @@
|
||||
/* |
||||
* 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.alert.plugin; |
||||
|
||||
import org.apache.dolphinscheduler.alert.utils.Constants; |
||||
import org.apache.dolphinscheduler.common.enums.ShowType; |
||||
import org.apache.dolphinscheduler.plugin.api.AlertPlugin; |
||||
import org.apache.dolphinscheduler.plugin.model.AlertData; |
||||
import org.apache.dolphinscheduler.plugin.model.AlertInfo; |
||||
import org.apache.dolphinscheduler.plugin.model.PluginName; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
public class EmailAlertPluginTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EmailAlertPluginTest.class); |
||||
|
||||
private AlertPlugin plugin; |
||||
|
||||
@Before |
||||
public void before() { |
||||
plugin = new EmailAlertPlugin(); |
||||
} |
||||
|
||||
@Test |
||||
public void getId() { |
||||
String id = plugin.getId(); |
||||
assertEquals(Constants.PLUGIN_DEFAULT_EMAIL, id); |
||||
} |
||||
|
||||
@Test |
||||
public void getName() { |
||||
PluginName pluginName = plugin.getName(); |
||||
assertEquals(Constants.PLUGIN_DEFAULT_EMAIL_CH, pluginName.getChinese()); |
||||
assertEquals(Constants.PLUGIN_DEFAULT_EMAIL_EN, pluginName.getEnglish()); |
||||
} |
||||
|
||||
@Test |
||||
public void process() { |
||||
AlertInfo alertInfo = new AlertInfo(); |
||||
AlertData alertData = new AlertData(); |
||||
alertData.setId(1) |
||||
.setAlertGroupId(1) |
||||
.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("xx@xx.com") |
||||
.setReceiversCc("xx@xx.com") |
||||
.setShowType(ShowType.TEXT.getDescp()) |
||||
.setTitle("test title"); |
||||
|
||||
alertInfo.setAlertData(alertData); |
||||
List<String> list = new ArrayList<String>(){{ add("xx@xx.com"); }}; |
||||
alertInfo.addProp("receivers", list); |
||||
Map<String, Object> ret = plugin.process(alertInfo); |
||||
assertFalse(Boolean.parseBoolean(String.valueOf(ret.get(Constants.STATUS)))); |
||||
} |
||||
} |
@ -0,0 +1,107 @@
|
||||
/* |
||||
* 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.common.Constants; |
||||
import org.apache.dolphinscheduler.plugin.api.AlertPlugin; |
||||
import org.apache.dolphinscheduler.plugin.spi.AlertPluginProvider; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.File; |
||||
import java.net.MalformedURLException; |
||||
import java.net.URL; |
||||
import java.util.Map; |
||||
import java.util.ServiceLoader; |
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
|
||||
/** |
||||
* FilePluginManager |
||||
*/ |
||||
public class FilePluginManager implements PluginManager { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FilePluginManager.class); |
||||
|
||||
private Map<String, AlertPlugin> pluginMap = new ConcurrentHashMap<>(); |
||||
|
||||
private Map<String, ServiceLoader<AlertPluginProvider>> pluginLoaderMap = new ConcurrentHashMap<>(); |
||||
|
||||
private Map<String, PluginClassLoader> classLoaderMap = new ConcurrentHashMap<>(); |
||||
|
||||
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); |
||||
return; |
||||
} |
||||
for (File file : files) { |
||||
if (file.isDirectory() && !file.getPath().endsWith(Constants.PLUGIN_JAR_SUFFIX)) { |
||||
continue; |
||||
} |
||||
String pluginName = file.getName() |
||||
.substring(0, file.getName().length() - Constants.PLUGIN_JAR_SUFFIX.length()); |
||||
URL[] urls = new URL[]{ file.toURI().toURL() }; |
||||
PluginClassLoader classLoader = |
||||
new PluginClassLoader(urls, Thread.currentThread().getContextClassLoader(), whitePrefixes, excludePrefixes); |
||||
classLoaderMap.put(pluginName, classLoader); |
||||
|
||||
ServiceLoader<AlertPluginProvider> loader = ServiceLoader.load(AlertPluginProvider.class, classLoader); |
||||
pluginLoaderMap.put(pluginName, loader); |
||||
|
||||
loader.forEach(provider -> { |
||||
AlertPlugin plugin = provider.createPlugin(); |
||||
pluginMap.put(plugin.getId(), plugin); |
||||
logger.info("loaded plugin - {}", plugin.getId()); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public AlertPlugin findOne(String name) { |
||||
return pluginMap.get(name); |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, AlertPlugin> findAll() { |
||||
return pluginMap; |
||||
} |
||||
|
||||
@Override |
||||
public void addPlugin(AlertPlugin plugin) { |
||||
pluginMap.put(plugin.getId(), plugin); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,154 @@
|
||||
/* |
||||
* 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.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URL; |
||||
import java.net.URLClassLoader; |
||||
import java.util.Enumeration; |
||||
import java.util.Iterator; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Plugin Class Loader |
||||
*/ |
||||
public class PluginClassLoader extends URLClassLoader { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PluginClassLoader.class); |
||||
|
||||
private static final String JAVA_PACKAGE_PREFIX = "java."; |
||||
private static final String JAVAX_PACKAGE_PREFIX = "javax."; |
||||
|
||||
private final String[] whitePrefixes; |
||||
|
||||
private final String[] excludePrefixes; |
||||
|
||||
public PluginClassLoader(URL[] urls, ClassLoader parent, String[] whitePrefix, String[] excludePreifx) { |
||||
super(urls, parent); |
||||
this.whitePrefixes = whitePrefix; |
||||
this.excludePrefixes = excludePreifx; |
||||
} |
||||
|
||||
@Override |
||||
public Class<?> loadClass(String name) throws ClassNotFoundException { |
||||
logger.trace("Received request to load class '{}'", name); |
||||
synchronized (getClassLoadingLock(name)) { |
||||
if (name.startsWith(JAVA_PACKAGE_PREFIX) || name.startsWith(JAVAX_PACKAGE_PREFIX)) { |
||||
return findSystemClass(name); |
||||
} |
||||
|
||||
boolean isWhitePrefixes = fromWhitePrefix(name); |
||||
boolean isExcludePrefixed = fromExcludePrefix(name); |
||||
|
||||
// if the class is part of the plugin engine use parent class loader
|
||||
if (!isWhitePrefixes && isExcludePrefixed) { |
||||
return getParent().loadClass(name); |
||||
} |
||||
|
||||
// check whether it's already been loaded
|
||||
Class<?> loadedClass = findLoadedClass(name); |
||||
if (loadedClass != null) { |
||||
logger.debug("Found loaded class '{}'", name); |
||||
return loadedClass; |
||||
} |
||||
|
||||
// nope, try to load locally
|
||||
try { |
||||
loadedClass = findClass(name); |
||||
logger.debug("Found class '{}' in plugin classpath", name); |
||||
return loadedClass; |
||||
} catch (ClassNotFoundException e) { |
||||
// try next step
|
||||
} |
||||
|
||||
// use the standard ClassLoader (which follows normal parent delegation)
|
||||
return super.loadClass(name); |
||||
} |
||||
} |
||||
|
||||
private boolean fromWhitePrefix(String name) { |
||||
if (this.whitePrefixes == null) { |
||||
return false; |
||||
} |
||||
for (String whitePrefix : this.whitePrefixes) { |
||||
if (name.startsWith(whitePrefix)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
private boolean fromExcludePrefix(String name) { |
||||
if (this.excludePrefixes == null) { |
||||
return false; |
||||
} |
||||
for (String excludePrefix : this.excludePrefixes) { |
||||
if (name.startsWith(excludePrefix)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public Enumeration<URL> getResources(String name) throws IOException { |
||||
List<URL> allRes = new LinkedList<>(); |
||||
|
||||
Enumeration<URL> thisRes = findResources(name); |
||||
if (thisRes != null) { |
||||
while (thisRes.hasMoreElements()) { |
||||
allRes.add(thisRes.nextElement()); |
||||
} |
||||
} |
||||
|
||||
Enumeration<URL> parentRes = super.findResources(name); |
||||
if (parentRes != null) { |
||||
while (parentRes.hasMoreElements()) { |
||||
allRes.add(parentRes.nextElement()); |
||||
} |
||||
} |
||||
|
||||
return new Enumeration<URL>() { |
||||
Iterator<URL> it = allRes.iterator(); |
||||
|
||||
@Override |
||||
public boolean hasMoreElements() { |
||||
return it.hasNext(); |
||||
} |
||||
|
||||
@Override |
||||
public URL nextElement() { |
||||
return it.next(); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public URL getResource(String name) { |
||||
URL res = null; |
||||
|
||||
res = findResource(name); |
||||
if (res == null) { |
||||
res = super.getResource(name); |
||||
} |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* 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 java.util.Map; |
||||
|
||||
/** |
||||
* PluginManager |
||||
*/ |
||||
public interface PluginManager { |
||||
|
||||
AlertPlugin findOne(String name); |
||||
|
||||
Map<String, AlertPlugin> findAll(); |
||||
|
||||
void addPlugin(AlertPlugin plugin); |
||||
} |
@ -0,0 +1,72 @@
|
||||
/* |
||||
* 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()); |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
/* |
||||
* 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()); |
||||
} |
||||
|
||||
} |
@ -1,19 +0,0 @@
|
||||
Copyright (C) 2009-2015 The Project Lombok Authors. |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
THE SOFTWARE. |
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0"?> |
||||
<!-- |
||||
~ 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. |
||||
--> |
||||
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" |
||||
xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler</artifactId> |
||||
<version>1.2.1-SNAPSHOT</version> |
||||
</parent> |
||||
<artifactId>dolphinscheduler-plugin-api</artifactId> |
||||
<name>${project.artifactId}</name> |
||||
<packaging>jar</packaging> |
||||
|
||||
<properties> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-io</groupId> |
||||
<artifactId>commons-io</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
@ -0,0 +1,45 @@
|
||||
/* |
||||
* 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.api; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.model.AlertInfo; |
||||
import org.apache.dolphinscheduler.plugin.model.PluginName; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Plugin |
||||
*/ |
||||
public interface AlertPlugin { |
||||
|
||||
/** |
||||
* Get alert plugin id |
||||
* |
||||
* @return alert plugin id, which should be unique |
||||
*/ |
||||
String getId(); |
||||
|
||||
/** |
||||
* Get alert plugin name, which will show in front end portal |
||||
* |
||||
* @return plugin name |
||||
*/ |
||||
PluginName getName(); |
||||
|
||||
Map<String, Object> process(AlertInfo info); |
||||
|
||||
} |
@ -0,0 +1,129 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* AlertData |
||||
*/ |
||||
public class AlertData { |
||||
|
||||
/** |
||||
* alert primary key |
||||
*/ |
||||
private int id; |
||||
/** |
||||
* title |
||||
*/ |
||||
private String title; |
||||
/** |
||||
* content |
||||
*/ |
||||
private String content; |
||||
/** |
||||
* log |
||||
*/ |
||||
private String log; |
||||
/** |
||||
* alertgroup_id |
||||
*/ |
||||
private int alertGroupId; |
||||
/** |
||||
* receivers |
||||
*/ |
||||
private String receivers; |
||||
/** |
||||
* show_type |
||||
*/ |
||||
private String showType; |
||||
/** |
||||
* receivers_cc |
||||
*/ |
||||
private String receiversCc; |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public AlertData setId(int id) { |
||||
this.id = id; |
||||
return this; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
|
||||
public AlertData setTitle(String title) { |
||||
this.title = title; |
||||
return this; |
||||
} |
||||
|
||||
public String getContent() { |
||||
return content; |
||||
} |
||||
|
||||
public AlertData setContent(String content) { |
||||
this.content = content; |
||||
return this; |
||||
} |
||||
|
||||
public String getLog() { |
||||
return log; |
||||
} |
||||
|
||||
public AlertData setLog(String log) { |
||||
this.log = log; |
||||
return this; |
||||
} |
||||
|
||||
public int getAlertGroupId() { |
||||
return alertGroupId; |
||||
} |
||||
|
||||
public AlertData setAlertGroupId(int alertGroupId) { |
||||
this.alertGroupId = alertGroupId; |
||||
return this; |
||||
} |
||||
|
||||
public String getReceivers() { |
||||
return receivers; |
||||
} |
||||
|
||||
public AlertData setReceivers(String receivers) { |
||||
this.receivers = receivers; |
||||
return this; |
||||
} |
||||
|
||||
public String getReceiversCc() { |
||||
return receiversCc; |
||||
} |
||||
|
||||
public AlertData setReceiversCc(String receiversCc) { |
||||
this.receiversCc = receiversCc; |
||||
return this; |
||||
} |
||||
|
||||
public String getShowType() { |
||||
return showType; |
||||
} |
||||
|
||||
public AlertData setShowType(String showType) { |
||||
this.showType = showType; |
||||
return this; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,61 @@
|
||||
/* |
||||
* 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 java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* AlertInfo |
||||
*/ |
||||
public class AlertInfo { |
||||
|
||||
private Map<String, Object> alertProps; |
||||
|
||||
private AlertData alertData; |
||||
|
||||
public AlertInfo() { |
||||
this.alertProps = new HashMap<>(); |
||||
} |
||||
|
||||
public Map<String, Object> getAlertProps() { |
||||
return alertProps; |
||||
} |
||||
|
||||
public AlertInfo setAlertProps(Map<String, Object> alertProps) { |
||||
this.alertProps = alertProps; |
||||
return this; |
||||
} |
||||
|
||||
public AlertInfo addProp(String key, Object value) { |
||||
this.alertProps.put(key, value); |
||||
return this; |
||||
} |
||||
|
||||
public Object getProp(String key) { |
||||
return this.alertProps.get(key); |
||||
} |
||||
|
||||
public AlertData getAlertData() { |
||||
return alertData; |
||||
} |
||||
|
||||
public AlertInfo setAlertData(AlertData alertData) { |
||||
this.alertData = alertData; |
||||
return this; |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
/** |
||||
* PluginName |
||||
*/ |
||||
public class PluginName { |
||||
|
||||
private String chinese; |
||||
|
||||
private String english; |
||||
|
||||
public String getChinese() { |
||||
return chinese; |
||||
} |
||||
|
||||
public PluginName setChinese(String chinese) { |
||||
this.chinese = chinese; |
||||
return this; |
||||
} |
||||
|
||||
public String getEnglish() { |
||||
return english; |
||||
} |
||||
|
||||
public PluginName setEnglish(String english) { |
||||
this.english = english; |
||||
return this; |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* 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.spi; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.api.AlertPlugin; |
||||
|
||||
/** |
||||
* PluginProvider |
||||
*/ |
||||
public interface AlertPluginProvider { |
||||
|
||||
/** |
||||
* create an alert plugin |
||||
* |
||||
* @return an alert plugin |
||||
*/ |
||||
AlertPlugin createPlugin(); |
||||
|
||||
} |
@ -0,0 +1,190 @@
|
||||
/* |
||||
* 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.utils; |
||||
|
||||
import org.apache.commons.io.IOUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.util.Properties; |
||||
|
||||
/** |
||||
* property utils |
||||
* single instance |
||||
*/ |
||||
public class PropertyUtils { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PropertyUtils.class); |
||||
|
||||
private static final Properties properties = new Properties(); |
||||
|
||||
private PropertyUtils() { |
||||
throw new IllegalStateException("PropertyUtils class"); |
||||
} |
||||
|
||||
static { |
||||
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 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; |
||||
} |
||||
|
||||
/** |
||||
* get property value |
||||
* |
||||
* @param key property name |
||||
* @return property value |
||||
*/ |
||||
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 |
||||
*/ |
||||
public static int getInt(String key) { |
||||
return getInt(key, -1); |
||||
} |
||||
|
||||
/** |
||||
* get int |
||||
* |
||||
* @param key key |
||||
* @param defaultValue default value |
||||
* @return property value |
||||
*/ |
||||
public static int getInt(String key, int defaultValue) { |
||||
String value = properties.getProperty(key.trim()); |
||||
if (value == null) { |
||||
return defaultValue; |
||||
} |
||||
try { |
||||
return Integer.parseInt(value); |
||||
} catch (NumberFormatException e) { |
||||
logger.info(e.getMessage(), e); |
||||
} |
||||
return defaultValue; |
||||
} |
||||
|
||||
/** |
||||
* get property value |
||||
* |
||||
* @param key property name |
||||
* @return property value |
||||
*/ |
||||
public static boolean getBoolean(String key) { |
||||
String value = properties.getProperty(key.trim()); |
||||
if (value == null) { |
||||
return false; |
||||
} |
||||
|
||||
return Boolean.parseBoolean(value); |
||||
} |
||||
|
||||
/** |
||||
* get property value |
||||
* |
||||
* @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 (value == null) { |
||||
return defaultValue; |
||||
} |
||||
|
||||
return Boolean.parseBoolean(value); |
||||
} |
||||
|
||||
/** |
||||
* get property long value |
||||
* |
||||
* @param key key |
||||
* @param defaultVal default value |
||||
* @return property value |
||||
*/ |
||||
public static long getLong(String key, long defaultVal) { |
||||
String val = getString(key); |
||||
return val == null ? defaultVal : Long.parseLong(val); |
||||
} |
||||
|
||||
/** |
||||
* get long |
||||
* |
||||
* @param key key |
||||
* @return property value |
||||
*/ |
||||
public static long getLong(String key) { |
||||
return getLong(key, -1); |
||||
} |
||||
|
||||
/** |
||||
* get double |
||||
* |
||||
* @param key key |
||||
* @param defaultVal default value |
||||
* @return property value |
||||
*/ |
||||
public static double getDouble(String key, double defaultVal) { |
||||
String val = properties.getProperty(key.trim()); |
||||
return val == null ? defaultVal : Double.parseDouble(val); |
||||
} |
||||
|
||||
/** |
||||
* @param key key |
||||
* @param type type |
||||
* @param defaultValue default value |
||||
* @param <T> T |
||||
* @return get enum value |
||||
*/ |
||||
public <T extends Enum<T>> T getEnum(String key, Class<T> type, |
||||
T defaultValue) { |
||||
String val = properties.getProperty(key.trim()); |
||||
return val == null ? defaultValue : Enum.valueOf(type, val); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,80 @@
|
||||
/* |
||||
* 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()); |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
/* |
||||
* 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()); |
||||
} |
||||
} |
@ -0,0 +1,83 @@
|
||||
/* |
||||
* 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.utils; |
||||
|
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
public class PropertyUtilsTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PropertyUtilsTest.class); |
||||
|
||||
/** |
||||
* Test getString |
||||
*/ |
||||
@Test |
||||
public void testGetString() { |
||||
|
||||
String result = PropertyUtils.getString("test.string"); |
||||
logger.info(result); |
||||
assertEquals("teststring", result); |
||||
|
||||
//If key is null, then return null
|
||||
result = PropertyUtils.getString(null); |
||||
assertNull(result); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Test getBoolean |
||||
*/ |
||||
@Test |
||||
public void testGetBoolean() { |
||||
|
||||
//Expected true
|
||||
Boolean result = PropertyUtils.getBoolean("test.true"); |
||||
assertTrue(result); |
||||
|
||||
//Expected false
|
||||
result = PropertyUtils.getBoolean("test.false"); |
||||
assertFalse(result); |
||||
} |
||||
|
||||
/** |
||||
* Test getLong |
||||
*/ |
||||
@Test |
||||
public void testGetLong() { |
||||
long result = PropertyUtils.getLong("test.long"); |
||||
assertSame(100L, result); |
||||
} |
||||
|
||||
/** |
||||
* Test getDouble |
||||
*/ |
||||
@Test |
||||
public void testGetDouble() { |
||||
|
||||
//If key is undefine in alert.properties, and there is a defaultval, then return defaultval
|
||||
double result = PropertyUtils.getDouble("abc", 5.0); |
||||
assertEquals(5.0, result, 0); |
||||
|
||||
result = PropertyUtils.getDouble("cba", 5.0); |
||||
assertEquals(3.1, result, 0.01); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
# |
||||
# 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. |
||||
# |
||||
|
||||
test.string=teststring |
||||
test.false=false |
||||
test.true=true |
||||
cba=3.1 |
||||
test.long=100 |
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash |
||||
|
||||
# |
||||
# 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. |
||||
# |
||||
|
||||
mkdir dist || true |
||||
|
||||
tar -zxf dolphinscheduler-dist/target/apache-dolphinscheduler*-bin.tar.gz --strip=1 -C dist |
||||
|
||||
# List all modules(jars) that belong to the DolphinScheduler itself, these will be ignored when checking the dependency |
||||
# licenses |
||||
echo '=== Self modules: ' && ./mvnw --batch-mode --quiet -Dexec.executable='echo' -Dexec.args='${project.artifactId}-${project.version}.jar' exec:exec | tee self-modules.txt |
||||
|
||||
echo '=== Distributed dependencies: ' && ls dist/lib | tee all-dependencies.txt |
||||
|
||||
# Exclude all self modules(jars) to generate all third-party dependencies |
||||
echo '=== Third party dependencies: ' && grep -vf self-modules.txt all-dependencies.txt | tee third-party-dependencies.txt |
||||
|
||||
# 1. Compare the third-party dependencies with known dependencies, expect that all third-party dependencies are KNOWN |
||||
# and the exit code of the command is 0, otherwise we should add its license to LICENSE file and add the dependency to |
||||
# known-dependencies.txt. 2. Unify the `sort` behaviour: here we'll sort them again in case that the behaviour of `sort` |
||||
# command in target OS is different from what we used to sort the file `known-dependencies.txt`, i.e. "sort the two file |
||||
# using the same command (and default arguments)" |
||||
|
||||
diff -w -B -U0 <(sort < tools/dependencies/known-dependencies.txt) <(sort < third-party-dependencies.txt) |
@ -0,0 +1,211 @@
|
||||
HikariCP-3.2.0.jar |
||||
activation-1.1.jar |
||||
ant-1.6.5.jar |
||||
aopalliance-1.0.jar |
||||
apache-el-8.5.35.1.jar |
||||
apacheds-i18n-2.0.0-M15.jar |
||||
apacheds-kerberos-codec-2.0.0-M15.jar |
||||
api-asn1-api-1.0.0-M20.jar |
||||
api-util-1.0.0-M20.jar |
||||
asm-3.1.jar |
||||
aspectjweaver-1.9.2.jar |
||||
audience-annotations-0.5.0.jar |
||||
avro-1.7.4.jar |
||||
aws-java-sdk-1.7.4.jar |
||||
bonecp-0.8.0.RELEASE.jar |
||||
byte-buddy-1.9.10.jar |
||||
classmate-1.4.0.jar |
||||
clickhouse-jdbc-0.1.52.jar |
||||
commons-cli-1.2.jar |
||||
commons-codec-1.6.jar |
||||
commons-collections-3.2.2.jar |
||||
commons-collections4-4.1.jar |
||||
commons-compiler-3.0.12.jar |
||||
commons-compress-1.4.1.jar |
||||
commons-configuration-1.10.jar |
||||
commons-daemon-1.0.13.jar |
||||
commons-dbcp-1.4.jar |
||||
commons-email-1.5.jar |
||||
commons-httpclient-3.0.1.jar |
||||
commons-io-2.4.jar |
||||
commons-lang-2.6.jar |
||||
commons-logging-1.1.1.jar |
||||
commons-math3-3.1.1.jar |
||||
commons-net-3.1.jar |
||||
commons-pool-1.6.jar |
||||
core-3.1.1.jar |
||||
cron-utils-5.0.5.jar |
||||
curator-client-4.3.0.jar |
||||
curator-framework-4.3.0.jar |
||||
curator-recipes-4.3.0.jar |
||||
datanucleus-api-jdo-4.2.1.jar |
||||
datanucleus-core-4.1.6.jar |
||||
datanucleus-rdbms-4.1.7.jar |
||||
derby-10.14.2.0.jar |
||||
druid-1.1.14.jar |
||||
fastjson-1.2.61.jar |
||||
gson-2.8.5.jar |
||||
guava-20.0.jar |
||||
guice-3.0.jar |
||||
guice-servlet-3.0.jar |
||||
h2-1.4.200.jar |
||||
hadoop-annotations-2.7.3.jar |
||||
hadoop-auth-2.7.3.jar |
||||
hadoop-aws-2.7.3.jar |
||||
hadoop-client-2.7.3.jar |
||||
hadoop-common-2.7.3.jar |
||||
hadoop-hdfs-2.7.3.jar |
||||
hadoop-mapreduce-client-app-2.7.3.jar |
||||
hadoop-mapreduce-client-common-2.7.3.jar |
||||
hadoop-mapreduce-client-core-2.7.3.jar |
||||
hadoop-mapreduce-client-jobclient-2.7.3.jar |
||||
hadoop-mapreduce-client-shuffle-2.7.3.jar |
||||
hadoop-yarn-api-2.7.3.jar |
||||
hadoop-yarn-client-2.7.3.jar |
||||
hadoop-yarn-common-2.7.3.jar |
||||
hadoop-yarn-server-common-2.7.3.jar |
||||
hamcrest-core-1.3.jar |
||||
hibernate-validator-6.0.14.Final.jar |
||||
hive-common-2.1.0.jar |
||||
hive-jdbc-2.1.0.jar |
||||
hive-metastore-2.1.0.jar |
||||
hive-orc-2.1.0.jar |
||||
hive-serde-2.1.0.jar |
||||
hive-service-2.1.0.jar |
||||
hive-service-rpc-2.1.0.jar |
||||
hive-storage-api-2.1.0.jar |
||||
htrace-core-3.1.0-incubating.jar |
||||
httpclient-4.4.1.jar |
||||
httpcore-4.4.1.jar |
||||
httpmime-4.5.7.jar |
||||
jackson-annotations-2.9.8.jar |
||||
jackson-core-2.9.8.jar |
||||
jackson-core-asl-1.9.13.jar |
||||
jackson-databind-2.9.8.jar |
||||
jackson-datatype-jdk8-2.9.8.jar |
||||
jackson-datatype-jsr310-2.9.8.jar |
||||
jackson-jaxrs-1.9.13.jar |
||||
jackson-mapper-asl-1.9.13.jar |
||||
jackson-module-parameter-names-2.9.8.jar |
||||
jackson-xc-1.9.13.jar |
||||
jamon-runtime-2.3.1.jar |
||||
janino-3.0.12.jar |
||||
java-xmlbuilder-0.4.jar |
||||
javax.activation-api-1.2.0.jar |
||||
javax.annotation-api-1.3.2.jar |
||||
javax.inject-1.jar |
||||
javax.jdo-3.2.0-m3.jar |
||||
javax.mail-1.6.2.jar |
||||
javax.servlet-api-3.1.0.jar |
||||
javolution-5.5.1.jar |
||||
jaxb-api-2.3.1.jar |
||||
jaxb-impl-2.2.3-1.jar |
||||
jboss-logging-3.3.2.Final.jar |
||||
jdo-api-3.0.1.jar |
||||
jersey-client-1.9.jar |
||||
jersey-core-1.9.jar |
||||
jersey-guice-1.9.jar |
||||
jersey-json-1.9.jar |
||||
jersey-server-1.9.jar |
||||
jets3t-0.9.0.jar |
||||
jettison-1.1.jar |
||||
jetty-6.1.26.jar |
||||
jetty-continuation-9.4.14.v20181114.jar |
||||
jetty-http-9.4.14.v20181114.jar |
||||
jetty-io-9.4.14.v20181114.jar |
||||
jetty-security-9.4.14.v20181114.jar |
||||
jetty-server-9.4.14.v20181114.jar |
||||
jetty-servlet-9.4.14.v20181114.jar |
||||
jetty-servlets-9.4.14.v20181114.jar |
||||
jetty-util-6.1.26.jar |
||||
jetty-util-9.4.14.v20181114.jar |
||||
jetty-webapp-9.4.14.v20181114.jar |
||||
jetty-xml-9.4.14.v20181114.jar |
||||
jline-0.9.94.jar |
||||
jna-4.5.2.jar |
||||
jna-platform-4.5.2.jar |
||||
joda-time-2.10.1.jar |
||||
jpam-1.1.jar |
||||
jsch-0.1.42.jar |
||||
jsp-2.1-6.1.14.jar |
||||
jsp-api-2.1-6.1.14.jar |
||||
jsp-api-2.1.jar |
||||
jsqlparser-2.1.jar |
||||
jsr305-3.0.0.jar |
||||
jta-1.1.jar |
||||
jul-to-slf4j-1.7.25.jar |
||||
junit-4.12.jar |
||||
leveldbjni-all-1.8.jar |
||||
libfb303-0.9.3.jar |
||||
libthrift-0.9.3.jar |
||||
log4j-1.2-api-2.11.2.jar |
||||
log4j-1.2.17.jar |
||||
log4j-api-2.11.2.jar |
||||
log4j-core-2.11.2.jar |
||||
logback-classic-1.2.3.jar |
||||
logback-core-1.2.3.jar |
||||
lz4-1.3.0.jar |
||||
mapstruct-1.2.0.Final.jar |
||||
mssql-jdbc-6.1.0.jre8.jar |
||||
mybatis-3.5.2.jar |
||||
mybatis-plus-3.2.0.jar |
||||
mybatis-plus-annotation-3.2.0.jar |
||||
mybatis-plus-boot-starter-3.2.0.jar |
||||
mybatis-plus-core-3.2.0.jar |
||||
mybatis-plus-extension-3.2.0.jar |
||||
mybatis-spring-2.0.2.jar |
||||
netty-3.6.2.Final.jar |
||||
netty-all-4.1.33.Final.jar |
||||
opencsv-2.3.jar |
||||
oshi-core-3.5.0.jar |
||||
paranamer-2.3.jar |
||||
parquet-hadoop-bundle-1.8.1.jar |
||||
poi-3.17.jar |
||||
postgresql-42.1.4.jar |
||||
protobuf-java-2.5.0.jar |
||||
quartz-2.2.3.jar |
||||
quartz-jobs-2.2.3.jar |
||||
slf4j-api-1.7.5.jar |
||||
snakeyaml-1.23.jar |
||||
snappy-0.2.jar |
||||
snappy-java-1.0.4.1.jar |
||||
spring-aop-5.1.5.RELEASE.jar |
||||
spring-beans-5.1.5.RELEASE.jar |
||||
spring-boot-2.1.3.RELEASE.jar |
||||
spring-boot-autoconfigure-2.1.3.RELEASE.jar |
||||
spring-boot-starter-2.1.3.RELEASE.jar |
||||
spring-boot-starter-aop-2.1.3.RELEASE.jar |
||||
spring-boot-starter-jdbc-2.1.3.RELEASE.jar |
||||
spring-boot-starter-jetty-2.1.3.RELEASE.jar |
||||
spring-boot-starter-json-2.1.3.RELEASE.jar |
||||
spring-boot-starter-logging-2.1.3.RELEASE.jar |
||||
spring-boot-starter-web-2.1.3.RELEASE.jar |
||||
spring-context-5.1.5.RELEASE.jar |
||||
spring-core-5.1.5.RELEASE.jar |
||||
spring-expression-5.1.5.RELEASE.jar |
||||
spring-jcl-5.1.5.RELEASE.jar |
||||
spring-jdbc-5.1.5.RELEASE.jar |
||||
spring-plugin-core-1.2.0.RELEASE.jar |
||||
spring-plugin-metadata-1.2.0.RELEASE.jar |
||||
spring-tx-5.1.5.RELEASE.jar |
||||
spring-web-5.1.5.RELEASE.jar |
||||
spring-webmvc-5.1.5.RELEASE.jar |
||||
springfox-core-2.9.2.jar |
||||
springfox-schema-2.9.2.jar |
||||
springfox-spi-2.9.2.jar |
||||
springfox-spring-web-2.9.2.jar |
||||
springfox-swagger-common-2.9.2.jar |
||||
springfox-swagger-ui-2.9.2.jar |
||||
springfox-swagger2-2.9.2.jar |
||||
swagger-annotations-1.5.20.jar |
||||
swagger-bootstrap-ui-1.9.3.jar |
||||
swagger-models-1.5.20.jar |
||||
tephra-api-0.6.0.jar |
||||
threetenbp-1.3.6.jar |
||||
transaction-api-1.1.jar |
||||
validation-api-2.0.1.Final.jar |
||||
xercesImpl-2.9.1.jar |
||||
xml-apis-1.4.01.jar |
||||
xmlenc-0.52.jar |
||||
xz-1.0.jar |
||||
zookeeper-3.4.14.jar |
Loading…
Reference in new issue