Skip to content

Commit 3ede0ed

Browse files
authored
SOLR-17864: Migrate System Properties to modern style (#3504)
* Migrate disable.config.edit, configset.upload.enabled, and disable.v2.api * Adopt solr.api.config.edit.enabled instead of solr.configset.edit.enabled * Expand language of error message to provide clearer feedback
1 parent a31193d commit 3ede0ed

File tree

9 files changed

+28
-23
lines changed

9 files changed

+28
-23
lines changed

solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.apache.solr.common.params.ModifiableSolrParams;
7272
import org.apache.solr.common.params.SolrParams;
7373
import org.apache.solr.common.util.CommandOperation;
74+
import org.apache.solr.common.util.EnvUtils;
7475
import org.apache.solr.common.util.ExecutorUtil;
7576
import org.apache.solr.common.util.NamedList;
7677
import org.apache.solr.common.util.SolrNamedThreadFactory;
@@ -102,9 +103,9 @@
102103
public class SolrConfigHandler extends RequestHandlerBase
103104
implements SolrCoreAware, PermissionNameProvider {
104105
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
105-
public static final String CONFIGSET_EDITING_DISABLED_ARG = "disable.configEdit";
106-
public static final boolean configEditing_disabled =
107-
Boolean.getBoolean(CONFIGSET_EDITING_DISABLED_ARG);
106+
public static final String CONFIG_EDITING_ENABLED_ARG = "solr.api.config.edit.enabled";
107+
public static final boolean configEditingEnabled =
108+
EnvUtils.getPropertyAsBool(CONFIG_EDITING_ENABLED_ARG, true);
108109
private static final Map<String, SolrConfig.SolrPluginInfo> namedPlugins;
109110
private final Lock reloadLock = new ReentrantLock(true);
110111

@@ -132,11 +133,11 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
132133
String httpMethod = (String) req.getContext().get("httpMethod");
133134
Command command = new Command(req, rsp, httpMethod);
134135
if ("POST".equals(httpMethod)) {
135-
if (configEditing_disabled || isImmutableConfigSet) {
136+
if (!configEditingEnabled || isImmutableConfigSet) {
136137
final String reason =
137-
configEditing_disabled
138-
? "due to " + CONFIGSET_EDITING_DISABLED_ARG
139-
: "because ConfigSet is immutable";
138+
!configEditingEnabled
139+
? "due to " + CONFIG_EDITING_ENABLED_ARG + " setting"
140+
: "because ConfigSet is marked immutable";
140141
throw new SolrException(
141142
SolrException.ErrorCode.FORBIDDEN, " solrconfig editing is not enabled " + reason);
142143
}

solr/core/src/java/org/apache/solr/handler/api/V2ApiUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.solr.client.api.model.SolrJerseyResponse;
2929
import org.apache.solr.common.MapWriter.EntryWriter;
3030
import org.apache.solr.common.params.SolrParams;
31+
import org.apache.solr.common.util.EnvUtils;
3132
import org.apache.solr.common.util.NamedList;
3233
import org.apache.solr.common.util.StrUtils;
3334
import org.apache.solr.common.util.Utils;
@@ -41,7 +42,7 @@ private V2ApiUtils() {
4142
}
4243

4344
public static boolean isEnabled() {
44-
return !"true".equals(System.getProperty("disable.v2.api", "false"));
45+
return EnvUtils.getPropertyAsBool("solr.api.v2.enabled", true);
4546
}
4647

4748
public static void flattenMapWithPrefix(

solr/core/src/java/org/apache/solr/handler/configsets/ConfigSetAPIBase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.solr.common.cloud.ZkNodeProps;
3737
import org.apache.solr.common.params.ConfigSetParams;
3838
import org.apache.solr.common.util.ContentStream;
39+
import org.apache.solr.common.util.EnvUtils;
3940
import org.apache.solr.common.util.SimpleOrderedMap;
4041
import org.apache.solr.common.util.Utils;
4142
import org.apache.solr.core.ConfigSetService;
@@ -96,10 +97,10 @@ protected void runConfigSetCommand(
9697
}
9798

9899
protected void ensureConfigSetUploadEnabled() {
99-
if (!"true".equals(System.getProperty("configset.upload.enabled", "true"))) {
100+
if (!EnvUtils.getPropertyAsBool("solr.configset.upload.enabled", true)) {
100101
throw new SolrException(
101102
SolrException.ErrorCode.BAD_REQUEST,
102-
"Configset upload feature is disabled. To enable this, start Solr with '-Dconfigset.upload.enabled=true'.");
103+
"Configset upload feature is disabled. To enable this, start Solr with '-Dsolr.configset.upload.enabled=true'.");
103104
}
104105
}
105106

solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public void testUploadDisabled(boolean v2) throws Exception {
417417

418418
ignoreException("Configset upload feature is disabled");
419419
for (boolean enabled : new boolean[] {true, false}) {
420-
System.setProperty("configset.upload.enabled", String.valueOf(enabled));
420+
System.setProperty("solr.configset.upload.enabled", String.valueOf(enabled));
421421
try {
422422
long statusCode =
423423
uploadConfigSet("regular", "test-enabled-is-" + enabled, null, zkClient, v2);
@@ -428,7 +428,7 @@ public void testUploadDisabled(boolean v2) throws Exception {
428428
enabled ? 0l : 400l,
429429
statusCode);
430430
} finally {
431-
System.clearProperty("configset.upload.enabled");
431+
System.clearProperty("solr.configset.upload.enabled");
432432
}
433433
}
434434
unIgnoreException("Configset upload feature is disabled");

solr/core/src/test/org/apache/solr/handler/api/V2ApiUtilsTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@
2828
public class V2ApiUtilsTest extends SolrTestCaseJ4 {
2929

3030
@Test
31-
public void testReadsDisableV2ApiSysprop() {
32-
System.clearProperty("disable.v2.api");
31+
public void testReadsEnableV2ApiSysprop() {
32+
System.clearProperty("solr.api.v2.enabled");
3333
assertTrue("v2 API should be enabled if sysprop not specified", V2ApiUtils.isEnabled());
3434

35-
System.setProperty("disable.v2.api", "false");
35+
System.setProperty("solr.api.v2.enabled", "true");
3636
assertTrue("v2 API should be enabled if sysprop explicitly enables it", V2ApiUtils.isEnabled());
3737

38-
System.setProperty("disable.v2.api", "asdf");
39-
assertTrue("v2 API should be enabled if sysprop has unexpected value", V2ApiUtils.isEnabled());
40-
41-
System.setProperty("disable.v2.api", "true");
38+
System.setProperty("solr.api.v2.enabled", "false");
4239
assertFalse(
4340
"v2 API should be disabled if sysprop explicitly disables it", V2ApiUtils.isEnabled());
4441
}

solr/solr-ref-guide/modules/configuration-guide/pages/configsets-api.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ The output will look like:
8888
Upload a configset, which is sent as a zipped file.
8989
A single, non-zipped file can also be uploaded with the `filePath` parameter.
9090

91-
This functionality is enabled by default, but can be disabled via a runtime parameter `-Dconfigset.upload.enabled=false`.
91+
This functionality is enabled by default, but can be disabled via a runtime parameter `-Dsolr.configset.upload.enabled=false`.
9292
Disabling this feature is advisable if you want to expose Solr installation to untrusted users (even though you should never do that!).
9393

9494
A configset is uploaded in a "trusted" mode if authentication is enabled and the upload operation is performed as an authenticated request.

solr/solr-ref-guide/modules/configuration-guide/pages/v2-api.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
The v2 API is a modernized self-documenting API interface covering most current Solr APIs.
2121
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.
2222
Today, the two API styles coexist, and all the old APIs will continue to work without any change.
23-
You can disable all v2 API endpoints if desired by starting your servers with this system property: `-Ddisable.v2.api=true`.
23+
You can disable all v2 API endpoints if desired by starting your servers with this system property: `-Dsolr.api.v2.enabled=false`.
2424

2525
NOTE: The v2 API is classified as "experimental".
2626
It may change in backwards-incompatible ways as it evolves to cover additional functionality.

solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ static synchronized void init(
232232
deprecatedKey,
233233
key);
234234
setProperty(key, String.valueOf(!Boolean.getBoolean(deprecatedKey)));
235-
} else if (deprecatedKey.equals("solr.hide.stack.trace")) {
235+
} else if (deprecatedKey.equals("disable.config.edit")
236+
|| deprecatedKey.equals("disable.v2.api")
237+
|| deprecatedKey.equals("solr.hide.stack.trace")) {
236238
log.warn(
237239
"Converting from legacy system property {} to modern .enabled equivalent {} by flipping the boolean property value.",
238240
deprecatedKey,

solr/solrj/src/resources/DeprecatedSystemPropertyMappings.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Mapping from legacy system property names to current system property
22
# This file only contains non-standard mappings that do not follow the standard naming conversion convention
33
# You do not need a entry for a solrMyProperty to solr.my.property conversion
4-
# We have changed some properties from ending in .disabled to ending as .enabled.
4+
# We have changed some properties from ending in .disabled to ending as .enabled.
55
# In that case we programatically flip the value.
66

77
# To be removed in Solr 12:
@@ -19,4 +19,7 @@ solr.enable.remote.streaming=solr.requests.streaming.remote.enabled
1919
solr.enable.stream.body=solr.requests.streaming.body.enabled
2020
solr.delete.unknown.cores=solr.cloud.startup.delete.unknown.cores.enabled
2121
solr.config.set.forbidden.file.types=solr.configset.forbidden.file.types
22+
disable.config.edit=solr.api.config.edit.enabled
23+
configset.upload.enabled=solr.configset.upload.enabled
24+
disable.v2.api=solr.api.v2.enabled
2225
solr.hide.stack.trace=solr.responses.stacktrace.enabled

0 commit comments

Comments
 (0)