Package org.apache.solr.cloud
Class MiniSolrCloudCluster
- java.lang.Object
-
- org.apache.solr.cloud.MiniSolrCloudCluster
-
public class MiniSolrCloudCluster extends Object
"Mini" SolrCloud cluster to be used for testing
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMiniSolrCloudCluster.BuilderBuilder class for a MiniSolrCloudClusterstatic classMiniSolrCloudCluster.JettySolrRunnerWithMetrics
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_CLOUD_SOLR_XMLstatic intDEFAULT_TIMEOUTstatic StringTEST_URL_ALLOW_LIST
-
Constructor Summary
Constructors Constructor Description MiniSolrCloudCluster(int numServers, String hostContext, Path baseDir, String solrXml, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters)Create a MiniSolrCloudClusterMiniSolrCloudCluster(int numServers, String hostContext, Path baseDir, String solrXml, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters, org.apache.solr.client.solrj.embedded.SSLConfig sslConfig)Create a MiniSolrCloudClusterMiniSolrCloudCluster(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.solr.client.solrj.impl.CloudLegacySolrClient.BuilderbasicSolrClientBuilder()creates 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.CloudSolrClientbuildSolrClient()voiddeleteAllCollections()Delete all collections (and aliases)voiddeleteAllConfigSets()voiddumpCoreInfo(PrintStream pw)voiddumpMetrics(File outputDirectory, String fileName)static org.apache.solr.common.cloud.CollectionStatePredicateexpectedActive()static org.apache.solr.common.cloud.CollectionStatePredicateexpectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas)voidexpireZkSession(JettySolrRunner jetty)Make the zookeeper session on a particular jetty lose connection and expirePathgetBaseDir()JettySolrRunnergetJettySolrRunner(int index)List<JettySolrRunner>getJettySolrRunners()org.apache.solr.cloud.OverseergetOpenOverseer()static org.apache.solr.cloud.OverseergetOpenOverseer(List<org.apache.solr.cloud.Overseer> overseers)JettySolrRunnergetRandomJetty(Random random)JettySolrRunnergetReplicaJetty(org.apache.solr.common.cloud.Replica replica)Return the jetty that a particular replica resides onorg.apache.solr.client.solrj.impl.CloudSolrClientgetSolrClient()org.apache.solr.client.solrj.impl.CloudSolrClientgetSolrClient(String collectionName)Returns a SolrClient that has a defaultCollection set for it.org.apache.solr.common.cloud.SolrZkClientgetZkClient()ZkTestServergetZkServer()org.apache.solr.common.cloud.ZkStateReadergetZkStateReader()TheZkStateReaderinsidegetSolrClient().voidinjectChaos(Random random)voidshutdown()Shut down the cluster, including all Solr nodes and ZooKeeperJettySolrRunnerstartJettySolrRunner()Start a new Solr instance, using the default configJettySolrRunnerstartJettySolrRunner(String name, String hostContext, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters)Start a new Solr instanceJettySolrRunnerstartJettySolrRunner(String name, String hostContext, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters, org.apache.solr.client.solrj.embedded.SSLConfig sslConfig)Start a new Solr instanceJettySolrRunnerstartJettySolrRunner(String name, String hostContext, JettyConfig config)Start a new Solr instance on a particular servlet contextJettySolrRunnerstartJettySolrRunner(JettySolrRunner jetty)Add a previously stopped node back to the clusterJettySolrRunnerstopJettySolrRunner(int index)Stop a Solr instanceJettySolrRunnerstopJettySolrRunner(JettySolrRunner jetty)Stop 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)voidzkSetData(String path, byte[] data, boolean retryOnConnLoss)Set data in zk without exposing caller to the ZK API, i.e.
-
-
-
Field Detail
-
TEST_URL_ALLOW_LIST
public static final String TEST_URL_ALLOW_LIST
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_CLOUD_SOLR_XML
public static final String DEFAULT_CLOUD_SOLR_XML
-
-
Constructor Detail
-
MiniSolrCloudCluster
public MiniSolrCloudCluster(int numServers, Path baseDir, JettyConfig jettyConfig) throws ExceptionCreate 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, String hostContext, Path baseDir, String solrXml, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters) throws ExceptionCreate a MiniSolrCloudCluster- Parameters:
numServers- number of Solr servers to starthostContext- context path of Solr servers used by JettybaseDir- base directory that the mini cluster should be run fromsolrXml- solr.xml file to be uploaded to ZooKeeperextraServlets- Extra servlets to be started by JettyextraRequestFilters- extra filters to be started by Jetty- Throws:
Exception- if there was an error starting the cluster
-
MiniSolrCloudCluster
public MiniSolrCloudCluster(int numServers, String hostContext, Path baseDir, String solrXml, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters, org.apache.solr.client.solrj.embedded.SSLConfig sslConfig) throws ExceptionCreate a MiniSolrCloudCluster- Parameters:
numServers- number of Solr servers to starthostContext- context path of Solr servers used by JettybaseDir- base directory that the mini cluster should be run fromsolrXml- solr.xml file to be uploaded to ZooKeeperextraServlets- Extra servlets to be started by JettyextraRequestFilters- extra filters to be started by JettysslConfig- SSL configuration- Throws:
Exception- if there was an error starting the cluster
-
MiniSolrCloudCluster
public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig) throws ExceptionCreate 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 ExceptionCreate 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 Detail
-
waitForNode
public void waitForNode(JettySolrRunner jetty, int timeoutSeconds) throws InterruptedException, TimeoutException
- Throws:
InterruptedExceptionTimeoutException
-
waitForAllNodes
public void waitForAllNodes(int timeout) throws IOException, InterruptedException, TimeoutExceptionThis 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
public ZkTestServer getZkServer()
- Returns:
- ZooKeeper server used by the MiniCluster
-
getZkStateReader
public org.apache.solr.common.cloud.ZkStateReader getZkStateReader()
TheZkStateReaderinsidegetSolrClient().
-
getJettySolrRunners
public List<JettySolrRunner> getJettySolrRunners()
- Returns:
- Unmodifiable list of all the currently started Solr Jettys.
-
getRandomJetty
public JettySolrRunner getRandomJetty(Random random)
- Returns:
- a randomly-selected Jetty
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(String name, String hostContext, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters) throws Exception
Start a new Solr instance- Parameters:
hostContext- context path of Solr servers used by JettyextraServlets- Extra servlets to be started by JettyextraRequestFilters- extra filters to be started by Jetty- Returns:
- new Solr instance
- Throws:
Exception
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(String name, String hostContext, SortedMap<org.eclipse.jetty.servlet.ServletHolder,String> extraServlets, SortedMap<Class<? extends javax.servlet.Filter>,String> extraRequestFilters, org.apache.solr.client.solrj.embedded.SSLConfig sslConfig) throws Exception
Start a new Solr instance- Parameters:
hostContext- context path of Solr servers used by JettyextraServlets- Extra servlets to be started by JettyextraRequestFilters- extra filters to be started by JettysslConfig- SSL configuration- Returns:
- new Solr instance
- Throws:
Exception
-
getJettySolrRunner
public JettySolrRunner getJettySolrRunner(int index)
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(String name, String hostContext, JettyConfig config) throws Exception
Start a new Solr instance on a particular servlet context- Parameters:
name- the instance namehostContext- the context to run onconfig- a JettyConfig for the instance'sJettySolrRunner- Returns:
- a JettySolrRunner
- Throws:
Exception
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner() throws Exception
Start a new Solr instance, using the default config- Returns:
- a JettySolrRunner
- Throws:
Exception
-
stopJettySolrRunner
public JettySolrRunner stopJettySolrRunner(int index) throws Exception
Stop a Solr instance- Parameters:
index- the index of node in collection returned bygetJettySolrRunners()- Returns:
- the shut down node
- Throws:
Exception
-
startJettySolrRunner
public JettySolrRunner startJettySolrRunner(JettySolrRunner jetty) throws Exception
Add a previously stopped node back to the cluster- Parameters:
jetty- aJettySolrRunnerpreviously returned bystopJettySolrRunner(int)- Returns:
- the started node
- Throws:
Exception- on error
-
stopJettySolrRunner
public JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception
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
public void uploadConfigSet(Path configDir, String configName) throws IOException
Upload a config set- Parameters:
configDir- a path to the config set to uploadconfigName- the name to give the configset- Throws:
IOException
-
deleteAllCollections
public void deleteAllCollections() throws ExceptionDelete all collections (and aliases)- Throws:
Exception
-
shutdown
public void shutdown() throws ExceptionShut down the cluster, including all Solr nodes and ZooKeeper- Throws:
Exception
-
getBaseDir
public Path getBaseDir()
-
getSolrClient
public org.apache.solr.client.solrj.impl.CloudSolrClient getSolrClient()
-
getSolrClient
public org.apache.solr.client.solrj.impl.CloudSolrClient getSolrClient(String collectionName)
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
public void zkSetData(String path, byte[] data, boolean retryOnConnLoss) throws InterruptedException
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
public org.apache.solr.client.solrj.impl.CloudLegacySolrClient.Builder 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
public JettySolrRunner getReplicaJetty(org.apache.solr.common.cloud.Replica replica)
Return the jetty that a particular replica resides on
-
expireZkSession
public void expireZkSession(JettySolrRunner jetty)
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)
-
waitForActiveCollection
public void waitForActiveCollection(String collection, long wait, TimeUnit unit, int shards, int totalReplicas)
-
waitForActiveCollection
public void waitForActiveCollection(String collection, int shards, int totalReplicas)
-
waitForActiveCollection
public void waitForActiveCollection(String collection, long wait, TimeUnit unit)
-
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
public void waitForJettyToStop(JettySolrRunner runner) throws TimeoutException
- Throws:
TimeoutException
-
dumpMetrics
public void dumpMetrics(File outputDirectory, String fileName) throws IOException
- Throws:
IOException
-
dumpCoreInfo
public void dumpCoreInfo(PrintStream pw) throws IOException
- Throws:
IOException
-
-