You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ge...@apache.org on 2022/05/18 12:38:03 UTC

[solr] branch main updated: SOLR-15744: Convert task-mgmt v2 APIs to annotations (#863)

This is an automated email from the ASF dual-hosted git repository.

gerlowskija pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 7b1aa1b6936 SOLR-15744: Convert task-mgmt v2 APIs to annotations (#863)
7b1aa1b6936 is described below

commit 7b1aa1b6936458be52f4ee119cfbad1a5d0cb681
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Wed May 18 08:37:58 2022 -0400

    SOLR-15744: Convert task-mgmt v2 APIs to annotations (#863)
    
    Solr's been in the slow process of moving its v2 APIs away from the
    existing apispec/mapping framework towards one that relies on more
    explicit annotations to specify API properties.
    
    This commit converts the APIs from the core.tasks.cancel.json and
    core.tasks.list.json apispec files to the "new" framework.
---
 .../solr/handler/admin/api/CancelTaskAPI.java      | 48 ++++++++++++++++++++++
 .../solr/handler/admin/api/ListActiveTasksAPI.java | 48 ++++++++++++++++++++++
 .../handler/component/ActiveTasksListHandler.java  |  5 ++-
 .../component/QueryCancellationHandler.java        |  5 ++-
 .../src/resources/apispec/core.tasks.cancel.json   | 18 --------
 .../src/resources/apispec/core.tasks.list.json     | 12 ------
 6 files changed, 102 insertions(+), 34 deletions(-)

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.java
new file mode 100644
index 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.java
new file mode 100644
index 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.java
index 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 {
 
   @Override
   public 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.java
index 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 {
 
   @Override
   public 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.json
deleted file mode 100644
index 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.json
deleted file mode 100644
index 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"
-    ]
-  }
-}