Package org.apache.solr.cloud
Class MiniSolrCloudCluster
java.lang.Object
org.apache.solr.cloud.MiniSolrCloudCluster
- All Implemented Interfaces:
AutoCloseable,SolrBackend
"Mini" SolrCloud cluster to be used for testing
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for a MiniSolrCloudCluster -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig) Create a MiniSolrCloudClusterMiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig, ZkTestServer zkTestServer, boolean formatZkServer) Create a MiniSolrCloudClusterMiniSolrCloudCluster(int numServers, Path baseDir, JettyConfig jettyConfig) Create a MiniSolrCloudCluster with default solr.xml -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shut down the cluster, including all Solr nodes and ZooKeeper.voidcreateCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) Creates a collection (or core for single-node backends).voidDelete all collections (and aliases)voidvoiddumpCoreInfo(PrintStream out) Dumps JSON-format information for all cores toout.voiddumpMetrics(PrintStream out) Dumps Prometheus-format metrics toout.static org.apache.solr.common.cloud.CollectionStatePredicateMatches when every slice is eitherSlice.State.ACTIVEorSlice.State.INACTIVE(none are mid-split or mid-restore), and every replica of the active slices is active.static org.apache.solr.common.cloud.CollectionStatePredicateexpectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas) Matches when the collection has exactlyexpectedShardsSlice.State.ACTIVEslices, and exactlyexpectedReplicasactive replicas across them.voidexpireZkSession(JettySolrRunner jetty) Make the zookeeper session on a particular jetty lose connection and expireorg.apache.solr.core.CoreContainerProvides access to an embedded/in-processCoreContainer-- if available (else null).Return the jetty for a node, identified by either its node name or its base URL.getJettySolrRunner(int index) org.apache.solr.cloud.Overseerstatic org.apache.solr.cloud.OverseergetOpenOverseer(List<org.apache.solr.cloud.Overseer> overseers) getRandomJetty(Random random) getReplicaJetty(org.apache.solr.common.cloud.Replica replica) Return the jetty that a particular replica resides onorg.apache.solr.client.solrj.impl.CloudSolrClientReturns the node / admin (collection-less)SolrClientowned by this backend.org.apache.solr.client.solrj.impl.CloudSolrClientgetSolrClient(String collectionName) Returns a SolrClient that has a defaultCollection set for it.org.apache.solr.client.solrj.SolrClientgetSolrClient(org.apache.solr.common.cloud.Replica replica) Returns the jetty-owned client for the node hostingreplica, scoped to that replica's core.org.apache.solr.common.cloud.SolrZkClientorg.apache.solr.common.cloud.ZkStateReaderTheZkStateReaderinsidegetSolrClient().booleanhasCollection(String name) Checks if a collection or core with the given name exists.booleanhasConfigSet(String name) Checks if a configSet with the given name exists.org.apache.solr.client.solrj.impl.CloudSolrClientnewSolrClient(String collection) Creates a newSolrClientdefaulted to the given collection.org.apache.solr.client.solrj.impl.CloudSolrClient.BuilderReturns a newCloudSolrClient.Builderpointed at this cluster.voidshutdown()Shut down the cluster, including all Solr nodes and ZooKeeperStart a new Solr instance, using the default configstartJettySolrRunner(String solrXml) Start a new Solr instance, using the default config but with a custom Solr xmlstartJettySolrRunner(String name, SortedMap<org.eclipse.jetty.ee10.servlet.ServletHolder, String> extraServlets, SortedMap<Class<? extends jakarta.servlet.Filter>, String> extraRequestFilters, org.apache.solr.client.solrj.jetty.SSLConfig sslConfig) Start a new Solr instancestartJettySolrRunner(String name, JettyConfig config, String solrXml) Start a new Solr instance on a particular servlet contextAdd a previously stopped node back to the cluster on a different portstartJettySolrRunner(JettySolrRunner jetty, boolean reusePort) Add a previously stopped node back to the clusterstopJettySolrRunner(int index) Stop a Solr instanceStop the given Solr instance.voiduploadConfigSet(Path configDir, String configName) Upload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).voidwaitForActiveCollection(String collection, int shards, int totalReplicas) voidwaitForActiveCollection(String collection, long wait, TimeUnit unit) voidwaitForActiveCollection(String collection, long wait, TimeUnit unit, int shards, int totalReplicas) voidwaitForAllNodes(int timeout) This method wait till all Solr JVMs ( Jettys ) are running .voidwaitForJettyToStop(JettySolrRunner runner) voidwaitForNode(JettySolrRunner jetty, int timeoutSeconds) voidSet data in zk without exposing caller to the ZK API, i.e.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.solr.SolrBackend
getBaseUrl, reloadCollection
-
Field Details
-
TEST_URL_ALLOW_LIST
- See Also:
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT- See Also:
-
DEFAULT_CLOUD_SOLR_XML
-
-
Constructor Details
-
MiniSolrCloudCluster
Create a MiniSolrCloudCluster with default solr.xml- Parameters:
numServers- number of Solr servers to startbaseDir- base directory that the mini cluster should be run fromjettyConfig- Jetty configuration- Throws:
Exception- if there was an error starting the cluster
-
MiniSolrCloudCluster
public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig) throws Exception Create a MiniSolrCloudCluster- Parameters:
numServers- number of Solr servers to startbaseDir- base directory that the mini cluster should be run fromsolrXml- solr.xml file to be uploaded to ZooKeeperjettyConfig- Jetty configuration- Throws:
Exception- if there was an error starting the cluster
-
MiniSolrCloudCluster
public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig, ZkTestServer zkTestServer, boolean formatZkServer) throws Exception Create a MiniSolrCloudCluster- Parameters:
numServers- number of Solr servers to startbaseDir- base directory that the mini cluster should be run fromsolrXml- solr.xml file to be uploaded to ZooKeeperjettyConfig- Jetty configurationzkTestServer- ZkTestServer to use. If null, one will be created- Throws:
Exception- if there was an error starting the cluster
-
-
Method Details
-
waitForNode
public void waitForNode(JettySolrRunner jetty, int timeoutSeconds) throws InterruptedException, TimeoutException - Throws:
InterruptedExceptionTimeoutException
-
waitForAllNodes
This method wait till all Solr JVMs ( Jettys ) are running . It waits up to the timeout (in seconds) for the JVMs to be up before throwing IllegalStateException. This is called automatically on cluster startup and so is only needed when starting additional Jetty instances.- Parameters:
timeout- number of seconds to wait before throwing an IllegalStateException- Throws:
IOException- if there was an error communicating with ZooKeeperInterruptedException- if the calling thread is interrupted during the wait operationTimeoutException- on timeout before all nodes being ready
-
getZkServer
- Returns:
- ZooKeeper server used by the MiniCluster
-
getZkStateReader
public org.apache.solr.common.cloud.ZkStateReader getZkStateReader()TheZkStateReaderinsidegetSolrClient(). -
getJettySolrRunners
- Returns:
- Unmodifiable list of all the currently started Solr Jettys.
-
getRandomJetty
- Returns:
- a randomly-selected Jetty
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(String name, SortedMap<org.eclipse.jetty.ee10.servlet.ServletHolder, String> extraServlets, SortedMap<Class<? extends jakarta.servlet.Filter>, throws ExceptionString> extraRequestFilters, org.apache.solr.client.solrj.jetty.SSLConfig sslConfig) Start a new Solr instance- Parameters:
extraServlets- Extra servlets to be started by JettyextraRequestFilters- extra filters to be started by JettysslConfig- SSL configuration- Returns:
- new Solr instance
- Throws:
Exception
-
getJettySolrRunner
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(String name, JettyConfig config, String solrXml) throws Exception Start a new Solr instance on a particular servlet context- Parameters:
name- the instance nameconfig- a JettyConfig for the instance'sJettySolrRunnersolrXml- the string content of the solr.xml file to use, or null to just use the cluster's default- Returns:
- a JettySolrRunner
- Throws:
Exception
-
startJettySolrRunner
Start a new Solr instance, using the default config- Returns:
- a JettySolrRunner
- Throws:
Exception
-
startJettySolrRunner
Start a new Solr instance, using the default config but with a custom Solr xml- Returns:
- a JettySolrRunner
- Throws:
Exception
-
startJettySolrRunner
Add a previously stopped node back to the cluster on a different port- Parameters:
jetty- aJettySolrRunnerpreviously returned bystopJettySolrRunner(int)- Returns:
- the started node
- Throws:
Exception- on error
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(JettySolrRunner jetty, boolean reusePort) throws Exception Add a previously stopped node back to the cluster- Parameters:
jetty- aJettySolrRunnerpreviously returned bystopJettySolrRunner(int)reusePort- the port previously used by jetty- Returns:
- the started node
- Throws:
Exception- on error
-
stopJettySolrRunner
Stop a Solr instance- Parameters:
index- the index of node in collection returned bygetJettySolrRunners()- Returns:
- the now shut down node
- Throws:
Exception
-
stopJettySolrRunner
Stop the given Solr instance. It will be removed from the cluster's list of running instances.- Parameters:
jetty- aJettySolrRunnerto be stopped- Returns:
- the same
JettySolrRunnerinstance provided to this method - Throws:
Exception- on error
-
deleteAllCollections
Delete all collections (and aliases)- Throws:
Exception
-
deleteAllConfigSets
- Throws:
Exception
-
uploadConfigSet
Description copied from interface:SolrBackendUpload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).- Specified by:
uploadConfigSetin interfaceSolrBackend- Parameters:
configDir- a path to the config set to uploadconfigName- the name to give the configSet- Throws:
IOException
-
hasConfigSet
Description copied from interface:SolrBackendChecks if a configSet with the given name exists.- Specified by:
hasConfigSetin interfaceSolrBackend- Parameters:
name- configSet name to check- Returns:
- true if the configSet exists, false otherwise
- Throws:
IOException
-
close
public void close()Shut down the cluster, including all Solr nodes and ZooKeeper. Doesn't throw.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSolrBackend
-
shutdown
Shut down the cluster, including all Solr nodes and ZooKeeper- Throws:
Exception
-
getBaseDir
-
getSolrClient
public org.apache.solr.client.solrj.impl.CloudSolrClient getSolrClient()Description copied from interface:SolrBackendReturns the node / admin (collection-less)SolrClientowned by this backend. The caller must NOT close it; it is released when this backend isSolrBackend.close()d. ACloudSolrClientshould be returned if appropriate. While it *can* be used to target specific collections, please useSolrBackend.newSolrClient(String)for that instead.- Specified by:
getSolrClientin interfaceSolrBackend
-
getSolrClient
Returns a SolrClient that has a defaultCollection set for it. SolrClients are cached by their collectionName for reuse and are closed for you.- Parameters:
collectionName- The name of the collection to get a SolrClient for.- Returns:
- CloudSolrClient configured for the specific collection.
-
newSolrClient
Description copied from interface:SolrBackendCreates 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.- Specified by:
newSolrClientin interfaceSolrBackend
-
newSolrClientBuilder
public org.apache.solr.client.solrj.impl.CloudSolrClient.Builder newSolrClientBuilder()Returns a newCloudSolrClient.Builderpointed at this cluster. -
getZkClient
public org.apache.solr.common.cloud.SolrZkClient getZkClient() -
zkSetData
Set data in zk without exposing caller to the ZK API, i.e. tests won't need to include Zookeeper dependencies- Throws:
InterruptedException
-
getReplicaJetty
Return the jetty that a particular replica resides on -
getJetty
Return the jetty for a node, identified by either its node name or its base URL. -
getSolrClient
public org.apache.solr.client.solrj.SolrClient getSolrClient(org.apache.solr.common.cloud.Replica replica) Returns the jetty-owned client for the node hostingreplica, scoped to that replica's core. The caller must not close the returned client -- it delegates to the jetty's own shared client, which the jetty itself owns. -
expireZkSession
Make the zookeeper session on a particular jetty lose connection and expire -
getOpenOverseer
public org.apache.solr.cloud.Overseer getOpenOverseer() -
getOpenOverseer
public static org.apache.solr.cloud.Overseer getOpenOverseer(List<org.apache.solr.cloud.Overseer> overseers) -
getCoreContainer
public org.apache.solr.core.CoreContainer getCoreContainer()Description copied from interface:SolrBackendProvides access to an embedded/in-processCoreContainer-- if available (else null). If there is more than one node, then one is returned.- Specified by:
getCoreContainerin interfaceSolrBackend- Returns:
- can be null.
-
createCollection
public void createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) throws org.apache.solr.client.solrj.SolrServerException, IOException Description copied from interface:SolrBackendCreates a collection (or core for single-node backends). Cloud backends honournumShardsandreplicationFactor; single-node backends (JettySolrRunner,EmbeddedSolrBackend) ignore those fields. Callers should useSolrBackend.hasCollection(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.- Specified by:
createCollectionin interfaceSolrBackend- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
hasCollection
Description copied from interface:SolrBackendChecks if a collection or core with the given name exists.- Specified by:
hasCollectionin interfaceSolrBackend- Parameters:
name- collection or core name to check- Returns:
- true if the collection/core exists, false otherwise
-
waitForActiveCollection
-
waitForActiveCollection
-
waitForActiveCollection
-
expectedShardsAndActiveReplicas
public static org.apache.solr.common.cloud.CollectionStatePredicate expectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas) Matches when the collection has exactlyexpectedShardsSlice.State.ACTIVEslices, and exactlyexpectedReplicasactive replicas across them. Slices in any other state (e.g. a split parent, or a slice under construction during a restore) and their replicas are not counted. -
expectedActive
public static org.apache.solr.common.cloud.CollectionStatePredicate expectedActive()Matches when every slice is eitherSlice.State.ACTIVEorSlice.State.INACTIVE(none are mid-split or mid-restore), and every replica of the active slices is active. -
waitForJettyToStop
- Throws:
TimeoutException
-
dumpMetrics
Description copied from interface:SolrBackendDumps Prometheus-format metrics toout. No-op is an acceptable implementation.- Specified by:
dumpMetricsin interfaceSolrBackend
-
dumpCoreInfo
Description copied from interface:SolrBackendDumps JSON-format information for all cores toout. No-op is an acceptable implementation. Default usesGET /admin/cores?indexInfo=true.- Specified by:
dumpCoreInfoin interfaceSolrBackend
-