Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for dynamic spring batch job invoication based on message header #968

Closed
wants to merge 6 commits into from
Closed

Conversation

jlpedrosa
Copy link
Contributor

@davsclaus
Copy link
Contributor

Can you run checkstyle and fix those issues

mvn compile -Psourcecheck

in the directory with the component.

Also the header name should use naming: CamelComponentNameHeaderName, eg CamelSpringBatchXXXXX

@@ -83,7 +85,7 @@ protected void doStart() throws Exception {
if (jobLauncher == null) {
jobLauncher = resolveJobLauncher();
}
if (job == null && jobName != null) {
if (job == null && jobName != null && jobName.compareTo("dynamic")!=0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dynamic".equals(jobName)? But, what is wrong on setting initial jobName in URI path? AFAIK this concept is not used anywhare in Camel, so please remove the check for "dynamic".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi as jobName is the path and can't be made null beacause it's mandatory, "dynamic" keyword is used to omit the lookup of the Job and allow dynamic lookup based on message. Due to camel URI schema it's IMPOSSIBLe as you said in the ticket to make it null, so I need a keyword to know when it should be ignored. please check the ticket and your answer.

@davsclaus
Copy link
Contributor

Can't you just use a dummy job name, and if there is a header that header take precedence. Or is there some pre-validation in the producer that a job with that name must exists?

}
}

if (job2run == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is rednudant, this.job is never null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's not redundant. if the jobName is dynamic, then the job will be set to null by the Endpoint.

@jlpedrosa
Copy link
Contributor Author

Hi, I was not aware of -Psourcecheck flag, I've added a new commit with the changes to correct the style warnings, sorry for the inconvenience.

Can't you just use a dummy job name,
that is exactly what it is a word to avoid in the enpoint looking for the job...
look this is current URI for springbatch
from("direct:start").to("spring-batch:mockJob").to("mock:test");

where jobName is mockJob so I can't add this feature without breaking the backwards compatibility.. as jobName is the UriPath and it's mandatory, I can't just remove it, so I use "dynamic" As a dummy job from("direct:dynamic").to("spring-batch:dynamic").

@@ -25,6 +25,7 @@
public class SpringBatchComponent extends UriEndpointComponent {

private static final String DEFAULT_JOB_LAUNCHER_REF_NAME = "jobLauncher";
public static final String DYNAMIC_JOBNAME = "DYNAMIC_JOBNAME_HEADER";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static final String JOB_NAME = "CamelSpringBoot.jobName";

@jlpedrosa
Copy link
Contributor Author

can we chat aboit this? skype? id: jlpedrosa

@jlpedrosa
Copy link
Contributor Author

Is it clear now why the dynamic is mandatory? There are no style check warnings, existing tests and new ones are passing.
Ok now? I'm available for discussing/explaining.

Rgds

JL

@trohovsky
Copy link
Contributor

You intention for using "dynamic" in URI path is clear form beginning, but as I said, it is not good to create such a convention. What if somebody wants to name the job "dynamic" (or already named) and actually don't select the job by the new header?

@jlpedrosa
Copy link
Contributor Author

That point you said of someone using the job name "dynamic" is the only
downside. What I am trying to achieve is being backwards compatible.

We could do something more elaborated like:
Springbatch:dynamic
Springbatch:static:jobName
But this would break backwards compatibility, if you want we can make the
keyword "use_message_header" so it's "absolutely" (the fake job sugested by
Claus) impossible that anyone wants to use it.

Due to the sytax uri constrains the path must be set, even if (like in this
case) needs to be set.

So options)

  1. use dynamic (or more elaborated keyword)
  2. break backwards compatibility
  3. send patch to trash
  4. any other idea?

I think 1) is the way forward.
On Apr 28, 2016 9:10 PM, "Tomas Rohovsky" notifications@github.com wrote:

You intention for using "dynamic" in URI path is clear form beginning, but
as I said, it is not good to create such a convention. What if somebody
wants to name the job "dynamic" (or already named) and actually don't
select the job by the new header?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#968 (comment)

