You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/09/16 12:52:26 UTC

[GitHub] [shardingsphere-elasticjob] gzdzss opened a new pull request #1462: Add DingTalkJobErrorHandler to support sending message

gzdzss opened a new pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462


   Fixes #1460.
   
   Changes proposed in this pull request:
   - Add DingTalkJobErrorHandler to support sending message
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] dongzl commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
dongzl commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489991044



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/config/DingtalkConfiguration.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.shardingsphere.elasticjob.error.handler.config;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@RequiredArgsConstructor
+public class DingtalkConfiguration {

Review comment:
       1. suggest a `final` class.
   2. Please add class comment.

##########
File path: examples/elasticjob-example-lite-java/src/main/resources/conf/elasticjob-dingtalk.properties
##########
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+

Review comment:
       please remove unused blank line.

##########
File path: examples/elasticjob-example-lite-java/pom.xml
##########
@@ -44,7 +44,12 @@
             <groupId>org.apache.shardingsphere.elasticjob</groupId>
             <artifactId>elasticjob-lite-core</artifactId>
         </dependency>
-        
+

Review comment:
       please remove unused blank line.

##########
File path: examples/elasticjob-example-jobs/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/job/simple/JavaErrorJob.java
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.shardingsphere.elasticjob.lite.example.job.simple;
+
+import org.apache.shardingsphere.elasticjob.api.ShardingContext;
+import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
+
+public class JavaErrorJob implements SimpleJob {

Review comment:
       1. suggest `final` class.
   2. add class comment.

##########
File path: examples/pom.xml
##########
@@ -73,6 +73,13 @@
                 <artifactId>elasticjob-cloud-executor</artifactId>
                 <version>${elastic-job.version}</version>
             </dependency>
+
+            <dependency>
+                <artifactId>elasticjob-error-handler-dingtalk</artifactId>
+                <groupId>org.apache.shardingsphere.elasticjob</groupId>
+                <version>${elastic-job.version}</version>
+            </dependency>
+
             

Review comment:
       please remove unused blank line.

##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/test/resources/conf/elasticjob-dingtalk.properties
##########
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+# It can also be configured through startup parameters, E.g: -Delasticjob.dingtalk.webhook=param1  -Delasticjob.dingtalk.keyword=param2  -Delasticjob.dingtalk.secret=param3
+elasticjob.dingtalk.webhook=http://localhost:9876/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f
+elasticjob.dingtalk.keyword=keyword
+elasticjob.dingtalk.secret=SEC0b0a6b13b6823b95737dd83491c23adee5d8a7a649899a12217e038eddc84ff4
+

Review comment:
       please remove unused blank line.

##########
File path: examples/pom.xml
##########
@@ -73,6 +73,13 @@
                 <artifactId>elasticjob-cloud-executor</artifactId>
                 <version>${elastic-job.version}</version>
             </dependency>
+

Review comment:
       please remove unused blank line.

##########
File path: examples/elasticjob-example-lite-java/pom.xml
##########
@@ -44,7 +44,12 @@
             <groupId>org.apache.shardingsphere.elasticjob</groupId>
             <artifactId>elasticjob-lite-core</artifactId>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.shardingsphere.elasticjob</groupId>
+            <artifactId>elasticjob-error-handler-dingtalk</artifactId>
+        </dependency>
+

Review comment:
       please remove unused blank 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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] Technoboy- commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489987799



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandler.java
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.JsonObject;
+import lombok.Setter;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URLEncoder;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Collections;
+
+/**
+ * Job error handler for dingtalk error message.
+ */
+@Slf4j
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
+    
+    @Setter
+    private DingtalkConfiguration dingtalkConfiguration;
+    
+    @SneakyThrows
+    @Override
+    public void handleException(final String jobName, final Throwable cause) {
+        if (null == dingtalkConfiguration) {
+            dingtalkConfiguration = DingtalkEnvironment.getInstance().getDingtalkConfiguration();
+        }
+        CloseableHttpClient httpclient = HttpClients.createDefault();

Review comment:
       Need to remove these logic outside the method.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] jiang2015 commented on pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
jiang2015 commented on pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#issuecomment-693953584


   Need to add this module into shardingsphere-elasticjob's pom.xml
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489430059



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/env/DingtalkEnvironment.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.env;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Bootstrap env.
+ */
+@Slf4j
+public final class DingtalkEnvironment {
+    
+    @Getter
+    private static final DingtalkEnvironment INSTANCE = new DingtalkEnvironment();
+    
+    private static final String PROPERTIES_PATH = "conf/dingtalk.properties";
+    
+    private final Properties properties;
+    
+    private DingtalkEnvironment() {
+        properties = getProperties();
+    }
+    
+    private Properties getProperties() {
+        Properties result = new Properties();
+        try (InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_PATH)) {
+            if (fileInputStream != null) {
+                result.load(fileInputStream);
+            }
+        } catch (final IOException ex) {
+            log.warn("Can not load properties file from path: '{}'.", PROPERTIES_PATH);
+        }
+        setPropertiesByEnv(result);
+        return result;
+    }
+    
+    private void setPropertiesByEnv(final Properties prop) {
+        for (EnvironmentArgument each : EnvironmentArgument.values()) {
+            String key = each.getKey();
+            String value = System.getProperties().getProperty(key);
+            if (!Strings.isNullOrEmpty(value)) {
+                log.info("Load property {} with value {} from ENV.", key, value);
+                prop.setProperty(each.getKey(), value);
+            }
+        }
+    }
+    
+    /**
+     * Get dingtalk configuration.
+     *
+     * @return dingtalk configuration
+     */
+    public DingtalkConfiguration getDingtalkConfiguration() {
+        String webhook = getValue(EnvironmentArgument.WEBHOOK);
+        String keyword = getValue(EnvironmentArgument.KEYWORD);
+        String secret = getValue(EnvironmentArgument.SECRET);
+        String connectTimeout = getValue(EnvironmentArgument.CONNECT_TIMEOUT);
+        String readTimeout = getValue(EnvironmentArgument.READ_TIMEOUT);
+        return new DingtalkConfiguration(webhook, keyword, secret, Integer.parseInt(connectTimeout), Integer.parseInt(readTimeout));
+    }
+    
+    private String getValue(final EnvironmentArgument environmentArgument) {
+        String result = properties.getProperty(environmentArgument.getKey(), environmentArgument.getDefaultValue());
+        if (environmentArgument.isRequired()) {
+            Preconditions.checkState(!Strings.isNullOrEmpty(result), String.format("Property `%s` is required.", environmentArgument.getKey()));
+        }
+        return result;
+    }
+    
+    /**
+     * Env args.
+     */
+    @RequiredArgsConstructor
+    @Getter
+    public enum EnvironmentArgument {
+        
+        WEBHOOK("webhook", "", true),
+        
+        KEYWORD("keyword", "", false),
+        
+        SECRET("secret", "", false),
+        
+        CONNECT_TIMEOUT("connectTimeout", "3000", false),
+        
+        READ_TIMEOUT("readTimeout", "5000", false);

Review comment:
       I think the name of keys are too simple that may increase the probability of conflict. Maybe we can define a prefix to prevent conflict. What do you think?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489995810



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/impl/fixture/DingtalkInternalController.java
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl.fixture;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+import org.apache.shardingsphere.elasticjob.restful.Http;
+import org.apache.shardingsphere.elasticjob.restful.RestfulController;
+import org.apache.shardingsphere.elasticjob.restful.annotation.Mapping;
+import org.apache.shardingsphere.elasticjob.restful.annotation.Param;
+import org.apache.shardingsphere.elasticjob.restful.annotation.ParamSource;
+import org.apache.shardingsphere.elasticjob.restful.annotation.RequestBody;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Map;
+
+@Slf4j
+public final class DingtalkInternalController implements RestfulController {
+    
+    private static final String ACCESS_TOKEN = "42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f";
+    
+    private static final String KEYWORD = "keyword";
+    
+    private static final String SECRET = "SEC0b0a6b13b6823b95737dd83491c23adee5d8a7a649899a12217e038eddc84ff4";
+    
+    
+    /**
+     * Send Dingtalk message.
+     *
+     * @param accessToken access token
+     * @param timestamp timestamp
+     * @param sign sign
+     * @param body body
+     * @return Send Result.
+     */
+    @SneakyThrows
+    @Mapping(method = Http.POST, path = "/send")
+    public String send(@Param(name = "access_token", source = ParamSource.QUERY) final String accessToken,
+                       @Param(name = "timestamp", source = ParamSource.QUERY, required = false) final Long timestamp,
+                       @Param(name = "sign", source = ParamSource.QUERY, required = false) final String sign,
+                       @RequestBody final Map<String, Object> body) {
+        if (!ACCESS_TOKEN.equals(accessToken)) {
+            return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 300001, "errmsg", "token is not exist"));
+        }
+        String content = Map.class.cast(body.get("text")).get("content").toString();
+        if (!content.startsWith(KEYWORD)) {
+            return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 310000, "errmsg", "keywords not in content, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"));
+        }
+        if (!Strings.isNullOrEmpty(sign)) {
+            Preconditions.checkNotNull(timestamp);
+            String checkSign = sign(timestamp);
+            if (!sign.equals(checkSign)) {
+                return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 310000, "errmsg", "sign not match, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"));
+            }
+        }
+        return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 0, "errmsg", "ok"));
+    }
+    
+    private String sign(final Long timestamp) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
+        String stringToSign = timestamp + "\n" + SECRET;
+        System.out.println(stringToSign);
+        Mac mac = Mac.getInstance("HmacSHA256");
+        mac.init(new SecretKeySpec(SECRET.getBytes("UTF-8"), "HmacSHA256"));
+        byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
+        return new String(Base64.getEncoder().encode(signData), "UTF-8");

