SOLR-14197: SolrResourceLoader refactorings to reduce API

* Remove SRL.listConfigDir (unused)
* Remove SRL.getDataDir
* Remove SRL.getCoreName
* Remove SRL.getCoreProperties
 XmlConfigFile needs to be passed in the substitutableProperties
 IndexSchema needs to be passed in the substitutableProperties
 Remove redundant Properties from CoreContainer constructors
* Remove SRL.newAdminHandlerInstance (unused)
* Remove SRL.openSchema and openConfig
* Avoid SRL.getConfigDir
 Also harmonized similar initialization logic between DIH Tika processor & ExtractingRequestHandler.
* Ensure SRL.addToClassLoader and reloadLuceneSPI are called at most once
 Don't auto-load "lib" in constructor; wrong place for this logic.
* Avoid SRL.getInstancePath
 Added SolrCore.getInstancePath instead
 Use CoreContainer.getSolrHome instead
 NodeConfig should track solrHome separate from SolrResourceLoader
* Simplify some SolrCore constructors
* Move locateSolrHome to new SolrPaths
* Move "User Files" stuff to SolrPaths
This commit is contained in:
David Smiley 2020-01-06 00:32:31 -05:00 committed by David Smiley
parent 9842744956
commit 732348ec7f
60 changed files with 585 additions and 768 deletions

View File

@ -40,6 +40,8 @@ Other Changes
* SOLR-14256: Remove HashDocSet; add DocSet.getBits() instead. DocSet is now strictly immutable and ascending order. * SOLR-14256: Remove HashDocSet; add DocSet.getBits() instead. DocSet is now strictly immutable and ascending order.
It's now locked-down to external extension; only 2 impls exist. (David Smiley) It's now locked-down to external extension; only 2 impls exist. (David Smiley)
* SOLR-14197: SolrResourceLoader: remove deprecated methods and do other improvements. (David Smiley)
================== 8.6.0 ================== ================== 8.6.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
@ -62,7 +64,8 @@ Bug Fixes
Other Changes Other Changes
--------------------- ---------------------
(No changes) * SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid
them. (David Smiley)
================== 8.5.0 ================== ================== 8.5.0 ==================

View File

