@Override public void close() { ofNullable(proxy).ifPresent(solr -> { try { solr.close(); } catch (final Exception exception) { exception.printStackTrace(); } }); if (defaultSolrHome) { // If using the default Solr home (eg. /tmp), unload and set // directory for deletion. ofNullable(proxy) .map(EmbeddedSolrServer::getCoreContainer) .map(CoreContainer::getAllCoreNames) .orElse(Collections.emptyList()) .forEach(coreName -> proxy.getCoreContainer().unload(coreName, true, true, false)); solrHome.deleteOnExit(); } ofNullable(renamedCoreProperties).ifPresent(file -> file.renameTo(coreProperties)); }
@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); } } }
/** * Shuts down the Solr core container.<p> */ private void shutDownSolrContainer() { if (m_coreContainer != null) { for (SolrCore core : m_coreContainer.getCores()) { // do not unload spellcheck core because otherwise the core.properties file is removed // even when calling m_coreContainer.unload(core.getName(), false, false, false); if (!core.getName().equals(CmsSolrSpellchecker.SPELLCHECKER_INDEX_CORE)) { m_coreContainer.unload(core.getName(), false, false, true); } } m_coreContainer.shutdown(); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SOLR_SHUTDOWN_SUCCESS_0)); } m_coreContainer = 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(); } }
/** * Removes a search index from the configuration.<p> * * @param searchIndex the search index to remove */ public void removeSearchIndex(CmsSearchIndex searchIndex) { // shut down index to remove potential config files of Solr indexes searchIndex.shutDown(); if (searchIndex instanceof CmsSolrIndex) { CmsSolrIndex solrIndex = (CmsSolrIndex)searchIndex; m_coreContainer.unload(solrIndex.getCoreName(), true, true, true); } m_indexes.remove(searchIndex); initOfflineIndexes(); if (LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_REMOVE_SEARCH_INDEX_2, searchIndex.getName(), searchIndex.getProject())); } }