List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer
public EmbeddedSolrServer(CoreContainer coreContainer, String coreName)
From source file:org.phenotips.data.indexing.internal.SolrPatientIndexer.java
License:Open Source License
@Override public void initialize() throws InitializationException { this.server = new EmbeddedSolrServer(this.cores.getContainer(), "patients"); }
From source file:org.phenotips.ontology.internal.solr.DefaultSolrOntologyServiceInitializer.java
License:Open Source License
@Override public void initialize(String serverName) throws InitializationException { try {//from w ww. ja va2 s . c om this.server = new EmbeddedSolrServer(this.cores.getContainer(), serverName); this.cache = this.cacheFactory.createNewLocalCache(new CacheConfiguration()); } catch (RuntimeException ex) { throw new InitializationException("Invalid URL specified for the Solr server: {}"); } catch (final CacheException ex) { throw new InitializationException("Cannot create cache: " + ex.getMessage()); } }
From source file:org.phenotips.termrequester.db.solr.SolrDatabaseService.java
License:Open Source License
@Override public synchronized void init(Path path) throws IOException { /* Make sure initialization is idempotent */ if (!up) {/*from w ww . j a v a2 s . c o m*/ up = true; File resources; this.path = path.resolve("solr"); try { ResourceManager.copyResourcesToPath(Paths.get("solr/"), this.path, SolrDatabaseService.class); } catch (DatabaseException e) { throw new IOException(e); } cores = new CoreContainer(this.path.toString()); cores.load(); server = new EmbeddedSolrServer(cores, CORE_NAME); if (server == null) { up = false; throw new IOException("Solr returned null server"); } mapper = new SolrMapper(); } }
From source file:org.phenotips.termrequester.db.solr.SolrDatabaseServiceTest.java
License:Open Source License
/** * Start up our own solr client. This is separate from usual start up to * make sure that our solr client doesn't mess with the instance being tested. * Will therefore shutdown the instance for the remainder of the test. *//* ww w .j a v a 2s .co m*/ private void startUpSolr() throws IOException { client.shutdown(); if (cores == null) { cores = new CoreContainer(folder.getRoot().toPath().resolve("solr").toString()); cores.load(); solr = new EmbeddedSolrServer(cores, SolrDatabaseService.CORE_NAME); } }
From source file:org.phenotips.variantstore.db.solr.SolrController.java
License:Open Source License
@Override public void init(Path path) throws DatabaseException { super.init(path); ResourceManager.copyResourcesToPath(this.getStoragePathSuffix(), this.path); // Spin Solr up logger.debug(String.valueOf(this.path)); cores = new CoreContainer(this.path.toString()); cores.load();/* ww w . j a va 2 s . c o m*/ server = new EmbeddedSolrServer(cores, "variants"); }
From source file:org.phenotips.vocabulary.internal.solr.DefaultSolrVocabularyResourceManager.java
License:Open Source License
@Override public void initialize(String vocabularyName) throws InitializationException { try {/*w w w . j av a2s .co m*/ this.core = new EmbeddedSolrServer(this.cores.getContainer(), vocabularyName); this.cache = this.cacheFactory.createNewLocalCache(new CacheConfiguration()); } catch (RuntimeException ex) { throw new InitializationException("Invalid Solr core: " + ex.getMessage()); } catch (final CacheException ex) { throw new InitializationException("Cannot create cache: " + ex.getMessage()); } }
From source file:org.reuseware.sokan.index.solr.SolrControler.java
License:Open Source License
private boolean startSolrServer() { if (solrConfig == null) { solrConfig = buildSolrConfig();//from www . j a v a 2 s. com } if (indexSchema == null) { indexSchema = buildIndexSchema(solrConfig); if (indexSchema == null) { return false; } } coreContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())); CoreDescriptor dcore = new CoreDescriptor(coreContainer, "", solrConfig.getResourceLoader().getInstanceDir()); dcore.setConfigName(solrConfig.getResourceName()); dcore.setSchemaName(indexSchema.getResourceName()); SolrCore core = new SolrCore(SolrConst.CORE_NAME, solrData, solrConfig, indexSchema, dcore); coreContainer.register(core, false); solrServer = new EmbeddedSolrServer(coreContainer, SolrConst.CORE_NAME); return true; }
From source file:org.roda.core.RodaCoreFactory.java
private static SolrClient instantiateSolr(Path solrHome) { SolrType solrType = SolrType.valueOf(getRodaConfiguration().getString(RodaConstants.CORE_SOLR_TYPE, RodaConstants.DEFAULT_SOLR_TYPE.toString())); if (TEST_SOLR_TYPE != null) { solrType = TEST_SOLR_TYPE;/* ww w. j a va 2 s . c o m*/ } if (solrType == RodaConstants.SolrType.HTTP) { String solrBaseUrl = getRodaConfiguration().getString(RodaConstants.CORE_SOLR_HTTP_URL, "http://localhost:8983/solr/"); return new HttpSolrClient(solrBaseUrl); } else if (solrType == RodaConstants.SolrType.HTTP_CLOUD) { String solrCloudZooKeeperUrls = getRodaConfiguration().getString( RodaConstants.CORE_SOLR_HTTP_CLOUD_URLS, "localhost:2181,localhost:2182,localhost:2183"); return new CloudSolrClient(solrCloudZooKeeperUrls); } else { // default to Embedded setSolrSystemProperties(); return new EmbeddedSolrServer(solrHome, "test"); } }
From source file:org.sakaiproject.nakamura.solr.EmbeddedSolrClient.java
License:Apache License
public void enable(SolrClientListener listener) throws IOException, ParserConfigurationException, SAXException { if (enabled) { return;/*from www. java 2s . com*/ } String schemaLocation = Utils.toString(properties.get(PROP_SOLR_SCHEMA), "schema.xml"); String configLocation = Utils.toString(properties.get(PROP_SOLR_CONFIG), "solrconfig.xml"); // Note that the following property could be set through JVM level // arguments too LOGGER.debug("Logger for Embedded Solr is in {slinghome}/log/solr.log at level INFO"); Configuration logConfiguration = getLogConfiguration(); // create a log configuration if none was found. leave alone any found // configurations // so that modifications will persist between server restarts if (logConfiguration == null) { logConfiguration = configurationAdmin .createFactoryConfiguration("org.apache.sling.commons.log.LogManager.factory.config", null); Dictionary<String, Object> loggingProperties = new Hashtable<String, Object>(); loggingProperties.put("org.apache.sling.commons.log.level", "INFO"); loggingProperties.put("org.apache.sling.commons.log.file", "logs/solr.log"); loggingProperties.put("org.apache.sling.commons.log.names", "org.apache.solr"); // add this property to give us something unique to re-find this // configuration loggingProperties.put(LOGGER_KEY, LOGGER_VAL); logConfiguration.update(loggingProperties); } System.setProperty("solr.solr.home", solrHome); File solrHomeFile = new File(solrHome); File coreDir = new File(solrHomeFile, "nakamura"); // File coreConfigDir = new File(solrHomeFile,"conf"); deployFile(solrHomeFile, "solr.xml"); // deployFile(coreConfigDir,"solrconfig.xml"); // deployFile(coreConfigDir,"schema.xml"); ClassLoader contextClassloader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ClosableInputSource schemaSource = null; ClosableInputSource configSource = null; try { NakamuraSolrResourceLoader loader = new NakamuraSolrResourceLoader(solrHome, this.getClass().getClassLoader()); coreContainer = new CoreContainer(loader); configSource = getSource(configLocation); schemaSource = getSource(schemaLocation); LOGGER.info("Configuring with Config {} schema {} ", configLocation, schemaLocation); SolrConfig config = new NakamuraSolrConfig(loader, configLocation, configSource); IndexSchema schema = new IndexSchema(config, schemaLocation, schemaSource); CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, "nakamura", coreDir.getAbsolutePath() + "nakamura"); nakamuraCore = new SolrCore("nakamura", coreDir.getAbsolutePath(), config, schema, coreDescriptor); coreContainer.register("nakamura", nakamuraCore, false); server = new EmbeddedSolrServer(coreContainer, "nakamura"); LoggerFactory.getLogger(this.getClass()).info("Contans cores {} ", coreContainer.getCoreNames()); this.enabled = true; this.listener = listener; } finally { Thread.currentThread().setContextClassLoader(contextClassloader); safeClose(schemaSource); safeClose(configSource); } }
From source file:org.sakaiproject.nakamura.solr.MultiMasterSolrClient.java
License:Apache License
public void enable(SolrClientListener listener) throws IOException, ParserConfigurationException, SAXException { if (enabled) { return;//from w ww . java 2 s. c o m } String configLocation = "solrconfig.xml"; String schemaLocation = "schema.xml"; if (multiMasterProperties != null) { configLocation = (String) multiMasterProperties.get(PROP_SOLR_CONFIG); schemaLocation = (String) multiMasterProperties.get(PROP_SOLR_SCHEMA); } // Note that the following property could be set through JVM level // arguments too LOGGER.debug("Logger for Embedded Solr is in {slinghome}/log/solr.log at level INFO"); Configuration logConfiguration = getLogConfiguration(); // create a log configuration if none was found. leave alone any found // configurations // so that modifications will persist between server restarts if (logConfiguration == null) { logConfiguration = configurationAdmin .createFactoryConfiguration("org.apache.sling.commons.log.LogManager.factory.config", null); Dictionary<String, Object> loggingProperties = new Hashtable<String, Object>(); loggingProperties.put("org.apache.sling.commons.log.level", "INFO"); loggingProperties.put("org.apache.sling.commons.log.file", "logs/solr.log"); loggingProperties.put("org.apache.sling.commons.log.names", "org.apache.solr"); // add this property to give us something unique to re-find this // configuration loggingProperties.put(LOGGER_KEY, LOGGER_VAL); logConfiguration.update(loggingProperties); } System.setProperty("solr.solr.home", solrHome); File solrHomeFile = new File(solrHome); File coreDir = new File(solrHomeFile, "nakamura"); // File coreConfigDir = new File(solrHomeFile,"conf"); deployFile(solrHomeFile, "solr.xml"); // deployFile(coreConfigDir,"solrconfig.xml"); // deployFile(coreConfigDir,"schema.xml"); ClassLoader contextClassloader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ClosableInputSource schemaSource = null; ClosableInputSource configSource = null; try { NakamuraSolrResourceLoader loader = new NakamuraSolrResourceLoader(solrHome, this.getClass().getClassLoader()); coreContainer = new CoreContainer(loader); configSource = getStream(configLocation); schemaSource = getStream(schemaLocation); SolrConfig config = new NakamuraSolrConfig(loader, configLocation, configSource); IndexSchema schema = new IndexSchema(config, null, schemaSource); nakamuraCore = new SolrCore("nakamura", coreDir.getAbsolutePath(), config, schema, null); coreContainer.register("nakamura", nakamuraCore, false); server = new EmbeddedSolrServer(coreContainer, "nakamura"); LoggerFactory.getLogger(this.getClass()).info("Contans cores {} ", coreContainer.getCoreNames()); } finally { Thread.currentThread().setContextClassLoader(contextClassloader); safeClose(schemaSource); safeClose(configSource); } this.enabled = true; this.listener = listener; }