Browse Source

[Improvement][SPI] support load single plugin (#5794)

change load operation of 'registry.plugin.dir'
2.0.7-release
Wenjun Ruan 3 years ago committed by GitHub
parent
commit
9c217d072d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/plugin/DolphinPluginLoader.java

28
dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/plugin/DolphinPluginLoader.java

@ -30,8 +30,10 @@ import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -80,7 +82,7 @@ public class DolphinPluginLoader {
public void loadPlugins() public void loadPlugins()
throws Exception { throws Exception {
for (File file : listPluginDirs(installedPluginsDir)) { for (File file : listPluginInstanceDirs(installedPluginsDir)) {
if (file.isDirectory()) { if (file.isDirectory()) {
loadPlugin(file.getAbsolutePath()); loadPlugin(file.getAbsolutePath());
} }
@ -145,7 +147,7 @@ public class DolphinPluginLoader {
throws Exception { throws Exception {
logger.info("Classpath for {}:", dir.getName()); logger.info("Classpath for {}:", dir.getName());
List<URL> urls = new ArrayList<>(); List<URL> urls = new ArrayList<>();
for (File file : listPluginDirs(dir)) { for (File file : listPluginInstanceJars(dir)) {
logger.info(" {}", file); logger.info(" {}", file);
urls.add(file.toURI().toURL()); urls.add(file.toURI().toURL());
} }
@ -172,12 +174,28 @@ public class DolphinPluginLoader {
return new DolphinPluginClassLoader(urls, parent, DOLPHIN_SPI_PACKAGES); return new DolphinPluginClassLoader(urls, parent, DOLPHIN_SPI_PACKAGES);
} }
private static List<File> listPluginDirs(File installedPluginsDir) { private static List<File> listPluginInstanceDirs(File installedPluginsDir) {
if (installedPluginsDir != null && installedPluginsDir.isDirectory()) { if (installedPluginsDir != null && installedPluginsDir.isDirectory()) {
File[] files = installedPluginsDir.listFiles(); File[] files = installedPluginsDir.listFiles();
if (files != null) { if (files != null) {
Arrays.sort(files); Optional<File> isNotDir = Arrays.stream(files).filter(file -> !file.isDirectory()).findAny();
return ImmutableList.copyOf(files); if (isNotDir.isPresent()) {
return ImmutableList.of(installedPluginsDir);
} else {
Arrays.sort(files);
return ImmutableList.copyOf(files);
}
}
}
return ImmutableList.of();
}
private static List<File> listPluginInstanceJars(File installedPluginsDir) {
if (installedPluginsDir != null && installedPluginsDir.isDirectory()) {
File[] files = installedPluginsDir.listFiles();
if (files != null) {
return ImmutableList.copyOf(Arrays.stream(files).filter(file -> file.isFile() && file.getName().endsWith(".jar"))
.collect(Collectors.toList()));
} }
} }
return ImmutableList.of(); return ImmutableList.of();

Loading…
Cancel
Save