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

public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig)
        throws Exception 

Source Link

Document

Create a MiniSolrCloudCluster

Usage

From source file:org.apache.coheigea.bigdata.solr.ranger.RangerSolrCloudTest.java

License:Apache License

@BeforeClass
public static void setUp() throws Exception {

    JettyConfig.Builder jettyConfig = JettyConfig.builder();
    jettyConfig.waitForLoadingCoresToFinish(null);

    String solrConfig = new String(Files.readAllBytes(Paths.get("target/test-classes/solrcloud/solr.xml")),
            Charset.defaultCharset());
    tempDir = Files.createTempDirectory("solrcloud");
    server = new MiniSolrCloudCluster(2, tempDir, solrConfig, jettyConfig.build());

    // Insert the RangerSolrAuthorizer + BasicAuthPlugin
    try (ZkStateReader zkStateReader = new ZkStateReader(server.getZkServer().getZkAddress(), 10000, 10000)) {
        zkStateReader.getZkClient().delete(ZkStateReader.SOLR_SECURITY_CONF_PATH, 0, true);
        String securityJson = new String(Files.readAllBytes(Paths.get("src/test/resources/security.json")),
                Charset.defaultCharset());
        zkStateReader.getZkClient().create(ZkStateReader.SOLR_SECURITY_CONF_PATH,
                securityJson.getBytes(Charset.defaultCharset()), CreateMode.PERSISTENT, true);
    }/*www. ja v  a  2  s .  co m*/

    String configName = "core1Config";
    File configDir = Paths.get("target/test-classes/solrcloud").toFile();
    server.uploadConfigDir(configDir, configName);

    Map<String, String> collectionProperties = new HashMap<>();
    collectionProperties.put("config", "solrconfig.xml");
    collectionProperties.put("schema", "schema.xml");

    server.createCollection("docs", 1, 1, configName, collectionProperties);

    JettySolrRunner startedServer = server.startJettySolrRunner();
    assertTrue(startedServer.isRunning());

}

From source file:org.apache.coheigea.bigdata.solr.SolrCloudTest.java

License:Apache License

@BeforeClass
public static void setUp() throws Exception {

    JettyConfig.Builder jettyConfig = JettyConfig.builder();
    jettyConfig.waitForLoadingCoresToFinish(null);

    String solrConfig = new String(Files.readAllBytes(Paths.get("target/test-classes/solrcloud/solr.xml")),
            Charset.defaultCharset());
    tempDir = Files.createTempDirectory("solrcloud");
    server = new MiniSolrCloudCluster(2, tempDir, solrConfig, jettyConfig.build());

    String configName = "core1Config";
    File configDir = Paths.get("target/test-classes/solrcloud").toFile();
    server.uploadConfigDir(configDir, configName);

    Map<String, String> collectionProperties = new HashMap<>();
    collectionProperties.put("config", "solrconfig.xml");
    collectionProperties.put("schema", "schema.xml");

    server.createCollection("docs", 1, 1, configName, collectionProperties);

    JettySolrRunner startedServer = server.startJettySolrRunner();
    assertTrue(startedServer.isRunning());
}

From source file:org.apache.metron.solr.integration.components.SolrComponent.java

License:Apache License

@Override
public void start() throws UnableToStartException {
    try {// w  ww.  j  a v  a  2s .  c  o m
        File baseDir = Files.createTempDirectory("solrcomponent").toFile();
        baseDir.deleteOnExit();
        miniSolrCloudCluster = new MiniSolrCloudCluster(1, baseDir, new File(solrXmlPath),
                JettyConfig.builder().setPort(port).build());
        for (String name : collections.keySet()) {
            String configPath = collections.get(name);
            miniSolrCloudCluster.uploadConfigDir(new File(configPath), name);
        }
        miniSolrCloudCluster.createCollection("metron", 1, 1, "metron", new HashMap<String, String>());
        if (postStartCallback != null)
            postStartCallback.apply(this);
    } catch (Exception e) {
        throw new UnableToStartException(e.getMessage(), e);
    }
}