Class MiniSolrCloudCluster

java.lang.Object
org.apache.solr.cloud.MiniSolrCloudCluster
All Implemented Interfaces:
AutoCloseable, SolrBackend

public class MiniSolrCloudCluster extends Object implements SolrBackend
"Mini" SolrCloud cluster to be used for testing
  • Field Details

  • Constructor Details

    • MiniSolrCloudCluster

      public MiniSolrCloudCluster(int numServers, Path baseDir, JettyConfig jettyConfig) throws Exception
      Create a MiniSolrCloudCluster with default solr.xml
      Parameters:
      numServers - number of Solr servers to start
      baseDir - base directory that the mini cluster should be run from
      jettyConfig - 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 start
      baseDir - base directory that the mini cluster should be run from
      solrXml - solr.xml file to be uploaded to ZooKeeper
      jettyConfig - 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 start
      baseDir - base directory that the mini cluster should be run from
      solrXml - solr.xml file to be uploaded to ZooKeeper
      jettyConfig - Jetty configuration
      zkTestServer - 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:
      InterruptedException
      TimeoutException
    • waitForAllNodes

      public void waitForAllNodes(int timeout) throws IOException, InterruptedException, TimeoutException
      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 ZooKeeper
      InterruptedException - if the calling thread is interrupted during the wait operation
      TimeoutException - 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()
      The ZkStateReader inside getSolrClient().
    • 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, 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) throws Exception
      Start a new Solr instance
      Parameters:
      extraServlets - Extra servlets to be started by Jetty
      extraRequestFilters - extra filters to be started by Jetty
      sslConfig - SSL configuration
      Returns:
      new Solr instance
      Throws:
      Exception
    • getJettySolrRunner

      public JettySolrRunner getJettySolrRunner(int index)
    • 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 name
      config - a JettyConfig for the instance's JettySolrRunner
      solrXml - 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

      public JettySolrRunner startJettySolrRunner() throws Exception
      Start a new Solr instance, using the default config
      Returns:
      a JettySolrRunner
      Throws:
      Exception
    • startJettySolrRunner

      public JettySolrRunner startJettySolrRunner(String solrXml) throws Exception
      Start a new Solr instance, using the default config but with a custom Solr xml
      Returns:
      a JettySolrRunner
      Throws:
      Exception
    • startJettySolrRunner

      public JettySolrRunner startJettySolrRunner(JettySolrRunner jetty) throws Exception
      Add a previously stopped node back to the cluster on a different port
      Parameters:
      jetty - a JettySolrRunner previously returned by stopJettySolrRunner(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 - a JettySolrRunner previously returned by stopJettySolrRunner(int)
      reusePort - the port previously used by jetty
      Returns:
      the started node
      Throws:
      Exception - on error
    • stopJettySolrRunner

      public JettySolrRunner stopJettySolrRunner(int index) throws Exception
      Stop a Solr instance
      Parameters:
      index - the index of node in collection returned by getJettySolrRunners()
      Returns:
      the now shut down node
      Throws:
      Exception
    • 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 - a JettySolrRunner to be stopped
      Returns:
      the same JettySolrRunner instance provided to this method
      Throws:
      Exception - on error
    • deleteAllCollections

      public void deleteAllCollections() throws Exception
      Delete all collections (and aliases)
      Throws:
      Exception
    • deleteAllConfigSets

      public void deleteAllConfigSets() throws Exception
      Throws:
      Exception
    • uploadConfigSet

      public void uploadConfigSet(Path configDir, String configName) throws IOException
      Description copied from interface: SolrBackend
      Upload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).
      Specified by:
      uploadConfigSet in interface SolrBackend
      Parameters:
      configDir - a path to the config set to upload
      configName - the name to give the configSet
      Throws:
      IOException
    • hasConfigSet

      public boolean hasConfigSet(String name) throws IOException
      Description copied from interface: SolrBackend
      Checks if a configSet with the given name exists.
      Specified by:
      hasConfigSet in interface SolrBackend
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface SolrBackend
    • shutdown

      public void shutdown() throws Exception
      Shut 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()
      Description copied from interface: SolrBackend
      Returns the node / admin (collection-less) SolrClient owned by this backend. The caller must NOT close it; it is released when this backend is SolrBackend.close()d. A CloudSolrClient should be returned if appropriate. While it *can* be used to target specific collections, please use SolrBackend.newSolrClient(String) for that instead.
      Specified by:
      getSolrClient in interface SolrBackend
    • 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.
    • newSolrClient

      public org.apache.solr.client.solrj.impl.CloudSolrClient newSolrClient(String collection)
      Description copied from interface: SolrBackend
      Creates a new SolrClient defaulted 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:
      newSolrClient in interface SolrBackend
    • newSolrClientBuilder

      public org.apache.solr.client.solrj.impl.CloudSolrClient.Builder newSolrClientBuilder()
      Returns a new CloudSolrClient.Builder pointed at this cluster.
    • getZkClient

      public org.apache.solr.common.cloud.SolrZkClient getZkClient()
    • zkSetData

      public void zkSetData(String path, byte[] data) 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
    • getReplicaJetty

      public JettySolrRunner getReplicaJetty(org.apache.solr.common.cloud.Replica replica)
      Return the jetty that a particular replica resides on
    • getJetty

      public JettySolrRunner getJetty(String nodeNameOrUrl)
      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 hosting replica, 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

      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)
    • getCoreContainer

      public org.apache.solr.core.CoreContainer getCoreContainer()
      Description copied from interface: SolrBackend
      Provides access to an embedded/in-process CoreContainer -- if available (else null). If there is more than one node, then one is returned.
      Specified by:
      getCoreContainer in interface SolrBackend
      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: SolrBackend
      Creates a collection (or core for single-node backends). Cloud backends honour numShards and replicationFactor; single-node backends (JettySolrRunner, EmbeddedSolrBackend) ignore those fields. Callers should use SolrBackend.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:
      createCollection in interface SolrBackend
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • hasCollection

      public boolean hasCollection(String name)
      Description copied from interface: SolrBackend
      Checks if a collection or core with the given name exists.
      Specified by:
      hasCollection in interface SolrBackend
      Parameters:
      name - collection or core name to check
      Returns:
      true if the collection/core exists, false otherwise
    • 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)
      Matches when the collection has exactly expectedShards Slice.State.ACTIVE slices, and exactly expectedReplicas active 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 either Slice.State.ACTIVE or Slice.State.INACTIVE (none are mid-split or mid-restore), and every replica of the active slices is active.
    • waitForJettyToStop

      public void waitForJettyToStop(JettySolrRunner runner) throws TimeoutException
      Throws:
      TimeoutException
    • dumpMetrics

      public void dumpMetrics(PrintStream out)
      Description copied from interface: SolrBackend
      Dumps Prometheus-format metrics to out. No-op is an acceptable implementation.
      Specified by:
      dumpMetrics in interface SolrBackend
    • dumpCoreInfo

      public void dumpCoreInfo(PrintStream out)
      Description copied from interface: SolrBackend
      Dumps JSON-format information for all cores to out. No-op is an acceptable implementation. Default uses GET /admin/cores?indexInfo=true.
      Specified by:
      dumpCoreInfo in interface SolrBackend