Commit Graph

2256 Commits

Author SHA1 Message Date
Mahmoud Ben Hassine
76c34c7f72 fix build warnings 2018-11-29 15:17:01 +01:00
Nicolas Widart
131e02e3a3 Add a getJobId convenience method to StepContext
Resolves BATCH-2769
2018-11-07 10:33:05 +01:00
Drummond Dawson
4192bfe01e Replace explicit type with diamond operator in core module 2018-11-06 20:28:08 +01:00
Dimitrios Liapis
e707a57157 Fix javadoc typo in PartitionStepBuilder#gridSize()
Resolves BATCH-2768
2018-11-06 17:07:59 +01:00
Mahmoud Ben Hassine
9e02e935ce Return null instead of 0 when a Long/Double job parameter is absent
Resolves BATCH-2385
2018-11-02 22:21:13 +01:00
Mahmoud Ben Hassine
fb4494b0d0 Add migration script to use characters instead of bytes for oracle db
Resolves BATCH-2091
2018-10-29 10:04:16 -05:00
David J. M. Karlsen
4283291cc8 use VARCHAR( n char) instead of VARCHAR(n) so semantics are used and not number of bytes. This is better when using multibyte charsets like UTF8 2018-10-29 10:04:10 -05:00
Mahmoud Ben Hassine
ebf156d529 Make JobParametersBuilder#getNextJobParameters consistent with CommandLineJobRunner and JobOperator
Before this commit, JobParametersBuilder#getNextJobParameters was checking
for restartability conditions. This is not only already done by the
JobLauncher, but also makes it inconsistent with the behaviour of
CommandLineJobRunner when used with "-next" option and
JobOperator#startNextInstance, which is starting the next instance in
sequence based on the incrementer without dealing with restartability.

This commit fixes the JobParametersBuilder#getNextJobParameters to behave
like the CommandLineJobRunner and JobOperator in regards to starting
the next instance.

Resolves BATCH-2711
2018-10-26 11:44:22 -05:00
Dimitrios Liapis
f8f8a02a4d Explicitly considering Start Time not being null for running Job Executions
This is to exclude from capturing erroneous Job Executions. An example is
whenever a TaskRejectedException is thrown after submitting to the
taskExecutor in SimpleJobLauncher#run(), the JobExecution is left without
a Start or End Time. Also related tests are fixed.

Resolves BATCH-2675
2018-10-25 11:36:21 +02:00
Mahmoud Ben Hassine
76f8cad29a Fix incorrect @Nullable on ItemReadListener#afterRead implementations
Resolves BATCH-2763
2018-10-24 15:37:54 +02:00
Mahmoud Ben Hassine
249fa2673e Fix typos 2018-10-02 22:40:56 +02:00
Mahmoud Ben Hassine
57c4acdf22 Fix Javadoc generation issues on Java 9
1. The first issue is:

```
> Task :api
DefaultBatchConfigurer.java:18: error: cannot find symbol
import javax.annotation.PostConstruct;
                       ^
  symbol:   class PostConstruct
  location: package javax.annotation
DataSourceConfiguration.java:18: error: cannot find symbol
import javax.annotation.PostConstruct;
                       ^
  symbol:   class PostConstruct
  location: package javax.annotation
DefaultBatchConfigurer.java:94: error: cannot find symbol
        @PostConstruct
         ^
  symbol:   class PostConstruct
  location: class DefaultBatchConfigurer
DataSourceConfiguration.java:46: error: cannot find symbol
        @PostConstruct
         ^
  symbol:   class PostConstruct
  location: class DataSourceConfiguration
4 errors
```

This issue is fixed by adding the `javax.annotation-api` dependency

2. The second issue is:

```
javadoc: error - An internal exception has occurred.
(com.sun.tools.javac.code.ClassFinder$BadClassFile: bad class file:
/org/springframework/batch/core/configuration/support/
GenericApplicationContextFactory$ResourceAnnotationApplicationContext$1.class

class file contains malformed variable arity method:
GenericApplicationContextFactory$ResourceAnnotationApplicationContext$1
Please remove or make sure it appears in the correct subdirectory of the classpath.)
```

The workaround to this issue is to use a named inner class instead of
an anonymous one.

Upgrade jacoco to version 0.8.2

Fix failing tests on Java 9

* `javax.xml.bind` is no longer contained in the default class path in
Java SE 9. This commit adds the module `java.xml.bind` to the JVM args
for tests

