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 job cancellation capability for IRS #947

Closed

Conversation

ds-pweick
Copy link

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 calls submit 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 added ResponseStatus of NOT_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, JobExceptions are created using a newly added constructor. This constructor allows for directly setting the error detail.

  • JobOrchestrator

    • A 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's cancelRequest method. In each iteration, if cancelRequest throws a JobException, the method evaluates what happened based on the error detail that was specified when creating the Exception in cancelRequest. This detail is then used to construct an error message, which is uploaded to the job store using markJobInError.
  • 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 calls cancelJob in JobOrchestrator.

  • Unit tests for AASTransferProcessManager and JobOrchestrator have been modified accordingly.

⚠️ IrsWireMockIntegrationTest does not have tests for this new functionality yet.

@ds-pweick ds-pweick closed this Jun 10, 2024
@ds-pweick ds-pweick deleted the feature/411-irs-job-cancellation branch June 26, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant