Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.solr.cloud;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 import java.io.File;
 import java.util.List;
 
 
 
 public class MiniSolrCloudCluster {
   
   private static Logger log = LoggerFactory.getLogger(MiniSolrCloudCluster.class);
 
   private ZkTestServer zkServer;
   private List<JettySolrRunnerjettys;
   private File testDir;

  
"Mini" SolrCloud cluster to be used for testing

Parameters:
numServers number of Solr servers to start
hostContext context path of Solr servers used by Jetty
solrXml solr.xml file to be uploaded to ZooKeeper
extraServlets Extra servlets to be started by Jetty
extraRequestFilters extra filters to be started by Jetty
 
   public MiniSolrCloudCluster(int numServersString hostContextFile solrXml,
       SortedMap<ServletHolderStringextraServlets,
       SortedMap<ClassStringextraRequestFiltersthrows Exception {
      = Files.createTempDir();
 
     String zkDir = .getAbsolutePath() + .
       + "zookeeper/server1/data";
      = new ZkTestServer(zkDir);
     .run();
 
     SolrZkClient zkClient = null;
     InputStream is = null;
     try {
       zkClient = new SolrZkClient(.getZkHost(),
         ., 45000, null);
       zkClient.makePath("/solr"falsetrue);
       is = new FileInputStream(solrXml);
       zkClient.create("/solr/solr.xml", IOUtils.toByteArray(is),
         ...true);
     } finally {
       IOUtils.closeQuietly(is);
       if (zkClient != nullzkClient.close();
     }
 
     // tell solr to look in zookeeper for solr.xml
     System.setProperty("solr.solrxml.location","zookeeper");
     System.setProperty("zkHost".getZkAddress());
 
      = new LinkedList<JettySolrRunner>();
     for (int i = 0; i < numServers; ++i) {
       startJettySolrRunner(hostContextextraServletsextraRequestFilters);
     }
   }

  

Returns:
ZooKeeper server used by the MiniCluster
 
   public ZkTestServer getZkServer() {
     return ;
   }

  

Returns:
Unmodifiable list of all the currently started Solr Jettys.
 
    return Collections.unmodifiableList();
  }

  
Start a new Solr instance

Parameters:
hostContext context path of Solr servers used by Jetty
extraServlets Extra servlets to be started by Jetty
extraRequestFilters extra filters to be started by Jetty
Returns:
new Solr instance
      SortedMap<ServletHolderStringextraServlets,
      SortedMap<ClassStringextraRequestFiltersthrows Exception {
    String context = getHostContextSuitableForServletContext(hostContext);
    JettySolrRunner jetty = new JettySolrRunner(.getAbsolutePath(), context, 0, nullnull,
      trueextraServletsnullextraRequestFilters);
    jetty.start();
    .add(jetty);
    return jetty;
  }

  
Stop a Solr instance

Parameters:
index the index of node in collection returned by getJettySolrRunners()
Returns:
the shut down node
  public JettySolrRunner stopJettySolrRunner(int indexthrows Exception {
    JettySolrRunner jetty = .get(index);
    jetty.stop();
    .remove(index);
    return jetty;
  }

  
Shut down the cluster, including all Solr nodes and ZooKeeper
  public void shutdown() throws Exception {
    try {
      for (int i = .size() - 1; i >= 0; --i) {
        stopJettySolrRunner(i);
      }
    } finally {
      try {
        .shutdown();
      } finally {
        System.clearProperty("solr.solrxml.location");
        System.clearProperty("zkHost");
      }
    }
  }
    if (ctx == null || "".equals(ctx)) ctx = "/solr";
    if (ctx.endsWith("/")) ctx = ctx.substring(0,ctx.length()-1);;
    if (!ctx.startsWith("/")) ctx = "/" + ctx;
    return ctx;
  }
New to GrepCode? Check out our FAQ X