public SnapShooter(SolrCore core, String location) throws IOException { solrCore = core; if (location == null) snapDir = core.getDataDir(); else { File base = new File(core.getCoreDescriptor().getInstanceDir()); snapDir = org.apache.solr.common.util.FileUtils.resolvePath(base, location).getAbsolutePath(); File dir = new File(snapDir); if (!dir.exists()) dir.mkdirs(); } lockFactory = new SimpleFSLockFactory(snapDir); }
@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 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; } }
public void run() { try { solrCore.getCoreDescriptor().getCoreContainer().reload(solrCore.getName()); } catch (Exception e) { LOG.error("Could not restart core ", e); } } }.start();
/** * Use the other constructor using a CoreContainer and a name. * @param core * @deprecated */ @Deprecated public EmbeddedSolrServer( SolrCore core ) { if ( core == null ) { throw new NullPointerException("SolrCore instance required"); } CoreDescriptor dcore = core.getCoreDescriptor(); if (dcore == null) throw new NullPointerException("CoreDescriptor required"); CoreContainer cores = dcore.getCoreContainer(); if (cores == null) throw new NullPointerException("CoreContainer required"); coreName = dcore.getName(); coreContainer = cores; _parser = new SolrRequestParsers( null ); }
public ArrayList<String> getShardURLs (boolean includeSelf) { // String[] urls = new String[shards.length + (includeSelf ? 0 : -1)]; ArrayList<String> urls = new ArrayList<String> (); String shardId = core.getCoreDescriptor().getCloudDescriptor().getShardId(); for (int i = 0; i < shards.length; i++) { if (!includeSelf) { if (shardId.equals(slices[i])) { // exclude this shard continue; } } List<String> replicas = StrUtils.splitSmart(shards[i], "|", true); for (String replica : replicas) { urls .add("http://" + replica); } } return urls; }
public String getCoreForDirectory(String coreNameOrPath) { if(coreNameOrPath.charAt(coreNameOrPath.length()-1) != File.separatorChar){ coreNameOrPath = coreNameOrPath+File.separatorChar; } for(SolrCore core : server.getCores()){ String instanceDir = core.getCoreDescriptor().getInstanceDir(); if(FilenameUtils.equalsNormalizedOnSystem( coreNameOrPath, instanceDir)){ return core.getName(); } } return null; } public CoreContainer getCoreContainer() {
public String getCoreForDirectory(String coreNameOrPath) { if(coreNameOrPath.charAt(coreNameOrPath.length()-1) != File.separatorChar){ coreNameOrPath = coreNameOrPath+File.separatorChar; } for(SolrCore core : server.getCores()){ String instanceDir = core.getCoreDescriptor().getInstanceDir(); if(FilenameUtils.equalsNormalizedOnSystem( coreNameOrPath, instanceDir)){ return core.getName(); } } return null; } public CoreContainer getCoreContainer() {
@Override public void removeIndex(String name, boolean deleteFiles) { if(name == null || name.isEmpty()){ throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!"); } SolrCore core = server.remove(name); core.close(); //decrease reference count if(deleteFiles){ String instanceDir = core.getCoreDescriptor().getInstanceDir(); while(!core.isClosed()){ //ensure the core is closed! core.close(); } try { FileUtils.deleteDirectory(new File(instanceDir)); } catch (IOException e) { log.error("Unable to delete instance directory '"+ instanceDir+"' of SolrCore '"+name+"'! Please delete this" + "directory manually."); } } }
@Override public void removeIndex(String name, boolean deleteFiles) { if(name == null || name.isEmpty()){ throw new IllegalArgumentException("The parsed index name MUST NOT be NULL nor empty!"); } SolrCore core = server.remove(name); core.close(); //decrease reference count if(deleteFiles){ String instanceDir = core.getCoreDescriptor().getInstanceDir(); while(!core.isClosed()){ //ensure the core is closed! core.close(); } try { FileUtils.deleteDirectory(new File(instanceDir)); } catch (IOException e) { log.error("Unable to delete instance directory '"+ instanceDir+"' of SolrCore '"+name+"'! Please delete this" + "directory manually."); } } }
@Override protected void findDirectory(DataImporter dataImporter, Map<String, String> params) { String collection = dataImporter.getCore().getCoreDescriptor().getCloudDescriptor().getCollectionName(); path = "/configs/" + collection + "/" + filename; }
private void checkIfTrusted(String trans) { if (docBuilder != null) { SolrCore core = docBuilder.dataImporter.getCore(); boolean trusted = (core != null)? core.getCoreDescriptor().isConfigSetTrusted(): true; if (!trusted) { Exception ex = new SolrException(ErrorCode.UNAUTHORIZED, "The configset for this collection was uploaded " + "without any authentication in place," + " and this transformer is not available for collections with untrusted configsets. To use this transformer," + " re-upload the configset after enabling authentication and authorization."); String msg = "Transformer: " + trans + ". " + ex.getMessage(); log.error(msg); wrapAndThrow(SEVERE, ex, msg); } } }
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { String collection = null; if (req.getCore() == null) { // if the request doesn't have a core, let's use the core stored on the // request handler collection = core.getCoreDescriptor().getCloudDescriptor().getCollectionName(); } SecureRequestHandlerUtil.checkSentryAdmin(req, SecureRequestHandlerUtil.QUERY_AND_UPDATE, getClass().getName(), true, collection); super.handleRequestBody(req, rsp); } }
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; }
/** * 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); }
/** * Updates the parsed {@link IndexMetadata} instance based on the * properties of the parsed {@link SolrCore}.<p> * This sets the state, index name and the directory. * @param metadata the {@link IndexMetadata} to update * @param core the core */ public static void updateMetadata(IndexMetadata metadata, SolrCore core){ if(metadata == null || core == null){ return; } metadata.setState(ManagedIndexState.ACTIVE); metadata.setIndexName(core.getName()); metadata.setDirectory(core.getCoreDescriptor().getInstanceDir()); } /**
public NamedList getStatistics() { NamedList lst = new SimpleOrderedMap(); lst.add("coreName", name==null ? "(null)" : name); lst.add("startTime", new Date(startTime)); lst.add("refCount", getOpenCount()); lst.add("aliases", getCoreDescriptor().getCoreContainer().getCoreNames(this)); return lst; }
/** * Updates the parsed {@link IndexMetadata} instance based on the * properties of the parsed {@link SolrCore}.<p> * This sets the state, index name and the directory. * @param metadata the {@link IndexMetadata} to update * @param core the core */ public static void updateMetadata(IndexMetadata metadata, SolrCore core){ if(metadata == null || core == null){ return; } metadata.setState(ManagedIndexState.ACTIVE); metadata.setIndexName(core.getName()); metadata.setDirectory(core.getCoreDescriptor().getInstanceDir()); } /**
/** * Creates an appropriate {@link DatasetGraph} for this SolRDF instance. * * @param request the current Solr request * @param response the current Solr response. * @param parser the Query parser associated with the current request. * @param consumer a {@link GraphEventConsumer} for this query cycle. * @return an appropriate {@link DatasetGraph} for this SolRDF instance. */ DatasetGraph datasetGraph(final SolrQueryRequest request, final SolrQueryResponse response, final QParser parser, final GraphEventConsumer consumer) { return request.getCore().getCoreDescriptor().getCoreContainer().isZooKeeperAware() ? new CloudDatasetGraph(request, response, server) : new LocalDatasetGraph(request, response, parser, consumer); } }
/** * 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; }