Apache Solr open-source search software
SOLR-15745: Convert corestatus APIs to annotations (#455)
Jason Gerlowski7e39a5d5336c
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.javaindex d045a9ee77c..f7438dd500e 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 PermissionNapublic 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.javanew file mode 100644index 00000000000..b3f1b079e82--- /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.javanew file mode 100644index 00000000000..8da96063668--- /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.javaindex 6d20869d5a5..6290c1330ab 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);@@ -143,6 +168,33 @@ public class V2CoresAPIMappingTest extends SolrTestCaseJ4 {};+ api.call(req, rsp);+ 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.javaindex 84d526fc368..52e78a686b4 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.jsondeleted file mode 100644index f62d203b7f5..00000000000--- 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- }- }- }-}