Search in sources :

Example 1 with CoreContainer

use of org.apache.solr.core.CoreContainer in project ORCID-Source by ORCID.

the class EmbeddedSolrFactory method createCoreContainer.

private static CoreContainer createCoreContainer() throws FileNotFoundException {
    URL solrHome = EmbeddedSolrFactory.class.getResource("/solr");
    URL solrXml = EmbeddedSolrFactory.class.getResource("/solr" + "/solr.xml");
    File solrHomeDir = new File(solrHome.getFile());
    System.setProperty("solr.solr.home", solrHomeDir.getAbsolutePath());
    File solrXmlFile = new File(solrXml.getFile());
    ;
    CoreContainer coreContainer = CoreContainer.createAndLoad(solrHomeDir.getAbsolutePath(), solrXmlFile);
    return coreContainer;
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) File(java.io.File) URL(java.net.URL)

Example 2 with CoreContainer

use of org.apache.solr.core.CoreContainer in project jackrabbit-oak by apache.

the class EmbeddedSolrServerProvider method createSolrServer.

private SolrServer createSolrServer() throws Exception {
    log.info("creating new embedded solr server with config: {}", solrServerConfiguration);
    String solrHomePath = solrServerConfiguration.getSolrHomePath();
    String coreName = solrServerConfiguration.getCoreName();
    EmbeddedSolrServerConfiguration.HttpConfiguration httpConfiguration = solrServerConfiguration.getHttpConfiguration();
    if (solrHomePath != null && coreName != null) {
        checkSolrConfiguration(solrHomePath, coreName);
        if (httpConfiguration != null) {
            if (log.isInfoEnabled()) {
                log.info("starting embedded Solr server with http bindings");
            }
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(JettySolrRunner.class.getClassLoader());
            Integer httpPort = httpConfiguration.getHttpPort();
            String context = httpConfiguration.getContext();
            JettySolrRunner jettySolrRunner = null;
            try {
                jettySolrRunner = new JettySolrRunner(solrHomePath, context, httpPort, "solrconfig.xml", "schema.xml", true);
                if (log.isInfoEnabled()) {
                    log.info("Jetty runner instantiated");
                }
                jettySolrRunner.start(true);
                if (log.isInfoEnabled()) {
                    log.info("Jetty runner started");
                }
            } catch (Exception t) {
                if (log.isErrorEnabled()) {
                    log.error("an error has occurred while starting Solr Jetty", t);
                }
            } finally {
                if (jettySolrRunner != null && !jettySolrRunner.isRunning()) {
                    try {
                        jettySolrRunner.stop();
                        if (log.isInfoEnabled()) {
                            log.info("Jetty runner stopped");
                        }
                    } catch (Exception e) {
                        if (log.isErrorEnabled()) {
                            log.error("error while stopping the Jetty runner", e);
                        }
                    }
                }
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            if (log.isInfoEnabled()) {
                log.info("starting HTTP Solr server");
            }
            return new HttpWithJettySolrServer(SolrServerConfigurationDefaults.LOCAL_BASE_URL + ':' + httpPort + context + '/' + coreName, jettySolrRunner);
        } else {
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
            CoreContainer coreContainer = new CoreContainer(solrHomePath);
            try {
                if (!coreContainer.isLoaded(coreName)) {
                    coreContainer.load();
                }
            } catch (Exception e) {
                log.error("cannot load core {}, shutting down embedded Solr..", coreName, e);
                try {
                    coreContainer.shutdown();
                } catch (Exception se) {
                    log.error("could not shutdown embedded Solr", se);
                }
                return null;
            } finally {
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName);
            if (server.ping().getStatus() == 0) {
                return server;
            } else {
                throw new IOException("the embedded Solr server is not alive");
            }
        }
    } else {
        throw new Exception("SolrServer configuration proprties not set");
    }
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) CoreContainer(org.apache.solr.core.CoreContainer) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) IOException(java.io.IOException) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) IOException(java.io.IOException)

Example 3 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class HttpPartitionTest method testRf2.

