Package org.apache.solr
Interface SolrBackend
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
EmbeddedSolrBackend,JettySolrRunner,MiniSolrCloudCluster,RemoteSolrBackend
Abstraction over a running Solr deployment for use in tests and benchmarks. The abstraction
normalizes how to shut down and perform other common operations as the methods indicate.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down this backend, releases the admin client, and all other resources.voidcreateCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) Creates a collection (or core for single-node backends).default voiddumpCoreInfo(PrintStream out) Dumps JSON-format information for all cores toout.default voiddumpMetrics(PrintStream out) Dumps Prometheus-format metrics toout.default StringgetBaseUrl(Random r) Returns the base URL of a Solr node.org.apache.solr.core.CoreContainerProvides access to an embedded/in-processCoreContainer-- if available (else null).org.apache.solr.client.solrj.SolrClientReturns the node / admin (collection-less)SolrClientowned by this backend.booleanhasCollection(String name) Checks if a collection or core with the given name exists.default booleanhasConfigSet(String name) Checks if a configSet with the given name exists.org.apache.solr.client.solrj.SolrClientnewSolrClient(String collection) Creates a newSolrClientdefaulted to the given collection.default voidreloadCollection(String name) Reloads a collection or core by this name.default voiduploadConfigSet(Path configDir, String name) Upload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).
-
Method Details
-
newSolrClient
Creates a newSolrClientdefaulted to the given collection. The caller owns this client and is responsible for closing it. Callers that want a long-lived client should cache it themselves. -
getSolrClient
org.apache.solr.client.solrj.SolrClient getSolrClient()Returns the node / admin (collection-less)SolrClientowned by this backend. The caller must NOT close it; it is released when this backend isclose()d. ACloudSolrClientshould be returned if appropriate. While it *can* be used to target specific collections, please usenewSolrClient(String)for that instead. -
uploadConfigSet
default void uploadConfigSet(Path configDir, String name) throws org.apache.solr.client.solrj.SolrServerException, IOException Upload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).- Parameters:
configDir- a path to the config set to uploadname- the name to give the configSet- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
hasConfigSet
default boolean hasConfigSet(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException Checks if a configSet with the given name exists.- Parameters:
name- configSet name to check- Returns:
- true if the configSet exists, false otherwise
- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
createCollection
void createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) throws org.apache.solr.client.solrj.SolrServerException, IOException Creates a collection (or core for single-node backends). Cloud backends honournumShardsandreplicationFactor; single-node backends (JettySolrRunner,EmbeddedSolrBackend) ignore those fields. Callers should usehasCollection(String)first if they want to avoid errors when the collection already exists. Tests/benchmarks that want to test how this works should not use this to do so.- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
hasCollection
boolean hasCollection(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException Checks if a collection or core with the given name exists.- Parameters:
name- collection or core name to check- Returns:
- true if the collection/core exists, false otherwise
- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
reloadCollection
default void reloadCollection(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException Reloads a collection or core by this name. The purpose is typically to clear caches.- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
getCoreContainer
org.apache.solr.core.CoreContainer getCoreContainer()Provides access to an embedded/in-processCoreContainer-- if available (else null). If there is more than one node, then one is returned.- Returns:
- can be null.
-
getBaseUrl
Returns the base URL of a Solr node. For cloud backends with multiple nodes, a live node is chosen at random. The URL does not include a trailing slash.- Returns:
- base URL (e.g., "http://localhost:8983/solr"). Null for EmbeddedSolrServer.
-
dumpMetrics
Dumps Prometheus-format metrics toout. No-op is an acceptable implementation. -
dumpCoreInfo
Dumps JSON-format information for all cores toout. No-op is an acceptable implementation. Default usesGET /admin/cores?indexInfo=true. -
close
void close()Shuts down this backend, releases the admin client, and all other resources.- Specified by:
closein interfaceAutoCloseable
-