Added job cancellation capability for IRS #947
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Job cancellation in IRS using Java interrupts
This PR addresses issue eclipse-tractusx#411.
AASTransferProcessManager
When a new thread is taken from the thread pool to execute a new transfer process, instead of using
execute
, the code now callssubmit
for the created Runnable. This returns a Future, which is then stored in a ConcurrentHashMap. The map's keys are the uuid strings of the transfer processes, thus making it possible to associate a transfer process id with the task it represents.To make use of this, there is now a
cancelRequest
method which retrieves a Future from the map using a transfer process uuid string argument. Then,cancel(true)
is called on that Future, which sets the interrupt flag for the thread executing the transfer process. Afterwards, the entry for that transfer process is removed from the map.Before initiating a request, this interrupt flag is checked. If it is set, the transfer process is not started and a
TransferInitiateResponse
is returned with a newly addedResponseStatus
ofNOT_STARTED_JOB_CANCELLED
.In case of the unhappy path, where the map somehow doesn't contain an entry for a transfer process or something goes wrong when setting the interrupt flag,
JobException
s are created using a newly added constructor. This constructor allows for directly setting the error detail.JobOrchestrator
cancelJob
method has been added which is called when the IRS receives a job cancellation request. It uses a passed MultiTransferJob argument to get all transfer process ids for the job that is to be cancelled and iterates over the collection of ids calling AASTransferProcessManager'scancelRequest
method. In each iteration, ifcancelRequest
throws aJobException
, the method evaluates what happened based on the error detail that was specified when creating the Exception incancelRequest
. This detail is then used to construct an error message, which is uploaded to the job store usingmarkJobInError
.BaseJobStore's
writeLock
now reliably triggers an InterruptedException, which allows to cancel any change to a job from one of the interrupted threads running the transfer processes.IrsItemGraphQueryService's
cancelJobById
now callscancelJob
in JobOrchestrator.Unit tests for AASTransferProcessManager and JobOrchestrator have been modified accordingly.
IrsWireMockIntegrationTest
does not have tests for this new functionality yet.