You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/01/22 23:38:26 UTC
[GitHub] [solr] janhoy opened a new pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
janhoy opened a new pull request #557:
URL: https://github.com/apache/solr/pull/557
https://issues.apache.org/jira/browse/SOLR-15914
I have structured this in three commits
1. 8199a5e3c60cb1e35bfb16652362c32d820e0ac7 Moving existing `shardLib` init from `CoreContainer` to `NodeConfig` as requested by @dsmiley in #525
2. 5adbb7572c25647be6a294d7db593109d0981d01 Logic for parsing string of comma separated module names either from solr.xml, system property or environment variable, and add libs for those modules to shared classloader
3. 927b349fc990dc6ac7e197827c0096a6ed50c632 Documentation
There are unit and integraion tests, but you can also test manually. While on the feature branch:
```bash
./gradlew dev
cd solr/packaging/build/dev/
SOLR_MODULES=langid,extraction bin/solr -c
grep "Added module" server/logs/solr.log
# You will see two log lines:
# [...] Added module langid. libPath=[...]contrib/langid/lib with 5 libs
# [...] Added module extraction. libPath=[...]contrib/extraction/lib with 43 libs
bin/solr create -c test
curl -X POST -H 'Content-type:application/json' -d '{
"add-requesthandler": {
"name": "/extract",
"class": "org.apache.solr.handler.extraction.ExtractingRequestHandler"
}
}' http://localhost:8983/solr/test/config
curl "http://localhost:8983/solr/test/extract?extractOnly=true&literal.id=1" --data-binary @example/exampledocs/sample.html -H 'Content-type:text/html'
# You see the extracted content
bin/solr stop
```
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] dsmiley commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790211840
##########
File path: solr/core/src/java/org/apache/solr/core/CoreContainer.java
##########
@@ -1581,7 +1553,7 @@ private void resetIndexDirectory(CoreDescriptor dcore, ConfigSet coreConfig) {
df.release(dir);
df.doneWithDirectory(dir);
} catch (IOException e) {
- SolrException.log(log, e);
Review comment:
Was this accidental?
##########
File path: solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
##########
@@ -327,6 +327,9 @@ private static NodeConfig fillSolrSection(NodeConfig.NodeConfigBuilder builder,
case "sharedLib":
builder.setSharedLibDirectory(value);
break;
+ case "modules":
+ builder.setModules(value);
Review comment:
Shouldn't we be comma splitting at this point so that we have modules declared as a list of strings?
##########
File path: solr/core/src/java/org/apache/solr/core/CoreContainer.java
##########
@@ -1884,8 +1855,6 @@ public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, b
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SolrException(ErrorCode.SERVER_ERROR, "Interrupted while unregistering core [" + name + "] from cloud state");
- } catch (KeeperException e) {
Review comment:
and more accidental?
##########
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)) {
Review comment:
This was helpful, and motivated my suggestion that getSolrInstallDir always return non-null.
##########
File path: solr/core/src/java/org/apache/solr/core/CoreContainer.java
##########
@@ -1711,7 +1683,6 @@ public void reload(String name, UUID coreId) {
// CoreDescriptor and we need to reload it from the disk files
CoreDescriptor cd = reloadCoreDescriptor(core.getCoreDescriptor());
solrCores.addCoreDescriptor(cd);
- Closeable oldCore = null;
Review comment:
more accidental?
##########
File path: solr/core/src/java/org/apache/solr/core/NodeConfig.java
##########
@@ -206,7 +218,16 @@ public Path getSolrDataHome() {
return solrDataHome;
}
- /**
+ /**
+ * Obtain the path of solr's binary installation directory, e.g. <code>/opt/solr</code>
+ * @return path to install dir, or null if property 'solr.install.dir' has not been initialized
+ */
+ public Path getSolrInstallDir() {
+ String prop = System.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
+ return prop != null ? Paths.get(prop) : null;
Review comment:
Maybe throw an exception to ensure we never return null? It should always be set; right? Perhaps not in tests? Ok but we could ensure this happens.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy merged pull request #557: SOLR-15914 Make it super simple to add a (contrib) module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy merged pull request #557:
URL: https://github.com/apache/solr/pull/557
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790198239
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
Please note - I made a "shortcut" here. Traditionally we have parsed environment variables in `bin/solr` and converted them to system properties on command line `java -jar start.jar -Dfoo=bar`, and then pick up *only* the sysprop in some xml config file.
In this patch I wanted to support both system property and env.var for all 9.0 users, even if they bring in a custom `solr.xml`, (without the `modules` tag). Thus we first look for a value from `solr.xml` (which also picks up direct sysprop such as `bin/solr start -Dsolr.modules=foo` or `bin/solr start -a "-Dsolr.modules=foo"`. But we also fall back to parsing sysprop and env.var direclty in Java, if no or empty value from solr.xml. But if a user in a custom `solr.xml` choose to override or pull the value from another sysprop, that will always win. Direct sysprod+env is a fallback.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] HoustonPutman commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
HoustonPutman commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r791859891
##########
File path: solr/CHANGES.txt
##########
@@ -564,7 +566,7 @@ Bug Fixes
* SOLR-15944: The Tagger's JSON response format now always uses an object/map to represent each tag instead of an
array, which didn't make sense. (David Smiley)
-* SOLR-15842: Async response for backups now correctly aggregates and returns information (Houston Putman, Artem Abeleshev, Christine Poerschke)
+* SOLR-15842: Async response for backups now correctly aggregates and returns information (Houston Putman, ijioio)
Review comment:
I think you overwrote a second commit I made...
##########
File path: solr/server/solr/solr.xml
##########
@@ -30,6 +30,7 @@
<int name="maxBooleanClauses">${solr.max.booleanClauses:1024}</int>
<str name="sharedLib">${solr.sharedLib:}</str>
+ <str name="modules">${solr.modules:}</str>
Review comment:
I think this should go in the ref guide's page on the solr.xml
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
I am a huge fan of this approach. We should be able to set node-level properties without modifying the solr.xml.
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static final String MODULES_FOLDER_NAME = "modules";
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
+ if (!StringUtils.isEmpty(modulesFromEnv)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromEnv, ',', true));
+ }
+ return mods.stream().map(String::trim).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns true if a module name is valid and exists in the system
+ */
+ public static boolean moduleExists(Path solrInstallDirPath, String moduleName) {
+ if (!isValidName(moduleName)) return false;
+ Path modPath = getModulesPath(solrInstallDirPath).resolve(moduleName);
+ return Files.isDirectory(modPath);
+ }
+
+ /**
+ * Returns nam of all existing modules
+ */
+ public static Set<String> listAvailableModules(Path solrInstallDirPath) {
+ try (var moduleFilesStream = Files.list(getModulesPath(solrInstallDirPath))) {
+ return moduleFilesStream.filter(Files::isDirectory)
+ .map(p -> p.getFileName().toString()).collect(Collectors.toSet());
+ } catch (IOException e) {
+ log.warn("Found no modules in {}", getModulesPath(solrInstallDirPath), e);
+ return Collections.emptySet();
+ }
+ }
+
+ /**
+ * Parses comma separated string of module names, in practice found in solr.xml.
+ * If input string is empty (nothing configured) or null (e.g. tag not present in solr.xml),
+ * we continue to resolve from system property <code>-Dsolr.modules</code> and if still empty,
+ * fall back to environment variable <code>SOLR_MODULES</code>.
+ * @param modulesFromString raw string of comma-separated module names
+ * @return a set of module
+ */
+ public static Set<String> resolveModulesFromStringOrSyspropOrEnv(String modulesFromString) {
+ Set<String> moduleNames;
Review comment:
Might as well make this a `Collection<String>` if you are going to `.stream()` it later. Then you don't have to create a new `HashSet` from the list below. Not a big deal though. This is never going to be a huge list...
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790261940
##########
File path: solr/core/src/java/org/apache/solr/core/CoreContainer.java
##########
@@ -1581,7 +1553,7 @@ private void resetIndexDirectory(CoreDescriptor dcore, ConfigSet coreConfig) {
df.release(dir);
df.doneWithDirectory(dir);
} catch (IOException e) {
- SolrException.log(log, e);
Review comment:
No. `SolrException.log()` is deprecated. But I'm reverting the change and leave deprecation removal for a followup issue.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] sonatype-lift[bot] commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
sonatype-lift[bot] commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790206940
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
+ if (!StringUtils.isEmpty(modulesFromEnv)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromEnv, ',', true));
+ }
+ return mods.stream().map(String::trim).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns true if a module name is valid and exists in the system
+ */
+ public static boolean moduleExists(Path solrInstallDirPath, String moduleName) {
+ if (!isValidName(moduleName)) return false;
+ Path modPath = getModulesPath(solrInstallDirPath).resolve(moduleName);
+ return Files.isDirectory(modPath);
+ }
+
+ /**
+ * Returns nam of all existing modules
+ */
+ public static Set<String> listAvailableModules(Path solrInstallDirPath) {
+ try {
+ return Files.list(getModulesPath(solrInstallDirPath)).filter(Files::isDirectory)
Review comment:
*StreamResourceLeak:* Streams that encapsulate a closeable resource should be closed using try-with-resources [(details)](https://errorprone.info/bugpattern/StreamResourceLeak)
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
##########
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:
*NULL_DEREFERENCE:* object returned by `getSolrInstallDir()` could be null and is dereferenced by call to `getModuleLibPath(...)` at line 440.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
##########
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:
*NULL_DEREFERENCE:* object returned by `getSolrInstallDir()` could be null and is dereferenced by call to `listAvailableModules(...)` at line 436.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
##########
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)) {
Review comment:
*NULL_DEREFERENCE:* object returned by `getSolrInstallDir()` could be null and is dereferenced by call to `moduleExists(...)` at line 435.
(at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790264842
##########
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)) {
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on pull request #557:
URL: https://github.com/apache/solr/pull/557#issuecomment-1022761719
Will await the latest ref-guide doc edits, and then if no more feedback, merge soon.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790263355
##########
File path: solr/core/src/java/org/apache/solr/core/NodeConfig.java
##########
@@ -206,7 +218,16 @@ public Path getSolrDataHome() {
return solrDataHome;
}
- /**
+ /**
+ * Obtain the path of solr's binary installation directory, e.g. <code>/opt/solr</code>
+ * @return path to install dir, or null if property 'solr.install.dir' has not been initialized
+ */
+ public Path getSolrInstallDir() {
+ String prop = System.getProperty(SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE);
+ return prop != null ? Paths.get(prop) : null;
Review comment:
Yep, I'll try with exception. Then not even tests should call this if they don't know that they have set it.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r793172544
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static final String MODULES_FOLDER_NAME = "modules";
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
+ if (!StringUtils.isEmpty(modulesFromEnv)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromEnv, ',', true));
+ }
+ return mods.stream().map(String::trim).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns true if a module name is valid and exists in the system
+ */
+ public static boolean moduleExists(Path solrInstallDirPath, String moduleName) {
+ if (!isValidName(moduleName)) return false;
+ Path modPath = getModulesPath(solrInstallDirPath).resolve(moduleName);
+ return Files.isDirectory(modPath);
+ }
+
+ /**
+ * Returns nam of all existing modules
+ */
+ public static Set<String> listAvailableModules(Path solrInstallDirPath) {
+ try (var moduleFilesStream = Files.list(getModulesPath(solrInstallDirPath))) {
+ return moduleFilesStream.filter(Files::isDirectory)
+ .map(p -> p.getFileName().toString()).collect(Collectors.toSet());
+ } catch (IOException e) {
+ log.warn("Found no modules in {}", getModulesPath(solrInstallDirPath), e);
+ return Collections.emptySet();
+ }
+ }
+
+ /**
+ * Parses comma separated string of module names, in practice found in solr.xml.
+ * If input string is empty (nothing configured) or null (e.g. tag not present in solr.xml),
+ * we continue to resolve from system property <code>-Dsolr.modules</code> and if still empty,
+ * fall back to environment variable <code>SOLR_MODULES</code>.
+ * @param modulesFromString raw string of comma-separated module names
+ * @return a set of module
+ */
+ public static Set<String> resolveModulesFromStringOrSyspropOrEnv(String modulesFromString) {
+ Set<String> moduleNames;
Review comment:
Good idea, fixed.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790198239
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
Please note - I made a "shortcut" here. Traditionally we have parsed environment variables in `bin/solr` and converted them to system properties on command line `java -jar start.jar -Dfoo=bar`, and then pick up *only* the sysprop in some xml config file.
In this patch I wanted to support both system property and env.var for all 9.0 users, even if they bring in a custom `solr.xml`, (without the `modules` tag). Thus we first look for a value from `solr.xml` (which also picks up direct sysprop such as `bin/solr start -Dsolr.modules=foo` or `bin/solr start -a "-Dsolr.modules=foo"`). But we also fall back to parsing sysprop and env.var direclty in Java, if no or empty value from solr.xml. But if a user in a custom `solr.xml` choose to override or pull the value from another sysprop, that will always win. Direct sysprod+env is a fallback.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790262307
##########
File path: solr/core/src/java/org/apache/solr/core/CoreContainer.java
##########
@@ -1884,8 +1855,6 @@ public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, b
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SolrException(ErrorCode.SERVER_ERROR, "Interrupted while unregistering core [" + name + "] from cloud state");
- } catch (KeeperException e) {
Review comment:
Yea, I had some unrelated cleanups in the same commit. This catch is redundant with the `catch (Exception)`- suggested by IDEA. But it disturbs the feature review, so reverted it too.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a (contrib) module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r793476338
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
Ok, this is off topic here, so I made https://issues.apache.org/jira/browse/SOLR-15960 to track.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] dsmiley commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r792280103
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
Yeah, being able to add stuff with env vars in preference to editing config files makes sense in our containerized world.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790262011
##########
File path: solr/core/src/java/org/apache/solr/core/CoreContainer.java
##########
@@ -1711,7 +1683,6 @@ public void reload(String name, UUID coreId) {
// CoreDescriptor and we need to reload it from the disk files
CoreDescriptor cd = reloadCoreDescriptor(core.getCoreDescriptor());
solrCores.addCoreDescriptor(cd);
- Closeable oldCore = null;
Review comment:
Unused variable. I think I'll leave it in, it's a cleanup.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] HoustonPutman commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
HoustonPutman commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r791859891
##########
File path: solr/CHANGES.txt
##########
@@ -564,7 +566,7 @@ Bug Fixes
* SOLR-15944: The Tagger's JSON response format now always uses an object/map to represent each tag instead of an
array, which didn't make sense. (David Smiley)
-* SOLR-15842: Async response for backups now correctly aggregates and returns information (Houston Putman, Artem Abeleshev, Christine Poerschke)
+* SOLR-15842: Async response for backups now correctly aggregates and returns information (Houston Putman, ijioio)
Review comment:
I think you overwrote a second commit I made...
##########
File path: solr/server/solr/solr.xml
##########
@@ -30,6 +30,7 @@
<int name="maxBooleanClauses">${solr.max.booleanClauses:1024}</int>
<str name="sharedLib">${solr.sharedLib:}</str>
+ <str name="modules">${solr.modules:}</str>
Review comment:
I think this should go in the ref guide's page on the solr.xml
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
I am a huge fan of this approach. We should be able to set node-level properties without modifying the solr.xml.
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static final String MODULES_FOLDER_NAME = "modules";
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
+ if (!StringUtils.isEmpty(modulesFromEnv)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromEnv, ',', true));
+ }
+ return mods.stream().map(String::trim).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns true if a module name is valid and exists in the system
+ */
+ public static boolean moduleExists(Path solrInstallDirPath, String moduleName) {
+ if (!isValidName(moduleName)) return false;
+ Path modPath = getModulesPath(solrInstallDirPath).resolve(moduleName);
+ return Files.isDirectory(modPath);
+ }
+
+ /**
+ * Returns nam of all existing modules
+ */
+ public static Set<String> listAvailableModules(Path solrInstallDirPath) {
+ try (var moduleFilesStream = Files.list(getModulesPath(solrInstallDirPath))) {
+ return moduleFilesStream.filter(Files::isDirectory)
+ .map(p -> p.getFileName().toString()).collect(Collectors.toSet());
+ } catch (IOException e) {
+ log.warn("Found no modules in {}", getModulesPath(solrInstallDirPath), e);
+ return Collections.emptySet();
+ }
+ }
+
+ /**
+ * Parses comma separated string of module names, in practice found in solr.xml.
+ * If input string is empty (nothing configured) or null (e.g. tag not present in solr.xml),
+ * we continue to resolve from system property <code>-Dsolr.modules</code> and if still empty,
+ * fall back to environment variable <code>SOLR_MODULES</code>.
+ * @param modulesFromString raw string of comma-separated module names
+ * @return a set of module
+ */
+ public static Set<String> resolveModulesFromStringOrSyspropOrEnv(String modulesFromString) {
+ Set<String> moduleNames;
Review comment:
Might as well make this a `Collection<String>` if you are going to `.stream()` it later. Then you don't have to create a new `HashSet` from the list below. Not a big deal though. This is never going to be a huge list...
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a (contrib) module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r793368513
##########
File path: solr/core/src/java/org/apache/solr/util/ModuleUtils.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.util;
+
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.util.StrUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Parses the list of modules the user has requested in solr.xml, property solr.modules or environment SOLR_MODULES.
+ * Then resolves the lib folder for each, so they can be added to class path.
+ */
+public class ModuleUtils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String MODULES_FOLDER_NAME = "contrib"; // TODO Change to "modules"
+ private static final Pattern validModNamesPattern = Pattern.compile("[\\w\\d-_]+");
+
+ /**
+ * Returns a path to a module's lib folder
+ * @param moduleName name of module
+ * @return the path to the module's lib folder
+ */
+ public static Path getModuleLibPath(Path solrInstallDirPath, String moduleName) {
+ return getModulesPath(solrInstallDirPath).resolve(moduleName).resolve("lib");
+ }
+
+ /**
+ * Finds list of module names requested by system property or environment variable
+ * @return set of raw volume names from sysprop and/or env.var
+ */
+ static Set<String> resolveFromSyspropOrEnv() {
+ // Fall back to sysprop and env.var if nothing configured through solr.xml
+ Set<String> mods = new HashSet<>();
+ String modulesFromProps = System.getProperty("solr.modules");
+ if (!StringUtils.isEmpty(modulesFromProps)) {
+ mods.addAll(StrUtils.splitSmart(modulesFromProps, ',', true));
+ }
+ String modulesFromEnv = System.getenv("SOLR_MODULES");
Review comment:
Glad to see some support. In the future I want to slim down `bin/solr`, `bin/solr.cmd` and also `SolrCLI` to remove all kinds of boiler-plate code to map between env.var and sys.prop, and introduce a new `ConfigResolver` to Solr, so some piece of code could say `ConfigResolver.getInt("solr.number")` and it would return and convert the value from either sys.prop `solr.number` or env.var `SOLR_NUMBER`. We could also add stuff like `ConfigResolver.getListOfStrings("solr.modules")` and it would return a `List<String>` for you. It could even support comma-separated, semicolon-separated or why not also props of format `["foo","bar"]`?
If we can somehow tie it in with loading values from solr.xml and our other config files, then we could have a DSL that would be really pleasant to use for falling back from explicit xml-config value to any of sys.prop or env.var.
Of course we still need to parse and set JVM-level props like memory in bin/solr.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r790264452
##########
File path: solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
##########
@@ -327,6 +327,9 @@ private static NodeConfig fillSolrSection(NodeConfig.NodeConfigBuilder builder,
case "sharedLib":
builder.setSharedLibDirectory(value);
break;
+ case "modules":
+ builder.setModules(value);
Review comment:
Did not do that for sharedLib, so chose to keep it transparent with user input here too. Currently the split and strip logic is done by consumer ModuleUtils, but it could of course have been moved earlier. Guess I prefer to not have a ton of additional logig in plain getters/setters.
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r793171312
##########
File path: solr/CHANGES.txt
##########
@@ -564,7 +566,7 @@ Bug Fixes
* SOLR-15944: The Tagger's JSON response format now always uses an object/map to represent each tag instead of an
array, which didn't make sense. (David Smiley)
-* SOLR-15842: Async response for backups now correctly aggregates and returns information (Houston Putman, Artem Abeleshev, Christine Poerschke)
+* SOLR-15842: Async response for backups now correctly aggregates and returns information (Houston Putman, ijioio)
Review comment:
Fixed
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
[GitHub] [solr] janhoy commented on a change in pull request #557: SOLR-15914 Make it super simple to add a contrib module to shared classpath
Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #557:
URL: https://github.com/apache/solr/pull/557#discussion_r793179432
##########
File path: solr/server/solr/solr.xml
##########
@@ -30,6 +30,7 @@
<int name="maxBooleanClauses">${solr.max.booleanClauses:1024}</int>
<str name="sharedLib">${solr.sharedLib:}</str>
+ <str name="modules">${solr.modules:}</str>
Review comment:
I was sure I did that, but now I have committed docs in `configuring-solr-xml.adoc`
--
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: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org