@Override public void initialize() { File solrHome = new File(this.environment.getPermanentDirectory().getAbsolutePath(), "solr"); this.cores = new CoreContainer(solrHome.getAbsolutePath()); this.cores.load(); }
public void destroy() { if (cores != null) { cores.shutdown(); cores = null; } }
/** * Handle "RENAME" Action * * @param req * @param rsp * * @return true if a modification has resulted that requires persistance * of the CoreContainer configuration. * * @throws SolrException */ protected boolean handleRenameAction(SolrQueryRequest req, SolrQueryResponse rsp) throws SolrException { SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.OTHER); String cname = params.get(CoreAdminParams.CORE); boolean doPersist = false; if (cname.equals(name)) return doPersist; SolrCore core = coreContainer.getCore(cname); if (core != null) { doPersist = coreContainer.isPersistent(); coreContainer.register(name, core, false); coreContainer.remove(cname); core.close(); } return doPersist; }
private CoreContainer createCoreContainer(String solrHome) throws SolrServerException { CoreContainer coreContainer = new CoreContainer(solrHome); coreContainer.load(); if (coreContainer.getCores().size() == 0) { throw new SolrServerException("Failed to initialize the Solr core. " + "Please check the configuration and log messages."); } else if (coreContainer.getCores().size() > 1) { this.logger.warn("Multiple Solr cores detected: [{}]. Using the first one.", StringUtils.join(coreContainer.getCoreNames(), ", ")); } return coreContainer; }
/** * Shuts down and frees any resources */ public void close() { if (container != null) { for (SolrCore c : container.getCores()) { if (c.getOpenCount() > 1) throw new RuntimeException("SolrCore.getOpenCount()=="+core.getOpenCount()); } } if (container != null) { container.shutdown(); container = null; } }
SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.NAME); CoreDescriptor dcore = new CoreDescriptor(coreContainer, name, params.get(CoreAdminParams.INSTANCE_DIR)); String opts = params.get(CoreAdminParams.CONFIG); if (opts != null) dcore.setConfigName(opts); opts = params.get(CoreAdminParams.SCHEMA); if (opts != null) dcore.setSchemaName(opts); opts = params.get(CoreAdminParams.DATA_DIR); dcore.setCoreProperties(null); SolrCore core = coreContainer.create(dcore); coreContainer.register(name, core, false); rsp.add("core", core.getName()); return coreContainer.isPersistent(); } catch (Exception ex) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error executing default implementation of CREATE", ex);
String alternate = cores.getManagementPath(); if (alternate != null && path.startsWith(alternate)) { path = path.substring(0, alternate.length()); if( path.equals( cores.getAdminPath() ) ) { handler = cores.getMultiCoreHandler(); solrReq = adminRequestParser.parse(null,path, req); handleAdminRequest(req, response, handler, solrReq); core = cores.getCore(corename); if (core != null) { path = path.substring( idx ); core = cores.getCore(""); final SolrConfig config = core.getSolrConfig(); handler = core.getRequestHandler( path ); String qt = solrReq.getParams().get( CommonParams.QT ); handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); solrReq.close();
SolrCore core = coreContainer.getCore( coreName ); if( core == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "No such core: " + coreName ); SolrRequestHandler handler = core.getRequestHandler( path ); if( handler == null ) { if( "/select".equals( path ) || "/select/".equalsIgnoreCase( path) ) { String qt = params.get( CommonParams.QT ); handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); path.equals( coreContainer.getAdminPath() ) ) { handler = coreContainer.getMultiCoreHandler(); core.close(); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+path ); req.getContext().put( "path", path ); SolrQueryResponse rsp = new SolrQueryResponse(); core.execute( handler, req, rsp ); req.close(); return normalized;
protected boolean handleMergeAction(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { boolean doPersist = false; SolrParams params = req.getParams(); SolrParams required = params.required(); String cname = required.get(CoreAdminParams.CORE); SolrCore core = coreContainer.getCore(cname); if (core != null) { try { doPersist = coreContainer.isPersistent(); String[] dirNames = required.getParams(CoreAdminParams.INDEX_DIR); DirectoryFactory dirFactory = core.getDirectoryFactory(); Directory[] dirs = new Directory[dirNames.length]; for (int i = 0; i < dirNames.length; i++) { dirs[i] = dirFactory.open(dirNames[i]); } UpdateRequestProcessorChain processorChain = core.getUpdateProcessingChain(params.get(UpdateParams.UPDATE_PROCESSOR)); SolrQueryRequest wrappedReq = new LocalSolrQueryRequest(core, req.getParams()); UpdateRequestProcessor processor = processorChain.createProcessor(wrappedReq, rsp); processor.processMergeIndexes(new MergeIndexesCommand(dirs)); } finally { core.close(); } } return doPersist; }
@Override public CoreContainer initialize() { CoreContainer container = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())); CoreDescriptor dcore = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstanceDir()); dcore.setConfigName(solrConfig.getResourceName()); dcore.setSchemaName(indexSchema.getResourceName()); SolrCore core = new SolrCore( null, dataDirectory, solrConfig, indexSchema, dcore); container.register(coreName, core, false); return container; } }
/** * Get a reference to the searcher for the required collection. If the collection is * not the same as the search collection, we assume it is under the same Solr instance. * @param rb the response builder holding the facets. * @return a counted reference to the searcher. * @throws SolrException if the collection cannot be found. */ private RefCounted<SolrIndexSearcher> getSearcherReference(ResponseBuilder rb) throws SolrException { RefCounted<SolrIndexSearcher> searcherRef; SolrCore currentCore = rb.req.getCore(); if (StringUtils.isBlank(collection)) { searcherRef = currentCore.getSearcher(); } else { // Using an alternative core - find it SolrCore reqCore = currentCore.getCoreDescriptor().getCoreContainer().getCore(collection); if (reqCore == null) { throw new SolrException(ErrorCode.BAD_REQUEST, "Collection \"" + collection + "\" cannot be found"); } searcherRef = reqCore.getSearcher(); } return searcherRef; }
SolrParams params = req.getParams(); String cname = params.get(CoreAdminParams.CORE); boolean doPersist = false; NamedList<Object> status = new SimpleOrderedMap<Object>(); try { if (cname == null) { for (String name : coreContainer.getCoreNames()) { status.add(name, getCoreStatus(coreContainer, name)); return doPersist; } catch (Exception ex) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error handling 'status' action ", ex);
/** * Handle "ALIAS" action * * @param req * @param rsp * * @return true if a modification has resulted that requires persistance * of the CoreContainer configuration. */ protected boolean handleAliasAction(SolrQueryRequest req, SolrQueryResponse rsp) { SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.OTHER); String cname = params.get(CoreAdminParams.CORE); boolean doPersist = false; if (cname.equals(name)) return doPersist; SolrCore core = coreContainer.getCore(cname); if (core != null) { doPersist = coreContainer.isPersistent(); coreContainer.register(name, core, false); // no core.close() since each entry in the cores map should increase the ref } return doPersist; }
/** * Recreates a SolrCore. * While the new core is loading, requests will continue to be dispatched to * and processed by the old core * * @param name the name of the SolrCore to reload * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public void reload(String name) throws ParserConfigurationException, IOException, SAXException { SolrCore core; synchronized(cores) { core = cores.get(name); } if (core == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name ); SolrCore newCore = create(core.getCoreDescriptor()); // point all aliases to the reloaded core for (String alias : getCoreNames(core)) { if (!name.equals(alias)) { newCore.open(); register(alias, newCore, false); } } register(name, newCore, false); }
cores = new CoreContainer(); cores.load(solrHome, fconf); abortOnConfigurationError = false; for (SolrCore c : cores.getCores()) { if (c.getSolrConfig().getBool("abortOnConfigurationError", false)) { abortOnConfigurationError = true; break; solrConfigFilename = cores.getConfigFile().getName(); } else { cores = new CoreContainer(solrHome); CoreDescriptor dcore = new CoreDescriptor(cores, "", "."); dcore.setCoreProperties(null); SolrResourceLoader resourceLoader = new SolrResourceLoader(solrHome, null, getCoreProps(solrHome, null,dcore.getCoreProperties())); cores.loader = resourceLoader; SolrConfig cfg = solrConfigFilename == null ? new SolrConfig(resourceLoader, solrConfigFilename,null); IndexSchema schema = indexSchemaFilename != null ? new IndexSchema(cfg, indexSchemaFilename, null) : null; SolrCore singlecore = new SolrCore(null, null, cfg, schema, dcore); abortOnConfigurationError = cfg.getBool( "abortOnConfigurationError", abortOnConfigurationError); cores.register("", singlecore, false); cores.setPersistent(false); solrConfigFilename = cfg.getName();
CoreContainer coreContainer = new CoreContainer(loader); coreContainer.load(); CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreId, solrCoreFolder.getAbsolutePath()); SolrCore core = coreContainer.create(coreDescriptor); coreContainer.register(coreId, core, true); return new EmbeddedSolrServer(coreContainer, coreId);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "can not find logging file: "+loggingConfig ); CoreContainer cores = new CoreContainer(new SolrResourceLoader(instanceDir)); SolrConfig solrConfig = new SolrConfig(instanceDir, SolrConfig.DEFAULT_CONF_FILE, null); CoreDescriptor dcore = new CoreDescriptor(cores, "", solrConfig.getResourceLoader().getInstanceDir()); IndexSchema indexSchema = new IndexSchema(solrConfig, instanceDir+"/conf/schema.xml", null); core = new SolrCore( null, dataDir, solrConfig, indexSchema, dcore); cores.register("", core, false); parser = new SolrRequestParsers( solrConfig );
System.setProperty("solr.autoSoftCommit.maxTime", "-1"); CoreContainer container = new CoreContainer(loader); container.load(); CoreDescriptor descr = new CoreDescriptor(container, "core1", solrHomeDir.toString()); descr.setDataDir(dataDirStr); descr.setCoreProperties(props); SolrCore core = container.create(descr); if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) { throw new UnsupportedOperationException( "Invalid configuration. Currently, the only DirectoryFactory supported is " container.register(core, false);
System.setProperty("solr.autoSoftCommit.maxTime", "-1"); CoreContainer container = new CoreContainer(loader); container.load(); SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()), ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false); if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) { throw new UnsupportedOperationException( "Invalid configuration. Currently, the only DirectoryFactory supported is "
System.setProperty("enable.cache-warming", "false"); // We certainly don't need to warm the cache CoreContainer coreContainer = new CoreContainer(tmpSolrHome.getAbsolutePath()); coreContainer.load(); Collection<SolrCore> cores = coreContainer.getCores(); SolrCore core = null; IndexSchema schema = core.getLatestSchema(); Map<String, SchemaField> solrFields = schema.getFields(); Set<String> schemeFieldnames = new HashSet<String>(); coreContainer.shutdown();