Example usage for org.apache.solr.core SolrResourceLoader getInstancePath

List of usage examples for org.apache.solr.core SolrResourceLoader getInstancePath

Introduction

In this page you can find the example usage for org.apache.solr.core SolrResourceLoader getInstancePath.

Prototype

public Path getInstancePath() 

Source Link

Usage

From source file:com.indoqa.solr.spring.client.EmbeddedSolrServerBuilder.java

License:Apache License

public static SolrClient build(String url, String embeddedSolrConfigurationPath) {
    if (new File(embeddedSolrConfigurationPath).exists()) {
        deleteOldCoreProperties(embeddedSolrConfigurationPath);

        SolrResourceLoader loader = new SolrResourceLoader(getNormalizedPath(embeddedSolrConfigurationPath));
        NodeConfig nodeConfig = new NodeConfigBuilder(null, loader).build();
        CoreContainer container = new CoreContainer(nodeConfig);
        container.load();//from   w  w  w  .  ja v  a 2s .  c  om

        Map<String, String> properties = new HashMap<String, String>();
        properties.put(CoreDescriptor.CORE_DATADIR, getNormalizedPath(getDataDir(url)).toString());

        SolrCore core = container.create(CORE_NAME, loader.getInstancePath(), properties);
        return new EmbeddedSolrServer(core);
    }

    // use a temporary directory for the resource loader because Solr needs a real directory for this
    SolrResourceLoader loader = new SolrResourceLoader(createTempDirectory());
    NodeConfig nodeConfig = new NodeConfigBuilder(null, loader).build();
    CoreContainer container = new CoreContainer(nodeConfig);
    container.load();

    Map<String, String> properties = new HashMap<String, String>();
    properties.put(CoreDescriptor.CORE_DATADIR, getNormalizedPath(getDataDir(url)).toString());
    properties.put(CoreDescriptor.CORE_CONFIG, embeddedSolrConfigurationPath + "/conf/solrconfig.xml");
    properties.put(CoreDescriptor.CORE_SCHEMA, embeddedSolrConfigurationPath + "/conf/schema.xml");

    SolrCore core = container.create(CORE_NAME, loader.getInstancePath(), properties);
    return new EmbeddedSolrServer(core);

}

From source file:com.ngdata.hbaseindexer.mr.TestUtils.java

License:Apache License

private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir)
        throws IOException {

    LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs
            + ", outputShardDir: " + outputShardDir);

    // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();//from   w  ww . j  a va2 s . c o  m
    FileUtils.copyDirectory(solrHomeDir, tmpDir);
    solrHomeDir = tmpDir;

    Path solrDataDir = new Path(outputShardDir, "data");

    String dataDirStr = solrDataDir.toUri().toString();

    SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

    LOG.info(String.format(Locale.ENGLISH,
            "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
            solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(), loader.getConfigDir(), dataDirStr,
            outputShardDir));

    // TODO: This is fragile and should be well documented
    System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
    System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
    System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
    System.setProperty("solr.hdfs.blockcache.enabled", "false");
    System.setProperty("solr.autoCommit.maxTime", "600000");
    System.setProperty("solr.autoSoftCommit.maxTime", "-1");

    CoreContainer container = new CoreContainer(loader);
    container.load();

    SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()),
            ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);

    if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
        throw new UnsupportedOperationException(
                "Invalid configuration. Currently, the only DirectoryFactory supported is "
                        + HdfsDirectoryFactory.class.getSimpleName());
    }

    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
    return solr;
}

From source file:org.codice.solr.factory.impl.SolrCoreContainer.java

License:Open Source License

public SolrCoreContainer(SolrResourceLoader loader) {
    super(SolrXmlConfig.fromSolrHome(loader, loader.getInstancePath()));
    this.load();
}