List of usage examples for org.apache.solr.core CoreContainer createAndLoad
public static CoreContainer createAndLoad(Path solrHome, Path configFile)
From source file:com.frank.search.solr.server.support.EmbeddedSolrServerFactory.java
License:Apache License
/** * Create {@link org.apache.solr.core.CoreContainer} for Solr version 4.4+ * /*from w ww . j a v a2 s . c o m*/ * @param solrHomeDirectory * @param solrXmlFile * @return */ private CoreContainer createCoreContainer(String solrHomeDirectory, File solrXmlFile) { return CoreContainer.createAndLoad(solrHomeDirectory, solrXmlFile); }
From source file:fr.cnes.sitools.metacatalogue.index.solr.SolRUtils.java
License:Open Source License
/** * //from ww w .ja v a 2 s . c o m * @param solrHome * @param configFileName * @return */ public static SolrServer getEmbeddedSolRServer(String solrHome, String configFileName, String coreName) { SolrServer solrServer; File configFile = new File(solrHome + "/" + configFileName); CoreContainer coreContainer = CoreContainer.createAndLoad(solrHome, configFile); EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName); solrServer = server; solrServer = checkServer(server); if (solrServer != null) { logger.info("First SolR valid connection"); } return solrServer; }
From source file:fr.jetoile.hadoopunit.component.SolrBootstrap.java
License:Apache License
private CoreContainer createCoreContainer(String solrHomeDirectory, File solrXmlFile) { return CoreContainer.createAndLoad(Paths.get(solrHomeDirectory), solrXmlFile.toPath()); }
From source file:io.redlink.solrlib.embedded.EmbeddedCoreContainer.java
License:Apache License
@Override
@SuppressWarnings({ "squid:S3725", "squid:S3776" })
protected synchronized void init(ExecutorService executorService) throws IOException {
Preconditions.checkState(Objects.isNull(coreContainer), "Already initialized!");
if (solrHome == null) {
solrHome = Files.createTempDirectory("solr-home");
log.debug("No solr-home set, using temp directory {}", solrHome);
deleteOnShutdown = true;//from www . j av a 2s . c o m
}
final Path absoluteSolrHome = this.solrHome.toAbsolutePath();
if (Files.isDirectory(absoluteSolrHome)) {
log.trace("solr-home exists: {}", absoluteSolrHome);
} else {
Files.createDirectories(absoluteSolrHome);
log.debug("Created solr-home: {}", absoluteSolrHome);
}
final Path lib = absoluteSolrHome.resolve("lib");
if (Files.isDirectory(lib)) {
log.trace("lib-directory exists: {}", lib);
} else {
Files.createDirectories(lib);
log.debug("Created solr-lib directory: {}", lib);
}
final Path solrXml = absoluteSolrHome.resolve("solr.xml");
if (!Files.exists(solrXml)) {
log.info("no solr.xml found, creating new at {}", solrXml);
try (PrintStream writer = new PrintStream(Files.newOutputStream(solrXml, StandardOpenOption.CREATE))) {
writer.printf("<!-- Generated by %s on %tF %<tT -->%n", getClass().getSimpleName(), new Date());
writer.println("<solr>");
writer.printf(" <str name=\"%s\">%s</str>%n", "sharedLib", absoluteSolrHome.relativize(lib));
writer.println("</solr>");
}
} else {
log.trace("found solr.xml: {}", solrXml);
}
for (SolrCoreDescriptor coreDescriptor : coreDescriptors) {
final String coreName = coreDescriptor.getCoreName();
if (availableCores.containsKey(coreName)) {
log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName,
coreDescriptor.getClass());
continue;
}
final Path coreDir = absoluteSolrHome.resolve(coreName);
Files.createDirectories(coreDir);
coreDescriptor.initCoreDirectory(coreDir, lib);
final Properties coreProperties = new Properties();
final Path corePropertiesFile = coreDir.resolve("core.properties");
if (Files.exists(corePropertiesFile)) {
try (InputStream inStream = Files.newInputStream(corePropertiesFile, StandardOpenOption.CREATE)) {
coreProperties.load(inStream);
}
log.debug("core.properties for {} found, updating", coreName);
} else {
log.debug("Creating new core {} in {}", coreName, coreDir);
}
coreProperties.setProperty("name", coreName);
try (OutputStream outputStream = Files.newOutputStream(corePropertiesFile)) {
coreProperties.store(outputStream, null);
}
if (coreDescriptor.getNumShards() > 1 || coreDescriptor.getReplicationFactor() > 1) {
log.warn("Deploying {} to EmbeddedCoreContainer, ignoring config of shards={},replication={}",
coreName, coreDescriptor.getNumShards(), coreDescriptor.getReplicationFactor());
}
availableCores.put(coreName, coreDescriptor);
}
log.info("Starting {} in solr-home '{}'", getClass().getSimpleName(), absoluteSolrHome);
coreContainer = CoreContainer.createAndLoad(absoluteSolrHome, solrXml);
availableCores.values().forEach(coreDescriptor -> {
final String coreName = coreDescriptor.getCoreName();
try (SolrClient solrClient = createSolrClient(coreName)) {
final NamedList<Object> coreStatus = CoreAdminRequest.getStatus(coreName, solrClient)
.getCoreStatus(coreName);
final NamedList<Object> indexStatus = coreStatus == null ? null
: (NamedList<Object>) coreStatus.get("index");
final Object lastModified = indexStatus == null ? null : indexStatus.get("lastModified");
// lastModified is null if there was never a update
scheduleCoreInit(executorService, coreDescriptor, lastModified == null);
} catch (SolrServerException | IOException e) {
if (log.isDebugEnabled()) {
log.error("Error initializing core {}", coreName, e);
}
//noinspection ThrowableResultOfMethodCallIgnored
coreInitExceptions.put(coreName, e);
}
});
}
From source file:io.vertigo.dynamo.plugins.search.solr.embedded.EmbeddedSolrSearchServicesPlugin.java
License:Apache License
private static CoreContainer createCoreContainer(final URL solrHomeURL) { Assertion.checkNotNull(solrHomeURL); //--------------------------------------------------------------------- final File home = new File(solrHomeURL.getFile()); Assertion.checkArgument(home.exists() && home.isDirectory(), "Le SolrHome : {0} n''existe pas, ou n''est pas un rpertoire.", home.getAbsolutePath()); Assertion.checkArgument(home.canWrite(), "L''application n''a pas les droits d''criture sur le SolrHome : {0}", home.getAbsolutePath()); final File solrXml = new File(home, "solr.xml"); final CoreContainer container; try {//from ww w . j av a2 s . c o m container = CoreContainer.createAndLoad(home.getAbsolutePath(), solrXml); //System.out.println("Solr Data In: " + home.getAbsolutePath() + "\\#CORE_NAME#\\data\\index\\"); return container; } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:net.yacy.cora.federate.solr.instance.EmbeddedInstance.java
License:Open Source License
public EmbeddedInstance(final File solr_config, final File containerPath, String givenDefaultCoreName, String[] initializeCoreNames) throws IOException { super();//from www . j a va 2 s.c o m // copy the solrconfig.xml to the storage path this.containerPath = containerPath; // ensure that default core path exists File defaultCorePath = new File(containerPath, givenDefaultCoreName); if (!defaultCorePath.exists()) defaultCorePath.mkdirs(); // migrate old conf directory File oldConf = new File(containerPath, "conf"); File confDir = new File(defaultCorePath, "conf"); if (oldConf.exists()) oldConf.renameTo(confDir); // migrate old data directory File oldData = new File(containerPath, "data"); File dataDir = new File(defaultCorePath, "data"); if (oldData.exists()) oldData.renameTo(dataDir); // create index subdirectory in data if it does not exist File indexDir = new File(dataDir, "index"); if (!indexDir.exists()) indexDir.mkdirs(); // initialize the cores' configuration for (String coreName : initializeCoreNames) { initializeCoreConf(solr_config, containerPath, coreName); } // initialize the coreContainer String containerDir = this.containerPath.getAbsolutePath(); // the home directory of all cores File configFile = new File(solr_config, "solr.xml"); // the configuration file for all cores this.coreContainer = CoreContainer.createAndLoad(containerDir, configFile); // this may take indefinitely long if solr files are broken if (this.coreContainer == null) throw new IOException( "cannot create core container dir = " + containerDir + ", configFile = " + configFile); // get the default core from the coreContainer this.defaultCoreName = givenDefaultCoreName; ConcurrentLog.info("SolrEmbeddedInstance", "detected default solr core: " + this.defaultCoreName); this.defaultCore = this.coreContainer.getCore(this.defaultCoreName); assert givenDefaultCoreName.equals(this.defaultCore.getName()) : "givenDefaultCoreName = " + givenDefaultCoreName + ", this.defaultCore.getName() = " + this.defaultCore.getName(); if (this.defaultCore == null) { throw new IOException("cannot get the default core; available = " + MemoryControl.available() + ", free = " + MemoryControl.free()); } this.defaultCoreServer = new EmbeddedSolrServer(this.coreContainer, this.defaultCoreName); // initialize core cache this.cores = new ConcurrentHashMap<String, SolrCore>(); this.cores.put(this.defaultCoreName, this.defaultCore); this.server = new ConcurrentHashMap<String, SolrClient>(); this.server.put(this.defaultCoreName, this.defaultCoreServer); }
From source file:org.broadleafcommerce.core.search.service.solr.SolrConfiguration.java
License:Open Source License
/** * This constructor should be used to set up embedded solr given a String to a SolrHome directory to use, or if * 'solrhome' is passed in as a parameter we will use the java temp directory to setup solr * * @param solrServer//from w ww . ja va2 s . c om * @throws IOException * @throws ParserConfigurationException * @throws SAXException * @throws IllegalStateException */ public SolrConfiguration(String solrServer) throws IOException, ParserConfigurationException, SAXException, IllegalStateException { // using embedded solr so we will default the core names this.setPrimaryName("primary"); this.setReindexName("reindex"); if (Objects.equals("solrhome", solrServer)) { final String baseTempPath = System.getProperty("java.io.tmpdir"); File tempDir = new File(baseTempPath + File.separator + System.getProperty("user.name") + File.separator + "solrhome-5.3.1"); if (System.getProperty("tmpdir.solrhome") != null) { //allow for an override of tmpdir tempDir = new File(System.getProperty("tmpdir.solrhome")); } if (!tempDir.exists()) { tempDir.mkdirs(); } solrServer = tempDir.getAbsolutePath(); } setSolrHomePath(solrServer); File solrXml = new File(new File(solrServer), "solr.xml"); if (!solrXml.exists()) { copyConfigToSolrHome(this.getClass().getResourceAsStream("/solr-default.xml"), solrXml); } buildSolrCoreDirectories(solrServer); LOG.debug(String.format("Using [%s] as solrhome", solrServer)); LOG.debug(String.format("Using [%s] as solr.xml", solrXml.getAbsoluteFile())); if (LOG.isTraceEnabled()) { LOG.trace("Contents of solr.xml:"); BufferedReader br = null; try { br = new BufferedReader(new FileReader(solrXml)); String line; while ((line = br.readLine()) != null) { LOG.trace(line); } } finally { if (br != null) { try { br.close(); } catch (Throwable e) { //do nothing } } } LOG.trace("Done printing solr.xml"); } CoreContainer coreContainer = CoreContainer.createAndLoad(solrServer, solrXml); EmbeddedSolrServer primaryServer = new EmbeddedSolrServer(coreContainer, getPrimaryName()); EmbeddedSolrServer reindexServer = new EmbeddedSolrServer(coreContainer, getReindexName()); this.setServer(primaryServer); this.setReindexServer(reindexServer); //NOTE: There is no reason to set the admin server here as the we will return the primary server //if the admin server is not set... }
From source file:org.broadleafcommerce.core.search.service.solr.SolrSearchServiceImpl.java
License:Apache License
public SolrSearchServiceImpl(String solrServer) throws IOException, ParserConfigurationException, SAXException { if ("solrhome".equals(solrServer)) { final String baseTempPath = System.getProperty("java.io.tmpdir"); File tempDir = new File(baseTempPath + File.separator + System.getProperty("user.name") + File.separator + "solrhome-4.10.3"); if (System.getProperty("tmpdir.solrhome") != null) { //allow for an override of tmpdir tempDir = new File(System.getProperty("tmpdir.solrhome")); }// w ww . ja v a 2s. c o m if (!tempDir.exists()) { tempDir.mkdirs(); } solrServer = tempDir.getAbsolutePath(); } solrHomePath = solrServer; File solrXml = new File(new File(solrServer), "solr.xml"); if (!solrXml.exists()) { copyConfigToSolrHome(this.getClass().getResourceAsStream("/solr-default.xml"), solrXml); } buildSolrCoreDirectories(solrServer); LOG.debug(String.format("Using [%s] as solrhome", solrServer)); LOG.debug(String.format("Using [%s] as solr.xml", solrXml.getAbsoluteFile())); if (LOG.isTraceEnabled()) { LOG.trace("Contents of solr.xml:"); BufferedReader br = null; try { br = new BufferedReader(new FileReader(solrXml)); String line; while ((line = br.readLine()) != null) { LOG.trace(line); } } finally { if (br != null) { try { br.close(); } catch (Throwable e) { //do nothing } } } LOG.trace("Done printing solr.xml"); } CoreContainer coreContainer = CoreContainer.createAndLoad(solrServer, solrXml); EmbeddedSolrServer primaryServer = new EmbeddedSolrServer(coreContainer, SolrContext.PRIMARY); EmbeddedSolrServer reindexServer = new EmbeddedSolrServer(coreContainer, SolrContext.REINDEX); SolrContext.setPrimaryServer(primaryServer); SolrContext.setReindexServer(reindexServer); //NOTE: There is no reason to set the admin server here as the SolrContext will return the primary server //if the admin server is not set... }
From source file:org.eclipse.rdf4j.sail.solr.client.embedded.Factory.java
License:Open Source License
@Override public SolrClient create(String spec) { String solrHome = SolrResourceLoader.locateSolrHome(); File configFile = new File(solrHome, SolrXmlConfig.SOLR_XML_FILE); return new EmbeddedSolrServer(CoreContainer.createAndLoad(solrHome, configFile), "embedded"); }
From source file:org.opencms.search.CmsSearchManager.java
License:Open Source License
/** * Creates the Solr core container.<p> * * @return the created core container//from w ww. j av a2s. c o m */ private CoreContainer createCoreContainer() { CoreContainer container = null; try { // get the core container // still no core container: create it container = CoreContainer.createAndLoad(Paths.get(m_solrConfig.getHome()), m_solrConfig.getSolrFile().toPath()); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SOLR_CORE_CONTAINER_CREATED_2, m_solrConfig.getHome(), m_solrConfig.getSolrFile().getName())); } } catch (Exception e) { LOG.error(Messages.get().container(Messages.ERR_SOLR_CORE_CONTAINER_NOT_CREATED_1, m_solrConfig.getSolrFile().getAbsolutePath()), e); } return container; }