* JsrBeanDefinitionDocumentReaderTests are failing because
`ClassLoader.class.getResourceAsStream` has a different behaviour on Java 9.
According to `https://stackoverflow.com/a/45173837/5019386`, it's best to
use the resource-lookup methods in Class rather than those in ClassLoader.

* DefaultJobParametersExtractorJobParametersTests#testGetAllJobParameters
is failing because jobParameters.toString() returns "{foo=bar, spam=bucket}"
on Java 9 and "{spam=bucket, foo=bar}" on Java 8. The fix asserts that
jobParameters contains the expected key/value pairs without relying on the
toString method

JIRA: BATCH-2751
2018-09-21 13:48:15 -05:00
Mahmoud Ben Hassine
a68d70043a Allow the transaction manager to be overridden in DefaultBatchConfigurer
Before this commit, it was not possible to override the transaction
manager by subclassing DefaultBatchConfigurer and overriding the
getTransactionManager method.

This commit uses the getTransactionManager method in the initialize method
in order to take into account the transaction manager provided by the user.

Resolves BATCH-2294
2018-08-31 16:33:43 -05:00
Mahmoud Ben Hassine
70d0e3c510 Add JSR-305 annotations to public APIs
(Partially) Resolves BATCH-2688
2018-08-31 15:11:50 -05:00
Mahmoud Ben Hassine
295def2b89 Polish e29f77e01e 2018-08-31 20:29:01 +02:00
Kui Liu
e29f77e01e BATCH-2715: Change the method name "getStartable" to "isStartable".
The method is named as "getStartable". "getStartable" is prone to obtain something. "isStartable" is a query asking whether the stepExecution is startable, which describes what the method is doning. So, "isStartable" should be more intuitive.
2018-08-31 20:08:01 +02:00
Michael Minella
3a2fc7d2ee Removed incorrect @Nullable annotations 2018-07-25 10:53:37 -05:00
Mahmoud Ben Hassine
276acd1960 code review changes 2018-07-23 16:07:37 -05:00
Mahmoud Ben Hassine
24b8d72a7a Add JSR-305 annotations to public APIs
(Partially) Resolves BATCH-2688
2018-07-23 16:07:34 -05:00
Michael Minella
98070e4a1c Polish and updated a test to validate the conditions 2018-05-25 16:46:32 -05:00
woniper
c2b0a208c3 fix up code formatting and typo 2018-05-17 14:45:16 +02:00
Mahmoud Ben Hassine
61bec2805d BATCH-2213: unwrap exceptions thrown from annotated step listeners
Currently, when a method of an annotated listener throws an exception,
the exception is wrapped in a InvocationTargetException (by the reflection
API) which in turn is wrapped in a IllegalArgumentException (by Spring Batch).
This requires the user to unwrap the original exception from the
StepListenerFailedException. This behavior is not consistent with
interface based listeners where the original exception is the root
cause of StepListenerFailedException.

This commit unwraps the original exception and make it the root cause of
StepListenerFailedException.

Resolves BATCH-2213
2018-05-02 11:17:55 -05:00
Pascal Schumacher
29dc4b05bf Remove duplicate blanks in log message 2018-04-16 12:08:11 +02:00
Mahmoud Ben Hassine
2b0532e910 BATCH-2624: add tests on mandatory item reader/writer 2018-04-13 13:11:23 +02:00
Michael Minella
3ccc4ff430 Align XML and Java based configuration
This commit aligns the XML and Java based validations.

When using XML to configure a chunk oriented step both an ItemReader and
ItemWriter are requied. However when using Java based configuration the
ItemWriter is optional if an ItemProcessor is present.

Having no ItemWriter and only an ItemProcessor lead to strange results
in one of our batch jobs, which was accidentily configured without an
ItemProcessor.

Related: BATCH-1520
Fixes: BATCH-2624
2018-04-13 13:11:23 +02:00
Mahmoud Ben Hassine
c1b79e5946 BATCH-2442: fix infinite loop when item processor fails during a scan
Currently, when the processor throws an exception during a scan, the
chunk is never marked as complete and the step never finishes. Moreover,
items that were processed unsuccessfully are still written.

This commit fixes the issue by excluding failed items from the scan.

