mirror of
https://github.com/apache/lucene.git
synced 2025-02-21 17:46:28 +00:00
SOLR-14934: Remove redundent deprecated "solr.solr.home" logic
This commit is contained in:
parent
e3572d0c4d
commit
5208d47e1a
@ -151,6 +151,8 @@ Other Changes
|
||||
* SOLR-14035: Remove deprecated preferLocalShards=true support in favour of the shards.preference=replica.location:local alternative.
|
||||
(Alex Bulygin via Christine Poerschke)
|
||||
|
||||
* SOLR-14934: Remove redundent deprecated "solr.solr.home" logic (hossman)
|
||||
|
||||
Bug Fixes
|
||||
---------------------
|
||||
* SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order execution
|
||||
|
@ -17,16 +17,11 @@
|
||||
|
||||
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.apache.commons.exec.OS;
|
||||
import org.apache.solr.common.SolrException;
|
||||
@ -39,57 +34,8 @@ import org.slf4j.LoggerFactory;
|
||||
public final class SolrPaths {
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
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>
|
||||
*
|
||||
* @return the Solr home, absolute and normalized.
|
||||
* @deprecated all code should get solr home from CoreContainer
|
||||
* @see CoreContainer#getSolrHome()
|
||||
*/
|
||||
@Deprecated
|
||||
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);
|
||||
}
|
||||
|
||||
// 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).toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures a directory name always ends with a '/'.
|
||||
*/
|
||||
@ -97,14 +43,6 @@ public final class SolrPaths {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the given path is relative to one of the allowPaths supplied. Typically this will be
|
||||
* called from {@link CoreContainer#assertPathAllowed(Path)} and allowPaths pre-filled with the node's
|
||||
|
@ -129,19 +129,9 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
|
||||
return schemaLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use <code>new SolrResourceLoader(Path)</code>
|
||||
* @see CoreContainer#getSolrHome
|
||||
*/
|
||||
@Deprecated
|
||||
public SolrResourceLoader() {
|
||||
this(SolrPaths.locateSolrHome(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a loader.
|
||||
* Note: we do NOT call {@link #reloadLuceneSPI()}.
|
||||
* (Behavior when <code>instanceDir</code> is <code>null</code> is un-specified, in future versions this will fail due to NPE)
|
||||
*/
|
||||
public SolrResourceLoader(String name, List<Path> classpath, Path instanceDir, ClassLoader parent) {
|
||||
this(instanceDir, parent);
|
||||
@ -160,7 +150,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
|
||||
|
||||
/**
|
||||
* Creates a loader.
|
||||
* (Behavior when <code>instanceDir</code> is <code>null</code> is un-specified, in future versions this will fail due to NPE)
|
||||
* @param instanceDir - base directory for this resource loader, must not be null
|
||||
*/
|
||||
public SolrResourceLoader(Path instanceDir) {
|
||||
this(instanceDir, null);
|
||||
@ -170,20 +160,14 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
|
||||
* This loader will delegate to Solr's classloader when possible,
|
||||
* otherwise it will attempt to resolve resources using any jar files
|
||||
* found in the "lib/" directory in the specified instance directory.
|
||||
*
|
||||
* @param instanceDir - base directory for this resource loader, if null locateSolrHome() will be used. (in future versions this will fail due to NPE)
|
||||
* @see SolrPaths#locateSolrHome()
|
||||
*/
|
||||
public SolrResourceLoader(Path instanceDir, ClassLoader parent) {
|
||||
if (instanceDir == null) {
|
||||
log.warn("SolrResourceLoader created with null instanceDir. This will not be supported in Solr 9.0");
|
||||
|
||||
this.instanceDir = SolrPaths.locateSolrHome();
|
||||
log.debug("new SolrResourceLoader for deduced Solr Home: '{}'", this.instanceDir);
|
||||
} else {
|
||||
this.instanceDir = instanceDir;
|
||||
log.debug("new SolrResourceLoader for directory: '{}'", this.instanceDir);
|
||||
throw new NullPointerException("SolrResourceLoader instanceDir must be non-null");
|
||||
}
|
||||
|
||||
this.instanceDir = instanceDir;
|
||||
log.debug("new SolrResourceLoader for directory: '{}'", this.instanceDir);
|
||||
|
||||
if (parent == null) {
|
||||
parent = getClass().getClassLoader();
|
||||
|
@ -16,6 +16,10 @@
|
||||
*/
|
||||
package org.apache.solr.servlet;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NoInitialContextException;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ReadListener;
|
||||
@ -73,7 +77,6 @@ import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.NodeConfig;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.core.SolrInfoBean;
|
||||
import org.apache.solr.core.SolrPaths;
|
||||
import org.apache.solr.core.SolrXmlConfig;
|
||||
import org.apache.solr.metrics.AltBufferPoolMetricSet;
|
||||
import org.apache.solr.metrics.MetricsMap;
|
||||
@ -289,11 +292,56 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective Solr Home to use for this node
|
||||
* Returns the effective Solr Home to use for this node, based on looking up the value in this order:
|
||||
* <ol>
|
||||
* <li>attribute in the FilterConfig</li>
|
||||
* <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>
|
||||
*
|
||||
* @return the Solr home, absolute and normalized.
|
||||
* @see #SOLRHOME_ATTRIBUTE
|
||||
*/
|
||||
private static Path computeSolrHome(FilterConfig config) {
|
||||
final String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE);
|
||||
return (solrHome == null ? SolrPaths.locateSolrHome() : Paths.get(solrHome));
|
||||
|
||||
// start with explicit check of servlet config...
|
||||
String source = "servlet config: " + SOLRHOME_ATTRIBUTE;
|
||||
String home = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE);
|
||||
|
||||
if (null == home) {
|
||||
final String lookup = "java:comp/env/solr/home";
|
||||
// Try JNDI
|
||||
source = "JNDI: " + lookup;
|
||||
try {
|
||||
Context c = new InitialContext();
|
||||
home = (String) c.lookup(lookup);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (null == home) {
|
||||
// Now try system property
|
||||
final String prop = "solr.solr.home";
|
||||
source = "system property: " + prop;
|
||||
home = System.getProperty(prop);
|
||||
}
|
||||
|
||||
if (null == home) {
|
||||
// if all else fails, assume default dir
|
||||
home = "solr/";
|
||||
source = "defaulted to '" + home + "' ... could not find system property or JNDI";
|
||||
}
|
||||
final Path solrHome = Paths.get(home).toAbsolutePath().normalize();
|
||||
log.info("Solr Home: {} (source: {})", solrHome, source);
|
||||
|
||||
return solrHome;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user