You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "corgy-w (via GitHub)" <gi...@apache.org> on 2024/08/11 10:21:39 UTC

[PR] [Improve][Connector-V2]Support multi-table sink feature for email [seatunnel]

corgy-w opened a new pull request, #7368:
URL: https://github.com/apache/seatunnel/pull/7368

   ### Purpose of this pull request
   
   1. Support tableSinkFactory for email
   2. Support multi-table sink for email
   
   ### Does this PR introduce _any_ user-facing change?
   
   
   ### How was this patch tested?
   
   
   ### Check list
   
   * [] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [] If you are contributing the connector code, please check that the following files are updated:
     1. Update change log that in connector document. For more details you can refer to [connector-v2](https://github.com/apache/seatunnel/tree/dev/docs/en/connector-v2)
     2. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     3. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
   * [] Update the [`release-note`](https://github.com/apache/seatunnel/blob/dev/release-note.md).


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


Re: [PR] [Improve][Connector-V2]Support multi-table sink feature for email [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #7368:
URL: https://github.com/apache/seatunnel/pull/7368#discussion_r1717834249


##########
seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/sink/EmailSinkWriter.java:
##########
@@ -78,38 +79,47 @@ public void write(SeaTunnelRow element) {
     public void close() {
         createFile();
         Properties properties = new Properties();
-
         properties.setProperty("mail.host", config.getEmailHost());
-
         properties.setProperty("mail.transport.protocol", config.getEmailTransportProtocol());
-
         properties.setProperty("mail.smtp.auth", config.getEmailSmtpAuth());
+        properties.setProperty("mail.smtp.port", config.getEmailSmtpPort().toString());
 
         try {
             MailSSLSocketFactory sf = new MailSSLSocketFactory();
             sf.setTrustAllHosts(true);
-            properties.put("mail.smtp.ssl.enable", "true");
             properties.put("mail.smtp.ssl.socketFactory", sf);
-            Session session =
-                    Session.getDefaultInstance(
-                            properties,
-                            new Authenticator() {
-                                @Override
-                                protected PasswordAuthentication getPasswordAuthentication() {
-                                    return new PasswordAuthentication(
-                                            config.getEmailFromAddress(),
-                                            config.getEmailAuthorizationCode());
-                                }
-                            });
+            Session session;
+            if ("true".equalsIgnoreCase(config.getEmailSmtpAuth())) {

Review Comment:
   how about change the `EMAIL_SMTP_AUTH` value to boolean type?



##########
seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/config/EmailConfig.java:
##########
@@ -66,4 +68,10 @@ public class EmailConfig {
                     .stringType()
                     .noDefaultValue()
                     .withDescription("Whether to use SMTP authentication");
+
+    public static final Option<String> EMAIL_SMTP_PORT =
+            Options.key("email_smtp_port")
+                    .stringType()
+                    .defaultValue("465")
+                    .withDescription("Select port for authentication.");

Review Comment:
   The port should be int?



##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-email-e2e/src/test/java/org/apache/seatunnel/e2e/connector/email/EmailWithMultiIT.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.e2e.connector.email;
+
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.EngineType;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.stream.Stream;
+
+@Slf4j
+public class EmailWithMultiIT extends TestSuiteBase implements TestResource {
+    private static final String IMAGE = "greenmail/standalone";
+    private static final String HOST = "email-e2e";
+    private static final int PORT = 3025;
+
+    private GenericContainer<?> smtpContainer;
+
+    @BeforeAll
+    @Override
+    public void startUp() {
+        this.smtpContainer =
+                new GenericContainer<>(DockerImageName.parse(IMAGE))
+                        .withNetwork(NETWORK)
+                        .withNetworkAliases(HOST)
+                        .withExposedPorts(PORT)
+                        .withLogConsumer(
+                                new Slf4jLogConsumer(LoggerFactory.getLogger("email-service")));
+        Startables.deepStart(Stream.of(smtpContainer)).join();
+        log.info("SMTP container started");
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        if (smtpContainer != null) {
+            smtpContainer.stop();
+        }
+    }
+
+    @TestTemplate
+    public void testEmailSink(TestContainer container) throws IOException, InterruptedException {
+        Container.ExecResult textWriteResult = container.executeJob("/fake_to_email.conf");
+        Assertions.assertEquals(0, textWriteResult.getExitCode());
+    }
+
+    @TestTemplate
+    @DisabledOnContainer(
+            value = {},
+            type = {EngineType.SPARK, EngineType.FLINK},
+            disabledReason = "Currently SPARK and FLINK do not support multi-table")

Review Comment:
   ```suggestion
       @DisabledOnContainer(
               value = {},
               type = { EngineType.FLINK},
               disabledReason = "Currently FLINK do not support multi-table")
   ```
   Spark support multi table now! #7283 



##########
seatunnel-connectors-v2/connector-email/src/main/java/org/apache/seatunnel/connectors/seatunnel/email/config/EmailConfig.java:
##########
@@ -37,7 +39,7 @@ public class EmailConfig {
     public static final Option<String> EMAIL_AUTHORIZATION_CODE =
             Options.key("email_authorization_code")
                     .stringType()
-                    .noDefaultValue()
+                    .defaultValue(null)

Review Comment:
   `noDefaultValue` means default value is null.



##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-email-e2e/src/test/resources/fake_to_email_test.conf:
##########
@@ -0,0 +1,62 @@
+#
+# 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.
+#
+
+env {

Review Comment:
   This file shoudl be removed? Because we never used.



##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-email-e2e/src/test/java/org/apache/seatunnel/e2e/connector/email/EmailWithMultiIT.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.e2e.connector.email;
+
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.EngineType;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.stream.Stream;
+
+@Slf4j
+public class EmailWithMultiIT extends TestSuiteBase implements TestResource {
+    private static final String IMAGE = "greenmail/standalone";
+    private static final String HOST = "email-e2e";
+    private static final int PORT = 3025;
+
+    private GenericContainer<?> smtpContainer;
+
+    @BeforeAll
+    @Override
+    public void startUp() {
+        this.smtpContainer =
+                new GenericContainer<>(DockerImageName.parse(IMAGE))
+                        .withNetwork(NETWORK)
+                        .withNetworkAliases(HOST)
+                        .withExposedPorts(PORT)
+                        .withLogConsumer(
+                                new Slf4jLogConsumer(LoggerFactory.getLogger("email-service")));
+        Startables.deepStart(Stream.of(smtpContainer)).join();
+        log.info("SMTP container started");
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        if (smtpContainer != null) {
+            smtpContainer.stop();
+        }
+    }
+
+    @TestTemplate
+    public void testEmailSink(TestContainer container) throws IOException, InterruptedException {
+        Container.ExecResult textWriteResult = container.executeJob("/fake_to_email.conf");
+        Assertions.assertEquals(0, textWriteResult.getExitCode());
+    }
+
+    @TestTemplate
+    @DisabledOnContainer(
+            value = {},
+            type = {EngineType.SPARK, EngineType.FLINK},
+            disabledReason = "Currently SPARK and FLINK do not support multi-table")
+    public void testMultipleTableEmailSink(TestContainer container)
+            throws IOException, InterruptedException {
+        Container.ExecResult textWriteResult = container.executeJob("/fake_to_multiemailsink.conf");
+        Assertions.assertEquals(0, textWriteResult.getExitCode());

Review Comment:
   Any way to check the email send successed?



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


Re: [PR] [Improve][Connector-V2]Support multi-table sink feature for email [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 merged PR #7368:
URL: https://github.com/apache/seatunnel/pull/7368


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


Re: [PR] [Improve][Connector-V2]Support multi-table sink feature for email [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #7368:
URL: https://github.com/apache/seatunnel/pull/7368#issuecomment-2296223306

   Thanks @corgy-w !


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