KYLIN-2909 refactor to host templates in each modules This closes #91
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/74e3f614 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/74e3f614 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/74e3f614 Branch: refs/heads/master Commit: 74e3f614d6a9cc2807865b8fb210836880b8da85 Parents: c96e1b1 Author: lidongsjtu <lid...@apache.org> Authored: Sun Jan 28 19:02:10 2018 +0800 Committer: lidongsjtu <lid...@apache.org> Committed: Sun Jan 28 19:42:26 2018 +0800 ---------------------------------------------------------------------- core-common/pom.xml | 30 +- .../kylin/common/util/EmailTemplateEnum.java | 49 --- .../kylin/common/util/EmailTemplateFactory.java | 93 ----- .../kylin/common/util/MailTemplateProvider.java | 77 ++++ .../main/resources/templates/JOB_DISCARD.ftl | 275 -------------- .../src/main/resources/templates/JOB_ERROR.ftl | 372 ------------------- .../main/resources/templates/JOB_SUCCEED.ftl | 274 -------------- .../templates/METADATA_PERSIST_FAIL.ftl | 179 --------- .../common/util/EmailTemplateFactoryTest.java | 32 -- .../kylin/job/execution/AbstractExecutable.java | 10 +- .../kylin/job/util/ExecutableStateUtil.java | 38 -- .../kylin/job/util/MailNotificationUtil.java | 81 ++++ .../resources/mail_templates/JOB_DISCARD.ftl | 275 ++++++++++++++ .../main/resources/mail_templates/JOB_ERROR.ftl | 372 +++++++++++++++++++ .../resources/mail_templates/JOB_SUCCEED.ftl | 274 ++++++++++++++ .../mail_templates/METADATA_PERSIST_FAIL.ftl | 179 +++++++++ .../job/util/MailNotificationUtilTest.java | 65 ++++ .../org/apache/kylin/engine/mr/CubingJob.java | 22 +- 18 files changed, 1337 insertions(+), 1360 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/pom.xml ---------------------------------------------------------------------- diff --git a/core-common/pom.xml b/core-common/pom.xml index 47d16f0..4d12a47 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -64,7 +64,7 @@ <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> </dependency> - + <!-- Metric & Tracing --> <dependency> <groupId>org.apache.kylin</groupId> @@ -77,7 +77,7 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> - + <dependency> <groupId>io.dropwizard.metrics</groupId> <artifactId>metrics-jvm</artifactId> @@ -96,30 +96,4 @@ <version>0.1.2</version> </dependency> </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <executions> - <execution> - <id>copy-templates</id> - <phase>process-sources</phase> - <goals> - <goal>copy-resources</goal> - </goals> - <configuration> - <outputDirectory>${basedir}/target/classes/templates</outputDirectory> - <resources> - <resource> - <directory>${basedir}/src/main/resources/templates</directory> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> </project> http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateEnum.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateEnum.java b/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateEnum.java deleted file mode 100644 index 699aa7a..0000000 --- a/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateEnum.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.kylin.common.util; - -import com.google.common.base.Strings; - -public enum EmailTemplateEnum { - JOB_DISCARD("JOB_DISCARD"), JOB_ERROR("JOB_ERROR"), JOB_SUCCEED("JOB_SUCCEED"), // - METADATA_PERSIST_FAIL("METADATA_PERSIST_FAIL"); - - private final String templateName; - - EmailTemplateEnum(String name) { - this.templateName = name; - } - - public static EmailTemplateEnum getByName(String name) { - if (Strings.isNullOrEmpty(name)) { - return null; - } - for (EmailTemplateEnum value : EmailTemplateEnum.values()) { - if (value.templateName.equalsIgnoreCase(name)) { - return value; - } - } - return null; - } - - @Override - public String toString() { - return templateName; - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateFactory.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateFactory.java b/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateFactory.java deleted file mode 100644 index 2acea5d..0000000 --- a/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateFactory.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.kylin.common.util; - -import java.io.StringWriter; -import java.io.Writer; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Joiner; - -import freemarker.template.Configuration; -import freemarker.template.Template; - -public class EmailTemplateFactory { - - private static final Logger logger = LoggerFactory.getLogger(EmailTemplateFactory.class); - - public static final String NA = "NA"; - - private static String localHostName; - static { - try { - localHostName = InetAddress.getLocalHost().getCanonicalHostName(); - } catch (UnknownHostException e) { - localHostName = "UNKNOWN"; - } - } - - public static String getLocalHostName() { - return localHostName; - } - - public static String getEmailTitle(String... titleParts) { - return "[" + Joiner.on("]-[").join(titleParts).toString() + "]"; - } - - private static EmailTemplateFactory instance = new EmailTemplateFactory(); - - public static EmailTemplateFactory getInstance() { - return instance; - } - - private final Configuration configuration; - - private EmailTemplateFactory() { - configuration = new Configuration(Configuration.getVersion()); - configuration.setClassForTemplateLoading(EmailTemplateFactory.class, "/templates"); - configuration.setDefaultEncoding("UTF-8"); - } - - public String buildEmailContent(EmailTemplateEnum state, Map<String, Object> root) { - try { - Template template = getTemplate(state); - if (template == null) { - return "Cannot find email template for " + state; - } - try (Writer out = new StringWriter()) { - template.process(root, out); - return out.toString(); - } - } catch (Throwable e) { - return e.getLocalizedMessage(); - } - } - - private Template getTemplate(EmailTemplateEnum state) throws Throwable { - if (state == null) { - return null; - } - return configuration.getTemplate(state.toString() + ".ftl"); - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/java/org/apache/kylin/common/util/MailTemplateProvider.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/util/MailTemplateProvider.java b/core-common/src/main/java/org/apache/kylin/common/util/MailTemplateProvider.java new file mode 100644 index 0000000..d403fbc --- /dev/null +++ b/core-common/src/main/java/org/apache/kylin/common/util/MailTemplateProvider.java @@ -0,0 +1,77 @@ +/* + * 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.kylin.common.util; + +import java.io.StringWriter; +import java.io.Writer; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import freemarker.template.Configuration; +import freemarker.template.Template; + +/** + * Use a key to find a template for email. + * + * The template file is [KEY].ftl file under /mail_templates directory with classloader. + */ +public class MailTemplateProvider { + + private static final Logger logger = LoggerFactory.getLogger(MailTemplateProvider.class); + + private static MailTemplateProvider DEFAULT_INSTANCE = new MailTemplateProvider(); + + public static MailTemplateProvider getInstance() { + return DEFAULT_INSTANCE; + } + + private final Configuration configuration; + + private MailTemplateProvider() { + configuration = new Configuration(Configuration.getVersion()); + configuration.setClassForTemplateLoading(MailTemplateProvider.class, "/mail_templates"); + configuration.setDefaultEncoding("UTF-8"); + } + + public String buildMailContent(String tplKey, Map<String, Object> data) { + try { + Template template = getTemplate(tplKey); + if (template == null) { + return "Cannot find email template for " + tplKey; + } + + try (Writer out = new StringWriter()) { + template.process(data, out); + return out.toString(); + } + } catch (Throwable e) { + return e.getLocalizedMessage(); + } + } + + private Template getTemplate(String tplKey) throws Throwable { + if (StringUtils.isEmpty(tplKey)) { + return null; + } + return configuration.getTemplate(tplKey + ".ftl"); + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/resources/templates/JOB_DISCARD.ftl ---------------------------------------------------------------------- diff --git a/core-common/src/main/resources/templates/JOB_DISCARD.ftl b/core-common/src/main/resources/templates/JOB_DISCARD.ftl deleted file mode 100644 index b00e9aa..0000000 --- a/core-common/src/main/resources/templates/JOB_DISCARD.ftl +++ /dev/null @@ -1,275 +0,0 @@ -<!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="margin-left:5%;margin-right:5%;font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> -<span style=" - line-height: 1.1;font-size: 18px;"> - <p style="text-align:left;">Dear Kylin user,</p> - <p>It's a pity that the job is discarded. Thank you for using Kylin.</p> -</span> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h1> - <span style="display: inline; - background-color: #607D8B; - color: #fff; - line-height: 1; - font-weight: 700; - font-size:36px; - text-align: center;"> Discarded </span> - </h1> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <table cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;border:1px solid #f8f8f8"> - - <tr> - - <td style="padding: 10px 15px; - background-color: #eeeeee; - border:1px solid #f8f8f8;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #404040; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - ${job_name} - </h4> - </td> - </tr> - - <tr> - - <td style="padding: 10px 15px; - background-color: #eeeeee; - border:1px solid #f8f8f8;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #404040; - 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="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Submitter - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${submitter} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Job Engine - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${job_engine} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Project - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${project_name} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Cube Name - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${cube_name} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Source Records Count - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${source_records_count} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Start Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${start_time} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Duration - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${duration} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">MR Waiting Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${mr_waiting} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Last Update Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${last_update_time} - </td> - </tr> - </table> - </td> - </tr> - </table> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h4 style="font-weight: 500; - line-height: 1.1;font-size:18px;"> - <p>Best Wishes!</p> - <p style="margin: 0 0 10px;"><b>Kylin Team</b></p> - </h4> -</div> -</body> - -</html>Ã \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/resources/templates/JOB_ERROR.ftl ---------------------------------------------------------------------- diff --git a/core-common/src/main/resources/templates/JOB_ERROR.ftl b/core-common/src/main/resources/templates/JOB_ERROR.ftl deleted file mode 100644 index 6012037..0000000 --- a/core-common/src/main/resources/templates/JOB_ERROR.ftl +++ /dev/null @@ -1,372 +0,0 @@ -<!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="margin-left:5%;margin-right:5%;font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> -<span style=" - line-height: 1.1;font-size: 18px;"> - <p style="text-align:left;">Dear Kylin user,</p> - <p>This cube <strong>failure</strong> may be caused by backend platform being busy, please try again.</p> - <p>Thank you for using Kylin and we apologize for the inconvenience.</p> -</span> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h1> - <span style="display: inline; - background-color: #d9534f; - color: #fff; - line-height: 1; - font-weight: 700; - font-size:36px; - text-align: center;"> Error </span> - </h1> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - - <table cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;border:1px solid #ebccd1;"> - - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - ${job_name} - </h4> - </td> - </tr> - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - 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="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Submitter - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${submitter} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Job Engine - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${job_engine} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Project - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${project_name} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Cube Name - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${cube_name} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Source Records Count - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${source_records_count} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Start Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${start_time} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Duration - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${duration} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">MR Waiting Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${mr_waiting} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Last Update Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${last_update_time} - </td> - </tr> - </table> - </td> - </tr> - - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - Job Error Details - </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="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Error Step - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${error_step} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - MR Job - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${mr_job_id} - </td> - </tr> - </table> - </td> - </tr> - - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - Logs - </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> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - - <pre style="white-space: pre-wrap;">${error_log}</pre> - </td> - </tr> - </table> - </td> - </tr> - </table> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h4 style="font-weight: 500; - line-height: 1.1;font-size:18px;"> - <p>Best Wishes!</p> - <p style="margin: 0 0 10px;"><b>Kylin Team</b></p> - </h4> -</div> -</body> - -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/resources/templates/JOB_SUCCEED.ftl ---------------------------------------------------------------------- diff --git a/core-common/src/main/resources/templates/JOB_SUCCEED.ftl b/core-common/src/main/resources/templates/JOB_SUCCEED.ftl deleted file mode 100644 index f1fb45c..0000000 --- a/core-common/src/main/resources/templates/JOB_SUCCEED.ftl +++ /dev/null @@ -1,274 +0,0 @@ -<!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="margin-left:5%;margin-right:5%;font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> -<span style="line-height: 1.1;font-size: 18px;"> - <p style="text-align:left;">Dear Kylin user,</p> - <p>Congratulations! Please feel free to query based on kylin cube. Thank you for using Kylin.</p> -</span> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h1> - <span style="display: inline; - background-color: #5cb85c; - color: #fff; - line-height: 1; - font-weight: 700; - font-size:36px; - text-align: center;"> Succeed </span> - </h1> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <table cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;border:1px solid #d6e9c6;"> - - <tr> - - <td style="padding: 10px 15px; - background-color: #dff0d8; - border:1px solid #d6e9c6;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #3c763d; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - ${job_name} - </h4> - </td> - </tr> - - <tr> - - <td style="padding: 10px 15px; - background-color: #dff0d8; - border:1px solid #d6e9c6;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #3c763d; - 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="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Submitter - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${submitter} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Job Engine - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${job_engine} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Project - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${project_name} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Cube Name - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${cube_name} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Source Records Count - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${source_records_count} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Start Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${start_time} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Duration - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${duration} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">MR Waiting Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${mr_waiting} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;"> - Last Update Time - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${last_update_time} - </td> - </tr> - </table> - </td> - </tr> - </table> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h4 style="font-weight: 500; - line-height: 1.1;font-size:18px;"> - <p>Best Wishes!</p> - <p style="margin: 0 0 10px;"><b>Kylin Team</b></p> - </h4> -</div> -</body> - -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/main/resources/templates/METADATA_PERSIST_FAIL.ftl ---------------------------------------------------------------------- diff --git a/core-common/src/main/resources/templates/METADATA_PERSIST_FAIL.ftl b/core-common/src/main/resources/templates/METADATA_PERSIST_FAIL.ftl deleted file mode 100644 index 2511b57..0000000 --- a/core-common/src/main/resources/templates/METADATA_PERSIST_FAIL.ftl +++ /dev/null @@ -1,179 +0,0 @@ -<!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="margin-left:5%;margin-right:5%;font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - <span style="line-height: 1.1;font-size: 18px;"> - <p style="text-align:left;">Dear Kylin user,</p> - <p>Kylin fails to update the job output due to some hbase issue. Need to ask Hadoop Service Team for help as soon as possible.</p> -</span> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h1> - <span style="display: inline; - background-color: #d9534f; - color: #fff; - line-height: 1; - font-weight: 700; - font-size:36px; - text-align: center;"> Error </span> - </h1> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <table cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;border:1px solid #ebccd1;"> - - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - ${job_name} - </h4> - </td> - </tr> - - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - 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="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Submitter - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${submitter} - </td> - </tr> - <tr> - <th width="30%" style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - text-align: left; - font-size: medium; - font-style: normal;">Job Engine - </th> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - ${job_engine} - </td> - </tr> - </table> - </td> - </tr> - - <tr> - - <td style="padding: 10px 15px; - background-color: #f2dede; - border:1px solid #ebccd1;"> - <h4 style="margin-top: 0; - margin-bottom: 0; - font-size: 16px; - color: inherit; - color: #a94442; - font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> - Logs - </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> - <td style="padding: 8px; - line-height: 1.42857143; - vertical-align: top; - border: 1px solid #ddd; - font-size: medium; - font-style: normal;"> - <pre style="white-space: pre-wrap;">${error_log}</pre> - </td> - </tr> - </table> - </td> - </tr> - </table> - <hr style="margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee;"> - <h4 style="font-weight: 500; - line-height: 1.1;font-size:18px;"> - <p>Best Wishes!</p> - <p style="margin: 0 0 10px;"><b>Kylin Team</b></p> - </h4> -</div> -</body> - -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-common/src/test/java/org/apache/kylin/common/util/EmailTemplateFactoryTest.java ---------------------------------------------------------------------- diff --git a/core-common/src/test/java/org/apache/kylin/common/util/EmailTemplateFactoryTest.java b/core-common/src/test/java/org/apache/kylin/common/util/EmailTemplateFactoryTest.java deleted file mode 100644 index 6acbd75..0000000 --- a/core-common/src/test/java/org/apache/kylin/common/util/EmailTemplateFactoryTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.kylin.common.util; - -import org.junit.Assert; -import org.junit.Test; - -public class EmailTemplateFactoryTest { - - @Test - public void testGetEmailTitle() { - String[] titleParts = new String[] { "JOB", "SUCCEED" }; - Assert.assertEquals("[" + titleParts[0] + "]-[" + titleParts[1] + "]", - EmailTemplateFactory.getEmailTitle(titleParts)); - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java ---------------------------------------------------------------------- diff --git a/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java b/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java index f4015bf..1a84871 100644 --- a/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java +++ b/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java @@ -29,14 +29,13 @@ import java.util.regex.Matcher; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.kylin.common.KylinConfig; -import org.apache.kylin.common.util.EmailTemplateEnum; -import org.apache.kylin.common.util.EmailTemplateFactory; import org.apache.kylin.common.util.MailService; import org.apache.kylin.common.util.Pair; import org.apache.kylin.common.util.StringUtil; import org.apache.kylin.job.exception.ExecuteException; import org.apache.kylin.job.exception.PersistentException; import org.apache.kylin.job.impl.threadpool.DefaultContext; +import org.apache.kylin.job.util.MailNotificationUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -194,13 +193,12 @@ public abstract class AbstractExecutable implements Executable, Idempotent { dataMap.put("job_name", getName()); dataMap.put("env_name", context.getConfig().getDeployEnv()); dataMap.put("submitter", StringUtil.noBlank(getSubmitter(), "missing submitter")); - dataMap.put("job_engine", EmailTemplateFactory.getLocalHostName()); + dataMap.put("job_engine", MailNotificationUtil.getLocalHostName()); dataMap.put("error_log", Matcher.quoteReplacement(StringUtil.noBlank(exception.getMessage(), "no error message"))); - String content = EmailTemplateFactory.getInstance().buildEmailContent(EmailTemplateEnum.METADATA_PERSIST_FAIL, - dataMap); - String title = EmailTemplateFactory.getEmailTitle("METADATA PERSIST", "FAIL", + String content = MailNotificationUtil.getMailContent(MailNotificationUtil.METADATA_PERSIST_FAIL, dataMap); + String title = MailNotificationUtil.getMailTitle("METADATA PERSIST", "FAIL", context.getConfig().getDeployEnv()); new MailService(context.getConfig()).sendMail(users, title, content); http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-job/src/main/java/org/apache/kylin/job/util/ExecutableStateUtil.java ---------------------------------------------------------------------- diff --git a/core-job/src/main/java/org/apache/kylin/job/util/ExecutableStateUtil.java b/core-job/src/main/java/org/apache/kylin/job/util/ExecutableStateUtil.java deleted file mode 100644 index 66f806c..0000000 --- a/core-job/src/main/java/org/apache/kylin/job/util/ExecutableStateUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.kylin.job.util; - -import org.apache.kylin.common.util.EmailTemplateEnum; -import org.apache.kylin.job.execution.ExecutableState; - -public class ExecutableStateUtil { - - public static EmailTemplateEnum getEmailTemplateEnum(ExecutableState state) { - switch (state) { - case ERROR: - return EmailTemplateEnum.JOB_ERROR; - case DISCARDED: - return EmailTemplateEnum.JOB_DISCARD; - case SUCCEED: - return EmailTemplateEnum.JOB_SUCCEED; - default: - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-job/src/main/java/org/apache/kylin/job/util/MailNotificationUtil.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..31c5b20 --- /dev/null +++ b/core-job/src/main/java/org/apache/kylin/job/util/MailNotificationUtil.java @@ -0,0 +1,81 @@ +/* + * 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.kylin.job.util; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Map; + +import org.apache.kylin.common.util.MailTemplateProvider; +import org.apache.kylin.job.execution.ExecutableState; + +import com.google.common.base.Joiner; + +public class MailNotificationUtil { + public static final String JOB_ERROR = "JOB_ERROR"; + 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 NA = "NA"; + + private static String localHostName; + + static { + try { + localHostName = InetAddress.getLocalHost().getCanonicalHostName(); + } catch (UnknownHostException e) { + localHostName = "UNKNOWN"; + } + } + + private static String getMailTemplateKey(ExecutableState state) { + switch (state) { + case ERROR: + return JOB_ERROR; + case DISCARDED: + return JOB_DISCARD; + case SUCCEED: + return JOB_SUCCEED; + default: + return null; + } + } + + public static String getLocalHostName() { + return localHostName; + } + + public static String getMailContent(ExecutableState state, Map<String, Object> dataMap) { + return MailTemplateProvider.getInstance().buildMailContent(MailNotificationUtil.getMailTemplateKey(state), + dataMap); + } + + public static String getMailContent(String key, Map<String, Object> dataMap) { + return MailTemplateProvider.getInstance().buildMailContent(key, dataMap); + } + + public static String getMailTitle(String... titleParts) { + return "[" + Joiner.on("]-[").join(titleParts) + "]"; + } + + public static boolean hasMailNotification(ExecutableState state) { + return getMailTemplateKey(state) != null; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-job/src/main/resources/mail_templates/JOB_DISCARD.ftl ---------------------------------------------------------------------- diff --git a/core-job/src/main/resources/mail_templates/JOB_DISCARD.ftl b/core-job/src/main/resources/mail_templates/JOB_DISCARD.ftl new file mode 100644 index 0000000..9712982 --- /dev/null +++ b/core-job/src/main/resources/mail_templates/JOB_DISCARD.ftl @@ -0,0 +1,275 @@ +<!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="margin-left:5%;margin-right:5%;font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> +<span style=" + line-height: 1.1;font-size: 18px;"> + <p style="text-align:left;">Dear Kylin user,</p> + <p>It's a pity that the job is discarded. Thank you for using Kylin.</p> +</span> + <hr style="margin-top: 20px; + margin-bottom: 20px; + border: 0; + border-top: 1px solid #eee;"> + <h1> + <span style="display: inline; + background-color: #607D8B; + color: #fff; + line-height: 1; + font-weight: 700; + font-size:36px; + text-align: center;"> Discarded </span> + </h1> + <hr style="margin-top: 20px; + margin-bottom: 20px; + border: 0; + border-top: 1px solid #eee;"> + <table cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;border:1px solid #f8f8f8"> + + <tr> + + <td style="padding: 10px 15px; + background-color: #eeeeee; + border:1px solid #f8f8f8;"> + <h4 style="margin-top: 0; + margin-bottom: 0; + font-size: 16px; + color: inherit; + color: #404040; + font-family: 'Trebuchet MS ', Arial, Helvetica, sans-serif;"> + ${job_name} + </h4> + </td> + </tr> + + <tr> + + <td style="padding: 10px 15px; + background-color: #eeeeee; + border:1px solid #f8f8f8;"> + <h4 style="margin-top: 0; + margin-bottom: 0; + font-size: 16px; + color: inherit; + color: #404040; + 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="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;">Submitter + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${submitter} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;">Job Engine + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${job_engine} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;">Project + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${project_name} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;">Cube Name + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${cube_name} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;"> + Source Records Count + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${source_records_count} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;">Start Time + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${start_time} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;"> + Duration + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${duration} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;">MR Waiting Time + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${mr_waiting} + </td> + </tr> + <tr> + <th width="30%" style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + text-align: left; + font-size: medium; + font-style: normal;"> + Last Update Time + </th> + <td style="padding: 8px; + line-height: 1.42857143; + vertical-align: top; + border: 1px solid #ddd; + font-size: medium; + font-style: normal;"> + ${last_update_time} + </td> + </tr> + </table> + </td> + </tr> + </table> + <hr style="margin-top: 20px; + margin-bottom: 20px; + border: 0; + border-top: 1px solid #eee;"> + <h4 style="font-weight: 500; + line-height: 1.1;font-size:18px;"> + <p>Best Wishes!</p> + <p style="margin: 0 0 10px;"><b>Kylin Team</b></p> + </h4> +</div> +</body> + +</html> \ No newline at end of file