epugh commented on code in PR #4180:
URL: https://github.com/apache/solr/pull/4180#discussion_r2877993968


##########
solr/core/src/java/org/apache/solr/handler/admin/api/CancelTaskAPI.java:
##########
@@ -17,32 +17,54 @@
 
 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.
  */
-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);
+    final QueryCancellationHandler cancellationHandler =
+        (QueryCancellationHandler) solrCore.getRequestHandler("/tasks/cancel");
+    cancellationHandler.handleRequestBody(solrQueryRequest, solrQueryResponse);
+    // Copy response data added by the handler into the jersey response object
+    solrQueryResponse

Review Comment:
   Not one hundread percent sure on this, but it was indicated as being needed 
after `cancellationHandler` did it's thing.



##########
solr/api/src/java/org/apache/solr/client/api/endpoint/CancelTaskApi.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.client.api.endpoint;
+
+import static org.apache.solr.client.api.util.Constants.INDEX_PATH_PREFIX;
+
+import io.swagger.v3.oas.annotations.Operation;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.QueryParam;
+import org.apache.solr.client.api.model.FlexibleSolrJerseyResponse;
+import org.apache.solr.client.api.util.StoreApiParameters;
+
+/**
+ * V2 API definition 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.
+ */
+@Path(INDEX_PATH_PREFIX + "/tasks/cancel")
+public interface CancelTaskApi {
+
+  @GET
+  @StoreApiParameters
+  @Operation(
+      summary = "Cancel a currently-running task",
+      tags = {"tasks"})
+  FlexibleSolrJerseyResponse cancelTask(@QueryParam("queryUUID") String 
queryUUID) throws Exception;

Review Comment:
   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`?  



##########
solr/core/src/test/org/apache/solr/handler/admin/api/CancelTaskAPITest.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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 {
+
+  @ClassRule public static SolrJettyTestRule solrTestRule = new 
SolrJettyTestRule();
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    EnvUtils.setProperty(
+        ALLOW_PATHS_SYSPROP, 
ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
+    // Disable URL allow-list checks to allow standalone shard dispatch in 
non-cloud mode
+    EnvUtils.setProperty(ENABLE_URL_ALLOW_LIST, "false");
+    solrTestRule.startSolr(createTempDir());
+    solrTestRule
+        .newCollection(DEFAULT_TEST_COLLECTION_NAME)
+        .withConfigSet(ExternalPaths.DEFAULT_CONFIGSET)
+        .create();
+  }
+
+  @Test
+  public void testCancelNonExistentTask() throws Exception {
+    final TasksApi.CancelTask request = new 
TasksApi.CancelTask(IndexType.CORE, DEFAULT_TEST_COLLECTION_NAME);
+    request.setQueryUUID("nonexistent-uuid");
+
+    final FlexibleSolrJerseyResponse response =
+        
request.process(solrTestRule.getSolrClient(DEFAULT_TEST_COLLECTION_NAME));
+    assertNotNull(response);
+    assertEquals("not found", 
response.unknownProperties().get("cancellationResult"));

Review Comment:
   I think the `unknownProperties` is an aspect of hte 
`FlexibleSolrJerseyResponse`



-- 
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]

Reply via email to