From fb505377ed23018549d389292bd53e28873575e6 Mon Sep 17 00:00:00 2001 From: Joshua Ouma Date: Tue, 11 Oct 2022 00:51:13 +0300 Subject: [PATCH] Created v2 equivalent of v1 'CLUSTERSTATUS' command --- .../org/apache/solr/handler/CollectionsAPI.java | 16 ++++++++++++++++ .../admin/V2CollectionsAPIMappingTest.java | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/solr/core/src/java/org/apache/solr/handler/CollectionsAPI.java b/solr/core/src/java/org/apache/solr/handler/CollectionsAPI.java index 11f1ee5df4a..3d10e763112 100644 --- a/solr/core/src/java/org/apache/solr/handler/CollectionsAPI.java +++ b/solr/core/src/java/org/apache/solr/handler/CollectionsAPI.java @@ -80,6 +80,22 @@ public void getCollections(SolrQueryRequest req, SolrQueryResponse rsp) throws E collectionsHandler.handleRequestBody(wrapParams(req, v1Params), rsp); } + /** + * V2 API for displaying basic information about all collections. + * + *

This API (GET /v2/collections?) is analogous to the v1 + * /admin/collections?action=CLUSTERSTATUS command. + */ + @EndPoint( + path = {"/c?", "/collections?"}, + method = GET, + permission = COLL_READ_PERM) + public void getCollectionsStatuses(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { + final Map v1Params = Maps.newHashMap(); + v1Params.put(ACTION, CollectionAction.CLUSTERSTATUS.toLower()); + collectionsHandler.handleRequestBody(wrapParams(req, v1Params), rsp); + } + @EndPoint( path = {"/c", "/collections"}, method = POST, diff --git a/solr/core/src/test/org/apache/solr/handler/admin/V2CollectionsAPIMappingTest.java b/solr/core/src/test/org/apache/solr/handler/admin/V2CollectionsAPIMappingTest.java index bf0b2db17cb..60014021df3 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/V2CollectionsAPIMappingTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/V2CollectionsAPIMappingTest.java @@ -281,4 +281,12 @@ public void testRestoreAllProperties() throws Exception { assertEquals("bar2", v1Params.get("property.foo2")); assertEquals(3, v1Params.getPrimitiveInt(ZkStateReader.REPLICATION_FACTOR)); } + + @Test + public void testListCollectionsStatusesAllProperties() throws Exception { + final String noBody = null; + final SolrParams v1Params = captureConvertedV1Params("/collections?", "GET", noBody); + + assertEquals(CollectionParams.CollectionAction.CLUSTERSTATUS.lowerName, v1Params.get(ACTION)); + } }