Copilot commented on code in PR #4828:
URL: https://github.com/apache/solr/pull/4828#discussion_r3893840425


##########
solr/solr-ref-guide/modules/deployment-guide/pages/task-management.adoc:
##########
@@ -124,13 +125,13 @@ V2 API::
 ====
 [source,bash]
 ----
-curl -X GET 
"http://localhost:8983/v2/collections/collectionName/tasks/cancel?queryUUID=5";
+curl -X DELETE "http://localhost:8983/v2/collections/collectionName/tasks/5";
 ----
 ====
 ======
 
 === Sample Response
-==== If the task UUID was found and successfully cancelled:
+==== If the task was found and successfully cancelled:

Review Comment:
   The new V2 API does not return either of these documented payloads. A 
successful DELETE returns the typed `CancelTaskResponse` with 
`"status":"SUCCESS"`, while a missing task is an HTTP 404 Jersey error response 
and neither response contains the legacy `responseCode` field. Please split 
this into V1/V2 response tabs (as the status section below already does) so 
users are not given the V1 contract for the newly documented V2 endpoint.



##########
solr/core/src/java/org/apache/solr/handler/admin/api/CancelTask.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.security.PermissionNameProvider.Name.READ_PERM;
+
+import jakarta.inject.Inject;
+import org.apache.solr.api.JerseyResource;
+import org.apache.solr.client.api.endpoint.TasksApi;
+import org.apache.solr.client.api.model.CancelTaskResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.handler.component.ActiveTaskQuerySupport;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.CancellableCollector;
+
+public class CancelTask extends JerseyResource implements TasksApi.Cancel {
+
+  private final SolrQueryRequest solrQueryRequest;
+
+  @Inject
+  public CancelTask(SolrQueryRequest solrQueryRequest) {
+    this.solrQueryRequest = solrQueryRequest;
+  }
+
+  @Override
+  @PermissionName(READ_PERM)
+  public CancelTaskResponse cancelRunningTask(String taskID) throws Exception {
+    final CancelTaskResponse response = 
instantiateJerseyResponse(CancelTaskResponse.class);
+
+    boolean isTaskCancelled = 
ActiveTaskQuerySupport.cancelTask(solrQueryRequest, taskID);
+
+    if (isTaskCancelled) {
+      response.status = CancelTaskResponse.CancellationStatus.SUCCESS;
+      return response;
+    }
+    throw new SolrException(
+        SolrException.ErrorCode.NOT_FOUND, 
CancelTaskResponse.CancellationStatus.NOT_FOUND.name());

Review Comment:
   The `NOT_FOUND` enum value is never assigned to the response's `status` 
field. Since `instantiateJerseyResponse` registers this typed response for the 
exception mapper, the 404 body currently has a null/omitted domain status 
rather than `NOT_FOUND`; its error message is also only the context-free string 
`NOT_FOUND`. Set the status before throwing and identify the missing task in 
the error.



##########
solr/core/src/test/org/apache/solr/handler/admin/api/CancelTaskTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.api.model.CancelTaskResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.core.CancellableQueryTracker;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.CancellableCollector;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CancelTaskTest extends SolrTestCaseJ4 {
+
+  private CancellableQueryTracker cancellableQueryTracker;
+  private CancelTask cancelTask;
+
+  @BeforeClass
+  public static void ensureWorkingMockito() {
+    assumeWorkingMockito();
+  }
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+
+    SolrQueryRequest solrQueryRequest = mock(SolrQueryRequest.class);
+    SolrCore solrCore = mock(SolrCore.class);
+    cancellableQueryTracker = mock(CancellableQueryTracker.class);
+
+    when(solrQueryRequest.getCore()).thenReturn(solrCore);
+    
when(solrCore.getCancellableQueryTracker()).thenReturn(cancellableQueryTracker);
+
+    cancelTask = new CancelTask(solrQueryRequest);
+  }
+
+  @Test
+  public void testCancelRunningTask() throws Exception {
+    CancellableCollector cancellableCollector = 
mock(CancellableCollector.class);
+    when(cancellableQueryTracker.getCancellableTask("taskID_running"))
+        .thenReturn(cancellableCollector);
+
+    CancelTaskResponse response = 
cancelTask.cancelRunningTask("taskID_running");
+
+    assertEquals(CancelTaskResponse.CancellationStatus.SUCCESS, 
response.status);
+    verify(cancellableCollector).cancel();
+  }
+
+  @Test
+  public void testCancelNonExistentTaskReturns404() {
+    
when(cancellableQueryTracker.getCancellableTask("taskID_missing")).thenReturn(null);
+
+    SolrException exception =
+        expectThrows(SolrException.class, () -> 
cancelTask.cancelRunningTask("taskID_missing"));

Review Comment:
   This unit test invokes the resource directly, so it cannot detect failures 
in the main purpose of this migration: Jersey route registration, DELETE 
dispatch, response serialization, HTTP 404 mapping, and cloud fan-out. Add an 
HTTP-level V2 test for both successful and missing-task cancellation; the 
existing `V2ApiIntegrationTest`/`TestTaskManagement` infrastructure already 
covers comparable V2 transport and distributed task behavior.



##########
solr/core/src/java/org/apache/solr/handler/admin/api/CancelTask.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.security.PermissionNameProvider.Name.READ_PERM;
+
+import jakarta.inject.Inject;
+import org.apache.solr.api.JerseyResource;
+import org.apache.solr.client.api.endpoint.TasksApi;
+import org.apache.solr.client.api.model.CancelTaskResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.handler.component.ActiveTaskQuerySupport;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.CancellableCollector;
+
+public class CancelTask extends JerseyResource implements TasksApi.Cancel {

Review Comment:
   This newly introduced resource class needs a concise class-level Javadoc 
describing the V2 task-cancellation API it implements.



##########
solr/core/src/test/org/apache/solr/handler/admin/api/CancelTaskTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.api.model.CancelTaskResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.core.CancellableQueryTracker;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.CancellableCollector;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CancelTaskTest extends SolrTestCaseJ4 {
+
+  private CancellableQueryTracker cancellableQueryTracker;
+  private CancelTask cancelTask;
+
+  @BeforeClass
+  public static void ensureWorkingMockito() {
+    assumeWorkingMockito();
+  }

Review Comment:
   New Java test suites should extend `SolrTestCase` rather than the legacy 
`SolrTestCaseJ4`. The Mockito assumption can still call 
`SolrTestCaseJ4.assumeWorkingMockito()` explicitly.



##########
solr/api/src/java/org/apache/solr/client/api/model/CancelTaskResponse.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class CancelTaskResponse extends SolrJerseyResponse {

Review Comment:
   This new public response-model class needs a concise class-level Javadoc so 
generated API consumers can understand what it represents.



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