/** Gets the core with its reference count incremented. * You must call core.close() when done! */ public SolrCore getCoreInc() { return container.getCore(coreName); }
/** Gets a core that does not have its refcount incremented (i.e. there is no need to * close when done). This is not MT safe in conjunction with reloads! */ public SolrCore getCore() { // get the core & decrease its refcount: // the container holds the core for the harness lifetime SolrCore core = container.getCore(coreName); if (core != null) core.close(); return core; }
@Override public File getSolrIndexDirectory(String name) { if(name == null || name.isEmpty()){ throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!"); } SolrCore core = server.getCore(name); if(core != null){ File instanceDir = new File(core.getCoreDescriptor().getInstanceDir()); core.close(); return instanceDir; } else { return null; } }
@Override public IndexMetadata getIndexMetadata(String indexName) { IndexMetadata metadata; SolrCore core = server.getCore(indexName); if(core != null){ metadata = getMetadata(core,serverName); core.close(); } else { metadata = null; } return metadata; } @Override
@Override public File getSolrIndexDirectory(String name) { if(name == null || name.isEmpty()){ throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!"); } SolrCore core = server.getCore(name); if(core != null){ File instanceDir = new File(core.getCoreDescriptor().getInstanceDir()); core.close(); return instanceDir; } else { return null; } }
@Override public IndexMetadata getIndexMetadata(String indexName) { IndexMetadata metadata; SolrCore core = server.getCore(indexName); if(core != null){ metadata = getMetadata(core,serverName); core.close(); } else { metadata = null; } return metadata; } @Override
@Override public void activateSolr() throws Exception { ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader( getClass().getClassLoader() ); try { File directory = new File( fileConfig.dataDirectory(), descriptor.identity().toString() ); directory.mkdirs(); System.setProperty( "solr.solr.home", directory.getAbsolutePath() ); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); coreContainer = initializer.initialize(); server = new EmbeddedSolrServer( coreContainer, "" ); core = coreContainer.getCore( "" ); } finally { Thread.currentThread().setContextClassLoader( oldCl ); } }
@Override public void discardReplacementCore(Vocabulary vocabulary) { final String replacementCoreId = vocabulary.getIdentifier() + TEMP; if (this.cores.containsKey(replacementCoreId)) { CoreContainer container = this.coreContainer.getContainer(); SolrCore solrCore = container.getCore(replacementCoreId); if (solrCore != null) { solrCore.close(); } container.unload(replacementCoreId, true, true, true); this.cores.remove(replacementCoreId); this.caches.remove(replacementCoreId); } } }
public TestHarness(String coreName, CoreContainer.Initializer init) { try { container = init.initialize(); if (coreName == null) coreName = ""; // get the core & decrease its refcount: // the container holds the core for the harness lifetime core = container.getCore(coreName); if (core != null) core.close(); builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); updater = new XmlUpdateRequestHandler(); updater.init( null ); } catch (Exception e) { throw new RuntimeException(e); } }
protected SolrCore getCore() { return coreContainer.getCore(coreContainer.getDefaultCoreName()); }
/** * @return the last core initialized. If you are using multiple cores, * this is not a function to use. * * @deprecated Use {@link CoreContainer#getCore(String)} instead. */ @Deprecated public static SolrCore getSolrCore() { synchronized( SolrCore.class ) { if( instance == null ) { try { // sets 'instance' to the latest solr core CoreContainer.Initializer init = new CoreContainer.Initializer(); instance = init.initialize().getCore(""); } catch(Exception xany) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "error creating core", xany ); } } } return instance; }
protected SolrCore getCore() { return coreContainer.getCore(coreContainer.getDefaultCoreName()); }
private String getCollectionFromCoreName(String coreName) { SolrCore solrCore = null; try { if (coreName != null && !coreName.equals("")) { solrCore = coreContainer.getCore(coreName); if (solrCore != null) { return solrCore.getCoreDescriptor().getCloudDescriptor().getCollectionName(); } } } finally { if (solrCore != null) { solrCore.close(); } } return null; }
@Override public void replaceCore(Vocabulary vocabulary) throws InitializationException { final String absPath = this.environment.getPermanentDirectory().getAbsolutePath(); final File indexOrigin = new File(absPath, SOLR + vocabulary.getIdentifier() + "/data"); final File indexTemp = new File(absPath, SOLR + vocabulary.getIdentifier() + TEMP + "/data"); try { CoreContainer container = this.coreContainer.getContainer(); SolrCore solrCore = container.getCore(vocabulary.getIdentifier()); if (solrCore != null) { solrCore.close(); } container.unload(vocabulary.getIdentifier(), true, false, false); FileUtils.copyDirectory(indexTemp, indexOrigin); initialize(vocabulary); } catch (IOException ex) { ex.printStackTrace(); } }
/** * 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; }
/** * Return singleton instance of the OpenCms spellchecker.<p> * * @param cms the cms object. * * @return instance of CmsSolrSpellchecker. */ public CmsSolrSpellchecker getSolrDictionary(CmsObject cms) { // get the core container that contains one core for each configured index if (m_coreContainer == null) { m_coreContainer = createCoreContainer(); } SolrCore spellcheckCore = m_coreContainer.getCore(CmsSolrSpellchecker.SPELLCHECKER_INDEX_CORE); if (spellcheckCore == null) { LOG.error( Messages.get().getBundle().key( Messages.ERR_SPELLCHECK_CORE_NOT_AVAILABLE_1, CmsSolrSpellchecker.SPELLCHECKER_INDEX_CORE)); return null; } else { return CmsSolrSpellchecker.getInstance(m_coreContainer, spellcheckCore); } }
/** * 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; }
/** * 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; }
/** * @see org.opencms.search.CmsSearchIndex#createIndexBackup() */ @Override protected String createIndexBackup() { if (!isBackupReindexing()) { // if no backup is generated we don't need to do anything return null; } if (m_solr instanceof EmbeddedSolrServer) { EmbeddedSolrServer ser = (EmbeddedSolrServer)m_solr; CoreContainer con = ser.getCoreContainer(); SolrCore core = con.getCore(getCoreName()); if (core != null) { try { SolrRequestHandler h = core.getRequestHandler("/replication"); if (h instanceof ReplicationHandler) { h.handleRequest( new LocalSolrQueryRequest(core, CmsRequestUtil.createParameterMap("?command=backup")), new SolrQueryResponse()); } } finally { core.close(); } } } return null; }
protected NamedList<Object> getCoreStatus(CoreContainer cores, String cname) throws IOException { NamedList<Object> info = new SimpleOrderedMap<Object>(); SolrCore core = cores.getCore(cname); if (core != null) { try { info.add("name", core.getName()); info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir())); info.add("dataDir", normalizePath(core.getDataDir())); info.add("startTime", new Date(core.getStartTime())); info.add("uptime", System.currentTimeMillis() - core.getStartTime()); RefCounted<SolrIndexSearcher> searcher = core.getSearcher(); try { info.add("index", LukeRequestHandler.getIndexInfo(searcher.get().getReader(), false)); } finally { searcher.decref(); } } finally { core.close(); } } return info; }