Resolves BATCH-2442
2018-03-27 14:07:27 +02:00
Mahmoud Ben Hassine
45cf68490d BATCH-2161: Update comment on ScopeConfiguration to match the actual code 2018-03-02 17:06:58 +01:00
Philippe Marschall
202ececcd5 BATCH-2161 ScopeConfiguration methods should be static
The scope bean factory methods in ScopeConfiguration are
BeanFactoryPostProcessors and should therefore be static.

 - Declare the scope beans in ScopeConfiguration as static

Issue: BATCH-2161

(cherry picked from commit 1e938e3)
2018-03-01 21:50:41 +01:00
Mahmoud Ben Hassine
4dc406ef60 BATCH-2564: make AutomaticJobRegistrar implement SmartLifeCycle
Before this commit, the AutomaticJobRegistrar was started on
ContextRefreshedEvent event. This is sometimes too late to register jobs
especially when other life cycle components that use the jobs are started
before this registrar.

This commit changes the AutomaticJobRegistrar to implement SmartLifeCycle
and makes its autoStartup and phase properties configurable.

It should be noted that the "onApplicationEvent" method has been removed
even if it is a public API. This method is not intended to be used by
client code and even if it was, its usage is considered wrong anyway.

Resolves BATCH-2564
2018-02-28 10:51:13 -06:00
Mahmoud Ben Hassine
daf0ecfc9f BATCH-2491: use LinkedHashSet instead of HashSet for command line options
Before this commit, options passed on the command line were collected
in a HashSet. This does not keep options order as they are passed in
the command line.

This commit changes the "opts" variable type to LinkedHashSet.
Note there is no test for this change as "opts" is a local variable to
the main method.

Resolves BATCH-2491
2018-02-26 13:59:08 -06:00
Mahmoud Ben Hassine
1ed5a33bd1 BATCH-2445: make annotation based chunk listeners available to non-fault tolerant steps
Before this commit, annotation based chunk listeners were not registered
when using a non-fault tolerant step builder.

This commit moves the code of chunk listener annotations handling to the
AbstractTaskletStepBuilder so that other tasklet builders can use it.

Resolves BATCH-2445
2018-02-26 12:53:47 -06:00
Mahmoud Ben Hassine
e11b838452 BATCH-2401: fix CPU intensive loop while polling partitions completion
Before this commit, the JsrPartitionHandler was polling partitions
completion continuously. This causes a high CPU usage.

This commit makes the polling thread sleep for a configurable amount
of time in order to decrease CPU usage during the polling period.

Resolves BATCH-2401
2018-02-26 11:47:09 -06:00
Mahmoud Ben Hassine
b0ffe55113 BATCH-2680: add custom Jackson module to (de)serialize job parameters
Currently, the Jackson2ExecutionContextStringSerializer fails to
deserialize json representations of:

* empty JobParameters instances due to the presence of "empty":true
 in the serialized json String. In this case, Jackson is not able to find a
 property named "empty" in the target type (JobParameters)

* JobParameter instances due to the presence of several constructors.
In this case, Jackson does not know which constructor to use.

This commit fixes these two issues by adding a custom Jackson module with:

* a mixin to ignore the "isEmpty" getter in JobParameters type
* a custom deserializer for JobParameter type

Resolves BATCH-2680
2018-02-26 10:43:52 -06:00
Mahmoud Ben Hassine
7a9a2a9c50 BATCH-2537: add support for @Primary annotated data sources
Currently, when multiple data sources are defined in the context, an
IllegalStateException is thrown even if one of the data sources is
annotated with @Primary (which should be the one to use).

This commit makes it possible to use the data source annotated with
@Primary when multiple data sources are defined. Note that the context
initialization will still fail (with a UnsatisfiedDependencyException
from Spring's bean factory) if multiple data sources are defined and
none of them is annotated with @Primary. If multiple data sources are
defined and none of them is annotated with @Primary but one of them is
named "dataSource", this data source will be used by the batch
configuration due to autowiring by name (this detail has been documented
in the javadoc of @EnableBatchProcessing).

Resolves BATCH-2537
2018-02-26 10:19:08 -06:00
Mahmoud Ben Hassine
79f3a67883 BATCH-2397: fix parameters handling in MethodInvokingTaskletAdapter
When a tasklet is declared with xml using the shortcut version, the
MethodInvokingTaskletAdapter that is created automatically does not
address passing parameters expected by Tasklet#execute (which is
incorrect since the documentation of the schema attribute "method"
says the bean should define a method with the same signature).

