List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer
public EmbeddedSolrServer(CoreContainer coreContainer, String coreName)
From source file:at.newmedialab.lmf.search.services.indexing.SolrCoreRuntime.java
License:Apache License
public SolrCoreRuntime(SolrCoreConfiguration configuration, SolrIndexingService parent) { super(configuration); this.parent = parent; serverLock = new ReentrantLock(); LMFSearchFilter filter = CDIContext.getInstance(LMFSearchFilter.class); if (filter.getCores() == null) { log.warn("SOLR server not registered in this application, cannot index resources"); } else {/* w w w.ja v a 2 s . c om*/ serverLock.lock(); try { server = new EmbeddedSolrServer(filter.getCores(), config.getName()); log.debug("({}) created embedded SolrServer", config.getName()); } finally { serverLock.unlock(); } } }
From source file:at.pagu.soldockr.AbstractITestWithEmbeddedSolrServer.java
License:Apache License
@BeforeClass public static void initSolrServer() throws IOException, ParserConfigurationException, SAXException { System.setProperty("solr.solr.home", StringUtils.remove(ResourceUtils.getURL("classpath:at/pagu/soldockr").toString(), "file:/")); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); solrServer = new EmbeddedSolrServer(coreContainer, ""); }
From source file:at.pagu.soldockr.core.EmbeddedSolrServerFactory.java
License:Apache License
/** * @param path Any Path expression valid for use with {@link ResourceUtils} * @return new instance of {@link EmbeddedSolrServer} * @throws ParserConfigurationException// w ww . j a v a 2s. com * @throws IOException * @throws SAXException */ public final EmbeddedSolrServer createPathConfiguredSolrServer(String path) throws ParserConfigurationException, IOException, SAXException { String solrHome = System.getProperty(SOLR_HOME_SYSTEM_PROPERTY); if (StringUtils.isBlank(solrHome)) { solrHome = StringUtils.remove(ResourceUtils.getURL(path).toString(), "file:/"); } return new EmbeddedSolrServer(new CoreContainer(solrHome, new File(solrHome + "/solr.xml")), null); }
From source file:at.pagu.soldockr.repository.cdi.SolrTemplateProducer.java
License:Apache License
private SolrServer getSolrServerInstance() throws IOException, ParserConfigurationException, SAXException { System.setProperty("solr.solr.home", StringUtils.remove(ResourceUtils.getURL("classpath:at/pagu/soldockr").toString(), "file:/")); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); return new EmbeddedSolrServer(coreContainer, ""); }
From source file:au.org.ala.bhl.service.IndexingService.java
License:Open Source License
/** * Create a new instance of the Solr server API facade * // w w w. java 2s. co m * @return */ private SolrServer createSolrServer() { try { synchronized (_serverLock) { if (_solrServer == null) { if (!StringUtils.isEmpty(_serverURL)) { if (_serverURL.startsWith("http://")) { _solrServer = new CommonsHttpSolrServer(_serverURL); } else { // Note that the following property could be set through JVM level arguments too System.setProperty("solr.solr.home", _serverURL); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); _coreContainer = initializer.initialize(); _solrServer = new EmbeddedSolrServer(_coreContainer, ""); } } else { throw new RuntimeException("Neither a local SOLR path or a SOLR HTTP Url was specified!"); } } } return _solrServer; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.datasalt.pangool.solr.SolrRecordWriter.java
License:Apache License
public SolrRecordWriter(int batchSize, boolean outputZipFile, int threadCount, int queueSize, String localSolrHome, String zipName, TupleDocumentConverter converter, TaskAttemptContext context) { this.localSolrHome = localSolrHome; this.zipName = zipName; conf = context.getConfiguration();/*from w w w. jav a 2s .co m*/ this.batchSize = batchSize; setLogLevel("org.apache.solr.core", "WARN"); setLogLevel("org.apache.solr.update", "WARN"); Logger.getLogger("org.apache.solr.core").setLevel(Level.WARN); Logger.getLogger("org.apache.solr.update").setLevel(Level.WARN); java.util.logging.Logger.getLogger("org.apache.solr.core").setLevel(java.util.logging.Level.WARNING); java.util.logging.Logger.getLogger("org.apache.solr.update").setLevel(java.util.logging.Level.WARNING); setLogLevel("org.apache.solr", "WARN"); Logger.getLogger("org.apache.solr").setLevel(Level.WARN); java.util.logging.Logger.getLogger("org.apache.solr").setLevel(java.util.logging.Level.WARNING); heartBeater = new HeartBeater(context); try { heartBeater.needHeartBeat(); /** The actual file in hdfs that holds the configuration. */ this.outputZipFile = outputZipFile; this.fs = FileSystem.get(conf); perm = new Path(FileOutputFormat.getOutputPath(context), getOutFileName(context, "part")); // Make a task unique name that contains the actual index output name to // make debugging simpler // Note: if using JVM reuse, the sequence number will not be reset for a // new task using the jvm Path temp = conf.getLocalPath("mapred.local.dir", "solr_" + conf.get("mapred.task.id") + '.' + sequence.incrementAndGet()); if (outputZipFile && !perm.getName().endsWith(".zip")) { perm = perm.suffix(".zip"); } fs.delete(temp, true); // delete old, if any fs.delete(perm, true); // delete old, if any local = fs.startLocalOutput(perm, temp); solrHome = findSolrConfig(conf); // } // Verify that the solr home has a conf and lib directory if (solrHome == null) { throw new IOException("Unable to find solr home setting"); } // Setup a solr instance that we can batch writes to LOG.info("SolrHome: " + solrHome.toUri()); String dataDir = new File(local.toString(), "data").getAbsoluteFile().toString(); // copy the schema to the conf dir File confDir = new File(local.toString(), "conf"); confDir.mkdirs(); File unpackedSolrHome = new File(solrHome.toString()); FileUtils.copyDirectory(new File(unpackedSolrHome, "conf"), confDir); Properties props = new Properties(); props.setProperty("solr.data.dir", dataDir); props.setProperty("solr.home", solrHome.toString()); SolrResourceLoader loader = new SolrResourceLoader(solrHome.toString(), null, props); LOG.info(String.format( "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to temporary directory %s, with permdir %s", solrHome, solrHome.toUri(), loader.getInstanceDir(), loader.getConfigDir(), dataDir, perm)); CoreContainer container = new CoreContainer(loader); CoreDescriptor descr = new CoreDescriptor(container, "core1", solrHome.toString()); descr.setDataDir(dataDir); descr.setCoreProperties(props); core = container.create(descr); container.register(core, false); solr = new EmbeddedSolrServer(container, "core1"); batchWriter = new BatchWriter(solr, batchSize, context.getTaskAttemptID().getTaskID(), threadCount, queueSize); this.converter = converter; } catch (Exception e) { e.printStackTrace(); LOG.error(e); throw new IllegalStateException(String.format("Failed to initialize record writer for %s, %s", context.getJobName(), conf.get("mapred.task.id")), e); } finally { heartBeater.cancelHeartBeat(); } }
From source file:com.frank.search.solr.server.support.EmbeddedSolrServerFactory.java
License:Apache License
/** * @param path/*from www . j av a 2 s . co m*/ * Any Path expression valid for use with * {@link org.springframework.util.ResourceUtils} * @return new instance of * {@link org.apache.solr.client.solrj.embedded.EmbeddedSolrServer} * @throws javax.xml.parsers.ParserConfigurationException * @throws java.io.IOException * @throws org.xml.sax.SAXException */ public final EmbeddedSolrServer createPathConfiguredSolrServer(String path) throws ParserConfigurationException, IOException, SAXException { String solrHomeDirectory = System.getProperty(SOLR_HOME_SYSTEM_PROPERTY); if (StringUtils.isBlank(solrHomeDirectory)) { solrHomeDirectory = ResourceUtils.getURL(path).getPath(); } solrHomeDirectory = URLDecoder.decode(solrHomeDirectory, "utf-8"); return new EmbeddedSolrServer(createCoreContainer(solrHomeDirectory), "collection1"); }
From source file:com.googlecode.fascinator.indexer.SolrWrapperQueueConsumer.java
License:Open Source License
/** * Initialize a Solr core object./*from ww w . j a va 2 s.co m*/ * * @param coreName : The core to initialize * @return SolrServer : The initialized core */ private SolrServer initCore(String core) { boolean isEmbedded = globalConfig.getBoolean(false, "indexer", core, "embedded"); try { // Embedded Solr if (isEmbedded) { // Solr over HTTP - Needed to run commits // so the core web server sees them. String uri = globalConfig.getString(null, "indexer", core, "uri"); if (uri == null) { log.error("No URI provided for core: '{}'", core); return null; } URI solrUri = new URI(uri); commit = new CommonsHttpSolrServer(solrUri.toURL()); username = globalConfig.getString(null, "indexer", core, "username"); password = globalConfig.getString(null, "indexer", core, "password"); if (username != null && password != null) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); HttpClient hc = ((CommonsHttpSolrServer) solr).getHttpClient(); hc.getParams().setAuthenticationPreemptive(true); hc.getState().setCredentials(AuthScope.ANY, credentials); } // First time execution if (coreContainer == null) { String home = globalConfig.getString(DEFAULT_SOLR_HOME, "indexer", "home"); log.info("Embedded Solr Home = {}", home); File homeDir = new File(home); if (!homeDir.exists()) { log.error("Solr directory does not exist!"); return null; } System.setProperty("solr.solr.home", homeDir.getAbsolutePath()); File coreXmlFile = new File(homeDir, "solr.xml"); coreContainer = new CoreContainer(homeDir.getAbsolutePath(), coreXmlFile); for (SolrCore aCore : coreContainer.getCores()) { log.info("Loaded core: {}", aCore.getName()); } } String coreName = globalConfig.getString(null, "indexer", core, "coreName"); if (coreName == null) { log.error("No 'coreName' node for core: '{}'", core); return null; } return new EmbeddedSolrServer(coreContainer, coreName); // Solr over HTTP } else { String uri = globalConfig.getString(null, "indexer", core, "uri"); if (uri == null) { log.error("No URI provided for core: '{}'", core); return null; } URI solrUri = new URI(uri); CommonsHttpSolrServer thisCore = new CommonsHttpSolrServer(solrUri.toURL()); username = globalConfig.getString(null, "indexer", core, "username"); password = globalConfig.getString(null, "indexer", core, "password"); if (username != null && password != null) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); HttpClient hc = thisCore.getHttpClient(); hc.getParams().setAuthenticationPreemptive(true); hc.getState().setCredentials(AuthScope.ANY, credentials); } return thisCore; } } catch (MalformedURLException mue) { log.error(core + " : Malformed URL", mue); } catch (URISyntaxException urise) { log.error(core + " : Invalid URI", urise); } catch (IOException ioe) { log.error(core + " : Failed to read Solr configuration", ioe); } catch (ParserConfigurationException pce) { log.error(core + " : Failed to parse Solr configuration", pce); } catch (SAXException saxe) { log.error(core + " : Failed to load Solr configuration", saxe); } return null; }
From source file:com.googlecode.solrgeonames.harvester.Harvester.java
License:Open Source License
/** * Start up an embedded Solr server.//from w w w . j a v a2 s .c o m * * @param home: The path to the Solr home directory * @return EmbeddedSolrServer: The instantiated server * @throws Exception if any errors occur */ private EmbeddedSolrServer startSolr(String home) throws Exception { try { SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null); IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); solrContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())); CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "", solrConfig.getResourceLoader().getInstanceDir()); descriptor.setConfigName(solrConfig.getResourceName()); descriptor.setSchemaName(schema.getResourceName()); solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor); solrContainer.register("", solrCore, false); return new EmbeddedSolrServer(solrContainer, ""); } catch (Exception ex) { log.error("\nFailed to start Solr server\n"); throw ex; } }
From source file:com.googlecode.solrgeonames.server.GeoContextListener.java
License:Open Source License
/** * Start up an embedded Solr server.//w w w . ja va 2 s . co m * * @param home: The path to the Solr home directory * @return EmbeddedSolrServer: The instantiated server * @throws Exception if any errors occur */ private EmbeddedSolrServer startSolr(String home) throws Exception { SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null); IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null); solrContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())); CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "", solrConfig.getResourceLoader().getInstanceDir()); descriptor.setConfigName(solrConfig.getResourceName()); descriptor.setSchemaName(schema.getResourceName()); SolrCore solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor); solrContainer.register("", solrCore, false); return new EmbeddedSolrServer(solrContainer, ""); }