Class JettySolrRunner

java.lang.Object
org.apache.solr.embedded.JettySolrRunner
All Implemented Interfaces:
AutoCloseable, SolrBackend

public class JettySolrRunner extends Object implements SolrBackend
Run solr using jetty
Since:
solr 1.3
  • Constructor Details

    • JettySolrRunner

      public JettySolrRunner(String solrHome, int port)
      Create a new JettySolrRunner.

      After construction, you must start the jetty with start()

      Parameters:
      solrHome - the solr home directory to use
      port - the port to run on
    • JettySolrRunner

      public JettySolrRunner(String solrHome, JettyConfig config)
      Construct a JettySolrRunner

      After construction, you must start the jetty with start()

      Parameters:
      solrHome - the base path to run from
      config - the configuration
    • JettySolrRunner

      public JettySolrRunner(String solrHome, Properties nodeProperties, JettyConfig config)
      Construct a JettySolrRunner

      After construction, you must start the jetty with start()

      Parameters:
      solrHome - the solrHome to use
      nodeProperties - the container properties
      config - the configuration
    • JettySolrRunner

      public JettySolrRunner(String solrHome, Properties nodeProperties, JettyConfig config, boolean enableProxy)
      Construct a JettySolrRunner

      After construction, you must start the jetty with start()

      Parameters:
      solrHome - the solrHome to use
      nodeProperties - the container properties
      config - the configuration
      enableProxy - enables proxy feature to disable connections
  • Method Details

    • injectJettyHandlers

      protected org.eclipse.jetty.server.Handler.Wrapper injectJettyHandlers(org.eclipse.jetty.server.Handler.Wrapper chain)
      descendants may inject own handler chaining it to the given root and then returning that own one
    • getFilter

      public <T extends jakarta.servlet.Filter> T getFilter(Class<T> filterClass)
      Returns:
      the first filter implemented by the specified class, or throws an exception
    • 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.
    • getNodeName

      public String getNodeName()
    • isRunning

      public boolean isRunning()
    • isStopped

      public boolean isStopped()
    • start

      public void start() throws Exception
      Start the Jetty server

      If the server has been started before, it will restart using the same port

      Throws:
      Exception - if an error occurs on startup
    • start

      public void start(boolean reusePort) throws Exception
      Start the Jetty server
      Parameters:
      reusePort - when true, will start up on the same port as used by any previous runs of this JettySolrRunner. If false, will use the port specified by the server's JettyConfig.
      Throws:
      Exception - if an error occurs on startup
    • stop

      public void stop() throws Exception
      Stop the Jetty server
      Throws:
      Exception - if an error occurs on shutdown
    • outputMetrics

      public void outputMetrics(PrintStream out) throws IOException
      Throws:
      IOException
    • dumpCoresInfo

      public void dumpCoresInfo(PrintStream pw)
    • getLocalPort

      public int getLocalPort()
      Returns the Local Port of the jetty Server.
      Throws:
      RuntimeException - if there is no Connector
    • getLocalPort

      public int getLocalPort(boolean internalPort)
      Returns the Local Port of the jetty Server.
      Parameters:
      internalPort - pass true to get the true jetty port rather than the proxy port if configured
      Throws:
      RuntimeException - if there is no Connector
    • setProxyPort

      public void setProxyPort(int proxyPort)
      Sets the port of a local socket proxy that sits in front of this server; if set then all client traffic will flow through the proxy, giving us the ability to simulate network partitions very easily.
    • getBaseUrl

      public URL getBaseUrl()
      Returns a base URL like http://localhost:8983/solr
    • getBaseURLV2

      public URL getBaseURLV2()
    • getProxyBaseUrl

      public URL getProxyBaseUrl()
      Returns a base URL consisting of the protocol, host, and port for a Connector in use by the Jetty Server contained in this runner.
    • main

      public static void main(String[] args) throws Exception
      A main class that starts jetty+solr This is useful for debugging
      Throws:
      Exception
    • getSolrHome

      public String getSolrHome()
      Returns:
      the Solr home directory of this JettySolrRunner
    • getNodeProperties

      public Properties getNodeProperties()
      Returns:
      this node's properties
    • getProxy

      public SocketProxy getProxy()
    • getRestClient

      public RestTestHarness getRestClient(String collection)
      Creates a REST client useful for HTTP operations. It closes when this JettySolrRunner is stopped.
    • newSolrClient

      public org.apache.solr.client.solrj.jetty.HttpJettySolrClient 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
    • getSolrClient

      public org.apache.solr.client.solrj.jetty.HttpJettySolrClient 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
    • createCollection

      public void createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create)
      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
    • 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
    • reloadCollection

      public void reloadCollection(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Description copied from interface: SolrBackend
      Reloads a collection or core by this name. The purpose is typically to clear caches.
      Specified by:
      reloadCollection in interface SolrBackend
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • getBaseUrl

      public String getBaseUrl(Random r)
      Description copied from interface: SolrBackend
      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.
      Specified by:
      getBaseUrl in interface SolrBackend
      Returns:
      base URL (e.g., "http://localhost:8983/solr"). Null for EmbeddedSolrServer.
    • close

      public void close()
      Description copied from interface: SolrBackend
      Shuts down this backend, releases the admin client, and all other resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SolrBackend