Package org.apache.solr.cloud
Class MiniSolrCloudCluster
java.lang.Object
org.apache.solr.cloud.MiniSolrCloudCluster
"Mini" SolrCloud cluster to be used for testing
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for a MiniSolrCloudClusterstatic final class -
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 TypeMethodDescriptioncreates a basic CloudSolrClient Builder that then can be customized by callers, for example by specifying what collection they want to use.protected org.apache.solr.client.solrj.impl.CloudSolrClientvoidDelete all collections (and aliases)voidvoidvoiddumpMetrics(Path outputDirectory, String fileName) static org.apache.solr.common.cloud.CollectionStatePredicatestatic org.apache.solr.common.cloud.CollectionStatePredicateexpectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas) voidexpireZkSession(JettySolrRunner jetty) Make the zookeeper session on a particular jetty lose connection and expiregetJettySolrRunner(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.CloudSolrClientorg.apache.solr.client.solrj.impl.CloudSolrClientgetSolrClient(String collectionName) Returns a SolrClient that has a defaultCollection set for it.org.apache.solr.common.cloud.SolrZkClientorg.apache.solr.common.cloud.ZkStateReaderTheZkStateReaderinsidegetSolrClient().voidinjectChaos(Random random) voidshutdown()Shut down the cluster, including all Solr nodes and ZooKeeperStart a new Solr instance, using the default configstartJettySolrRunner(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 config setvoidwaitForActiveCollection(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.
-
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
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 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
-
uploadConfigSet
Upload a config set- Parameters:
configDir- a path to the config set to uploadconfigName- the name to give the configset- Throws:
IOException
-
deleteAllCollections
Delete all collections (and aliases)- Throws:
Exception
-
deleteAllConfigSets
- Throws:
Exception
-
shutdown
Shut down the cluster, including all Solr nodes and ZooKeeper- Throws:
Exception
-
getBaseDir
-
getSolrClient
public org.apache.solr.client.solrj.impl.CloudSolrClient getSolrClient() -
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.
-
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
-
buildSolrClient
protected org.apache.solr.client.solrj.impl.CloudSolrClient buildSolrClient() -
basicSolrClientBuilder
creates a basic CloudSolrClient Builder that then can be customized by callers, for example by specifying what collection they want to use.- Returns:
- CloudLegacySolrClient.Builder
-
getReplicaJetty
Return the jetty that a particular replica resides on -
expireZkSession
Make the zookeeper session on a particular jetty lose connection and expire -
injectChaos
- Throws:
Exception
-
getOpenOverseer
public org.apache.solr.cloud.Overseer getOpenOverseer() -
getOpenOverseer
public static org.apache.solr.cloud.Overseer getOpenOverseer(List<org.apache.solr.cloud.Overseer> overseers) -
waitForActiveCollection
-
waitForActiveCollection
-
waitForActiveCollection
-
expectedShardsAndActiveReplicas
public static org.apache.solr.common.cloud.CollectionStatePredicate expectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas) -
expectedActive
public static org.apache.solr.common.cloud.CollectionStatePredicate expectedActive() -
waitForJettyToStop
- Throws:
TimeoutException
-
dumpMetrics
- Throws:
IOException
-
dumpCoreInfo
- Throws:
IOException
-