use of org.apache.solr.core.CoreContainer in project stanbol by apache.
the class SolrServerPublishingComponent method updateFilter.
/**
* A change was made to the tracked CoreContainer (adding ,removal, ranking change).
* This removes and re-add the Servlet filter to apply such changes.
* @param name The name of the filter to be updated
* @param ref The serviceReference for the new CoreContainer to be added for
* the parsed name. <code>null</code> if the filter for that name needs only
* to be removed
* @param server The {@link CoreContainer} may be parsed in cases a reference
* is already available. If not the {@link #tracker} is used to look it up
* based on the parsed reference. This is basically a workaround for the
* fact that if the call originates form
* {@link ServiceTrackerCustomizer#addingService(ServiceReference)} the
* {@link CoreContainer} is not yet available via the tracker.
*/
protected void updateFilter(String name, ServiceReference ref, CoreContainer server) {
String serverPrefix = gloablPrefix + name;
Filter filter = published.remove(name);
if (filter != null) {
extHttpService.unregisterFilter(filter);
filter = null;
log.info("removed ServletFilter for SolrServer {} and prefix {}", name, serverPrefix);
}
// else no current filter for that name
if (ref != null || server != null) {
if (server == null) {
server = (CoreContainer) tracker.getService(ref);
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
try {
filter = new SolrFilter(server);
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
Dictionary<String, Object> filterPrpoerties = new Hashtable<String, Object>();
filterPrpoerties.put("path-prefix", serverPrefix);
String filterPrefix = serverPrefix + "/.*";
try {
extHttpService.registerFilter(filter, filterPrefix, filterPrpoerties, 0, null);
} catch (ServletException e) {
throw new IllegalStateException("Unable to register SolrDispatchFilter for" + "CoreContainer with name" + name + " (prefix: " + filterPrefix + "| properties: " + filterPrpoerties + ").", e);
}
log.info("added ServletFilter for SolrServer {} and prefix {}", name, serverPrefix);
}
// else no new filter to add
}
use of org.apache.solr.core.CoreContainer in project stanbol by apache.
the class EmbeddedSolrHelper method makeEmbeddedSolrServer.
/**
* Create a single core Solr server with it's own folder hierarchy.
*/
public static EmbeddedSolrServer makeEmbeddedSolrServer(File rootFolder, String solrServerId, String coreId, String configName) throws IOException, ParserConfigurationException, SAXException {
File solrFolder = new File(rootFolder, solrServerId);
FileUtils.deleteQuietly(solrFolder);
solrFolder.mkdir();
// solr conf file
File solrFile = new File(solrFolder, "solr.xml");
InputStream is = EmbeddedSolrHelper.class.getResourceAsStream("/solr.xml");
if (is == null) {
throw new IllegalArgumentException("missing test solr.xml file");
}
IOUtils.copy(is, new FileOutputStream(solrFile));
// solr conf folder with schema
File solrCoreFolder = new File(solrFolder, coreId);
solrCoreFolder.mkdir();
File solrConfFolder = new File(solrCoreFolder, "conf");
solrConfFolder.mkdir();
File schemaFile = new File(solrConfFolder, "schema.xml");
is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/schema.xml");
if (is == null) {
throw new IllegalArgumentException("missing test schema.xml file");
}
IOUtils.copy(is, new FileOutputStream(schemaFile));
File solrConfigFile = new File(solrConfFolder, "solrconfig.xml");
is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/solrconfig.xml");
if (is == null) {
throw new IllegalArgumentException("missing test solrconfig.xml file");
}
IOUtils.copy(is, new FileOutputStream(solrConfigFile));
// create the embedded server
SolrResourceLoader loader = new SolrResourceLoader(solrFolder.getAbsolutePath());
CoreContainer coreContainer = new CoreContainer(loader);
//NOTE: with Solr 4.4 we need to call coreContainer.load() otherwise we
//would be affected by the issue stated at
//http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201301.mbox/%3CB7B8B36F1A0BE24F842758C318E56E925EB334%40EXCHDB2.na1.ad.group%3E
//while this was introduced with 4.1 this only affects this code with 4.4
//as with an API change the methods implicitly calling load() where
//removed.
coreContainer.load();
CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreId, solrCoreFolder.getAbsolutePath());
SolrCore core = coreContainer.create(coreDescriptor);
// coreContainer.createAndLoad(solrHome, configFile)load();
coreContainer.register(coreId, core, true);
return new EmbeddedSolrServer(coreContainer, coreId);
}
use of org.apache.solr.core.CoreContainer in project Xponents by OpenSextant.
the class SolrProxy method setupCore.
/**
* Creates an EmbeddedSolrServer given solr home & the core to use.
* These may be null and you get the default.
*
* @param _solrHome solr home
* @param _coreName name of core
* @return the embedded solr server
* @throws ConfigException on err
*/
public static EmbeddedSolrServer setupCore(String _solrHome, String _coreName) throws ConfigException {
try {
CoreContainer solrContainer;
if (_solrHome == null) {
solrContainer = new CoreContainer();
} else {
solrContainer = new CoreContainer(_solrHome);
}
// since Solr 4.4
solrContainer.load();
return new EmbeddedSolrServer(solrContainer, _coreName);
} catch (Exception err) {
throw new ConfigException("Failed to set up Embedded Solr at " + _solrHome + " CORE:" + _coreName, err);
}
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class SolrSlf4jReporterTest method testReporter.
@Test
public void testReporter() throws Exception {
LogWatcherConfig watcherCfg = new LogWatcherConfig(true, null, null, 100);
LogWatcher watcher = LogWatcher.newRegisteredLogWatcher(watcherCfg, null);
watcher.setThreshold("INFO");
Path home = Paths.get(TEST_HOME());
// define these properties, they are used in solrconfig.xml
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8");
NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
h.coreName = DEFAULT_TEST_CORENAME;
SolrMetricManager metricManager = cc.getMetricManager();
Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
assertTrue(reporters.toString(), reporters.size() >= 2);
SolrMetricReporter reporter = reporters.get("test1");
assertNotNull(reporter);
assertTrue(reporter instanceof SolrSlf4jReporter);
reporter = reporters.get("test2");
assertNotNull(reporter);
assertTrue(reporter instanceof SolrSlf4jReporter);
watcher.reset();
Thread.sleep(5000);
SolrDocumentList history = watcher.getHistory(-1, null);
// dot-separated names are treated like class names and collapsed
// in regular log output, but here we get the full name
assertTrue(history.stream().filter(d -> "solr.node".equals(d.getFirstValue("logger"))).count() > 0);
assertTrue(history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() > 0);
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class SolrCloudReportersTest method testDefaultPlugins.
@Test
public void testDefaultPlugins() throws Exception {
String solrXml = IOUtils.toString(SolrCloudReportersTest.class.getResourceAsStream("/solr/solr.xml"), "UTF-8");
configureCluster(2).withSolrXml(solrXml).configure();
cluster.uploadConfigSet(Paths.get(TEST_PATH().toString(), "configsets", "minimal", "conf"), "test");
System.out.println("ZK: " + cluster.getZkServer().getZkAddress());
CollectionAdminRequest.createCollection("test_collection", "test", 2, 2).setMaxShardsPerNode(4).process(cluster.getSolrClient());
waitForState("Expected test_collection with 2 shards and 2 replicas", "test_collection", clusterShape(2, 2));
cluster.getJettySolrRunners().forEach(jetty -> {
CoreContainer cc = jetty.getCoreContainer();
SolrMetricManager metricManager = cc.getMetricManager();
Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.cluster");
assertEquals(reporters.toString(), 0, reporters.size());
for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*")) {
reporters = metricManager.getReporters(registryName);
assertEquals(reporters.toString(), 0 + jmxReporter, reporters.size());
}
});
}
Aggregations