Apache Solr open-source search software
SOLR-17864: Migrate System Properties to modern style (#3504)
Eric Pugh3ede0ed89035
diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.javaindex 32093a5031f..d298d69fb0a 100644--- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java@@ -71,6 +71,7 @@ import org.apache.solr.common.params.MapSolrParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.CommandOperation;+import org.apache.solr.common.util.EnvUtils;import org.apache.solr.common.util.ExecutorUtil;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SolrNamedThreadFactory;@@ -102,9 +103,9 @@ import org.slf4j.LoggerFactory;public class SolrConfigHandler extends RequestHandlerBaseimplements SolrCoreAware, PermissionNameProvider {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());- public static final String CONFIGSET_EDITING_DISABLED_ARG = "disable.configEdit";- public static final boolean configEditing_disabled =- Boolean.getBoolean(CONFIGSET_EDITING_DISABLED_ARG);+ public static final String CONFIG_EDITING_ENABLED_ARG = "solr.api.config.edit.enabled";+ public static final boolean configEditingEnabled =+ EnvUtils.getPropertyAsBool(CONFIG_EDITING_ENABLED_ARG, true);private static final Map<String, SolrConfig.SolrPluginInfo> namedPlugins;private final Lock reloadLock = new ReentrantLock(true);@@ -132,11 +133,11 @@ public class SolrConfigHandler extends RequestHandlerBaseString httpMethod = (String) req.getContext().get("httpMethod");Command command = new Command(req, rsp, httpMethod);if ("POST".equals(httpMethod)) {- if (configEditing_disabled || isImmutableConfigSet) {+ if (!configEditingEnabled || isImmutableConfigSet) {final String reason =- configEditing_disabled- ? "due to " + CONFIGSET_EDITING_DISABLED_ARG- : "because ConfigSet is immutable";+ !configEditingEnabled+ ? "due to " + CONFIG_EDITING_ENABLED_ARG + " setting"+ : "because ConfigSet is marked immutable";throw new SolrException(SolrException.ErrorCode.FORBIDDEN, " solrconfig editing is not enabled " + reason);}diff --git a/solr/core/src/java/org/apache/solr/handler/api/V2ApiUtils.java b/solr/core/src/java/org/apache/solr/handler/api/V2ApiUtils.javaindex f3cb152204d..d05de0fc0c7 100644--- a/solr/core/src/java/org/apache/solr/handler/api/V2ApiUtils.java+++ b/solr/core/src/java/org/apache/solr/handler/api/V2ApiUtils.java@@ -28,6 +28,7 @@ import java.util.Map;import org.apache.solr.client.api.model.SolrJerseyResponse;import org.apache.solr.common.MapWriter.EntryWriter;import org.apache.solr.common.params.SolrParams;+import org.apache.solr.common.util.EnvUtils;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.StrUtils;import org.apache.solr.common.util.Utils;@@ -41,7 +42,7 @@ public class V2ApiUtils {}public static boolean isEnabled() {- return !"true".equals(System.getProperty("disable.v2.api", "false"));+ return EnvUtils.getPropertyAsBool("solr.api.v2.enabled", true);}public static void flattenMapWithPrefix(diff --git a/solr/core/src/java/org/apache/solr/handler/configsets/ConfigSetAPIBase.java b/solr/core/src/java/org/apache/solr/handler/configsets/ConfigSetAPIBase.javaindex 503917da584..3b829f6faef 100644--- a/solr/core/src/java/org/apache/solr/handler/configsets/ConfigSetAPIBase.java+++ b/solr/core/src/java/org/apache/solr/handler/configsets/ConfigSetAPIBase.java@@ -36,6 +36,7 @@ import org.apache.solr.common.SolrException;import org.apache.solr.common.cloud.ZkNodeProps;import org.apache.solr.common.params.ConfigSetParams;import org.apache.solr.common.util.ContentStream;+import org.apache.solr.common.util.EnvUtils;import org.apache.solr.common.util.SimpleOrderedMap;import org.apache.solr.common.util.Utils;import org.apache.solr.core.ConfigSetService;@@ -96,10 +97,10 @@ public class ConfigSetAPIBase extends JerseyResource {}protected void ensureConfigSetUploadEnabled() {- if (!"true".equals(System.getProperty("configset.upload.enabled", "true"))) {+ if (!EnvUtils.getPropertyAsBool("solr.configset.upload.enabled", true)) {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Configset upload feature is disabled. To enable this, start Solr with '-Dconfigset.upload.enabled=true'.");+ "Configset upload feature is disabled. To enable this, start Solr with '-Dsolr.configset.upload.enabled=true'.");}}diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.javaindex cc42e9eaf73..a652c10b84c 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java@@ -417,7 +417,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {ignoreException("Configset upload feature is disabled");for (boolean enabled : new boolean[] {true, false}) {- System.setProperty("configset.upload.enabled", String.valueOf(enabled));+ System.setProperty("solr.configset.upload.enabled", String.valueOf(enabled));try {long statusCode =uploadConfigSet("regular", "test-enabled-is-" + enabled, null, zkClient, v2);@@ -428,7 +428,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {enabled ? 0l : 400l,statusCode);} finally {- System.clearProperty("configset.upload.enabled");+ System.clearProperty("solr.configset.upload.enabled");}}unIgnoreException("Configset upload feature is disabled");diff --git a/solr/core/src/test/org/apache/solr/handler/api/V2ApiUtilsTest.java b/solr/core/src/test/org/apache/solr/handler/api/V2ApiUtilsTest.javaindex 608b28161a3..1c64f41b3db 100644--- a/solr/core/src/test/org/apache/solr/handler/api/V2ApiUtilsTest.java+++ b/solr/core/src/test/org/apache/solr/handler/api/V2ApiUtilsTest.java@@ -28,17 +28,14 @@ import org.junit.Test;public class V2ApiUtilsTest extends SolrTestCaseJ4 {@Test- public void testReadsDisableV2ApiSysprop() {- System.clearProperty("disable.v2.api");+ public void testReadsEnableV2ApiSysprop() {+ System.clearProperty("solr.api.v2.enabled");assertTrue("v2 API should be enabled if sysprop not specified", V2ApiUtils.isEnabled());- System.setProperty("disable.v2.api", "false");+ System.setProperty("solr.api.v2.enabled", "true");assertTrue("v2 API should be enabled if sysprop explicitly enables it", V2ApiUtils.isEnabled());- System.setProperty("disable.v2.api", "asdf");- assertTrue("v2 API should be enabled if sysprop has unexpected value", V2ApiUtils.isEnabled());-- System.setProperty("disable.v2.api", "true");+ System.setProperty("solr.api.v2.enabled", "false");assertFalse("v2 API should be disabled if sysprop explicitly disables it", V2ApiUtils.isEnabled());}diff --git a/solr/solr-ref-guide/modules/configuration-guide/pages/configsets-api.adoc b/solr/solr-ref-guide/modules/configuration-guide/pages/configsets-api.adocindex eeb48138a20..74f2c6751a5 100644--- a/solr/solr-ref-guide/modules/configuration-guide/pages/configsets-api.adoc+++ b/solr/solr-ref-guide/modules/configuration-guide/pages/configsets-api.adoc@@ -88,7 +88,7 @@ The output will look like:Upload a configset, which is sent as a zipped file.A single, non-zipped file can also be uploaded with the `filePath` parameter.-This functionality is enabled by default, but can be disabled via a runtime parameter `-Dconfigset.upload.enabled=false`.+This functionality is enabled by default, but can be disabled via a runtime parameter `-Dsolr.configset.upload.enabled=false`.Disabling this feature is advisable if you want to expose Solr installation to untrusted users (even though you should never do that!).A configset is uploaded in a "trusted" mode if authentication is enabled and the upload operation is performed as an authenticated request.diff --git a/solr/solr-ref-guide/modules/configuration-guide/pages/v2-api.adoc b/solr/solr-ref-guide/modules/configuration-guide/pages/v2-api.adocindex c7743122229..a9e1e8cff3c 100644--- a/solr/solr-ref-guide/modules/configuration-guide/pages/v2-api.adoc+++ b/solr/solr-ref-guide/modules/configuration-guide/pages/v2-api.adoc@@ -20,7 +20,7 @@The v2 API is a modernized self-documenting API interface covering most current Solr APIs.It is anticipated that once the v2 API reaches full coverage, and Solr-internal API usages like SolrJ and the Admin UI have been converted from the old API to the v2 API, the old API will eventually be retired.Today, the two API styles coexist, and all the old APIs will continue to work without any change.-You can disable all v2 API endpoints if desired by starting your servers with this system property: `-Ddisable.v2.api=true`.+You can disable all v2 API endpoints if desired by starting your servers with this system property: `-Dsolr.api.v2.enabled=false`.NOTE: The v2 API is classified as "experimental".It may change in backwards-incompatible ways as it evolves to cover additional functionality.diff --git a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.javaindex 6f613016cf8..28668882ad4 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java@@ -232,7 +232,9 @@ public class EnvUtils {deprecatedKey,key);setProperty(key, String.valueOf(!Boolean.getBoolean(deprecatedKey)));- } else if (deprecatedKey.equals("solr.hide.stack.trace")) {+ } else if (deprecatedKey.equals("disable.config.edit")+ || deprecatedKey.equals("disable.v2.api")+ || deprecatedKey.equals("solr.hide.stack.trace")) {log.warn("Converting from legacy system property {} to modern .enabled equivalent {} by flipping the boolean property value.",deprecatedKey,diff --git a/solr/solrj/src/resources/DeprecatedSystemPropertyMappings.properties b/solr/solrj/src/resources/DeprecatedSystemPropertyMappings.propertiesindex da2227a7b72..b63af2b47a4 100644--- a/solr/solrj/src/resources/DeprecatedSystemPropertyMappings.properties+++ b/solr/solrj/src/resources/DeprecatedSystemPropertyMappings.properties@@ -1,7 +1,7 @@# Mapping from legacy system property names to current system property# This file only contains non-standard mappings that do not follow the standard naming conversion convention# You do not need a entry for a solrMyProperty to solr.my.property conversion-# We have changed some properties from ending in .disabled to ending as .enabled.+# We have changed some properties from ending in .disabled to ending as .enabled.# In that case we programatically flip the value.# To be removed in Solr 12:@@ -19,4 +19,7 @@ solr.enable.remote.streaming=solr.requests.streaming.remote.enabledsolr.enable.stream.body=solr.requests.streaming.body.enabledsolr.delete.unknown.cores=solr.cloud.startup.delete.unknown.cores.enabledsolr.config.set.forbidden.file.types=solr.configset.forbidden.file.types+disable.config.edit=solr.api.config.edit.enabled+configset.upload.enabled=solr.configset.upload.enabled+disable.v2.api=solr.api.v2.enabledsolr.hide.stack.trace=solr.responses.stacktrace.enabled