You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/03/28 07:48:17 UTC

[GitHub] [incubator-seatunnel] ruanwenjun opened a new pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

ruanwenjun opened a new pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592


   ## Purpose of this pull request
   
   close #1591 
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in you PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/developement/NewLicenseGuide.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836294715



##########
File path: seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-druid/src/main/java/org/apache/seatunnel/druid/sink/DruidOutputFormat.java
##########
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.seatunnel.flink.sink;
+package org.apache.seatunnel.druid.sink;

Review comment:
       Did you miss the flink package distinction?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836508593



##########
File path: seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/ConfigBuilder.java
##########
@@ -130,49 +129,37 @@ private boolean checkIsContainHive() {
     /**
      * create plugin class instance, ignore case.
      **/
-    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String name, PluginType pluginType) throws Exception {
-        if (name.split("\\.").length != 1) {
-            // canonical class name
-            return (T) Class.forName(name).newInstance();
+    @SuppressWarnings("unchecked")
+    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String pluginName, PluginType pluginType) throws Exception {
+        Map<PluginType, Class<?>> pluginBaseClassMap = engine.getPluginTypes();
+        if (!pluginBaseClassMap.containsKey(pluginType)) {
+            throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
         }
-        String packageName;
-        ServiceLoader<T> plugins;
-        switch (pluginType) {
-            case SOURCE:
-                packageName = configPackage.getSourcePackage();
-                Class<T> baseSource = (Class<T>) Class.forName(configPackage.getBaseSourceClass());
-                plugins = ServiceLoader.load(baseSource);
-                break;
-            case TRANSFORM:
-                packageName = configPackage.getTransformPackage();
-                Class<T> baseTransform = (Class<T>) Class.forName(configPackage.getBaseTransformClass());
-                plugins = ServiceLoader.load(baseTransform);
-                break;
-            case SINK:
-                packageName = configPackage.getSinkPackage();
-                Class<T> baseSink = (Class<T>) Class.forName(configPackage.getBaseSinkClass());
-                plugins = ServiceLoader.load(baseSink);
-                break;
-            default:
-                throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
+        Class<T> pluginBaseClass = (Class<T>) pluginBaseClassMap.get(pluginType);
+        if (pluginName.split("\\.").length != 1) {
+            // canonical class name
+            Class<T> pluginClass = (Class<T>) Class.forName(pluginName);
+            if (pluginClass.isAssignableFrom(pluginBaseClass)) {
+                throw new IllegalArgumentException("plugin: " + pluginName + " is not extends from " + pluginBaseClass);
+            }
+            return pluginClass.newInstance();
         }
-        String canonicalName = packageName + "." + name;
+
+        ServiceLoader<T> plugins = ServiceLoader.load(pluginBaseClass);
         for (Iterator<T> it = plugins.iterator(); it.hasNext(); ) {
             try {
                 T plugin = it.next();
                 Class<?> serviceClass = plugin.getClass();
-                String serviceClassName = serviceClass.getName();
-                String clsNameToLower = serviceClassName.toLowerCase();
-                if (clsNameToLower.equals(canonicalName.toLowerCase())) {
+                if (StringUtils.equalsIgnoreCase(serviceClass.getSimpleName(), pluginName)) {

Review comment:
       This won't happen here, since we use the plugin type to load the target plugins, so the sink and source will not both exist in this method.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836556292



##########
File path: seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/EngineType.java
##########
@@ -17,18 +17,51 @@
 
 package org.apache.seatunnel.config;
 
+import org.apache.seatunnel.flink.BaseFlinkSink;
+import org.apache.seatunnel.flink.BaseFlinkSource;
+import org.apache.seatunnel.flink.BaseFlinkTransform;
+import org.apache.seatunnel.spark.BaseSparkSink;
+import org.apache.seatunnel.spark.BaseSparkSource;
+import org.apache.seatunnel.spark.BaseSparkTransform;
+
+import java.util.HashMap;
+import java.util.Map;
+
 public enum EngineType {
-    SPARK("spark"),
-    FLINK("flink"),
+
+    SPARK("spark", new HashMap<PluginType, Class<?>>() {
+        {
+            put(PluginType.SOURCE, BaseSparkSource.class);
+            put(PluginType.TRANSFORM, BaseSparkTransform.class);
+            put(PluginType.SINK, BaseSparkSink.class);
+        }
+    }),
+
+    FLINK("flink", new HashMap<PluginType, Class<?>>() {
+        {
+            put(PluginType.SOURCE, BaseFlinkSource.class);
+            put(PluginType.TRANSFORM, BaseFlinkTransform.class);
+            put(PluginType.SINK, BaseFlinkSink.class);
+        }
+    }),

Review comment:
       Ok, add a PluginFactory class to do the create plugins work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836467508



##########
File path: seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/EngineType.java
##########
@@ -17,18 +17,51 @@
 
 package org.apache.seatunnel.config;
 
+import org.apache.seatunnel.flink.BaseFlinkSink;
+import org.apache.seatunnel.flink.BaseFlinkSource;
+import org.apache.seatunnel.flink.BaseFlinkTransform;
+import org.apache.seatunnel.spark.BaseSparkSink;
+import org.apache.seatunnel.spark.BaseSparkSource;
+import org.apache.seatunnel.spark.BaseSparkTransform;
+
+import java.util.HashMap;
+import java.util.Map;
+
 public enum EngineType {
-    SPARK("spark"),
-    FLINK("flink"),
+
+    SPARK("spark", new HashMap<PluginType, Class<?>>() {
+        {
+            put(PluginType.SOURCE, BaseSparkSource.class);
+            put(PluginType.TRANSFORM, BaseSparkTransform.class);
+            put(PluginType.SINK, BaseSparkSink.class);
+        }
+    }),
+
+    FLINK("flink", new HashMap<PluginType, Class<?>>() {
+        {
+            put(PluginType.SOURCE, BaseFlinkSource.class);
+            put(PluginType.TRANSFORM, BaseFlinkTransform.class);
+            put(PluginType.SINK, BaseFlinkSink.class);
+        }
+    }),

Review comment:
       Only static class initializers should be used




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#issuecomment-1081320621


   > LGTM BTW, it's better not to use force push
   
   Thanks for your advice.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836360484



##########
File path: seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-druid/src/main/java/org/apache/seatunnel/druid/sink/DruidOutputFormat.java
##########
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.seatunnel.flink.sink;
+package org.apache.seatunnel.druid.sink;

Review comment:
       Yes, fixed this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#issuecomment-1080383916


   > 
   
   It has been done, please help to review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836292674



##########
File path: seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/resources/META-INF/services/org.apache.seatunnel.spark.BaseSparkSink
##########
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.seatunnel.spark.sink.Email
+org.apache.seatunnel.spark.email.sink.Email

Review comment:
       ignore me




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#issuecomment-1080477150


   > 
   
   Yes, I have run the three example, it's all success.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836464479



##########
File path: seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/ConfigBuilder.java
##########
@@ -130,49 +129,37 @@ private boolean checkIsContainHive() {
     /**
      * create plugin class instance, ignore case.
      **/
-    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String name, PluginType pluginType) throws Exception {
-        if (name.split("\\.").length != 1) {
-            // canonical class name
-            return (T) Class.forName(name).newInstance();
+    @SuppressWarnings("unchecked")
+    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String pluginName, PluginType pluginType) throws Exception {
+        Map<PluginType, Class<?>> pluginBaseClassMap = engine.getPluginTypes();
+        if (!pluginBaseClassMap.containsKey(pluginType)) {
+            throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
         }
-        String packageName;
-        ServiceLoader<T> plugins;
-        switch (pluginType) {
-            case SOURCE:
-                packageName = configPackage.getSourcePackage();
-                Class<T> baseSource = (Class<T>) Class.forName(configPackage.getBaseSourceClass());
-                plugins = ServiceLoader.load(baseSource);
-                break;
-            case TRANSFORM:
-                packageName = configPackage.getTransformPackage();
-                Class<T> baseTransform = (Class<T>) Class.forName(configPackage.getBaseTransformClass());
-                plugins = ServiceLoader.load(baseTransform);
-                break;
-            case SINK:
-                packageName = configPackage.getSinkPackage();
-                Class<T> baseSink = (Class<T>) Class.forName(configPackage.getBaseSinkClass());
-                plugins = ServiceLoader.load(baseSink);
-                break;
-            default:
-                throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
+        Class<T> pluginBaseClass = (Class<T>) pluginBaseClassMap.get(pluginType);
+        if (pluginName.split("\\.").length != 1) {
+            // canonical class name
+            Class<T> pluginClass = (Class<T>) Class.forName(pluginName);
+            if (pluginClass.isAssignableFrom(pluginBaseClass)) {
+                throw new IllegalArgumentException("plugin: " + pluginName + " is not extends from " + pluginBaseClass);
+            }
+            return pluginClass.newInstance();
         }
-        String canonicalName = packageName + "." + name;
+
+        ServiceLoader<T> plugins = ServiceLoader.load(pluginBaseClass);
         for (Iterator<T> it = plugins.iterator(); it.hasNext(); ) {
             try {
                 T plugin = it.next();
                 Class<?> serviceClass = plugin.getClass();
-                String serviceClassName = serviceClass.getName();
-                String clsNameToLower = serviceClassName.toLowerCase();
-                if (clsNameToLower.equals(canonicalName.toLowerCase())) {
+                if (StringUtils.equalsIgnoreCase(serviceClass.getSimpleName(), pluginName)) {

Review comment:
       It is better to use `serviceClass.getName()` to avoid having the same name but one is `sink` and one is `source`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] liujinhui1994 commented on pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
liujinhui1994 commented on pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#issuecomment-1080452671


   @ruanwenjun  Can you do a small verification? Such as console, to ensure that it is feasible. Because it is very troublesome to do all the verification now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] liujinhui1994 commented on pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
liujinhui1994 commented on pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#issuecomment-1080377901


   Can this be done today?
   @ruanwenjun 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836292208



##########
File path: seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/resources/META-INF/services/org.apache.seatunnel.spark.BaseSparkSink
##########
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.seatunnel.spark.sink.Email
+org.apache.seatunnel.spark.email.sink.Email

Review comment:
       It looks weird 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs merged pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs merged pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] CalvinKirs commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836465551



##########
File path: seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/ConfigBuilder.java
##########
@@ -130,49 +129,37 @@ private boolean checkIsContainHive() {
     /**
      * create plugin class instance, ignore case.
      **/
-    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String name, PluginType pluginType) throws Exception {
-        if (name.split("\\.").length != 1) {
-            // canonical class name
-            return (T) Class.forName(name).newInstance();
+    @SuppressWarnings("unchecked")
+    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String pluginName, PluginType pluginType) throws Exception {
+        Map<PluginType, Class<?>> pluginBaseClassMap = engine.getPluginTypes();
+        if (!pluginBaseClassMap.containsKey(pluginType)) {
+            throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
         }
-        String packageName;
-        ServiceLoader<T> plugins;
-        switch (pluginType) {
-            case SOURCE:
-                packageName = configPackage.getSourcePackage();
-                Class<T> baseSource = (Class<T>) Class.forName(configPackage.getBaseSourceClass());
-                plugins = ServiceLoader.load(baseSource);
-                break;
-            case TRANSFORM:
-                packageName = configPackage.getTransformPackage();
-                Class<T> baseTransform = (Class<T>) Class.forName(configPackage.getBaseTransformClass());
-                plugins = ServiceLoader.load(baseTransform);
-                break;
-            case SINK:
-                packageName = configPackage.getSinkPackage();
-                Class<T> baseSink = (Class<T>) Class.forName(configPackage.getBaseSinkClass());
-                plugins = ServiceLoader.load(baseSink);
-                break;
-            default:
-                throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
+        Class<T> pluginBaseClass = (Class<T>) pluginBaseClassMap.get(pluginType);
+        if (pluginName.split("\\.").length != 1) {
+            // canonical class name
+            Class<T> pluginClass = (Class<T>) Class.forName(pluginName);
+            if (pluginClass.isAssignableFrom(pluginBaseClass)) {
+                throw new IllegalArgumentException("plugin: " + pluginName + " is not extends from " + pluginBaseClass);
+            }
+            return pluginClass.newInstance();

Review comment:
       Note that 'newInstance()' is deprecated




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] ruanwenjun commented on a change in pull request #1592: [Feature][core] Optimize the plugin load, rename plugin package name

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on a change in pull request #1592:
URL: https://github.com/apache/incubator-seatunnel/pull/1592#discussion_r836555803



##########
File path: seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/config/ConfigBuilder.java
##########
@@ -130,49 +129,37 @@ private boolean checkIsContainHive() {
     /**
      * create plugin class instance, ignore case.
      **/
-    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String name, PluginType pluginType) throws Exception {
-        if (name.split("\\.").length != 1) {
-            // canonical class name
-            return (T) Class.forName(name).newInstance();
+    @SuppressWarnings("unchecked")
+    private <T extends Plugin<ENVIRONMENT>> T createPluginInstanceIgnoreCase(String pluginName, PluginType pluginType) throws Exception {
+        Map<PluginType, Class<?>> pluginBaseClassMap = engine.getPluginTypes();
+        if (!pluginBaseClassMap.containsKey(pluginType)) {
+            throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
         }
-        String packageName;
-        ServiceLoader<T> plugins;
-        switch (pluginType) {
-            case SOURCE:
-                packageName = configPackage.getSourcePackage();
-                Class<T> baseSource = (Class<T>) Class.forName(configPackage.getBaseSourceClass());
-                plugins = ServiceLoader.load(baseSource);
-                break;
-            case TRANSFORM:
-                packageName = configPackage.getTransformPackage();
-                Class<T> baseTransform = (Class<T>) Class.forName(configPackage.getBaseTransformClass());
-                plugins = ServiceLoader.load(baseTransform);
-                break;
-            case SINK:
-                packageName = configPackage.getSinkPackage();
-                Class<T> baseSink = (Class<T>) Class.forName(configPackage.getBaseSinkClass());
-                plugins = ServiceLoader.load(baseSink);
-                break;
-            default:
-                throw new IllegalArgumentException("PluginType not support : [" + pluginType + "]");
+        Class<T> pluginBaseClass = (Class<T>) pluginBaseClassMap.get(pluginType);
+        if (pluginName.split("\\.").length != 1) {
+            // canonical class name
+            Class<T> pluginClass = (Class<T>) Class.forName(pluginName);
+            if (pluginClass.isAssignableFrom(pluginBaseClass)) {
+                throw new IllegalArgumentException("plugin: " + pluginName + " is not extends from " + pluginBaseClass);
+            }
+            return pluginClass.newInstance();

Review comment:
       Done, use constructor to create instance.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org