List of usage examples for org.apache.solr.client.solrj.response CoreAdminResponse getCoreStatus
public NamedList<Object> getCoreStatus(String core)
From source file:com.hurence.logisland.service.solr.api.SolrClientService.java
License:Apache License
protected boolean existsCore(String name) throws IOException, SolrServerException { CoreAdminResponse response = CoreAdminRequest.getStatus(name, getClient()); return response.getCoreStatus(name).size() > 1; }
From source file:com.mmj.app.lucene.solr.client.SolrClient.java
License:Open Source License
private boolean isDataDirExsited(String namespace) { CoreAdminResponse status; try {//from w ww .ja va 2s.co m status = CoreAdminRequest.getStatus(namespace, solrServer); } catch (SolrServerException e) { logger.error("isSolrCoreExist", e); throw new SolrServerUnAvailableException("isSolrCoreExist", e); } catch (IOException e) { logger.error("isSolrCoreExist", e); throw new SolrServerUnAvailableException("isSolrCoreExist", e); } return status != null && status.getCoreStatus(namespace).get("instanceDir") != null; }
From source file:com.ms.scombiz.solr.solr.SolrClient.java
License:Open Source License
private boolean isDataDirExsited(String namespace) { CoreAdminResponse status; try {//from ww w . j a va 2 s . c o m status = CoreAdminRequest.getStatus(namespace, rootSolrServer); } catch (SolrServerException e) { logger.error("isSolrCoreExist", e); throw new SolrServerUnAvailableException("isSolrCoreExist", e); } catch (IOException e) { logger.error("isSolrCoreExist", e); throw new SolrServerUnAvailableException("isSolrCoreExist", e); } return status != null && status.getCoreStatus(namespace).get("instanceDir") != null; }
From source file:org.codice.solr.factory.impl.HttpSolrClientFactory.java
License:Open Source License
private static boolean solrCoreExists(SolrClient client, String coreName) throws IOException, SolrServerException { CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, client); return response.getCoreStatus(coreName).get("instanceDir") != null; }
From source file:org.codice.solr.factory.SolrServerFactory.java
License:Open Source License
private static boolean solrCoreExists(SolrServer solrServer, String coreName) { try {/* w ww. ja v a 2 s. c o m*/ CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, solrServer); return response.getCoreStatus(coreName).get("instanceDir") != null; } catch (SolrServerException e) { LOGGER.info("SolrServerException getting " + coreName + " core status", e); return false; } catch (IOException e) { LOGGER.info("IOException getting " + coreName + " core status", e); return false; } }
From source file:org.craftercms.search.service.impl.SolrAdminService.java
License:Open Source License
@Override public Map<String, Object> getIndexInfo(String id) throws SearchException { CoreAdminRequest request = new CoreAdminRequest(); request.setCoreName(id);/*from w ww .j ava 2s .c om*/ request.setIndexInfoNeeded(true); request.setAction(CoreAdminParams.CoreAdminAction.STATUS); try { CoreAdminResponse response = request.process(solrClient); Map<String, Object> info = null; if (response != null) { NamedList<Object> status = response.getCoreStatus(id); if (status != null) { info = status.asShallowMap(); } } if (MapUtils.isNotEmpty(info)) { return info; } else { throw new IndexNotFoundException("Index '" + id + "' not "); } } catch (SolrServerException | IOException e) { throw new SearchException(id, "Failed to get core info", e); } }
From source file:org.dspace.util.SolrImportExport.java
License:BSD License
/** * Reindexes the specified core/*from w w w .ja v a 2 s .co m*/ * * @param indexName the name of the core to reindex * @param exportDirName the name of the directory to use for export. If this directory doesn't exist, it will be created. * @param keepExport whether to keep the contents of the exportDir after the reindex. If keepExport is false and the * export directory was created by this method, the export directory will be deleted at the end of the reimport. */ private static void reindex(String indexName, String exportDirName, boolean keepExport) throws IOException, SolrServerException, SolrImportExportException { String tempIndexName = indexName + "-temp"; String origSolrUrl = makeSolrUrl(indexName); String baseSolrUrl = StringUtils.substringBeforeLast(origSolrUrl, "/"); // need to get non-core solr URL String tempSolrUrl = baseSolrUrl + "/" + tempIndexName; String solrInstanceDir = ConfigurationManager.getProperty("dspace.dir") + File.separator + "solr" + File.separator + indexName; // the [dspace]/solr/[indexName]/conf directory needs to be available on the local machine for this to work // -- we need access to the schema.xml and solrconfig.xml file, plus files referenced from there // if this directory can't be found, output an error message and skip this index File solrInstance = new File(solrInstanceDir); if (!solrInstance.exists() || !solrInstance.canRead() || !solrInstance.isDirectory()) { throw new SolrImportExportException("Directory " + solrInstanceDir + "/conf/ doesn't exist or isn't readable." + " The reindexing process requires the Solr configuration directory for this index to be present on the local machine" + " even if Solr is running on a different host. Not reindexing index " + indexName); } String timeField = makeTimeField(indexName); // Ensure the export directory exists and is writable File exportDir = new File(exportDirName); boolean createdExportDir = exportDir.mkdirs(); if (!createdExportDir && !exportDir.exists()) { throw new SolrImportExportException("Could not create export directory " + exportDirName); } if (!exportDir.canWrite()) { throw new SolrImportExportException("Can't write to export directory " + exportDirName); } try { HttpSolrServer adminSolr = new HttpSolrServer(baseSolrUrl); // try to find out size of core and compare with free space in export directory CoreAdminResponse status = CoreAdminRequest.getStatus(indexName, adminSolr); Object coreSizeObj = status.getCoreStatus(indexName).get("sizeInBytes"); long coreSize = coreSizeObj != null ? Long.valueOf(coreSizeObj.toString()) : -1; long usableExportSpace = exportDir.getUsableSpace(); if (coreSize >= 0 && usableExportSpace < coreSize) { System.err.println("Not enough space in export directory " + exportDirName + "; need at least as much space as the index (" + FileUtils.byteCountToDisplaySize(coreSize) + ") but usable space in export directory is only " + FileUtils.byteCountToDisplaySize(usableExportSpace) + ". Not continuing with reindex, please use the " + DIRECTORY_OPTION + " option to specify an alternative export directy with sufficient space."); return; } // Create a temp directory to store temporary core data File tempDataDir = new File(ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator + "solr-data"); boolean createdTempDataDir = tempDataDir.mkdirs(); if (!createdTempDataDir && !tempDataDir.exists()) { throw new SolrImportExportException( "Could not create temporary data directory " + tempDataDir.getCanonicalPath()); } if (!tempDataDir.canWrite()) { throw new SolrImportExportException( "Can't write to temporary data directory " + tempDataDir.getCanonicalPath()); } try { // create a temporary core to hold documents coming in during the reindex CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); createRequest.setInstanceDir(solrInstanceDir); createRequest.setDataDir(tempDataDir.getCanonicalPath()); createRequest.setCoreName(tempIndexName); createRequest.process(adminSolr).getStatus(); } catch (SolrServerException e) { // try to continue -- it may just be that the core already existed from a previous, failed attempt System.err.println("Caught exception when trying to create temporary core: " + e.getMessage() + "; trying to recover."); e.printStackTrace(System.err); } // swap actual core with temporary one CoreAdminRequest swapRequest = new CoreAdminRequest(); swapRequest.setCoreName(indexName); swapRequest.setOtherCoreName(tempIndexName); swapRequest.setAction(CoreAdminParams.CoreAdminAction.SWAP); swapRequest.process(adminSolr); try { // export from the actual core (from temp core name, actual data dir) exportIndex(indexName, exportDir, tempSolrUrl, timeField); // clear actual core (temp core name, clearing actual data dir) & import importIndex(indexName, exportDir, tempSolrUrl, true, true); } catch (Exception e) { // we ran into some problems with the export/import -- keep going to try and restore the solr cores System.err.println("Encountered problem during reindex: " + e.getMessage() + ", will attempt to restore Solr cores"); e.printStackTrace(System.err); } // commit changes HttpSolrServer origSolr = new HttpSolrServer(origSolrUrl); origSolr.commit(); // swap back (statistics now going to actual core name in actual data dir) swapRequest = new CoreAdminRequest(); swapRequest.setCoreName(tempIndexName); swapRequest.setOtherCoreName(indexName); swapRequest.setAction(CoreAdminParams.CoreAdminAction.SWAP); swapRequest.process(adminSolr); // export all docs from now-temp core into export directory -- this won't cause name collisions with the actual export // because the core name for the temporary export has -temp in it while the actual core doesn't exportIndex(tempIndexName, exportDir, tempSolrUrl, timeField); // ...and import them into the now-again-actual core *without* clearing importIndex(tempIndexName, exportDir, origSolrUrl, false, true); // commit changes origSolr.commit(); // unload now-temp core (temp core name) CoreAdminRequest.unloadCore(tempIndexName, false, false, adminSolr); // clean up temporary data dir if this method created it if (createdTempDataDir && tempDataDir.exists()) { FileUtils.deleteDirectory(tempDataDir); } } finally { // clean up export dir if appropriate if (!keepExport && createdExportDir && exportDir.exists()) { FileUtils.deleteDirectory(exportDir); } } }
From source file:org.emonocot.harvest.common.SolrOptimizingTasklet.java
License:Open Source License
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { CoreAdminResponse coreAdminResponse = CoreAdminRequest.getStatus(core, solrServer); NamedList<Object> index = (NamedList<Object>) coreAdminResponse.getCoreStatus(core).get("index"); Integer segmentCount = (Integer) index.get("segmentCount"); if (segmentCount < maxSegments) { logger.debug("Core " + core + " only has " + segmentCount + " segments, skipping optimization"); } else {//from ww w. j a v a 2s .c o m logger.debug("Core " + core + " has " + segmentCount + " segments, starting optimization"); solrServer.optimize(true, true); logger.debug("Core " + core + " optimized"); } return RepeatStatus.FINISHED; }