@ -82,22 +82,26 @@ public class TikaEntityProcessor extends EntityProcessorBase {
@Override @Override
protected void firstInit(Context context) { protected void firstInit(Context context) {
super.firstInit(context); super.firstInit(context);
// See similar code in ExtractingRequestHandler.inform
try { try {
String tikaConfigFile = context.getResolvedEntityAttribute("tikaConfig"); String tikaConfigLoc = context.getResolvedEntityAttribute("tikaConfig");
if (tikaConfigFile == null) { if (tikaConfigLoc == null) {
ClassLoader classLoader = context.getSolrCore().getResourceLoader().getClassLoader(); ClassLoader classLoader = context.getSolrCore().getResourceLoader().getClassLoader();
try (InputStream is = classLoader.getResourceAsStream("solr-default-tika-config.xml")) { try (InputStream is = classLoader.getResourceAsStream("solr-default-tika-config.xml")) {
tikaConfig = new TikaConfig(is); tikaConfig = new TikaConfig(is);
} }
} else { } else {
File configFile = new File(tikaConfigFile); File configFile = new File(tikaConfigLoc);
if (!configFile.isAbsolute()) { if (configFile.isAbsolute()) {
configFile = new File(context.getSolrCore().getResourceLoader().getConfigDir(), tikaConfigFile); tikaConfig = new TikaConfig(configFile);
} else { // in conf/
try (InputStream is = context.getSolrCore().getResourceLoader().openResource(tikaConfigLoc)) {
tikaConfig = new TikaConfig(is);
}
} }
tikaConfig = new TikaConfig(configFile);
} }
} catch (Exception e) { } catch (Exception e) {
wrapAndThrow (SEVERE, e,"Unable to load Tika Config"); wrapAndThrow(SEVERE, e,"Unable to load Tika Config");
} }
String extractEmbeddedString = context.getResolvedEntityAttribute("extractEmbedded"); String extractEmbeddedString = context.getResolvedEntityAttribute("extractEmbedded");

View File

@ -113,8 +113,8 @@ public class DocBuilder {
VariableResolver resolver = null; VariableResolver resolver = null;
String epoch = propWriter.convertDateToString(EPOCH); String epoch = propWriter.convertDateToString(EPOCH);
if(dataImporter != null && dataImporter.getCore() != null if(dataImporter != null && dataImporter.getCore() != null
&& dataImporter.getCore().getResourceLoader().getCoreProperties() != null){ && dataImporter.getCore().getCoreDescriptor().getSubstitutableProperties() != null){
resolver = new VariableResolver(dataImporter.getCore().getResourceLoader().getCoreProperties()); resolver = new VariableResolver(dataImporter.getCore().getCoreDescriptor().getSubstitutableProperties());
} else { } else {
resolver = new VariableResolver(); resolver = new VariableResolver();
} }

View File

@ -38,7 +38,7 @@ import java.util.Properties;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.util.SuppressForbidden; import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrPaths;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -126,7 +126,7 @@ public class SimplePropertiesWriter extends DIHProperties {
} else { } else {
SolrCore core = dataImporter.getCore(); SolrCore core = dataImporter.getCore();
if (core == null) { if (core == null) {
configDir = SolrResourceLoader.locateSolrHome().toString(); configDir = SolrPaths.locateSolrHome().toString();
} else { } else {
configDir = core.getResourceLoader().getConfigDir(); configDir = core.getResourceLoader().getConfigDir();
} }

View File

@ -17,7 +17,6 @@
package org.apache.solr.handler.extraction; package org.apache.solr.handler.extraction;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
@ -32,8 +31,6 @@ import org.apache.solr.security.PermissionNameProvider;
import org.apache.solr.update.processor.UpdateRequestProcessor; import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.util.plugin.SolrCoreAware; import org.apache.solr.util.plugin.SolrCoreAware;
import org.apache.tika.config.TikaConfig; import org.apache.tika.config.TikaConfig;
import org.apache.tika.exception.TikaException;
import org.xml.sax.SAXException;
/** /**
* Handler for rich documents like PDF or Word or any other file format that Tika handles that need the text to be extracted * Handler for rich documents like PDF or Word or any other file format that Tika handles that need the text to be extracted
@ -61,40 +58,34 @@ public class ExtractingRequestHandler extends ContentStreamHandlerBase implement
@Override @Override
public void inform(SolrCore core) { public void inform(SolrCore core) {
if (initArgs != null) { try {
//if relative,then relative to config dir, otherwise, absolute path
String tikaConfigLoc = (String) initArgs.get(CONFIG_LOCATION); String tikaConfigLoc = (String) initArgs.get(CONFIG_LOCATION);
if (tikaConfigLoc != null) { if (tikaConfigLoc == null) { // default
File configFile = new File(tikaConfigLoc); ClassLoader classLoader = core.getResourceLoader().getClassLoader();
if (configFile.isAbsolute() == false) { try (InputStream is = classLoader.getResourceAsStream("solr-default-tika-config.xml")) {
configFile = new File(core.getResourceLoader().getConfigDir(), configFile.getPath()); config = new TikaConfig(is);
} }
try { } else {
File configFile = new File(tikaConfigLoc);
if (configFile.isAbsolute()) {
config = new TikaConfig(configFile); config = new TikaConfig(configFile);
} catch (Exception e) { } else { // in conf/
throw new SolrException(ErrorCode.SERVER_ERROR, e); try (InputStream is = core.getResourceLoader().openResource(tikaConfigLoc)) {
config = new TikaConfig(is);
}
} }
} }
String parseContextConfigLoc = (String) initArgs.get(PARSE_CONTEXT_CONFIG); String parseContextConfigLoc = (String) initArgs.get(PARSE_CONTEXT_CONFIG);
if (parseContextConfigLoc != null) { if (parseContextConfigLoc == null) { // default:
try { parseContextConfig = new ParseContextConfig();
parseContextConfig = new ParseContextConfig(core.getResourceLoader(), parseContextConfigLoc); } else {
} catch (Exception e) { parseContextConfig = new ParseContextConfig(core.getResourceLoader(), parseContextConfigLoc);
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
} }
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to load Tika Config", e);
} }
if (config == null) {
try (InputStream is = core.getResourceLoader().getClassLoader().getResourceAsStream("solr-default-tika-config.xml")){
config = new TikaConfig(is);
} catch (IOException | SAXException | TikaException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}
if (parseContextConfig == null) {
parseContextConfig = new ParseContextConfig();
}
factory = createFactory(); factory = createFactory();
} }

View File

@ -216,7 +216,7 @@ public class SolrExporter {
private static MetricsConfiguration loadMetricsConfiguration(Path configPath) { private static MetricsConfiguration loadMetricsConfiguration(Path configPath) {
try (SolrResourceLoader loader = new SolrResourceLoader(configPath.getParent())) { try (SolrResourceLoader loader = new SolrResourceLoader(configPath.getParent())) {
XmlConfigFile config = new XmlConfigFile(loader, configPath.getFileName().toString()); XmlConfigFile config = new XmlConfigFile(loader, configPath.getFileName().toString(), null, null);
return MetricsConfiguration.from(config); return MetricsConfiguration.from(config);
} catch (Exception e) { } catch (Exception e) {
log.error("Could not load scrape configuration from {}", configPath.toAbsolutePath()); log.error("Could not load scrape configuration from {}", configPath.toAbsolutePath());

View File

@ -25,6 +25,7 @@ import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -50,7 +51,6 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.request.SolrRequestInfo; import org.apache.solr.request.SolrRequestInfo;
@ -92,7 +92,7 @@ public class EmbeddedSolrServer extends SolrClient {
* @param defaultCoreName the core to route requests to by default (optional) * @param defaultCoreName the core to route requests to by default (optional)
*/ */
public EmbeddedSolrServer(Path solrHome, String defaultCoreName) { public EmbeddedSolrServer(Path solrHome, String defaultCoreName) {
this(load(new CoreContainer(SolrXmlConfig.fromSolrHome(solrHome))), defaultCoreName); this(load(new CoreContainer(solrHome, new Properties())), defaultCoreName);
} }
/** /**

View File

@ -75,8 +75,7 @@ public class CloudConfigSetService extends ConfigSetService {
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Trouble resolving configSet for collection " + colName + ": " + ex.getMessage()); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Trouble resolving configSet for collection " + colName + ": " + ex.getMessage());
} }
return new ZkSolrResourceLoader(cd.getInstanceDir(), configSetName, parentLoader.getClassLoader(), return new ZkSolrResourceLoader(cd.getInstanceDir(), configSetName, parentLoader.getClassLoader(), zkController);
cd.getSubstitutableProperties(), zkController);
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import java.io.PrintStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -206,14 +207,14 @@ public class ZkCLI implements CLIO {
System.exit(1); System.exit(1);
} }
CoreContainer cc = new CoreContainer(solrHome); CoreContainer cc = new CoreContainer(Paths.get(solrHome), new Properties());
if(!ZkController.checkChrootPath(zkServerAddress, true)) { if(!ZkController.checkChrootPath(zkServerAddress, true)) {
stdout.println("A chroot was specified in zkHost but the znode doesn't exist. "); stdout.println("A chroot was specified in zkHost but the znode doesn't exist. ");
System.exit(1); System.exit(1);
} }
ZkController.bootstrapConf(zkClient, cc, solrHome); ZkController.bootstrapConf(zkClient, cc);
// No need to close the CoreContainer, as it wasn't started // No need to close the CoreContainer, as it wasn't started
// up in the first place... // up in the first place...

View File

@ -2017,14 +2017,14 @@ public class ZkController implements Closeable {
/** /**
* If in SolrCloud mode, upload config sets for each SolrCore in solr.xml. * If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
*/ */
public static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc, String solrHome) throws IOException { public static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc) throws IOException {
ZkConfigManager configManager = new ZkConfigManager(zkClient); ZkConfigManager configManager = new ZkConfigManager(zkClient);
//List<String> allCoreNames = cfg.getAllCoreNames(); //List<String> allCoreNames = cfg.getAllCoreNames();
List<CoreDescriptor> cds = cc.getCoresLocator().discover(cc); List<CoreDescriptor> cds = cc.getCoresLocator().discover(cc);
log.info("bootstrapping config for " + cds.size() + " cores into ZooKeeper using solr.xml from " + solrHome); log.info("bootstrapping config for " + cds.size() + " cores into ZooKeeper using solr.xml from " + cc.getSolrHome());
for (CoreDescriptor cd : cds) { for (CoreDescriptor cd : cds) {
String coreName = cd.getName(); String coreName = cd.getName();

View File

@ -22,10 +22,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
import java.util.Properties;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.ZkConfigManager; import org.apache.solr.common.cloud.ZkConfigManager;
import org.apache.solr.common.cloud.ZooKeeperException; import org.apache.solr.common.cloud.ZooKeeperException;
@ -49,12 +46,6 @@ public class ZkSolrResourceLoader extends SolrResourceLoader {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public ZkSolrResourceLoader(Path instanceDir, String configSet, ZkController zooKeeperController) {
super(instanceDir);
this.zkController = zooKeeperController;
configSetZkPath = ZkConfigManager.CONFIGS_ZKNODE + "/" + configSet;
}
/** /**
* <p> * <p>
* This loader will first attempt to load resources from ZooKeeper, but if not found * This loader will first attempt to load resources from ZooKeeper, but if not found
@ -63,8 +54,8 @@ public class ZkSolrResourceLoader extends SolrResourceLoader {
* the "lib/" directory in the specified instance directory. * the "lib/" directory in the specified instance directory.
*/ */
public ZkSolrResourceLoader(Path instanceDir, String configSet, ClassLoader parent, public ZkSolrResourceLoader(Path instanceDir, String configSet, ClassLoader parent,
Properties coreProperties, ZkController zooKeeperController) { ZkController zooKeeperController) {
super(instanceDir, parent, coreProperties); super(instanceDir, parent);
this.zkController = zooKeeperController; this.zkController = zooKeeperController;
configSetZkPath = ZkConfigManager.CONFIGS_ZKNODE + "/" + configSet; configSetZkPath = ZkConfigManager.CONFIGS_ZKNODE + "/" + configSet;
} }
@ -152,25 +143,6 @@ public class ZkSolrResourceLoader extends SolrResourceLoader {
ErrorCode.SERVER_ERROR, ErrorCode.SERVER_ERROR,
"ZkSolrResourceLoader does not support getConfigDir() - likely, what you are trying to do is not supported in ZooKeeper mode"); "ZkSolrResourceLoader does not support getConfigDir() - likely, what you are trying to do is not supported in ZooKeeper mode");
} }
@Override
public String[] listConfigDir() {
List<String> list;
try {
list = zkController.getZkClient().getChildren(configSetZkPath, null, true);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (KeeperException e) {
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
}
return list.toArray(new String[0]);
}
public String getConfigSetZkPath() { public String getConfigSetZkPath() {
return configSetZkPath; return configSetZkPath;

View File

@ -108,7 +108,7 @@ public abstract class ConfigSetService {
* @return a SolrConfig object * @return a SolrConfig object
*/ */
protected SolrConfig createSolrConfig(CoreDescriptor cd, SolrResourceLoader loader, boolean isTrusted) { protected SolrConfig createSolrConfig(CoreDescriptor cd, SolrResourceLoader loader, boolean isTrusted) {
return SolrConfig.readFromResourceLoader(loader, cd.getConfigName(), isTrusted); return SolrConfig.readFromResourceLoader(loader, cd.getConfigName(), isTrusted, cd.getSubstitutableProperties());
} }
/** /**
@ -126,10 +126,10 @@ public abstract class ConfigSetService {
// want to pay the overhead of that at this juncture. If we guess wrong, no schema sharing. // want to pay the overhead of that at this juncture. If we guess wrong, no schema sharing.
// The fix is usually to name your schema managed-schema instead of schema.xml. // The fix is usually to name your schema managed-schema instead of schema.xml.
IndexSchemaFactory indexSchemaFactory = IndexSchemaFactory.newIndexSchemaFactory(solrConfig); IndexSchemaFactory indexSchemaFactory = IndexSchemaFactory.newIndexSchemaFactory(solrConfig);
String guessSchemaName = indexSchemaFactory.getSchemaResourceName(cdSchemaName);
String configSet = cd.getConfigSet(); String configSet = cd.getConfigSet();
if (configSet != null && schemaCache != null) { if (configSet != null && schemaCache != null) {
String guessSchemaName = indexSchemaFactory.getSchemaResourceName(cdSchemaName);
Long modVersion = getCurrentSchemaModificationVersion(configSet, solrConfig, guessSchemaName); Long modVersion = getCurrentSchemaModificationVersion(configSet, solrConfig, guessSchemaName);
if (modVersion != null) { if (modVersion != null) {
// note: luceneMatchVersion influences the schema // note: luceneMatchVersion influences the schema
@ -204,7 +204,7 @@ public abstract class ConfigSetService {
@Override @Override
public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) { public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) {
Path instanceDir = locateInstanceDir(cd); Path instanceDir = locateInstanceDir(cd);
return new SolrResourceLoader(instanceDir, parentLoader.getClassLoader(), cd.getSubstitutableProperties()); return new SolrResourceLoader(instanceDir, parentLoader.getClassLoader());
} }
@Override @Override

View File

@ -19,6 +19,7 @@ package org.apache.solr.core;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
@ -192,7 +193,7 @@ public class CoreContainer {
protected final NodeConfig cfg; protected final NodeConfig cfg;
protected final SolrResourceLoader loader; protected final SolrResourceLoader loader;
protected final String solrHome; protected final Path solrHome;
protected final CoresLocator coresLocator; protected final CoresLocator coresLocator;
@ -277,36 +278,16 @@ public class CoreContainer {
log.debug("New CoreContainer " + System.identityHashCode(this)); log.debug("New CoreContainer " + System.identityHashCode(this));
} }
/**
* Create a new CoreContainer using system properties to detect the solr home
* directory. The container's cores are not loaded.
*
* @see #load()
*/
public CoreContainer() {
this(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
}
/**
* Create a new CoreContainer using the given SolrResourceLoader. The container's
* cores are not loaded.
*
* @param loader the SolrResourceLoader
* @see #load()
*/
public CoreContainer(SolrResourceLoader loader) {
this(SolrXmlConfig.fromSolrHome(loader, loader.getInstancePath()));
}
/** /**
* Create a new CoreContainer using the given solr home directory. The container's * Create a new CoreContainer using the given solr home directory. The container's
* cores are not loaded. * cores are not loaded.
* *
* @param solrHome a String containing the path to the solr home directory * @param solrHome a String containing the path to the solr home directory
* @param properties substitutable properties (alternative to Sys props)
* @see #load() * @see #load()
*/ */
public CoreContainer(String solrHome) { public CoreContainer(Path solrHome, Properties properties) {
this(new SolrResourceLoader(Paths.get(solrHome))); this(SolrXmlConfig.fromSolrHome(solrHome, properties));
} }
/** /**
@ -318,25 +299,21 @@ public class CoreContainer {
* @see #load() * @see #load()
*/ */
public CoreContainer(NodeConfig config) { public CoreContainer(NodeConfig config) {
this(config, new Properties()); this(config, new CorePropertiesLocator(config.getCoreRootDirectory()));
} }
public CoreContainer(NodeConfig config, Properties properties) { public CoreContainer(NodeConfig config, boolean asyncSolrCoreLoad) {
this(config, properties, new CorePropertiesLocator(config.getCoreRootDirectory())); this(config, new CorePropertiesLocator(config.getCoreRootDirectory()), asyncSolrCoreLoad);
} }
public CoreContainer(NodeConfig config, Properties properties, boolean asyncSolrCoreLoad) { public CoreContainer(NodeConfig config, CoresLocator locator) {
this(config, properties, new CorePropertiesLocator(config.getCoreRootDirectory()), asyncSolrCoreLoad); this(config, locator, false);
} }
public CoreContainer(NodeConfig config, Properties properties, CoresLocator locator) { public CoreContainer(NodeConfig config, CoresLocator locator, boolean asyncSolrCoreLoad) {
this(config, properties, locator, false);
}
public CoreContainer(NodeConfig config, Properties properties, CoresLocator locator, boolean asyncSolrCoreLoad) {
this.cfg = requireNonNull(config);
this.loader = config.getSolrResourceLoader(); this.loader = config.getSolrResourceLoader();
this.solrHome = loader.getInstancePath().toString(); this.solrHome = config.getSolrHome();
this.cfg = requireNonNull(config);
try { try {
containerHandlers.put(PublicKeyHandler.PATH, new PublicKeyHandler(cfg.getCloudConfig())); containerHandlers.put(PublicKeyHandler.PATH, new PublicKeyHandler(cfg.getCloudConfig()));
} catch (IOException | InvalidKeySpecException e) { } catch (IOException | InvalidKeySpecException e) {
@ -346,7 +323,7 @@ public class CoreContainer {
IndexSearcher.setMaxClauseCount(this.cfg.getBooleanQueryMaxClauseCount()); IndexSearcher.setMaxClauseCount(this.cfg.getBooleanQueryMaxClauseCount());
} }
this.coresLocator = locator; this.coresLocator = locator;
this.containerProperties = new Properties(properties); this.containerProperties = new Properties(config.getSolrProperties());
this.asyncSolrCoreLoad = asyncSolrCoreLoad; this.asyncSolrCoreLoad = asyncSolrCoreLoad;
this.replayUpdatesExecutor = new OrderedExecutor( this.replayUpdatesExecutor = new OrderedExecutor(
cfg.getReplayUpdatesThreads(), cfg.getReplayUpdatesThreads(),
@ -557,8 +534,7 @@ public class CoreContainer {
* @return a loaded CoreContainer * @return a loaded CoreContainer
*/ */
public static CoreContainer createAndLoad(Path solrHome, Path configFile) { public static CoreContainer createAndLoad(Path solrHome, Path configFile) {
SolrResourceLoader loader = new SolrResourceLoader(solrHome); CoreContainer cc = new CoreContainer(SolrXmlConfig.fromFile(solrHome, configFile, new Properties()));
CoreContainer cc = new CoreContainer(SolrXmlConfig.fromFile(loader, configFile));
try { try {
cc.load(); cc.load();
} catch (Exception e) { } catch (Exception e) {
@ -607,7 +583,7 @@ public class CoreContainer {
* Load the cores defined for this CoreContainer * Load the cores defined for this CoreContainer
*/ */
public void load() { public void load() {
log.debug("Loading cores into CoreContainer [instanceDir={}]", loader.getInstancePath()); log.debug("Loading cores into CoreContainer [instanceDir={}]", getSolrHome());
// Always add $SOLR_HOME/lib to the shared resource loader // Always add $SOLR_HOME/lib to the shared resource loader
Set<String> libDirs = new LinkedHashSet<>(); Set<String> libDirs = new LinkedHashSet<>();
@ -621,13 +597,13 @@ public class CoreContainer {
boolean modified = false; boolean modified = false;
// add the sharedLib to the shared resource loader before initializing cfg based plugins // add the sharedLib to the shared resource loader before initializing cfg based plugins
for (String libDir : libDirs) { for (String libDir : libDirs) {
Path libPath = loader.getInstancePath().resolve(libDir); Path libPath = Paths.get(getSolrHome()).resolve(libDir);
try { if (Files.exists(libPath)) {
loader.addToClassLoader(SolrResourceLoader.getURLs(libPath)); try {
modified = true; loader.addToClassLoader(SolrResourceLoader.getURLs(libPath));
} catch (IOException e) { modified = true;
if (!libDir.equals("lib")) { // Don't complain if default "lib" dir does not exist } catch (IOException e) {
log.warn("Couldn't add files from {} to classpath: {}", libPath, e.getMessage()); throw new SolrException(ErrorCode.SERVER_ERROR, "Couldn't load libs: " + e, e);
} }
} }
} }
@ -664,7 +640,7 @@ public class CoreContainer {
hostName = cfg.getNodeName(); hostName = cfg.getNodeName();
zkSys.initZooKeeper(this, solrHome, cfg.getCloudConfig()); zkSys.initZooKeeper(this, cfg.getCloudConfig());
if (isZooKeeperAware()) { if (isZooKeeperAware()) {
pkiAuthenticationPlugin = new PKIAuthenticationPlugin(this, zkSys.getZkController().getNodeName(), pkiAuthenticationPlugin = new PKIAuthenticationPlugin(this, zkSys.getZkController().getNodeName(),
(PublicKeyHandler) containerHandlers.get(PublicKeyHandler.PATH)); (PublicKeyHandler) containerHandlers.get(PublicKeyHandler.PATH));
@ -1907,8 +1883,9 @@ public class CoreContainer {
return solrCores.getUnloadedCoreDescriptor(cname); return solrCores.getUnloadedCoreDescriptor(cname);
} }
//TODO return Path
public String getSolrHome() { public String getSolrHome() {
return solrHome; return solrHome.toString();
} }
public boolean isZooKeeperAware() { public boolean isZooKeeperAware() {

View File

@ -412,7 +412,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
path = cd.getName(); path = cd.getName();
} }
return normalize(SolrResourceLoader.normalizeDir(ZkController return normalize(SolrPaths.normalizeDir(ZkController
.trimLeadingAndTrailingSlashes(hdfsDataDir) .trimLeadingAndTrailingSlashes(hdfsDataDir)
+ "/" + "/"
+ path + path

View File

@ -86,7 +86,8 @@ public class NodeConfig {
String coreAdminHandlerClass, String collectionsAdminHandlerClass, String coreAdminHandlerClass, String collectionsAdminHandlerClass,
String healthCheckHandlerClass, String infoHandlerClass, String configSetsHandlerClass, String healthCheckHandlerClass, String infoHandlerClass, String configSetsHandlerClass,
LogWatcherConfig logWatcherConfig, CloudConfig cloudConfig, Integer coreLoadThreads, int replayUpdatesThreads, LogWatcherConfig logWatcherConfig, CloudConfig cloudConfig, Integer coreLoadThreads, int replayUpdatesThreads,
int transientCacheSize, boolean useSchemaCache, String managementPath, SolrResourceLoader loader, int transientCacheSize, boolean useSchemaCache, String managementPath,
Path solrHome, SolrResourceLoader loader,
Properties solrProperties, PluginInfo[] backupRepositoryPlugins, Properties solrProperties, PluginInfo[] backupRepositoryPlugins,
MetricsConfig metricsConfig, PluginInfo transientCacheConfig, PluginInfo tracerConfig) { MetricsConfig metricsConfig, PluginInfo transientCacheConfig, PluginInfo tracerConfig) {
this.nodeName = nodeName; this.nodeName = nodeName;
@ -109,6 +110,7 @@ public class NodeConfig {
this.transientCacheSize = transientCacheSize; this.transientCacheSize = transientCacheSize;
this.useSchemaCache = useSchemaCache; this.useSchemaCache = useSchemaCache;
this.managementPath = managementPath; this.managementPath = managementPath;
this.solrHome = solrHome;
this.loader = loader; this.loader = loader;
this.solrProperties = solrProperties; this.solrProperties = solrProperties;
this.backupRepositoryPlugins = backupRepositoryPlugins; this.backupRepositoryPlugins = backupRepositoryPlugins;
@ -216,6 +218,7 @@ public class NodeConfig {
return transientCacheSize; return transientCacheSize;
} }
protected final Path solrHome;
protected final SolrResourceLoader loader; protected final SolrResourceLoader loader;
protected final Properties solrProperties; protected final Properties solrProperties;
@ -223,6 +226,10 @@ public class NodeConfig {
return solrProperties; return solrProperties;
} }
public Path getSolrHome() {
return solrHome;
}
public SolrResourceLoader getSolrResourceLoader() { public SolrResourceLoader getSolrResourceLoader() {
return loader; return loader;
} }
@ -243,6 +250,7 @@ public class NodeConfig {
public static class NodeConfigBuilder { public static class NodeConfigBuilder {
private SolrResourceLoader loader;
private Path coreRootDirectory; private Path coreRootDirectory;
private Path solrDataHome; private Path solrDataHome;
private Integer booleanQueryMaxClauseCount; private Integer booleanQueryMaxClauseCount;
@ -270,7 +278,7 @@ public class NodeConfig {
private PluginInfo transientCacheConfig; private PluginInfo transientCacheConfig;
private PluginInfo tracerConfig; private PluginInfo tracerConfig;
private final SolrResourceLoader loader; private final Path solrHome;
private final String nodeName; private final String nodeName;
public static final int DEFAULT_CORE_LOAD_THREADS = 3; public static final int DEFAULT_CORE_LOAD_THREADS = 3;
@ -293,28 +301,28 @@ public class NodeConfig {
"zkDigestReadonlyPassword" "zkDigestReadonlyPassword"
)); ));
public NodeConfigBuilder(String nodeName, SolrResourceLoader loader) { public NodeConfigBuilder(String nodeName, Path solrHome) {
this.nodeName = nodeName; this.nodeName = nodeName;
this.loader = loader; this.solrHome = solrHome;
this.coreRootDirectory = loader.getInstancePath(); this.coreRootDirectory = solrHome;
// always init from sysprop because <solrDataHome> config element may be missing // always init from sysprop because <solrDataHome> config element may be missing
String dataHomeProperty = System.getProperty(SolrXmlConfig.SOLR_DATA_HOME); String dataHomeProperty = System.getProperty(SolrXmlConfig.SOLR_DATA_HOME);
if (dataHomeProperty != null && !dataHomeProperty.isEmpty()) { if (dataHomeProperty != null && !dataHomeProperty.isEmpty()) {
solrDataHome = loader.getInstancePath().resolve(dataHomeProperty); solrDataHome = solrHome.resolve(dataHomeProperty);
} }
this.configSetBaseDirectory = loader.getInstancePath().resolve("configsets"); this.configSetBaseDirectory = solrHome.resolve("configsets");
this.metricsConfig = new MetricsConfig.MetricsConfigBuilder().build(); this.metricsConfig = new MetricsConfig.MetricsConfigBuilder().build();
} }
public NodeConfigBuilder setCoreRootDirectory(String coreRootDirectory) { public NodeConfigBuilder setCoreRootDirectory(String coreRootDirectory) {
this.coreRootDirectory = loader.getInstancePath().resolve(coreRootDirectory); this.coreRootDirectory = solrHome.resolve(coreRootDirectory);
return this; return this;
} }
public NodeConfigBuilder setSolrDataHome(String solrDataHomeString) { public NodeConfigBuilder setSolrDataHome(String solrDataHomeString) {
// keep it null unless explicitly set to non-empty value // keep it null unless explicitly set to non-empty value
if (solrDataHomeString != null && !solrDataHomeString.isEmpty()) { if (solrDataHomeString != null && !solrDataHomeString.isEmpty()) {
this.solrDataHome = loader.getInstancePath().resolve(solrDataHomeString); this.solrDataHome = solrHome.resolve(solrDataHomeString);
} }
return this; return this;
} }
@ -325,7 +333,7 @@ public class NodeConfig {
} }
public NodeConfigBuilder setConfigSetBaseDirectory(String configSetBaseDirectory) { public NodeConfigBuilder setConfigSetBaseDirectory(String configSetBaseDirectory) {
this.configSetBaseDirectory = loader.getInstancePath().resolve(configSetBaseDirectory); this.configSetBaseDirectory = solrHome.resolve(configSetBaseDirectory);
return this; return this;
} }
@ -432,12 +440,22 @@ public class NodeConfig {
} }
public NodeConfig build() { public NodeConfig build() {
// if some things weren't set then set them now. Simple primitives are set on the field declaration
if (loader == null) {
loader = new SolrResourceLoader(solrHome);
}
return new NodeConfig(nodeName, coreRootDirectory, solrDataHome, booleanQueryMaxClauseCount, return new NodeConfig(nodeName, coreRootDirectory, solrDataHome, booleanQueryMaxClauseCount,
configSetBaseDirectory, sharedLibDirectory, shardHandlerFactoryConfig, configSetBaseDirectory, sharedLibDirectory, shardHandlerFactoryConfig,
updateShardHandlerConfig, coreAdminHandlerClass, collectionsAdminHandlerClass, healthCheckHandlerClass, infoHandlerClass, configSetsHandlerClass, updateShardHandlerConfig, coreAdminHandlerClass, collectionsAdminHandlerClass, healthCheckHandlerClass, infoHandlerClass, configSetsHandlerClass,
logWatcherConfig, cloudConfig, coreLoadThreads, replayUpdatesThreads, transientCacheSize, useSchemaCache, managementPath, loader, solrProperties, logWatcherConfig, cloudConfig, coreLoadThreads, replayUpdatesThreads, transientCacheSize, useSchemaCache, managementPath,
solrHome, loader, solrProperties,
backupRepositoryPlugins, metricsConfig, transientCacheConfig, tracerConfig); backupRepositoryPlugins, metricsConfig, transientCacheConfig, tracerConfig);
} }
public NodeConfigBuilder setSolrResourceLoader(SolrResourceLoader resourceLoader) {
this.loader = resourceLoader;
return this;
}
} }
} }

View File

@ -25,6 +25,7 @@ import java.io.InputStreamReader;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.ParseException; import java.text.ParseException;
@ -79,7 +80,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import static org.apache.solr.common.params.CommonParams.NAME; import static org.apache.solr.common.params.CommonParams.NAME;
@ -133,20 +133,18 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
private final SolrRequestParsers solrRequestParsers; private final SolrRequestParsers solrRequestParsers;
/** /**
* Creates a configuration instance from an instance directory, configuration name and stream. * TEST-ONLY: Creates a configuration instance from an instance directory and file name
*
* @param instanceDir the directory used to create the resource loader * @param instanceDir the directory used to create the resource loader
* @param name the configuration name used by the loader if the stream is null * @param name the configuration name used by the loader if the stream is null
* @param is the configuration stream
*/ */
public SolrConfig(Path instanceDir, String name, InputSource is, boolean isConfigsetTrusted) public SolrConfig(Path instanceDir, String name)
throws ParserConfigurationException, IOException, SAXException { throws ParserConfigurationException, IOException, SAXException {
this(new SolrResourceLoader(instanceDir), name, is, isConfigsetTrusted); this(new SolrResourceLoader(instanceDir), name, true, null);
} }
public static SolrConfig readFromResourceLoader(SolrResourceLoader loader, String name, boolean isConfigsetTrusted) { public static SolrConfig readFromResourceLoader(SolrResourceLoader loader, String name, boolean isConfigsetTrusted, Properties substitutableProperties) {
try { try {
return new SolrConfig(loader, name, null, isConfigsetTrusted); return new SolrConfig(loader, name, isConfigsetTrusted, substitutableProperties);
} catch (Exception e) { } catch (Exception e) {
String resource; String resource;
if (loader instanceof ZkSolrResourceLoader) { if (loader instanceof ZkSolrResourceLoader) {
@ -162,18 +160,18 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
* Creates a configuration instance from a resource loader, a configuration name and a stream. * Creates a configuration instance from a resource loader, a configuration name and a stream.
* If the stream is null, the resource loader will open the configuration stream. * If the stream is null, the resource loader will open the configuration stream.
* If the stream is not null, no attempt to load the resource will occur (the name is not used). * If the stream is not null, no attempt to load the resource will occur (the name is not used).
* * @param loader the resource loader
* @param loader the resource loader
* @param name the configuration name * @param name the configuration name
* @param is the configuration stream
* @param isConfigsetTrusted false if configset was uploaded using unsecured configset upload API, true otherwise * @param isConfigsetTrusted false if configset was uploaded using unsecured configset upload API, true otherwise
* @param substitutableProperties optional properties to substitute into the XML
*/ */
private SolrConfig(SolrResourceLoader loader, String name, InputSource is, boolean isConfigsetTrusted) private SolrConfig(SolrResourceLoader loader, String name, boolean isConfigsetTrusted, Properties substitutableProperties)
throws ParserConfigurationException, IOException, SAXException { throws ParserConfigurationException, IOException, SAXException {
super(loader, name, is, "/config/"); // insist we have non-null substituteProperties; it might get overlayed
super(loader, name, null, "/config/", substitutableProperties == null ? new Properties() : substitutableProperties);
getOverlay();//just in case it is not initialized getOverlay();//just in case it is not initialized
getRequestParams(); getRequestParams();
initLibs(isConfigsetTrusted); initLibs(loader, isConfigsetTrusted);
luceneMatchVersion = SolrConfig.parseLuceneVersionString(getVal(IndexSchema.LUCENE_MATCH_VERSION_PARAM, true)); luceneMatchVersion = SolrConfig.parseLuceneVersionString(getVal(IndexSchema.LUCENE_MATCH_VERSION_PARAM, true));
log.info("Using Lucene MatchVersion: {}", luceneMatchVersion); log.info("Using Lucene MatchVersion: {}", luceneMatchVersion);
@ -748,7 +746,22 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
"Multiple plugins configured for type: " + type); "Multiple plugins configured for type: " + type);
} }
private void initLibs(boolean isConfigsetTrusted) { private void initLibs(SolrResourceLoader loader, boolean isConfigsetTrusted) {
// TODO Want to remove SolrResourceLoader.getInstancePath; it can be on a Standalone subclass.
// For Zk subclass, it's needed for the time being as well. We could remove that one if we remove two things
// in SolrCloud: (1) instancePath/lib and (2) solrconfig lib directives with relative paths. Can wait till 9.0.
Path instancePath = loader.getInstancePath();
List<URL> urls = new ArrayList<>();
Path libPath = instancePath.resolve("lib");
if (Files.exists(libPath)) {
try {
urls.addAll(SolrResourceLoader.getURLs(libPath));
} catch (IOException e) {
log.warn("Couldn't add files from {} to classpath: {}", libPath, e.getMessage());
}
}
NodeList nodes = (NodeList) evaluate("lib", XPathConstants.NODESET); NodeList nodes = (NodeList) evaluate("lib", XPathConstants.NODESET);
if (nodes == null || nodes.getLength() == 0) return; if (nodes == null || nodes.getLength() == 0) return;
if (!isConfigsetTrusted) { if (!isConfigsetTrusted) {
@ -757,17 +770,13 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
+ " after enabling authentication and authorization."); + " after enabling authentication and authorization.");
} }
log.debug("Adding specified lib dirs to ClassLoader");
SolrResourceLoader loader = getResourceLoader();
List<URL> urls = new ArrayList<>();
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i); Node node = nodes.item(i);
String baseDir = DOMUtil.getAttr(node, "dir"); String baseDir = DOMUtil.getAttr(node, "dir");
String path = DOMUtil.getAttr(node, PATH); String path = DOMUtil.getAttr(node, PATH);
if (null != baseDir) { if (null != baseDir) {
// :TODO: add support for a simpler 'glob' mutually exclusive of regex // :TODO: add support for a simpler 'glob' mutually exclusive of regex
Path dir = loader.getInstancePath().resolve(baseDir); Path dir = instancePath.resolve(baseDir);
String regex = DOMUtil.getAttr(node, "regex"); String regex = DOMUtil.getAttr(node, "regex");
try { try {
if (regex == null) if (regex == null)
@ -778,7 +787,7 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
log.warn("Couldn't add files from {} filtered by {} to classpath: {}", dir, regex, e.getMessage()); log.warn("Couldn't add files from {} filtered by {} to classpath: {}", dir, regex, e.getMessage());
} }
} else if (null != path) { } else if (null != path) {
final Path dir = loader.getInstancePath().resolve(path); final Path dir = instancePath.resolve(path);
try { try {
urls.add(dir.toUri().toURL()); urls.add(dir.toUri().toURL());
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
@ -789,10 +798,8 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
} }
} }
if (urls.size() > 0) { loader.addToClassLoader(urls);
loader.addToClassLoader(urls); loader.reloadLuceneSPI();
loader.reloadLuceneSPI();
}
} }
public int getMultipartUploadLimitKB() { public int getMultipartUploadLimitKB() {
@ -917,7 +924,7 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
} }
@Override @Override
protected Properties getSubstituteProperties() { public Properties getSubstituteProperties() {
Map<String, Object> p = getOverlay().getUserProps(); Map<String, Object> p = getOverlay().getUserProps();
if (p == null || p.isEmpty()) return super.getSubstituteProperties(); if (p == null || p.isEmpty()) return super.getSubstituteProperties();
Properties result = new Properties(super.getSubstituteProperties()); Properties result = new Properties(super.getSubstituteProperties());

View File

@ -134,7 +134,6 @@ import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
import org.apache.solr.rest.RestManager; import org.apache.solr.rest.RestManager;
import org.apache.solr.schema.FieldType; import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.IndexSchemaFactory;
import org.apache.solr.schema.ManagedIndexSchema; import org.apache.solr.schema.ManagedIndexSchema;
import org.apache.solr.schema.SimilarityFactory; import org.apache.solr.schema.SimilarityFactory;
import org.apache.solr.search.QParserPlugin; import org.apache.solr.search.QParserPlugin;
@ -327,6 +326,11 @@ public final class SolrCore implements SolrInfoBean, Closeable {
return schema; return schema;
} }
/** The core's instance directory. */
public Path getInstancePath() {
return getCoreDescriptor().getInstanceDir();
}
/** /**
* Sets the latest schema snapshot to be used by this core instance. * Sets the latest schema snapshot to be used by this core instance.
* If the specified <code>replacementSchema</code> uses a {@link SimilarityFactory} which is * If the specified <code>replacementSchema</code> uses a {@link SimilarityFactory} which is
@ -687,9 +691,8 @@ public final class SolrCore implements SolrInfoBean, Closeable {
try { try {
CoreDescriptor cd = new CoreDescriptor(name, getCoreDescriptor()); CoreDescriptor cd = new CoreDescriptor(name, getCoreDescriptor());
cd.loadExtraProperties(); //Reload the extra properties cd.loadExtraProperties(); //Reload the extra properties
core = new SolrCore(coreContainer, getName(), getDataDir(), coreConfig.getSolrConfig(), core = new SolrCore(coreContainer, getName(), coreConfig, cd, getDataDir(),
coreConfig.getIndexSchema(), coreConfig.getProperties(), updateHandler, solrDelPolicy, currentCore, true);
cd, updateHandler, solrDelPolicy, currentCore, true);
// we open a new IndexWriter to pick up the latest config // we open a new IndexWriter to pick up the latest config
core.getUpdateHandler().getSolrCoreState().newIndexWriter(core, false); core.getUpdateHandler().getSolrCoreState().newIndexWriter(core, false);
@ -897,8 +900,8 @@ public final class SolrCore implements SolrInfoBean, Closeable {
} }
public SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet coreConfig) { public SolrCore(CoreContainer coreContainer, CoreDescriptor cd, ConfigSet coreConfig) {
this(coreContainer, cd.getName(), null, coreConfig.getSolrConfig(), coreConfig.getIndexSchema(), coreConfig.getProperties(), this(coreContainer, cd.getName(), coreConfig, cd, null,
cd, null, null, null, false); null, null, null, false);
} }
public CoreContainer getCoreContainer() { public CoreContainer getCoreContainer() {
@ -909,15 +912,9 @@ public final class SolrCore implements SolrInfoBean, Closeable {
/** /**
* Creates a new core and register it in the list of cores. If a core with the * Creates a new core and register it in the list of cores. If a core with the
* same name already exists, it will be stopped and replaced by this one. * same name already exists, it will be stopped and replaced by this one.
*
* @param dataDir the index directory
* @param config a solr config instance
* @param schema a solr schema instance
* @since solr 1.3
*/ */
public SolrCore(CoreContainer coreContainer, String name, String dataDir, SolrConfig config, private SolrCore(CoreContainer coreContainer, String name, ConfigSet configSet, CoreDescriptor coreDescriptor,
IndexSchema schema, NamedList configSetProperties, String dataDir, UpdateHandler updateHandler,
CoreDescriptor coreDescriptor, UpdateHandler updateHandler,
IndexDeletionPolicyWrapper delPolicy, SolrCore prev, boolean reload) { IndexDeletionPolicyWrapper delPolicy, SolrCore prev, boolean reload) {
assert ObjectReleaseTracker.track(searcherExecutor); // ensure that in unclean shutdown tests we still close this assert ObjectReleaseTracker.track(searcherExecutor); // ensure that in unclean shutdown tests we still close this
@ -927,6 +924,7 @@ public final class SolrCore implements SolrInfoBean, Closeable {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
try { try {
IndexSchema schema = configSet.getIndexSchema();
CoreDescriptor cd = Objects.requireNonNull(coreDescriptor, "coreDescriptor cannot be null"); CoreDescriptor cd = Objects.requireNonNull(coreDescriptor, "coreDescriptor cannot be null");
coreContainer.solrCores.addCoreDescriptor(cd); coreContainer.solrCores.addCoreDescriptor(cd);
@ -934,11 +932,11 @@ public final class SolrCore implements SolrInfoBean, Closeable {
setName(name); setName(name);
MDCLoggingContext.setCore(this); MDCLoggingContext.setCore(this);
resourceLoader = config.getResourceLoader(); this.solrConfig = configSet.getSolrConfig();
this.solrConfig = config; this.resourceLoader = configSet.getSolrConfig().getResourceLoader();
this.configSetProperties = configSetProperties; this.configSetProperties = configSet.getProperties();
// Initialize the metrics manager // Initialize the metrics manager
this.coreMetricManager = initCoreMetricManager(config); this.coreMetricManager = initCoreMetricManager(solrConfig);
solrMetricsContext = coreMetricManager.getSolrMetricsContext(); solrMetricsContext = coreMetricManager.getSolrMetricsContext();
this.coreMetricManager.loadReporters(); this.coreMetricManager.loadReporters();
@ -953,13 +951,13 @@ public final class SolrCore implements SolrInfoBean, Closeable {
isReloaded = true; isReloaded = true;
} }
this.dataDir = initDataDir(dataDir, config, coreDescriptor); this.dataDir = initDataDir(dataDir, solrConfig, coreDescriptor);
this.ulogDir = initUpdateLogDir(coreDescriptor); this.ulogDir = initUpdateLogDir(coreDescriptor);
log.info("[{}] Opening new SolrCore at [{}], dataDir=[{}]", logid, resourceLoader.getInstancePath(), log.info("[{}] Opening new SolrCore at [{}], dataDir=[{}]", logid, getInstancePath(), this.dataDir);
this.dataDir);
checkVersionFieldExistsInSchema(schema, coreDescriptor); checkVersionFieldExistsInSchema(schema, coreDescriptor);
setLatestSchema(schema);
// initialize core metrics // initialize core metrics
initializeMetrics(solrMetricsContext, null); initializeMetrics(solrMetricsContext, null);
@ -970,10 +968,8 @@ public final class SolrCore implements SolrInfoBean, Closeable {
solrFieldCacheBean.initializeMetrics(solrMetricsContext, "core"); solrFieldCacheBean.initializeMetrics(solrMetricsContext, "core");
infoRegistry.put("fieldCache", solrFieldCacheBean); infoRegistry.put("fieldCache", solrFieldCacheBean);
initSchema(config, schema); this.maxWarmingSearchers = solrConfig.maxWarmingSearchers;
this.slowQueryThresholdMillis = solrConfig.slowQueryThresholdMillis;
this.maxWarmingSearchers = config.maxWarmingSearchers;
this.slowQueryThresholdMillis = config.slowQueryThresholdMillis;
initListeners(); initListeners();
@ -1154,20 +1150,6 @@ public final class SolrCore implements SolrInfoBean, Closeable {
return newUpdateHandler; return newUpdateHandler;
} }
/**
* Initializes the "Latest Schema" for this SolrCore using either the provided <code>schema</code>
* if non-null, or a new instance build via the factory identified in the specified <code>config</code>
*
* @see IndexSchemaFactory
* @see #setLatestSchema
*/
private void initSchema(SolrConfig config, IndexSchema schema) {
if (schema == null) {
schema = IndexSchemaFactory.buildIndexSchema(IndexSchema.DEFAULT_SCHEMA_FILE, config);
}
setLatestSchema(schema);
}
/** /**
* Initializes the core's {@link SolrCoreMetricManager} with a given configuration. * Initializes the core's {@link SolrCoreMetricManager} with a given configuration.
* If metric reporters are configured, they are also initialized for this core. * If metric reporters are configured, they are also initialized for this core.
@ -1191,7 +1173,7 @@ public final class SolrCore implements SolrInfoBean, Closeable {
parentContext.gauge(() -> name == null ? "(null)" : name, true, "coreName", Category.CORE.toString()); parentContext.gauge(() -> name == null ? "(null)" : name, true, "coreName", Category.CORE.toString());
parentContext.gauge(() -> startTime, true, "startTime", Category.CORE.toString()); parentContext.gauge(() -> startTime, true, "startTime", Category.CORE.toString());
parentContext.gauge(() -> getOpenCount(), true, "refCount", Category.CORE.toString()); parentContext.gauge(() -> getOpenCount(), true, "refCount", Category.CORE.toString());
parentContext.gauge(() -> resourceLoader.getInstancePath().toString(), true, "instanceDir", Category.CORE.toString()); parentContext.gauge(() -> getInstancePath().toString(), true, "instanceDir", Category.CORE.toString());
parentContext.gauge(() -> isClosed() ? "(closed)" : getIndexDir(), true, "indexDir", Category.CORE.toString()); parentContext.gauge(() -> isClosed() ? "(closed)" : getIndexDir(), true, "indexDir", Category.CORE.toString());
parentContext.gauge(() -> isClosed() ? 0 : getIndexSize(), true, "sizeInBytes", Category.INDEX.toString()); parentContext.gauge(() -> isClosed() ? 0 : getIndexSize(), true, "sizeInBytes", Category.INDEX.toString());
parentContext.gauge(() -> isClosed() ? "(closed)" : NumberUtils.readableSize(getIndexSize()), true, "size", Category.INDEX.toString()); parentContext.gauge(() -> isClosed() ? "(closed)" : NumberUtils.readableSize(getIndexSize()), true, "size", Category.INDEX.toString());
@ -1293,7 +1275,7 @@ public final class SolrCore implements SolrInfoBean, Closeable {
} }
} }
} }
return SolrResourceLoader.normalizeDir(dataDir); return SolrPaths.normalizeDir(dataDir);
} }

View File

@ -0,0 +1,130 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.core;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utility methods about paths in Solr.
*/
public final class SolrPaths {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
/**
* Solr allows users to store arbitrary files in a special directory located directly under SOLR_HOME.
* <p>
* This directory is generally created by each node on startup. Files located in this directory can then be
* manipulated using select Solr features (e.g. streaming expressions).
*/
public static final String USER_FILES_DIRECTORY = "userfiles";
private static final Set<String> loggedOnce = new ConcurrentSkipListSet<>();
private SolrPaths() {} // don't create this
/**
* Finds the solrhome based on looking up the value in one of three places:
* <ol>
* <li>JNDI: via java:comp/env/solr/home</li>
* <li>The system property solr.solr.home</li>
* <li>Look in the current working directory for a solr/ directory</li>
* </ol>
* <p>
* The return value is normalized. Normalization essentially means it ends in a trailing slash.
*
* @return A normalized solrhome
* @see #normalizeDir(String)
*/
public static Path locateSolrHome() {
String home = null;
// Try JNDI
try {
Context c = new InitialContext();
home = (String) c.lookup("java:comp/env/solr/home");
logOnceInfo("home_using_jndi", "Using JNDI solr.home: " + home);
} catch (NoInitialContextException e) {
log.debug("JNDI not configured for solr (NoInitialContextEx)");
} catch (NamingException e) {
log.debug("No /solr/home in JNDI");
} catch (RuntimeException ex) {
log.warn("Odd RuntimeException while testing for JNDI: " + ex.getMessage());
}
// Now try system property
if (home == null) {
String prop = "solr.solr.home";
home = System.getProperty(prop);
if (home != null) {
logOnceInfo("home_using_sysprop", "Using system property " + prop + ": " + home);
}
}
// if all else fails, try
if (home == null) {
home = "solr/";
logOnceInfo("home_default", "solr home defaulted to '" + home + "' (could not find system property or JNDI)");
}
return Paths.get(home);
}
public static void ensureUserFilesDataDir(Path solrHome) {
final Path userFilesPath = getUserFilesPath(solrHome);
final File userFilesDirectory = new File(userFilesPath.toString());
if (!userFilesDirectory.exists()) {
try {
final boolean created = userFilesDirectory.mkdir();
if (!created) {
log.warn("Unable to create [{}] directory in SOLR_HOME [{}]. Features requiring this directory may fail.", USER_FILES_DIRECTORY, solrHome);
}
} catch (Exception e) {
log.warn("Unable to create [" + USER_FILES_DIRECTORY + "] directory in SOLR_HOME [" + solrHome + "]. Features requiring this directory may fail.", e);
}
}
}
public static Path getUserFilesPath(Path solrHome) {
return Paths.get(solrHome.toAbsolutePath().toString(), USER_FILES_DIRECTORY).toAbsolutePath();
}
/**
* Ensures a directory name always ends with a '/'.
*/
public static String normalizeDir(String path) {
return (path != null && (!(path.endsWith("/") || path.endsWith("\\")))) ? path + File.separator : path;
}
// Logs a message only once per startup
private static void logOnceInfo(String key, String msg) {
if (!loggedOnce.contains(key)) {
loggedOnce.add(key);
log.info(msg);
}
}
}

View File

@ -16,10 +16,6 @@
*/ */
package org.apache.solr.core; package org.apache.solr.core;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -38,17 +34,13 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.PathMatcher; import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -65,7 +57,6 @@ import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.handler.component.SearchComponent; import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.ShardHandlerFactory; import org.apache.solr.handler.component.ShardHandlerFactory;
import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.request.SolrRequestHandler;
@ -86,30 +77,24 @@ import org.slf4j.LoggerFactory;
public class SolrResourceLoader implements ResourceLoader, Closeable { public class SolrResourceLoader implements ResourceLoader, Closeable {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
static final String project = "solr"; private static final String base = "org.apache.solr";
static final String base = "org.apache" + "." + project; private static final String[] packages = {
static final String[] packages = {
"", "analysis.", "schema.", "handler.", "handler.tagger.", "search.", "update.", "core.", "response.", "request.", "", "analysis.", "schema.", "handler.", "handler.tagger.", "search.", "update.", "core.", "response.", "request.",
"update.processor.", "util.", "spelling.", "handler.component.", "handler.dataimport.", "update.processor.", "util.", "spelling.", "handler.component.", "handler.dataimport.",
"spelling.suggest.", "spelling.suggest.fst.", "rest.schema.analysis.", "security.", "handler.admin.", "spelling.suggest.", "spelling.suggest.fst.", "rest.schema.analysis.", "security.", "handler.admin.",
"cloud.autoscaling." "cloud.autoscaling."
}; };
private static final java.lang.String SOLR_CORE_NAME = "solr.core.name";
private static Set<String> loggedOnce = new ConcurrentSkipListSet<>();
private static final Charset UTF_8 = StandardCharsets.UTF_8; private static final Charset UTF_8 = StandardCharsets.UTF_8;
private String name = ""; private String name = "";
protected URLClassLoader classLoader; protected URLClassLoader classLoader;
private final Path instanceDir; private final Path instanceDir;
private String dataDir;
private final List<SolrCoreAware> waitingForCore = Collections.synchronizedList(new ArrayList<SolrCoreAware>()); private final List<SolrCoreAware> waitingForCore = Collections.synchronizedList(new ArrayList<SolrCoreAware>());
private final List<SolrInfoBean> infoMBeans = Collections.synchronizedList(new ArrayList<SolrInfoBean>()); private final List<SolrInfoBean> infoMBeans = Collections.synchronizedList(new ArrayList<SolrInfoBean>());
private final List<ResourceLoaderAware> waitingForResources = Collections.synchronizedList(new ArrayList<ResourceLoaderAware>()); private final List<ResourceLoaderAware> waitingForResources = Collections.synchronizedList(new ArrayList<ResourceLoaderAware>());
private final Properties coreProperties;
private volatile boolean live; private volatile boolean live;
// Provide a registry so that managed resources can register themselves while the XML configuration // Provide a registry so that managed resources can register themselves while the XML configuration
@ -118,6 +103,9 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
// (such as the SolrZkClient) when XML docs are being parsed. // (such as the SolrZkClient) when XML docs are being parsed.
private RestManager.Registry managedResourceRegistry; private RestManager.Registry managedResourceRegistry;
/** @see #reloadLuceneSPI() */
private boolean needToReloadLuceneSPI = false; // requires synchronization
public synchronized RestManager.Registry getManagedResourceRegistry() { public synchronized RestManager.Registry getManagedResourceRegistry() {
if (managedResourceRegistry == null) { if (managedResourceRegistry == null) {
managedResourceRegistry = new RestManager.Registry(); managedResourceRegistry = new RestManager.Registry();
@ -126,47 +114,43 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
} }
public SolrResourceLoader() { public SolrResourceLoader() {
this(SolrResourceLoader.locateSolrHome(), null, null); this(SolrPaths.locateSolrHome(), null);
} }
/** /**
* <p> * Creates a loader.
* This loader will delegate to the context classloader when possible, * Note: we do NOT call {@link #reloadLuceneSPI()}.
* otherwise it will attempt to resolve resources using any jar files
* found in the "lib/" directory in the specified instance directory.
* If the instance directory is not specified (=null), SolrResourceLoader#locateInstanceDir will provide one.
*/ */
public SolrResourceLoader(Path instanceDir, ClassLoader parent) { public SolrResourceLoader(String name, List<Path> classpath, Path instanceDir, ClassLoader parent) {
this(instanceDir, parent, null);
}
public SolrResourceLoader(String name, List<Path> classpath, Path instanceDir, ClassLoader parent) throws MalformedURLException {
this(instanceDir, parent); this(instanceDir, parent);
this.name = name; this.name = name;
for (Path path : classpath) { final List<URL> libUrls = new ArrayList<>(classpath.size());
addToClassLoader(path.toUri().normalize().toURL()); try {
for (Path path : classpath) {
libUrls.add(path.toUri().normalize().toURL());
}
} catch (MalformedURLException e) { // impossible?
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} }
addToClassLoader(libUrls);
} }
public SolrResourceLoader(Path instanceDir) { public SolrResourceLoader(Path instanceDir) {
this(instanceDir, null, null); this(instanceDir, null);
} }
/** /**
* <p>
* This loader will delegate to Solr's classloader when possible, * This loader will delegate to Solr's classloader when possible,
* otherwise it will attempt to resolve resources using any jar files * otherwise it will attempt to resolve resources using any jar files
* found in the "lib/" directory in the specified instance directory. * found in the "lib/" directory in the specified instance directory.
* </p>
* *
* @param instanceDir - base directory for this resource loader, if null locateSolrHome() will be used. * @param instanceDir - base directory for this resource loader, if null locateSolrHome() will be used.
* @see #locateSolrHome * @see SolrPaths#locateSolrHome()
*/ */
public SolrResourceLoader(Path instanceDir, ClassLoader parent, Properties coreProperties) { public SolrResourceLoader(Path instanceDir, ClassLoader parent) {
if (instanceDir == null) { if (instanceDir == null) {
this.instanceDir = SolrResourceLoader.locateSolrHome().toAbsolutePath().normalize(); this.instanceDir = SolrPaths.locateSolrHome().toAbsolutePath().normalize();
log.debug("new SolrResourceLoader for deduced Solr Home: '{}'", this.instanceDir); log.debug("new SolrResourceLoader for deduced Solr Home: '{}'", this.instanceDir);
} else { } else {
this.instanceDir = instanceDir.toAbsolutePath().normalize(); this.instanceDir = instanceDir.toAbsolutePath().normalize();
@ -177,25 +161,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
parent = getClass().getClassLoader(); parent = getClass().getClassLoader();
} }
this.classLoader = URLClassLoader.newInstance(new URL[0], parent); this.classLoader = URLClassLoader.newInstance(new URL[0], parent);
/*
* Skip the lib subdirectory when we are loading from the solr home.
* Otherwise load it, so core lib directories still get loaded.
* The default sharedLib will pick this up later, and if the user has
* changed sharedLib, then we don't want to load that location anyway.
*/
if (!this.instanceDir.equals(SolrResourceLoader.locateSolrHome())) {
Path libDir = this.instanceDir.resolve("lib");
if (Files.exists(libDir)) {
try {
addToClassLoader(getURLs(libDir));
} catch (IOException e) {
log.warn("Couldn't add files from {} to classpath: {}", libDir, e.getMessage());
}
reloadLuceneSPI();
}
}
this.coreProperties = coreProperties;
} }
/** /**
@ -206,46 +171,36 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
* *
* @param urls the URLs of files to add * @param urls the URLs of files to add
*/ */
void addToClassLoader(List<URL> urls) { synchronized void addToClassLoader(List<URL> urls) {
URLClassLoader newLoader = addURLsToClassLoader(classLoader, urls); URLClassLoader newLoader = addURLsToClassLoader(classLoader, urls);
if (newLoader != classLoader) { if (newLoader == classLoader) {
this.classLoader = newLoader; return; // short-circuit
} }
log.info("[{}] Added {} libs to classloader, from paths: {}", this.classLoader = newLoader;
getCoreName("null"), urls.size(), urls.stream() this.needToReloadLuceneSPI = true;
log.info("Added {} libs to classloader, from paths: {}",
urls.size(), urls.stream()
.map(u -> u.getPath().substring(0,u.getPath().lastIndexOf("/"))) .map(u -> u.getPath().substring(0,u.getPath().lastIndexOf("/")))
.sorted() .sorted()
.distinct() .distinct()
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
private String getCoreName(String defaultVal) {
if (getCoreProperties() != null) {
return getCoreProperties().getProperty(SOLR_CORE_NAME, defaultVal);
} else {
return defaultVal;
}
}
/**
* Adds URLs to the ResourceLoader's internal classloader. This method <b>MUST</b>
* only be called prior to using this ResourceLoader to get any resources, otherwise
* its behavior will be non-deterministic. You also have to {link @reloadLuceneSPI}
* before using this ResourceLoader.
*
* @param urls the URLs of files to add
*/
void addToClassLoader(URL... urls) {
addToClassLoader(Arrays.asList(urls));
}
/** /**
* Reloads all Lucene SPI implementations using the new classloader. * Reloads all Lucene SPI implementations using the new classloader.
* This method must be called after {@link #addToClassLoader(List)} * This method must be called after {@link #addToClassLoader(List)}
* and before using this ResourceLoader. * and before using this ResourceLoader.
*/ */
void reloadLuceneSPI() { synchronized void reloadLuceneSPI() {
// TODO improve to use a static Set<URL> to check when we need to
if (!needToReloadLuceneSPI) {
return;
}
needToReloadLuceneSPI = false; // reset
log.debug("Reloading Lucene SPI");
// Codecs: // Codecs:
PostingsFormat.reloadPostingsFormats(this.classLoader); PostingsFormat.reloadPostingsFormats(this.classLoader);
DocValuesFormat.reloadDocValuesFormats(this.classLoader); DocValuesFormat.reloadDocValuesFormats(this.classLoader);
@ -324,34 +279,10 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
}); });
} }
/**
* Ensures a directory name always ends with a '/'.
*/
public static String normalizeDir(String path) {
return (path != null && (!(path.endsWith("/") || path.endsWith("\\")))) ? path + File.separator : path;
}
public String[] listConfigDir() {
File configdir = new File(getConfigDir());
if (configdir.exists() && configdir.isDirectory()) {
return configdir.list();
} else {
return new String[0];
}
}
public String getConfigDir() { public String getConfigDir() {
return instanceDir.resolve("conf").toString(); return instanceDir.resolve("conf").toString();
} }
public String getDataDir() {
return dataDir;
}
public Properties getCoreProperties() {
return coreProperties;
}
/** /**
* EXPERT * EXPERT
* <p> * <p>
@ -363,26 +294,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
return classLoader; return classLoader;
} }
/**
* Opens a schema resource by its name.
* Override this method to customize loading schema resources.
*
* @return the stream for the named schema
*/
public InputStream openSchema(String name) throws IOException {
return openResource(name);
}
/**
* Opens a config resource by its name.
* Override this method to customize loading config resources.
*
* @return the stream for the named configuration
*/
public InputStream openConfig(String name) throws IOException {
return openResource(name);
}
private Path checkPathIsSafe(Path pathToCheck) throws IOException { private Path checkPathIsSafe(Path pathToCheck) throws IOException {
if (Boolean.getBoolean("solr.allow.unsafe.resourceloading")) if (Boolean.getBoolean("solr.allow.unsafe.resourceloading"))
return pathToCheck; return pathToCheck;
@ -509,7 +420,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
// Using this pattern, legacy analysis components from previous Solr versions are identified and delegated to SPI loader: // Using this pattern, legacy analysis components from previous Solr versions are identified and delegated to SPI loader:
private static final Pattern legacyAnalysisPattern = private static final Pattern legacyAnalysisPattern =
Pattern.compile("((\\Q" + base + ".analysis.\\E)|(\\Q" + project + ".\\E))([\\p{L}_$][\\p{L}\\p{N}_$]+?)(TokenFilter|Filter|Tokenizer|CharFilter)Factory"); Pattern.compile("((\\Q" + base + ".analysis.\\E)|(\\Qsolr.\\E))([\\p{L}_$][\\p{L}\\p{N}_$]+?)(TokenFilter|Filter|Tokenizer|CharFilter)Factory");
@Override @Override
public <T> Class<? extends T> findClass(String cname, Class<T> expectedType) { public <T> Class<? extends T> findClass(String cname, Class<T> expectedType) {
@ -569,8 +480,8 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
return clazz = Class.forName(cname, true, classLoader).asSubclass(expectedType); return clazz = Class.forName(cname, true, classLoader).asSubclass(expectedType);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
String newName = cname; String newName = cname;
if (newName.startsWith(project)) { if (newName.startsWith("solr")) {
newName = cname.substring(project.length() + 1); newName = cname.substring("solr".length() + 1);
} }
for (String subpackage : subpackages) { for (String subpackage : subpackages) {
try { try {
@ -619,35 +530,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
return newInstance(cname, expectedType, subpackages, NO_CLASSES, NO_OBJECTS); return newInstance(cname, expectedType, subpackages, NO_CLASSES, NO_OBJECTS);
} }
public CoreAdminHandler newAdminHandlerInstance(final CoreContainer coreContainer, String cname, String... subpackages) {
Class<? extends CoreAdminHandler> clazz = findClass(cname, CoreAdminHandler.class, subpackages);
if (clazz == null) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Can not find class: " + cname + " in " + classLoader);
}
CoreAdminHandler obj = null;
try {
Constructor<? extends CoreAdminHandler> ctor = clazz.getConstructor(CoreContainer.class);
obj = ctor.newInstance(coreContainer);
} catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Error instantiating class: '" + clazz.getName() + "'", e);
}
if (!live) {
//TODO: Does SolrCoreAware make sense here since in a multi-core context
// which core are we talking about ?
if (obj instanceof ResourceLoaderAware) {
assertAwareCompatibility(ResourceLoaderAware.class, obj);
waitingForResources.add((ResourceLoaderAware) obj);
}
}
return obj;
}
public <T> T newInstance(String cName, Class<T> expectedType, String[] subPackages, Class[] params, Object[] args) { public <T> T newInstance(String cName, Class<T> expectedType, String[] subPackages, Class[] params, Object[] args) {
Class<? extends T> clazz = findClass(cName, expectedType, subPackages); Class<? extends T> clazz = findClass(cName, expectedType, subPackages);
if (clazz == null) { if (clazz == null) {
@ -705,8 +587,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
* Tell all {@link SolrCoreAware} instances about the SolrCore * Tell all {@link SolrCoreAware} instances about the SolrCore
*/ */
public void inform(SolrCore core) { public void inform(SolrCore core) {
this.dataDir = core.getDataDir();
// make a copy to avoid potential deadlock of a callback calling newInstance and trying to // make a copy to avoid potential deadlock of a callback calling newInstance and trying to
// add something to waitingForCore. // add something to waitingForCore.
SolrCoreAware[] arr; SolrCoreAware[] arr;
@ -781,86 +661,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable {
* if both fail, defaults to solr/ * if both fail, defaults to solr/
* @return the instance directory name * @return the instance directory name
*/ */
/**
* Finds the solrhome based on looking up the value in one of three places:
* <ol>
* <li>JNDI: via java:comp/env/solr/home</li>
* <li>The system property solr.solr.home</li>
* <li>Look in the current working directory for a solr/ directory</li>
* </ol>
* <p>
* The return value is normalized. Normalization essentially means it ends in a trailing slash.
*
* @return A normalized solrhome
* @see #normalizeDir(String)
*/
public static Path locateSolrHome() {
String home = null;
// Try JNDI
try {
Context c = new InitialContext();
home = (String) c.lookup("java:comp/env/" + project + "/home");
logOnceInfo("home_using_jndi", "Using JNDI solr.home: " + home);
} catch (NoInitialContextException e) {
log.debug("JNDI not configured for " + project + " (NoInitialContextEx)");
} catch (NamingException e) {
log.debug("No /" + project + "/home in JNDI");
} catch (RuntimeException ex) {
log.warn("Odd RuntimeException while testing for JNDI: " + ex.getMessage());
}
// Now try system property
if (home == null) {
String prop = project + ".solr.home";
home = System.getProperty(prop);
if (home != null) {
logOnceInfo("home_using_sysprop", "Using system property " + prop + ": " + home);
}
}
// if all else fails, try
if (home == null) {
home = project + '/';
logOnceInfo("home_default", project + " home defaulted to '" + home + "' (could not find system property or JNDI)");
}
return Paths.get(home);
}
/**
* Solr allows users to store arbitrary files in a special directory located directly under SOLR_HOME.
* <p>
* This directory is generally created by each node on startup. Files located in this directory can then be
* manipulated using select Solr features (e.g. streaming expressions).
*/
public static final String USER_FILES_DIRECTORY = "userfiles";
public static void ensureUserFilesDataDir(Path solrHome) {
final Path userFilesPath = getUserFilesPath(solrHome);
final File userFilesDirectory = new File(userFilesPath.toString());
if (!userFilesDirectory.exists()) {
try {
final boolean created = userFilesDirectory.mkdir();
if (!created) {
log.warn("Unable to create [{}] directory in SOLR_HOME [{}]. Features requiring this directory may fail.", USER_FILES_DIRECTORY, solrHome);
}
} catch (Exception e) {
log.warn("Unable to create [" + USER_FILES_DIRECTORY + "] directory in SOLR_HOME [" + solrHome + "]. Features requiring this directory may fail.", e);
}
}
}
public static Path getUserFilesPath(Path solrHome) {
return Paths.get(solrHome.toAbsolutePath().toString(), USER_FILES_DIRECTORY).toAbsolutePath();
}
// Logs a message only once per startup
private static void logOnceInfo(String key, String msg) {
if (!loggedOnce.contains(key)) {
loggedOnce.add(key);
log.info(msg);
}
}
/** /**
* @return the instance path for this resource loader * @return the instance path for this resource loader

View File

@ -55,21 +55,22 @@ import static org.apache.solr.common.params.CommonParams.NAME;
/** /**
* * Loads {@code solr.xml}.
*/ */
public class SolrXmlConfig { public class SolrXmlConfig {
// TODO should these from* methods return a NodeConfigBuilder so that the caller (a test) can make further
// manipulations like add properties and set the CorePropertiesLocator and "async" mode?
public final static String SOLR_XML_FILE = "solr.xml"; public final static String SOLR_XML_FILE = "solr.xml";
public final static String SOLR_DATA_HOME = "solr.data.home"; public final static String SOLR_DATA_HOME = "solr.data.home";
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static NodeConfig fromConfig(XmlConfigFile config) { public static NodeConfig fromConfig(Path solrHome, XmlConfigFile config) {
checkForIllegalConfig(config); checkForIllegalConfig(config);
config.substituteProperties();
CloudConfig cloudConfig = null; CloudConfig cloudConfig = null;
UpdateShardHandlerConfig deprecatedUpdateConfig = null; UpdateShardHandlerConfig deprecatedUpdateConfig = null;
@ -96,7 +97,8 @@ public class SolrXmlConfig {
updateConfig = deprecatedUpdateConfig; updateConfig = deprecatedUpdateConfig;
} }
NodeConfig.NodeConfigBuilder configBuilder = new NodeConfig.NodeConfigBuilder(nodeName, config.getResourceLoader()); NodeConfig.NodeConfigBuilder configBuilder = new NodeConfig.NodeConfigBuilder(nodeName, solrHome);
configBuilder.setSolrResourceLoader(config.getResourceLoader());
configBuilder.setUpdateShardHandlerConfig(updateConfig); configBuilder.setUpdateShardHandlerConfig(updateConfig);
configBuilder.setShardHandlerFactoryConfig(getShardHandlerFactoryPluginInfo(config)); configBuilder.setShardHandlerFactoryConfig(getShardHandlerFactoryPluginInfo(config));
configBuilder.setSolrCoreCacheFactoryConfig(getTransientCoreCacheFactoryPluginInfo(config)); configBuilder.setSolrCoreCacheFactoryConfig(getTransientCoreCacheFactoryPluginInfo(config));
@ -110,7 +112,7 @@ public class SolrXmlConfig {
return fillSolrSection(configBuilder, entries); return fillSolrSection(configBuilder, entries);
} }
public static NodeConfig fromFile(SolrResourceLoader loader, Path configFile) { public static NodeConfig fromFile(Path solrHome, Path configFile, Properties substituteProps) {
log.info("Loading container configuration from {}", configFile); log.info("Loading container configuration from {}", configFile);
@ -120,7 +122,7 @@ public class SolrXmlConfig {
} }
try (InputStream inputStream = Files.newInputStream(configFile)) { try (InputStream inputStream = Files.newInputStream(configFile)) {
return fromInputStream(loader, inputStream); return fromInputStream(solrHome, inputStream, substituteProps);
} catch (SolrException exc) { } catch (SolrException exc) {
throw exc; throw exc;
} catch (Exception exc) { } catch (Exception exc) {
@ -129,16 +131,24 @@ public class SolrXmlConfig {
} }
} }
public static NodeConfig fromString(SolrResourceLoader loader, String xml) { /** TEST-ONLY */
return fromInputStream(loader, new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); public static NodeConfig fromString(Path solrHome, String xml) {
return fromInputStream(
solrHome,
new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)),
new Properties());
} }
public static NodeConfig fromInputStream(SolrResourceLoader loader, InputStream is) { public static NodeConfig fromInputStream(Path solrHome, InputStream is, Properties substituteProps) {
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
if (substituteProps == null) {
substituteProps = new Properties();
}
try { try {
byte[] buf = IOUtils.toByteArray(is); byte[] buf = IOUtils.toByteArray(is);
try (ByteArrayInputStream dup = new ByteArrayInputStream(buf)) { try (ByteArrayInputStream dup = new ByteArrayInputStream(buf)) {
XmlConfigFile config = new XmlConfigFile(loader, null, new InputSource(dup), null, false); XmlConfigFile config = new XmlConfigFile(loader, null, new InputSource(dup), null, substituteProps);
return fromConfig(config); return fromConfig(solrHome, config);
} }
} catch (SolrException exc) { } catch (SolrException exc) {
throw exc; throw exc;
@ -147,13 +157,8 @@ public class SolrXmlConfig {
} }
} }
public static NodeConfig fromSolrHome(SolrResourceLoader loader, Path solrHome) { public static NodeConfig fromSolrHome(Path solrHome, Properties substituteProps) {
return fromFile(loader, solrHome.resolve(SOLR_XML_FILE)); return fromFile(solrHome, solrHome.resolve(SOLR_XML_FILE), substituteProps);
}
public static NodeConfig fromSolrHome(Path solrHome) {
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
return fromSolrHome(loader, solrHome);
} }
private static void checkForIllegalConfig(XmlConfigFile config) { private static void checkForIllegalConfig(XmlConfigFile config) {
@ -187,7 +192,7 @@ public class SolrXmlConfig {
Node node = ((NodeList) config.evaluate("solr", XPathConstants.NODESET)).item(0); Node node = ((NodeList) config.evaluate("solr", XPathConstants.NODESET)).item(0);
XPath xpath = config.getXPath(); XPath xpath = config.getXPath();
NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET); NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET);
Properties properties = new Properties(); Properties properties = new Properties(config.getSubstituteProperties());
for (int i = 0; i < props.getLength(); i++) { for (int i = 0; i < props.getLength(); i++) {
Node prop = props.item(i); Node prop = props.item(i);
properties.setProperty(DOMUtil.getAttr(prop, NAME), properties.setProperty(DOMUtil.getAttr(prop, NAME),

View File

@ -72,20 +72,25 @@ public class XmlConfigFile { // formerly simply "Config"
private final String prefix; private final String prefix;
private final String name; private final String name;
private final SolrResourceLoader loader; private final SolrResourceLoader loader;
private final Properties substituteProperties;
private int zkVersion = -1; private int zkVersion = -1;
/** /**
* Builds a config from a resource name with no xpath prefix. * Builds a config from a resource name with no xpath prefix. Does no property substitution.
*/ */
public XmlConfigFile(SolrResourceLoader loader, String name) throws ParserConfigurationException, IOException, SAXException public XmlConfigFile(SolrResourceLoader loader, String name) throws ParserConfigurationException, IOException, SAXException
{ {
this( loader, name, null, null ); this( loader, name, null, null );
} }
/**
* Builds a config. Does no property substitution.
*/
public XmlConfigFile(SolrResourceLoader loader, String name, InputSource is, String prefix) throws ParserConfigurationException, IOException, SAXException public XmlConfigFile(SolrResourceLoader loader, String name, InputSource is, String prefix) throws ParserConfigurationException, IOException, SAXException
{ {
this(loader, name, is, prefix, true); this(loader, name, is, prefix, null);
} }
/** /**
* Builds a config: * Builds a config:
* <p> * <p>
@ -101,20 +106,22 @@ public class XmlConfigFile { // formerly simply "Config"
* @param name the resource name used if the input stream 'is' is null * @param name the resource name used if the input stream 'is' is null
* @param is the resource as a SAX InputSource * @param is the resource as a SAX InputSource
* @param prefix an optional prefix that will be prepended to all non-absolute xpath expressions * @param prefix an optional prefix that will be prepended to all non-absolute xpath expressions
* @param substituteProps optional property substitution
*/ */
public XmlConfigFile(SolrResourceLoader loader, String name, InputSource is, String prefix, boolean substituteProps) throws ParserConfigurationException, IOException, SAXException public XmlConfigFile(SolrResourceLoader loader, String name, InputSource is, String prefix, Properties substituteProps) throws ParserConfigurationException, IOException, SAXException
{ {
if( loader == null ) { if( loader == null ) {
loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome()); loader = new SolrResourceLoader(SolrPaths.locateSolrHome());
} }
this.loader = loader; this.loader = loader;
this.substituteProperties = substituteProps;
this.name = name; this.name = name;
this.prefix = (prefix != null && !prefix.endsWith("/"))? prefix + '/' : prefix; this.prefix = (prefix != null && !prefix.endsWith("/"))? prefix + '/' : prefix;
try { try {
javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
if (is == null) { if (is == null) {
InputStream in = loader.openConfig(name); InputStream in = loader.openResource(name);
if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) { if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {
zkVersion = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion(); zkVersion = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();
log.debug("loaded config {} with version {} ",name,zkVersion); log.debug("loaded config {} with version {} ",name,zkVersion);
@ -143,7 +150,7 @@ public class XmlConfigFile { // formerly simply "Config"
// some XML parsers are broken and don't close the byte stream (but they should according to spec) // some XML parsers are broken and don't close the byte stream (but they should according to spec)
IOUtils.closeQuietly(is.getByteStream()); IOUtils.closeQuietly(is.getByteStream());
} }
if (substituteProps) { if (substituteProps != null) {
DOMUtil.substituteProperties(doc, getSubstituteProperties()); DOMUtil.substituteProperties(doc, getSubstituteProperties());
} }
} catch (ParserConfigurationException | SAXException | TransformerException e) { } catch (ParserConfigurationException | SAXException | TransformerException e) {
@ -167,23 +174,11 @@ public class XmlConfigFile { // formerly simply "Config"
} }
} }
/** Returns non-null props to substitute. Param is the base/default set, also non-null. */
protected Properties getSubstituteProperties() { protected Properties getSubstituteProperties() {
return loader.getCoreProperties(); return this.substituteProperties;
} }
public XmlConfigFile(SolrResourceLoader loader, String name, Document doc) {
this.prefix = null;
this.doc = doc;
try {
this.origDoc = copyDoc(doc);
} catch (TransformerException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
this.name = name;
this.loader = loader;
}
private static Document copyDoc(Document doc) throws TransformerException { private static Document copyDoc(Document doc) throws TransformerException {
TransformerFactory tfactory = TransformerFactory.newInstance(); TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer tx = tfactory.newTransformer(); Transformer tx = tfactory.newTransformer();
@ -224,11 +219,6 @@ public class XmlConfigFile { // formerly simply "Config"
return (prefix==null || path.startsWith("/")) ? path : prefix+path; return (prefix==null || path.startsWith("/")) ? path : prefix+path;
} }
public void substituteProperties() {
DOMUtil.substituteProperties(doc, getSubstituteProperties());
}
public Object evaluate(String path, QName type) { public Object evaluate(String path, QName type) {
XPath xpath = xpathFactory.newXPath(); XPath xpath = xpathFactory.newXPath();
try { try {
@ -442,8 +432,4 @@ public class XmlConfigFile { // formerly simply "Config"
return zkVersion; return zkVersion;
} }
public XmlConfigFile getOriginalConfig() {
return new XmlConfigFile(loader, null, origDoc);
}
} }

View File

@ -60,7 +60,7 @@ public class ZkContainer {
} }
public void initZooKeeper(final CoreContainer cc, String solrHome, CloudConfig config) { public void initZooKeeper(final CoreContainer cc, CloudConfig config) {
ZkController zkController = null; ZkController zkController = null;
@ -79,6 +79,7 @@ public class ZkContainer {
// TODO: remove after updating to an slf4j based zookeeper // TODO: remove after updating to an slf4j based zookeeper
System.setProperty("zookeeper.jmx.log4j.disable", "true"); System.setProperty("zookeeper.jmx.log4j.disable", "true");
String solrHome = cc.getSolrHome();
if (zkRun != null) { if (zkRun != null) {
String zkDataHome = System.getProperty("zkServerDataDir", Paths.get(solrHome).resolve("zoo_data").toString()); String zkDataHome = System.getProperty("zkServerDataDir", Paths.get(solrHome).resolve("zoo_data").toString());
String zkConfHome = System.getProperty("zkServerConfDir", solrHome); String zkConfHome = System.getProperty("zkServerConfDir", solrHome);
@ -147,7 +148,7 @@ public class ZkContainer {
if(boostrapConf) { if(boostrapConf) {
ZkController.bootstrapConf(zkController.getZkClient(), cc, solrHome); ZkController.bootstrapConf(zkController.getZkClient(), cc);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -73,9 +73,8 @@ public class DistribPackageStore implements PackageStore {
public DistribPackageStore(CoreContainer coreContainer) { public DistribPackageStore(CoreContainer coreContainer) {
this.coreContainer = coreContainer; this.coreContainer = coreContainer;
solrhome = this.coreContainer.getResourceLoader().getInstancePath(); this.solrhome = Paths.get(this.coreContainer.getSolrHome());
ensurePackageStoreDir(coreContainer.getResourceLoader().getInstancePath()); ensurePackageStoreDir(Paths.get(coreContainer.getSolrHome()));
} }
@Override @Override

View File

@ -42,7 +42,7 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.StringUtils; import org.apache.solr.common.StringUtils;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrPaths;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -95,9 +95,9 @@ public class CatStream extends TupleStream implements Expressible {
} }
final SolrCore core = (SolrCore) context.get("solr-core"); final SolrCore core = (SolrCore) context.get("solr-core");
this.chroot = Paths.get(core.getCoreContainer().getSolrHome(), SolrResourceLoader.USER_FILES_DIRECTORY).toString(); this.chroot = Paths.get(core.getCoreContainer().getSolrHome(), SolrPaths.USER_FILES_DIRECTORY).toString();
if (! new File(this.chroot).exists()) { if (! new File(this.chroot).exists()) {
throw new IllegalStateException(SolrResourceLoader.USER_FILES_DIRECTORY + " directory used to load files must exist but could not be found!"); throw new IllegalStateException(SolrPaths.USER_FILES_DIRECTORY + " directory used to load files must exist but could not be found!");
} }
} }

View File

@ -321,7 +321,7 @@ enum CoreAdminOperation implements CoreAdminOp {
try (SolrCore core = cores.getCore(cname)) { try (SolrCore core = cores.getCore(cname)) {
if (core != null) { if (core != null) {
info.add(NAME, core.getName()); info.add(NAME, core.getName());
info.add("instanceDir", core.getResourceLoader().getInstancePath().toString()); info.add("instanceDir", core.getInstancePath().toString());
info.add("dataDir", normalizePath(core.getDataDir())); info.add("dataDir", normalizePath(core.getDataDir()));
info.add("config", core.getConfigResource()); info.add("config", core.getConfigResource());
info.add("schema", core.getSchemaResource()); info.add("schema", core.getSchemaResource());

View File

@ -188,7 +188,7 @@ public class SystemInfoHandler extends RequestHandlerBase
// Solr Home // Solr Home
SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<>(); SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<>();
dirs.add( "cwd" , new File( System.getProperty("user.dir")).getAbsolutePath() ); dirs.add( "cwd" , new File( System.getProperty("user.dir")).getAbsolutePath() );
dirs.add("instance", core.getResourceLoader().getInstancePath().toString()); dirs.add("instance", core.getInstancePath().toString());
try { try {
dirs.add( "data", core.getDirectoryFactory().normalize(core.getDataDir())); dirs.add( "data", core.getDirectoryFactory().normalize(core.getDataDir()));
} catch (IOException e) { } catch (IOException e) {

View File

@ -20,8 +20,8 @@ package org.apache.solr.pkg;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.net.MalformedURLException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -265,15 +265,11 @@ public class PackageLoader implements Closeable {
paths.add(coreContainer.getPackageStoreAPI().getPackageStore().getRealpath(file)); paths.add(coreContainer.getPackageStoreAPI().getPackageStore().getRealpath(file));
} }
try { loader = new SolrResourceLoader(
loader = new SolrResourceLoader( "PACKAGE_LOADER: " + parent.name() + ":" + version,
"PACKAGE_LOADER: " + parent.name() + ":" + version, paths,
paths, Paths.get(coreContainer.getSolrHome()),
coreContainer.getResourceLoader().getInstancePath(), coreContainer.getResourceLoader().getClassLoader());
coreContainer.getResourceLoader().getClassLoader());
} catch (MalformedURLException e) {
log.error("Could not load classloader ", e);
}
} }
public String getVersion() { public String getVersion() {

View File

@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.TextResponseWriter; import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser; import org.apache.solr.search.QParser;
import org.apache.solr.search.function.FileFloatSource; import org.apache.solr.search.function.FileFloatSource;
@ -95,7 +96,7 @@ public class ExternalFileField extends FieldType implements SchemaAware {
* @return a FileFloatSource * @return a FileFloatSource
*/ */
public FileFloatSource getFileFloatSource(SchemaField field) { public FileFloatSource getFileFloatSource(SchemaField field) {
return getFileFloatSource(field, schema.getResourceLoader().getDataDir()); return getFileFloatSource(field, SolrRequestInfo.getRequestInfo().getReq().getCore().getDataDir());
} }
/** /**

View File

@ -34,6 +34,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -134,6 +135,7 @@ public class IndexSchema {
protected final Version luceneVersion; protected final Version luceneVersion;
protected float version; protected float version;
protected final SolrResourceLoader loader; protected final SolrResourceLoader loader;
protected final Properties substitutableProperties;
protected Map<String,SchemaField> fields = new HashMap<>(); protected Map<String,SchemaField> fields = new HashMap<>();
protected Map<String,FieldType> fieldTypes = new HashMap<>(); protected Map<String,FieldType> fieldTypes = new HashMap<>();
@ -141,6 +143,7 @@ public class IndexSchema {
protected List<SchemaField> fieldsWithDefaultValue = new ArrayList<>(); protected List<SchemaField> fieldsWithDefaultValue = new ArrayList<>();
protected Collection<SchemaField> requiredFields = new HashSet<>(); protected Collection<SchemaField> requiredFields = new HashSet<>();
protected DynamicField[] dynamicFields = new DynamicField[] {}; protected DynamicField[] dynamicFields = new DynamicField[] {};
public DynamicField[] getDynamicFields() { return dynamicFields; } public DynamicField[] getDynamicFields() { return dynamicFields; }
protected Cache<String, SchemaField> dynamicFieldCache = new ConcurrentLRUCache(10000, 8000, 9000,100, false,false, null); protected Cache<String, SchemaField> dynamicFieldCache = new ConcurrentLRUCache(10000, 8000, 9000,100, false,false, null);
@ -166,12 +169,11 @@ public class IndexSchema {
/** /**
* Constructs a schema using the specified resource name and stream. * Constructs a schema using the specified resource name and stream.
* @see SolrResourceLoader#openSchema
* By default, this follows the normal config path directory searching rules. * By default, this follows the normal config path directory searching rules.
* @see SolrResourceLoader#openResource * @see SolrResourceLoader#openResource
*/ */
public IndexSchema(String name, InputSource is, Version luceneVersion, SolrResourceLoader resourceLoader) { public IndexSchema(String name, InputSource is, Version luceneVersion, SolrResourceLoader resourceLoader, Properties substitutableProperties) {
this(luceneVersion, resourceLoader); this(luceneVersion, resourceLoader, substitutableProperties);
this.resourceName = Objects.requireNonNull(name); this.resourceName = Objects.requireNonNull(name);
try { try {
@ -182,9 +184,10 @@ public class IndexSchema {
} }
} }
protected IndexSchema(Version luceneVersion, SolrResourceLoader loader) { protected IndexSchema(Version luceneVersion, SolrResourceLoader loader, Properties substitutableProperties) {
this.luceneVersion = Objects.requireNonNull(luceneVersion); this.luceneVersion = Objects.requireNonNull(luceneVersion);
this.loader = loader; this.loader = loader;
this.substitutableProperties = substitutableProperties;
} }
/** /**
@ -468,17 +471,13 @@ public class IndexSchema {
try { try {
// pass the config resource loader to avoid building an empty one for no reason: // pass the config resource loader to avoid building an empty one for no reason:
// in the current case though, the stream is valid so we wont load the resource by name // in the current case though, the stream is valid so we wont load the resource by name
XmlConfigFile schemaConf = new XmlConfigFile(loader, SCHEMA, is, SLASH+SCHEMA+SLASH); XmlConfigFile schemaConf = new XmlConfigFile(loader, SCHEMA, is, SLASH+SCHEMA+SLASH, substitutableProperties);
Document document = schemaConf.getDocument(); Document document = schemaConf.getDocument();
final XPath xpath = schemaConf.getXPath(); final XPath xpath = schemaConf.getXPath();
String expression = stepsToPath(SCHEMA, AT + NAME); String expression = stepsToPath(SCHEMA, AT + NAME);
Node nd = (Node) xpath.evaluate(expression, document, XPathConstants.NODE); Node nd = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
String coreName = getCoreName("null");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// Another case where the initialization from the test harness is different than the "real world" // Another case where the initialization from the test harness is different than the "real world"
sb.append("[");
sb.append(coreName);
sb.append("] ");
if (nd==null) { if (nd==null) {
sb.append("schema has no name!"); sb.append("schema has no name!");
log.warn(sb.toString()); log.warn(sb.toString());
@ -620,14 +619,6 @@ public class IndexSchema {
log.info("Loaded schema {}/{} with uniqueid field {}", name, version, uniqueKeyFieldName); log.info("Loaded schema {}/{} with uniqueid field {}", name, version, uniqueKeyFieldName);
} }
private String getCoreName(String defaultVal) {
if (loader != null && loader.getCoreProperties() != null) {
return loader.getCoreProperties().getProperty(SOLR_CORE_NAME, defaultVal);
} else {
return defaultVal;
}
}
protected void postReadInform() { protected void postReadInform() {
//Run the callbacks on SchemaAware now that everything else is done //Run the callbacks on SchemaAware now that everything else is done
for (SchemaAware aware : schemaAware) { for (SchemaAware aware : schemaAware) {

View File

@ -74,7 +74,7 @@ public abstract class IndexSchemaFactory implements NamedListInitializedPlugin {
} }
try { try {
schemaInputStream = loader.openSchema(resourceName); schemaInputStream = loader.openResource(resourceName);
} catch (Exception e) { } catch (Exception e) {
final String msg = "Error loading schema resource " + resourceName; final String msg = "Error loading schema resource " + resourceName;
log.error(msg, e); log.error(msg, e);
@ -82,7 +82,7 @@ public abstract class IndexSchemaFactory implements NamedListInitializedPlugin {
} }
InputSource inputSource = new InputSource(schemaInputStream); InputSource inputSource = new InputSource(schemaInputStream);
inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(resourceName)); inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(resourceName));
IndexSchema schema = new IndexSchema(resourceName, inputSource, config.luceneMatchVersion, loader); IndexSchema schema = new IndexSchema(resourceName, inputSource, config.luceneMatchVersion, loader, config.getSubstituteProperties());
return schema; return schema;
} }

View File

@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -96,13 +97,12 @@ public final class ManagedIndexSchema extends IndexSchema {
/** /**
* Constructs a schema using the specified resource name and stream. * Constructs a schema using the specified resource name and stream.
* *
* @see org.apache.solr.core.SolrResourceLoader#openSchema * By default, this follows the normal config path directory searching rules.
* By default, this follows the normal config path directory searching rules.
* @see org.apache.solr.core.SolrResourceLoader#openResource * @see org.apache.solr.core.SolrResourceLoader#openResource
*/ */
ManagedIndexSchema(SolrConfig solrConfig, String name, InputSource is, boolean isMutable, ManagedIndexSchema(SolrConfig solrConfig, String name, InputSource is, boolean isMutable,
String managedSchemaResourceName, int schemaZkVersion, Object schemaUpdateLock) { String managedSchemaResourceName, int schemaZkVersion, Object schemaUpdateLock) {
super(name, is, solrConfig.luceneMatchVersion, solrConfig.getResourceLoader()); super(name, is, solrConfig.luceneMatchVersion, solrConfig.getResourceLoader(), solrConfig.getSubstituteProperties());
this.isMutable = isMutable; this.isMutable = isMutable;
this.managedSchemaResourceName = managedSchemaResourceName; this.managedSchemaResourceName = managedSchemaResourceName;
this.schemaZkVersion = schemaZkVersion; this.schemaZkVersion = schemaZkVersion;
@ -1323,8 +1323,8 @@ public final class ManagedIndexSchema extends IndexSchema {
} }
private ManagedIndexSchema(Version luceneVersion, SolrResourceLoader loader, boolean isMutable, private ManagedIndexSchema(Version luceneVersion, SolrResourceLoader loader, boolean isMutable,
String managedSchemaResourceName, int schemaZkVersion, Object schemaUpdateLock) { String managedSchemaResourceName, int schemaZkVersion, Object schemaUpdateLock, Properties substitutableProps) {
super(luceneVersion, loader); super(luceneVersion, loader, substitutableProps);
this.isMutable = isMutable; this.isMutable = isMutable;
this.managedSchemaResourceName = managedSchemaResourceName; this.managedSchemaResourceName = managedSchemaResourceName;
this.schemaZkVersion = schemaZkVersion; this.schemaZkVersion = schemaZkVersion;
@ -1342,7 +1342,7 @@ public final class ManagedIndexSchema extends IndexSchema {
*/ */
ManagedIndexSchema shallowCopy(boolean includeFieldDataStructures) { ManagedIndexSchema shallowCopy(boolean includeFieldDataStructures) {
ManagedIndexSchema newSchema = new ManagedIndexSchema ManagedIndexSchema newSchema = new ManagedIndexSchema
(luceneVersion, loader, isMutable, managedSchemaResourceName, schemaZkVersion, getSchemaUpdateLock()); (luceneVersion, loader, isMutable, managedSchemaResourceName, schemaZkVersion, getSchemaUpdateLock(), substitutableProperties);
newSchema.name = name; newSchema.name = name;
newSchema.version = version; newSchema.version = version;

View File

@ -149,7 +149,7 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
if (null == schemaInputStream) { if (null == schemaInputStream) {
// The managed schema file could not be found - load the non-managed schema // The managed schema file could not be found - load the non-managed schema
try { try {
schemaInputStream = loader.openSchema(resourceName); schemaInputStream = loader.openResource(resourceName);
loadedResource = resourceName; loadedResource = resourceName;
shouldUpgrade = true; shouldUpgrade = true;
} catch (Exception e) { } catch (Exception e) {
@ -190,7 +190,7 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
InputStream schemaInputStream = null; InputStream schemaInputStream = null;
try { try {
// Attempt to load the managed schema // Attempt to load the managed schema
schemaInputStream = loader.openSchema(managedSchemaResourceName); schemaInputStream = loader.openResource(managedSchemaResourceName);
loadedResource = managedSchemaResourceName; loadedResource = managedSchemaResourceName;
warnIfNonManagedSchemaExists(); warnIfNonManagedSchemaExists();
} catch (IOException e) { } catch (IOException e) {
@ -200,7 +200,7 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
if (null == schemaInputStream) { if (null == schemaInputStream) {
// The managed schema file could not be found - load the non-managed schema // The managed schema file could not be found - load the non-managed schema
try { try {
schemaInputStream = loader.openSchema(resourceName); schemaInputStream = loader.openResource(resourceName);
loadedResource = resourceName; loadedResource = resourceName;
shouldUpgrade = true; shouldUpgrade = true;
} catch (Exception e) { } catch (Exception e) {
@ -235,7 +235,7 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
} else { // Config is not in ZooKeeper } else { // Config is not in ZooKeeper
InputStream nonManagedSchemaInputStream = null; InputStream nonManagedSchemaInputStream = null;
try { try {
nonManagedSchemaInputStream = loader.openSchema(resourceName); nonManagedSchemaInputStream = loader.openResource(resourceName);
if (null != nonManagedSchemaInputStream) { if (null != nonManagedSchemaInputStream) {
exists = true; exists = true;
} }

View File

@ -72,8 +72,8 @@ import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoBean; import org.apache.solr.core.SolrInfoBean;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.core.SolrPaths;
import org.apache.solr.metrics.AltBufferPoolMetricSet; import org.apache.solr.metrics.AltBufferPoolMetricSet;
import org.apache.solr.metrics.MetricsMap; import org.apache.solr.metrics.MetricsMap;
import org.apache.solr.metrics.OperatingSystemMetricSet; import org.apache.solr.metrics.OperatingSystemMetricSet;
@ -179,9 +179,9 @@ public class SolrDispatchFilter extends BaseSolrFilter {
extraProperties = new Properties(); extraProperties = new Properties();
String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE); String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE);
final Path solrHomePath = solrHome == null ? SolrResourceLoader.locateSolrHome() : Paths.get(solrHome); final Path solrHomePath = solrHome == null ? SolrPaths.locateSolrHome() : Paths.get(solrHome);
coresInit = createCoreContainer(solrHomePath, extraProperties); coresInit = createCoreContainer(solrHomePath, extraProperties);
SolrResourceLoader.ensureUserFilesDataDir(solrHomePath); SolrPaths.ensureUserFilesDataDir(solrHomePath);
this.httpClient = coresInit.getUpdateShardHandler().getDefaultHttpClient(); this.httpClient = coresInit.getUpdateShardHandler().getDefaultHttpClient();
setupJvmMetrics(coresInit); setupJvmMetrics(coresInit);
log.debug("user.dir=" + System.getProperty("user.dir")); log.debug("user.dir=" + System.getProperty("user.dir"));
@ -259,7 +259,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
*/ */
protected CoreContainer createCoreContainer(Path solrHome, Properties extraProperties) { protected CoreContainer createCoreContainer(Path solrHome, Properties extraProperties) {
NodeConfig nodeConfig = loadNodeConfig(solrHome, extraProperties); NodeConfig nodeConfig = loadNodeConfig(solrHome, extraProperties);
final CoreContainer coreContainer = new CoreContainer(nodeConfig, extraProperties, true); final CoreContainer coreContainer = new CoreContainer(nodeConfig, true);
coreContainer.load(); coreContainer.load();
return coreContainer; return coreContainer;
} }
@ -270,33 +270,28 @@ public class SolrDispatchFilter extends BaseSolrFilter {
* @return the NodeConfig * @return the NodeConfig
*/ */
public static NodeConfig loadNodeConfig(Path solrHome, Properties nodeProperties) { public static NodeConfig loadNodeConfig(Path solrHome, Properties nodeProperties) {
NodeConfig cfg = null; if (!StringUtils.isEmpty(System.getProperty("solr.solrxml.location"))) {
try (SolrResourceLoader loader = new SolrResourceLoader(solrHome, SolrDispatchFilter.class.getClassLoader(), nodeProperties)) { log.warn("Solr property solr.solrxml.location is no longer supported. " +
if (!StringUtils.isEmpty(System.getProperty("solr.solrxml.location"))) { "Will automatically load solr.xml from ZooKeeper if it exists");
log.warn("Solr property solr.solrxml.location is no longer supported. " +
"Will automatically load solr.xml from ZooKeeper if it exists");
}
String zkHost = System.getProperty("zkHost");
if (!StringUtils.isEmpty(zkHost)) {
int startUpZkTimeOut = Integer.getInteger("waitForZk", 30);
startUpZkTimeOut *= 1000;
try (SolrZkClient zkClient = new SolrZkClient(zkHost, startUpZkTimeOut)) {
if (zkClient.exists("/solr.xml", true)) {
log.info("solr.xml found in ZooKeeper. Loading...");
byte[] data = zkClient.getData("/solr.xml", null, null, true);
return SolrXmlConfig.fromInputStream(loader, new ByteArrayInputStream(data));
}
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Error occurred while loading solr.xml from zookeeper", e);
}
log.info("Loading solr.xml from SolrHome (not found in ZooKeeper)");
}
cfg = SolrXmlConfig.fromSolrHome(loader, loader.getInstancePath());
} catch (IOException e) {
// do nothing.
} }
return cfg;
String zkHost = System.getProperty("zkHost");
if (!StringUtils.isEmpty(zkHost)) {
int startUpZkTimeOut = Integer.getInteger("waitForZk", 30);
startUpZkTimeOut *= 1000;
try (SolrZkClient zkClient = new SolrZkClient(zkHost, startUpZkTimeOut)) {
if (zkClient.exists("/solr.xml", true)) {
log.info("solr.xml found in ZooKeeper. Loading...");
byte[] data = zkClient.getData("/solr.xml", null, null, true);
return SolrXmlConfig.fromInputStream(solrHome, new ByteArrayInputStream(data), nodeProperties);
}
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Error occurred while loading solr.xml from zookeeper", e);
}
log.info("Loading solr.xml from SolrHome (not found in ZooKeeper)");
}
return SolrXmlConfig.fromSolrHome(solrHome, nodeProperties);
} }
public CoreContainer getCores() { public CoreContainer getCores() {

View File

@ -17,8 +17,6 @@
package org.apache.solr.client.solrj.embedded; package org.apache.solr.client.solrj.embedded;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrClient;
@ -29,18 +27,15 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.Test; import org.junit.Test;
public class TestEmbeddedSolrServerAdminHandler extends SolrTestCaseJ4 { public class TestEmbeddedSolrServerAdminHandler extends SolrTestCaseJ4 {
@Test @Test
public void testPathIsAddedToContext() throws IOException, SolrServerException { public void testPathIsAddedToContext() throws IOException, SolrServerException {
final Path path = createTempDir();
final SolrResourceLoader loader = new SolrResourceLoader(path); final NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", TEST_PATH())
final NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader) .setConfigSetBaseDirectory(TEST_PATH().resolve("configsets").toString())
.setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString())
.build(); .build();
try (final EmbeddedSolrServer server = new EmbeddedSolrServer(config, "collection1")) { try (final EmbeddedSolrServer server = new EmbeddedSolrServer(config, "collection1")) {

View File

@ -25,7 +25,6 @@ import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.Test; import org.junit.Test;
public class TestEmbeddedSolrServerConstructors extends SolrTestCaseJ4 { public class TestEmbeddedSolrServerConstructors extends SolrTestCaseJ4 {
@ -42,8 +41,7 @@ public class TestEmbeddedSolrServerConstructors extends SolrTestCaseJ4 {
public void testNodeConfigConstructor() throws Exception { public void testNodeConfigConstructor() throws Exception {
Path path = createTempDir(); Path path = createTempDir();
SolrResourceLoader loader = new SolrResourceLoader(path); NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", path)
NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader)
.setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString()) .setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString())
.build(); .build();

View File

@ -361,7 +361,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT); UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT);
public MockCoreContainer() { public MockCoreContainer() {
super(SolrXmlConfig.fromString(null, "<solr/>")); super(SolrXmlConfig.fromString(TEST_PATH(), "<solr/>"));
this.shardHandlerFactory = new HttpShardHandlerFactory(); this.shardHandlerFactory = new HttpShardHandlerFactory();
this.coreAdminHandler = new CoreAdminHandler(); this.coreAdminHandler = new CoreAdminHandler();
} }

View File

@ -16,9 +16,9 @@
*/ */
package org.apache.solr.cloud.api.collections; package org.apache.solr.cloud.api.collections;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP; import javax.management.MBeanServer;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR; import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
@ -38,10 +38,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer; import com.google.common.collect.ImmutableList;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrQuery;
@ -81,7 +78,8 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList; import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
/** /**
* Tests the Cloud Collections API. * Tests the Cloud Collections API.
@ -503,7 +501,7 @@ public class CollectionsAPIDistributedZkTest extends SolrCloudTestCase {
Collection<SolrCore> theCores = cores.getCores(); Collection<SolrCore> theCores = cores.getCores();
for (SolrCore core : theCores) { for (SolrCore core : theCores) {
// look for core props file // look for core props file
Path instancedir = core.getResourceLoader().getInstancePath(); Path instancedir = core.getInstancePath();
assertTrue("Could not find expected core.properties file", Files.exists(instancedir.resolve("core.properties"))); assertTrue("Could not find expected core.properties file", Files.exists(instancedir.resolve("core.properties")));
Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve(core.getName()); Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve(core.getName());

View File

@ -121,6 +121,6 @@ public class DirectoryFactoryTest extends SolrTestCase {
private NodeConfig loadNodeConfig(String config) throws Exception { private NodeConfig loadNodeConfig(String config) throws Exception {
InputStream is = DirectoryFactoryTest.class.getResourceAsStream(config); InputStream is = DirectoryFactoryTest.class.getResourceAsStream(config);
return SolrXmlConfig.fromInputStream(loader, is); return SolrXmlConfig.fromInputStream(solrHome, is, new Properties());
} }
} }

View File

@ -23,6 +23,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -169,12 +170,13 @@ public class ResourceLoaderTest extends SolrTestCaseJ4 {
} }
SolrResourceLoader loader = new SolrResourceLoader(tmpRoot); SolrResourceLoader loader = new SolrResourceLoader(tmpRoot);
loader.addToClassLoader(SolrResourceLoader.getURLs(lib));
// ./lib is accessible by default // check "lib/aLibFile"
assertNotNull(loader.getClassLoader().getResource("aLibFile")); assertNotNull(loader.getClassLoader().getResource("aLibFile"));
// add inidividual jars from other paths // add inidividual jars from other paths
loader.addToClassLoader(otherLib.resolve("jar2.jar").toUri().toURL()); loader.addToClassLoader(Collections.singletonList(otherLib.resolve("jar2.jar").toUri().toURL()));
assertNotNull(loader.getClassLoader().getResource("explicitFile")); assertNotNull(loader.getClassLoader().getResource("explicitFile"));
assertNull(loader.getClassLoader().getResource("otherFile")); assertNull(loader.getClassLoader().getResource("otherFile"));

View File

@ -110,7 +110,7 @@ public class TestConfig extends SolrTestCaseJ4 {
@Test @Test
public void testCacheEnablingDisabling() throws Exception { public void testCacheEnablingDisabling() throws Exception {
// ensure if cache is not defined in the config then cache is disabled // ensure if cache is not defined in the config then cache is disabled
SolrConfig sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-defaults.xml", null, true); SolrConfig sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-defaults.xml");
assertNull(sc.filterCacheConfig); assertNull(sc.filterCacheConfig);
assertNull(sc.queryResultCacheConfig); assertNull(sc.queryResultCacheConfig);
assertNull(sc.documentCacheConfig); assertNull(sc.documentCacheConfig);
@ -119,7 +119,7 @@ public class TestConfig extends SolrTestCaseJ4 {
System.setProperty("filterCache.enabled", "true"); System.setProperty("filterCache.enabled", "true");
System.setProperty("queryResultCache.enabled", "true"); System.setProperty("queryResultCache.enabled", "true");
System.setProperty("documentCache.enabled", "true"); System.setProperty("documentCache.enabled", "true");
sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-cache-enable-disable.xml", null, true); sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-cache-enable-disable.xml");
assertNotNull(sc.filterCacheConfig); assertNotNull(sc.filterCacheConfig);
assertNotNull(sc.queryResultCacheConfig); assertNotNull(sc.queryResultCacheConfig);
assertNotNull(sc.documentCacheConfig); assertNotNull(sc.documentCacheConfig);
@ -128,7 +128,7 @@ public class TestConfig extends SolrTestCaseJ4 {
System.setProperty("filterCache.enabled", "false"); System.setProperty("filterCache.enabled", "false");
System.setProperty("queryResultCache.enabled", "false"); System.setProperty("queryResultCache.enabled", "false");
System.setProperty("documentCache.enabled", "false"); System.setProperty("documentCache.enabled", "false");
sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-cache-enable-disable.xml", null, true); sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-cache-enable-disable.xml");
assertNull(sc.filterCacheConfig); assertNull(sc.filterCacheConfig);
assertNull(sc.queryResultCacheConfig); assertNull(sc.queryResultCacheConfig);
assertNull(sc.documentCacheConfig); assertNull(sc.documentCacheConfig);
@ -146,7 +146,7 @@ public class TestConfig extends SolrTestCaseJ4 {
int numDefaultsTested = 0; int numDefaultsTested = 0;
int numNullDefaults = 0; int numNullDefaults = 0;
SolrConfig sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-defaults.xml", null, true); SolrConfig sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-defaults.xml");
SolrIndexConfig sic = sc.indexConfig; SolrIndexConfig sic = sc.indexConfig;
++numDefaultsTested; assertEquals("default useCompoundFile", false, sic.useCompoundFile); ++numDefaultsTested; assertEquals("default useCompoundFile", false, sic.useCompoundFile);
@ -210,7 +210,7 @@ public class TestConfig extends SolrTestCaseJ4 {
@Test @Test
public void testMaxSizeSettingWithoutAutoCommit() throws Exception { public void testMaxSizeSettingWithoutAutoCommit() throws Exception {
SolrConfig solrConfig = new SolrConfig(TEST_PATH().resolve("collection1"), "bad-solrconfig-no-autocommit-tag.xml", null, true); SolrConfig solrConfig = new SolrConfig(TEST_PATH().resolve("collection1"), "bad-solrconfig-no-autocommit-tag.xml");
Assert.assertEquals(-1, solrConfig.getUpdateHandlerInfo().autoCommitMaxSizeBytes); Assert.assertEquals(-1, solrConfig.getUpdateHandlerInfo().autoCommitMaxSizeBytes);
Assert.assertEquals(-1, solrConfig.getUpdateHandlerInfo().autoCommmitMaxDocs); Assert.assertEquals(-1, solrConfig.getUpdateHandlerInfo().autoCommmitMaxDocs);
Assert.assertEquals(-1, solrConfig.getUpdateHandlerInfo().autoCommmitMaxTime); Assert.assertEquals(-1, solrConfig.getUpdateHandlerInfo().autoCommmitMaxTime);
@ -219,7 +219,7 @@ public class TestConfig extends SolrTestCaseJ4 {
// sanity check that sys properties are working as expected // sanity check that sys properties are working as expected
public void testSanityCheckTestSysPropsAreUsed() throws Exception { public void testSanityCheckTestSysPropsAreUsed() throws Exception {
SolrConfig sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-basic.xml", null, true); SolrConfig sc = new SolrConfig(TEST_PATH().resolve("collection1"), "solrconfig-basic.xml");
SolrIndexConfig sic = sc.indexConfig; SolrIndexConfig sic = sc.indexConfig;
assertEquals("ramBufferSizeMB sysprop", assertEquals("ramBufferSizeMB sysprop",

View File

@ -47,8 +47,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
System.setProperty("configsets", configSetsBaseDir); System.setProperty("configsets", configSetsBaseDir);
SolrResourceLoader loader = new SolrResourceLoader(testDirectory); CoreContainer container = new CoreContainer(SolrXmlConfig.fromString(testDirectory, solrxml));
CoreContainer container = new CoreContainer(SolrXmlConfig.fromString(loader, solrxml));
container.load(); container.load();
return container; return container;
@ -56,17 +55,17 @@ public class TestConfigSets extends SolrTestCaseJ4 {
@Test @Test
public void testDefaultConfigSetBasePathResolution() throws IOException { public void testDefaultConfigSetBasePathResolution() throws IOException {
try (SolrResourceLoader loader = new SolrResourceLoader(Paths.get("/path/to/solr/home"))) { Path solrHome = Paths.get("/path/to/solr/home");
NodeConfig config NodeConfig config
= SolrXmlConfig.fromString(loader, "<solr><str name=\"configSetBaseDir\">configsets</str></solr>"); = SolrXmlConfig.fromString(solrHome, "<solr><str name=\"configSetBaseDir\">configsets</str></solr>");
assertThat(config.getConfigSetBaseDirectory().toAbsolutePath(), assertThat(config.getConfigSetBaseDirectory().toAbsolutePath(),
is(Paths.get("/path/to/solr/home/configsets").toAbsolutePath())); is(Paths.get("/path/to/solr/home/configsets").toAbsolutePath()));
NodeConfig absConfig
= SolrXmlConfig.fromString(solrHome, "<solr><str name=\"configSetBaseDir\">/path/to/configsets</str></solr>");
assertThat(absConfig.getConfigSetBaseDirectory().toAbsolutePath(), is(Paths.get("/path/to/configsets").toAbsolutePath()));
NodeConfig absConfig
= SolrXmlConfig.fromString(loader, "<solr><str name=\"configSetBaseDir\">/path/to/configsets</str></solr>");
assertThat(absConfig.getConfigSetBaseDirectory().toAbsolutePath(), is(Paths.get("/path/to/configsets").toAbsolutePath()));
}
} }
@Test @Test
@ -74,11 +73,11 @@ public class TestConfigSets extends SolrTestCaseJ4 {
CoreContainer container = null; CoreContainer container = null;
try { try {
container = setupContainer(TEST_PATH().resolve("configsets").toString()); container = setupContainer(TEST_PATH().resolve("configsets").toString());
Path testDirectory = container.getResourceLoader().getInstancePath(); Path solrHome = Paths.get(container.getSolrHome());
SolrCore core1 = container.create("core1", ImmutableMap.of("configSet", "configset-2")); SolrCore core1 = container.create("core1", ImmutableMap.of("configSet", "configset-2"));
assertThat(core1.getCoreDescriptor().getName(), is("core1")); assertThat(core1.getCoreDescriptor().getName(), is("core1"));
assertThat(Paths.get(core1.getDataDir()).toString(), is(testDirectory.resolve("core1").resolve("data").toString())); assertThat(Paths.get(core1.getDataDir()).toString(), is(solrHome.resolve("core1").resolve("data").toString()));
} }
finally { finally {
if (container != null) if (container != null)
@ -90,8 +89,6 @@ public class TestConfigSets extends SolrTestCaseJ4 {
public void testNonExistentConfigSetThrowsException() { public void testNonExistentConfigSetThrowsException() {
final CoreContainer container = setupContainer(getFile("solr/configsets").getAbsolutePath()); final CoreContainer container = setupContainer(getFile("solr/configsets").getAbsolutePath());
try { try {
Path testDirectory = container.getResourceLoader().getInstancePath();
Exception thrown = expectThrows(Exception.class, "Expected core creation to fail", () -> { Exception thrown = expectThrows(Exception.class, "Expected core creation to fail", () -> {
container.create("core1", ImmutableMap.of("configSet", "nonexistent")); container.create("core1", ImmutableMap.of("configSet", "nonexistent"));
}); });
@ -113,8 +110,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
String csd = configSetsDir.getAbsolutePath(); String csd = configSetsDir.getAbsolutePath();
System.setProperty("configsets", csd); System.setProperty("configsets", csd);
SolrResourceLoader loader = new SolrResourceLoader(testDirectory); CoreContainer container = new CoreContainer(SolrXmlConfig.fromString(testDirectory, solrxml));
CoreContainer container = new CoreContainer(SolrXmlConfig.fromString(loader, solrxml));
container.load(); container.load();
// We initially don't have a /dump handler defined // We initially don't have a /dump handler defined

View File

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -76,8 +75,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
} }
private CoreContainer init(Path homeDirectory, String xml) throws Exception { private CoreContainer init(Path homeDirectory, String xml) throws Exception {
SolrResourceLoader loader = new SolrResourceLoader(homeDirectory); CoreContainer ret = new CoreContainer(SolrXmlConfig.fromString(homeDirectory, xml));
CoreContainer ret = new CoreContainer(SolrXmlConfig.fromString(loader, xml));
ret.load(); ret.load();
return ret; return ret;
} }
@ -199,12 +197,11 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
MockCoresLocator cl = new MockCoresLocator(); MockCoresLocator cl = new MockCoresLocator();
SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir()); Path solrHome = createTempDir();
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath()); System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
final CoreContainer cc = new CoreContainer(SolrXmlConfig.fromString(resourceLoader, CONFIGSETS_SOLR_XML), new Properties(), cl); final CoreContainer cc = new CoreContainer(SolrXmlConfig.fromString(solrHome, CONFIGSETS_SOLR_XML), cl);
Path corePath = resourceLoader.getInstancePath().resolve("badcore"); Path corePath = solrHome.resolve("badcore");
CoreDescriptor badcore = new CoreDescriptor("badcore", corePath, cc, CoreDescriptor badcore = new CoreDescriptor("badcore", corePath, cc,
"configSet", "nosuchconfigset"); "configSet", "nosuchconfigset");
@ -471,14 +468,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
// init the CoreContainer with the mix of ok/bad cores // init the CoreContainer with the mix of ok/bad cores
MockCoresLocator cl = new MockCoresLocator(); MockCoresLocator cl = new MockCoresLocator();
SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir()); Path solrHome = createTempDir();
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath()); System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
final CoreContainer cc = new CoreContainer(SolrXmlConfig.fromString(resourceLoader, CONFIGSETS_SOLR_XML), new Properties(), cl); final CoreContainer cc = new CoreContainer(SolrXmlConfig.fromString(solrHome, CONFIGSETS_SOLR_XML), cl);
cl.add(new CoreDescriptor("col_ok", resourceLoader.getInstancePath().resolve("col_ok"), cc, cl.add(new CoreDescriptor("col_ok", solrHome.resolve("col_ok"), cc,
"configSet", "minimal")); "configSet", "minimal"));
cl.add(new CoreDescriptor("col_bad", resourceLoader.getInstancePath().resolve("col_bad"), cc, cl.add(new CoreDescriptor("col_bad", solrHome.resolve("col_bad"), cc,
"configSet", "bad-mergepolicy")); "configSet", "bad-mergepolicy"));
cc.load(); cc.load();

View File

@ -114,7 +114,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
} }
private CoreContainer init() throws Exception { private CoreContainer init() throws Exception {
final CoreContainer container = new CoreContainer(); final CoreContainer container = new CoreContainer(SolrPaths.locateSolrHome(), new Properties());
try { try {
container.load(); container.load();
} catch (Exception e) { } catch (Exception e) {
@ -298,7 +298,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
addCoreWithProps("coreT6", makeCoreProperties("coreT6", true, true, "dataDir=coreT6")); addCoreWithProps("coreT6", makeCoreProperties("coreT6", true, true, "dataDir=coreT6"));
// Do this specially since we need to search. // Do this specially since we need to search.
final CoreContainer cc = new CoreContainer(solrHomeDirectory.toString()); final CoreContainer cc = new CoreContainer(solrHomeDirectory, new Properties());
try { try {
cc.load(); cc.load();
// Just check that the proper number of cores are loaded since making the test depend on order would be fragile // Just check that the proper number of cores are loaded since making the test depend on order would be fragile
@ -547,13 +547,10 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
@Test @Test
public void testRootDirectoryResolution() { public void testRootDirectoryResolution() {
NodeConfig config = SolrXmlConfig.fromString(solrHomeDirectory, "<solr><str name=\"coreRootDirectory\">relative</str></solr>");
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory);
NodeConfig config = SolrXmlConfig.fromString(loader, "<solr><str name=\"coreRootDirectory\">relative</str></solr>");
assertThat(config.getCoreRootDirectory().toString(), containsString(solrHomeDirectory.toAbsolutePath().toString())); assertThat(config.getCoreRootDirectory().toString(), containsString(solrHomeDirectory.toAbsolutePath().toString()));
NodeConfig absConfig = SolrXmlConfig.fromString(loader, "<solr><str name=\"coreRootDirectory\">/absolute</str></solr>"); NodeConfig absConfig = SolrXmlConfig.fromString(solrHomeDirectory, "<solr><str name=\"coreRootDirectory\">/absolute</str></solr>");
assertThat(absConfig.getCoreRootDirectory().toString(), not(containsString(solrHomeDirectory.toAbsolutePath().toString()))); assertThat(absConfig.getCoreRootDirectory().toString(), not(containsString(solrHomeDirectory.toAbsolutePath().toString())));
} }

View File

@ -615,8 +615,7 @@ public class TestLazyCores extends SolrTestCaseJ4 {
writeCustomConfig(coreName, min_config, bad_schema, rand_snip); writeCustomConfig(coreName, min_config, bad_schema, rand_snip);
} }
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.toPath()); NodeConfig config = SolrXmlConfig.fromString(solrHomeDirectory.toPath(), "<solr/>");
NodeConfig config = SolrXmlConfig.fromString(loader, "<solr/>");
// OK this should succeed, but at the end we should have recorded a series of errors. // OK this should succeed, but at the end we should have recorded a series of errors.
return createCoreContainer(config, new CorePropertiesLocator(config.getCoreRootDirectory())); return createCoreContainer(config, new CorePropertiesLocator(config.getCoreRootDirectory()));

View File

@ -18,16 +18,17 @@ package org.apache.solr.core;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale; import java.util.Locale;
import java.util.Properties;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.update.UpdateShardHandlerConfig; import org.apache.solr.update.UpdateShardHandlerConfig;
import org.junit.AfterClass; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
@ -44,27 +45,18 @@ public class TestSolrXml extends SolrTestCaseJ4 {
public ExpectedException expectedException = ExpectedException.none(); public ExpectedException expectedException = ExpectedException.none();
// tmp dir, cleaned up automatically. // tmp dir, cleaned up automatically.
private static File solrHome = null; private Path solrHome;
private static SolrResourceLoader loader = null;
@BeforeClass @Before
public static void setupLoader() throws Exception { public void doBefore() {
solrHome = createTempDir().toFile(); solrHome = createTempDir();
loader = new SolrResourceLoader(solrHome.toPath());
}
@AfterClass
public static void cleanupLoader() throws Exception {
solrHome = null;
loader = null;
} }
public void testAllInfoPresent() throws IOException { public void testAllInfoPresent() throws IOException {
Path testSrcRoot = TEST_PATH();
Files.copy(testSrcRoot.resolve("solr-50-all.xml"), solrHome.resolve("solr.xml"));
File testSrcRoot = new File(SolrTestCaseJ4.TEST_HOME()); NodeConfig cfg = SolrXmlConfig.fromSolrHome(solrHome, new Properties());
FileUtils.copyFile(new File(testSrcRoot, "solr-50-all.xml"), new File(solrHome, "solr.xml"));
NodeConfig cfg = SolrXmlConfig.fromSolrHome(loader, solrHome.toPath());
CloudConfig ccfg = cfg.getCloudConfig(); CloudConfig ccfg = cfg.getCloudConfig();
UpdateShardHandlerConfig ucfg = cfg.getUpdateShardHandlerConfig(); UpdateShardHandlerConfig ucfg = cfg.getUpdateShardHandlerConfig();
PluginInfo[] backupRepoConfigs = cfg.getBackupRepositoryPlugins(); PluginInfo[] backupRepoConfigs = cfg.getBackupRepositoryPlugins();
@ -117,16 +109,16 @@ public class TestSolrXml extends SolrTestCaseJ4 {
System.setProperty("socketTimeout", "220"); System.setProperty("socketTimeout", "220");
System.setProperty("connTimeout", "200"); System.setProperty("connTimeout", "200");
File testSrcRoot = new File(SolrTestCaseJ4.TEST_HOME()); Path testSrcRoot = TEST_PATH();
FileUtils.copyFile(new File(testSrcRoot, "solr-50-all.xml"), new File(solrHome, "solr.xml")); Files.copy(testSrcRoot.resolve("solr-50-all.xml"), solrHome.resolve("solr.xml"));
NodeConfig cfg = SolrXmlConfig.fromSolrHome(loader, solrHome.toPath()); NodeConfig cfg = SolrXmlConfig.fromSolrHome(solrHome, new Properties());
assertThat(cfg.getCoreRootDirectory().toString(), containsString("myCoreRoot")); assertThat(cfg.getCoreRootDirectory().toString(), containsString("myCoreRoot"));
assertEquals("solr host port", 8888, cfg.getCloudConfig().getSolrHostPort()); assertEquals("solr host port", 8888, cfg.getCloudConfig().getSolrHostPort());
assertEquals("schema cache", false, cfg.hasSchemaCache()); assertEquals("schema cache", false, cfg.hasSchemaCache());
} }
public void testExplicitNullGivesDefaults() throws IOException { public void testExplicitNullGivesDefaults() {
String solrXml = "<solr>" + String solrXml = "<solr>" +
"<null name=\"maxBooleanClauses\"/>" + "<null name=\"maxBooleanClauses\"/>" +
"<solrcloud>" + "<solrcloud>" +
@ -136,48 +128,48 @@ public class TestSolrXml extends SolrTestCaseJ4 {
"<null name=\"leaderVoteWait\"/>" + "<null name=\"leaderVoteWait\"/>" +
"</solrcloud></solr>"; "</solrcloud></solr>";
NodeConfig cfg = SolrXmlConfig.fromString(loader, solrXml); NodeConfig cfg = SolrXmlConfig.fromString(solrHome, solrXml);
assertNull("maxBooleanClauses", cfg.getBooleanQueryMaxClauseCount()); // default is null assertNull("maxBooleanClauses", cfg.getBooleanQueryMaxClauseCount()); // default is null
assertEquals("leaderVoteWait", 180000, cfg.getCloudConfig().getLeaderVoteWait()); assertEquals("leaderVoteWait", 180000, cfg.getCloudConfig().getLeaderVoteWait());
} }
public void testIntAsLongBad() throws IOException { public void testIntAsLongBad() {
String bad = ""+TestUtil.nextLong(random(), Integer.MAX_VALUE, Long.MAX_VALUE); String bad = ""+TestUtil.nextLong(random(), Integer.MAX_VALUE, Long.MAX_VALUE);
String solrXml = "<solr><long name=\"transientCacheSize\">"+bad+"</long></solr>"; String solrXml = "<solr><long name=\"transientCacheSize\">"+bad+"</long></solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("transientCacheSize"); expectedException.expectMessage("transientCacheSize");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testIntAsLongOk() throws IOException { public void testIntAsLongOk() {
int ok = random().nextInt(); int ok = random().nextInt();
String solrXml = "<solr><long name=\"transientCacheSize\">"+ok+"</long></solr>"; String solrXml = "<solr><long name=\"transientCacheSize\">"+ok+"</long></solr>";
NodeConfig cfg = SolrXmlConfig.fromString(loader, solrXml); NodeConfig cfg = SolrXmlConfig.fromString(solrHome, solrXml);
assertEquals(ok, cfg.getTransientCacheSize()); assertEquals(ok, cfg.getTransientCacheSize());
} }
public void testMultiCloudSectionError() throws IOException { public void testMultiCloudSectionError() {
String solrXml = "<solr>" String solrXml = "<solr>"
+ "<solrcloud><bool name=\"genericCoreNodeNames\">true</bool></solrcloud>" + "<solrcloud><bool name=\"genericCoreNodeNames\">true</bool></solrcloud>"
+ "<solrcloud><bool name=\"genericCoreNodeNames\">false</bool></solrcloud>" + "<solrcloud><bool name=\"genericCoreNodeNames\">false</bool></solrcloud>"
+ "</solr>"; + "</solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Multiple instances of solrcloud section found in solr.xml"); expectedException.expectMessage("Multiple instances of solrcloud section found in solr.xml");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testMultiLoggingSectionError() throws IOException { public void testMultiLoggingSectionError() {
String solrXml = "<solr>" String solrXml = "<solr>"
+ "<logging><str name=\"class\">foo</str></logging>" + "<logging><str name=\"class\">foo</str></logging>"
+ "<logging><str name=\"class\">foo</str></logging>" + "<logging><str name=\"class\">foo</str></logging>"
+ "</solr>"; + "</solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Multiple instances of logging section found in solr.xml"); expectedException.expectMessage("Multiple instances of logging section found in solr.xml");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testMultiLoggingWatcherSectionError() throws IOException { public void testMultiLoggingWatcherSectionError() {
String solrXml = "<solr><logging>" String solrXml = "<solr><logging>"
+ "<watcher><int name=\"threshold\">42</int></watcher>" + "<watcher><int name=\"threshold\">42</int></watcher>"
+ "<watcher><int name=\"threshold\">42</int></watcher>" + "<watcher><int name=\"threshold\">42</int></watcher>"
@ -186,42 +178,42 @@ public class TestSolrXml extends SolrTestCaseJ4 {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Multiple instances of logging/watcher section found in solr.xml"); expectedException.expectMessage("Multiple instances of logging/watcher section found in solr.xml");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testValidStringValueWhenBoolTypeIsExpected() throws IOException { public void testValidStringValueWhenBoolTypeIsExpected() {
boolean schemaCache = random().nextBoolean(); boolean schemaCache = random().nextBoolean();
String solrXml = String.format(Locale.ROOT, "<solr><str name=\"shareSchema\">%s</str></solr>", schemaCache); String solrXml = String.format(Locale.ROOT, "<solr><str name=\"shareSchema\">%s</str></solr>", schemaCache);
NodeConfig nodeConfig = SolrXmlConfig.fromString(loader, solrXml); NodeConfig nodeConfig = SolrXmlConfig.fromString(solrHome, solrXml);
assertEquals("gen core node names", schemaCache, nodeConfig.hasSchemaCache()); assertEquals("gen core node names", schemaCache, nodeConfig.hasSchemaCache());
} }
public void testValidStringValueWhenIntTypeIsExpected() throws IOException { public void testValidStringValueWhenIntTypeIsExpected() {
int maxUpdateConnections = random().nextInt(); int maxUpdateConnections = random().nextInt();
String solrXml = String.format(Locale.ROOT, "<solr><updateshardhandler><str name=\"maxUpdateConnections\">%d</str></updateshardhandler></solr>", maxUpdateConnections); String solrXml = String.format(Locale.ROOT, "<solr><updateshardhandler><str name=\"maxUpdateConnections\">%d</str></updateshardhandler></solr>", maxUpdateConnections);
NodeConfig nodeConfig = SolrXmlConfig.fromString(loader, solrXml); NodeConfig nodeConfig = SolrXmlConfig.fromString(solrHome, solrXml);
assertEquals("max update conn", maxUpdateConnections, nodeConfig.getUpdateShardHandlerConfig().getMaxUpdateConnections()); assertEquals("max update conn", maxUpdateConnections, nodeConfig.getUpdateShardHandlerConfig().getMaxUpdateConnections());
} }
public void testFailAtConfigParseTimeWhenIntTypeIsExpectedAndLongTypeIsGiven() throws IOException { public void testFailAtConfigParseTimeWhenIntTypeIsExpectedAndLongTypeIsGiven() {
long val = TestUtil.nextLong(random(), Integer.MAX_VALUE, Long.MAX_VALUE); long val = TestUtil.nextLong(random(), Integer.MAX_VALUE, Long.MAX_VALUE);
String solrXml = String.format(Locale.ROOT, "<solr><solrcloud><long name=\"maxUpdateConnections\">%d</long></solrcloud></solr>", val); String solrXml = String.format(Locale.ROOT, "<solr><solrcloud><long name=\"maxUpdateConnections\">%d</long></solrcloud></solr>", val);
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Error parsing 'maxUpdateConnections'"); expectedException.expectMessage("Error parsing 'maxUpdateConnections'");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenBoolTypeIsExpectedAndValueIsInvalidString() throws IOException { public void testFailAtConfigParseTimeWhenBoolTypeIsExpectedAndValueIsInvalidString() {
String solrXml = "<solr><solrcloud><bool name=\"genericCoreNodeNames\">NOT_A_BOOLEAN</bool></solrcloud></solr>"; String solrXml = "<solr><solrcloud><bool name=\"genericCoreNodeNames\">NOT_A_BOOLEAN</bool></solrcloud></solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("invalid boolean value: NOT_A_BOOLEAN"); expectedException.expectMessage("invalid boolean value: NOT_A_BOOLEAN");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenIntTypeIsExpectedAndBoolTypeIsGiven() throws IOException { public void testFailAtConfigParseTimeWhenIntTypeIsExpectedAndBoolTypeIsGiven() {
// given: // given:
boolean randomBoolean = random().nextBoolean(); boolean randomBoolean = random().nextBoolean();
String solrXml = String.format(Locale.ROOT, "<solr><logging><int name=\"unknown-option\">%s</int></logging></solr>", randomBoolean); String solrXml = String.format(Locale.ROOT, "<solr><logging><int name=\"unknown-option\">%s</int></logging></solr>", randomBoolean);
@ -229,37 +221,37 @@ public class TestSolrXml extends SolrTestCaseJ4 {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage(String.format(Locale.ROOT, "Value of 'unknown-option' can not be parsed as 'int': \"%s\"", randomBoolean)); expectedException.expectMessage(String.format(Locale.ROOT, "Value of 'unknown-option' can not be parsed as 'int': \"%s\"", randomBoolean));
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenUnrecognizedSolrCloudOptionWasFound() throws IOException { public void testFailAtConfigParseTimeWhenUnrecognizedSolrCloudOptionWasFound() {
String solrXml = "<solr><solrcloud><str name=\"host\">host</str><int name=\"hostPort\">8983</int><str name=\"hostContext\"></str><bool name=\"unknown-option\">true</bool></solrcloud></solr>"; String solrXml = "<solr><solrcloud><str name=\"host\">host</str><int name=\"hostPort\">8983</int><str name=\"hostContext\"></str><bool name=\"unknown-option\">true</bool></solrcloud></solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Unknown configuration parameter in <solrcloud> section of solr.xml: unknown-option"); expectedException.expectMessage("Unknown configuration parameter in <solrcloud> section of solr.xml: unknown-option");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenUnrecognizedSolrOptionWasFound() throws IOException { public void testFailAtConfigParseTimeWhenUnrecognizedSolrOptionWasFound() {
String solrXml = "<solr><bool name=\"unknown-bool-option\">true</bool><str name=\"unknown-str-option\">true</str></solr>"; String solrXml = "<solr><bool name=\"unknown-bool-option\">true</bool><str name=\"unknown-str-option\">true</str></solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Unknown configuration value in solr.xml: unknown-bool-option"); expectedException.expectMessage("Unknown configuration value in solr.xml: unknown-bool-option");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenUnrecognizedLoggingOptionWasFound() throws IOException { public void testFailAtConfigParseTimeWhenUnrecognizedLoggingOptionWasFound() {
String solrXml = String.format(Locale.ROOT, "<solr><logging><bool name=\"unknown-option\">%s</bool></logging></solr>", random().nextBoolean()); String solrXml = String.format(Locale.ROOT, "<solr><logging><bool name=\"unknown-option\">%s</bool></logging></solr>", random().nextBoolean());
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Unknown value in logwatcher config: unknown-option"); expectedException.expectMessage("Unknown value in logwatcher config: unknown-option");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenLoggingConfigParamsAreDuplicated() throws IOException { public void testFailAtConfigParseTimeWhenLoggingConfigParamsAreDuplicated() {
String v1 = ""+random().nextInt(); String v1 = ""+random().nextInt();
String v2 = ""+random().nextInt(); String v2 = ""+random().nextInt();
String solrXml = String.format(Locale.ROOT, String solrXml = String.format(Locale.ROOT,
@ -272,10 +264,10 @@ public class TestSolrXml extends SolrTestCaseJ4 {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("<logging> section of solr.xml contains duplicated 'class'"); expectedException.expectMessage("<logging> section of solr.xml contains duplicated 'class'");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testFailAtConfigParseTimeWhenSolrCloudConfigParamsAreDuplicated() throws IOException { public void testFailAtConfigParseTimeWhenSolrCloudConfigParamsAreDuplicated() {
String v1 = ""+random().nextInt(); String v1 = ""+random().nextInt();
String v2 = ""+random().nextInt(); String v2 = ""+random().nextInt();
String v3 = ""+random().nextInt(); String v3 = ""+random().nextInt();
@ -291,11 +283,11 @@ public class TestSolrXml extends SolrTestCaseJ4 {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("<solrcloud> section of solr.xml contains duplicated 'zkClientTimeout'"); expectedException.expectMessage("<solrcloud> section of solr.xml contains duplicated 'zkClientTimeout'");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
@Ignore @Ignore
public void testFailAtConfigParseTimeWhenSolrConfigParamsAreDuplicated() throws IOException { public void testFailAtConfigParseTimeWhenSolrConfigParamsAreDuplicated() {
String v1 = ""+random().nextInt(); String v1 = ""+random().nextInt();
String v2 = ""+random().nextInt(); String v2 = ""+random().nextInt();
String solrXml = String.format(Locale.ROOT, String solrXml = String.format(Locale.ROOT,
@ -308,34 +300,34 @@ public class TestSolrXml extends SolrTestCaseJ4 {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Main section of solr.xml contains duplicated 'coreLoadThreads'"); expectedException.expectMessage("Main section of solr.xml contains duplicated 'coreLoadThreads'");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
public void testCloudConfigRequiresHost() throws Exception { public void testCloudConfigRequiresHost() {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("solrcloud section missing required entry 'host'"); expectedException.expectMessage("solrcloud section missing required entry 'host'");
SolrXmlConfig.fromString(loader, "<solr><solrcloud></solrcloud></solr>"); SolrXmlConfig.fromString(solrHome, "<solr><solrcloud></solrcloud></solr>");
} }
public void testCloudConfigRequiresHostPort() throws Exception { public void testCloudConfigRequiresHostPort() {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("solrcloud section missing required entry 'hostPort'"); expectedException.expectMessage("solrcloud section missing required entry 'hostPort'");
SolrXmlConfig.fromString(loader, "<solr><solrcloud><str name=\"host\">host</str></solrcloud></solr>"); SolrXmlConfig.fromString(solrHome, "<solr><solrcloud><str name=\"host\">host</str></solrcloud></solr>");
} }
public void testCloudConfigRequiresHostContext() throws Exception { public void testCloudConfigRequiresHostContext() {
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("solrcloud section missing required entry 'hostContext'"); expectedException.expectMessage("solrcloud section missing required entry 'hostContext'");
SolrXmlConfig.fromString(loader, "<solr><solrcloud><str name=\"host\">host</str><int name=\"hostPort\">8983</int></solrcloud></solr>"); SolrXmlConfig.fromString(solrHome, "<solr><solrcloud><str name=\"host\">host</str><int name=\"hostPort\">8983</int></solrcloud></solr>");
} }
public void testMultiBackupSectionError() throws IOException { public void testMultiBackupSectionError() {
String solrXml = "<solr><backup></backup><backup></backup></solr>"; String solrXml = "<solr><backup></backup><backup></backup></solr>";
expectedException.expect(SolrException.class); expectedException.expect(SolrException.class);
expectedException.expectMessage("Multiple instances of backup section found in solr.xml"); expectedException.expectMessage("Multiple instances of backup section found in solr.xml");
SolrXmlConfig.fromString(loader, solrXml); // return not used, only for validation SolrXmlConfig.fromString(solrHome, solrXml); // return not used, only for validation
} }
} }

View File

@ -20,6 +20,7 @@ package org.apache.solr.filestore;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -252,7 +253,7 @@ public class TestDistribPackageStore extends SolrCloudTestCase {
public static void uploadKey(byte[] bytes, String path, MiniSolrCloudCluster cluster) throws Exception { public static void uploadKey(byte[] bytes, String path, MiniSolrCloudCluster cluster) throws Exception {
JettySolrRunner jetty = cluster.getRandomJetty(random()); JettySolrRunner jetty = cluster.getRandomJetty(random());
try(HttpSolrClient client = (HttpSolrClient) jetty.newClient()) { try(HttpSolrClient client = (HttpSolrClient) jetty.newClient()) {
PackageUtils.uploadKey(bytes, path, jetty.getCoreContainer().getResourceLoader().getInstancePath(), client); PackageUtils.uploadKey(bytes, path, Paths.get(jetty.getCoreContainer().getSolrHome()), client);
Object resp = Utils.executeGET(client.getHttpClient(), jetty.getBaseURLV2().toString() + "/node/files" + path + "?sync=true", null); Object resp = Utils.executeGET(client.getHttpClient(), jetty.getBaseURLV2().toString() + "/node/files" + path + "?sync=true", null);
System.out.println("sync resp: "+jetty.getBaseURLV2().toString() + "/node/files" + path + "?sync=true"+" ,is: "+resp); System.out.println("sync resp: "+jetty.getBaseURLV2().toString() + "/node/files" + path + "?sync=true"+" ,is: "+resp);
} }

View File

@ -26,7 +26,6 @@ import com.codahale.metrics.Metric;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrJettyTestBase; import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -118,18 +117,17 @@ public class JvmMetricsTest extends SolrJettyTestBase {
@Test @Test
public void testHiddenSysProps() throws Exception { public void testHiddenSysProps() throws Exception {
Path home = Paths.get(TEST_HOME()); Path home = Paths.get(TEST_HOME());
SolrResourceLoader loader = new SolrResourceLoader(home);
// default config // default config
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr.xml").toFile(), "UTF-8"); String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr.xml").toFile(), "UTF-8");
NodeConfig config = SolrXmlConfig.fromString(loader, solrXml); NodeConfig config = SolrXmlConfig.fromString(home, solrXml);
NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS.forEach(s -> { NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS.forEach(s -> {
assertTrue(s, config.getMetricsConfig().getHiddenSysProps().contains(s)); assertTrue(s, config.getMetricsConfig().getHiddenSysProps().contains(s));
}); });
// custom config // custom config
solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-hiddensysprops.xml").toFile(), "UTF-8"); solrXml = FileUtils.readFileToString(home.resolve("solr-hiddensysprops.xml").toFile(), "UTF-8");
NodeConfig config2 = SolrXmlConfig.fromString(loader, solrXml); NodeConfig config2 = SolrXmlConfig.fromString(home, solrXml);
Arrays.asList("foo", "bar", "baz").forEach(s -> { Arrays.asList("foo", "bar", "baz").forEach(s -> {
assertTrue(s, config2.getMetricsConfig().getHiddenSysProps().contains(s)); assertTrue(s, config2.getMetricsConfig().getHiddenSysProps().contains(s));
}); });

View File

@ -18,6 +18,7 @@ package org.apache.solr.metrics;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import com.codahale.metrics.Clock; import com.codahale.metrics.Clock;
@ -27,7 +28,6 @@ import com.codahale.metrics.SlidingTimeWindowReservoir;
import com.codahale.metrics.UniformReservoir; import com.codahale.metrics.UniformReservoir;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -45,24 +45,21 @@ public class MetricsConfigTest extends SolrTestCaseJ4 {
// tmp dir, cleaned up automatically. // tmp dir, cleaned up automatically.
private static File solrHome = null; private static File solrHome = null;
private static SolrResourceLoader loader = null;
@BeforeClass @BeforeClass
public static void setupLoader() throws Exception { public static void setupLoader() throws Exception {
solrHome = createTempDir().toFile(); solrHome = createTempDir().toFile();
loader = new SolrResourceLoader(solrHome.toPath());
} }
@AfterClass @AfterClass
public static void cleanupLoader() throws Exception { public static void cleanupLoader() throws Exception {
solrHome = null; solrHome = null;
loader = null;
} }
@Test @Test
public void testDefaults() throws Exception { public void testDefaults() throws Exception {
NodeConfig cfg = loadNodeConfig(); NodeConfig cfg = loadNodeConfig();
SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig()); SolrMetricManager mgr = new SolrMetricManager(cfg.getSolrResourceLoader(), cfg.getMetricsConfig());
assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier); assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier); assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier); assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
@ -80,7 +77,7 @@ public class MetricsConfigTest extends SolrTestCaseJ4 {
System.setProperty("histogram.window", "600"); System.setProperty("histogram.window", "600");
System.setProperty("histogram.reservoir", SlidingTimeWindowReservoir.class.getName()); System.setProperty("histogram.reservoir", SlidingTimeWindowReservoir.class.getName());
NodeConfig cfg = loadNodeConfig(); NodeConfig cfg = loadNodeConfig();
SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig()); SolrMetricManager mgr = new SolrMetricManager(cfg.getSolrResourceLoader(), cfg.getMetricsConfig());
assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier); assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier); assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier); assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
@ -98,7 +95,7 @@ public class MetricsConfigTest extends SolrTestCaseJ4 {
System.setProperty("timer.class", MockTimerSupplier.class.getName()); System.setProperty("timer.class", MockTimerSupplier.class.getName());
System.setProperty("histogram.class", MockHistogramSupplier.class.getName()); System.setProperty("histogram.class", MockHistogramSupplier.class.getName());
NodeConfig cfg = loadNodeConfig(); NodeConfig cfg = loadNodeConfig();
SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig()); SolrMetricManager mgr = new SolrMetricManager(cfg.getSolrResourceLoader(), cfg.getMetricsConfig());
assertTrue(mgr.getCounterSupplier() instanceof MockCounterSupplier); assertTrue(mgr.getCounterSupplier() instanceof MockCounterSupplier);
assertTrue(mgr.getMeterSupplier() instanceof MockMeterSupplier); assertTrue(mgr.getMeterSupplier() instanceof MockMeterSupplier);
assertTrue(mgr.getTimerSupplier() instanceof MockTimerSupplier); assertTrue(mgr.getTimerSupplier() instanceof MockTimerSupplier);
@ -121,6 +118,6 @@ public class MetricsConfigTest extends SolrTestCaseJ4 {
private NodeConfig loadNodeConfig() throws Exception { private NodeConfig loadNodeConfig() throws Exception {
InputStream is = MetricsConfigTest.class.getResourceAsStream("/solr/solr-metricsconfig.xml"); InputStream is = MetricsConfigTest.class.getResourceAsStream("/solr/solr-metricsconfig.xml");
return SolrXmlConfig.fromInputStream(loader, is); return SolrXmlConfig.fromInputStream(TEST_PATH(), is, new Properties()); //TODO pass in props
} }
} }

View File

@ -34,7 +34,6 @@ import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.PluginInfo; import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrInfoBean; import org.apache.solr.core.SolrInfoBean;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.metrics.reporters.MockMetricReporter; import org.apache.solr.metrics.reporters.MockMetricReporter;
import org.apache.solr.util.JmxUtil; import org.apache.solr.util.JmxUtil;
@ -73,7 +72,7 @@ public class SolrMetricsIntegrationTest extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop1", "propone"); System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo"); System.setProperty("solr.test.sys.prop2", "proptwo");
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-metricreporter.xml").toFile(), "UTF-8"); String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-metricreporter.xml").toFile(), "UTF-8");
NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml); NodeConfig cfg = SolrXmlConfig.fromString(home, solrXml);
cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator
(DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(), (DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(),
"solrconfig.xml", "schema.xml")); "solrconfig.xml", "schema.xml"));
@ -181,7 +180,7 @@ public class SolrMetricsIntegrationTest extends SolrTestCaseJ4 {
assertTrue(metrics.containsKey("CONTAINER.version.specification")); assertTrue(metrics.containsKey("CONTAINER.version.specification"));
assertTrue(metrics.containsKey("CONTAINER.version.implementation")); assertTrue(metrics.containsKey("CONTAINER.version.implementation"));
Gauge<?> g = (Gauge<?>)metrics.get("CONTAINER.fs.path"); Gauge<?> g = (Gauge<?>)metrics.get("CONTAINER.fs.path");
assertEquals(g.getValue(), cc.getResourceLoader().getInstancePath().toAbsolutePath().toString()); assertEquals(g.getValue(), cc.getSolrHome());
boolean spins = IOUtils.spins(cc.getCoreRootDirectory()); boolean spins = IOUtils.spins(cc.getCoreRootDirectory());
g = (Gauge<?>)metrics.get("CONTAINER.fs.coreRoot.spins"); g = (Gauge<?>)metrics.get("CONTAINER.fs.coreRoot.spins");
assertEquals(spins, g.getValue()); assertEquals(spins, g.getValue());

View File

@ -32,7 +32,6 @@ import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.metrics.SolrMetricManager; import org.apache.solr.metrics.SolrMetricManager;
import org.apache.solr.metrics.SolrMetricReporter; import org.apache.solr.metrics.SolrMetricReporter;
@ -60,7 +59,7 @@ public class SolrGraphiteReporterTest extends SolrTestCaseJ4 {
// define the port where MockGraphite is running // define the port where MockGraphite is running
System.setProperty("mock-graphite-port", String.valueOf(mock.port)); System.setProperty("mock-graphite-port", String.valueOf(mock.port));
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-graphitereporter.xml").toFile(), "UTF-8"); String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-graphitereporter.xml").toFile(), "UTF-8");
NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml); NodeConfig cfg = SolrXmlConfig.fromString(home, solrXml);
CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator
(DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(), (DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(),
"solrconfig.xml", "schema.xml")); "solrconfig.xml", "schema.xml"));

View File

@ -27,7 +27,6 @@ import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.logging.LogWatcher; import org.apache.solr.logging.LogWatcher;
import org.apache.solr.logging.LogWatcherConfig; import org.apache.solr.logging.LogWatcherConfig;
@ -53,7 +52,7 @@ public class SolrSlf4jReporterTest extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop2", "proptwo"); System.setProperty("solr.test.sys.prop2", "proptwo");
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8"); String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8");
NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml); NodeConfig cfg = SolrXmlConfig.fromString(home, solrXml);
CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator
(DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(), (DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(),
"solrconfig.xml", "schema.xml")); "solrconfig.xml", "schema.xml"));

View File

@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
@ -92,7 +93,7 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
File solrXml = new File(solrHomeDirectory, "solr.xml"); File solrXml = new File(solrHomeDirectory, "solr.xml");
FileUtils.write(solrXml, discoveryXml, StandardCharsets.UTF_8); FileUtils.write(solrXml, discoveryXml, StandardCharsets.UTF_8);
final CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath()); final CoreContainer cores = new CoreContainer(solrHomeDirectory.toPath(), new Properties());
cores.load(); cores.load();
return cores; return cores;
} }

View File

@ -38,7 +38,7 @@ public class DateFieldTest extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop1", "propone"); System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo"); System.setProperty("solr.test.sys.prop2", "proptwo");
SolrConfig config = new SolrConfig SolrConfig config = new SolrConfig
(Paths.get(testInstanceDir), testConfHome + "solrconfig.xml", null, true); (Paths.get(testInstanceDir), testConfHome + "solrconfig.xml");
IndexSchema schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema.xml", config); IndexSchema schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema.xml", config);
f = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP) f = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)
? new DatePointField() : new TrieDateField(); ? new DatePointField() : new TrieDateField();

View File

@ -45,7 +45,7 @@ public class PrimitiveFieldTypeTest extends SolrTestCaseJ4 {
System.setProperty("solr.allow.unsafe.resourceloading", "true"); System.setProperty("solr.allow.unsafe.resourceloading", "true");
initMap = new HashMap<>(); initMap = new HashMap<>();
config = new SolrConfig(TEST_PATH().resolve("collection1"), testConfHome + "solrconfig.xml", null, true); config = new SolrConfig(TEST_PATH().resolve("collection1"), testConfHome + "solrconfig.xml");
} }
@Override @Override

View File

@ -174,8 +174,8 @@ public class TestManagedSchemaThreadSafety extends SolrTestCaseJ4 {
private Runnable indexSchemaLoader(String configsetName, final ZkController zkController) { private Runnable indexSchemaLoader(String configsetName, final ZkController zkController) {
return () -> { return () -> {
try { try {
SolrResourceLoader loader = new ZkSolrResourceLoader(loaderPath, configsetName, zkController); SolrResourceLoader loader = new ZkSolrResourceLoader(loaderPath, configsetName, null, zkController);
SolrConfig solrConfig = SolrConfig.readFromResourceLoader(loader, "solrconfig.xml", true); SolrConfig solrConfig = SolrConfig.readFromResourceLoader(loader, "solrconfig.xml", true, null);
ManagedIndexSchemaFactory factory = new ManagedIndexSchemaFactory(); ManagedIndexSchemaFactory factory = new ManagedIndexSchemaFactory();
factory.init(new NamedList()); factory.init(new NamedList());

View File

@ -62,7 +62,7 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
@Test @Test
public void testFailingSolrIndexConfigCreation() throws Exception { public void testFailingSolrIndexConfigCreation() throws Exception {
SolrConfig solrConfig = new SolrConfig(instanceDir,"bad-mpf-solrconfig.xml", null, true); SolrConfig solrConfig = new SolrConfig(instanceDir,"bad-mpf-solrconfig.xml");
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig); IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
h.getCore().setLatestSchema(indexSchema); h.getCore().setLatestSchema(indexSchema);
@ -75,7 +75,7 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
@Test @Test
public void testTieredMPSolrIndexConfigCreation() throws Exception { public void testTieredMPSolrIndexConfigCreation() throws Exception {
String solrConfigFileName = solrConfigFileNameTieredMergePolicyFactory; String solrConfigFileName = solrConfigFileNameTieredMergePolicyFactory;
SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName, null, true); SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig); IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
@ -100,7 +100,7 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
@Test @Test
public void testConcurrentMergeSchedularSolrIndexConfigCreation() throws Exception { public void testConcurrentMergeSchedularSolrIndexConfigCreation() throws Exception {
String solrConfigFileName = solrConfigFileNameConnMSPolicyFactory; String solrConfigFileName = solrConfigFileNameConnMSPolicyFactory;
SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName, null, true); SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig); IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
@ -124,7 +124,7 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
final SortField.Type expectedFieldType = SortField.Type.INT; final SortField.Type expectedFieldType = SortField.Type.INT;
final boolean expectedFieldSortDescending = true; final boolean expectedFieldSortDescending = true;
SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileNameSortingMergePolicyFactory, null, true); SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileNameSortingMergePolicyFactory);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
assertNotNull(solrIndexConfig); assertNotNull(solrIndexConfig);
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig); IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
@ -142,7 +142,7 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
} }
public void testMergedSegmentWarmerIndexConfigCreation() throws Exception { public void testMergedSegmentWarmerIndexConfigCreation() throws Exception {
SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileNameWarmerRandomMergePolicyFactory, null, true); SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileNameWarmerRandomMergePolicyFactory);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
assertNotNull(solrIndexConfig); assertNotNull(solrIndexConfig);
assertNotNull(solrIndexConfig.mergedSegmentWarmerInfo); assertNotNull(solrIndexConfig.mergedSegmentWarmerInfo);
@ -158,7 +158,7 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
final String solrConfigFileNameWarmer = solrConfigFileNameWarmerRandomMergePolicyFactory; final String solrConfigFileNameWarmer = solrConfigFileNameWarmerRandomMergePolicyFactory;
final String solrConfigFileNameTMP = solrConfigFileNameTieredMergePolicyFactory; final String solrConfigFileNameTMP = solrConfigFileNameTieredMergePolicyFactory;
final String solrConfigFileName = (random().nextBoolean() ? solrConfigFileNameWarmer : solrConfigFileNameTMP); final String solrConfigFileName = (random().nextBoolean() ? solrConfigFileNameWarmer : solrConfigFileNameTMP);
SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName, null, true); SolrConfig solrConfig = new SolrConfig(instanceDir, solrConfigFileName);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
assertNotNull(solrIndexConfig); assertNotNull(solrIndexConfig);
assertNotNull(solrIndexConfig.mergePolicyFactoryInfo); assertNotNull(solrIndexConfig.mergePolicyFactoryInfo);

View File

@ -31,7 +31,9 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.Properties;
/** /**
* Abstract base class for testing merge indexes command * Abstract base class for testing merge indexes command
@ -48,12 +50,12 @@ public abstract class MergeIndexesExampleTestBase extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
static String getSolrHome() { static Path getSolrHome() {
return SolrTestCaseJ4.getFile("solrj/solr/multicore").getAbsolutePath(); return SolrTestCaseJ4.getFile("solrj/solr/multicore").toPath();
} }
protected void setupCoreContainer() { protected void setupCoreContainer() {
cores = new CoreContainer(getSolrHome()); cores = new CoreContainer(getSolrHome(), new Properties());
cores.load(); cores.load();
//cores = CoreContainer.createAndLoad(getSolrHome(), new File(TEMP_DIR, "solr.xml")); //cores = CoreContainer.createAndLoad(getSolrHome(), new File(TEMP_DIR, "solr.xml"));
} }

View File

@ -55,7 +55,7 @@ import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.core.CoreDescriptor; import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrPaths;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -3296,7 +3296,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
final String baseDir = cluster.getBaseDir().toAbsolutePath().toString(); final String baseDir = cluster.getBaseDir().toAbsolutePath().toString();
for (CoreDescriptor coreDescriptor : jetty.getCoreContainer().getCoreDescriptors()) { for (CoreDescriptor coreDescriptor : jetty.getCoreContainer().getCoreDescriptors()) {
if (coreDescriptor.getCollectionName().equals(FILESTREAM_COLLECTION)) { if (coreDescriptor.getCollectionName().equals(FILESTREAM_COLLECTION)) {
return Paths.get(jetty.getSolrHome(), SolrResourceLoader.USER_FILES_DIRECTORY).toAbsolutePath().toString(); return Paths.get(jetty.getSolrHome(), SolrPaths.USER_FILES_DIRECTORY).toAbsolutePath().toString();
} }
} }
} }

View File

@ -122,7 +122,6 @@ import org.apache.solr.core.CoresLocator;
import org.apache.solr.core.NodeConfig; import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.handler.UpdateRequestHandler; import org.apache.solr.handler.UpdateRequestHandler;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
@ -555,7 +554,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
if (xmlStr == null) if (xmlStr == null)
xmlStr = "<solr></solr>"; xmlStr = "<solr></solr>";
Files.write(solrHome.resolve(SolrXmlConfig.SOLR_XML_FILE), xmlStr.getBytes(StandardCharsets.UTF_8)); Files.write(solrHome.resolve(SolrXmlConfig.SOLR_XML_FILE), xmlStr.getBytes(StandardCharsets.UTF_8));
h = new TestHarness(SolrXmlConfig.fromSolrHome(solrHome)); h = new TestHarness(SolrXmlConfig.fromSolrHome(solrHome, new Properties()));
lrf = h.getRequestFactory("/select", 0, 20, CommonParams.VERSION, "2.2"); lrf = h.getRequestFactory("/select", 0, 20, CommonParams.VERSION, "2.2");
} }
@ -817,14 +816,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
} }
public static CoreContainer createCoreContainer(NodeConfig config, CoresLocator locator) { public static CoreContainer createCoreContainer(NodeConfig config, CoresLocator locator) {
testSolrHome = config.getSolrResourceLoader().getInstancePath(); testSolrHome = config.getSolrHome();
h = new TestHarness(config, locator); h = new TestHarness(config, locator);
lrf = h.getRequestFactory("", 0, 20, CommonParams.VERSION, "2.2"); lrf = h.getRequestFactory("", 0, 20, CommonParams.VERSION, "2.2");
return h.getCoreContainer(); return h.getCoreContainer();
} }
public static CoreContainer createCoreContainer(String coreName, String dataDir, String solrConfig, String schema) { public static CoreContainer createCoreContainer(String coreName, String dataDir, String solrConfig, String schema) {
NodeConfig nodeConfig = TestHarness.buildTestNodeConfig(new SolrResourceLoader(TEST_PATH())); NodeConfig nodeConfig = TestHarness.buildTestNodeConfig(TEST_PATH());
CoresLocator locator = new TestHarness.TestCoresLocator(coreName, dataDir, solrConfig, schema); CoresLocator locator = new TestHarness.TestCoresLocator(coreName, dataDir, solrConfig, schema);
CoreContainer cc = createCoreContainer(nodeConfig, locator); CoreContainer cc = createCoreContainer(nodeConfig, locator);
h.coreName = coreName; h.coreName = coreName;

View File

@ -24,7 +24,6 @@ import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
@ -43,7 +42,7 @@ import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.PluginInfo; import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrPaths;
import org.apache.solr.core.SolrXmlConfig; import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.handler.UpdateRequestHandler; import org.apache.solr.handler.UpdateRequestHandler;
import org.apache.solr.metrics.reporters.SolrJmxReporter; import org.apache.solr.metrics.reporters.SolrJmxReporter;
@ -86,7 +85,7 @@ public class TestHarness extends BaseTestHarness {
System.setProperty("solr.test.sys.prop1", "propone"); System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo"); System.setProperty("solr.test.sys.prop2", "proptwo");
try { try {
return new SolrConfig(solrHome.resolve(coreName), confFile, null, true); return new SolrConfig(solrHome.resolve(coreName), confFile);
} catch (Exception xany) { } catch (Exception xany) {
throw new RuntimeException(xany); throw new RuntimeException(xany);
} }
@ -140,7 +139,7 @@ public class TestHarness extends BaseTestHarness {
* @param indexSchema schema resource name * @param indexSchema schema resource name
*/ */
public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) { public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {
this(buildTestNodeConfig(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())), this(buildTestNodeConfig(SolrPaths.locateSolrHome()),
new TestCoresLocator(coreName, dataDir, solrConfig, indexSchema)); new TestCoresLocator(coreName, dataDir, solrConfig, indexSchema));
this.coreName = (coreName == null) ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName; this.coreName = (coreName == null) ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;
} }
@ -155,16 +154,7 @@ public class TestHarness extends BaseTestHarness {
* @param solrXml the text of a solrxml * @param solrXml the text of a solrxml
*/ */
public TestHarness(Path solrHome, String solrXml) { public TestHarness(Path solrHome, String solrXml) {
this(new SolrResourceLoader(solrHome), solrXml); this(SolrXmlConfig.fromString(solrHome, solrXml));
}
/**
* Create a TestHarness using a specific solr resource loader and solr xml
* @param loader the SolrResourceLoader to use
* @param solrXml the text of a solrxml
*/
public TestHarness(SolrResourceLoader loader, String solrXml) {
this(SolrXmlConfig.fromString(loader, solrXml));
} }
public TestHarness(NodeConfig nodeConfig) { public TestHarness(NodeConfig nodeConfig) {
@ -176,13 +166,13 @@ public class TestHarness extends BaseTestHarness {
* @param config the ConfigSolr to use * @param config the ConfigSolr to use
*/ */
public TestHarness(NodeConfig config, CoresLocator coresLocator) { public TestHarness(NodeConfig config, CoresLocator coresLocator) {
container = new CoreContainer(config, new Properties(), coresLocator); container = new CoreContainer(config, coresLocator);
container.load(); container.load();
updater = new UpdateRequestHandler(); updater = new UpdateRequestHandler();
updater.init(null); updater.init(null);
} }
public static NodeConfig buildTestNodeConfig(SolrResourceLoader loader) { public static NodeConfig buildTestNodeConfig(Path solrHome) {
CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder(System.getProperty("host"), CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder(System.getProperty("host"),
Integer.getInteger("hostPort", 8983), Integer.getInteger("hostPort", 8983),
System.getProperty("hostContext", "")) System.getProperty("hostContext", ""))
@ -204,7 +194,7 @@ public class TestHarness extends BaseTestHarness {
.setMetricReporterPlugins(new PluginInfo[] {defaultPlugin}) .setMetricReporterPlugins(new PluginInfo[] {defaultPlugin})
.build(); .build();
return new NodeConfig.NodeConfigBuilder("testNode", loader) return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
.setUseSchemaCache(Boolean.getBoolean("shareSchema")) .setUseSchemaCache(Boolean.getBoolean("shareSchema"))
.setCloudConfig(cloudConfig) .setCloudConfig(cloudConfig)
.setUpdateShardHandlerConfig(updateShardHandlerConfig) .setUpdateShardHandlerConfig(updateShardHandlerConfig)