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

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


The following commit(s) were added to refs/heads/main by this push:
     new c203b3f  refactor: remove standalone Solr support, require SolrCloud 
(#71)
c203b3f is described below

commit c203b3fe46e2b29274ba2bd16076534f49f706ca
Author: Aditya Parikh <[email protected]>
AuthorDate: Tue Mar 24 14:10:10 2026 -0400

    refactor: remove standalone Solr support, require SolrCloud (#71)
    
    ---------
    
    Signed-off-by: adityamparikh <[email protected]>
    Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
 .../mcp/server/collection/CollectionService.java   |  61 +++--------
 .../apache/solr/mcp/server/config/SolrConfig.java  |   5 +-
 .../server/collection/CollectionServiceTest.java   | 115 +++++----------------
 3 files changed, 41 insertions(+), 140 deletions(-)

diff --git 
a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java 
b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
index c121914..de24120 100644
--- a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
+++ b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
@@ -31,17 +31,13 @@ import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.request.CoreAdminRequest;
 import org.apache.solr.client.solrj.request.GenericSolrRequest;
 import org.apache.solr.client.solrj.request.LukeRequest;
 import org.apache.solr.client.solrj.response.CollectionAdminResponse;
-import org.apache.solr.client.solrj.response.CoreAdminResponse;
 import org.apache.solr.client.solrj.response.LukeResponse;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.client.solrj.response.SolrPingResponse;
-import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.mcp.server.config.SolrConfigurationProperties;
@@ -67,8 +63,8 @@ import org.springframework.stereotype.Service;
  * <strong>Core Capabilities:</strong>
  *
  * <ul>
- * <li><strong>Collection Discovery</strong>: Lists available collections with
- * automatic SolrCloud vs standalone detection
+ * <li><strong>Collection Discovery</strong>: Lists available collections using
+ * the SolrCloud Collections API
  * <li><strong>Performance Monitoring</strong>: Comprehensive metrics 
collection
  * including index, query, cache, and handler statistics
  * <li><strong>Health Monitoring</strong>: Real-time health checks with
@@ -100,7 +96,6 @@ import org.springframework.stereotype.Service;
  *
  * <ul>
  * <li><strong>SolrCloud</strong>: Distributed mode using Collections API
- * <li><strong>Standalone</strong>: Single-node mode using Core Admin API
  * </ul>
  *
  * <p>
@@ -319,23 +314,16 @@ public class CollectionService {
        }
 
        /**
-        * Lists all available Solr collections in the cluster.
+        * Lists all available Solr collections in the SolrCloud cluster.
         *
         * <p>
-        * This method automatically detects the Solr deployment type and uses 
the
-        * appropriate API:
-        *
-        * <ul>
-        * <li><strong>SolrCloud</strong>: Uses Collections API to list 
distributed
-        * collections
-        * <li><strong>Standalone</strong>: Uses Core Admin API to list 
individual
-        * collections
-        * </ul>
+        * This method uses the SolrCloud Collections API to retrieve the list 
of
+        * available collections. Standalone Solr instances are not supported.
         *
         * <p>
-        * In SolrCloud environments, the returned names may include shard 
identifiers
-        * (e.g., "films_shard1_replica_n1"). Use {@link 
#extractCollectionName(String)}
-        * to get the base collection name if needed.
+        * The returned names may include shard identifiers (e.g.,
+        * "films_shard1_replica_n1"). Use {@link 
#extractCollectionName(String)} to get
+        * the base collection name if needed.
         *
         * <p>
         * <strong>Error Handling:</strong>
@@ -356,33 +344,17 @@ public class CollectionService {
         * @return a list of collection names, or an empty list if unable to 
retrieve
         *         them
         * @see CollectionAdminRequest.List
-        * @see CoreAdminRequest
         */
        @McpTool(name = "list-collections", description = "List solr 
collections")
        public List<String> listCollections() {
                try {
-                       if (solrClient instanceof CloudSolrClient) {
-                               // For SolrCloud - use Collections API
-                               CollectionAdminRequest.List request = new 
CollectionAdminRequest.List();
-                               CollectionAdminResponse response = 
request.process(solrClient);
+                       CollectionAdminRequest.List request = new 
CollectionAdminRequest.List();
+                       CollectionAdminResponse response = 
request.process(solrClient);
 
-                               @SuppressWarnings("unchecked")
-                               List<String> collections = (List<String>) 
response.getResponse().get(COLLECTIONS_KEY);
-                               return collections != null ? collections : new 
ArrayList<>();
-                       } else {
-                               // For standalone Solr - use Core Admin API
-                               CoreAdminRequest coreAdminRequest = new 
CoreAdminRequest();
-                               
coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
-                               CoreAdminResponse coreResponse = 
coreAdminRequest.process(solrClient);
-
-                               List<String> cores = new ArrayList<>();
-                               NamedList<NamedList<Object>> coreStatus = 
coreResponse.getCoreStatus();
-                               for (int i = 0; i < coreStatus.size(); i++) {
-                                       cores.add(coreStatus.getName(i));
-                               }
-                               return cores;
-                       }
-               } catch (SolrServerException | IOException _) {
+                       @SuppressWarnings("unchecked")
+                       List<String> collections = (List<String>) 
response.getResponse().get(COLLECTIONS_KEY);
+                       return collections != null ? collections : new 
ArrayList<>();
+               } catch (SolrServerException | IOException e) {
                        return new ArrayList<>();
                }
        }
@@ -952,9 +924,8 @@ public class CollectionService {
         * </ol>
         *
         * <p>
-        * This dual approach ensures compatibility with both standalone Solr 
(which
-        * returns collection names directly) and SolrCloud (which may return 
shard
-        * names).
+        * This dual approach ensures compatibility with SolrCloud environments 
where
+        * shard names may be returned alongside collection names.
         *
         * <p>
         * <strong>Error Handling:</strong>
diff --git a/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java 
b/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
index 7359ccf..f39651f 100644
--- a/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
+++ b/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
@@ -139,9 +139,8 @@ public class SolrConfig {
         *
         * <p>
         * Creates an {@code HttpSolrClient} configured for standard HTTP-based
-        * communication with Solr servers. This client type is suitable for 
both
-        * standalone Solr instances and SolrCloud deployments when used with 
load
-        * balancers.
+        * communication with SolrCloud servers. This client type is suitable 
for
+        * SolrCloud deployments when used with load balancers.
         *
         * <p>
         * <strong>Error Handling:</strong>
diff --git 
a/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceTest.java
 
b/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceTest.java
index ed5bca8..4f72424 100644
--- 
a/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceTest.java
+++ 
b/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceTest.java
@@ -30,7 +30,6 @@ import java.util.List;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.response.LukeResponse;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.client.solrj.response.SolrPingResponse;
@@ -48,9 +47,6 @@ class CollectionServiceTest {
        @Mock
        private SolrClient solrClient;
 
-       @Mock
-       private CloudSolrClient cloudSolrClient;
-
        @Mock
        private QueryResponse queryResponse;
 
@@ -75,32 +71,17 @@ class CollectionServiceTest {
                assertNotNull(collectionService);
        }
 
-       @Test
-       void listCollections_WithCloudSolrClient_ShouldReturnCollections() 
throws Exception {
-               // Given - This test verifies the service can be constructed 
with
-               // CloudSolrClient
-               CollectionService cloudService = new 
CollectionService(cloudSolrClient, objectMapper);
-
-               // Note: This test cannot fully exercise listCollections() 
because it requires
-               // mocking static methods in CollectionAdminRequest which 
requires PowerMock or
-               // Mockito inline. The actual behavior is tested in integration 
tests.
-
-               // When/Then - Verify service construction
-               assertNotNull(cloudService, "Should be able to construct 
service with CloudSolrClient");
-       }
-
        @Test
        void listCollections_WhenExceptionOccurs_ShouldReturnEmptyList() throws 
Exception {
-               // Note: This test cannot fully exercise listCollections() with 
mock SolrClient
-               // because it requires mocking CoreAdminRequest processing. The 
actual error
-               // handling behavior is tested in integration tests.
+               // Given - mock throws exception
+               when(solrClient.request(any(), any())).thenThrow(new 
SolrServerException("Connection error"));
 
-               // Given/When - Using regular SolrClient (non-cloud) which will 
attempt
-               // CoreAdmin
-               // The mock doesn't have a real CoreAdmin implementation
+               // When
+               List<String> result = collectionService.listCollections();
 
-               // Then - Verify service is constructed
-               assertNotNull(collectionService, "Service should be constructed 
successfully");
+               // Then
+               assertNotNull(result);
+               assertTrue(result.isEmpty());
        }
 
        // Collection name extraction tests
@@ -697,16 +678,13 @@ class CollectionServiceTest {
 
        // List collections tests
        @Test
-       void listCollections_CloudClient_Success() throws Exception {
-               CloudSolrClient cloudClient = mock(CloudSolrClient.class);
-
+       void listCollections_Success() throws Exception {
                NamedList<Object> response = new NamedList<>();
                response.add("collections", Arrays.asList("collection1", 
"collection2"));
 
-               when(cloudClient.request(any(), any())).thenReturn(response);
+               when(solrClient.request(any(), any())).thenReturn(response);
 
-               CollectionService service = new CollectionService(cloudClient, 
objectMapper);
-               List<String> result = service.listCollections();
+               List<String> result = collectionService.listCollections();
 
                assertNotNull(result);
                assertEquals(2, result.size());
@@ -715,64 +693,33 @@ class CollectionServiceTest {
        }
 
        @Test
-       void listCollections_CloudClient_NullCollections() throws Exception {
-               CloudSolrClient cloudClient = mock(CloudSolrClient.class);
-
+       void listCollections_NullCollections() throws Exception {
                NamedList<Object> response = new NamedList<>();
                response.add("collections", null);
 
-               when(cloudClient.request(any(), any())).thenReturn(response);
+               when(solrClient.request(any(), any())).thenReturn(response);
 
-               CollectionService service = new CollectionService(cloudClient, 
objectMapper);
-               List<String> result = service.listCollections();
+               List<String> result = collectionService.listCollections();
 
                assertNotNull(result);
                assertTrue(result.isEmpty());
        }
 
        @Test
-       void listCollections_CloudClient_Error() throws Exception {
-               CloudSolrClient cloudClient = mock(CloudSolrClient.class);
-               when(cloudClient.request(any(), any())).thenThrow(new 
SolrServerException("Connection error"));
+       void listCollections_Error() throws Exception {
+               when(solrClient.request(any(), any())).thenThrow(new 
SolrServerException("Connection error"));
 
-               CollectionService service = new CollectionService(cloudClient, 
objectMapper);
-               List<String> result = service.listCollections();
+               List<String> result = collectionService.listCollections();
 
                assertNotNull(result);
                assertTrue(result.isEmpty());
        }
 
        @Test
-       void listCollections_NonCloudClient_Success() throws Exception {
-               // Create a NamedList to represent the core status response
-               NamedList<Object> response = new NamedList<>();
-               NamedList<Object> status = new NamedList<>();
-
-               NamedList<Object> core1Status = new NamedList<>();
-               NamedList<Object> core2Status = new NamedList<>();
-
-               status.add("core1", core1Status);
-               status.add("core2", core2Status);
-               response.add("status", status);
-
-               // Mock the solrClient request to return the response
-               when(solrClient.request(any(), any())).thenReturn(response);
-
-               CollectionService service = new CollectionService(solrClient, 
objectMapper);
-               List<String> result = service.listCollections();
-
-               assertNotNull(result);
-               assertEquals(2, result.size());
-               assertTrue(result.contains("core1"));
-               assertTrue(result.contains("core2"));
-       }
-
-       @Test
-       void listCollections_NonCloudClient_Error() throws Exception {
+       void listCollections_IOError() throws Exception {
                when(solrClient.request(any(), any())).thenThrow(new 
IOException("IO error"));
 
-               CollectionService service = new CollectionService(solrClient, 
objectMapper);
-               List<String> result = service.listCollections();
+               List<String> result = collectionService.listCollections();
 
                assertNotNull(result);
                assertTrue(result.isEmpty());
@@ -897,38 +844,22 @@ class CollectionServiceTest {
 
        // createCollection tests
        @Test
-       void createCollection_success_cloudClient() throws Exception {
-               CloudSolrClient cloudClient = mock(CloudSolrClient.class);
-               when(cloudClient.request(any(), any())).thenReturn(new 
NamedList<>());
-
-               CollectionService service = new CollectionService(cloudClient, 
objectMapper);
-               CollectionCreationResult result = 
service.createCollection("new_collection", "_default", 1, 1);
-
-               assertNotNull(result);
-               assertTrue(result.success());
-               assertEquals("new_collection", result.name());
-               assertNotNull(result.createdAt());
-       }
-
-       @Test
-       void createCollection_success_standaloneClient() throws Exception {
+       void createCollection_success() throws Exception {
                when(solrClient.request(any(), isNull())).thenReturn(new 
NamedList<>());
 
-               CollectionCreationResult result = 
collectionService.createCollection("new_core", null, null, null);
+               CollectionCreationResult result = 
collectionService.createCollection("new_collection", "_default", 1, 1);
 
                assertNotNull(result);
                assertTrue(result.success());
-               assertEquals("new_core", result.name());
+               assertEquals("new_collection", result.name());
                assertNotNull(result.createdAt());
        }
 
        @Test
        void createCollection_defaultsApplied() throws Exception {
-               CloudSolrClient cloudClient = mock(CloudSolrClient.class);
-               when(cloudClient.request(any(), any())).thenReturn(new 
NamedList<>());
+               when(solrClient.request(any(), isNull())).thenReturn(new 
NamedList<>());
 
-               CollectionService service = new CollectionService(cloudClient, 
objectMapper);
-               CollectionCreationResult result = 
service.createCollection("defaults_collection", null, null, null);
+               CollectionCreationResult result = 
collectionService.createCollection("defaults_collection", null, null, null);
 
                assertTrue(result.success());
                assertEquals("defaults_collection", result.name());

Reply via email to