From 9d1610e08588fe9284b917392b87ef2acc96f8d4 Mon Sep 17 00:00:00 2001 From: yangzhong Date: Tue, 8 Mar 2016 10:02:47 +0800 Subject: [PATCH] KYLIN-672: Add Env and Project Info in job email notification --- .../org/apache/kylin/common/KylinConfigBase.java | 3 ++ .../kylin/job/constant/ExecutableConstants.java | 2 +- .../java/org/apache/kylin/engine/mr/CubingJob.java | 36 +++++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) 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 826a28c..c6c7979 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 @@ -550,4 +550,7 @@ public class KylinConfigBase implements Serializable { return getOptional("kylin.hive.beeline.params", ""); } + public String getDeployEnv() { + return getOptional("deploy.env", "DEV"); + } } 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 ba50880..8f580fc 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 @@ -74,5 +74,5 @@ public final class ExecutableConstants { public static final String PROP_JOB_KILLED = "jobKilled"; public static final String PROP_JOB_RUNTIME_FLOWS = "jobFlows"; - public static final String NOTIFY_EMAIL_TEMPLATE = "
Build Result of Job ${job_name}
    " + "
  • Build Result: ${result}
  • " + "
  • Job Engine: ${job_engine}
  • " + "
  • Cube Name: ${cube_name}
  • " + "
  • Source Records Count: ${source_records_count}
  • " + "
  • Start Time: ${start_time}
  • " + "
  • Duration: ${duration}
  • " + "
  • MR Waiting: ${mr_waiting}
  • " + "
  • Last Update Time: ${last_update_time}
  • " + "
  • Submitter: ${submitter}
  • " + "
  • Error Log: ${error_log}
  • " + "
"; + public static final String NOTIFY_EMAIL_TEMPLATE = "
Build Result of Job ${job_name}
    " + "
  • Build Result: ${result}
  • " + "
  • Job Engine: ${job_engine}
  • " + "
  • Env: ${env_name}
  • " + "
  • Project: ${project_name}
  • " + "
  • Cube Name: ${cube_name}
  • " + "
  • Source Records Count: ${source_records_count}
  • " + "
  • Start Time: ${start_time}
  • " + "
  • Duration: ${duration}
  • " + "
  • MR Waiting: ${mr_waiting}
  • " + "
  • Last Update Time: ${last_update_time}
  • " + "
  • Submitter: ${submitter}
  • " + "
  • Error Log: ${error_log}
  • " + "
"; } 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 979ff75..e939a74 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 @@ -30,6 +30,7 @@ import java.util.regex.Matcher; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; +import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.util.StringUtil; import org.apache.kylin.cube.CubeInstance; import org.apache.kylin.cube.CubeManager; @@ -43,6 +44,8 @@ import org.apache.kylin.job.execution.ExecutableContext; 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.metadata.project.ProjectInstance; +import org.apache.kylin.metadata.project.ProjectManager; /** */ @@ -58,6 +61,8 @@ public class CubingJob extends DefaultChainedExecutable { public static final String CUBE_SIZE_BYTES = "byteSizeBytes"; public static final String MAP_REDUCE_WAIT_TIME = "mapReduceWaitTime"; + private static final String DEPLOY_ENV_NAME = "envName"; + private static final String PROJECT_INSTANCE_NAME = "projectName"; private static final String CUBE_INSTANCE_NAME = "cubeName"; private static final String SEGMENT_ID = "segmentId"; @@ -70,9 +75,20 @@ public class CubingJob extends DefaultChainedExecutable { } private static CubingJob initCubingJob(CubeSegment seg, String jobType, String submitter, JobEngineConfig config) { + KylinConfig kylinConfig = config.getConfig(); + CubeInstance cube = seg.getCubeInstance(); + List projList = ProjectManager.getInstance(kylinConfig).findProjects(cube.getType(),cube.getName()); + if(projList==null || projList.size()==0){ + throw new RuntimeException("Cannot find the project containing the cube " +cube.getName()+"!!!"); + }else if(projList.size()>=2){ + throw new RuntimeException("Find more than one project containing the cube "+cube.getName()+". It does't meet the uniqueness requirement!!! "); + } + CubingJob result = new CubingJob(); SimpleDateFormat format = new SimpleDateFormat("z yyyy-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone(config.getTimeZone())); + result.setDeployEnvName(kylinConfig.getDeployEnv()); + result.setProjectName(projList.get(0).getName()); result.setCubeName(seg.getCubeInstance().getName()); result.setSegmentId(seg.getUuid()); result.setName(seg.getCubeInstance().getName() + " - " + seg.getName() + " - " + jobType + " - " + format.format(new Date(System.currentTimeMillis()))); @@ -85,6 +101,22 @@ public class CubingJob extends DefaultChainedExecutable { super(); } + void setDeployEnvName(String name) { + setParam(DEPLOY_ENV_NAME, name); + } + + public String getDeployEnvName() { + return getParam(DEPLOY_ENV_NAME); + } + + void setProjectName(String name) { + setParam(PROJECT_INSTANCE_NAME, name); + } + + public String getProjectName() { + return getParam(PROJECT_INSTANCE_NAME); + } + void setCubeName(String name) { setParam(CUBE_INSTANCE_NAME, name); } @@ -131,6 +163,8 @@ public class CubingJob extends DefaultChainedExecutable { 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\\}", getCubeName()); content = content.replaceAll("\\$\\{source_records_count\\}", String.valueOf(findSourceRecordCount())); content = content.replaceAll("\\$\\{start_time\\}", new Date(getStartTime()).toString()); @@ -147,7 +181,7 @@ public class CubingJob extends DefaultChainedExecutable { logger.warn(e.getLocalizedMessage(), e); } - String title = "[" + state.toString() + "] - [Kylin Cube Build Job]-" + getCubeName(); + String title = "[" + state.toString() + "] - [" + getDeployEnvName() + "] - [" + getProjectName() + "] - " + getCubeName(); return Pair.of(title, content); } -- 2.5.4 (Apple Git-61)