Example usage for org.apache.solr.cloud MiniSolrCloudCluster MiniSolrCloudCluster

List of usage examples for org.apache.solr.cloud MiniSolrCloudCluster MiniSolrCloudCluster

Introduction

In this page you can find the example usage for org.apache.solr.cloud MiniSolrCloudCluster MiniSolrCloudCluster.

Prototype

MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig,
        ZkTestServer zkTestServer, Optional<String> securityJson) throws Exception 

Source Link

Document

Create a MiniSolrCloudCluster.

Usage

From source file:org.janusgraph.diskstorage.solr.SolrRunner.java

License:Apache License

public static void start(boolean isKerberosEnabled) throws Exception {
    kerberosEnabled = isKerberosEnabled;

    if (ZOOKEEPER_URLS_SYSTEM_PROPERTY != null) {
        return;//  ww  w  . j  a  v a2  s.  co  m
    }
    String userDir = System.getProperty("user.dir");
    String solrHome = userDir.contains("janusgraph-solr")
            ? Joiner.on(File.separator).join(userDir, "target", "test-classes", "solr")
            : Joiner.on(File.separator).join(userDir, "janusgraph-solr", "target", "test-classes", "solr");

    File templateDirectory = new File(solrHome + File.separator + TEMPLATE_DIRECTORY);
    Preconditions.checkState(templateDirectory.exists());

    File temp = new File(TMP_DIRECTORY + File.separator + "solr-" + System.nanoTime());
    Preconditions.checkState(!temp.exists());

    Preconditions.checkState(temp.mkdirs(), "Unable to create solr temporary directory {}",
            temp.getAbsolutePath());
    temp.deleteOnExit();

    final String solrXml = new String(Files.readAllBytes(new File(solrHome, "solr.xml").toPath()));
    if (!kerberosEnabled) {
        miniSolrCloudCluster = new MiniSolrCloudCluster(NUM_SERVERS, null, temp.toPath(), solrXml, null, null);
    } else {
        JettyConfig jettyConfig = JettyConfig.builder().setContext(null).withSSLConfig(null).withFilters(null)
                .withServlets(null).build();
        miniSolrCloudCluster = new ConfigurableMiniSolrCloudCluster(NUM_SERVERS, temp.toPath(), solrXml,
                jettyConfig, null, Optional.of(SECURITY_JSON));
    }

    for (String core : COLLECTIONS) {
        File coreDirectory = new File(temp.getAbsolutePath() + File.separator + core);
        Preconditions.checkState(coreDirectory.mkdirs());
        FileUtils.copyDirectory(templateDirectory, coreDirectory);
        miniSolrCloudCluster.uploadConfigSet(Paths.get(coreDirectory.getAbsolutePath()), core);
    }
}