This is an automated email from the ASF dual-hosted git repository.

nju_yaho pushed a commit to tag ebay-3.1.0-release-20200701
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit 344edfc30ca3593cf63a5de2b00a032754447357
Author: sanjulian <julian....@hotmail.com>
AuthorDate: Fri Jun 19 16:58:27 2020 +0800

    KYLIN-4587 Send out notification email when triggering cube optimization
---
 .../kylin/job/util/MailNotificationUtil.java       |   1 +
 .../mail_templates/CUBE_OPTIMIZE_TRIGGER.ftl       | 206 +++++++++++++++++++++
 .../org/apache/kylin/rest/service/JobService.java  |  35 ++++
 3 files changed, 242 insertions(+)

diff --git 
a/core-job/src/main/java/org/apache/kylin/job/util/MailNotificationUtil.java 
b/core-job/src/main/java/org/apache/kylin/job/util/MailNotificationUtil.java
index 2335965..234a225 100644
--- a/core-job/src/main/java/org/apache/kylin/job/util/MailNotificationUtil.java
+++ b/core-job/src/main/java/org/apache/kylin/job/util/MailNotificationUtil.java
@@ -32,6 +32,7 @@ public class MailNotificationUtil {
     public static final String JOB_DISCARD = "JOB_DISCARD";
     public static final String JOB_SUCCEED = "JOB_SUCCEED";
     public static final String METADATA_PERSIST_FAIL = "METADATA_PERSIST_FAIL";
+    public static final String CUBE_OPTIMIZE_TRIGGER = "CUBE_OPTIMIZE_TRIGGER";
 
     public static final String NA = "NA";
 
diff --git 
a/core-job/src/main/resources/mail_templates/CUBE_OPTIMIZE_TRIGGER.ftl 
b/core-job/src/main/resources/mail_templates/CUBE_OPTIMIZE_TRIGGER.ftl
new file mode 100644
index 0000000..1687b55
--- /dev/null
+++ b/core-job/src/main/resources/mail_templates/CUBE_OPTIMIZE_TRIGGER.ftl
@@ -0,0 +1,206 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+
+<head>
+    <meta http-equiv="Content-Type" content="Multipart/Alternative; 
charset=UTF-8"/>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+</head>
+<style>
+    html {
+        font-size: 10px;
+    }
+
+    * {
+        box-sizing: border-box;
+    }
+
+    a:hover,
+    a:focus {
+        color: #23527c;
+        text-decoration: underline;
+    }
+
+    a:focus {
+        outline: 5px auto -webkit-focus-ring-color;
+        outline-offset: -2px;
+    }
+</style>
+
+<body>
+<div style="font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;">
+<span style="
+line-height: 1;font-size: 16px;">
+<p style="text-align:left;">Dear Kylin user,</p>
+<p>Congratulations! You trigger the optimize cube job.Thank you for using cube 
planner function in Kylin.</p>
+</span>
+    <hr style="margin-top: 10px;
+margin-bottom: 10px;
+height:0px;
+border-top: 1px solid #eee;
+border-right:0px;
+border-bottom:0px;
+border-left:0px;">
+    <span style="display: inline;
+    background-color: #337ab7;
+    color: #fff;
+    line-height: 1;
+    font-weight: 700;
+    font-size:36px;
+    text-align: center;">&nbsp;Info&nbsp;</span>
+    <hr style="margin-top: 10px;
+    margin-bottom: 10px;
+    height:0px;
+    border-top: 1px solid #eee;
+    border-right:0px;
+    border-bottom:0px;
+    border-left:0px;">
+
+    <table cellpadding="0" cellspacing="0" width="100%" 
style="border-collapse: collapse;border:1px solid #bce8f1;">
+
+        <tr>
+
+            <td style="padding: 10px 15px;
+            background-color: #d9edf7;
+            border:1px solid #bce8f1;">
+                <h4 style="margin-top: 0;
+                margin-bottom: 0;
+                font-size: 14px;
+                color: #31708f;
+                font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;">
+                ${job_name}
+                </h4>
+            </td>
+        </tr>
+        <tr>
+
+            <td style="padding: 10px 15px;
+            background-color: #d9edf7;
+            border:1px solid #bce8f1;">
+                <h4 style="margin-top: 0;
+                margin-bottom: 0;
+                font-size: 14px;
+                color: #31708f;
+                font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;">
+                ${env_name}
+                </h4>
+            </td>
+        </tr>
+        <tr>
+
+            <td style="padding: 15px;">
+                <table cellpadding="0" cellspacing="0" width="100%"
+                       style="margin-bottom: 20px;border:1 solid 
#ddd;border-collapse: collapse;font-family: 'Trebuchet MS ', Arial, Helvetica, 
sans-serif;">
+                    <tr>
+                        <th width="30%" style="border: 1px solid #ddd;
+                    padding: 8px;">
+                            <h4 style="
+                                        margin-top: 0;
+                                        margin-bottom: 0;
+                                        line-height: 1.5;
+                                        text-align: left;
+                                        font-size: 14px;
+                                        font-style: normal;">Submitter</h4>
+                        </th>
+                        <td style="border: 1px solid #ddd;
+                padding: 8px;">
+                            <h4 style="margin-top: 0;
+                        margin-bottom: 0;
+                        line-height: 1.5;
+                        text-align: left;
+                        font-size: 14px;
+                        font-style: normal;
+                        font-weight: 300;">
+                            ${submitter}
+                        </td>
+                    </tr>
+                    <tr>
+                        <th width="30%" style="border: 1px solid #ddd;
+                    padding: 8px;">
+                            <h4 style="
+                                        margin-top: 0;
+                                        margin-bottom: 0;
+                                        line-height: 1.5;
+                                        text-align: left;
+                                        font-size: 14px;
+                                        font-style: normal;">Job Engine</h4>
+                        </th>
+                        <td style="border: 1px solid #ddd;
+                padding: 8px;">
+                            <h4 style="margin-top: 0;
+                        margin-bottom: 0;
+                        line-height: 1.5;
+                        text-align: left;
+                        font-size: 14px;
+                        font-style: normal;
+                        font-weight: 300;">
+                            ${job_engine}
+                        </td>
+                    </tr>
+                    <tr>
+                        <th width="30%" style="border: 1px solid #ddd;
+                    padding: 8px;">
+                            <h4 style="
+                                        margin-top: 0;
+                                        margin-bottom: 0;
+                                        line-height: 1.5;
+                                        text-align: left;
+                                        font-size: 14px;
+                                        font-style: normal;">Project</h4>
+                        </th>
+                        <td style="border: 1px solid #ddd;
+                padding: 8px;">
+                            <h4 style="margin-top: 0;
+                        margin-bottom: 0;
+                        line-height: 1.5;
+                        text-align: left;
+                        font-size: 14px;
+                        font-style: normal;
+                        font-weight: 300;">
+                            ${project_name}
+                        </td>
+                    </tr>
+                    <tr>
+                        <th width="30%" style="border: 1px solid #ddd;
+                    padding: 8px;">
+                            <h4 style="
+                                        margin-top: 0;
+                                        margin-bottom: 0;
+                                        line-height: 1.5;
+                                        text-align: left;
+                                        font-size: 14px;
+                                        font-style: normal;">Cube Name</h4>
+                        </th>
+                        <td style="border: 1px solid #ddd;
+                padding: 8px;">
+                            <h4 style="margin-top: 0;
+                        margin-bottom: 0;
+                        line-height: 1.5;
+                        text-align: left;
+                        font-size: 14px;
+                        font-style: normal;
+                        font-weight: 300;">
+                            ${cube_name}
+                        </td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+    </table>
+    <hr style="margin-top: 20px;
+margin-bottom: 20px;
+height:0px;
+border-top: 1px solid #eee;
+border-right:0px;
+border-bottom:0px;
+border-left:0px;">
+    <h4 style="font-weight: 500;
+    line-height: 1;font-size:16px;">
+        <p>Best Wishes!</p>
+        <p style="margin: 0 0 10px;"><a 
href="mailto:dl-ebay-kylin-c...@ebay.com "
+                                        style="color: #337ab7;text-decoration: 
none;">eBay ADI Kylin Team</a></p>
+    </h4>
+</div>
+</body>
+
+</html>
\ No newline at end of file
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java 
b/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java
index 2f42410..a214c12 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java
@@ -33,10 +33,14 @@ import java.util.TimeZone;
 
 import javax.annotation.Nullable;
 
+import com.google.common.collect.Maps;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.lock.DistributedLock;
+import org.apache.kylin.common.util.MailService;
+import org.apache.kylin.common.util.MailTemplateProvider;
 import org.apache.kylin.common.util.Pair;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.common.zookeeper.KylinServerDiscovery;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
@@ -66,6 +70,7 @@ import org.apache.kylin.job.execution.CheckpointExecutable;
 import org.apache.kylin.job.execution.DefaultChainedExecutable;
 import org.apache.kylin.job.execution.ExecutableState;
 import org.apache.kylin.job.execution.Output;
+import org.apache.kylin.job.util.MailNotificationUtil;
 import org.apache.kylin.metadata.model.SegmentRange;
 import org.apache.kylin.metadata.model.SegmentRange.TSRange;
 import org.apache.kylin.metadata.model.SegmentStatusEnum;
@@ -328,6 +333,12 @@ public class JobService extends BasicService implements 
InitializingBean {
 
             getExecutableManager().addJob(checkpointJob);
 
+            try {
+                sendTriggerOptimizeMail(cube, checkpointJob.getName(), 
checkpointJob.getProjectName(), submitter);
+            } catch (Exception e) {
+                logger.warn("fail to send cube optimization notification 
email");
+            }
+
             return new Pair(getCheckpointJobInstance(checkpointJob), 
optimizeJobInstances);
         } catch (Exception e) {
             if (optimizeSegments != null) {
@@ -345,6 +356,30 @@ public class JobService extends BasicService implements 
InitializingBean {
         }
     }
 
+    private void sendTriggerOptimizeMail(CubeInstance cube, String jobName, 
String projectName, String submitter) {
+        KylinConfig config = getConfig();
+        String cubeName = cube.getName();
+        Map<String, Object> dataMap = Maps.newHashMap();
+        dataMap.put("job_name", jobName);
+        dataMap.put("env_name", config.getDeployEnv());
+        dataMap.put("submitter", StringUtil.noBlank(submitter, "missing 
submitter"));
+        dataMap.put("job_engine", MailNotificationUtil.getLocalHostName());
+        dataMap.put("project_name", projectName);
+        dataMap.put("cube_name", cubeName);
+        String content = MailTemplateProvider.getInstance()
+                .buildMailContent(MailNotificationUtil.CUBE_OPTIMIZE_TRIGGER, 
dataMap);
+        String title = MailTemplateProvider.getMailTitle("OPTIMIZE INFO", 
config.getDeployEnv(), projectName, cubeName);
+        List<String> users = Lists.newArrayList();
+        users.addAll(cube.getDescriptor().getNotifyList());
+        final String[] adminDls = config.getAdminDls();
+        if (null != adminDls) {
+            for (String adminDl : adminDls) {
+                users.add(adminDl);
+            }
+        }
+        new MailService(config).sendMail(users, title, content);
+    }
+
     public JobInstance submitRecoverSegmentOptimizeJob(CubeSegment segment, 
String submitter)
             throws IOException, JobException {
         CubeInstance cubeInstance = segment.getCubeInstance();

Reply via email to