-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add a property to all for Batch JobParameters to enable configuration via environment variables #23411
Comments
If I understand the request correctly, we can probably add a field to The only thing that feels a bit odd to me is using serialized JSON for the properties. We currently delegate to I wonder if we can get away with a simpler format? Perhaps a list of ':' delimited items? e.g:
|
You understand the request correctly. As for the use of JSON for the properties, that really was just following the model of the One other note. We'd like to get this into Boot 2.4 since it is actually impacting a SCDF use case currently. We can do the PR if that helps. |
I've reserved this one for a conference event that's happening early Oct. Hopefully someone will take this on for that, if not, I'm sure we can work together to get something in for 2.4. |
I am a bit confused. @mminella approved this but, on the other hand, talks about environment variables. I don't think we should update Wouldn't we detect that |
This commit adds a "spring.batch.job.parameters" property that can be used to specify the job parameters that should be used to run jobs on startup. This property can be specified as a comma-separate list of "key=value" pair or as an indexed list in case one of the value contains a comma. If the property is set, it takes precedence over application arguments and is parsed using the same converter. Closes spring-projectsgh-23411
This commit adds a "spring.batch.job.parameters" property that can be used to specify job parameters that should be used to run jobs on startup. This property can be specified as a comma-separate list of "key=value" pair or as an indexed list in case one of the value contains a comma. Each parameter specified this way are parsed using the same converter used to parse application arguments. If a job parameter is specified both using the property and an application argument, the latter takes precedence. Closes spring-projectsgh-23411
OK so I've tested something that exposes a Something I didn't catch initially on this issue but a discussion with @mminella revealed. It is important that application arguments still override whatever has been specified using this property. I've pushed a proposal in snicoll@cc9f02b and welcome any feedback. Thanks! |
@snicoll I took the JSON approach to this issue. https://github.com/cppwfs/spring-boot/tree/BOOT-23411 . |
Yes, I've read the diff in the PR you've raised @cppwfs. As I've mentioned there, we're not keen to use json for this. Please review the commit I've reference above and let me know if there is any problem. Thank you. |
@snicoll Thank you for creating this branch. I had a chance to run some of our tests from data flow. The only scenario that I can see that this branch does not cover is when a user has embedded commas in the job param. i.e. |
Thanks for reviewing.
There is an explicit mention of that use case in the commit that I've shared. It is mapped to a list so we need a separate to split the various elements. If you have a comma, you can specific the parameters with an index (one property per value) rather than a single value with everything. We could also consider changing the separator if that helps. |
Hello @snicoll, |
If we implement 1 (the ability to pass parameters via properties) while ignoring 2 (the need to specify which Job gets each job parameter), we're likely to need to make breaking changes to 1 when we subsequently tackle 2. We already know that passing parameters via the command line is broken in this regard. It would seem foolish to make the same mistake again when adding support for providing job parameters via the environment. It seems to me that we have two ways forward here:
Option 1 would breaking things for the users that are combining multiple jobs for many reasons but would allow property-based parameter support to be implemented relatively easily. Option 2 would seem to require us to take a step back and agree on how to provide parameters in a per-job basis and then add the environment as input to that as a second step. |
While not our recommendation, 1 would be a jaring change for many users. I know it is a common question about how to package multiple jobs into a single artifact and run only the one that matters at that time (they wish to avoid having an artifact per job). I would vote for option two if we are going to address both issues at once. |
There's a difference between packaging multiple jobs into a single artifact and running multiple jobs at the same time. If the goal is to avoid having one artifact per job, we could support that while also requiring that we only execute one job. If the context only contains a single job, we execute it. If the context contains multiple jobs, we require that a property be used to identify the job to execute. This is what @snicoll described above. We'd rename Before we can make progress on this, I think the first thing we need to decide is whether or not we want to continue to support executing multiple jobs at the same time. That's the default behaviour at the moment and we also have a property that can be used to specify the jobs that are executed if you don't want to execute all of them. Users that package multiple jobs in the same artifact but only execute one of them would be unaffected by this, other than a possible change to the property name used to identify the job to execute. Users that package multiple jobs in the same artifact and execute all of them would be adversely affected as they'd either have to start the same artifact n times or split it into n different artifacts and start each of them. |
|
@wilkinsona Looking into this now. There are a lot of details discussed here, so I will check and get back to you asap. |
I will let the boot team decide on that, but I would not continue the support for running multiple jobs at the same time, because this is problematic in many ways: Same arguments are passed to all jobs (as mentioned by Stephane), mixed logs, ambiguous job execution order(ing), confusing exit code, etc. I can elaborate on each of those, but I believe there are obvious reasons why the current behaviour is confusing. So following the unix philosophy of making one thing do one thing and do it well, I would change the current behaviour to run a single job at a time. Now regarding the initial feature request of adding support to pass job parameters through environment variables, I am not sure I fully understand the problem that led to this request. Here is what I understand from the original issue (spring-cloud/spring-cloud-dataflow#4119): SCDF tries to restart a failed job execution with a command similar to
That's why I would like to fully understand the problem before thinking of or proposing a solution. FTR, we have a meeting planned this week with @cppwfs to discuss the matter, and I would like someone from the boot team to join. As a side note, this |
Hello All,
Thoughts? |
Based on what @benas has said above, I don't understand how this will help as
When is this meeting scheduled? |
Hello @wilkinsona ,
|
As just discussed with @cppwfs and @benas, we don't think that Boot is the right place to solve this as it's a more general problem. SCDF is responsible for mapping command line arguments to environment variables in situations where the entry point cannot consume command line arguments. When the common line argument's name contains characters that are illegal in an environment variable's name, it performs a mapping to something that is legal. It then needs to perform the reverse of this mapping so that the transformed environment variables are turned back into their original command line arguments and made available to the application. We also discussed the possibility of Batch being able to consume job parameters from sources other than the command line. This would be a new Batch feature that @benas is happy to consider should there be sufficient demand. My feeling was that if sources other than the command line are going to be considered, using Spring Framework's |
I've opened #25373 so that we can deprecate support for running multiple jobs. |
Currently the only way for a user to provide Spring Batch Job Parameters is via command line args. This requested enhancement is to create a Boot property that accepts JSON to be deserialized into
JobParameters
. This is needed for the Kubernetes functionality when you attempt to restart a job using theshell
entry point on your image. In this use case, there is no way to pass command line arguments to the application and some elements of normal parameters are not friendly to being set as environment variable names (run.id(long)=5
for example). I'd assume that the order of precedence for resolving duplicateJobParameters
would follow the normal Boot conventions.The text was updated successfully, but these errors were encountered: