Skip to content

Migrate CancelTaskAPI to JAX-RS #4180

Open
epugh wants to merge 14 commits intoapache:mainfrom
epugh:copilot/migrate-cancel-task-api
Open

Migrate CancelTaskAPI to JAX-RS #4180
epugh wants to merge 14 commits intoapache:mainfrom
epugh:copilot/migrate-cancel-task-api

Conversation

@epugh
Copy link
Contributor

@epugh epugh commented Mar 3, 2026

Migrates CancelTaskAPI from the homegrown @EndPoint annotation to standard JAX-RS, and replaces the manual GenericSolrRequest usage in the integration test with the code-generated TasksApi.CancelTask SolrJ client.

API interface (solr/api)

  • New CancelTaskApi interface with @Path, @GET, @QueryParam JAX-RS annotations using @StoreApiParameters for core/collection path support
  • Returns FlexibleSolrJerseyResponse (instead of SolrJerseyResponse) so the dynamic cancellationResult field is captured via @JsonAnySetter when deserializing

Server implementation (solr/core)

  • CancelTaskAPI extends JerseyResource, implements CancelTaskApi, uses @Inject for SolrCore/SolrQueryRequest/SolrQueryResponse
  • Delegates to QueryCancellationHandler.handleRequestBody() (logic stays in V1 handler), then copies non-header entries from solrQueryResponse into the returned jersey response — required because Jersey's JSON path serializes the returned object directly, not solrQueryResponse
  • QueryCancellationHandler now uses getJerseyResources() / empty getApis() instead of AnnotatedApi

Test

Uses the generated TasksApi.CancelTask with SolrJettyTestRule. The generated class handles V2 URL routing (/api/… vs /solr/…) automatically via getApiVersion() == V2, eliminating the need to construct a separate V2 HttpSolrClient.

Copilot AI and others added 6 commits March 3, 2026 01:48
Co-authored-by: epugh <22395+epugh@users.noreply.github.com>
…ericSolrRequest

Co-authored-by: epugh <22395+epugh@users.noreply.github.com>
@epugh epugh requested a review from Copilot March 3, 2026 12:28
@epugh epugh marked this pull request as ready for review March 3, 2026 12:28
@epugh epugh changed the title Migrate CancelTaskAPI to JAX-RS and use generated SolrJ client in tests Migrate CancelTaskAPI to JAX-RS Mar 3, 2026
@Operation(
summary = "Cancel a currently-running task",
tags = {"tasks"})
FlexibleSolrJerseyResponse cancelTask(@QueryParam("queryUUID") String queryUUID) throws Exception;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the Ref Guide https://solr.apache.org/guide/solr/latest/deployment-guide/task-management.html#taskuuid-parameter we refer when listing tasks to taskUUID but here we have queryUUID, which we also refer to in https://solr.apache.org/guide/solr/latest/deployment-guide/task-management.html#cancelling-an-active-cancellable-task, but then also call it a taskUUID! I don't know that we want to get into fixing the APIS as part of the migration, but this one does seem werid. If someone else confirms it, at a minimum we should open a JIRA. But maybe this is targeted enough to fix here? Seems like it should be taskUUID and honestly, maybe just taskID?

final FlexibleSolrJerseyResponse response =
request.process(solrTestRule.getSolrClient(DEFAULT_TEST_COLLECTION_NAME));
assertNotNull(response);
assertEquals("not found", response.unknownProperties().get("cancellationResult"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the unknownProperties is an aspect of hte FlexibleSolrJerseyResponse

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the query-cancellation “cancel task” endpoint from Solr’s legacy @EndPoint API wiring to JAX-RS, and updates the integration test to use the generated SolrJ client and a flexible response model that can capture dynamic fields.

Changes:

  • Introduces a new JAX-RS CancelTaskApi interface under solr/api using @Path, @GET, and @QueryParam.
  • Refactors core-side wiring so QueryCancellationHandler registers CancelTaskAPI as a Jersey resource (instead of using AnnotatedApi), and CancelTaskAPI adapts handler output into FlexibleSolrJerseyResponse.
  • Adds an integration test that calls the endpoint using the generated TasksApi.CancelTask request class.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
solr/core/src/test/org/apache/solr/handler/admin/api/CancelTaskAPITest.java Adds an integration test using the generated TasksApi.CancelTask client and asserts the flexible response captures cancellationResult.
solr/core/src/java/org/apache/solr/handler/component/QueryCancellationHandler.java Switches v2 exposure from AnnotatedApi to Jersey resource registration (getJerseyResources).
solr/core/src/java/org/apache/solr/handler/admin/api/CancelTaskAPI.java Implements the new JAX-RS interface and adapts handler output into FlexibleSolrJerseyResponse.
solr/api/src/java/org/apache/solr/client/api/endpoint/CancelTaskApi.java Adds the JAX-RS endpoint definition for canceling tasks under the index path prefix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

epugh and others added 8 commits March 3, 2026 07:38
…kAPI.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…kAPI.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…skApi.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants