use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer 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.client.solrj.embedded.EmbeddedSolrServer 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.client.solrj.embedded.EmbeddedSolrServer in project stanbol by apache.
the class FstLinkingEngineTest method setup.
@BeforeClass
public static void setup() throws Exception {
// get the working directory
// use property substitution to test this feature!
String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
String solrServerDir = prefix + TEST_INDEX_REL_PATH;
log.info("Test Solr Server Directory: {}", solrServerDir);
System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
config.setAllowInitialisation(false);
//the dbpedia default data
config.setIndexConfigurationName(TEST_SOLR_CORE_CONFIGURATION);
//init from datafile provider
config.setAllowInitialisation(true);
config.setName("DBpedia.org default data");
config.setDescription("Data used for FstLinkingEngie tests");
// create the Yard used for the tests
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrIndexRef, config.getIndexConfigurationName());
Assert.assertNotNull("Unable to initialise SolrServer for testing", server);
core = ((EmbeddedSolrServer) server).getCoreContainer().getCore(solrIndexRef.getIndex());
Assert.assertNotNull("Unable to get SolrCore '" + config.getIndexConfigurationName() + "' from SolrServer " + server, core);
yard = new SolrYard(server, config, null);
//setup the index configuration
LanguageConfiguration langConf = new LanguageConfiguration("not.used", new String[] { "en;field=dbpedia-ont:surfaceForm;generate=true" });
fstConfig = new IndexConfiguration(langConf, core, FieldEncodingEnum.SolrYard, "");
fstConfig.setExecutorService(Executors.newFixedThreadPool(1));
fstConfig.setTypeField("rdf:type");
fstConfig.setRankingField("entityhub:entityRank");
//fstConfig.setEntityCacheManager(new FastLRUCacheManager(2048));
fstConfig.setOrigin(new PlainLiteralImpl(TEST_ORIGIN));
//activate the FST config
//activate this configuration
fstConfig.activate();
//validate that the index contains the expected entities
validateTestIndex();
//now create the FST models
List<Future<?>> creationTasks = new ArrayList<Future<?>>();
for (CorpusInfo corpus : fstConfig.getCorpora()) {
Assert.assertTrue("Failure in UnitTest - all FST models need to be generate=true", corpus.allowCreation);
if (!corpus.isFstFile()) {
//create a task on the FST corpus creation service
creationTasks.add(fstConfig.getExecutorService().submit(new CorpusCreationTask(fstConfig, corpus)));
}
}
//typical hardware
for (Future<?> future : creationTasks) {
try {
future.get(FST_CREATION_WAIT_TIME, TimeUnit.SECONDS);
} catch (TimeoutException e) {
// we assert on future.isDone instead
}
Assert.assertTrue("FST Model creation not finished after " + FST_CREATION_WAIT_TIME + "seconds", future.isDone());
}
}
use of org.apache.solr.client.solrj.embedded.EmbeddedSolrServer 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.client.solrj.embedded.EmbeddedSolrServer in project jackrabbit-oak by apache.
the class FullTextSolrSearchTest method createEmbeddedSolrServerProvider.
private EmbeddedSolrServerProvider createEmbeddedSolrServerProvider(boolean http) throws Exception {
String tempDirectoryPath = FileUtils.getTempDirectoryPath();
File solrHome = new File(tempDirectoryPath, "solr" + System.nanoTime());
EmbeddedSolrServerConfiguration embeddedSolrServerConfiguration = new EmbeddedSolrServerConfiguration(solrHome.getAbsolutePath(), "oak");
if (http) {
embeddedSolrServerConfiguration = embeddedSolrServerConfiguration.withHttpConfiguration("/solr", 8983);
}
EmbeddedSolrServerProvider embeddedSolrServerProvider = embeddedSolrServerConfiguration.getProvider();
SolrServer solrServer = embeddedSolrServerProvider.getSolrServer();
if (storageEnabled != null && !storageEnabled) {
// change schema.xml and reload the core
File schemaXML = new File(solrHome.getAbsolutePath() + "/oak/conf", "schema.xml");
InputStream inputStream = getClass().getResourceAsStream("/solr/oak/conf/schema.xml");
String schemaString = IOUtils.toString(inputStream).replace("<dynamicField name=\"*\" type=\"text_general\" indexed=\"true\" stored=\"true\" multiValued=\"true\"/>", "<dynamicField name=\"*\" type=\"text_general\" indexed=\"true\" stored=\"false\" multiValued=\"true\"/>");
FileOutputStream fileOutputStream = new FileOutputStream(schemaXML);
IOUtils.copy(new StringReader(schemaString), fileOutputStream);
fileOutputStream.flush();
((EmbeddedSolrServer) solrServer).getCoreContainer().reload("oak");
}
return embeddedSolrServerProvider;
}
Aggregations