This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

JobParametersValidator validate after the job was launchedPage Title Module

JobParametersValidator validate after the job was launched

Jan 6th, 2010, 09:28 AM

Hi,

It seems that the JobParametersValidator it is possible to specify for each job is executed only into the execute method of AbstractJob. This has for consequence that it not possible to be informed if the validation fail, except by looking at the status of the job. Plus, as far as I've seen, it is not possible to get a reference to that JobParametersValidator instance.

I can understand why the job validate itself when it is launched, but the bad point is that, in most use cases I can imagine, I want to validate those parameters before the job is launched.

For example, if we have a generic web interface to launch any type of jobs and specify parameters. If we put wrong parameters for a job we would like to get an error message right now, not think that the job launched correctly and see later in the logs that it failed just because the parameters were wrong.

Another example, but here we want to validate the parameters without launching the job at all: we use a quartz scheduler and we have a web interface that allow us to specify scheduling and parameters for a job, it would be cool to have the parameters validated when we schedule a job and not when it is effectively launched.

To make those examples possible using the JobParametersValidator mechanism already implemented, don't you think it would be a good idea to put the JobParametersValidator instance already in AbstractJob accessible from the Job interface?

Comment

Agreed, but we didn't want to do that in a point release. In Batch 3.0 the Job interface might change, but not in 2.1.

You can always inject the same validator into a Job and into another component that is used before the launch.

Fair enough.

Let me give you a bit of background. We are implementing a thin layer on top of the Job launcher that adds added value to the default behavior of a batch launch. Ideally, we want to reuse what batch developers (not us!) have configured on their job.

In this particular case, we would like to simply reuse the validator that has been defined on the job without requiring our "users" to define it twice. We're good with some kind of home-made repository that would scan the jobs and retrieve the validators but right now, casting is the only solution. It's not a big deal but a cleaner solution is always better