@trohovsky
Copy link
Contributor

Does a use case, that no job is known from beginning, really exist? I don't think so. If yes, then recipientList or toD are still in the game.

@jlpedrosa
Copy link
Contributor Author

Hi Tomas

I understand you think drop the patch is best and use tod.

In my opinion:
Force to have a know job is more complicated than having a dynamic tag.

In my use case I don't know any job during the route creation, as I'm
mixing this with kafka to create a generic kafka interface for a job
launcher.

And I doubt anyone would try to create a job with name "dynamic" or
"use_header_jobname".

As I said in the Jira ticket, toD would work for me, but as Claus pointed
out it would create unncesaary amount of endpoints/producers.

Regards
On Apr 28, 2016 22:09, "Tomas Rohovsky" notifications@github.com wrote:

Does a use case, that no job is known from beginning, really exist? I
don't think so. If yes, then recipientList or toD are still in the game.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#968 (comment)

@trohovsky
Copy link
Contributor

trohovsky commented Apr 29, 2016

I am not for rejecting the patch at all, I just don't like using a constant path to achieve a no-job endpoint during startup.

@jlpedrosa
Copy link
Contributor Author

jlpedrosa commented Apr 29, 2016

Tomas,

I agree with you, having a magic keyword, it's not a perfect solution, but
I can't see any other way without breaking backwards compatibility.

So options)

  1. use dynamic or more elaborated "keyword" as path
  • Not perfect from cleannes poing of view
  • Keeps backwards compatibility.
  • Keeps single endpoint
  1. Use a more sofisticated path like springbatch:(dynamic|static:jobName)
  • Clean solution
  • Break backwards compatibility
  • Keeps single endpoint
  1. Don't do the dynamic header jobname and use tod (so, send patch to trash)
  • Clean solution
  • keeps backwards compatibility
  • mutliple endpoint
  1. don't use dynamic or more elaborated "keyword" as path, and force to
    have an existing job at compilation
  • Not perfect from cleannes poing of view (force to have a job is not
    clean)
  • Keeps backwards compatibility.
  • Keeps single endpoint
  1. any other idea?

maybe the answer is mixed? 2) for 2.18 and 1) for 2.17?

Tomas, Claus is your call.

On Fri, Apr 29, 2016 at 10:28 AM, Tomas Rohovsky notifications@github.com
wrote:

I am not for rejecting the patch at all, I just don't like using any
constant path to achieve a no-job endpoint during startup.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#968 (comment)

}

@Test
public void dynamicJobWorksIfHeaderWithInvalidJobName() throws Exception {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this test be named dynamicJobFailsIfHeaderWithInvalidJobName with the word Fails replacing the word Works ?

@davsclaus
Copy link
Contributor

We can add a query option jobFromHeader you can set to true,then it will ignore the job name you set in the context path.

@jlpedrosa
Copy link
Contributor Author

Ok, that´s ok, I’ll implement it on monday, is it enough?

On 07 May 2016, at 10:00, Claus Ibsen notifications@github.com wrote:

We can add a query option jobFromHeader you can set to true,then it will ignore the job name you set in the context path.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub #968 (comment)

@davsclaus
Copy link
Contributor

Yeah sounds good. Maybe open a new PR with the jobFromHeader so its easier to review

@davsclaus
Copy link
Contributor

@jlpedrosa are you able to work on a new PR?

@jlpedrosa
Copy link
Contributor Author

Hi Claus

Yes, I'll get it done next week, is it ok?
On May 21, 2016 7:46 AM, "Claus Ibsen" notifications@github.com wrote:

@jlpedrosa https://github.com/jlpedrosa are you able to work on a new
PR?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#968 (comment)

@davsclaus
Copy link
Contributor

Yes thats fine

Joseluis Pedrosa added 2 commits May 27, 2016 12:55
@jlpedrosa
Copy link
Contributor Author

Contiunued in
#1001

as a sugestion of @davsclaus

zregvart pushed a commit to zregvart/camel that referenced this pull request Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants