public void inform(SolrCore core) { loader = core.getResourceLoader(); //solrHome = new File(loader.getInstanceDir()); }
public void inform(SolrCore core) { loader = core.getResourceLoader(); //solrHome = new File(loader.getInstanceDir()); }
@Override public void inform(SolrCore core) { // need to leverage SolrResourceLoader, so load init.properties.file here instead of init() if (initPropertiesFileName != null) { InputStream is = null; try { velocityInitProps.load(new InputStreamReader(core.getResourceLoader().openResource(initPropertiesFileName), StandardCharsets.UTF_8)); } catch (IOException e) { log.warn("Error loading " + PROPERTIES_FILE + " specified property file: " + initPropertiesFileName, e); } } }
private List<String> readLines(SolrCore core, String fileName) throws IOException { return core.getResourceLoader().getLines(fileName, characterEncoding); }
@SuppressWarnings("unchecked") static Class loadClass(String name, SolrCore core) throws ClassNotFoundException { try { return core != null ? core.getResourceLoader().findClass(name, Object.class) : Class.forName(name); } catch (Exception e) { try { String n = DocBuilder.class.getPackage().getName() + "." + name; return core != null ? core.getResourceLoader().findClass(n, Object.class) : Class.forName(n); } catch (Exception e1) { throw new ClassNotFoundException("Unable to load " + name + " or " + DocBuilder.class.getPackage().getName() + "." + name, e); } } }
protected void findDirectory(DataImporter dataImporter, Map<String, String> params) { if(params.get(DIRECTORY) != null) { configDir = params.get(DIRECTORY); } else { SolrCore core = dataImporter.getCore(); if (core == null) { configDir = SolrResourceLoader.locateSolrHome().toString(); } else { configDir = core.getResourceLoader().getConfigDir(); } } }
public SolrResourceLocator(SolrCore core, SolrParams initParams) { resourceLoader = core.getResourceLoader(); String resourcesDir = initParams.get(CarrotParams.RESOURCES_DIR); carrot2ResourcesDir = firstNonNull(resourcesDir, CarrotClusteringEngine.CARROT_RESOURCES_PREFIX); }
/** * The conf files are copied to the tmp dir to the conf dir. A backup of the old file is maintained */ private void copyTmpConfFiles2Conf(File tmpconfDir) throws IOException { File confDir = new File(solrCore.getResourceLoader().getConfigDir()); for (File file : tmpconfDir.listFiles()) { File oldFile = new File(confDir, file.getName()); if (oldFile.exists()) { File backupFile = new File(confDir, oldFile.getName() + "." + getDateAsStr(new Date(oldFile.lastModified()))); boolean status = oldFile.renameTo(backupFile); if (!status) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to rename: " + oldFile + " to: " + backupFile); } } boolean status = file.renameTo(oldFile); if (status) { } else { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to rename: " + file + " to: " + oldFile); } } }
/** * This is a utility function that lets you get the contents of an admin file * * It is only used so that we can get rid of "/admin/get-file.jsp" and include * "admin-extra.html" in "/admin/index.html" using jsp scriptlets * * @deprecated This functionality is implemented in * {@link #handleRequestBody(SolrQueryRequest, SolrQueryResponse)}. */ @Deprecated public static String getFileContents( String path ) { if( instance != null && instance.hiddenFiles != null ) { if( instance.hiddenFiles.contains( path ) ) { return ""; // ignore it... } } try { SolrCore core = SolrCore.getSolrCore(); InputStream input = core.getResourceLoader().openResource(path); return IOUtils.toString( input ); } catch( Exception ex ) {} // ignore it return ""; }
public void build(SolrCore core, SolrIndexSearcher searcher) { try { loadExternalFileDictionary(core.getSchema(), core.getResourceLoader()); spellChecker.clearIndex(); spellChecker.indexDictionary(dictionary); } catch (IOException e) { throw new RuntimeException(e); } }
private void downloadConfFiles(List<Map<String, Object>> confFilesToDownload, long latestVersion) throws Exception { LOG.info("Starting download of configuration files from master: " + confFilesToDownload); confFilesDownloaded = Collections.synchronizedList(new ArrayList<Map<String, Object>>()); File tmpconfDir = new File(solrCore.getResourceLoader().getConfigDir(), "conf." + getDateAsStr(new Date())); try { boolean status = tmpconfDir.mkdirs(); if (!status) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed to create temporary config folder: " + tmpconfDir.getName()); } for (Map<String, Object> file : confFilesToDownload) { String saveAs = (String) (file.get(ALIAS) == null ? file.get(NAME) : file.get(ALIAS)); fileFetcher = new FileFetcher(tmpconfDir, file, saveAs, true, latestVersion); currentFile = file; fileFetcher.fetchFile(); confFilesDownloaded.add(new HashMap<String, Object>(file)); } // this is called before copying the files to the original conf dir // so that if there is an exception avoid corrupting the original files. terminateAndWaitFsyncService(); copyTmpConfFiles2Conf(tmpconfDir); } finally { delTree(tmpconfDir); } }
private void initDirectoryFactory() { DirectoryFactory dirFactory; PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName()); if (info != null) { dirFactory = (DirectoryFactory) getResourceLoader().newInstance(info.className); dirFactory.init(info.initArgs); } else { dirFactory = new StandardDirectoryFactory(); } // And set it directoryFactory = dirFactory; }
/** * For configuration files, checksum of the file is included because, unlike index files, they may have same content * but different timestamps. * <p/> * The local conf files information is cached so that everytime it does not have to compute the checksum. The cache is * refreshed only if the lastModified of the file changes */ List<Map<String, Object>> getConfFileInfoFromCache(NamedList<String> nameAndAlias, final Map<String, FileInfo> confFileInfoCache) { List<Map<String, Object>> confFiles = new ArrayList<Map<String, Object>>(); synchronized (confFileInfoCache) { File confDir = new File(core.getResourceLoader().getConfigDir()); Checksum checksum = null; for (int i = 0; i < nameAndAlias.size(); i++) { String cf = nameAndAlias.getName(i); File f = new File(confDir, cf); if (!f.exists() || f.isDirectory()) continue; //must not happen FileInfo info = confFileInfoCache.get(cf); if (info == null || info.lastmodified != f.lastModified() || info.size != f.length()) { if (checksum == null) checksum = new Adler32(); info = new FileInfo(f.lastModified(), cf, f.length(), getCheckSum(checksum, f)); confFileInfoCache.put(cf, info); } Map<String, Object> m = info.getAsMap(); if (nameAndAlias.getVal(i) != null) m.put(ALIAS, nameAndAlias.getVal(i)); confFiles.add(m); } } return confFiles; }
Map<String, ElevationObj> getElevationMap( IndexReader reader, SolrCore core ) throws Exception { synchronized( elevationCache ) { Map<String, ElevationObj> map = elevationCache.get( null ); if (map != null) return map; map = elevationCache.get( reader ); if( map == null ) { String f = initArgs.get( CONFIG_FILE ); if( f == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "QueryElevationComponent must specify argument: "+CONFIG_FILE ); } log.info( "Loading QueryElevation from data dir: "+f ); InputStream is = VersionedFile.getLatestFile( core.getDataDir(), f ); Config cfg = new Config( core.getResourceLoader(), f, is, null ); map = loadElevationMap( cfg ); elevationCache.put( reader, map ); } return map; } }
/** * Gets the checksum of a file */ private void getFileChecksum(SolrParams solrParams, SolrQueryResponse rsp) { Checksum checksum = new Adler32(); File dir = new File(core.getIndexDir()); rsp.add(CHECKSUM, getCheckSums(solrParams.getParams(FILE), dir, checksum)); dir = new File(core.getResourceLoader().getConfigDir()); rsp.add(CONF_CHECKSUM, getCheckSums(solrParams.getParams(CONF_FILE_SHORT), dir, checksum)); }
@Override public String init(NamedList config, final SolrCore core) { String result = super.init(config, core); SolrParams initParams = SolrParams.toSolrParams(config); // Initialize Carrot2 controller. Pass initialization attributes, if any. HashMap<String, Object> initAttributes = new HashMap<String, Object>(); extractCarrotAttributes(initParams, initAttributes); this.controller.init(initAttributes); this.idFieldName = core.getSchema().getUniqueKeyField().getName(); // Make sure the requested Carrot2 clustering algorithm class is available String carrotAlgorithmClassName = initParams.get(CarrotParams.ALGORITHM); Class<?> algorithmClass = core.getResourceLoader().findClass(carrotAlgorithmClassName); if (!IClusteringAlgorithm.class.isAssignableFrom(algorithmClass)) { throw new IllegalArgumentException("Class provided as " + CarrotParams.ALGORITHM + " must implement " + IClusteringAlgorithm.class.getName()); } this.clusteringAlgorithmClass = (Class<? extends IClusteringAlgorithm>) algorithmClass; return result; }
/** * Get system info */ private static SimpleOrderedMap<Object> getCoreInfo( SolrCore core ) throws Exception { SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>(); IndexSchema schema = core.getSchema(); info.add( "schema", schema != null ? schema.getSchemaName():"no schema!" ); // Host InetAddress addr = InetAddress.getLocalHost(); info.add( "host", addr.getCanonicalHostName() ); // Now info.add( "now", new Date() ); // Start Time info.add( "start", new Date(core.getStartTime()) ); // Solr Home SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<Object>(); dirs.add( "instance", new File( core.getResourceLoader().getInstanceDir() ).getAbsolutePath() ); dirs.add( "data", new File( core.getDataDir() ).getAbsolutePath() ); dirs.add( "index", new File( core.getIndexDir() ).getAbsolutePath() ); info.add( "directory", dirs ); return info; }
private VelocityEngine getEngine(SolrQueryRequest request) { VelocityEngine engine = new VelocityEngine(); String template_root = request.getParams().get("v.base_dir"); File baseDir = new File(request.getCore().getResourceLoader().getConfigDir(), "velocity"); if (template_root != null) { baseDir = new File(template_root);
@Override public Object cluster(Query query, SolrDocumentList solrDocList, Map<SolrDocument, Integer> docIds, SolrQueryRequest sreq) { try { // Prepare attributes for Carrot2 clustering call Map<String, Object> attributes = new HashMap<>(); List<Document> documents = getDocuments(solrDocList, docIds, query, sreq); attributes.put(AttributeNames.DOCUMENTS, documents); attributes.put(AttributeNames.QUERY, query.toString()); // Pass the fields on which clustering runs. attributes.put("solrFieldNames", getFieldsForClustering(sreq)); // Pass extra overriding attributes from the request, if any extractCarrotAttributes(sreq.getParams(), attributes); // Perform clustering and convert to an output structure of clusters. // // Carrot2 uses current thread's context class loader to get // certain classes (e.g. custom tokenizer/stemmer) at runtime. // To make sure classes from contrib JARs are available, // we swap the context class loader for the time of clustering. return withContextClassLoader(core.getResourceLoader().getClassLoader(), () -> clustersToNamedList(controller.process(attributes, clusteringAlgorithmClass).getClusters(), sreq.getParams())); } catch (Exception e) { log.error("Carrot2 clustering failed", e); throw new SolrException(ErrorCode.SERVER_ERROR, "Carrot2 clustering failed", e); } }
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; }