allthingssecurity opened a new pull request, #30534:
URL: https://github.com/apache/camel/pull/30534

   # Description
   
   [CAMEL-27287](https://issues.apache.org/jira/browse/CAMEL-27287)
   
   With `durableJob=true` and the default `deleteJob=true`, a Quartz endpoint 
unschedules its trigger when it stops (the route is removed, or CamelContext 
stops), and Quartz keeps the durable job, as `durableJob` asks. The next 
endpoint with that trigger key found no trigger and called 
`scheduleJob(jobDetail, trigger)`, which failed with 
`ObjectAlreadyExistsException` because the job was still stored. So a route 
such as `from("quartz://myGroup/myTimer?durableJob=true&cron=...")` could not 
be added again after it was removed (a route reload in dev mode, or a route 
removed and added at runtime), and with a persistent (JDBC) job store the 
application failed to start every time after it had stopped once. A clustered 
job store is not affected by the stop (the endpoint does not unschedule there), 
but a durable job whose trigger was removed in another way (a simple trigger 
that fired its last repeat, which Quartz removes, or the Quartz API) failed 
there with `SchedulerException: Trigger cou
 ld not be found in quartz scheduler.`; it is now scheduled again as well.
   
   A route stop/start is not affected: it only pauses and resumes the trigger.
   
   This is the endpoint side of the case that CAMEL-27171 (#30354) handled in 
`QuartzScheduledPollConsumerScheduler` (a durable job whose trigger was removed 
in between).
   
   Fix (`QuartzEndpoint.addJobInScheduler`): when `scheduleJob` fails with 
`ObjectAlreadyExistsException`, the trigger is not in the scheduler and the job 
is, the endpoint stores its own job in place of the stored one and schedules it 
with the trigger (`scheduleJob(jobDetail, Set.of(trigger), true)`, one store 
call). The job of the endpoint is used rather than the stored one because its 
data names this endpoint and CamelContext (`updateJobDataMap`), and its class 
and parameters follow the current options (`stateful`, `jobParameters`). Every 
other case is unchanged: an existing trigger is still reused (and rescheduled 
when changed), and `ObjectAlreadyExistsException` with the trigger present 
still fails outside a clustered store.
   
   Not changed (noted for reviewers): a simple trigger that fired for the last 
time (`trigger.repeatCount`) is removed by Quartz; a route stop/start does not 
schedule it again (the endpoint keeps `jobAdded` and only resumes), with or 
without `durableJob`. That is the existing behaviour and not part of this fix.
   
   Tests: `QuartzDurableJobScheduleAgainTest` (RAM job store, the scheduler of 
the component): (1) a durable route is stopped, removed and added again: the 
trigger is gone, the job is still stored, and the route added again must fire; 
(2) a durable job without trigger is already in the scheduler (what a 
persistent store keeps after the application stopped), then the route is added: 
it must fire, and the stored job must now carry the endpoint URI of the new 
endpoint. Quartz 2.5.2 checked with javap: `QuartzScheduler.scheduleJobs` sets 
the job key of each trigger and computes its first fire time before 
`JobStore.storeJobsAndTriggers(map, replace)`. Runs (offline, Quartz 2.5.2): 
both tests fail on main (`FailedToCreateRouteException` caused by 
`ObjectAlreadyExistsException: Unable to store Job : 'durable.myTimer', because 
one already exists with this identification.`) and pass with the fix; 
camel-quartz module tests 137 run, 0 failures except 
`QuartzAddRoutesAfterCamelContextStartedTest
 ` (expected 2 fires within 30 s, got 1, on a loaded machine; it does not use a 
durable job and passed in the rerun together with `QuartzAddDynamicRouteTest` 
and `QuartzPauseJobRouteAddedAgainTest`, 10 run, 0 failures); the new test 
class 20 times in one JVM: 40 of 40.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-27287](https://issues.apache.org/jira/browse/CAMEL-27287).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built the core modules and camel-quartz with the formatter and 
import-sort plugins. No option or generated file changed. I did not run the 
full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to