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/06/01 03:28:11 UTC

[GitHub] [incubator-seatunnel] BenJFan opened a new pull request, #1979: [Core] [Fix] add plugin mapping ignore case

BenJFan opened a new pull request, #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979

   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   add plugin mapping ignore case
   This close #1884 
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.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] ruanwenjun commented on a diff in pull request #1979: [Core] [Fix] add plugin mapping ignore case

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979#discussion_r886332279


##########
seatunnel-core/seatunnel-core-base/src/test/java/org/apache/seatunnel/core/base/config/PluginFactoryTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.seatunnel.core.base.config;
+
+import org.apache.seatunnel.common.config.Common;
+import org.apache.seatunnel.spark.SparkEnvironment;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigResolveOptions;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+public class PluginFactoryTest {
+
+    @Test
+    public void getPluginMappingValueTest() throws Exception {
+
+        Common.setDeployMode("cluster");
+        Config config = new ConfigBuilder<>(Paths.get(Objects.requireNonNull(PluginFactoryTest.class.getResource("/flink.batch" +
+                ".conf")).getPath()), EngineType.SPARK).getConfig();
+
+        Config pluginMapping = ConfigFactory
+                .parseFile(new File(Objects.requireNonNull(PluginFactoryTest.class.getResource("/plugin-mapping.properties")).getPath()))
+                .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
+                .resolveWith(ConfigFactory.systemProperties(),
+                        ConfigResolveOptions.defaults().setAllowUnresolved(true));
+
+        PluginFactory<SparkEnvironment> factory = new PluginFactory<>(config, EngineType.SPARK);
+
+        Method method = factory.getClass().getDeclaredMethod("getPluginMappingValue", Config.class,

Review Comment:
   You can remove the private of `getPluginMappingValue`, then you don't need to use reflect in UT.



-- 
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 merged pull request #1979: [Core] [Fix] add plugin mapping ignore case

Posted by GitBox <gi...@apache.org>.
ruanwenjun merged PR #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979


-- 
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] BenJFan commented on a diff in pull request #1979: [Core] [Fix] add plugin mapping ignore case

Posted by GitBox <gi...@apache.org>.
BenJFan commented on code in PR #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979#discussion_r886343020


##########
seatunnel-core/seatunnel-core-base/src/test/java/org/apache/seatunnel/core/base/config/PluginFactoryTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.seatunnel.core.base.config;
+
+import org.apache.seatunnel.common.config.Common;
+import org.apache.seatunnel.spark.SparkEnvironment;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigResolveOptions;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+public class PluginFactoryTest {
+
+    @Test
+    public void getPluginMappingValueTest() throws Exception {
+
+        Common.setDeployMode("cluster");
+        Config config = new ConfigBuilder<>(Paths.get(Objects.requireNonNull(PluginFactoryTest.class.getResource("/flink.batch" +
+                ".conf")).getPath()), EngineType.SPARK).getConfig();
+
+        Config pluginMapping = ConfigFactory
+                .parseFile(new File(Objects.requireNonNull(PluginFactoryTest.class.getResource("/plugin-mapping.properties")).getPath()))
+                .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
+                .resolveWith(ConfigFactory.systemProperties(),
+                        ConfigResolveOptions.defaults().setAllowUnresolved(true));
+
+        PluginFactory<SparkEnvironment> factory = new PluginFactory<>(config, EngineType.SPARK);
+
+        Method method = factory.getClass().getDeclaredMethod("getPluginMappingValue", Config.class,

Review Comment:
   In fact, `getPluginMappingValue` should be private, so I think we should use reflect in here



-- 
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] BenJFan commented on a diff in pull request #1979: [Core] [Fix] add plugin mapping ignore case

Posted by GitBox <gi...@apache.org>.
BenJFan commented on code in PR #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979#discussion_r886624134


##########
seatunnel-core/seatunnel-core-base/src/test/java/org/apache/seatunnel/core/base/config/PluginFactoryTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.seatunnel.core.base.config;
+
+import org.apache.seatunnel.common.config.Common;
+import org.apache.seatunnel.spark.SparkEnvironment;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigResolveOptions;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+public class PluginFactoryTest {
+
+    @Test
+    public void getPluginMappingValueTest() throws Exception {
+
+        Common.setDeployMode("cluster");
+        Config config = new ConfigBuilder<>(Paths.get(Objects.requireNonNull(PluginFactoryTest.class.getResource("/flink.batch" +
+                ".conf")).getPath()), EngineType.SPARK).getConfig();
+
+        Config pluginMapping = ConfigFactory
+                .parseFile(new File(Objects.requireNonNull(PluginFactoryTest.class.getResource("/plugin-mapping.properties")).getPath()))
+                .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
+                .resolveWith(ConfigFactory.systemProperties(),
+                        ConfigResolveOptions.defaults().setAllowUnresolved(true));
+
+        PluginFactory<SparkEnvironment> factory = new PluginFactory<>(config, EngineType.SPARK);
+
+        Method method = factory.getClass().getDeclaredMethod("getPluginMappingValue", Config.class,

Review Comment:
   Ok, I will change 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 a diff in pull request #1979: [Core] [Fix] add plugin mapping ignore case

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979#discussion_r886574836


##########
seatunnel-core/seatunnel-core-base/src/test/java/org/apache/seatunnel/core/base/config/PluginFactoryTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.seatunnel.core.base.config;
+
+import org.apache.seatunnel.common.config.Common;
+import org.apache.seatunnel.spark.SparkEnvironment;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigResolveOptions;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+public class PluginFactoryTest {
+
+    @Test
+    public void getPluginMappingValueTest() throws Exception {
+
+        Common.setDeployMode("cluster");
+        Config config = new ConfigBuilder<>(Paths.get(Objects.requireNonNull(PluginFactoryTest.class.getResource("/flink.batch" +
+                ".conf")).getPath()), EngineType.SPARK).getConfig();
+
+        Config pluginMapping = ConfigFactory
+                .parseFile(new File(Objects.requireNonNull(PluginFactoryTest.class.getResource("/plugin-mapping.properties")).getPath()))
+                .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
+                .resolveWith(ConfigFactory.systemProperties(),
+                        ConfigResolveOptions.defaults().setAllowUnresolved(true));
+
+        PluginFactory<SparkEnvironment> factory = new PluginFactory<>(config, EngineType.SPARK);
+
+        Method method = factory.getClass().getDeclaredMethod("getPluginMappingValue", Config.class,

Review Comment:
   You can change the scope to default or protect, this can help to test. Using reflect in UT is not a good practice, when we change the method name, we cannot get the error in compile time.



-- 
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 diff in pull request #1979: [Core] [Fix] add plugin mapping ignore case

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #1979:
URL: https://github.com/apache/incubator-seatunnel/pull/1979#discussion_r886336620


##########
seatunnel-core/seatunnel-core-base/src/main/java/org/apache/seatunnel/core/base/config/PluginFactory.java:
##########
@@ -156,7 +156,11 @@ private String getPluginMappingKey(PluginType type, String pluginName) {
     }
 
     private String getPluginMappingValue(Config pluginMapping, PluginType type, String pluginName) {
-        return pluginMapping.getConfig(this.engineType.getEngine()).getConfig(type.getType()).getString(pluginName);
+
+        return pluginMapping.getConfig(this.engineType.getEngine()).getConfig(type.getType()).entrySet()
+                .stream().filter(entry -> entry.getKey().equalsIgnoreCase(pluginName))
+                .collect(Collectors.toList()).get(0).getValue().unwrapped().toString();
+

Review Comment:
   `.get(0)` there might cause NullPointException. It's better change to 
   ```java
   .stream()
   .filter()
   .findAny()
   ```
   



-- 
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