Back Forum Reply New

Can jobs inherit steps?

I'm trying to inherit a job definition, as outlined in the reference documentation. My configuration looks like this:Code:
lt;batch:job id=quot;flatFileImportJobquot; gt;   lt;batch:decision id=quot;inputExistsDecisionquot; decider=quot;inputExistsDeciderquot;gt;     lt;batch:next on=quot;NO INPUTquot; to=quot;noInputStepquot;/gt;     lt;batch:next on=quot;*quot; to=quot;importMasterquot; /gt;   lt;/batch:decisiongt;   lt;batch:step id=quot;noInputStepquot; parent=quot;dummyStepquot;/gt;   lt;batch:step id=quot;importMasterquot; parent=quot;simplePartitionMasterquot;/gt;
lt;/batch:jobgt;

lt;batch:job id=quot;usageListImportJobquot; parent=quot;flatFileImportJobquot; gt;
lt;/batch:jobgt;
When I attempt to run usageListImportJob, it throws an exception; here's the relevant bit:Code:
Caused by: java.lang.IllegalArgumentException: No start state was found. You must specify at least one step in a job.
at org..batch.core.job.flow.support.SimpleFlow.initializeTransitions(SimpleFlow.java:215)
at org..batch.core.job.flow.support.SimpleFlow.afterPropertiesSet(SimpleFlow.java:112)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 24 more

The child job is not inheriting the steps from the parent job. If I add a step to the child job it executes only that step, and not the steps from the parent.

The job inheritance example in the reference doc shows only listener inheritance; are only certain properties supported using job inheritance?

You are correct: steps are not inherited.  The purpose of job/step inheritance is to inherit the configuration settings of the job/step to make them reusable.  It doesn't make as much sense to inherit steps because they generally wouldn't be reusable in the same way.  There would also be no way to add flow behavior to the inherited steps, so flow could not travel from an inherited step to a non-inherited step.

If you have a step (or series of steps) that are only executed in certain conditions you can either:
1) Define all of the steps externally (as quot;standalonequot; steps), use parent= attributes on all of the steps, and copy the flow into multiple jobs, or
2) Use a decider in the job to execute the step(s) based on certain conditions.

Thanks for the reply. I came to realize there were some problems, both in theory and in implementation, with step inheritance in jobs.

What I'm trying to implement is the template design pattern at the job level. That is, I want to define the series of steps at the parent job level, and each child job would provide concrete implementations for each of those steps. I can't do this using job inheritance, so if anyone has any alternative suggestions, I would be most grateful.

I'm also trying to do similar things: define a template step flow with default concrete implementations for each step, then allow a child job to override just the ones it needs overriding, without copy and pasting all the config files every time a child job is created. What would be the best way to do this?
Thanks!

The lt;job/gt; element in the batch namespace doesn't support the behavior you are describing.  You could do it by writing your own FactoryBean, but I wouldn't really recommend it.  Most batch job flows are simple enough that copying and pasting the flow shouldn't really be a problem.
¥
Back Forum Reply New