This commit fixes parameters passing when using the shortcut version.

Resolves BATCH-2397
2018-01-26 13:15:20 -06:00
Mahmoud Ben Hassine
c78701a871 BATCH-2663: re-initialize filter count when scanning a chunk
Before this commit, the filter count of the contribution was applied
for each item of a scanned chunk. For example, with a chunk of 30,
if the filter count is 10 and an item is skipped during write, then the
filter count is equal to 210 (10 + 20 * 10).

If this commit is applied, the filter count will be re-initialized when
scanning the chunk.

Resolves BATCH-2663
2018-01-24 15:09:07 -06:00
Mahmoud Ben Hassine
d81ab76823 BATCH-2667: update warning message to be more explicit
Before this commit, when a job execution is stopped from a different
JVM than the one running the job, a warning says that the job cannot
be found. This was confusing to some users since the job can be found
in the database (but is actually not defined in the job registry of
the application context of the second JVM).

After this commit is applied, the warning will be more explicit to
inform the user that the job cannot be found in the job registry
(to not be confused with the database)

Resolves BATCH-2667
2018-01-19 21:24:06 +01:00
Michael Minella
7a3a72f5ca Updated copyright date 2017-11-30 15:28:12 -06:00
Alexis Hafner
3a3404412c BATCH-2543 New method on DefaultBatchConfigurer 2017-11-30 15:20:01 -06:00
Michael Minella
f61679b55f Added updates for properties files as well 2017-11-27 12:06:29 -06:00
Michael Minella
8a223e35c6 Fixed javadoc for JobOperator#abandon
The javadoc in the `JobOperator#abandon` indicated that a JobExecution
marked as `ABANDONED` can be restarted (it cannot).

Resolves BATCH-2654
2017-11-22 09:19:03 -06:00
Eduardo Jolo
509be945fc Set the StepExecution ExitStatus in the JobStep doExecute 2017-11-02 12:56:09 -05:00
Michael Minella
fa286dc1e9 Refactored JobExecution for performance
In order to make the Map based JobRepository threadsafe, the
JobExecutino was modified to use a `CopyOnWriteArraySet` for the
collection backing the child `StepExecution` collection.  However, this
collection option has bad performance characteristics when used with
large collections.  When using partitioning, it can be common to have a
large number of `StepExecution` instances to add which drastically hurts
start up time.

This commit remove the use of the `CopyOnWriteArraySet` for the
`JobExecution#stepExecutions` and replaces it with a `LinkedHashSet`
wrapped via `Collection.synchronizedSet`.

Resolves BATCH-2384
2017-11-02 12:38:35 -05:00
Daniel Heinrich
9322fe6fae BATCH-2455 unifie listener ordering
Why:
Listeners should be called in normal order before some event
(i.e. read, write) and after that event in reverse order.

Side effects:
The ordering of Chunk and ItemReader Listeners is changed and will
change some behaviors of users. This change is still neccesary because
it is not only the correct and obviouse way, but also prevents new
users to hack around this problem.
2017-11-02 10:29:09 -05:00
Michael Minella
e5fe6a5de6 Updated DefaultBatchConfigurer to not overwrite when autowiring
This commit prevents autowiring from overwriting a value set for the
`DataSource` if it has already been set.

Resolves BATCH-2636
2017-11-02 09:58:11 -05:00
Michael Minella
52d2c257c5 Version updates 2017-10-23 15:52:55 -05:00
Michael Minella
b2f8f7f9cd Refactored to add a way to copy JobParameters into another via builder
In a previous commit, the JobParametersBuilder was updated to include
some code from Spring Boot that handled the incrementing of
JobParameters for a previous job.  That commit brought over a private
`merge` method that is actually useful for general consumption.

This commit adds a `addJobParameters` method to the builder providing
the same functionality the `merge` method did in a public method.
2017-10-20 12:43:06 -05:00
Michael Minella
63dfe4b912 Polish 2017-10-20 11:57:56 -05:00
Glenn Renfro
a35784dbd6 Support getNextJobParameters from JobParametersBuilder.
resolves BATCH-2640

Cleanup and added tests to JobParametersBuilder.
2017-10-20 11:06:04 -05:00
Michael Minella
24fbb882e6 Updated job.adoc to have java config examples
This commit addresses the job.adoc and how to configure the various
pieces of the framework it covers via java configuration.
2017-10-18 12:00:27 -05:00