You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/10/21 13:33:27 UTC
[shardingsphere-elasticjob] branch master updated: Revert error
handler configuration to props (#1626)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 9710071 Revert error handler configuration to props (#1626)
9710071 is described below
commit 9710071edf1a4eee3bbf96b4c4f688b89836804d
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Oct 21 21:33:20 2020 +0800
Revert error handler configuration to props (#1626)
* Revert error handler configuration to props
* Remove useless spring namespace
* Remove ErrorHandlerConfiguration.getType
* Remove XXXType
* For code style
---
.../error/handler/ErrorHandlerConfiguration.java | 7 --
.../elasticjob/error/handler/JobErrorHandler.java | 8 +-
.../handler/dingtalk/DingtalkConfiguration.java | 88 +--------------
.../handler/dingtalk/DingtalkJobErrorHandler.java | 18 ++-
...kType.java => DingtalkPropertiesConstants.java} | 23 +++-
.../dingtalk/DingtalkConfigurationTest.java | 55 ---------
.../dingtalk/DingtalkJobErrorHandlerTest.java | 30 +++--
.../error/handler/email/EmailConfiguration.java | 123 +--------------------
.../error/handler/email/EmailJobErrorHandler.java | 22 +++-
.../handler/email/EmailPropertiesConstants.java | 54 +++++++++
.../elasticjob/error/handler/email/EmailType.java | 29 -----
.../handler/email/EmailConfigurationTest.java | 92 ---------------
.../handler/email/EmailJobErrorHandlerTest.java | 17 ++-
.../handler/general/IgnoreJobErrorHandler.java | 7 +-
.../error/handler/general/LogJobErrorHandler.java | 7 +-
.../handler/general/ThrowJobErrorHandler.java | 7 +-
.../error/handler/wechat/WechatConfiguration.java | 62 +----------
.../handler/wechat/WechatJobErrorHandler.java | 18 ++-
...hatType.java => WechatPropertiesConstants.java} | 19 +++-
.../handler/wechat/WechatConfigurationTest.java | 50 ---------
.../handler/wechat/WechatJobErrorHandlerTest.java | 19 +++-
.../elasticjob/executor/ElasticJobExecutor.java | 20 +---
.../namespace/ElasticJobNamespaceHandler.java | 6 -
.../DingtalkErrorHandlerBeanDefinitionParser.java | 43 -------
.../EmailErrorHandlerBeanDefinitionParser.java | 49 --------
.../WechatErrorHandlerBeanDefinitionParser.java | 41 -------
.../tag/DingtalkErrorHandlerBeanDefinitionTag.java | 38 -------
.../tag/EmailErrorHandlerBeanDefinitionTag.java | 50 ---------
.../tag/WechatErrorHandlerBeanDefinitionTag.java | 34 ------
.../resources/META-INF/namespace/elasticjob.xsd | 46 --------
30 files changed, 203 insertions(+), 879 deletions(-)
diff --git a/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/ErrorHandlerConfiguration.java b/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/ErrorHandlerConfiguration.java
index 8e27ccc..566939e 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/ErrorHandlerConfiguration.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/ErrorHandlerConfiguration.java
@@ -23,11 +23,4 @@ import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
* Error handler configuration.
*/
public interface ErrorHandlerConfiguration extends JobExtraConfiguration {
-
- /**
- * Get type.
- *
- * @return type
- */
- String getType();
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/JobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/JobErrorHandler.java
index be77e50..95757b4 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/JobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-spi/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/JobErrorHandler.java
@@ -19,17 +19,19 @@ package org.apache.shardingsphere.elasticjob.error.handler;
import org.apache.shardingsphere.elasticjob.infra.spi.TypedSPI;
+import java.util.Properties;
+
/**
* Job error handler.
*/
-public interface JobErrorHandler<T extends ErrorHandlerConfiguration> extends TypedSPI {
+public interface JobErrorHandler extends TypedSPI {
/**
* Handle exception.
*
* @param jobName job name
- * @param config error handler configuration
+ * @param props job properties
* @param cause failure cause
*/
- void handleException(String jobName, T config, Throwable cause);
+ void handleException(String jobName, Properties props, Throwable cause);
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfiguration.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfiguration.java
index 9d5f29f..be30415 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfiguration.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfiguration.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.elasticjob.error.handler.dingtalk;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
@@ -27,7 +24,7 @@ import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfigurat
/**
* Job error handler configuration for send error message via dingtalk.
*/
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+@RequiredArgsConstructor
@Getter
public final class DingtalkConfiguration implements ErrorHandlerConfiguration {
@@ -40,87 +37,4 @@ public final class DingtalkConfiguration implements ErrorHandlerConfiguration {
private final int connectTimeoutMillisecond;
private final int readTimeoutMillisecond;
-
- @Override
- public String getType() {
- return DingtalkType.TYPE;
- }
-
- /**
- * Create dingtalk configuration builder.
- *
- * @param webhook webhook
- * @return dingtalk configuration builder
- */
- public static Builder newBuilder(final String webhook) {
- return new Builder(webhook);
- }
-
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
- public static final class Builder {
-
- private final String webhook;
-
- private String keyword;
-
- private String secret;
-
- private int connectTimeoutMillisecond = 3000;
-
- private int readTimeoutMillisecond = 5000;
-
- /**
- * Set keyword.
- *
- * @param keyword keyword
- * @return dingTalk configuration builder
- */
- public Builder keyword(final String keyword) {
- this.keyword = keyword;
- return this;
- }
-
- /**
- * Set secret.
- *
- * @param secret secret
- * @return dingTalk configuration builder
- */
- public Builder secret(final String secret) {
- this.secret = secret;
- return this;
- }
-
- /**
- * Set connect timeout millisecond.
- *
- * @param connectTimeoutMillisecond connect timeout millisecond
- * @return dingTalk configuration builder
- */
- public Builder connectTimeoutMillisecond(final int connectTimeoutMillisecond) {
- this.connectTimeoutMillisecond = connectTimeoutMillisecond;
- return this;
- }
-
- /**
- * Set read timeout millisecond.
- *
- * @param readTimeoutMillisecond read timeout millisecond
- * @return dingTalk configuration builder
- */
- public Builder readTimeoutMillisecond(final int readTimeoutMillisecond) {
- this.readTimeoutMillisecond = readTimeoutMillisecond;
- return this;
- }
-
- /**
- * Build dingTalk configuration.
- *
- * @return dingTalk configuration
- */
- public DingtalkConfiguration build() {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(webhook), "webhook can not be empty.");
- return new DingtalkConfiguration(webhook, keyword, secret, connectTimeoutMillisecond, readTimeoutMillisecond);
- }
- }
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
index a29d862..4575dbe 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
@@ -45,12 +45,13 @@ import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Collections;
+import java.util.Properties;
/**
* Job error handler for send error message via dingtalk.
*/
@Slf4j
-public final class DingtalkJobErrorHandler implements JobErrorHandler<DingtalkConfiguration> {
+public final class DingtalkJobErrorHandler implements JobErrorHandler {
private final CloseableHttpClient httpclient = HttpClients.createDefault();
@@ -71,8 +72,8 @@ public final class DingtalkJobErrorHandler implements JobErrorHandler<DingtalkCo
}
@Override
- public void handleException(final String jobName, final DingtalkConfiguration config, final Throwable cause) {
- HttpPost httpPost = createHTTPPostMethod(jobName, cause, config);
+ public void handleException(final String jobName, final Properties props, final Throwable cause) {
+ HttpPost httpPost = createHTTPPostMethod(jobName, cause, createConfiguration(props));
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
int status = response.getStatusLine().getStatusCode();
if (HttpURLConnection.HTTP_OK == status) {
@@ -91,6 +92,15 @@ public final class DingtalkJobErrorHandler implements JobErrorHandler<DingtalkCo
}
}
+ private DingtalkConfiguration createConfiguration(final Properties props) {
+ String webhook = props.getProperty(DingtalkPropertiesConstants.WEBHOOK);
+ String keyword = props.getProperty(DingtalkPropertiesConstants.KEYWORD);
+ String secret = props.getProperty(DingtalkPropertiesConstants.SECRET);
+ int connectTimeoutMillisecond = Integer.parseInt(props.getProperty(DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, DingtalkPropertiesConstants.DEFAULT_CONNECT_TIMEOUT_MILLISECOND));
+ int readTimeoutMillisecond = Integer.parseInt(props.getProperty(DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECOND, DingtalkPropertiesConstants.DEFAULT_READ_TIMEOUT_MILLISECOND));
+ return new DingtalkConfiguration(webhook, keyword, secret, connectTimeoutMillisecond, readTimeoutMillisecond);
+ }
+
private HttpPost createHTTPPostMethod(final String jobName, final Throwable cause, final DingtalkConfiguration config) {
HttpPost result = new HttpPost(getURL(config));
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(config.getConnectTimeoutMillisecond()).setSocketTimeout(config.getReadTimeoutMillisecond()).build();
@@ -136,6 +146,6 @@ public final class DingtalkJobErrorHandler implements JobErrorHandler<DingtalkCo
@Override
public String getType() {
- return DingtalkType.TYPE;
+ return "DINGTALK";
}
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkType.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkPropertiesConstants.java
similarity index 54%
rename from elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkType.java
rename to elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkPropertiesConstants.java
index 1fd1dc3..c5f6c67 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkType.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkPropertiesConstants.java
@@ -18,12 +18,23 @@
package org.apache.shardingsphere.elasticjob.error.handler.dingtalk;
/**
- * Dingtalk type.
+ * Job error handler properties constants for send error message via dingtalk.
*/
-public final class DingtalkType {
+public final class DingtalkPropertiesConstants {
- /**
- * Dingtalk type.
- */
- public static final String TYPE = "DINGTALK";
+ public static final String DEFAULT_CONNECT_TIMEOUT_MILLISECOND = "3000";
+
+ public static final String DEFAULT_READ_TIMEOUT_MILLISECOND = "5000";
+
+ private static final String PREFIX = "dingtalk.";
+
+ public static final String WEBHOOK = PREFIX + "webhook";
+
+ public static final String KEYWORD = PREFIX + "keyword";
+
+ public static final String SECRET = PREFIX + "secret";
+
+ public static final String CONNECT_TIMEOUT_MILLISECOND = PREFIX + "connectTimeoutMillisecond";
+
+ public static final String READ_TIMEOUT_MILLISECOND = PREFIX + "readTimeoutMillisecond";
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfigurationTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfigurationTest.java
deleted file mode 100644
index 0038fd1..0000000
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkConfigurationTest.java
+++ /dev/null
@@ -1,55 +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.shardingsphere.elasticjob.error.handler.dingtalk;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class DingtalkConfigurationTest {
-
- @Test
- public void assertBuildAllProperties() {
- DingtalkConfiguration actual = DingtalkConfiguration.newBuilder("webhook").keyword("keyword").secret("secret").connectTimeoutMillisecond(4000).readTimeoutMillisecond(2000).build();
- assertThat(actual.getWebhook(), is("webhook"));
- assertThat(actual.getKeyword(), is("keyword"));
- assertThat(actual.getSecret(), is("secret"));
- assertThat(actual.getConnectTimeoutMillisecond(), is(4000));
- assertThat(actual.getReadTimeoutMillisecond(), is(2000));
- }
-
- @Test
- public void assertBuildRequiredProperties() {
- DingtalkConfiguration actual = DingtalkConfiguration.newBuilder("webhook").build();
- assertThat(actual.getWebhook(), is("webhook"));
- assertNull(actual.getKeyword());
- assertNull(actual.getSecret());
- assertThat(actual.getConnectTimeoutMillisecond(), is(3000));
- assertThat(actual.getReadTimeoutMillisecond(), is(5000));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyWebhook() {
- DingtalkConfiguration.newBuilder("").build();
- }
-}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerTest.java
index 87e1141..853bc12 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerTest.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerTest.java
@@ -34,6 +34,7 @@ import org.slf4j.Logger;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.util.Properties;
import static org.mockito.Mockito.verify;
@@ -70,7 +71,7 @@ public final class DingtalkJobErrorHandlerTest {
DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", createDingtalkConfiguration("http://localhost:9875/send?access_token=mocked_token"), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://localhost:9875/send?access_token=mocked_token"), cause);
verify(log).info("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", "test_job", cause);
}
@@ -79,7 +80,7 @@ public final class DingtalkJobErrorHandlerTest {
DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", createDingtalkConfiguration("http://localhost:9875/send?access_token=wrong_token"), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://localhost:9875/send?access_token=wrong_token"), cause);
verify(log).info("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: {}", "test_job", "token is not exist", cause);
}
@@ -88,7 +89,7 @@ public final class DingtalkJobErrorHandlerTest {
DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", createDingtalkConfiguration("http://localhost:9875/404"), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://localhost:9875/404"), cause);
verify(log).error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: Unexpected response status: {}", "test_job", 404, cause);
}
@@ -97,7 +98,7 @@ public final class DingtalkJobErrorHandlerTest {
DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", createNoSignJobDingtalkConfiguration("http://wrongUrl"), cause);
+ actual.handleException("test_job", createNoSignJobConfigurationProperties("http://wrongUrl"), cause);
verify(log).error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of", "test_job", cause);
}
@@ -106,7 +107,7 @@ public final class DingtalkJobErrorHandlerTest {
DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", createNoSignJobDingtalkConfiguration("http://localhost:9875/send?access_token=mocked_token"), cause);
+ actual.handleException("test_job", createNoSignJobConfigurationProperties("http://localhost:9875/send?access_token=mocked_token"), cause);
verify(log).info("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", "test_job", cause);
}
@@ -124,11 +125,22 @@ public final class DingtalkJobErrorHandlerTest {
field.set(dingtalkJobErrorHandler, log);
}
- private DingtalkConfiguration createDingtalkConfiguration(final String webhook) {
- return DingtalkConfiguration.newBuilder(webhook).keyword("mocked_keyword").secret("mocked_secret").connectTimeoutMillisecond(4000).readTimeoutMillisecond(6000).build();
+ private Properties createConfigurationProperties(final String webhook) {
+ Properties result = new Properties();
+ result.setProperty(DingtalkPropertiesConstants.WEBHOOK, webhook);
+ result.setProperty(DingtalkPropertiesConstants.KEYWORD, "mocked_keyword");
+ result.setProperty(DingtalkPropertiesConstants.SECRET, "mocked_secret");
+ result.setProperty(DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "4000");
+ result.setProperty(DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECOND, "6000");
+ return result;
}
- private DingtalkConfiguration createNoSignJobDingtalkConfiguration(final String webhook) {
- return DingtalkConfiguration.newBuilder(webhook).keyword("mocked_keyword").connectTimeoutMillisecond(4000).readTimeoutMillisecond(6000).build();
+ private Properties createNoSignJobConfigurationProperties(final String webhook) {
+ Properties result = new Properties();
+ result.setProperty(DingtalkPropertiesConstants.WEBHOOK, webhook);
+ result.setProperty(DingtalkPropertiesConstants.KEYWORD, "mocked_keyword");
+ result.setProperty(DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "4000");
+ result.setProperty(DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECOND, "6000");
+ return result;
}
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfiguration.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfiguration.java
index b6a8957..6f851e7 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfiguration.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfiguration.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.elasticjob.error.handler.email;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
@@ -27,7 +24,7 @@ import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfigurat
/**
* Job error handler configuration for send error message via email.
*/
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+@RequiredArgsConstructor
@Getter
public final class EmailConfiguration implements ErrorHandlerConfiguration {
@@ -52,122 +49,4 @@ public final class EmailConfiguration implements ErrorHandlerConfiguration {
private final String bcc;
private final boolean debug;
-
- @Override
- public String getType() {
- return EmailType.TYPE;
- }
-
- /**
- * Create email configuration builder.
- *
- * @param host host
- * @param port port
- * @param username username
- * @param password password
- * @param from from
- * @param to to
- * @return email configuration builder
- */
- public static Builder newBuilder(final String host, final int port, final String username, final String password, final String from, final String to) {
- return new Builder(host, port, username, password, from, to);
- }
-
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
- public static final class Builder {
-
- private final String host;
-
- private final int port;
-
- private final String username;
-
- private final String password;
-
- private boolean useSsl = true;
-
- private String subject = "ElasticJob error message";
-
- private final String from;
-
- private final String to;
-
- private String cc;
-
- private String bcc;
-
- private boolean debug;
-
- /**
- * Set whether use SSL.
- *
- * @param useSsl use SSL or not
- * @return email configuration builder
- */
- public Builder useSsl(final boolean useSsl) {
- this.useSsl = useSsl;
- return this;
- }
-
- /**
- * Set subject.
- *
- * @param subject subject
- * @return email configuration builder
- */
- public Builder subject(final String subject) {
- if (!Strings.isNullOrEmpty(subject)) {
- this.subject = subject;
- }
- return this;
- }
-
- /**
- * Set cc.
- *
- * @param cc cc
- * @return email configuration builder
- */
- public Builder cc(final String cc) {
- this.cc = cc;
- return this;
- }
-
- /**
- * Set bcc.
- *
- * @param bcc bcc
- * @return email configuration builder
- */
- public Builder bcc(final String bcc) {
- this.bcc = bcc;
- return this;
- }
-
- /**
- * Set whether use debug mode.
- *
- * @param debug use debug mode or not
- * @return email configuration builder
- */
- public Builder debug(final boolean debug) {
- this.debug = debug;
- return this;
- }
-
- /**
- * Build email configuration.
- *
- * @return email configuration
- */
- public EmailConfiguration build() {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(host), "host can not be empty.");
- Preconditions.checkArgument(port > 0 && port < 65535, "port should larger than 0 and small than 65535.");
- Preconditions.checkArgument(!Strings.isNullOrEmpty(username), "username can not be empty.");
- Preconditions.checkArgument(!Strings.isNullOrEmpty(password), "password can not be empty.");
- Preconditions.checkArgument(!Strings.isNullOrEmpty(from), "from can not be empty.");
- Preconditions.checkArgument(!Strings.isNullOrEmpty(to), "to can not be empty.");
- return new EmailConfiguration(host, port, username, password, useSsl, subject, from, to, cc, bcc, debug);
- }
- }
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
index f5b2ed4..280602d 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
@@ -43,13 +43,14 @@ import java.util.Properties;
* Job error handler for send error message via email.
*/
@Slf4j
-public final class EmailJobErrorHandler implements JobErrorHandler<EmailConfiguration> {
+public final class EmailJobErrorHandler implements JobErrorHandler {
private Session session;
@Override
- public void handleException(final String jobName, final EmailConfiguration config, final Throwable cause) {
+ public void handleException(final String jobName, final Properties props, final Throwable cause) {
String errorMessage = getErrorMessage(jobName, cause);
+ EmailConfiguration config = createConfiguration(props);
try {
sendMessage(createMessage(errorMessage, config), config);
log.error("An exception has occurred in Job '{}', Notification to email was successful..", jobName, cause);
@@ -59,6 +60,21 @@ public final class EmailJobErrorHandler implements JobErrorHandler<EmailConfigur
}
}
+ private EmailConfiguration createConfiguration(final Properties props) {
+ String host = props.getProperty(EmailPropertiesConstants.HOST);
+ int port = Integer.parseInt(props.getProperty(EmailPropertiesConstants.PORT));
+ String username = props.getProperty(EmailPropertiesConstants.USERNAME);
+ String password = props.getProperty(EmailPropertiesConstants.PASSWORD);
+ boolean isUseSSL = Boolean.getBoolean(props.getProperty(EmailPropertiesConstants.IS_USE_SSL, EmailPropertiesConstants.DEFAULT_IS_USE_SSL));
+ String subject = props.getProperty(EmailPropertiesConstants.SUBJECT, EmailPropertiesConstants.DEFAULT_SUBJECT);
+ String from = props.getProperty(EmailPropertiesConstants.FROM);
+ String to = props.getProperty(EmailPropertiesConstants.TO);
+ String cc = props.getProperty(EmailPropertiesConstants.CC);
+ String bcc = props.getProperty(EmailPropertiesConstants.BCC);
+ boolean isDebug = Boolean.getBoolean(props.getProperty(EmailPropertiesConstants.IS_DEBUG, EmailPropertiesConstants.DEFAULT_IS_DEBUG));
+ return new EmailConfiguration(host, port, username, password, isUseSSL, subject, from, to, cc, bcc, isDebug);
+ }
+
private String getErrorMessage(final String jobName, final Throwable cause) {
StringWriter writer = new StringWriter();
cause.printStackTrace(new PrintWriter(writer, true));
@@ -132,6 +148,6 @@ public final class EmailJobErrorHandler implements JobErrorHandler<EmailConfigur
@Override
public String getType() {
- return EmailType.TYPE;
+ return "EMAIL";
}
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java
new file mode 100644
index 0000000..eff753b
--- /dev/null
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java
@@ -0,0 +1,54 @@
+/*
+ * 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.email;
+
+/**
+ * Job error handler properties constants for send error message via email.
+ */
+public final class EmailPropertiesConstants {
+
+ public static final String DEFAULT_IS_USE_SSL = Boolean.TRUE.toString();
+
+ public static final String DEFAULT_SUBJECT = "ElasticJob error message";
+
+ public static final String DEFAULT_IS_DEBUG = Boolean.FALSE.toString();
+
+ private static final String PREFIX = "email.";
+
+ public static final String HOST = PREFIX + "host";
+
+ public static final String PORT = PREFIX + "port";
+
+ public static final String USERNAME = PREFIX + "username";
+
+ public static final String PASSWORD = PREFIX + "password";
+
+ public static final String IS_USE_SSL = PREFIX + "useSsl";
+
+ public static final String SUBJECT = PREFIX + "subject";
+
+ public static final String FROM = PREFIX + "from";
+
+ public static final String TO = PREFIX + "to";
+
+ public static final String CC = PREFIX + "cc";
+
+ public static final String BCC = PREFIX + "bcc";
+
+ public static final String IS_DEBUG = PREFIX + "debug";
+}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailType.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailType.java
deleted file mode 100644
index e181a95..0000000
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailType.java
+++ /dev/null
@@ -1,29 +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.shardingsphere.elasticjob.error.handler.email;
-
-/**
- * Email type.
- */
-public final class EmailType {
-
- /**
- * Email type.
- */
- public static final String TYPE = "EMAIL";
-}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationTest.java
deleted file mode 100644
index da36dfa..0000000
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailConfigurationTest.java
+++ /dev/null
@@ -1,92 +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.shardingsphere.elasticjob.error.handler.email;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class EmailConfigurationTest {
-
- @Test
- public void assertBuildAllProperties() {
- EmailConfiguration actual = EmailConfiguration.newBuilder("smtp.xxx.com", 25, "username", "password", "from@xx.xx", "to@xx.xx")
- .useSsl(false).subject("subject").cc("cc@xx.xx").bcc("bcc@xx.xx").debug(true).build();
- assertThat(actual.getHost(), is("smtp.xxx.com"));
- assertThat(actual.getPort(), is(25));
- assertThat(actual.getUsername(), is("username"));
- assertThat(actual.getPassword(), is("password"));
- assertFalse(actual.isUseSsl());
- assertThat(actual.getSubject(), is("subject"));
- assertThat(actual.getFrom(), is("from@xx.xx"));
- assertThat(actual.getTo(), is("to@xx.xx"));
- assertThat(actual.getCc(), is("cc@xx.xx"));
- assertThat(actual.getBcc(), is("bcc@xx.xx"));
- assertTrue(actual.isDebug());
- }
-
- @Test
- public void assertBuildRequiredProperties() {
- EmailConfiguration actual = EmailConfiguration.newBuilder("smtp.xxx.com", 25, "username", "password", "from@xx.xx", "to@xx.xx").build();
- assertThat(actual.getHost(), is("smtp.xxx.com"));
- assertThat(actual.getPort(), is(25));
- assertThat(actual.getUsername(), is("username"));
- assertThat(actual.getPassword(), is("password"));
- assertTrue(actual.isUseSsl());
- assertThat(actual.getSubject(), is("ElasticJob error message"));
- assertThat(actual.getFrom(), is("from@xx.xx"));
- assertThat(actual.getTo(), is("to@xx.xx"));
- assertFalse(actual.isDebug());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyHost() {
- EmailConfiguration.newBuilder("", 25, "username", "password", "from@xx.xx", "to@xx.xx").build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithInvalidPort() {
- EmailConfiguration.newBuilder("smtp.xxx.com", -1, "username", "password", "from@xx.xx", "to@xx.xx").build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyUsername() {
- EmailConfiguration.newBuilder("smtp.xxx.com", 25, "", "password", "from@xx.xx", "to@xx.xx").build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyPassword() {
- EmailConfiguration.newBuilder("smtp.xxx.com", 25, "username", "", "from@xx.xx", "to@xx.xx").build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyFrom() {
- EmailConfiguration.newBuilder("smtp.xxx.com", 25, "username", "password", "", "to@xx.xx").build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyTo() {
- EmailConfiguration.newBuilder("smtp.xxx.com", 25, "username", "password", "from@xx.xx", "").build();
- }
-}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
index ad2b841..2afbf4c 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.util.Properties;
import static org.mockito.Mockito.verify;
@@ -42,7 +43,7 @@ public final class EmailJobErrorHandlerTest {
EmailJobErrorHandler emailJobErrorHandler = getEmailJobErrorHandler();
setStaticFieldValue(emailJobErrorHandler, "log", log);
Throwable cause = new RuntimeException("test");
- emailJobErrorHandler.handleException("test_job", createEmailConfiguration(), cause);
+ emailJobErrorHandler.handleException("test_job", createConfigurationProperties(), cause);
verify(log).error("An exception has occurred in Job '{}', But failed to send alert by email because of", "test_job", cause);
}
@@ -60,7 +61,17 @@ public final class EmailJobErrorHandlerTest {
fieldLog.set(wechatJobErrorHandler, value);
}
- private EmailConfiguration createEmailConfiguration() {
- return EmailConfiguration.newBuilder("xxx", 465, "xxx", "xxx", "from@xxx.xx", "to1@xxx.xx,to2@xxx.xx").subject("Unit test notification").cc("cc@xxx.xx").bcc("bcc@xxx.xx").build();
+ private Properties createConfigurationProperties() {
+ Properties result = new Properties();
+ result.setProperty(EmailPropertiesConstants.HOST, "localhost");
+ result.setProperty(EmailPropertiesConstants.PORT, "465");
+ result.setProperty(EmailPropertiesConstants.USERNAME, "user");
+ result.setProperty(EmailPropertiesConstants.PASSWORD, "xxx");
+ result.setProperty(EmailPropertiesConstants.SUBJECT, "Unit test notification");
+ result.setProperty(EmailPropertiesConstants.FROM, "from@xxx.xx");
+ result.setProperty(EmailPropertiesConstants.TO, "to1@xxx.xx,to2@xxx.xx");
+ result.setProperty(EmailPropertiesConstants.CC, "cc@xxx.xx");
+ result.setProperty(EmailPropertiesConstants.BCC, "bcc@xxx.xx");
+ return result;
}
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandler.java
index 90ac5bc..6e8ad3d 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandler.java
@@ -17,16 +17,17 @@
package org.apache.shardingsphere.elasticjob.error.handler.general;
-import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler;
+import java.util.Properties;
+
/**
* Job error handler for ignore exception.
*/
-public final class IgnoreJobErrorHandler implements JobErrorHandler<ErrorHandlerConfiguration> {
+public final class IgnoreJobErrorHandler implements JobErrorHandler {
@Override
- public void handleException(final String jobName, final ErrorHandlerConfiguration config, final Throwable cause) {
+ public void handleException(final String jobName, final Properties props, final Throwable cause) {
}
@Override
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandler.java
index a939c6e..0e83df1 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandler.java
@@ -18,17 +18,18 @@
package org.apache.shardingsphere.elasticjob.error.handler.general;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler;
+import java.util.Properties;
+
/**
* Job error handler for log error message.
*/
@Slf4j
-public final class LogJobErrorHandler implements JobErrorHandler<ErrorHandlerConfiguration> {
+public final class LogJobErrorHandler implements JobErrorHandler {
@Override
- public void handleException(final String jobName, final ErrorHandlerConfiguration config, final Throwable cause) {
+ public void handleException(final String jobName, final Properties props, final Throwable cause) {
log.error(String.format("Job '%s' exception occur in job processing", jobName), cause);
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandler.java
index 3bd4a21..f9f9e3e 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandler.java
@@ -17,17 +17,18 @@
package org.apache.shardingsphere.elasticjob.error.handler.general;
-import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler;
import org.apache.shardingsphere.elasticjob.infra.exception.JobSystemException;
+import java.util.Properties;
+
/**
* Job error handler for throw exception.
*/
-public final class ThrowJobErrorHandler implements JobErrorHandler<ErrorHandlerConfiguration> {
+public final class ThrowJobErrorHandler implements JobErrorHandler {
@Override
- public void handleException(final String jobName, final ErrorHandlerConfiguration config, final Throwable cause) {
+ public void handleException(final String jobName, final Properties props, final Throwable cause) {
throw new JobSystemException(cause);
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfiguration.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfiguration.java
index b35d785..f6e844e 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfiguration.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfiguration.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.elasticjob.error.handler.wechat;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
@@ -27,7 +24,7 @@ import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfigurat
/**
* Job error handler configuration for send error message via wechat.
*/
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+@RequiredArgsConstructor
@Getter
public final class WechatConfiguration implements ErrorHandlerConfiguration {
@@ -36,61 +33,4 @@ public final class WechatConfiguration implements ErrorHandlerConfiguration {
private final int connectTimeoutMillisecond;
private final int readTimeoutMillisecond;
-
- @Override
- public String getType() {
- return WechatType.TYPE;
- }
-
- /**
- * Create wechat configuration builder.
- *
- * @param webhook webhook
- * @return wechat configuration builder
- */
- public static Builder newBuilder(final String webhook) {
- return new Builder(webhook);
- }
-
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
- public static final class Builder {
-
- private final String webhook;
-
- private int connectTimeoutMillisecond = 3000;
-
- private int readTimeoutMillisecond = 5000;
-
- /**
- * Set connect timeout millisecond.
- *
- * @param connectTimeoutMillisecond connect timeout millisecond
- * @return wechat configuration builder
- */
- public Builder connectTimeoutMillisecond(final int connectTimeoutMillisecond) {
- this.connectTimeoutMillisecond = connectTimeoutMillisecond;
- return this;
- }
-
- /**
- * Set read timeout millisecond.
- *
- * @param readTimeoutMillisecond read timeout millisecond
- * @return weChat configuration builder
- */
- public Builder readTimeoutMillisecond(final int readTimeoutMillisecond) {
- this.readTimeoutMillisecond = readTimeoutMillisecond;
- return this;
- }
-
- /**
- * Build wechat configuration.
- *
- * @return wechat configuration
- */
- public WechatConfiguration build() {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(webhook), "webhook can not be empty.");
- return new WechatConfiguration(webhook, connectTimeoutMillisecond, readTimeoutMillisecond);
- }
- }
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
index a303f2c..9340cff 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
@@ -37,12 +37,13 @@ import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
+import java.util.Properties;
/**
* Job error handler for send error message via wechat.
*/
@Slf4j
-public final class WechatJobErrorHandler implements JobErrorHandler<WechatConfiguration> {
+public final class WechatJobErrorHandler implements JobErrorHandler {
private final CloseableHttpClient httpclient = HttpClients.createDefault();
@@ -52,7 +53,7 @@ public final class WechatJobErrorHandler implements JobErrorHandler<WechatConfig
private void registerShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread("WechatJobErrorHandler Shutdown-Hook") {
-
+
@SneakyThrows
@Override
public void run() {
@@ -63,8 +64,8 @@ public final class WechatJobErrorHandler implements JobErrorHandler<WechatConfig
}
@Override
- public void handleException(final String jobName, final WechatConfiguration config, final Throwable cause) {
- HttpPost httpPost = createHTTPPostMethod(jobName, cause, config);
+ public void handleException(final String jobName, final Properties props, final Throwable cause) {
+ HttpPost httpPost = createHTTPPostMethod(jobName, cause, createConfiguration(props));
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
int status = response.getStatusLine().getStatusCode();
if (HttpURLConnection.HTTP_OK == status) {
@@ -83,6 +84,13 @@ public final class WechatJobErrorHandler implements JobErrorHandler<WechatConfig
}
}
+ private WechatConfiguration createConfiguration(final Properties props) {
+ String webhook = props.getProperty(WechatPropertiesConstants.WEBHOOK);
+ int connectTimeoutMillisecond = Integer.parseInt(props.getProperty(WechatPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, WechatPropertiesConstants.DEFAULT_CONNECT_TIMEOUT_MILLISECOND));
+ int readTimeoutMillisecond = Integer.parseInt(props.getProperty(WechatPropertiesConstants.READ_TIMEOUT_MILLISECOND, WechatPropertiesConstants.DEFAULT_READ_TIMEOUT_MILLISECOND));
+ return new WechatConfiguration(webhook, connectTimeoutMillisecond, readTimeoutMillisecond);
+ }
+
private HttpPost createHTTPPostMethod(final String jobName, final Throwable cause, final WechatConfiguration config) {
HttpPost result = new HttpPost(config.getWebhook());
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(config.getConnectTimeoutMillisecond()).setSocketTimeout(config.getReadTimeoutMillisecond()).build();
@@ -106,6 +114,6 @@ public final class WechatJobErrorHandler implements JobErrorHandler<WechatConfig
@Override
public String getType() {
- return WechatType.TYPE;
+ return "WECHAT";
}
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatType.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatPropertiesConstants.java
similarity index 59%
rename from elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatType.java
rename to elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatPropertiesConstants.java
index 88fc858..82fbce7 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatType.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatPropertiesConstants.java
@@ -18,12 +18,19 @@
package org.apache.shardingsphere.elasticjob.error.handler.wechat;
/**
- * Wechat type.
+ * Job error handler properties constants for send error message via wechat.
*/
-public final class WechatType {
+public final class WechatPropertiesConstants {
- /**
- * Wechat type.
- */
- public static final String TYPE = "WECHAT";
+ public static final String DEFAULT_CONNECT_TIMEOUT_MILLISECOND = "3000";
+
+ public static final String DEFAULT_READ_TIMEOUT_MILLISECOND = "5000";
+
+ private static final String PREFIX = "wechat.";
+
+ public static final String WEBHOOK = PREFIX + "webhook";
+
+ public static final String CONNECT_TIMEOUT_MILLISECOND = PREFIX + "connectTimeoutMillisecond";
+
+ public static final String READ_TIMEOUT_MILLISECOND = PREFIX + "readTimeoutMillisecond";
}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfigurationTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfigurationTest.java
deleted file mode 100644
index 8bbe2e2..0000000
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatConfigurationTest.java
+++ /dev/null
@@ -1,50 +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.shardingsphere.elasticjob.error.handler.wechat;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class WechatConfigurationTest {
-
- @Test
- public void assertBuildAllProperties() {
- WechatConfiguration actual = WechatConfiguration.newBuilder("webhook").connectTimeoutMillisecond(4000).readTimeoutMillisecond(2000).build();
- assertThat(actual.getWebhook(), is("webhook"));
- assertThat(actual.getConnectTimeoutMillisecond(), is(4000));
- assertThat(actual.getReadTimeoutMillisecond(), is(2000));
- }
-
- @Test
- public void assertBuildRequiredProperties() {
- WechatConfiguration actual = WechatConfiguration.newBuilder("webhook").build();
- assertThat(actual.getWebhook(), is("webhook"));
- assertThat(actual.getConnectTimeoutMillisecond(), is(3000));
- assertThat(actual.getReadTimeoutMillisecond(), is(5000));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWithEmptyWebhook() {
- WechatConfiguration.newBuilder("").build();
- }
-}
diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerTest.java
index 363b77f..2bc2354 100644
--- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerTest.java
+++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerTest.java
@@ -34,6 +34,7 @@ import org.slf4j.Logger;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.util.Properties;
import static org.mockito.Mockito.verify;
@@ -70,7 +71,7 @@ public final class WechatJobErrorHandlerTest {
WechatJobErrorHandler actual = getWechatJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", WechatConfiguration.newBuilder("http://localhost:9872/send?key=mocked_key").connectTimeoutMillisecond(1000).readTimeoutMillisecond(2000).build(), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://localhost:9872/send?key=mocked_key"), cause);
verify(log).info("An exception has occurred in Job '{}', Notification to wechat was successful.", "test_job", cause);
}
@@ -79,7 +80,7 @@ public final class WechatJobErrorHandlerTest {
WechatJobErrorHandler actual = getWechatJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", WechatConfiguration.newBuilder("http://localhost:9872/send?key=wrong_key").connectTimeoutMillisecond(1000).readTimeoutMillisecond(2000).build(), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://localhost:9872/send?key=wrong_key"), cause);
verify(log).info("An exception has occurred in Job '{}', But failed to send alert by wechat because of: {}", "test_job", "token is invalid", cause);
}
@@ -88,7 +89,7 @@ public final class WechatJobErrorHandlerTest {
WechatJobErrorHandler actual = getWechatJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", WechatConfiguration.newBuilder("http://wrongUrl").connectTimeoutMillisecond(1000).readTimeoutMillisecond(2000).build(), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://wrongUrl"), cause);
verify(log).error("An exception has occurred in Job '{}', But failed to send alert by wechat because of", "test_job", cause);
}
@@ -97,10 +98,10 @@ public final class WechatJobErrorHandlerTest {
WechatJobErrorHandler actual = getWechatJobErrorHandler();
setStaticFieldValue(actual);
Throwable cause = new RuntimeException("test");
- actual.handleException("test_job", WechatConfiguration.newBuilder("http://localhost:9872/404").connectTimeoutMillisecond(1000).readTimeoutMillisecond(2000).build(), cause);
+ actual.handleException("test_job", createConfigurationProperties("http://localhost:9872/404"), cause);
verify(log).error("An exception has occurred in Job '{}', But failed to send alert by wechat because of: Unexpected response status: {}", "test_job", 404, cause);
}
-
+
private WechatJobErrorHandler getWechatJobErrorHandler() {
return (WechatJobErrorHandler) JobErrorHandlerFactory.createHandler("WECHAT").orElseThrow(() -> new JobConfigurationException("WECHAT error handler not found."));
}
@@ -114,4 +115,12 @@ public final class WechatJobErrorHandlerTest {
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(wechatJobErrorHandler, log);
}
+
+ private Properties createConfigurationProperties(final String webhook) {
+ Properties result = new Properties();
+ result.setProperty(WechatPropertiesConstants.WEBHOOK, webhook);
+ result.setProperty(WechatPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "1000");
+ result.setProperty(WechatPropertiesConstants.READ_TIMEOUT_MILLISECOND, "2000");
+ return result;
+ }
}
diff --git a/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java b/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
index d33ef83..1e9d712 100644
--- a/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
+++ b/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.elasticjob.executor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
-import org.apache.shardingsphere.elasticjob.error.handler.ErrorHandlerConfiguration;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory;
import org.apache.shardingsphere.elasticjob.executor.item.JobItemExecutor;
@@ -38,7 +36,6 @@ import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent.St
import java.util.Collection;
import java.util.Map;
-import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -85,12 +82,11 @@ public final class ElasticJobExecutor {
/**
* Execute job.
*/
- @SuppressWarnings("unchecked")
public void execute() {
try {
jobFacade.checkJobExecutionEnvironment();
} catch (final JobExecutionEnvironmentException cause) {
- jobErrorHandler.handleException(jobConfig.getJobName(), findErrorHandlerConfiguration().orElse(null), cause);
+ jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause);
}
ShardingContexts shardingContexts = jobFacade.getShardingContexts();
jobFacade.postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_STAGING, String.format("Job '%s' execute begin.", jobConfig.getJobName()));
@@ -105,7 +101,7 @@ public final class ElasticJobExecutor {
//CHECKSTYLE:OFF
} catch (final Throwable cause) {
//CHECKSTYLE:ON
- jobErrorHandler.handleException(jobConfig.getJobName(), findErrorHandlerConfiguration().orElse(null), cause);
+ jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause);
}
execute(shardingContexts, ExecutionSource.NORMAL_TRIGGER);
while (jobFacade.isExecuteMisfired(shardingContexts.getShardingItemParameters().keySet())) {
@@ -118,7 +114,7 @@ public final class ElasticJobExecutor {
//CHECKSTYLE:OFF
} catch (final Throwable cause) {
//CHECKSTYLE:ON
- jobErrorHandler.handleException(jobConfig.getJobName(), findErrorHandlerConfiguration().orElse(null), cause);
+ jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause);
}
}
@@ -188,18 +184,10 @@ public final class ElasticJobExecutor {
completeEvent = startEvent.executionFailure(ExceptionUtils.transform(cause));
jobFacade.postJobExecutionEvent(completeEvent);
itemErrorMessages.put(item, ExceptionUtils.transform(cause));
- jobErrorHandler.handleException(jobConfig.getJobName(), findErrorHandlerConfiguration().orElse(null), cause);
+ jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause);
}
}
- private Optional<ErrorHandlerConfiguration> findErrorHandlerConfiguration() {
- return jobConfig.getExtraConfigurations().stream().filter(this::isMatchErrorHandlerType).map(extraConfig -> (ErrorHandlerConfiguration) extraConfig).findFirst();
- }
-
- private boolean isMatchErrorHandlerType(final JobExtraConfiguration extraConfig) {
- return extraConfig instanceof ErrorHandlerConfiguration && ((ErrorHandlerConfiguration) extraConfig).getType().equals(jobConfig.getJobErrorHandlerType());
- }
-
/**
* Shutdown executor.
*/
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/ElasticJobNamespaceHandler.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/ElasticJobNamespaceHandler.java
index 663bd72..374746b 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/ElasticJobNamespaceHandler.java
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/ElasticJobNamespaceHandler.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.elasticjob.lite.spring.namespace;
-import org.apache.shardingsphere.elasticjob.lite.spring.namespace.error.parser.DingtalkErrorHandlerBeanDefinitionParser;
-import org.apache.shardingsphere.elasticjob.lite.spring.namespace.error.parser.EmailErrorHandlerBeanDefinitionParser;
-import org.apache.shardingsphere.elasticjob.lite.spring.namespace.error.parser.WechatErrorHandlerBeanDefinitionParser;
import org.apache.shardingsphere.elasticjob.lite.spring.namespace.job.parser.JobBeanDefinitionParser;
import org.apache.shardingsphere.elasticjob.lite.spring.namespace.reg.parser.ZookeeperBeanDefinitionParser;
import org.apache.shardingsphere.elasticjob.lite.spring.namespace.snapshot.parser.SnapshotBeanDefinitionParser;
@@ -37,8 +34,5 @@ public final class ElasticJobNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionParser("zookeeper", new ZookeeperBeanDefinitionParser());
registerBeanDefinitionParser("snapshot", new SnapshotBeanDefinitionParser());
registerBeanDefinitionParser("rdb-tracing", new TracingBeanDefinitionParser());
- registerBeanDefinitionParser("email-error-handler", new EmailErrorHandlerBeanDefinitionParser());
- registerBeanDefinitionParser("wechat-error-handler", new WechatErrorHandlerBeanDefinitionParser());
- registerBeanDefinitionParser("dingtalk-error-handler", new DingtalkErrorHandlerBeanDefinitionParser());
}
}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/DingtalkErrorHandlerBeanDefinitionParser.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/DingtalkErrorHandlerBeanDefinitionParser.java
deleted file mode 100644
index 38ef33f..0000000
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/DingtalkErrorHandlerBeanDefinitionParser.java
+++ /dev/null
@@ -1,43 +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.shardingsphere.elasticjob.lite.spring.namespace.error.parser;
-
-import org.apache.shardingsphere.elasticjob.error.handler.dingtalk.DingtalkConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.spring.namespace.error.tag.DingtalkErrorHandlerBeanDefinitionTag;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.w3c.dom.Element;
-
-/**
- * Dingtalk error handler bean definition parser.
- */
-public final class DingtalkErrorHandlerBeanDefinitionParser extends AbstractBeanDefinitionParser {
-
- @Override
- protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
- BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(DingtalkConfiguration.class);
- factory.addConstructorArgValue(element.getAttribute(DingtalkErrorHandlerBeanDefinitionTag.WEBHOOK));
- factory.addConstructorArgValue(element.getAttribute(DingtalkErrorHandlerBeanDefinitionTag.KEYWORD));
- factory.addConstructorArgValue(element.getAttribute(DingtalkErrorHandlerBeanDefinitionTag.SECRET));
- factory.addConstructorArgValue(element.getAttribute(DingtalkErrorHandlerBeanDefinitionTag.CONNECT_TIMEOUT_MILLISECOND));
- factory.addConstructorArgValue(element.getAttribute(DingtalkErrorHandlerBeanDefinitionTag.READ_TIMEOUT_MILLISECOND));
- return factory.getBeanDefinition();
- }
-}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/EmailErrorHandlerBeanDefinitionParser.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/EmailErrorHandlerBeanDefinitionParser.java
deleted file mode 100644
index 7f22e67..0000000
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/EmailErrorHandlerBeanDefinitionParser.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.shardingsphere.elasticjob.lite.spring.namespace.error.parser;
-
-import org.apache.shardingsphere.elasticjob.error.handler.email.EmailConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.spring.namespace.error.tag.EmailErrorHandlerBeanDefinitionTag;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.w3c.dom.Element;
-
-/**
- * Email error handler bean definition parser.
- */
-public final class EmailErrorHandlerBeanDefinitionParser extends AbstractBeanDefinitionParser {
-
- @Override
- protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
- BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(EmailConfiguration.class);
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.HOST));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.PORT));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.USERNAME));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.PASSWORD));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.USE_SSL));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.SUBJECT));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.FROM));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.TO));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.CC));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.BCC));
- factory.addConstructorArgValue(element.getAttribute(EmailErrorHandlerBeanDefinitionTag.DEBUG));
- return factory.getBeanDefinition();
- }
-}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/WechatErrorHandlerBeanDefinitionParser.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/WechatErrorHandlerBeanDefinitionParser.java
deleted file mode 100644
index d1ccedb..0000000
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/parser/WechatErrorHandlerBeanDefinitionParser.java
+++ /dev/null
@@ -1,41 +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.shardingsphere.elasticjob.lite.spring.namespace.error.parser;
-
-import org.apache.shardingsphere.elasticjob.error.handler.wechat.WechatConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.spring.namespace.error.tag.WechatErrorHandlerBeanDefinitionTag;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.w3c.dom.Element;
-
-/**
- * Wechat error handler bean definition parser.
- */
-public final class WechatErrorHandlerBeanDefinitionParser extends AbstractBeanDefinitionParser {
-
- @Override
- protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
- BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(WechatConfiguration.class);
- factory.addConstructorArgValue(element.getAttribute(WechatErrorHandlerBeanDefinitionTag.WEBHOOK));
- factory.addConstructorArgValue(element.getAttribute(WechatErrorHandlerBeanDefinitionTag.CONNECT_TIMEOUT_MILLISECOND));
- factory.addConstructorArgValue(element.getAttribute(WechatErrorHandlerBeanDefinitionTag.READ_TIMEOUT_MILLISECOND));
- return factory.getBeanDefinition();
- }
-}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/DingtalkErrorHandlerBeanDefinitionTag.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/DingtalkErrorHandlerBeanDefinitionTag.java
deleted file mode 100644
index 3535e58..0000000
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/DingtalkErrorHandlerBeanDefinitionTag.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.shardingsphere.elasticjob.lite.spring.namespace.error.tag;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Dingtalk error handler bean definition tag.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DingtalkErrorHandlerBeanDefinitionTag {
-
- public static final String WEBHOOK = "webhook";
-
- public static final String KEYWORD = "keyword";
-
- public static final String SECRET = "secret";
-
- public static final String CONNECT_TIMEOUT_MILLISECOND = "connect-timeout-millisecond";
-
- public static final String READ_TIMEOUT_MILLISECOND = "read-timeout-millisecond";
-}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/EmailErrorHandlerBeanDefinitionTag.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/EmailErrorHandlerBeanDefinitionTag.java
deleted file mode 100644
index 7f7b90a..0000000
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/EmailErrorHandlerBeanDefinitionTag.java
+++ /dev/null
@@ -1,50 +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.shardingsphere.elasticjob.lite.spring.namespace.error.tag;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Email error handler bean definition tag.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class EmailErrorHandlerBeanDefinitionTag {
-
- public static final String HOST = "host";
-
- public static final String PORT = "port";
-
- public static final String USERNAME = "username";
-
- public static final String PASSWORD = "password";
-
- public static final String USE_SSL = "use-ssl";
-
- public static final String SUBJECT = "subject";
-
- public static final String FROM = "from";
-
- public static final String TO = "to";
-
- public static final String CC = "cc";
-
- public static final String BCC = "bcc";
-
- public static final String DEBUG = "debug";
-}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/WechatErrorHandlerBeanDefinitionTag.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/WechatErrorHandlerBeanDefinitionTag.java
deleted file mode 100644
index 6a555b9..0000000
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/error/tag/WechatErrorHandlerBeanDefinitionTag.java
+++ /dev/null
@@ -1,34 +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.shardingsphere.elasticjob.lite.spring.namespace.error.tag;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Wechat error handler bean definition tag.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class WechatErrorHandlerBeanDefinitionTag {
-
- public static final String WEBHOOK = "webhook";
-
- public static final String CONNECT_TIMEOUT_MILLISECOND = "connect-timeout-millisecond";
-
- public static final String READ_TIMEOUT_MILLISECOND = "read-timeout-millisecond";
-}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/resources/META-INF/namespace/elasticjob.xsd b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/resources/META-INF/namespace/elasticjob.xsd
index c9aa306..f99b55f 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/resources/META-INF/namespace/elasticjob.xsd
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/main/resources/META-INF/namespace/elasticjob.xsd
@@ -83,52 +83,6 @@
</xsd:complexType>
</xsd:element>
- <xsd:element name="email-error-handler">
- <xsd:complexType>
- <xsd:complexContent>
- <xsd:extension base="beans:identifiedType">
- <xsd:attribute name="host" type="xsd:string" use="required" />
- <xsd:attribute name="port" type="xsd:string" use="required" />
- <xsd:attribute name="username" type="xsd:string" use="required" />
- <xsd:attribute name="password" type="xsd:string" use="required" />
- <xsd:attribute name="use-ssl" type="xsd:string" use="required" />
- <xsd:attribute name="subject" type="xsd:string" use="required" />
- <xsd:attribute name="from" type="xsd:string" use="required" />
- <xsd:attribute name="to" type="xsd:string" use="required" />
- <xsd:attribute name="cc" type="xsd:string" use="required" />
- <xsd:attribute name="bcc" type="xsd:string" use="required" />
- <xsd:attribute name="debug" type="xsd:string" use="required" />
- </xsd:extension>
- </xsd:complexContent>
- </xsd:complexType>
- </xsd:element>
-
- <xsd:element name="wechat-error-handler">
- <xsd:complexType>
- <xsd:complexContent>
- <xsd:extension base="beans:identifiedType">
- <xsd:attribute name="webhook" type="xsd:string" use="required" />
- <xsd:attribute name="connect-timeout-millisecond" type="xsd:string" use="required" />
- <xsd:attribute name="read-timeout-millisecond" type="xsd:string" use="required" />
- </xsd:extension>
- </xsd:complexContent>
- </xsd:complexType>
- </xsd:element>
-
- <xsd:element name="dingtalk-error-handler">
- <xsd:complexType>
- <xsd:complexContent>
- <xsd:extension base="beans:identifiedType">
- <xsd:attribute name="webhook" type="xsd:string" use="required" />
- <xsd:attribute name="keyword" type="xsd:string" use="required" />
- <xsd:attribute name="secret" type="xsd:string" use="required" />
- <xsd:attribute name="connect-timeout-millisecond" type="xsd:string" use="required" />
- <xsd:attribute name="read-timeout-millisecond" type="xsd:string" use="required" />
- </xsd:extension>
- </xsd:complexContent>
- </xsd:complexType>
- </xsd:element>
-
<xsd:element name="snapshot">
<xsd:complexType>
<xsd:complexContent>