You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/11/28 18:07:43 UTC
[solr] 03/04: SOLR-16553: solr.install.dir property not initialized
This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
commit b0eff2ca815c2ec6b0487df4a77a694065c7eb43
Author: Kevin Risden <kr...@apache.org>
AuthorDate: Tue Nov 22 13:21:54 2022 -0500
SOLR-16553: solr.install.dir property not initialized
---
.../src/java/org/apache/solr/core/NodeConfig.java | 37 +++++++++++++++++-----
.../org/apache/solr/core/TestCoreContainer.java | 5 +--
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
index 10bd39ec55c..ad9f9844ee1 100644
--- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
@@ -253,13 +253,13 @@ public class NodeConfig {
/**
* Obtain the path of solr's binary installation directory, e.g. <code>/opt/solr</code>
*
- * @return path to install dir
- * @throws SolrException if property 'solr.install.dir' has not been initialized
+ * @return path to install dir or null if solr.install.dir not set.
*/
public Path getSolrInstallDir() {
String prop = System.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
if (prop == null || prop.isBlank()) {
- throw new SolrException(ErrorCode.SERVER_ERROR, "solr.install.dir property not initialized");
+ log.debug("solr.install.dir property not initialized.");
+ return null;
}
return Paths.get(prop);
}
@@ -436,8 +436,15 @@ public class NodeConfig {
Set<String> libDirs = new LinkedHashSet<>();
libDirs.add("lib");
- // Always add $SOLR_TIP/lib to the shared resource loader
- libDirs.add(getSolrInstallDir().resolve("lib").toAbsolutePath().normalize().toString());
+ Path solrInstallDir = getSolrInstallDir();
+ if (solrInstallDir == null) {
+ log.warn(
+ "Unable to add $SOLR_HOME/lib for shared lib since {} was not set.",
+ SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
+ } else {
+ // Always add $SOLR_TIP/lib to the shared resource loader
+ libDirs.add(solrInstallDir.resolve("lib").toAbsolutePath().normalize().toString());
+ }
if (!StringUtils.isBlank(getSharedLibDirectory())) {
List<String> sharedLibs = Arrays.asList(getSharedLibDirectory().split("\\s*,\\s*"));
@@ -478,16 +485,30 @@ public class NodeConfig {
private void initModules() {
var moduleNames = ModuleUtils.resolveModulesFromStringOrSyspropOrEnv(getModules());
boolean modified = false;
+
+ Path solrInstallDir = getSolrInstallDir();
+ if (solrInstallDir == null) {
+ if (!moduleNames.isEmpty()) {
+ throw new SolrException(
+ ErrorCode.SERVER_ERROR,
+ "Unable to setup modules "
+ + moduleNames
+ + " because "
+ + SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE
+ + " was not set.");
+ }
+ return;
+ }
for (String m : moduleNames) {
- if (!ModuleUtils.moduleExists(getSolrInstallDir(), m)) {
+ if (!ModuleUtils.moduleExists(solrInstallDir, m)) {
log.error(
"No module with name {}, available modules are {}",
m,
- ModuleUtils.listAvailableModules(getSolrInstallDir()));
+ ModuleUtils.listAvailableModules(solrInstallDir));
// Fail-fast if user requests a non-existing module
throw new SolrException(ErrorCode.SERVER_ERROR, "No module with name " + m);
}
- Path moduleLibPath = ModuleUtils.getModuleLibPath(getSolrInstallDir(), m);
+ Path moduleLibPath = ModuleUtils.getModuleLibPath(solrInstallDir, m);
if (Files.exists(moduleLibPath)) {
try {
List<URL> urls = SolrResourceLoader.getURLs(moduleLibPath);
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index a536191ad50..41eeb5e78a0 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -496,10 +496,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
Path solrInstallDir = cores.getConfig().getSolrInstallDir();
assertTrue(
"solrInstallDir was " + solrInstallDir,
- solrInstallDir != null
- && installDirPath
- .toString()
- .equals(cores.getConfig().getSolrInstallDir().toString()));
+ solrInstallDir != null && installDirPath.toString().equals(solrInstallDir.toString()));
// Proves that <solr-install-dir>/lib/jar1.jar is found, and the resource inside available
assertNotNull(cores.getResourceLoader().openResource("solrInstallDirLibResource"));
} finally {