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;
}
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");
}
}
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);
}
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");
}
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");
}
Aggregations