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 7e39a5d SOLR-15745: Convert corestatus APIs to annotations (#455)
7e39a5d is described below
commit 7e39a5d5336c23be376afe62eb8da2c71ae34ce8
Author: Jason Gerlowski <[email protected]>
AuthorDate: Sat Dec 18 13:03:17 2021 -0500
SOLR-15745: Convert corestatus APIs to annotations (#455)
Solr has historically supported two frameworks for definings its v2
APIs: a JSON-based 'apispec' framework, and a more modern replacement
that relies on JAX-RS-like annotations to specify endpoints and
parameters.
The community is in the process of migrating to the annotation based
approach, but many apispec APIs remain.
This commit converts GET /v2/cores and GET /v2/cores/coreName over to
the annotation framework.
---
.../solr/handler/admin/CoreAdminHandler.java | 4 ++
.../solr/handler/admin/api/AllCoresStatusAPI.java | 53 ++++++++++++++++++++
.../handler/admin/api/SingleCoreStatusAPI.java | 57 ++++++++++++++++++++++
.../solr/handler/admin/V2CoresAPIMappingTest.java | 52 ++++++++++++++++++++
.../solr/client/solrj/request/CoreApiMapping.java | 2 -
solr/solrj/src/resources/apispec/cores.Status.json | 20 --------
6 files changed, 166 insertions(+), 22 deletions(-)
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
index d045a9e..f7438dd 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
@@ -36,10 +36,12 @@ import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.handler.RequestHandlerBase;
+import org.apache.solr.handler.admin.api.AllCoresStatusAPI;
import org.apache.solr.handler.admin.api.CreateCoreAPI;
import org.apache.solr.handler.admin.api.InvokeClassAPI;
import org.apache.solr.handler.admin.api.OverseerOperationAPI;
import org.apache.solr.handler.admin.api.RejoinLeaderElectionAPI;
+import org.apache.solr.handler.admin.api.SingleCoreStatusAPI;
import org.apache.solr.logging.MDCLoggingContext;
import org.apache.solr.metrics.SolrMetricManager;
import org.apache.solr.metrics.SolrMetricsContext;
@@ -411,6 +413,8 @@ public class CoreAdminHandler extends RequestHandlerBase
implements PermissionNa
public Collection<Api> getApis() {
final List<Api> apis = Lists.newArrayList(coreAdminHandlerApi.getApis());
// Only some core-admin APIs use the v2 AnnotatedApi framework
+ apis.addAll(AnnotatedApi.getApis(new AllCoresStatusAPI(this)));
+ apis.addAll(AnnotatedApi.getApis(new SingleCoreStatusAPI(this)));
apis.addAll(AnnotatedApi.getApis(new CreateCoreAPI(this)));
apis.addAll(AnnotatedApi.getApis(new InvokeClassAPI(this)));
apis.addAll(AnnotatedApi.getApis(new RejoinLeaderElectionAPI(this)));
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/AllCoresStatusAPI.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/AllCoresStatusAPI.java
new file mode 100644
index 0000000..b3f1b07
--- /dev/null
+++
b/solr/core/src/java/org/apache/solr/handler/admin/api/AllCoresStatusAPI.java
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.solr.api.EndPoint;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
+import static org.apache.solr.common.params.CommonParams.ACTION;
+import static org.apache.solr.common.params.CommonParams.STATUS;
+import static org.apache.solr.handler.ClusterAPI.wrapParams;
+import static
org.apache.solr.security.PermissionNameProvider.Name.CORE_READ_PERM;
+
+/**
+ * V2 API for retrieving status information for all cores on the receiving
node.
+ *
+ * This API (GET /v2/cores is analogous to the v1 /admin/cores?action=status
command.
+ *
+ * @see SingleCoreStatusAPI
+ */
+public class AllCoresStatusAPI {
+
+ private final CoreAdminHandler coreAdminHandler;
+
+ public AllCoresStatusAPI(CoreAdminHandler coreAdminHandler) {
+ this.coreAdminHandler = coreAdminHandler;
+ }
+
+ @EndPoint(path = {"/cores"},
+ method = GET,
+ permission = CORE_READ_PERM)
+ public void getStatusOfAllCores(SolrQueryRequest req, SolrQueryResponse
rsp) throws Exception {
+ req = wrapParams(req, ACTION, STATUS);
+ coreAdminHandler.handleRequestBody(req, rsp);
+ }
+}
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/SingleCoreStatusAPI.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/SingleCoreStatusAPI.java
new file mode 100644
index 0000000..8da9606
--- /dev/null
+++
b/solr/core/src/java/org/apache/solr/handler/admin/api/SingleCoreStatusAPI.java
@@ -0,0 +1,57 @@
+/*
+ * 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 org.apache.solr.api.EndPoint;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
+import static org.apache.solr.common.params.CommonParams.ACTION;
+import static org.apache.solr.common.params.CommonParams.STATUS;
+import static org.apache.solr.common.params.CoreAdminParams.CORE;
+import static org.apache.solr.handler.ClusterAPI.wrapParams;
+import static
org.apache.solr.security.PermissionNameProvider.Name.CORE_READ_PERM;
+
+/**
+ * V2 API for checking the status of a specific core.
+ *
+ * This API (GET /v2/cores/coreName is analogous to the v1
/admin/cores?action=status&core=coreName
+ * command.
+ *
+ * @see AllCoresStatusAPI
+ */
+public class SingleCoreStatusAPI {
+
+ private final CoreAdminHandler coreAdminHandler;
+
+ public SingleCoreStatusAPI(CoreAdminHandler coreAdminHandler) {
+ this.coreAdminHandler = coreAdminHandler;
+ }
+
+ @EndPoint(path = {"/cores/{core}"},
+ method = GET,
+ permission = CORE_READ_PERM)
+ public void getStatusOfSingleCore(SolrQueryRequest req, SolrQueryResponse
rsp) throws Exception {
+ req = wrapParams(req,
+ ACTION, STATUS,
+ CORE, req.getPathTemplateValues().get(CORE));
+ coreAdminHandler.handleRequestBody(req, rsp);
+ }
+}
diff --git
a/solr/core/src/test/org/apache/solr/handler/admin/V2CoresAPIMappingTest.java
b/solr/core/src/test/org/apache/solr/handler/admin/V2CoresAPIMappingTest.java
index 6d20869..6290c13 100644
---
a/solr/core/src/test/org/apache/solr/handler/admin/V2CoresAPIMappingTest.java
+++
b/solr/core/src/test/org/apache/solr/handler/admin/V2CoresAPIMappingTest.java
@@ -24,7 +24,9 @@ import org.apache.solr.api.ApiBag;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.CommandOperation;
import org.apache.solr.common.util.ContentStreamBase;
+import org.apache.solr.handler.admin.api.AllCoresStatusAPI;
import org.apache.solr.handler.admin.api.CreateCoreAPI;
+import org.apache.solr.handler.admin.api.SingleCoreStatusAPI;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
@@ -44,6 +46,7 @@ import static
org.apache.solr.common.params.CommonAdminParams.ASYNC;
import static org.apache.solr.common.params.CommonParams.ACTION;
import static org.apache.solr.common.params.CoreAdminParams.*;
import static
org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.CREATE;
+import static
org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.STATUS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -72,6 +75,8 @@ public class V2CoresAPIMappingTest extends SolrTestCaseJ4 {
apiBag = new ApiBag(false);
apiBag.registerObject(new CreateCoreAPI(mockCoreAdminHandler));
+ apiBag.registerObject(new SingleCoreStatusAPI(mockCoreAdminHandler));
+ apiBag.registerObject(new AllCoresStatusAPI(mockCoreAdminHandler));
}
@Test
@@ -120,6 +125,26 @@ public class V2CoresAPIMappingTest extends SolrTestCaseJ4 {
assertEquals("requestTrackingId", v1Params.get(ASYNC));
}
+ @Test
+ public void testSpecificCoreStatusApiAllParams() throws Exception {
+ final SolrParams v1Params =
captureConvertedV1Params("/cores/someCore", "GET",
+ Map.of(INDEX_INFO, new String[] { "true" }));
+
+ assertEquals(STATUS.name().toLowerCase(Locale.ROOT),
v1Params.get(ACTION));
+ assertEquals("someCore", v1Params.get(CORE));
+ assertEquals(true, v1Params.getPrimitiveBool(INDEX_INFO));
+ }
+
+ @Test
+ public void testAllCoreStatusApiAllParams() throws Exception {
+ final SolrParams v1Params = captureConvertedV1Params("/cores", "GET",
+ Map.of(INDEX_INFO, new String[] { "true" }));
+
+ assertEquals(STATUS.name().toLowerCase(Locale.ROOT),
v1Params.get(ACTION));
+ assertNull("Expected 'core' parameter to be null", v1Params.get(CORE));
+ assertEquals(true, v1Params.getPrimitiveBool(INDEX_INFO));
+ }
+
private SolrParams captureConvertedV1Params(String path, String method,
String v2RequestBody) throws Exception {
final HashMap<String, String> parts = new HashMap<>();
final Api api = apiBag.lookup(path, method, parts);
@@ -147,4 +172,31 @@ public class V2CoresAPIMappingTest extends SolrTestCaseJ4 {
verify(mockCoreAdminHandler).handleRequestBody(queryRequestCaptor.capture(),
any());
return queryRequestCaptor.getValue().getParams();
}
+
+ private SolrParams captureConvertedV1Params(String path, String method,
Map<String, String[]> queryParams) throws Exception {
+ final HashMap<String, String> parts = new HashMap<>();
+ final Api api = apiBag.lookup(path, method, parts);
+ final SolrQueryResponse rsp = new SolrQueryResponse();
+ final LocalSolrQueryRequest req = new LocalSolrQueryRequest(null,
queryParams) {
+ @Override
+ public List<CommandOperation> getCommands(boolean validateInput) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Map<String, String> getPathTemplateValues() {
+ return parts;
+ }
+
+ @Override
+ public String getHttpMethod() {
+ return method;
+ }
+ };
+
+
+ api.call(req, rsp);
+
verify(mockCoreAdminHandler).handleRequestBody(queryRequestCaptor.capture(),
any());
+ return queryRequestCaptor.getValue().getParams();
+ }
}
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.java
index 84d526f..52e78a6 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.java
@@ -37,7 +37,6 @@ public class CoreApiMapping {
public enum Meta implements CommandMeta {
UNLOAD(PER_CORE_COMMANDS, POST, CoreAdminAction.UNLOAD, "unload", null),
RELOAD(PER_CORE_COMMANDS, POST, CoreAdminAction.RELOAD, "reload", null),
- STATUS(CORES_STATUS, GET, CoreAdminAction.STATUS, "status", null),
SWAP(PER_CORE_COMMANDS, POST, CoreAdminAction.SWAP, "swap",
Collections.singletonMap("other", "with")),
RENAME(PER_CORE_COMMANDS, POST, CoreAdminAction.RENAME, "rename",
Collections.singletonMap("other", "to")),
MERGEINDEXES(PER_CORE_COMMANDS, POST, CoreAdminAction.MERGEINDEXES,
"merge-indexes", null),
@@ -86,7 +85,6 @@ public class CoreApiMapping {
}
public enum EndPoint implements ApiMapping.V2EndPoint {
- CORES_STATUS("cores.Status"),
PER_CORE_COMMANDS("cores.core.Commands");
final String specName;
diff --git a/solr/solrj/src/resources/apispec/cores.Status.json
b/solr/solrj/src/resources/apispec/cores.Status.json
deleted file mode 100644
index f62d203..0000000
--- a/solr/solrj/src/resources/apispec/cores.Status.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "documentation":
"https://solr.apache.org/guide/coreadmin-api.html#coreadmin-status",
- "description": "Provides status and other information about the status of
each core. Individual cores can be requested by core name.",
- "methods": [
- "GET"
- ],
- "url": {
- "paths": [
- "/cores",
- "/cores/{core}"
- ],
- "params": {
- "indexInfo": {
- "type": "boolean",
- "description": "If true, index information will be returned, such as
information about number of documents, deletions, segments, etc. In a large
cluster with more than hundreds of cores, this can take a long time to
retrieve. If you have a large cluster, consider setting this to false.",
- "default": true
- }
- }
- }
-}