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 2128695 Redesign JobErrorHandler's interface (#1583) 2128695 is described below commit 2128695b30d59fd209725c1c27026656cf1fcf6f Author: Liang Zhang <terrym...@163.com> AuthorDate: Sun Oct 18 22:21:00 2020 +0800 Redesign JobErrorHandler's interface (#1583) * Redesign JobErrorHandler's interface * For code format --- .../elasticjob/error/handler/JobErrorHandler.java | 8 ++-- .../handler/dingtalk/DingtalkJobErrorHandler.java | 38 +++++++-------- .../dingtalk/DingtalkJobErrorHandlerTest.java | 42 ++++++++--------- .../error/handler/email/EmailJobErrorHandler.java | 55 +++++++++++----------- .../handler/email/EmailJobErrorHandlerTest.java | 40 ++++++++-------- .../handler/general/IgnoreJobErrorHandler.java | 5 +- .../error/handler/general/LogJobErrorHandler.java | 7 +-- .../handler/general/ThrowJobErrorHandler.java | 5 +- .../handler/general/IgnoreJobErrorHandlerTest.java | 5 +- .../handler/general/LogJobErrorHandlerTest.java | 4 +- .../handler/general/ThrowJobErrorHandlerTest.java | 5 +- .../handler/wechat/WechatJobErrorHandler.java | 26 +++++----- .../handler/wechat/WechatJobErrorHandlerTest.java | 22 ++++----- .../elasticjob/executor/ElasticJobExecutor.java | 8 ++-- 14 files changed, 138 insertions(+), 132 deletions(-) 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 11973d7..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 @@ -17,9 +17,10 @@ package org.apache.shardingsphere.elasticjob.error.handler; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.infra.spi.TypedSPI; +import java.util.Properties; + /** * Job error handler. */ @@ -28,8 +29,9 @@ public interface JobErrorHandler extends TypedSPI { /** * Handle exception. * - * @param jobConfig job configuration + * @param jobName job name + * @param props job properties * @param cause failure cause */ - void handleException(JobConfiguration jobConfig, 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/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 fd2a53f..c08a294 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 @@ -29,7 +29,6 @@ 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.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler; import org.apache.shardingsphere.elasticjob.error.handler.dingtalk.config.DingtalkConfiguration; import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory; @@ -47,6 +46,7 @@ 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. @@ -73,45 +73,45 @@ public final class DingtalkJobErrorHandler implements JobErrorHandler { } @Override - public void handleException(final JobConfiguration jobConfig, final Throwable cause) { - DingtalkConfiguration dingtalkConfig = new DingtalkConfiguration(jobConfig.getProps()); - HttpPost httpPost = createHTTPPostMethod(jobConfig.getJobName(), cause, dingtalkConfig); + public void handleException(final String jobName, final Properties props, final Throwable cause) { + DingtalkConfiguration config = new DingtalkConfiguration(props); + HttpPost httpPost = createHTTPPostMethod(jobName, cause, config); try (CloseableHttpResponse response = httpclient.execute(httpPost)) { int status = response.getStatusLine().getStatusCode(); if (HttpURLConnection.HTTP_OK == status) { JsonObject responseMessage = GsonFactory.getGson().fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class); if (!"0".equals(responseMessage.get("errcode").getAsString())) { - log.info("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: {}", jobConfig.getJobName(), responseMessage.get("errmsg").getAsString(), cause); + log.info("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: {}", jobName, responseMessage.get("errmsg").getAsString(), cause); } else { - log.info("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", jobConfig.getJobName(), cause); + log.info("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", jobName, cause); } } else { - log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: Unexpected response status: {}", jobConfig.getJobName(), status, cause); + log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of: Unexpected response status: {}", jobName, status, cause); } } catch (final IOException ex) { cause.addSuppressed(ex); - log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of", jobConfig.getJobName(), cause); + log.error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of", jobName, cause); } } - private HttpPost createHTTPPostMethod(final String jobName, final Throwable cause, final DingtalkConfiguration dingtalkConfig) { - HttpPost result = new HttpPost(getURL(dingtalkConfig)); - RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(dingtalkConfig.getConnectTimeoutMillisecond()).setSocketTimeout(dingtalkConfig.getReadTimeoutMillisecond()).build(); + 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(); result.setConfig(requestConfig); - StringEntity entity = new StringEntity(getJsonParameter(getErrorMessage(jobName, dingtalkConfig, cause)), StandardCharsets.UTF_8); + StringEntity entity = new StringEntity(getJsonParameter(getErrorMessage(jobName, config, cause)), StandardCharsets.UTF_8); entity.setContentEncoding(StandardCharsets.UTF_8.name()); entity.setContentType("application/json"); result.setEntity(entity); return result; } - private String getURL(final DingtalkConfiguration dingtalkConfig) { - return Strings.isNullOrEmpty(dingtalkConfig.getSecret()) ? dingtalkConfig.getWebhook() : getSignedURL(dingtalkConfig); + private String getURL(final DingtalkConfiguration config) { + return Strings.isNullOrEmpty(config.getSecret()) ? config.getWebhook() : getSignedURL(config); } - private String getSignedURL(final DingtalkConfiguration dingtalkConfig) { + private String getSignedURL(final DingtalkConfiguration config) { long timestamp = System.currentTimeMillis(); - return String.format("%s×tamp=%s&sign=%s", dingtalkConfig.getWebhook(), timestamp, generateSignature(timestamp, dingtalkConfig.getSecret())); + return String.format("%s×tamp=%s&sign=%s", config.getWebhook(), timestamp, generateSignature(timestamp, config.getSecret())); } @SneakyThrows({NoSuchAlgorithmException.class, UnsupportedEncodingException.class, InvalidKeyException.class}) @@ -127,12 +127,12 @@ public final class DingtalkJobErrorHandler implements JobErrorHandler { return GsonFactory.getGson().toJson(ImmutableMap.of("msgtype", "text", "text", Collections.singletonMap("content", message))); } - private String getErrorMessage(final String jobName, final DingtalkConfiguration dingtalkConfig, final Throwable cause) { + private String getErrorMessage(final String jobName, final DingtalkConfiguration config, final Throwable cause) { StringWriter writer = new StringWriter(); cause.printStackTrace(new PrintWriter(writer, true)); String result = String.format("Job '%s' exception occur in job processing, caused by %s", jobName, writer.toString()); - if (!Strings.isNullOrEmpty(dingtalkConfig.getKeyword())) { - result = dingtalkConfig.getKeyword().concat(result); + if (!Strings.isNullOrEmpty(config.getKeyword())) { + result = config.getKeyword().concat(result); } return result; } 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 01fdb9f..0ca80ce 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 @@ -18,7 +18,6 @@ package org.apache.shardingsphere.elasticjob.error.handler.dingtalk; import lombok.SneakyThrows; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory; import org.apache.shardingsphere.elasticjob.error.handler.dingtalk.config.DingtalkPropertiesConstants; import org.apache.shardingsphere.elasticjob.error.handler.dingtalk.fixture.DingtalkInternalController; @@ -36,6 +35,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; @@ -72,7 +72,7 @@ public final class DingtalkJobErrorHandlerTest { DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://localhost:9875/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f"), cause); + actual.handleException("test_job", createJobProperties("http://localhost:9875/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f"), cause); verify(log).info("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", "test_job", cause); } @@ -81,7 +81,7 @@ public final class DingtalkJobErrorHandlerTest { DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://localhost:9875/send?access_token=wrongToken"), cause); + actual.handleException("test_job", createJobProperties("http://localhost:9875/send?access_token=wrongToken"), 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); } @@ -90,7 +90,7 @@ public final class DingtalkJobErrorHandlerTest { DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://localhost:9875/404"), cause); + actual.handleException("test_job", createJobProperties("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); } @@ -99,7 +99,7 @@ public final class DingtalkJobErrorHandlerTest { DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getNoSignJobConfiguration("http://wrongUrl"), cause); + actual.handleException("test_job", createNoSignJobProperties("http://wrongUrl"), cause); verify(log).error("An exception has occurred in Job '{}', But failed to send alert by Dingtalk because of", "test_job", cause); } @@ -108,7 +108,7 @@ public final class DingtalkJobErrorHandlerTest { DingtalkJobErrorHandler actual = getDingtalkJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getNoSignJobConfiguration("http://localhost:9875/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f"), cause); + actual.handleException("test_job", createNoSignJobProperties("http://localhost:9875/send?access_token=42eead064e81ce81fc6af2c107fbe10a4339a3d40a7db8abf5b34d8261527a3f"), cause); verify(log).info("An exception has occurred in Job '{}', Notification to Dingtalk was successful.", "test_job", cause); } @@ -126,22 +126,22 @@ public final class DingtalkJobErrorHandlerTest { field.set(dingtalkJobErrorHandler, log); } - private JobConfiguration getJobConfiguration(final String webhook) { - return JobConfiguration.newBuilder("test_job", 3) - .setProperty(DingtalkPropertiesConstants.WEBHOOK, webhook) - .setProperty(DingtalkPropertiesConstants.KEYWORD, "keyword") - .setProperty(DingtalkPropertiesConstants.SECRET, "SEC0b0a6b13b6823b95737dd83491c23adee5d8a7a649899a12217e038eddc84ff4") - .setProperty(DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "4000") - .setProperty(DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECOND, "6000") - .build(); + private Properties createJobProperties(final String webhook) { + Properties result = new Properties(); + result.setProperty(DingtalkPropertiesConstants.WEBHOOK, webhook); + result.setProperty(DingtalkPropertiesConstants.KEYWORD, "keyword"); + result.setProperty(DingtalkPropertiesConstants.SECRET, "SEC0b0a6b13b6823b95737dd83491c23adee5d8a7a649899a12217e038eddc84ff4"); + result.setProperty(DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "4000"); + result.setProperty(DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECOND, "6000"); + return result; } - private JobConfiguration getNoSignJobConfiguration(final String webhook) { - return JobConfiguration.newBuilder("test_job", 3) - .setProperty(DingtalkPropertiesConstants.WEBHOOK, webhook) - .setProperty(DingtalkPropertiesConstants.KEYWORD, "keyword") - .setProperty(DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "4000") - .setProperty(DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECOND, "6000") - .build(); + private Properties createNoSignJobProperties(final String webhook) { + Properties result = new Properties(); + result.setProperty(DingtalkPropertiesConstants.WEBHOOK, webhook); + result.setProperty(DingtalkPropertiesConstants.KEYWORD, "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/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 40e9494..7e575a1 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 @@ -19,7 +19,6 @@ package org.apache.shardingsphere.elasticjob.error.handler.email; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler; import org.apache.shardingsphere.elasticjob.error.handler.email.config.EmailConfiguration; @@ -50,15 +49,15 @@ public final class EmailJobErrorHandler implements JobErrorHandler { private Session session; @Override - public void handleException(final JobConfiguration jobConfig, final Throwable cause) { - EmailConfiguration emailConfig = new EmailConfiguration(jobConfig.getProps()); - String errorMessage = getErrorMessage(jobConfig.getJobName(), cause); + public void handleException(final String jobName, final Properties props, final Throwable cause) { + EmailConfiguration config = new EmailConfiguration(props); + String errorMessage = getErrorMessage(jobName, cause); try { - sendMessage(createMessage(errorMessage, emailConfig), emailConfig); - log.error("An exception has occurred in Job '{}', Notification to email was successful..", jobConfig.getJobName(), cause); + sendMessage(createMessage(errorMessage, config), config); + log.error("An exception has occurred in Job '{}', Notification to email was successful..", jobName, cause); } catch (final MessagingException ex) { cause.addSuppressed(ex); - log.error("An exception has occurred in Job '{}', But failed to send alert by email because of", jobConfig.getJobName(), cause); + log.error("An exception has occurred in Job '{}', But failed to send alert by email because of", jobName, cause); } } @@ -68,67 +67,67 @@ public final class EmailJobErrorHandler implements JobErrorHandler { return String.format("Job '%s' exception occur in job processing, caused by %s", jobName, writer.toString()); } - private Message createMessage(final String content, final EmailConfiguration emailConfig) throws MessagingException { - MimeMessage result = new MimeMessage(Optional.ofNullable(session).orElseGet(() -> createSession(emailConfig))); - result.setFrom(new InternetAddress(emailConfig.getFrom())); - result.setSubject(emailConfig.getSubject()); + private Message createMessage(final String content, final EmailConfiguration config) throws MessagingException { + MimeMessage result = new MimeMessage(Optional.ofNullable(session).orElseGet(() -> createSession(config))); + result.setFrom(new InternetAddress(config.getFrom())); + result.setSubject(config.getSubject()); result.setSentDate(new Date()); Multipart multipart = new MimeMultipart(); BodyPart mailBody = new MimeBodyPart(); mailBody.setContent(content, "text/html; charset=utf-8"); multipart.addBodyPart(mailBody); result.setContent(multipart); - String to = emailConfig.getTo(); + String to = config.getTo(); if (StringUtils.isNotBlank(to)) { String[] tos = to.split(","); for (String each : tos) { result.addRecipient(Message.RecipientType.TO, new InternetAddress(each)); } } - if (StringUtils.isNotBlank(emailConfig.getCc())) { - result.addRecipient(Message.RecipientType.CC, new InternetAddress(emailConfig.getCc())); + if (StringUtils.isNotBlank(config.getCc())) { + result.addRecipient(Message.RecipientType.CC, new InternetAddress(config.getCc())); } - if (StringUtils.isNotBlank(emailConfig.getBcc())) { - result.addRecipient(Message.RecipientType.BCC, new InternetAddress(emailConfig.getBcc())); + if (StringUtils.isNotBlank(config.getBcc())) { + result.addRecipient(Message.RecipientType.BCC, new InternetAddress(config.getBcc())); } result.saveChanges(); return result; } - private void sendMessage(final Message message, final EmailConfiguration emailConfig) throws MessagingException { - try (Transport transport = Optional.ofNullable(session).orElseGet(() -> createSession(emailConfig)).getTransport()) { + private void sendMessage(final Message message, final EmailConfiguration config) throws MessagingException { + try (Transport transport = Optional.ofNullable(session).orElseGet(() -> createSession(config)).getTransport()) { transport.connect(); transport.sendMessage(message, message.getAllRecipients()); } } - private synchronized Session createSession(final EmailConfiguration emailConfig) { + private synchronized Session createSession(final EmailConfiguration config) { if (null == session) { - session = Session.getDefaultInstance(createSessionProperties(emailConfig), getSessionAuthenticator(emailConfig)); + session = Session.getDefaultInstance(createSessionProperties(config), getSessionAuthenticator(config)); } return session; } - private Properties createSessionProperties(final EmailConfiguration emailConfig) { + private Properties createSessionProperties(final EmailConfiguration config) { Properties result = new Properties(); - result.put("mail.smtp.host", emailConfig.getHost()); - result.put("mail.smtp.port", emailConfig.getPort()); + result.put("mail.smtp.host", config.getHost()); + result.put("mail.smtp.port", config.getPort()); result.put("mail.smtp.auth", "true"); result.put("mail.transport.protocol", "smtp"); - result.setProperty("mail.debug", Boolean.toString(emailConfig.isDebug())); - if (emailConfig.isUseSsl()) { + result.setProperty("mail.debug", Boolean.toString(config.isDebug())); + if (config.isUseSsl()) { result.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); result.setProperty("mail.smtp.socketFactory.fallback", "false"); } return result; } - private Authenticator getSessionAuthenticator(final EmailConfiguration emailConfig) { + private Authenticator getSessionAuthenticator(final EmailConfiguration config) { return new Authenticator() { - + @Override public PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword()); + return new PasswordAuthentication(config.getUsername(), config.getPassword()); } }; } 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 816da79..f4cd111 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 @@ -18,7 +18,6 @@ package org.apache.shardingsphere.elasticjob.error.handler.email; import lombok.SneakyThrows; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory; import org.apache.shardingsphere.elasticjob.error.handler.email.config.EmailPropertiesConstants; import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException; @@ -30,6 +29,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; @@ -44,10 +44,14 @@ public final class EmailJobErrorHandlerTest { EmailJobErrorHandler emailJobErrorHandler = getEmailJobErrorHandler(); setStaticFieldValue(emailJobErrorHandler, "log", log); Throwable cause = new RuntimeException("test"); - emailJobErrorHandler.handleException(getJobConfiguration(), cause); + emailJobErrorHandler.handleException("test_job", createJobProperties(), cause); verify(log).error("An exception has occurred in Job '{}', But failed to send alert by email because of", "test_job", cause); } + private EmailJobErrorHandler getEmailJobErrorHandler() { + return (EmailJobErrorHandler) JobErrorHandlerFactory.createHandler("EMAIL").orElseThrow(() -> new JobConfigurationException("EMAIL error handler not found.")); + } + @SneakyThrows private void setStaticFieldValue(final EmailJobErrorHandler wechatJobErrorHandler, final String name, final Object value) { Field fieldLog = wechatJobErrorHandler.getClass().getDeclaredField(name); @@ -58,23 +62,19 @@ public final class EmailJobErrorHandlerTest { fieldLog.set(wechatJobErrorHandler, value); } - private JobConfiguration getJobConfiguration() { - return JobConfiguration.newBuilder("test_job", 3) - .setProperty(EmailPropertiesConstants.HOST, "xxx") - .setProperty(EmailPropertiesConstants.PORT, "465") - .setProperty(EmailPropertiesConstants.USERNAME, "xxx") - .setProperty(EmailPropertiesConstants.PASSWORD, "xxx") - .setProperty(EmailPropertiesConstants.IS_USE_SSL, "true") - .setProperty(EmailPropertiesConstants.SUBJECT, "Unit test notification") - .setProperty(EmailPropertiesConstants.FROM, "f...@xxx.com") - .setProperty(EmailPropertiesConstants.TO, "t...@xxx.com,t...@xxx.com") - .setProperty(EmailPropertiesConstants.CC, "c...@xxx.com") - .setProperty(EmailPropertiesConstants.BCC, "b...@xxx.com") - .setProperty(EmailPropertiesConstants.IS_DEBUG, "false") - .build(); - } - - private EmailJobErrorHandler getEmailJobErrorHandler() { - return (EmailJobErrorHandler) JobErrorHandlerFactory.createHandler("EMAIL").orElseThrow(() -> new JobConfigurationException("EMAIL error handler not found.")); + private Properties createJobProperties() { + Properties result = new Properties(); + result.setProperty(EmailPropertiesConstants.HOST, "xxx"); + result.setProperty(EmailPropertiesConstants.PORT, "465"); + result.setProperty(EmailPropertiesConstants.USERNAME, "xxx"); + result.setProperty(EmailPropertiesConstants.PASSWORD, "xxx"); + result.setProperty(EmailPropertiesConstants.IS_USE_SSL, "true"); + result.setProperty(EmailPropertiesConstants.SUBJECT, "Unit test notification"); + result.setProperty(EmailPropertiesConstants.FROM, "f...@xxx.com"); + result.setProperty(EmailPropertiesConstants.TO, "t...@xxx.com,t...@xxx.com"); + result.setProperty(EmailPropertiesConstants.CC, "c...@xxx.com"); + result.setProperty(EmailPropertiesConstants.BCC, "b...@xxx.com"); + result.setProperty(EmailPropertiesConstants.IS_DEBUG, Boolean.FALSE.toString()); + 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 0f361b0..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.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler; +import java.util.Properties; + /** * Job error handler for ignore exception. */ public final class IgnoreJobErrorHandler implements JobErrorHandler { @Override - public void handleException(final JobConfiguration jobConfig, 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 8833c19..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,9 +18,10 @@ package org.apache.shardingsphere.elasticjob.error.handler.general; import lombok.extern.slf4j.Slf4j; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler; +import java.util.Properties; + /** * Job error handler for log error message. */ @@ -28,8 +29,8 @@ import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler; public final class LogJobErrorHandler implements JobErrorHandler { @Override - public void handleException(final JobConfiguration jobConfig, final Throwable cause) { - log.error(String.format("Job '%s' exception occur in job processing", jobConfig.getJobName()), 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); } @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/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 9d3e12d..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.api.JobConfiguration; 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 { @Override - public void handleException(final JobConfiguration jobConfig, 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-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandlerTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandlerTest.java index ef86fcf..d160a37 100644 --- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandlerTest.java +++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/IgnoreJobErrorHandlerTest.java @@ -17,16 +17,17 @@ package org.apache.shardingsphere.elasticjob.error.handler.general; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory; import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException; import org.junit.Test; +import java.util.Properties; + public final class IgnoreJobErrorHandlerTest { @Test public void assertHandleException() { JobErrorHandlerFactory.createHandler("IGNORE").orElseThrow(() -> new JobConfigurationException("IGNORE error handler not found.")) - .handleException(JobConfiguration.newBuilder("test_job", 3).build(), new RuntimeException("test")); + .handleException("test_job", new Properties(), new RuntimeException("test")); } } diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandlerTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandlerTest.java index bc38321..18fe5ce 100644 --- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandlerTest.java +++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/LogJobErrorHandlerTest.java @@ -18,7 +18,6 @@ package org.apache.shardingsphere.elasticjob.error.handler.general; import lombok.SneakyThrows; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory; import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException; import org.junit.Test; @@ -29,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; @@ -43,7 +43,7 @@ public final class LogJobErrorHandlerTest { LogJobErrorHandler actual = (LogJobErrorHandler) JobErrorHandlerFactory.createHandler("LOG").orElseThrow(() -> new JobConfigurationException("LOG error handler not found.")); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(JobConfiguration.newBuilder("test_job", 3).build(), cause); + actual.handleException("test_job", new Properties(), cause); verify(log).error("Job 'test_job' exception occur in job processing", cause); } diff --git a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandlerTest.java b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandlerTest.java index bd89cc3..273a5e9 100644 --- a/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandlerTest.java +++ b/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-general/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/general/ThrowJobErrorHandlerTest.java @@ -17,17 +17,18 @@ package org.apache.shardingsphere.elasticjob.error.handler.general; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory; import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException; import org.apache.shardingsphere.elasticjob.infra.exception.JobSystemException; import org.junit.Test; +import java.util.Properties; + public final class ThrowJobErrorHandlerTest { @Test(expected = JobSystemException.class) public void assertHandleException() { JobErrorHandlerFactory.createHandler("THROW").orElseThrow(() -> new JobConfigurationException("THROW error handler not found.")) - .handleException(JobConfiguration.newBuilder("test_job", 3).build(), new RuntimeException("test")); + .handleException("test_job", new Properties(), new RuntimeException("test")); } } 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 56c7958..73c62c2 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 @@ -28,7 +28,6 @@ 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.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler; import org.apache.shardingsphere.elasticjob.error.handler.wechat.config.WechatConfiguration; import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory; @@ -39,6 +38,7 @@ 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. @@ -65,30 +65,30 @@ public final class WechatJobErrorHandler implements JobErrorHandler { } @Override - public void handleException(final JobConfiguration jobConfig, final Throwable cause) { - WechatConfiguration wechatConfig = new WechatConfiguration(jobConfig.getProps()); - HttpPost httpPost = createHTTPPostMethod(jobConfig.getJobName(), cause, wechatConfig); + public void handleException(final String jobName, final Properties props, final Throwable cause) { + WechatConfiguration config = new WechatConfiguration(props); + HttpPost httpPost = createHTTPPostMethod(jobName, cause, config); try (CloseableHttpResponse response = httpclient.execute(httpPost)) { int status = response.getStatusLine().getStatusCode(); if (HttpURLConnection.HTTP_OK == status) { JsonObject resp = GsonFactory.getGson().fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class); if (!"0".equals(resp.get("errcode").getAsString())) { - log.info("An exception has occurred in Job '{}', But failed to send alert by wechat because of: {}", jobConfig.getJobName(), resp.get("errmsg").getAsString(), cause); + log.info("An exception has occurred in Job '{}', But failed to send alert by wechat because of: {}", jobName, resp.get("errmsg").getAsString(), cause); } else { - log.info("An exception has occurred in Job '{}', Notification to wechat was successful.", jobConfig.getJobName(), cause); + log.info("An exception has occurred in Job '{}', Notification to wechat was successful.", jobName, cause); } } else { - log.error("An exception has occurred in Job '{}', But failed to send alert by wechat because of: Unexpected response status: {}", jobConfig.getJobName(), status, cause); + log.error("An exception has occurred in Job '{}', But failed to send alert by wechat because of: Unexpected response status: {}", jobName, status, cause); } } catch (final IOException ex) { cause.addSuppressed(ex); - log.error("An exception has occurred in Job '{}', But failed to send alert by wechat because of", jobConfig.getJobName(), cause); + log.error("An exception has occurred in Job '{}', But failed to send alert by wechat because of", jobName, cause); } } - - private HttpPost createHTTPPostMethod(final String jobName, final Throwable cause, final WechatConfiguration wechatConfig) { - HttpPost result = new HttpPost(wechatConfig.getWebhook()); - RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(wechatConfig.getConnectTimeoutMillisecond()).setSocketTimeout(wechatConfig.getReadTimeoutMillisecond()).build(); + + 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(); result.setConfig(requestConfig); StringEntity entity = new StringEntity(getJsonParameter(getErrorMessage(jobName, cause)), StandardCharsets.UTF_8); entity.setContentEncoding(StandardCharsets.UTF_8.name()); @@ -96,7 +96,7 @@ public final class WechatJobErrorHandler implements JobErrorHandler { result.setEntity(entity); return result; } - + private String getJsonParameter(final String message) { return GsonFactory.getGson().toJson(ImmutableMap.of("msgtype", "text", "text", Collections.singletonMap("content", message))); } 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 c668c30..3098a74 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 @@ -18,7 +18,6 @@ package org.apache.shardingsphere.elasticjob.error.handler.wechat; import lombok.SneakyThrows; -import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerFactory; import org.apache.shardingsphere.elasticjob.error.handler.wechat.config.WechatPropertiesConstants; import org.apache.shardingsphere.elasticjob.error.handler.wechat.fixture.WechatInternalController; @@ -36,6 +35,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; @@ -72,7 +72,7 @@ public final class WechatJobErrorHandlerTest { WechatJobErrorHandler actual = getWechatJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://localhost:9872/send?key=TLQEC0cPivqV1MkT0IPMtzunTBBVyIV3"), cause); + actual.handleException("test_job", getJobProperties("http://localhost:9872/send?key=TLQEC0cPivqV1MkT0IPMtzunTBBVyIV3"), cause); verify(log).info("An exception has occurred in Job '{}', Notification to wechat was successful.", "test_job", cause); } @@ -81,7 +81,7 @@ public final class WechatJobErrorHandlerTest { WechatJobErrorHandler actual = getWechatJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://localhost:9872/send?key=wrongToken"), cause); + actual.handleException("test_job", getJobProperties("http://localhost:9872/send?key=wrongToken"), 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); } @@ -90,7 +90,7 @@ public final class WechatJobErrorHandlerTest { WechatJobErrorHandler actual = getWechatJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://wrongUrl"), cause); + actual.handleException("test_job", getJobProperties("http://wrongUrl"), cause); verify(log).error("An exception has occurred in Job '{}', But failed to send alert by wechat because of", "test_job", cause); } @@ -99,7 +99,7 @@ public final class WechatJobErrorHandlerTest { WechatJobErrorHandler actual = getWechatJobErrorHandler(); setStaticFieldValue(actual); Throwable cause = new RuntimeException("test"); - actual.handleException(getJobConfiguration("http://localhost:9872/404"), cause); + actual.handleException("test_job", getJobProperties("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); } @@ -117,11 +117,11 @@ public final class WechatJobErrorHandlerTest { field.set(wechatJobErrorHandler, log); } - private JobConfiguration getJobConfiguration(final String webhook) { - return JobConfiguration.newBuilder("test_job", 3) - .setProperty(WechatPropertiesConstants.WEBHOOK, webhook) - .setProperty(WechatPropertiesConstants.CONNECT_TIMEOUT_MILLISECOND, "1000") - .setProperty(WechatPropertiesConstants.READ_TIMEOUT_MILLISECOND, "2000") - .build(); + private Properties getJobProperties(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 6cfd9f9..c828434 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 @@ -86,7 +86,7 @@ public final class ElasticJobExecutor { try { jobFacade.checkJobExecutionEnvironment(); } catch (final JobExecutionEnvironmentException cause) { - jobErrorHandler.handleException(jobConfig, 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())); @@ -101,7 +101,7 @@ public final class ElasticJobExecutor { //CHECKSTYLE:OFF } catch (final Throwable cause) { //CHECKSTYLE:ON - jobErrorHandler.handleException(jobConfig, cause); + jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause); } execute(shardingContexts, ExecutionSource.NORMAL_TRIGGER); while (jobFacade.isExecuteMisfired(shardingContexts.getShardingItemParameters().keySet())) { @@ -114,7 +114,7 @@ public final class ElasticJobExecutor { //CHECKSTYLE:OFF } catch (final Throwable cause) { //CHECKSTYLE:ON - jobErrorHandler.handleException(jobConfig, cause); + jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause); } } @@ -184,7 +184,7 @@ public final class ElasticJobExecutor { completeEvent = startEvent.executionFailure(ExceptionUtils.transform(cause)); jobFacade.postJobExecutionEvent(completeEvent); itemErrorMessages.put(item, ExceptionUtils.transform(cause)); - jobErrorHandler.handleException(jobConfig, cause); + jobErrorHandler.handleException(jobConfig.getJobName(), jobConfig.getProps(), cause); } }