You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2018/01/28 11:57:49 UTC
[1/6] kylin git commit: KYLIN-2909 add freemarker based
EmailTemplateFactory & templates for notification emails
Repository: kylin
Updated Branches:
refs/heads/master 8e2744925 -> 5eedd135d
KYLIN-2909 add freemarker based EmailTemplateFactory & templates for notification emails
Signed-off-by: Zhong <nj...@apache.org>
Signed-off-by: lidongsjtu <li...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/7dc18758
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/7dc18758
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/7dc18758
Branch: refs/heads/master
Commit: 7dc1875831d225d9968e587599ee274d8d1a93f8
Parents: 8e27449
Author: Zhang Xueyu <co...@mail.ustc.edu.cn>
Authored: Sat Sep 30 13:13:33 2017 +0800
Committer: lidongsjtu <li...@apache.org>
Committed: Fri Jan 26 23:09:01 2018 +0800
----------------------------------------------------------------------
core-common/pom.xml | 30 ++
.../kylin/common/util/EmailTemplateEnum.java | 49 +++
.../kylin/common/util/EmailTemplateFactory.java | 98 +++++
.../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 +++++++++
pom.xml | 6 +
8 files changed, 1283 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/7dc18758/core-common/pom.xml
----------------------------------------------------------------------
diff --git a/core-common/pom.xml b/core-common/pom.xml
index 22733b4..47d16f0 100644
--- a/core-common/pom.xml
+++ b/core-common/pom.xml
@@ -50,6 +50,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.freemarker</groupId>
+ <artifactId>freemarker</artifactId>
+ </dependency>
<!-- Provided -->
<dependency>
@@ -92,4 +96,30 @@
<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/7dc18758/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
new file mode 100644
index 0000000..699aa7a
--- /dev/null
+++ b/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateEnum.java
@@ -0,0 +1,49 @@
+/*
+ * 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/7dc18758/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
new file mode 100644
index 0000000..fcf554d
--- /dev/null
+++ b/core-common/src/main/java/org/apache/kylin/common/util/EmailTemplateFactory.java
@@ -0,0 +1,98 @@
+/*
+ * 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 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) {
+ StringBuilder sb = new StringBuilder();
+ for (String part : titleParts) {
+ if (sb.length() > 0) {
+ sb.append("-");
+ }
+ sb.append("[" + part + "]");
+ }
+ return sb.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/7dc18758/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
new file mode 100644
index 0000000..fbef3f7
--- /dev/null
+++ b/core-common/src/main/resources/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
http://git-wip-us.apache.org/repos/asf/kylin/blob/7dc18758/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
new file mode 100644
index 0000000..6012037
--- /dev/null
+++ b/core-common/src/main/resources/templates/JOB_ERROR.ftl
@@ -0,0 +1,372 @@
+<!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/7dc18758/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
new file mode 100644
index 0000000..4b443d5
--- /dev/null
+++ b/core-common/src/main/resources/templates/JOB_SUCCEED.ftl
@@ -0,0 +1,274 @@
+<!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/7dc18758/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
new file mode 100644
index 0000000..2511b57
--- /dev/null
+++ b/core-common/src/main/resources/templates/METADATA_PERSIST_FAIL.ftl
@@ -0,0 +1,179 @@
+<!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/7dc18758/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index be2d2bf..dd592bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -115,6 +115,7 @@
<cors.version>2.5</cors.version>
<tomcat.version>7.0.82</tomcat.version>
<t-digest.version>3.1</t-digest.version>
+ <freemarker.version>2.3.23</freemarker.version>
<!--metric-->
<dropwizard.version>3.1.2</dropwizard.version>
<!-- REST Service, ref https://github.com/spring-projects/spring-boot/blob/v1.3.8.RELEASE/spring-boot-dependencies/pom.xml -->
@@ -651,6 +652,11 @@
<artifactId>commons-validator</artifactId>
<version>${commons-validator.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.freemarker</groupId>
+ <artifactId>freemarker</artifactId>
+ <version>${freemarker.version}</version>
+ </dependency>
<!-- Logging -->
<dependency>
[4/6] kylin git commit: KYLIN-2909 refactor to host templates in each
modules
Posted by li...@apache.org.
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 <li...@apache.org>
Authored: Sun Jan 28 19:02:10 2018 +0800
Committer: lidongsjtu <li...@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
[6/6] kylin git commit: minor, stablize
org.apache.kylin.dict.TrieDictionaryForestTest#englishWordsTest
Posted by li...@apache.org.
minor, stablize org.apache.kylin.dict.TrieDictionaryForestTest#englishWordsTest
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5eedd135
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5eedd135
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5eedd135
Branch: refs/heads/master
Commit: 5eedd135d27da96c2242079fd9e188fce0518f90
Parents: 9198cfe
Author: lidongsjtu <li...@apache.org>
Authored: Sun Jan 28 19:55:07 2018 +0800
Committer: lidongsjtu <li...@apache.org>
Committed: Sun Jan 28 19:55:07 2018 +0800
----------------------------------------------------------------------
.../kylin/dict/TrieDictionaryForestTest.java | 28 ++++++++++++++------
1 file changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/5eedd135/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java b/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
index 099075c..1f63111 100644
--- a/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
+++ b/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
@@ -43,6 +43,7 @@ import java.util.NoSuchElementException;
import java.util.Random;
import java.util.TreeSet;
+import org.apache.kylin.common.util.Bytes;
import org.junit.Ignore;
import org.junit.Test;
@@ -187,8 +188,14 @@ public class TrieDictionaryForestTest {
str.add("party");
str.add("parties");
str.add("paint");
- String longStr = "paintjkjdfklajkdljfkdsajklfjklsadjkjekjrklewjrklewjklrjklewjkljkljkljkljweklrjewkljrklewjrlkjewkljrkljkljkjlkjjkljkljkljkljlkjlkjlkjljdfadfads" + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk" + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk" + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk" + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk" + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
- + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk" + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk";
+ String longStr = "paintjkjdfklajkdljfkdsajklfjklsadjkjekjrklewjrklewjklrjklewjkljkljkljkljweklrjewkljrklewjrlkjewkljrkljkljkjlkjjkljkljkljkljlkjlkjlkjljdfadfads"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk"
+ + "dddddddddddddddddddddddddddddddddddddddddddddddddkfjadslkfjdsakljflksadjklfjklsjfkljwelkrjewkljrklewjklrjelkwjrklewjrlkjwkljerklkljlkjrlkwejrk";
System.out.println("The length of the long string is " + longStr.length());
str.add(longStr);
@@ -740,7 +747,8 @@ public class TrieDictionaryForestTest {
System.out.println("times:" + i);
}
- System.out.println("compare build time. Old trie : " + oldDictTotalBuildTime / 1000.0 + "s.New trie : " + newDictTotalBuildTime / 1000.0 + "s");
+ System.out.println("compare build time. Old trie : " + oldDictTotalBuildTime / 1000.0 + "s.New trie : "
+ + newDictTotalBuildTime / 1000.0 + "s");
}
private void evaluateDataSize(ArrayList<String> list) {
@@ -806,7 +814,8 @@ public class TrieDictionaryForestTest {
benchmark("Benchmark", dict, set, map, strArray, array);
}
- private static int benchmark(String msg, TrieDictionaryForest<String> dict, TreeSet<String> set, HashMap<String, Integer> map, String[] strArray, byte[][] array) {
+ private static int benchmark(String msg, TrieDictionaryForest<String> dict, TreeSet<String> set,
+ HashMap<String, Integer> map, String[] strArray, byte[][] array) {
int n = set.size();
int times = Math.max(10 * 1000 * 1000 / n, 1); // run 10 million lookups
int keep = 0; // make sure JIT don't OPT OUT function calls under test
@@ -889,7 +898,7 @@ public class TrieDictionaryForestTest {
assertEquals(id, dict.getIdFromValue(value));
assertEquals(value, dict.getValueFromId(id));
- assertArrayEquals(value.getBytes(), dict.getValueByteFromId(id));
+ assertArrayEquals(Bytes.toBytes(value), dict.getValueByteFromId(id));
}
//test not found value
@@ -932,14 +941,16 @@ public class TrieDictionaryForestTest {
}
public static TrieDictionaryForestBuilder<String> newDictBuilder(Iterable<String> strs, int baseId) {
- TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter(), baseId);
+ TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter(),
+ baseId);
for (String s : strs)
b.addValue(s);
return b;
}
public static TrieDictionaryForestBuilder<String> newDictBuilder(Iterable<String> strs, int baseId, int treeSize) {
- TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter(), baseId);
+ TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter(),
+ baseId);
b.setMaxTrieTreeSize(treeSize);
for (String s : strs) {
b.addValue(s);
@@ -948,7 +959,8 @@ public class TrieDictionaryForestTest {
}
public static TrieDictionaryForestBuilder<String> newDictBuilder(Iterator<String> strs, int baseId, int treeSize) {
- TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter(), baseId);
+ TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter(),
+ baseId);
b.setMaxTrieTreeSize(treeSize);
while (strs.hasNext())
b.addValue(strs.next());
[3/6] kylin git commit: KYLIN-2909 refactor to host templates in each
modules
Posted by li...@apache.org.
http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/core-job/src/main/resources/mail_templates/JOB_ERROR.ftl
----------------------------------------------------------------------
diff --git a/core-job/src/main/resources/mail_templates/JOB_ERROR.ftl b/core-job/src/main/resources/mail_templates/JOB_ERROR.ftl
new file mode 100644
index 0000000..6012037
--- /dev/null
+++ b/core-job/src/main/resources/mail_templates/JOB_ERROR.ftl
@@ -0,0 +1,372 @@
+<!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-job/src/main/resources/mail_templates/JOB_SUCCEED.ftl
----------------------------------------------------------------------
diff --git a/core-job/src/main/resources/mail_templates/JOB_SUCCEED.ftl b/core-job/src/main/resources/mail_templates/JOB_SUCCEED.ftl
new file mode 100644
index 0000000..f1fb45c
--- /dev/null
+++ b/core-job/src/main/resources/mail_templates/JOB_SUCCEED.ftl
@@ -0,0 +1,274 @@
+<!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-job/src/main/resources/mail_templates/METADATA_PERSIST_FAIL.ftl
----------------------------------------------------------------------
diff --git a/core-job/src/main/resources/mail_templates/METADATA_PERSIST_FAIL.ftl b/core-job/src/main/resources/mail_templates/METADATA_PERSIST_FAIL.ftl
new file mode 100644
index 0000000..2511b57
--- /dev/null
+++ b/core-job/src/main/resources/mail_templates/METADATA_PERSIST_FAIL.ftl
@@ -0,0 +1,179 @@
+<!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-job/src/test/java/org/apache/kylin/job/util/MailNotificationUtilTest.java
----------------------------------------------------------------------
diff --git a/core-job/src/test/java/org/apache/kylin/job/util/MailNotificationUtilTest.java b/core-job/src/test/java/org/apache/kylin/job/util/MailNotificationUtilTest.java
new file mode 100644
index 0000000..50627e0
--- /dev/null
+++ b/core-job/src/test/java/org/apache/kylin/job/util/MailNotificationUtilTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.job.execution.ExecutableState;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class MailNotificationUtilTest {
+
+ @Test
+ public void testGetMailTitle() {
+ String[] titleParts = new String[] { "JOB", "SUCCEED" };
+ Assert.assertEquals("[" + titleParts[0] + "]-[" + titleParts[1] + "]",
+ MailNotificationUtil.getMailTitle(titleParts));
+ }
+
+ @Test
+ public void testHasMailNotification() {
+ Assert.assertTrue(MailNotificationUtil.hasMailNotification(ExecutableState.DISCARDED));
+ Assert.assertTrue(MailNotificationUtil.hasMailNotification(ExecutableState.ERROR));
+ Assert.assertTrue(MailNotificationUtil.hasMailNotification(ExecutableState.SUCCEED));
+ Assert.assertFalse(MailNotificationUtil.hasMailNotification(ExecutableState.RUNNING));
+ Assert.assertFalse(MailNotificationUtil.hasMailNotification(ExecutableState.STOPPED));
+ Assert.assertFalse(MailNotificationUtil.hasMailNotification(ExecutableState.READY));
+ }
+
+ @Test
+ public void testGetMailContent() {
+ Assert.assertFalse(
+ MailNotificationUtil.getMailContent(ExecutableState.DISCARDED, Maps.<String, Object>newHashMap())
+ .startsWith("Cannot find email template for"));
+ Assert.assertFalse(MailNotificationUtil.getMailContent(ExecutableState.ERROR, Maps.<String, Object>newHashMap())
+ .startsWith("Cannot find email template for"));
+ Assert.assertFalse(
+ MailNotificationUtil.getMailContent(ExecutableState.SUCCEED, Maps.<String, Object>newHashMap())
+ .startsWith("Cannot find email template for"));
+ Assert.assertTrue(
+ MailNotificationUtil.getMailContent(ExecutableState.RUNNING, Maps.<String, Object>newHashMap())
+ .startsWith("Cannot find email template for"));
+ Assert.assertTrue(
+ MailNotificationUtil.getMailContent(ExecutableState.STOPPED, Maps.<String, Object>newHashMap())
+ .startsWith("Cannot find email template for"));
+ Assert.assertTrue(MailNotificationUtil.getMailContent(ExecutableState.READY, Maps.<String, Object>newHashMap())
+ .startsWith("Cannot find email template for"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/kylin/blob/74e3f614/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
----------------------------------------------------------------------
diff --git a/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java b/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
index 548dcb9..9173dbd 100644
--- a/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
+++ b/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
@@ -27,10 +27,7 @@ import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
-
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.Pair;
import org.apache.kylin.common.util.StringUtil;
import org.apache.kylin.cube.CubeInstance;
@@ -47,7 +44,7 @@ import org.apache.kylin.job.execution.ExecutableState;
import org.apache.kylin.job.execution.ExecuteResult;
import org.apache.kylin.job.execution.Output;
import org.apache.kylin.job.metrics.JobMetricsFacade;
-import org.apache.kylin.job.util.ExecutableStateUtil;
+import org.apache.kylin.job.util.MailNotificationUtil;
import org.apache.kylin.metadata.project.ProjectInstance;
import org.apache.kylin.metadata.project.ProjectManager;
import org.slf4j.Logger;
@@ -205,8 +202,7 @@ public class CubingJob extends DefaultChainedExecutable {
return null;
}
- EmailTemplateEnum templateEnum = ExecutableStateUtil.getEmailTemplateEnum(state);
- if (templateEnum == null) {
+ if (!MailNotificationUtil.hasMailNotification(state)) {
logger.info("Cannot find email template for job state: " + state);
return null;
}
@@ -215,7 +211,7 @@ public class CubingJob extends DefaultChainedExecutable {
dataMap.put("job_name", getName());
dataMap.put("env_name", getDeployEnvName());
dataMap.put("submitter", StringUtil.noBlank(getSubmitter(), "missing submitter"));
- dataMap.put("job_engine", EmailTemplateFactory.getLocalHostName());
+ dataMap.put("job_engine", MailNotificationUtil.getLocalHostName());
dataMap.put("project_name", getProjectName());
dataMap.put("cube_name", cubeInstance.getName());
dataMap.put("source_records_count", String.valueOf(findSourceRecordCount()));
@@ -242,15 +238,14 @@ public class CubingJob extends DefaultChainedExecutable {
final String mrJobId = errorOutput.getExtra().get(ExecutableConstants.MR_JOB_ID);
dataMap.put("mr_job_id", StringUtil.noBlank(mrJobId, "Not initialized"));
} else {
- dataMap.put("mr_job_id", EmailTemplateFactory.NA);
+ dataMap.put("mr_job_id", MailNotificationUtil.NA);
}
dataMap.put("error_log",
Matcher.quoteReplacement(StringUtil.noBlank(output.getVerboseMsg(), "no error message")));
}
- String content = EmailTemplateFactory.getInstance()
- .buildEmailContent(ExecutableStateUtil.getEmailTemplateEnum(state), dataMap);
- String title = EmailTemplateFactory.getEmailTitle("JOB", state.toString(), getDeployEnvName(), getProjectName(),
+ String content = MailNotificationUtil.getMailContent(state, dataMap);
+ String title = MailNotificationUtil.getMailTitle("JOB", state.toString(), getDeployEnvName(), getProjectName(),
cubeInstance.getName());
return Pair.newPair(title, content);
}
@@ -279,9 +274,8 @@ public class CubingJob extends DefaultChainedExecutable {
protected void updateMetrics(ExecutableContext context, ExecuteResult result, ExecutableState state) {
JobMetricsFacade.JobStatisticsResult jobStats = new JobMetricsFacade.JobStatisticsResult();
- jobStats.setWrapper(getSubmitter(), getProjectName(),
- CubingExecutableUtil.getCubeName(getParams()), getId(), getJobType(),
- getAlgorithm() == null ? "NULL" : getAlgorithm().toString());
+ jobStats.setWrapper(getSubmitter(), getProjectName(), CubingExecutableUtil.getCubeName(getParams()), getId(),
+ getJobType(), getAlgorithm() == null ? "NULL" : getAlgorithm().toString());
if (state == ExecutableState.SUCCEED) {
jobStats.setJobStats(findSourceSizeBytes(), findCubeSizeBytes(), getDuration(), getMapReduceWaitTime(),
[5/6] kylin git commit: minor, fix some typos
Posted by li...@apache.org.
minor, fix some typos
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/9198cfe8
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/9198cfe8
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/9198cfe8
Branch: refs/heads/master
Commit: 9198cfe8f1439246eff6abff38b3869453325aca
Parents: 74e3f61
Author: lidongsjtu <li...@apache.org>
Authored: Sun Jan 28 19:43:00 2018 +0800
Committer: lidongsjtu <li...@apache.org>
Committed: Sun Jan 28 19:43:00 2018 +0800
----------------------------------------------------------------------
.../java/org/apache/kylin/source/hive/HiveMetadataExplorer.java | 4 ++--
.../src/main/java/org/apache/kylin/source/jdbc/JdbcExplorer.java | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/9198cfe8/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java
----------------------------------------------------------------------
diff --git a/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java b/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java
index cb3eb02..9d4cc53 100644
--- a/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java
+++ b/source-hive/src/main/java/org/apache/kylin/source/hive/HiveMetadataExplorer.java
@@ -185,7 +185,7 @@ public class HiveMetadataExplorer implements ISourceMetadataExplorer, ISampleDat
@Override
public ColumnDesc[] evalQueryMetadata(String query) {
if (StringUtils.isEmpty(query)) {
- throw new RuntimeException("Evalutate query shall not be empty.");
+ throw new RuntimeException("Evaluate query shall not be empty.");
}
KylinConfig config = KylinConfig.getInstanceFromEnv();
@@ -204,7 +204,7 @@ public class HiveMetadataExplorer implements ISourceMetadataExplorer, ISampleDat
HiveTableMeta hiveTableMeta = hiveClient.getHiveTableMeta(tmpDatabase, tmpView);
return extractColumnFromMeta(hiveTableMeta);
} catch (Exception e) {
- throw new RuntimeException("Cannot evalutate metadata of query: " + query, e);
+ throw new RuntimeException("Cannot evaluate metadata of query: " + query, e);
} finally {
try {
logger.debug("Cleaning up.");
http://git-wip-us.apache.org/repos/asf/kylin/blob/9198cfe8/source-hive/src/main/java/org/apache/kylin/source/jdbc/JdbcExplorer.java
----------------------------------------------------------------------
diff --git a/source-hive/src/main/java/org/apache/kylin/source/jdbc/JdbcExplorer.java b/source-hive/src/main/java/org/apache/kylin/source/jdbc/JdbcExplorer.java
index d96a68d..c34597a 100644
--- a/source-hive/src/main/java/org/apache/kylin/source/jdbc/JdbcExplorer.java
+++ b/source-hive/src/main/java/org/apache/kylin/source/jdbc/JdbcExplorer.java
@@ -232,7 +232,7 @@ public class JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeploye
@Override
public ColumnDesc[] evalQueryMetadata(String query) {
if (StringUtils.isEmpty(query)) {
- throw new RuntimeException("Evalutate query shall not be empty.");
+ throw new RuntimeException("Evaluate query shall not be empty.");
}
KylinConfig config = KylinConfig.getInstanceFromEnv();
@@ -256,7 +256,7 @@ public class JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeploye
DBUtils.closeQuietly(con);
return result;
} catch (Exception e) {
- throw new RuntimeException("Cannot evalutate metadata of query: " + query, e);
+ throw new RuntimeException("Cannot evaluate metadata of query: " + query, e);
} finally {
try {
logger.debug("Cleaning up.");
[2/6] kylin git commit: KYLIN-2909 use EmailTemplateFactory in
CubingJob (Thanks Yanghong Zhong and Julian Pan)
Posted by li...@apache.org.
KYLIN-2909 use EmailTemplateFactory in CubingJob (Thanks Yanghong Zhong and Julian Pan)
Signed-off-by: lidongsjtu <li...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/c96e1b19
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/c96e1b19
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/c96e1b19
Branch: refs/heads/master
Commit: c96e1b1947ca8764066ff4390ea1f9e4aa0f6c40
Parents: 7dc1875
Author: Zhong <nj...@apache.org>
Authored: Sat Sep 30 14:26:24 2017 +0800
Committer: lidongsjtu <li...@apache.org>
Committed: Sun Jan 28 15:57:30 2018 +0800
----------------------------------------------------------------------
.../apache/kylin/common/KylinConfigBase.java | 4 +
.../kylin/common/util/EmailTemplateFactory.java | 11 +-
.../main/resources/templates/JOB_DISCARD.ftl | 2 +-
.../main/resources/templates/JOB_SUCCEED.ftl | 2 +-
.../common/util/EmailTemplateFactoryTest.java | 32 +++++
.../kylin/job/constant/ExecutableConstants.java | 1 -
.../kylin/job/execution/AbstractExecutable.java | 92 ++++++++++---
.../kylin/job/util/ExecutableStateUtil.java | 38 ++++++
.../org/apache/kylin/engine/mr/CubingJob.java | 134 ++++++++-----------
9 files changed, 202 insertions(+), 114 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
index 6d1b7f9..7b48935 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
@@ -661,6 +661,10 @@ abstract public class KylinConfigBase implements Serializable {
return getOptional("kylin.job.tracking-url-pattern", "");
}
+ public int getJobMetadataPersistRetry() {
+ return Integer.parseInt(this.getOptional("kylin.job.metadata-persist-retry", "5"));
+ }
+
// ============================================================================
// SOURCE.HIVE
// ============================================================================
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/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
index fcf554d..2acea5d 100644
--- 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
@@ -27,6 +27,8 @@ 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;
@@ -50,14 +52,7 @@ public class EmailTemplateFactory {
}
public static String getEmailTitle(String... titleParts) {
- StringBuilder sb = new StringBuilder();
- for (String part : titleParts) {
- if (sb.length() > 0) {
- sb.append("-");
- }
- sb.append("[" + part + "]");
- }
- return sb.toString();
+ return "[" + Joiner.on("]-[").join(titleParts).toString() + "]";
}
private static EmailTemplateFactory instance = new EmailTemplateFactory();
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/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
index fbef3f7..b00e9aa 100644
--- a/core-common/src/main/resources/templates/JOB_DISCARD.ftl
+++ b/core-common/src/main/resources/templates/JOB_DISCARD.ftl
@@ -33,7 +33,7 @@
<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>
+ <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;
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/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
index 4b443d5..f1fb45c 100644
--- a/core-common/src/main/resources/templates/JOB_SUCCEED.ftl
+++ b/core-common/src/main/resources/templates/JOB_SUCCEED.ftl
@@ -32,7 +32,7 @@
<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>
+ <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;
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/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
new file mode 100644
index 0000000..6acbd75
--- /dev/null
+++ b/core-common/src/test/java/org/apache/kylin/common/util/EmailTemplateFactoryTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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/c96e1b19/core-job/src/main/java/org/apache/kylin/job/constant/ExecutableConstants.java
----------------------------------------------------------------------
diff --git a/core-job/src/main/java/org/apache/kylin/job/constant/ExecutableConstants.java b/core-job/src/main/java/org/apache/kylin/job/constant/ExecutableConstants.java
index cf61722..b9a3651 100644
--- a/core-job/src/main/java/org/apache/kylin/job/constant/ExecutableConstants.java
+++ b/core-job/src/main/java/org/apache/kylin/job/constant/ExecutableConstants.java
@@ -62,5 +62,4 @@ public final class ExecutableConstants {
public static final String STEP_NAME_GARBAGE_COLLECTION_HBASE = "Garbage Collection on HBase";
public static final String STEP_NAME_GARBAGE_COLLECTION_HDFS = "Garbage Collection on HDFS";
public static final String STEP_NAME_REDISTRIBUTE_FLAT_HIVE_TABLE = "Redistribute Flat Hive Table";
- public static final String NOTIFY_EMAIL_TEMPLATE = "<div><b>Build Result of Job ${job_name}</b><pre><ul>" + "<li>Build Result: <b>${result}</b></li>" + "<li>Job Engine: ${job_engine}</li>" + "<li>Env: ${env_name}</li>" + "<li>Project: ${project_name}</li>" + "<li>Cube Name: ${cube_name}</li>" + "<li>Source Records Count: ${source_records_count}</li>" + "<li>Start Time: ${start_time}</li>" + "<li>Duration: ${duration}</li>" + "<li>MR Waiting: ${mr_waiting}</li>" + "<li>Last Update Time: ${last_update_time}</li>" + "<li>Submitter: ${submitter}</li>" + "<li>Error Log: ${error_log}</li>" + "</ul></pre><div/>";
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/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 6a0db97..f4015bf 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
@@ -24,12 +24,16 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.regex.Matcher;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.tuple.Pair;
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;
@@ -64,16 +68,16 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
public AbstractExecutable() {
setId(UUID.randomUUID().toString());
}
-
+
protected void initConfig(KylinConfig config) {
Preconditions.checkState(this.config == null || this.config == config);
this.config = config;
}
-
+
protected KylinConfig getConfig() {
return config;
}
-
+
protected ExecutableManager getManager() {
return ExecutableManager.getInstance(config);
}
@@ -84,6 +88,36 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
getManager().updateJobOutput(getId(), ExecutableState.RUNNING, info, null);
}
+ private void onExecuteFinishedWithRetry(ExecuteResult result, ExecutableContext executableContext)
+ throws ExecuteException {
+ Throwable exception;
+ int nRetry = 0;
+ do {
+ nRetry++;
+ exception = null;
+ try {
+ onExecuteFinished(result, executableContext);
+ } catch (Exception e) {
+ logger.error(nRetry + "th retries for onExecuteFinished fails due to {}", e);
+ if (isMetaDataPersistException(e)) {
+ exception = e;
+ try {
+ Thread.sleep(1000L * (long) Math.pow(4, nRetry));
+ } catch (InterruptedException exp) {
+ throw new RuntimeException(exp);
+ }
+ } else {
+ throw e;
+ }
+ }
+ } while (exception != null && nRetry <= executableContext.getConfig().getJobMetadataPersistRetry());
+
+ if (exception != null) {
+ handleMetadataPersistException(executableContext, exception);
+ throw new ExecuteException(exception);
+ }
+ }
+
protected void onExecuteFinished(ExecuteResult result, ExecutableContext executableContext) {
setEndTime(System.currentTimeMillis());
if (!isDiscarded() && !isRunnable()) {
@@ -134,28 +168,42 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
retry++;
} while (needRetry(result, exception));
- //check exception in result to avoid retry on ChainedExecutable(only need retry on subtask actually)
- if (exception != null || result.getThrowable() != null) {
+ if (exception != null) {
onExecuteError(exception, executableContext);
throw new ExecuteException(exception);
}
- onExecuteFinished(result, executableContext);
+ onExecuteFinishedWithRetry(result, executableContext);
+ } catch (ExecuteException e) {
+ throw e;
} catch (Exception e) {
- if (isMetaDataPersistException(e)) {
- handleMetaDataPersistException(e);
- }
- if (e instanceof ExecuteException) {
- throw e;
- } else {
- throw new ExecuteException(e);
- }
+ throw new ExecuteException(e);
}
return result;
}
- protected void handleMetaDataPersistException(Exception e) {
- // do nothing.
+ protected void handleMetadataPersistException(ExecutableContext context, Throwable exception) {
+ final String[] adminDls = context.getConfig().getAdminDls();
+ if (adminDls == null || adminDls.length < 1) {
+ logger.warn("no need to send email, user list is empty");
+ return;
+ }
+ List<String> users = Lists.newArrayList(adminDls);
+
+ Map<String, Object> dataMap = Maps.newHashMap();
+ 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("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",
+ context.getConfig().getDeployEnv());
+
+ new MailService(context.getConfig()).sendMail(users, title, content);
}
private boolean isMetaDataPersistException(Exception e) {
@@ -299,7 +347,7 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
logger.info("job name:" + getName());
logger.info("submitter:" + getSubmitter());
logger.info("notify list:" + users);
- new MailService(kylinConfig).sendMail(users, email.getLeft(), email.getRight());
+ new MailService(kylinConfig).sendMail(users, email.getFirst(), email.getSecond());
}
protected void sendMail(Pair<String, String> email) {
@@ -335,7 +383,7 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
public static long getEndTime(Output output) {
return getExtraInfoAsLong(output, END_TIME, 0L);
}
-
+
public static long getInterruptTime(Output output) {
return getExtraInfoAsLong(output, INTERRUPT_TIME, 0L);
}
@@ -437,8 +485,7 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
if (retryableEx == null || retryableEx.length == 0) {
return true;
}
- if ((result != null && isRetryableExecutionResult(result))
- || e != null && isRetrableException(e)) {
+ if ((result != null && isRetryableExecutionResult(result)) || e != null && isRetrableException(e)) {
return true;
}
return false;
@@ -446,6 +493,7 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
@Override
public String toString() {
- return Objects.toStringHelper(this).add("id", getId()).add("name", getName()).add("state", getStatus()).toString();
+ return Objects.toStringHelper(this).add("id", getId()).add("name", getName()).add("state", getStatus())
+ .toString();
}
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/c96e1b19/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
new file mode 100644
index 0000000..66f806c
--- /dev/null
+++ b/core-job/src/main/java/org/apache/kylin/job/util/ExecutableStateUtil.java
@@ -0,0 +1,38 @@
+/*
+ * 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/c96e1b19/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
----------------------------------------------------------------------
diff --git a/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java b/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
index 6f26c35..548dcb9 100644
--- a/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
+++ b/engine-mr/src/main/java/org/apache/kylin/engine/mr/CubingJob.java
@@ -18,20 +18,20 @@
package org.apache.kylin.engine.mr;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
-import org.apache.commons.lang3.tuple.Pair;
+
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.Pair;
import org.apache.kylin.common.util.StringUtil;
import org.apache.kylin.cube.CubeInstance;
import org.apache.kylin.cube.CubeManager;
@@ -47,12 +47,15 @@ import org.apache.kylin.job.execution.ExecutableState;
import org.apache.kylin.job.execution.ExecuteResult;
import org.apache.kylin.job.execution.Output;
import org.apache.kylin.job.metrics.JobMetricsFacade;
+import org.apache.kylin.job.util.ExecutableStateUtil;
import org.apache.kylin.metadata.project.ProjectInstance;
import org.apache.kylin.metadata.project.ProjectManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
/**
*/
@@ -195,52 +198,61 @@ public class CubingJob extends DefaultChainedExecutable {
CubeInstance cubeInstance = CubeManager.getInstance(context.getConfig())
.getCube(CubingExecutableUtil.getCubeName(this.getParams()));
final Output output = getManager().getOutput(getId());
- String logMsg;
state = output.getState();
if (state != ExecutableState.ERROR
&& !cubeInstance.getDescriptor().getStatusNeedNotify().contains(state.toString())) {
logger.info("state:" + state + " no need to notify users");
return null;
}
- switch (state) {
- case ERROR:
- logMsg = output.getVerboseMsg();
- break;
- case DISCARDED:
- logMsg = "job has been discarded";
- break;
- case SUCCEED:
- logMsg = "job has succeeded";
- break;
- default:
+
+ EmailTemplateEnum templateEnum = ExecutableStateUtil.getEmailTemplateEnum(state);
+ if (templateEnum == null) {
+ logger.info("Cannot find email template for job state: " + state);
return null;
}
- String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE;
- content = content.replaceAll("\\$\\{job_name\\}", getName());
- content = content.replaceAll("\\$\\{result\\}", state.toString());
- content = content.replaceAll("\\$\\{env_name\\}", getDeployEnvName());
- content = content.replaceAll("\\$\\{project_name\\}", getProjectName());
- content = content.replaceAll("\\$\\{cube_name\\}", CubingExecutableUtil.getCubeName(this.getParams()));
- content = content.replaceAll("\\$\\{source_records_count\\}", String.valueOf(findSourceRecordCount()));
- content = content.replaceAll("\\$\\{start_time\\}", new Date(getStartTime()).toString());
- content = content.replaceAll("\\$\\{duration\\}", getDuration() / 60000 + "mins");
- content = content.replaceAll("\\$\\{mr_waiting\\}", getMapReduceWaitTime() / 60000 + "mins");
- content = content.replaceAll("\\$\\{last_update_time\\}", new Date(getLastModified()).toString());
- content = content.replaceAll("\\$\\{submitter\\}", StringUtil.noBlank(getSubmitter(), "missing submitter"));
- content = content.replaceAll("\\$\\{error_log\\}",
- Matcher.quoteReplacement(StringUtil.noBlank(logMsg, "no error message")));
-
- try {
- InetAddress inetAddress = InetAddress.getLocalHost();
- content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName());
- } catch (UnknownHostException e) {
- logger.warn(e.getLocalizedMessage(), e);
- }
- String title = "[" + state.toString() + "] - [" + getDeployEnvName() + "] - [" + getProjectName() + "] - "
- + CubingExecutableUtil.getCubeName(this.getParams());
+ Map<String, Object> dataMap = Maps.newHashMap();
+ dataMap.put("job_name", getName());
+ dataMap.put("env_name", getDeployEnvName());
+ dataMap.put("submitter", StringUtil.noBlank(getSubmitter(), "missing submitter"));
+ dataMap.put("job_engine", EmailTemplateFactory.getLocalHostName());
+ dataMap.put("project_name", getProjectName());
+ dataMap.put("cube_name", cubeInstance.getName());
+ dataMap.put("source_records_count", String.valueOf(findSourceRecordCount()));
+ dataMap.put("start_time", new Date(getStartTime()).toString());
+ dataMap.put("duration", getDuration() / 60000 + "mins");
+ dataMap.put("mr_waiting", getMapReduceWaitTime() / 60000 + "mins");
+ dataMap.put("last_update_time", new Date(getLastModified()).toString());
+
+ if (state == ExecutableState.ERROR) {
+ AbstractExecutable errorTask = null;
+ Output errorOutput = null;
+ for (AbstractExecutable task : getTasks()) {
+ errorOutput = getManager().getOutput(task.getId());
+ if (errorOutput.getState() == ExecutableState.ERROR) {
+ errorTask = task;
+ break;
+ }
+ }
+ Preconditions.checkNotNull(errorTask,
+ "None of the sub tasks of cubing job " + getId() + " is error and this job should become success.");
- return Pair.of(title, content);
+ dataMap.put("error_step", errorTask.getName());
+ if (errorTask instanceof MapReduceExecutable) {
+ final String mrJobId = errorOutput.getExtra().get(ExecutableConstants.MR_JOB_ID);
+ dataMap.put("mr_job_id", StringUtil.noBlank(mrJobId, "Not initialized"));
+ } else {
+ dataMap.put("mr_job_id", EmailTemplateFactory.NA);
+ }
+ dataMap.put("error_log",
+ Matcher.quoteReplacement(StringUtil.noBlank(output.getVerboseMsg(), "no error message")));
+ }
+
+ String content = EmailTemplateFactory.getInstance()
+ .buildEmailContent(ExecutableStateUtil.getEmailTemplateEnum(state), dataMap);
+ String title = EmailTemplateFactory.getEmailTitle("JOB", state.toString(), getDeployEnvName(), getProjectName(),
+ cubeInstance.getName());
+ return Pair.newPair(title, content);
}
@Override
@@ -297,46 +309,6 @@ public class CubingJob extends DefaultChainedExecutable {
return timeCost * 1.0 / size;
}
- /**
- * build fail because the metadata store has problem.
- * @param exception
- */
- @Override
- protected void handleMetaDataPersistException(Exception exception) {
- String title = "[ERROR] - [" + getDeployEnvName() + "] - [" + getProjectName() + "] - "
- + CubingExecutableUtil.getCubeName(this.getParams());
- String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE;
- final String UNKNOWN = "UNKNOWN";
- String errMsg = null;
- if (exception != null) {
- final StringWriter out = new StringWriter();
- exception.printStackTrace(new PrintWriter(out));
- errMsg = out.toString();
- }
-
- content = content.replaceAll("\\$\\{job_name\\}", getName());
- content = content.replaceAll("\\$\\{result\\}", ExecutableState.ERROR.toString());
- content = content.replaceAll("\\$\\{env_name\\}", getDeployEnvName());
- content = content.replaceAll("\\$\\{project_name\\}", getProjectName());
- content = content.replaceAll("\\$\\{cube_name\\}", CubingExecutableUtil.getCubeName(this.getParams()));
- content = content.replaceAll("\\$\\{source_records_count\\}", UNKNOWN);
- content = content.replaceAll("\\$\\{start_time\\}", UNKNOWN);
- content = content.replaceAll("\\$\\{duration\\}", UNKNOWN);
- content = content.replaceAll("\\$\\{mr_waiting\\}", UNKNOWN);
- content = content.replaceAll("\\$\\{last_update_time\\}", UNKNOWN);
- content = content.replaceAll("\\$\\{submitter\\}", StringUtil.noBlank(getSubmitter(), "missing submitter"));
- content = content.replaceAll("\\$\\{error_log\\}",
- Matcher.quoteReplacement(StringUtil.noBlank(errMsg, "no error message")));
-
- try {
- InetAddress inetAddress = InetAddress.getLocalHost();
- content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName());
- } catch (UnknownHostException e) {
- logger.warn(e.getLocalizedMessage(), e);
- }
- sendMail(Pair.of(title, content));
- }
-
public long getMapReduceWaitTime() {
return getExtraInfoAsLong(MAP_REDUCE_WAIT_TIME, 0L);
}