gerlowskija commented on code in PR #4180: URL: https://github.com/apache/solr/pull/4180#discussion_r3046185031
########## solr/core/src/test/org/apache/solr/handler/admin/api/CancelTaskAPITest.java: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.admin.api; + +import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP; +import static org.apache.solr.security.AllowListUrlChecker.ENABLE_URL_ALLOW_LIST; + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.client.api.model.FlexibleSolrJerseyResponse; +import org.apache.solr.client.api.model.IndexType; +import org.apache.solr.client.solrj.request.TasksApi; +import org.apache.solr.common.util.EnvUtils; +import org.apache.solr.util.ExternalPaths; +import org.apache.solr.util.SolrJettyTestRule; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; + +/** Integration tests for the {@link CancelTaskAPI} V2 endpoint. */ +public class CancelTaskAPITest extends SolrTestCaseJ4 { Review Comment: [0] Looks like a good bit of duplication between this and the existing `TestTaskManagement`. Maybe it makes sense to drop this new test class, and instead modify TestTaskManagement to sometimes use the v2 version of the API? ########## changelog/unreleased/migrate-cancel-task-api.yml: ########## @@ -0,0 +1,7 @@ +title: Migrate CancelTasksAPI to JAX-RS. Cancel Task API now has OpenAPI and SolrJ support. +type: changed Review Comment: [0] We've added a whole new SolrRequest/SolrResponse to SolrJ - this would probably be better as "added" IMO. ########## changelog/unreleased/migrate-cancel-task-api.yml: ########## @@ -0,0 +1,7 @@ +title: Migrate CancelTasksAPI to JAX-RS. Cancel Task API now has OpenAPI and SolrJ support. Review Comment: [0] As in other PRs, users are unlikely to care about the implementing framework. What they're more likely to care about is the SolrJ binding and where they can find it. ########## solr/core/src/java/org/apache/solr/handler/admin/api/CancelTaskAPI.java: ########## @@ -17,32 +17,56 @@ package org.apache.solr.handler.admin.api; -import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET; +import static org.apache.solr.response.SolrQueryResponse.RESPONSE_HEADER_KEY; +import static org.apache.solr.security.PermissionNameProvider.Name.READ_PERM; -import org.apache.solr.api.EndPoint; +import jakarta.inject.Inject; +import org.apache.solr.api.JerseyResource; +import org.apache.solr.client.api.endpoint.CancelTaskApi; +import org.apache.solr.client.api.model.FlexibleSolrJerseyResponse; +import org.apache.solr.core.SolrCore; import org.apache.solr.handler.component.QueryCancellationHandler; +import org.apache.solr.jersey.PermissionName; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.SolrQueryResponse; -import org.apache.solr.security.PermissionNameProvider; /** * V2 API for cancelling a currently running "task". * - * <p>This API (GET /v2/collections/collectionName/tasks/cancel) is analogous to the v1 - * /solr/collectionName/tasks/cancel API. + * <p>This API (GET /v2/collections/{collectionName}/tasks/cancel and GET + * /v2/cores/{coreName}/tasks/cancel) is analogous to the v1 + * /solr/{collectionName|coreName}/tasks/cancel API. */ -public class CancelTaskAPI { - private final QueryCancellationHandler cancellationHandler; +public class CancelTaskAPI extends JerseyResource implements CancelTaskApi { + private final SolrCore solrCore; + private final SolrQueryRequest solrQueryRequest; + private final SolrQueryResponse solrQueryResponse; - public CancelTaskAPI(QueryCancellationHandler cancellationHandler) { - this.cancellationHandler = cancellationHandler; + @Inject + public CancelTaskAPI(SolrCore solrCore, SolrQueryRequest req, SolrQueryResponse rsp) { + this.solrCore = solrCore; + this.solrQueryRequest = req; + this.solrQueryResponse = rsp; } - @EndPoint( - path = {"/tasks/cancel"}, - method = GET, - permission = PermissionNameProvider.Name.READ_PERM) - public void cancelActiveTask(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { - cancellationHandler.handleRequestBody(req, rsp); + @Override + @PermissionName(READ_PERM) + public FlexibleSolrJerseyResponse cancelTask(String queryUUID) throws Exception { + final FlexibleSolrJerseyResponse response = + instantiateJerseyResponse(FlexibleSolrJerseyResponse.class); + ensureRequiredParameterProvided("queryUUID", queryUUID); + final QueryCancellationHandler cancellationHandler = + (QueryCancellationHandler) solrCore.getRequestHandler("/tasks/cancel"); Review Comment: [-1] The way we've been handling the v1/v2 split is to have the actual logic/functionality live in v2, and have the v1 code (i.e. QueryCancellationHandler) call into those methods. This serves a few purposes: 1. Makes it easier to delete the v1 code down the road. 2. Prevents v2 code from "falling behind" or being forgotten when query-params or API functionality changes 3. Ensures better test coverage - Most of our test code is for v1 APIs, so having the v1 code call v2 gives us at least some confidence that the v2 endpoints work despite their lack of test coverage. That's all to say - the actual logic in QueryCancellationHandler needs moved over here in order to get all those benefits. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
