Copilot commented on code in PR #4180:
URL: https://github.com/apache/solr/pull/4180#discussion_r2878014201
##########
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.
Review Comment:
The Javadoc claims this endpoint is only `GET
/v2/collections/{collectionName}/tasks/cancel`, but the API is actually
registered under `INDEX_PATH_PREFIX` which supports both `cores` and
`collections`. Updating the Javadoc to reflect both forms will prevent
misleading docs/clients.
```suggestion
* <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.
```
##########
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
Review Comment:
The Javadoc states the endpoint is `GET
/v2/collections/{collectionName}/tasks/cancel`, but `INDEX_PATH_PREFIX` expands
to both `/cores/{indexName}` and `/collections/{indexName}`. Please update the
comment to match the actual path(s) exposed by `@Path(INDEX_PATH_PREFIX +
"/tasks/cancel")`.
```suggestion
* <p>This API (GET /v2/collections/{collectionName}/tasks/cancel and
* GET /v2/cores/{coreName}/tasks/cancel) is analogous to the v1
```
##########
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);
Review Comment:
`queryUUID` is accepted as a method argument but never validated/used before
delegating to `QueryCancellationHandler`. If the query param is missing, the
handler throws `IllegalArgumentException`, which v2 exception handling will
treat as a 500 (since only `SolrException` sets a non-500 code). Consider
calling `ensureRequiredParameterProvided("queryUUID", queryUUID)` (or throwing
a `SolrException(BAD_REQUEST, ...)`) up front so the API returns a 400 for
missing required input.
```suggestion
instantiateJerseyResponse(FlexibleSolrJerseyResponse.class);
ensureRequiredParameterProvided("queryUUID", queryUUID);
```
--
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]