protected void testRf2() throws Exception {
    // create a collection that has 1 shard but 2 replicas
    String testCollectionName = "c8n_1x2";
    createCollectionRetry(testCollectionName, 1, 2, 1);
    cloudClient.setDefaultCollection(testCollectionName);
    sendDoc(1);
    Replica notLeader = ensureAllReplicasAreActive(testCollectionName, "shard1", 1, 2, maxWaitSecsToSeeAllActive).get(0);
    // ok, now introduce a network partition between the leader and the replica
    SocketProxy proxy = getProxyForReplica(notLeader);
    proxy.close();
    // indexing during a partition
    sendDoc(2);
    // Have the partition last at least 1 sec
    // While this gives the impression that recovery is timing related, this is
    // really only
    // to give time for the state to be written to ZK before the test completes.
    // In other words,
    // without a brief pause, the test finishes so quickly that it doesn't give
    // time for the recovery process to kick-in
    Thread.sleep(sleepMsBeforeHealPartition);
    proxy.reopen();
    List<Replica> notLeaders = ensureAllReplicasAreActive(testCollectionName, "shard1", 1, 2, maxWaitSecsToSeeAllActive);
    sendDoc(3);
    // sent 3 docs in so far, verify they are on the leader and replica
    assertDocsExistInAllReplicas(notLeaders, testCollectionName, 1, 3);
    // Get the max version from the replica core to make sure it gets updated after recovery (see SOLR-7625)
    JettySolrRunner replicaJetty = getJettyOnPort(getReplicaPort(notLeader));
    CoreContainer coreContainer = replicaJetty.getCoreContainer();
    ZkCoreNodeProps replicaCoreNodeProps = new ZkCoreNodeProps(notLeader);
    String coreName = replicaCoreNodeProps.getCoreName();
    Long maxVersionBefore = null;
    try (SolrCore core = coreContainer.getCore(coreName)) {
        assertNotNull("Core '" + coreName + "' not found for replica: " + notLeader.getName(), core);
        UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
        maxVersionBefore = ulog.getCurrentMaxVersion();
    }
    assertNotNull("max version bucket seed not set for core " + coreName, maxVersionBefore);
    log.info("Looked up max version bucket seed " + maxVersionBefore + " for core " + coreName);
    // now up the stakes and do more docs
    int numDocs = TEST_NIGHTLY ? 1000 : 100;
    boolean hasPartition = false;
    for (int d = 0; d < numDocs; d++) {
        // create / restore partition every 100 docs
        if (d % 10 == 0) {
            if (hasPartition) {
                proxy.reopen();
                hasPartition = false;
            } else {
                if (d >= 10) {
                    proxy.close();
                    hasPartition = true;
                    Thread.sleep(sleepMsBeforeHealPartition);
                }
            }
        }
        // 4 is offset as we've already indexed 1-3
        sendDoc(d + 4);
    }
    // restore connectivity if lost
    if (hasPartition) {
        proxy.reopen();
    }
    notLeaders = ensureAllReplicasAreActive(testCollectionName, "shard1", 1, 2, maxWaitSecsToSeeAllActive);
    try (SolrCore core = coreContainer.getCore(coreName)) {
        assertNotNull("Core '" + coreName + "' not found for replica: " + notLeader.getName(), core);
        Long currentMaxVersion = core.getUpdateHandler().getUpdateLog().getCurrentMaxVersion();
        log.info("After recovery, looked up NEW max version bucket seed " + currentMaxVersion + " for core " + coreName + ", was: " + maxVersionBefore);
        assertTrue("max version bucket seed not updated after recovery!", currentMaxVersion > maxVersionBefore);
    }
    // verify all docs received
    assertDocsExistInAllReplicas(notLeaders, testCollectionName, 1, numDocs + 3);
    log.info("testRf2 succeeded ... deleting the " + testCollectionName + " collection");
    // try to clean up
    attemptCollectionDelete(cloudClient, testCollectionName);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrCore(org.apache.solr.core.SolrCore) UpdateLog(org.apache.solr.update.UpdateLog) Replica(org.apache.solr.common.cloud.Replica)

Example 4 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class LeaderElectionIntegrationTest method setupContainer.

private void setupContainer(int port, String shard) throws IOException, ParserConfigurationException, SAXException {
    Path data = createTempDir();
    System.setProperty("hostPort", Integer.toString(port));
    System.setProperty("shard", shard);
    System.setProperty("solr.data.dir", data.toString());
    System.setProperty("solr.solr.home", TEST_HOME());
    Set<Integer> ports = shardPorts.get(shard);
    if (ports == null) {
        ports = new HashSet<>();
        shardPorts.put(shard, ports);
    }
    ports.add(port);
    SolrResourceLoader loader = new SolrResourceLoader(createTempDir());
    Files.copy(TEST_PATH().resolve("solr.xml"), loader.getInstancePath().resolve("solr.xml"));
    CoreContainer container = new CoreContainer(loader);
    container.load();
    container.create("collection1_" + shard, ImmutableMap.of("collection", "collection1"));
    containerMap.put(port, container);
    System.clearProperty("solr.solr.home");
    System.clearProperty("hostPort");
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer)

Example 5 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class LeaderElectionIntegrationTest method tearDown.

@Override
public void tearDown() throws Exception {
    if (zkClient != null) {
        zkClient.close();
    }
    if (reader != null) {
        reader.close();
    }
    for (CoreContainer cc : containerMap.values()) {
        if (!cc.isShutDown()) {
            cc.shutdown();
        }
    }
    zkServer.shutdown();
    super.tearDown();
    System.clearProperty("zkClientTimeout");
    System.clearProperty("zkHost");
    System.clearProperty("hostPort");
    System.clearProperty("shard");
    System.clearProperty("solrcloud.update.delay");
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer)

Aggregations

CoreContainer (org.apache.solr.core.CoreContainer)95 SolrCore (org.apache.solr.core.SolrCore)30 Test (org.junit.Test)23 SolrException (org.apache.solr.common.SolrException)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)14 File (java.io.File)13 HashMap (java.util.HashMap)11 Replica (org.apache.solr.common.cloud.Replica)11 CoreDescriptor (org.apache.solr.core.CoreDescriptor)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)8 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 Map (java.util.Map)7 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Properties (java.util.Properties)6 DocCollection (org.apache.solr.common.cloud.DocCollection)6 Slice (org.apache.solr.common.cloud.Slice)6 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6