Updated to files to fit the Standard.
This commit is contained in:
@@ -64,8 +64,8 @@ import org.springframework.context.annotation.Lazy;
|
||||
@ConditionalOnClass(Job.class)
|
||||
@ConditionalOnBean({ Job.class, TaskLifecycleListener.class })
|
||||
// @checkstyle:off
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
@AutoConfigureAfter(SimpleTaskAutoConfiguration.class)
|
||||
public class BatchEventAutoConfiguration {
|
||||
@@ -121,88 +121,85 @@ public class BatchEventAutoConfiguration {
|
||||
@ConditionalOnExpression("T(org.springframework.util.StringUtils).isEmpty('${spring.batch.job.jobName:}')")
|
||||
public static class JobExecutionListenerConfiguration {
|
||||
|
||||
|
||||
@Autowired
|
||||
private TaskEventProperties taskEventProperties;
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.job-execution",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.job-execution", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public JobExecutionListener jobExecutionEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingJobExecutionListener(
|
||||
messagePublisher,
|
||||
public JobExecutionListener jobExecutionEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingJobExecutionListener(messagePublisher,
|
||||
this.taskEventProperties.getJobExecutionOrder(), properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.step-execution",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.step-execution", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public StepExecutionListener stepExecutionEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingStepExecutionListener(
|
||||
messagePublisher,
|
||||
public StepExecutionListener stepExecutionEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingStepExecutionListener(messagePublisher,
|
||||
this.taskEventProperties.getStepExecutionOrder(), properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@Lazy
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.chunk",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.chunk", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public EventEmittingChunkListener chunkEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingChunkListener(messagePublisher,
|
||||
this.taskEventProperties.getChunkOrder(), properties);
|
||||
public EventEmittingChunkListener chunkEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingChunkListener(messagePublisher, this.taskEventProperties.getChunkOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-read",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-read", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public ItemReadListener itemReadEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingItemReadListener(
|
||||
messagePublisher,
|
||||
this.taskEventProperties.getItemReadOrder(), properties);
|
||||
public ItemReadListener itemReadEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemReadListener(messagePublisher, this.taskEventProperties.getItemReadOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-write",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-write", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public ItemWriteListener itemWriteEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemWriteListener(
|
||||
messagePublisher,
|
||||
this.taskEventProperties.getItemWriteOrder(), properties);
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemWriteListener(messagePublisher, this.taskEventProperties.getItemWriteOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-process",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.item-process", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public ItemProcessListener itemProcessEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemProcessListener(
|
||||
messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingItemProcessListener(messagePublisher,
|
||||
this.taskEventProperties.getItemProcessOrder(), properties);
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.skip",
|
||||
name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events.skip", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public SkipListener skipEventsListener(MessagePublisher messagePublisher,
|
||||
TaskEventProperties properties) {
|
||||
return new EventEmittingSkipListener(messagePublisher,
|
||||
this.taskEventProperties.getItemProcessOrder(), properties);
|
||||
public SkipListener skipEventsListener(MessagePublisher messagePublisher, TaskEventProperties properties) {
|
||||
return new EventEmittingSkipListener(messagePublisher, this.taskEventProperties.getItemProcessOrder(),
|
||||
properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -55,14 +55,12 @@ public class EventEmittingChunkListener implements ChunkListener, Ordered {
|
||||
|
||||
@Override
|
||||
public void beforeChunk(ChunkContext context) {
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(),
|
||||
"Before Chunk Processing");
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(), "Before Chunk Processing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterChunk(ChunkContext context) {
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(),
|
||||
"After Chunk Processing");
|
||||
this.messagePublisher.publish(this.properties.getChunkEventBindingName(), "After Chunk Processing");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,8 +43,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class EventEmittingItemProcessListener implements ItemProcessListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EventEmittingItemProcessListener.class);
|
||||
private static final Log logger = LogFactory.getLog(EventEmittingItemProcessListener.class);
|
||||
|
||||
private MessagePublisher messagePublisher;
|
||||
|
||||
@@ -59,7 +58,8 @@ public class EventEmittingItemProcessListener implements ItemProcessListener, Or
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingItemProcessListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingItemProcessListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
@@ -74,10 +74,12 @@ public class EventEmittingItemProcessListener implements ItemProcessListener, Or
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(), "1 item was filtered");
|
||||
}
|
||||
else if (item.equals(result)) {
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(), "item equaled result after processing");
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(),
|
||||
"item equaled result after processing");
|
||||
}
|
||||
else {
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(), "item did not equal result after processing");
|
||||
this.messagePublisher.publish(this.properties.getItemProcessEventBindingName(),
|
||||
"item did not equal result after processing");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,9 +88,8 @@ public class EventEmittingItemProcessListener implements ItemProcessListener, Or
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onProcessError: " + e.getMessage(), e);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(
|
||||
this.properties.getItemProcessEventBindingName(),
|
||||
"Exception while item was being processed", e.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getItemProcessEventBindingName(),
|
||||
"Exception while item was being processed", e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class EventEmittingItemReadListener implements ItemReadListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EventEmittingItemReadListener.class);
|
||||
private static final Log logger = LogFactory.getLog(EventEmittingItemReadListener.class);
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@@ -56,8 +55,7 @@ public class EventEmittingItemReadListener implements ItemReadListener, Ordered
|
||||
this.messagePublisher = messagePublisher;
|
||||
}
|
||||
|
||||
public EventEmittingItemReadListener(MessagePublisher messagePublisher,
|
||||
int order, TaskEventProperties properties) {
|
||||
public EventEmittingItemReadListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class EventEmittingItemWriteListener implements ItemWriteListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EventEmittingItemWriteListener.class);
|
||||
private static final Log logger = LogFactory.getLog(EventEmittingItemWriteListener.class);
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@@ -58,7 +57,8 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingItemWriteListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingItemWriteListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
@Override
|
||||
public void beforeWrite(List items) {
|
||||
this.messagePublisher.publish(this.properties.getItemWriteEventBindingName(),
|
||||
items.size() + " items to be written.");
|
||||
items.size() + " items to be written.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +75,7 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
logger.debug("Executing afterWrite: " + items);
|
||||
}
|
||||
this.messagePublisher.publish(this.properties.getItemWriteEventBindingName(),
|
||||
items.size() + " items have been written.");
|
||||
items.size() + " items have been written.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,10 +83,9 @@ public class EventEmittingItemWriteListener implements ItemWriteListener, Ordere
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onWriteError: " + exception.getMessage(), exception);
|
||||
}
|
||||
String payload = "Exception while " + items.size()
|
||||
+ " items are attempted to be written.";
|
||||
this.messagePublisher.publishWithThrowableHeader(
|
||||
this.properties.getItemWriteEventBindingName(), payload, exception.getMessage());
|
||||
String payload = "Exception while " + items.size() + " items are attempted to be written.";
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getItemWriteEventBindingName(), payload,
|
||||
exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,19 +47,22 @@ public class EventEmittingJobExecutionListener implements JobExecutionListener,
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingJobExecutionListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingJobExecutionListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(), new JobExecutionEvent(jobExecution));
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(),
|
||||
new JobExecutionEvent(jobExecution));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterJob(JobExecution jobExecution) {
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(), new JobExecutionEvent(jobExecution));
|
||||
this.messagePublisher.publish(properties.getJobExecutionEventBindingName(),
|
||||
new JobExecutionEvent(jobExecution));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,7 +67,8 @@ public class EventEmittingSkipListener implements SkipListener, Ordered {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onSkipInRead: " + t.getMessage(), t);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), "Skipped when reading.", t.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(),
|
||||
"Skipped when reading.", t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +76,8 @@ public class EventEmittingSkipListener implements SkipListener, Ordered {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onSkipInWrite: " + t.getMessage(), t);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item, t.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item,
|
||||
t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +85,8 @@ public class EventEmittingSkipListener implements SkipListener, Ordered {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing onSkipInProcess: " + t.getMessage(), t);
|
||||
}
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item, t.getMessage());
|
||||
this.messagePublisher.publishWithThrowableHeader(this.properties.getSkipEventBindingName(), item,
|
||||
t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.springframework.util.Assert;
|
||||
* @author Glenn Renfro
|
||||
* @author Ali Shahbour
|
||||
*/
|
||||
public class EventEmittingStepExecutionListener
|
||||
implements StepExecutionListener, Ordered {
|
||||
public class EventEmittingStepExecutionListener implements StepExecutionListener, Ordered {
|
||||
|
||||
private final MessagePublisher<StepExecutionEvent> messagePublisher;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
private TaskEventProperties properties;
|
||||
@@ -50,19 +50,22 @@ public class EventEmittingStepExecutionListener
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public EventEmittingStepExecutionListener(MessagePublisher messagePublisher, int order, TaskEventProperties properties) {
|
||||
public EventEmittingStepExecutionListener(MessagePublisher messagePublisher, int order,
|
||||
TaskEventProperties properties) {
|
||||
this(messagePublisher, properties);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(), new StepExecutionEvent(stepExecution));
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(),
|
||||
new StepExecutionEvent(stepExecution));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(), new StepExecutionEvent(stepExecution));
|
||||
this.messagePublisher.publish(this.properties.getStepExecutionEventBindingName(),
|
||||
new StepExecutionEvent(stepExecution));
|
||||
|
||||
return stepExecution.getExitStatus();
|
||||
}
|
||||
|
||||
@@ -57,8 +57,7 @@ public class JobExecutionEvent extends Entity {
|
||||
|
||||
private Date lastUpdated = null;
|
||||
|
||||
private ExitStatus exitStatus = new ExitStatus(
|
||||
new org.springframework.batch.core.ExitStatus("UNKNOWN"));
|
||||
private ExitStatus exitStatus = new ExitStatus(new org.springframework.batch.core.ExitStatus("UNKNOWN"));
|
||||
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
@@ -73,8 +72,7 @@ public class JobExecutionEvent extends Entity {
|
||||
* @param original the StepExecution to build this DTO around.
|
||||
*/
|
||||
public JobExecutionEvent(JobExecution original) {
|
||||
this.jobParameters = new JobParametersEvent(
|
||||
original.getJobParameters().getParameters());
|
||||
this.jobParameters = new JobParametersEvent(original.getJobParameters().getParameters());
|
||||
this.jobInstance = new JobInstanceEvent(original.getJobInstance().getId(),
|
||||
original.getJobInstance().getJobName());
|
||||
for (StepExecution stepExecution : original.getStepExecutions()) {
|
||||
@@ -264,8 +262,8 @@ public class JobExecutionEvent extends Entity {
|
||||
public String toString() {
|
||||
return super.toString() + String.format(
|
||||
", startTime=%s, endTime=%s, lastUpdated=%s, status=%s, exitStatus=%s, job=[%s], jobParameters=[%s]",
|
||||
this.startTime, this.endTime, this.lastUpdated, this.status,
|
||||
this.exitStatus, this.jobInstance, this.jobParameters);
|
||||
this.startTime, this.endTime, this.lastUpdated, this.status, this.exitStatus, this.jobInstance,
|
||||
this.jobParameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,25 +79,22 @@ public class JobParameterEvent {
|
||||
}
|
||||
|
||||
JobParameterEvent rhs = (JobParameterEvent) obj;
|
||||
return this.parameter == null
|
||||
? rhs.parameter == null && this.parameterType == rhs.parameterType
|
||||
return this.parameter == null ? rhs.parameter == null && this.parameterType == rhs.parameterType
|
||||
: this.parameter.equals(rhs.parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.parameter == null ? null
|
||||
: (this.parameterType == JobParameterEvent.ParameterType.DATE
|
||||
? "" + ((Date) this.parameter).getTime()
|
||||
: this.parameter.toString());
|
||||
return this.parameter == null ? null : (this.parameterType == JobParameterEvent.ParameterType.DATE
|
||||
? "" + ((Date) this.parameter).getTime() : this.parameter.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int BASE_HASH = 7;
|
||||
final int MULTIPLIER_HASH = 21;
|
||||
return BASE_HASH + MULTIPLIER_HASH * (this.parameter == null
|
||||
? this.parameterType.hashCode() : this.parameter.hashCode());
|
||||
return BASE_HASH + MULTIPLIER_HASH
|
||||
* (this.parameter == null ? this.parameterType.hashCode() : this.parameter.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,20 +42,16 @@ public class JobParametersEvent {
|
||||
this.parameters = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, JobParameter> entry : jobParameters.entrySet()) {
|
||||
if (entry.getValue().getValue() instanceof String) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
else if (entry.getValue().getValue() instanceof Long) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
else if (entry.getValue().getValue() instanceof Date) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
else if (entry.getValue().getValue() instanceof Double) {
|
||||
this.parameters.put(entry.getKey(),
|
||||
new JobParameterEvent(entry.getValue()));
|
||||
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MessagePublisher<P> {
|
||||
|
||||
|
||||
private final StreamBridge streamBridge;
|
||||
|
||||
public MessagePublisher(StreamBridge streamBridge) {
|
||||
@@ -52,8 +51,8 @@ public class MessagePublisher<P> {
|
||||
}
|
||||
|
||||
public void publishWithThrowableHeader(String bindingName, P payload, String header) {
|
||||
Message<P> message = MessageBuilder.withPayload(payload)
|
||||
.setHeader(BatchJobHeaders.BATCH_EXCEPTION, header).build();
|
||||
Message<P> message = MessageBuilder.withPayload(payload).setHeader(BatchJobHeaders.BATCH_EXCEPTION, header)
|
||||
.build();
|
||||
publishMessage(bindingName, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,7 @@ public class StepExecutionEvent extends Entity {
|
||||
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
private ExitStatus exitStatus = new ExitStatus(
|
||||
org.springframework.batch.core.ExitStatus.EXECUTING);
|
||||
private ExitStatus exitStatus = new ExitStatus(org.springframework.batch.core.ExitStatus.EXECUTING);
|
||||
|
||||
private boolean terminateOnly;
|
||||
|
||||
@@ -82,8 +81,7 @@ public class StepExecutionEvent extends Entity {
|
||||
*/
|
||||
public StepExecutionEvent(StepExecution stepExecution) {
|
||||
super();
|
||||
Assert.notNull(stepExecution,
|
||||
"StepExecution must be provided to re-hydrate an existing StepExecutionEvent");
|
||||
Assert.notNull(stepExecution, "StepExecution must be provided to re-hydrate an existing StepExecutionEvent");
|
||||
Assert.notNull(stepExecution.getJobExecution(),
|
||||
"JobExecution must be provided to re-hydrate an existing StepExecutionEvent");
|
||||
setId(stepExecution.getId());
|
||||
@@ -393,8 +391,7 @@ public class StepExecutionEvent extends Entity {
|
||||
}
|
||||
StepExecution other = (StepExecution) obj;
|
||||
|
||||
return this.stepName.equals(other.getStepName())
|
||||
&& (this.jobExecutionId == other.getJobExecutionId())
|
||||
return this.stepName.equals(other.getStepName()) && (this.jobExecutionId == other.getJobExecutionId())
|
||||
&& getId().equals(other.getId());
|
||||
}
|
||||
|
||||
@@ -407,16 +404,13 @@ public class StepExecutionEvent extends Entity {
|
||||
public int hashCode() {
|
||||
Object jobExecutionId = getJobExecutionId();
|
||||
Long id = getId();
|
||||
return super.hashCode()
|
||||
+ 31 * (this.stepName != null ? this.stepName.hashCode() : 0)
|
||||
+ 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0)
|
||||
+ 59 * (id != null ? id.hashCode() : 0);
|
||||
return super.hashCode() + 31 * (this.stepName != null ? this.stepName.hashCode() : 0)
|
||||
+ 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(getSummary() + ", exitDescription=%s",
|
||||
this.exitStatus.getExitDescription());
|
||||
return String.format(getSummary() + ", exitDescription=%s", this.exitStatus.getExitDescription());
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
@@ -424,9 +418,8 @@ public class StepExecutionEvent extends Entity {
|
||||
", name=%s, status=%s, exitStatus=%s, readCount=%d, "
|
||||
+ "filterCount=%d, writeCount=%d readSkipCount=%d, writeSkipCount=%d"
|
||||
+ ", processSkipCount=%d, commitCount=%d, rollbackCount=%d",
|
||||
this.stepName, this.status, this.exitStatus.getExitCode(), this.readCount,
|
||||
this.filterCount, this.writeCount, this.readSkipCount,
|
||||
this.writeSkipCount, this.processSkipCount, this.commitCount,
|
||||
this.stepName, this.status, this.exitStatus.getExitCode(), this.readCount, this.filterCount,
|
||||
this.writeCount, this.readSkipCount, this.writeSkipCount, this.processSkipCount, this.commitCount,
|
||||
this.rollbackCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
registerJobExecutionEventListener(bean);
|
||||
|
||||
@@ -83,13 +82,11 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
registerChunkEventsListener(bean);
|
||||
|
||||
if (tasklet instanceof ChunkOrientedTasklet) {
|
||||
Field chunkProviderField = ReflectionUtils
|
||||
.findField(ChunkOrientedTasklet.class, "chunkProvider");
|
||||
Field chunkProviderField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProvider");
|
||||
ReflectionUtils.makeAccessible(chunkProviderField);
|
||||
SimpleChunkProvider chunkProvider = (SimpleChunkProvider) ReflectionUtils
|
||||
.getField(chunkProviderField, tasklet);
|
||||
Field chunkProcessorField = ReflectionUtils
|
||||
.findField(ChunkOrientedTasklet.class, "chunkProcessor");
|
||||
Field chunkProcessorField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProcessor");
|
||||
ReflectionUtils.makeAccessible(chunkProcessorField);
|
||||
SimpleChunkProcessor chunkProcessor = (SimpleChunkProcessor) ReflectionUtils
|
||||
.getField(chunkProcessorField, tasklet);
|
||||
@@ -106,63 +103,55 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void registerItemProcessEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((ItemProcessListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerItemReadEvents(SimpleChunkProvider chunkProvider) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener((ItemReadListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerItemWriteEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((ItemWriteListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerSkipEvents(SimpleChunkProvider chunkProvider) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener((SkipListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener(
|
||||
(SkipListener) this.applicationContext.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerSkipEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((SkipListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener(
|
||||
(SkipListener) this.applicationContext.getBean(BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerChunkEventsListener(Object bean) {
|
||||
if (this.applicationContext
|
||||
.containsBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER)) {
|
||||
((TaskletStep) bean)
|
||||
.registerChunkListener((ChunkListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER));
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER)) {
|
||||
((TaskletStep) bean).registerChunkListener(
|
||||
(ChunkListener) this.applicationContext.getBean(BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerJobExecutionEventListener(Object bean) {
|
||||
if (bean instanceof AbstractJob && this.applicationContext.containsBean(
|
||||
BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER)) {
|
||||
if (bean instanceof AbstractJob
|
||||
&& this.applicationContext.containsBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER)) {
|
||||
JobExecutionListener jobExecutionEventsListener = (JobExecutionListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER);
|
||||
|
||||
@@ -172,8 +161,7 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
}
|
||||
|
||||
private void registerStepExecutionEventListener(Object bean) {
|
||||
if (this.applicationContext.containsBean(
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER)) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER)) {
|
||||
StepExecutionListener stepExecutionListener = (StepExecutionListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
AbstractStep step = (AbstractStep) bean;
|
||||
|
||||
@@ -68,12 +68,19 @@ public class TaskEventProperties {
|
||||
private int skipOrder = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
private String jobExecutionEventBindingName = "job-execution-events";
|
||||
|
||||
private String skipEventBindingName = "skip-events";
|
||||
|
||||
private String chunkEventBindingName = "chunk-events";
|
||||
|
||||
private String itemProcessEventBindingName = "item-process-events";
|
||||
|
||||
private String itemReadEventBindingName = "item-read-events";
|
||||
|
||||
private String itemWriteEventBindingName = "item-write-events";
|
||||
|
||||
private String stepExecutionEventBindingName = "step-execution-events";
|
||||
|
||||
private String taskEventBindingName = "task-events";
|
||||
|
||||
public int getJobExecutionOrder() {
|
||||
@@ -132,7 +139,6 @@ public class TaskEventProperties {
|
||||
this.skipOrder = skipOrder;
|
||||
}
|
||||
|
||||
|
||||
public String getJobExecutionEventBindingName() {
|
||||
return jobExecutionEventBindingName;
|
||||
}
|
||||
@@ -196,4 +202,5 @@ public class TaskEventProperties {
|
||||
public void setTaskEventBindingName(String taskEventBindingName) {
|
||||
this.taskEventBindingName = taskEventBindingName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,18 +56,14 @@ public class TaskLaunchRequest implements Serializable {
|
||||
* @param applicationName name to be applied to the launched task. If set to null then
|
||||
* the launched task name will be "Task-`hash code of the TaskLaunchRequest`.
|
||||
*/
|
||||
public TaskLaunchRequest(String uri, List<String> commandlineArguments,
|
||||
Map<String, String> environmentProperties,
|
||||
public TaskLaunchRequest(String uri, List<String> commandlineArguments, Map<String, String> environmentProperties,
|
||||
Map<String, String> deploymentProperties, String applicationName) {
|
||||
Assert.hasText(uri, "uri must not be empty nor null.");
|
||||
|
||||
this.uri = uri;
|
||||
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<>()
|
||||
: commandlineArguments;
|
||||
this.environmentProperties = environmentProperties == null ? new HashMap<>()
|
||||
: environmentProperties;
|
||||
this.deploymentProperties = deploymentProperties == null ? new HashMap<>()
|
||||
: deploymentProperties;
|
||||
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<>() : commandlineArguments;
|
||||
this.environmentProperties = environmentProperties == null ? new HashMap<>() : environmentProperties;
|
||||
this.deploymentProperties = deploymentProperties == null ? new HashMap<>() : deploymentProperties;
|
||||
setApplicationName(applicationName);
|
||||
}
|
||||
|
||||
@@ -125,16 +121,15 @@ public class TaskLaunchRequest implements Serializable {
|
||||
* @param applicationName the name to be
|
||||
*/
|
||||
public void setApplicationName(String applicationName) {
|
||||
this.applicationName = !StringUtils.hasText(applicationName)
|
||||
? "Task-" + UUID.randomUUID().toString() : applicationName;
|
||||
this.applicationName = !StringUtils.hasText(applicationName) ? "Task-" + UUID.randomUUID().toString()
|
||||
: applicationName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskLaunchRequest{" + "uri='" + this.uri + '\''
|
||||
+ ", commandlineArguments=" + this.commandlineArguments
|
||||
+ ", environmentProperties=" + this.environmentProperties
|
||||
+ ", deploymentProperties=" + this.deploymentProperties + '}';
|
||||
return "TaskLaunchRequest{" + "uri='" + this.uri + '\'' + ", commandlineArguments=" + this.commandlineArguments
|
||||
+ ", environmentProperties=" + this.environmentProperties + ", deploymentProperties="
|
||||
+ this.deploymentProperties + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,12 +65,10 @@ public class TaskLauncherSink {
|
||||
Assert.notNull(this.taskLauncher, "TaskLauncher has not been initialized");
|
||||
logger.info("Launching Task for the following uri " + taskLaunchRequest.getUri());
|
||||
Resource resource = this.resourceLoader.getResource(taskLaunchRequest.getUri());
|
||||
AppDefinition definition = new AppDefinition(
|
||||
taskLaunchRequest.getApplicationName(),
|
||||
AppDefinition definition = new AppDefinition(taskLaunchRequest.getApplicationName(),
|
||||
taskLaunchRequest.getEnvironmentProperties());
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource,
|
||||
taskLaunchRequest.getDeploymentProperties(),
|
||||
taskLaunchRequest.getCommandlineArguments());
|
||||
taskLaunchRequest.getDeploymentProperties(), taskLaunchRequest.getCommandlineArguments());
|
||||
this.taskLauncher.launch(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ import org.springframework.context.annotation.PropertySource;
|
||||
@ConditionalOnBean(TaskLifecycleListener.class)
|
||||
@ConditionalOnExpression("T(org.springframework.util.StringUtils).isEmpty('${spring.batch.job.jobName:}')")
|
||||
// @checkstyle:off
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.events", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.events", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
@PropertySource("classpath:/org/springframework/cloud/task/application.properties")
|
||||
@AutoConfigureBefore(BindingServiceConfiguration.class)
|
||||
@@ -55,8 +55,10 @@ public class TaskEventAutoConfiguration {
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public static class ListenerConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskExecutionListener taskEventEmitter(StreamBridge streamBridge, TaskEventProperties taskEventProperties) {
|
||||
public TaskExecutionListener taskEventEmitter(StreamBridge streamBridge,
|
||||
TaskEventProperties taskEventProperties) {
|
||||
return new TaskExecutionListener() {
|
||||
@Override
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
|
||||
Reference in New Issue
Block a user