janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790264796



##########
File path: solr/core/src/java/org/apache/solr/core/NodeConfig.java
##########
@@ -360,6 +381,86 @@ public String getDefaultZkHost() {
     return allowUrls;
   }
 
+  // Configures SOLR_HOME/lib to the shared class loader
+  private void setupSharedLib() {
+    // Always add $SOLR_HOME/lib to the shared resource loader
+    Set<String> libDirs = new LinkedHashSet<>();
+    libDirs.add("lib");
+
+    // Always add $SOLR_TIP/lib to the shared resource loader, to allow 
loading of i.e. /opt/solr/lib/foo.jar
+    if (getSolrInstallDir() != null) {
+      
libDirs.add(getSolrInstallDir().resolve("lib").toAbsolutePath().normalize().toString());
+    }
+
+    if (!StringUtils.isBlank(getSharedLibDirectory())) {
+      List<String> sharedLibs = 
Arrays.asList(getSharedLibDirectory().split("\\s*,\\s*"));
+      libDirs.addAll(sharedLibs);
+    }
+
+    addFoldersToSharedLib(libDirs);
+  }
+
+  /**
+   * Returns the modules as configured in solr.xml. Comma separated list. May 
be null if not defined
+   */
+  public String getModules() {
+    return modules;
+  }
+
+  // Finds every jar in each folder and adds it to shardLib, then reloads 
Lucene SPI
+  private void addFoldersToSharedLib(Set<String> libDirs) {
+    boolean modified = false;
+    // add the sharedLib to the shared resource loader before initializing cfg 
based plugins
+    for (String libDir : libDirs) {
+      Path libPath = getSolrHome().resolve(libDir);
+      if (Files.exists(libPath)) {
+        try {
+          loader.addToClassLoader(SolrResourceLoader.getURLs(libPath));
+          modified = true;
+        } catch (IOException e) {
+          throw new SolrException(ErrorCode.SERVER_ERROR, "Couldn't load libs: 
" + e, e);
+        }
+      }
+    }
+    if (modified) {
+      loader.reloadLuceneSPI();
+    }
+  }
+
+  // Adds modules to shared classpath
+  private void initModules() {
+    Set<String> moduleNames = 
ModuleUtils.resolveModulesFromStringOrSyspropOrEnv(getModules());
+    boolean modified = false;
+    for (String m : moduleNames) {
+      if (!ModuleUtils.moduleExists(getSolrInstallDir(), m)) {
+        log.error("No module with name {}, available modules are {}", m, 
ModuleUtils.listAvailableModules(getSolrInstallDir()));
+        // 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);

Review comment:
       Should be fixed now by `getSolrInstallDir()` not returning null but 
throwing exception.

##########
File path: solr/core/src/java/org/apache/solr/core/NodeConfig.java
##########
@@ -360,6 +381,86 @@ public String getDefaultZkHost() {
     return allowUrls;
   }
 
+  // Configures SOLR_HOME/lib to the shared class loader
+  private void setupSharedLib() {
+    // Always add $SOLR_HOME/lib to the shared resource loader
+    Set<String> libDirs = new LinkedHashSet<>();
+    libDirs.add("lib");
+
+    // Always add $SOLR_TIP/lib to the shared resource loader, to allow 
loading of i.e. /opt/solr/lib/foo.jar
+    if (getSolrInstallDir() != null) {
+      
libDirs.add(getSolrInstallDir().resolve("lib").toAbsolutePath().normalize().toString());
+    }
+
+    if (!StringUtils.isBlank(getSharedLibDirectory())) {
+      List<String> sharedLibs = 
Arrays.asList(getSharedLibDirectory().split("\\s*,\\s*"));
+      libDirs.addAll(sharedLibs);
+    }
+
+    addFoldersToSharedLib(libDirs);
+  }
+
+  /**
+   * Returns the modules as configured in solr.xml. Comma separated list. May 
be null if not defined
+   */
+  public String getModules() {
+    return modules;
+  }
+
+  // Finds every jar in each folder and adds it to shardLib, then reloads 
Lucene SPI
+  private void addFoldersToSharedLib(Set<String> libDirs) {
+    boolean modified = false;
+    // add the sharedLib to the shared resource loader before initializing cfg 
based plugins
+    for (String libDir : libDirs) {
+      Path libPath = getSolrHome().resolve(libDir);
+      if (Files.exists(libPath)) {
+        try {
+          loader.addToClassLoader(SolrResourceLoader.getURLs(libPath));
+          modified = true;
+        } catch (IOException e) {
+          throw new SolrException(ErrorCode.SERVER_ERROR, "Couldn't load libs: 
" + e, e);
+        }
+      }
+    }
+    if (modified) {
+      loader.reloadLuceneSPI();
+    }
+  }
+
+  // Adds modules to shared classpath
+  private void initModules() {
+    Set<String> moduleNames = 
ModuleUtils.resolveModulesFromStringOrSyspropOrEnv(getModules());
+    boolean modified = false;
+    for (String m : moduleNames) {
+      if (!ModuleUtils.moduleExists(getSolrInstallDir(), m)) {
+        log.error("No module with name {}, available modules are {}", m, 
ModuleUtils.listAvailableModules(getSolrInstallDir()));

Review comment:
       Should be fixed now by `getSolrInstallDir()` not returning null but 
throwing exception.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to