Apache Solr open-source search software
SOLR-15744: Convert task-mgmt v2 APIs to annotations (#863)
Jason Gerlowski7b1aa1b69364
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/CancelTaskAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/CancelTaskAPI.javanew file mode 100644index 00000000000..a63adc055f4--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/CancelTaskAPI.java@@ -0,0 +1,48 @@+/*+ * 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.client.solrj.SolrRequest.METHOD.GET;++import org.apache.solr.api.EndPoint;+import org.apache.solr.handler.component.QueryCancellationHandler;+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 CancelTaskAPI(QueryCancellationHandler cancellationHandler) {+ this.cancellationHandler = cancellationHandler;+ }++ @EndPoint(+ path = {"/tasks/cancel"},+ method = GET,+ permission = PermissionNameProvider.Name.READ_PERM)+ public void cancelActiveTask(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {+ cancellationHandler.handleRequestBody(req, rsp);+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/ListActiveTasksAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/ListActiveTasksAPI.javanew file mode 100644index 00000000000..fba3d9d26f3--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/ListActiveTasksAPI.java@@ -0,0 +1,48 @@+/*+ * 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.client.solrj.SolrRequest.METHOD.GET;++import org.apache.solr.api.EndPoint;+import org.apache.solr.handler.component.ActiveTasksListHandler;+import org.apache.solr.request.SolrQueryRequest;+import org.apache.solr.response.SolrQueryResponse;+import org.apache.solr.security.PermissionNameProvider;++/**+ * V2 API for listing any currently running "tasks".+ *+ * <p>This API (GET /v2/collections/collectionName/tasks/list) is analogous to the v1+ * /solr/collectionName/tasks/list API.+ */+public class ListActiveTasksAPI {+ private final ActiveTasksListHandler listTaskHandler;++ public ListActiveTasksAPI(ActiveTasksListHandler listTaskHandler) {+ this.listTaskHandler = listTaskHandler;+ }++ @EndPoint(+ path = {"/tasks/list"},+ method = GET,+ permission = PermissionNameProvider.Name.READ_PERM)+ public void listActiveTasks(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {+ listTaskHandler.handleRequestBody(req, rsp);+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/component/ActiveTasksListHandler.java b/solr/core/src/java/org/apache/solr/handler/component/ActiveTasksListHandler.javaindex ebfa9b1f3f5..f1ce12cd937 100644--- a/solr/core/src/java/org/apache/solr/handler/component/ActiveTasksListHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/component/ActiveTasksListHandler.java@@ -22,8 +22,9 @@ import java.util.Collection;import java.util.HashMap;import java.util.List;import java.util.Map;+import org.apache.solr.api.AnnotatedApi;import org.apache.solr.api.Api;-import org.apache.solr.api.ApiBag;+import org.apache.solr.handler.admin.api.ListActiveTasksAPI;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrRequestHandler;import org.apache.solr.response.SolrQueryResponse;@@ -89,7 +90,7 @@ public class ActiveTasksListHandler extends TaskManagementHandler {@Overridepublic Collection<Api> getApis() {- return ApiBag.wrapRequestHandlers(this, "core.tasks.list");+ return AnnotatedApi.getApis(new ListActiveTasksAPI(this));}private List<SearchComponent> getComponentsList() {diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryCancellationHandler.java b/solr/core/src/java/org/apache/solr/handler/component/QueryCancellationHandler.javaindex d71bfdaf0ec..18c99ba09c3 100644--- a/solr/core/src/java/org/apache/solr/handler/component/QueryCancellationHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryCancellationHandler.java@@ -22,8 +22,9 @@ import java.util.Collection;import java.util.HashMap;import java.util.List;import java.util.Map;+import org.apache.solr.api.AnnotatedApi;import org.apache.solr.api.Api;-import org.apache.solr.api.ApiBag;+import org.apache.solr.handler.admin.api.CancelTaskAPI;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrRequestHandler;import org.apache.solr.response.SolrQueryResponse;@@ -93,7 +94,7 @@ public class QueryCancellationHandler extends TaskManagementHandler {@Overridepublic Collection<Api> getApis() {- return ApiBag.wrapRequestHandlers(this, "core.tasks.cancel");+ return AnnotatedApi.getApis(new CancelTaskAPI(this));}private List<SearchComponent> getComponentsList() {diff --git a/solr/solrj/src/resources/apispec/core.tasks.cancel.json b/solr/solrj/src/resources/apispec/core.tasks.cancel.jsondeleted file mode 100644index 2034d1f6ba9..00000000000--- a/solr/solrj/src/resources/apispec/core.tasks.cancel.json+++ /dev/null@@ -1,18 +0,0 @@-{- "documentation": "https://solr.apache.org/guide/task-management.html",- "description": "Cancel a currently running task",- "methods": [- "GET"- ],- "url": {- "paths": [- "/tasks/cancel"- ],- "params": {- "cancelUUID": {- "type":"string",- "description": "Specify the UUID for the query to cancel"- }- }- }-}diff --git a/solr/solrj/src/resources/apispec/core.tasks.list.json b/solr/solrj/src/resources/apispec/core.tasks.list.jsondeleted file mode 100644index 9a4caf3c021..00000000000--- a/solr/solrj/src/resources/apispec/core.tasks.list.json+++ /dev/null@@ -1,12 +0,0 @@-{- "documentation": "https://solr.apache.org/guide/task-management.html",- "description": "List currently running tasks",- "methods": [- "GET"- ],- "url": {- "paths": [- "/tasks/list"- ]- }-}