yanghua commented on a change in pull request #1596: URL: https://github.com/apache/kylin/pull/1596#discussion_r601106437
########## File path: core-common/src/main/java/org/apache/kylin/common/notify/util/DingTalkTemplateProvider.java ########## @@ -0,0 +1,71 @@ +/* + * 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.notify.util; + +import org.apache.kylin.shaded.com.google.common.base.Strings; + +import java.util.Map; + +public class DingTalkTemplateProvider { + + private static DingTalkTemplateProvider DEFAULT_INSTANCE = new DingTalkTemplateProvider(); + + public static DingTalkTemplateProvider getInstance() { + return DEFAULT_INSTANCE; + } + + public String buildDingTalkContent(String state, String title, Map<String, Object> data) { + String titleStart = "<font color=%s size=3>"; + String titleEnd = "</font>"; + StringBuilder sb = new StringBuilder(Strings.lenientFormat(titleStart, titleColor(state))) + .append(title) + .append(titleEnd) + .append(" \n"); + for (Map.Entry<String, Object> entry : data.entrySet()) { + sb.append(" **") + .append(entry.getKey()) Review comment: indent. ########## File path: core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java ########## @@ -54,12 +57,12 @@ public static final String CUBE_NAME = "cubeName"; protected static final String SUBMITTER = "submitter"; - protected static final String NOTIFY_LIST = "notify_list"; protected static final String START_TIME = "startTime"; protected static final String END_TIME = "endTime"; protected static final String INTERRUPT_TIME = "interruptTime"; protected static final String BUILD_INSTANCE = "buildInstance"; protected static final String PROJECT_INSTANCE_NAME = "projectName"; + public static final String MAP_REDUCE_WAIT_TIME = "mapReduceWaitTime"; Review comment: Does this change relate to this PR? ########## File path: core-common/src/main/java/org/apache/kylin/common/notify/util/DingTalkTemplateProvider.java ########## @@ -0,0 +1,71 @@ +/* + * 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.notify.util; + +import org.apache.kylin.shaded.com.google.common.base.Strings; + +import java.util.Map; + +public class DingTalkTemplateProvider { + + private static DingTalkTemplateProvider DEFAULT_INSTANCE = new DingTalkTemplateProvider(); + + public static DingTalkTemplateProvider getInstance() { + return DEFAULT_INSTANCE; + } + + public String buildDingTalkContent(String state, String title, Map<String, Object> data) { Review comment: Since we have no shared fields, can we let this method be a `static` utility method? ########## File path: core-common/src/main/java/org/apache/kylin/common/notify/util/DingTalkTemplateProvider.java ########## @@ -0,0 +1,71 @@ +/* + * 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.notify.util; + +import org.apache.kylin.shaded.com.google.common.base.Strings; + +import java.util.Map; + +public class DingTalkTemplateProvider { + + private static DingTalkTemplateProvider DEFAULT_INSTANCE = new DingTalkTemplateProvider(); + + public static DingTalkTemplateProvider getInstance() { + return DEFAULT_INSTANCE; + } + + public String buildDingTalkContent(String state, String title, Map<String, Object> data) { + String titleStart = "<font color=%s size=3>"; + String titleEnd = "</font>"; + StringBuilder sb = new StringBuilder(Strings.lenientFormat(titleStart, titleColor(state))) + .append(title) + .append(titleEnd) + .append(" \n"); + for (Map.Entry<String, Object> entry : data.entrySet()) { + sb.append(" **") + .append(entry.getKey()) + .append(" :** ") + .append(entry.getValue()) + .append(" \n"); + } + + return sb.toString(); + } + + private String titleColor(String state) { Review comment: ditto ########## File path: core-common/src/test/java/org/apache/kylin/common/notify/DingTalkServiceTest.java ########## @@ -0,0 +1,69 @@ +/* + * 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.notify; + +import org.apache.kylin.common.KylinConfig; +import org.apache.kylin.common.util.LocalFileMetadataTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +@Ignore("convenient trial tool for dev") +public class DingTalkServiceTest extends LocalFileMetadataTestCase { + + @Before + public void setup() throws Exception { + this.createTestMetadata(); + + } + + @After + public void after() throws Exception { + this.cleanupTestMetadata(); + } + + @Test + public void testSendEmail() throws IOException { + + KylinConfig config = KylinConfig.getInstanceFromEnv(); + + DingTalkService dingTalkservice = new DingTalkService(config); + boolean sent = sendTestEmail(dingTalkservice); + assert !sent; + + System.setProperty("kylin.job.notification-enabled", "false"); + // set kylin.job.notification-enabled=false, and run again, this time should be no mail delivered + dingTalkservice = new DingTalkService(config); + sent = sendTestEmail(dingTalkservice); + assert !sent; + Review comment: still some empty line ########## File path: core-common/src/test/java/org/apache/kylin/common/notify/MailServiceTest.java ########## @@ -46,23 +50,29 @@ public void after() throws Exception { public void testSendEmail() throws IOException { KylinConfig config = KylinConfig.getInstanceFromEnv(); + List<String> receivers = new ArrayList<String>(1); + receivers.add("[email protected]"); + Map<String, List<String>> receiversMap = new HashMap(); + receiversMap.put(NotificationConstants.NOTIFY_EMAIL_LIST, receivers); + + Map<String, Object> content = new HashMap(); + content.put("info", "email notification"); + + NotificationContext notificationInfo = new NotificationContext(config, receiversMap, NotificationConstants.JOB_ERROR, Pair.newPair(new String[]{"test"}, content)); Review comment: too long line -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