Review comment:
       Consider using `java.nio.charset.StandardCharsets#UTF_8`

##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandler.java
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.JsonObject;
+import lombok.Setter;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URLEncoder;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Collections;
+
+/**
+ * Job error handler for dingtalk error message.
+ */
+@Slf4j
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
+    
+    @Setter
+    private DingtalkConfiguration dingtalkConfiguration;
+    
+    @SneakyThrows
+    @Override
+    public void handleException(final String jobName, final Throwable cause) {
+        if (null == dingtalkConfiguration) {
+            dingtalkConfiguration = DingtalkEnvironment.getInstance().getDingtalkConfiguration();
+        }
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+        try {
+            HttpPost httpPost = new HttpPost(getUrl());
+            String paramJson = getParamJson(getMsg(jobName, cause));
+            StringEntity entity = new StringEntity(paramJson, "UTF-8");
+            entity.setContentEncoding("UTF-8");
+            entity.setContentType("application/json");

Review comment:
       Maybe there are some constants can be used to get the String?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] gzdzss closed pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
gzdzss closed pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] gzdzss commented on pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
gzdzss commented on pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#issuecomment-695915241


   Because the structure is adjusted, so I close it and use another PR to deal with it.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489449180



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandler.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.apache.shardingsphere.elasticjob.infra.exception.JobExecutionException;
+import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Job error handler for dingtalk error message.
+ */
+@Slf4j
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
+    
+    private DingtalkConfiguration dingtalkConfiguration;
+    
+    @Override
+    public void handleException(final String jobName, final Throwable cause) {
+        if (dingtalkConfiguration == null) {

Review comment:
       Constants on the left.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489421665



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandlerTest.java
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.junit.Test;
+
+public final class DingtalkJobErrorHandlerTest {
+    
+    @Test
+    public void assertHandleException() {
+        DingtalkJobErrorHandler actual = new DingtalkJobErrorHandler();
+        Throwable cause = new RuntimeException("test");
+        actual.handleException("test_job", cause);
+    }
+    
+    @Test
+    public void assertHandleExceptionWithSystemProperties() {
+        System.getProperties().setProperty(DingtalkEnvironment.EnvironmentArgument.WEBHOOK.getKey(),
+                "https://oapi.dingtalk.com/robot/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f");
+        System.getProperties().setProperty(DingtalkEnvironment.EnvironmentArgument.SECRET.getKey(),
+                "SEC0b0a6b13b6823b95737dd83491c23adee5d8a7a649899a12217e038eddc84ff4");
+        System.getProperties().setProperty(DingtalkEnvironment.EnvironmentArgument.KEYWORD.getKey(), "关键字1111");

Review comment:
       English is required.

##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/pom.xml
##########
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.shardingsphere.elasticjob</groupId>
+        <artifactId>elasticjob-error-handler</artifactId>
+        <version>3.0.0-beta-SNAPSHOT</version>
+    </parent>
+    <artifactId>elasticjob-error-handler-dingtalk</artifactId>
+    <name>${project.artifactId}</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere.elasticjob</groupId>
+            <artifactId>elasticjob-infra-common</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>

Review comment:
       "provided" scope is recommended.

##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandler.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.apache.shardingsphere.elasticjob.infra.exception.JobExecutionException;
+import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Job error handler for dingtalk error message.
+ */
+@Slf4j
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
+    
+    private DingtalkConfiguration dingtalkConfiguration;
+    
+    @Override
+    public void handleException(final String jobName, final Throwable cause) {
+        if (dingtalkConfiguration == null) {
+            dingtalkConfiguration = DingtalkEnvironment.getINSTANCE().getDingtalkConfiguration();
+        }
+        HttpURLConnection connection = null;
+        try {
+            URL url = getUrl();
+            connection = (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("POST");
+            connection.setDoOutput(true);
+            connection.setConnectTimeout(dingtalkConfiguration.getConnectTimeout());
+            connection.setReadTimeout(dingtalkConfiguration.getReadTimeout());
+            connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
+            connection.connect();
+            OutputStream outputStream = connection.getOutputStream();
+            String msg = getMsg(jobName, cause);
+            String paramJson = getParamJson(msg);
+            outputStream.write(paramJson.getBytes(StandardCharsets.UTF_8));
+            int code = connection.getResponseCode();
+            if (HttpURLConnection.HTTP_OK == code) {
+                InputStream resultInputStream = connection.getInputStream();
+                StringBuilder result = new StringBuilder();
+                try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resultInputStream, StandardCharsets.UTF_8))) {
+                    String line;
+                    while (null != (line = bufferedReader.readLine())) {
+                        result.append(line);
+                    }
+                }
+                JsonObject resp = GsonFactory.getGson().fromJson(result.toString(), JsonObject.class);
+                if (!"0".equals(resp.get("errcode").getAsString())) {
+                    log.error("Job '{}' exception occur in job processing, But the notification Dingtalk failure, error is : {}", jobName, resp.get("errmsg").getAsString(), cause);
+                }
+            }
+        } catch (IOException | NoSuchAlgorithmException | InvalidKeyException ex) {
+            throw new JobExecutionException(ex);
+        } finally {
+            if (null != connection) {
+                connection.disconnect();
+            }
+        }
+    }
+    
+    private String getParamJson(final String msg) {
+        Map<String, Object> param = Maps.newLinkedHashMap();

Review comment:
       <p><b>Note for Java 7 and later:</b> this method is now unnecessary and should be treated as
   deprecated. Instead, use the {@code LinkedHashMap} constructor directly, taking advantage of
   the new <a href="http://goo.gl/iz2Wi">"diamond" syntax</a>.
   




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] gzdzss closed pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
gzdzss closed pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489450900



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandlerTest.java
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.junit.Test;
+
+public final class DingtalkJobErrorHandlerTest {

Review comment:
       Test case need precised assertion.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489446091



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandler.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.apache.shardingsphere.elasticjob.infra.exception.JobExecutionException;
+import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Job error handler for dingtalk error message.
+ */
+@Slf4j
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
+    
+    private DingtalkConfiguration dingtalkConfiguration;
+    
+    @Override
+    public void handleException(final String jobName, final Throwable cause) {
+        if (dingtalkConfiguration == null) {
+            dingtalkConfiguration = DingtalkEnvironment.getINSTANCE().getDingtalkConfiguration();
+        }
+        HttpURLConnection connection = null;
+        try {
+            URL url = getUrl();
+            connection = (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("POST");
+            connection.setDoOutput(true);
+            connection.setConnectTimeout(dingtalkConfiguration.getConnectTimeout());
+            connection.setReadTimeout(dingtalkConfiguration.getReadTimeout());
+            connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
+            connection.connect();
+            OutputStream outputStream = connection.getOutputStream();
+            String msg = getMsg(jobName, cause);
+            String paramJson = getParamJson(msg);
+            outputStream.write(paramJson.getBytes(StandardCharsets.UTF_8));
+            int code = connection.getResponseCode();
+            if (HttpURLConnection.HTTP_OK == code) {
+                InputStream resultInputStream = connection.getInputStream();
+                StringBuilder result = new StringBuilder();
+                try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resultInputStream, StandardCharsets.UTF_8))) {
+                    String line;
+                    while (null != (line = bufferedReader.readLine())) {
+                        result.append(line);
+                    }
+                }
+                JsonObject resp = GsonFactory.getGson().fromJson(result.toString(), JsonObject.class);
+                if (!"0".equals(resp.get("errcode").getAsString())) {
+                    log.error("Job '{}' exception occur in job processing, But the notification Dingtalk failure, error is : {}", jobName, resp.get("errmsg").getAsString(), cause);

Review comment:
       The exception has already <b>"occurred"</b>. I think using past tense is better. 
   ```
   "An exception has occurred in Job '{}'. But failed to send alert by Dingtalk because of {}"
   ```

##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/impl/DingtalkJobErrorHandler.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.shardingsphere.elasticjob.error.handler.impl;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.error.handler.config.DingtalkConfiguration;
+import org.apache.shardingsphere.elasticjob.error.handler.env.DingtalkEnvironment;
+import org.apache.shardingsphere.elasticjob.infra.exception.JobExecutionException;
+import org.apache.shardingsphere.elasticjob.infra.handler.error.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Job error handler for dingtalk error message.
+ */
+@Slf4j
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
+    
+    private DingtalkConfiguration dingtalkConfiguration;
+    
+    @Override
+    public void handleException(final String jobName, final Throwable cause) {
+        if (dingtalkConfiguration == null) {
+            dingtalkConfiguration = DingtalkEnvironment.getINSTANCE().getDingtalkConfiguration();

Review comment:
       How about name it using camel-case? such as `org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry#getInstance`




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] gzdzss commented on pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
gzdzss commented on pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#issuecomment-695915241


   Because the structure is adjusted, so I close it and use another PR to deal with it.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a change in pull request #1462: Add DingTalkJobErrorHandler to support sending message

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on a change in pull request #1462:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1462#discussion_r489414782



##########
File path: elasticjob-error-handler/elasticjob-error-handler-dingtalk/pom.xml
##########
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.shardingsphere.elasticjob</groupId>
+        <artifactId>elasticjob-error-handler</artifactId>
+        <version>3.0.0-beta-SNAPSHOT</version>
+    </parent>
+    <artifactId>elasticjob-error-handler-dingtalk</artifactId>
+    <name>${project.artifactId}</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere.elasticjob</groupId>
+            <artifactId>elasticjob-infra-common</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>log4j-over-slf4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

Review comment:
       Need a blank line.

##########
File path: examples/elasticjob-example-lite-java/src/main/resources/conf/dingtalk.properties
##########
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+
+# Elasticjob-error-dingtalk is required to introduce this configuration
+# It can also be configured with startup parameters: -Dwebhook=param1  -Dkeyword=param2  -Dsecret=param3
+
+webhook=https://oapi.dingtalk.com/robot/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f
+keyword=\u5173\u952e\u5b57
+secret=SEC0b0a6b13b6823b95737dd83491c23adee5d8a7a649899a12217e038eddc84ff4

Review comment:
       Need a blank line.

##########
File path: elasticjob-error-handler/pom.xml
##########
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.shardingsphere.elasticjob</groupId>
+        <artifactId>elasticjob</artifactId>
+        <version>3.0.0-beta-SNAPSHOT</version>
+    </parent>
+    <artifactId>elasticjob-error-handler</artifactId>
+    <packaging>pom</packaging>
+    <name>${project.artifactId}</name>
+
+    <modules>
+        <module>elasticjob-error-handler-dingtalk</module>
+    </modules>
+</project>

Review comment:
       Need a blank 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:
users@infra.apache.org