Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15349: Remove solrcore.properties support (#3905)

Eric Pugh4bbbe20898c4
diff --git a/changelog/unreleased/SOLR-15349.yml b/changelog/unreleased/SOLR-15349.yml
new file mode 100644
index 00000000000..1ff94edae68
--- /dev/null
+++ b/changelog/unreleased/SOLR-15349.yml
@@ -0,0 +1,8 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+title: Remove solrcore.properties support
+type: removed # added, changed, fixed, deprecated, removed, dependency_update, security, other
+authors:
+ - name: Eric Pugh
+links:
+ - name: SOLR-15349
+ url: https://issues.apache.org/jira/browse/SOLR-15349
diff --git a/gradle/testing/randomization/policies/solr-tests.policy b/gradle/testing/randomization/policies/solr-tests.policy
index 8daf6cf43ab..d95d4b245dc 100644
--- a/gradle/testing/randomization/policies/solr-tests.policy
+++ b/gradle/testing/randomization/policies/solr-tests.policy
@@ -32,9 +32,6 @@ grant {
permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete";
permission java.io.FilePermission "${tests.linedocsfile}", "read";
- // DirectoryFactoryTest messes with these (wtf?)
- permission java.io.FilePermission "/tmp/inst1/conf/solrcore.properties", "read";
- permission java.io.FilePermission "/path/to/myinst/conf/solrcore.properties", "read";
// TestConfigSets messes with these (wtf?)
permission java.io.FilePermission "/path/to/solr/home/lib", "read";
diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
index d38c5ff0b35..e4dca2930fe 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
@@ -61,9 +61,6 @@ public class CoreDescriptor {
public static final String CORE_CONFIGSET_PROPERTIES = "configSetProperties";
public static final String SOLR_CORE_PROP_PREFIX = "solr.core.";
- public static final String DEFAULT_EXTERNAL_PROPERTIES_FILE =
- "conf" + FileSystems.getDefault().getSeparator() + "solrcore.properties";
-
/**
* Get the standard properties in persistable form
*
@@ -219,14 +216,16 @@ public class CoreDescriptor {
/**
* Load properties specified in an external properties file.
*
- * <p>The file to load can be specified in a {@code properties} property on the original
- * Properties object used to create this CoreDescriptor. If this has not been set, then we look
- * for {@code conf/solrcore.properties} underneath the instance dir.
+ * <p>The file to load is specified in a {@code properties} property on the original Properties
+ * object used to create this CoreDescriptor.
*
* <p>File paths are taken as read from the core's instance directory if they are not absolute.
*/
protected void loadExtraProperties() {
- String filename = coreProperties.getProperty(CORE_PROPERTIES, DEFAULT_EXTERNAL_PROPERTIES_FILE);
+ String filename = coreProperties.getProperty(CORE_PROPERTIES);
+ if (filename == null) {
+ return;
+ }
Path propertiesFile = instanceDir.resolve(filename);
if (Files.exists(propertiesFile)) {
try (Reader r = Files.newBufferedReader(propertiesFile, StandardCharsets.UTF_8)) {
diff --git a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java
similarity index 73%
rename from solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
rename to solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java
index aad315e3eb9..4173d80d5ab 100644
--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
+++ b/solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java
@@ -24,29 +24,29 @@ import java.util.Properties;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
/**
- * Test for Loading core properties from a properties file
- *
- * @since solr 1.4
+ * Test for Loading a custom core properties file referenced from the standard core.properties file.
*/
-public class TestSolrCoreProperties extends SolrJettyTestBase {
+public class TestCustomCoreProperties extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrClientTestRule = new SolrJettyTestRule();
// TODO these properties files don't work with configsets
@BeforeClass
- public static void beforeTest() throws Exception {
+ public static void beforeClass() throws Exception {
Path homeDir = createTempDir();
Path collDir = homeDir.resolve("collection1");
- Path dataDir = collDir.resolve("data");
Path confDir = collDir.resolve("conf");
- Files.createDirectories(homeDir);
- Files.createDirectories(collDir);
- Files.createDirectories(dataDir);
Files.createDirectories(confDir);
Files.copy(SolrTestCaseJ4.TEST_HOME().resolve("solr.xml"), homeDir.resolve("solr.xml"));
@@ -61,12 +61,17 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {
Properties p = new Properties();
p.setProperty("foo.foo1", "f1");
p.setProperty("foo.foo2", "f2");
- try (Writer fos =
- Files.newBufferedWriter(confDir.resolve("solrcore.properties"), StandardCharsets.UTF_8)) {
+ var coreCustomProperties = confDir.resolve("core_custom_properties.properties");
+ try (Writer fos = Files.newBufferedWriter(coreCustomProperties, StandardCharsets.UTF_8)) {
p.store(fos, null);
}
- Files.createFile(collDir.resolve("core.properties"));
+ Properties coreProperties = new Properties();
+ coreProperties.setProperty(CoreDescriptor.CORE_PROPERTIES, coreCustomProperties.toString());
+ try (Writer fos =
+ Files.newBufferedWriter(collDir.resolve("core.properties"), StandardCharsets.UTF_8)) {
+ coreProperties.store(fos, null);
+ }
Properties nodeProperties = new Properties();
// this sets the property for jetty starting SolrDispatchFilter
@@ -75,16 +80,15 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {
}
solrClientTestRule.startSolr(homeDir, nodeProperties, JettyConfig.builder().build());
-
- // createJetty(homeDir.getAbsolutePath(), null, null);
}
+ @Test
public void testSimple() throws Exception {
SolrParams params =
params(
"q", "*:*",
"echoParams", "all");
- QueryResponse res = getSolrClient().query(params);
+ QueryResponse res = solrClientTestRule.getSolrClient("collection1").query(params);
assertEquals(0, res.getResults().getNumFound());
NamedList<?> echoedParams = (NamedList<?>) res.getHeader().get("params");
diff --git a/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java b/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java
index 0438df638fe..f84a00e45d8 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java
@@ -16,8 +16,6 @@
*/
package org.apache.solr.core;
-import java.io.BufferedWriter;
-import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -25,54 +23,86 @@ import java.nio.file.Path;
import java.util.Properties;
import org.apache.commons.io.file.PathUtils;
import org.apache.solr.SolrTestCaseJ4;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestCorePropertiesReload extends SolrTestCaseJ4 {
- private final Path solrHomeDirectory = createTempDir();
+ private static Path solrHomeDirectory;
+ private static CoreContainer coreContainer;
- public void setMeUp() throws Exception {
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ solrHomeDirectory = createTempDir();
PathUtils.copyDirectory(TEST_HOME(), solrHomeDirectory);
+
+ System.setProperty("solr.test.sys.prop1", "propone");
+ System.setProperty("solr.test.sys.prop2", "proptwo");
Properties props = new Properties();
props.setProperty("test", "Before reload");
- writeProperties(props);
- initCore("solrconfig.xml", "schema.xml", solrHomeDirectory);
+ writeCustomProperties(props);
+
+ writeCoreProperties();
+ String solrXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<solr></solr>";
+
+ coreContainer = createCoreContainer(solrHomeDirectory, solrXml);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ if (coreContainer != null) {
+ coreContainer.shutdown();
+ coreContainer = null;
+ }
}
@Test
public void testPropertiesReload() throws Exception {
- setMeUp();
- SolrCore core = h.getCore();
- CoreDescriptor coreDescriptor = core.getCoreDescriptor();
- String testProp = coreDescriptor.getCoreProperty("test", null);
- assertEquals("Before reload", testProp);
+ try (SolrCore core = coreContainer.getCore("collection1")) {
+ assertNotNull("Core collection1 should exist", core);
+ CoreDescriptor coreDescriptor = core.getCoreDescriptor();
+ String testProp = coreDescriptor.getCoreProperty("test", null);
+ assertEquals("Before reload", testProp);
+ }
- // Re-write the properties file
Properties props = new Properties();
props.setProperty("test", "After reload");
- writeProperties(props);
+ writeCustomProperties(props);
- h.reload();
- core = h.getCore();
- coreDescriptor = core.getCoreDescriptor();
+ coreContainer.reload("collection1");
- testProp = coreDescriptor.getCoreProperty("test", null);
- assertEquals("After reload", testProp);
+ try (SolrCore core = coreContainer.getCore("collection1")) {
+ CoreDescriptor coreDescriptor = core.getCoreDescriptor();
+ String testProp = coreDescriptor.getCoreProperty("test", null);
+ assertEquals("After reload", testProp);
+ }
}
- private void writeProperties(Properties props) throws Exception {
- Writer out = null;
- try {
- Path confDir = solrHomeDirectory.resolve("collection1").resolve("conf");
- out =
- new BufferedWriter(
- new OutputStreamWriter(
- Files.newOutputStream(confDir.resolve("solrcore.properties")),
- StandardCharsets.UTF_8));
- props.store(out, "Reload Test");
-
- } finally {
- out.close();
+ private static void writeCoreProperties() throws Exception {
+ Path coreDir = solrHomeDirectory.resolve("collection1");
+ Path propFile = coreDir.resolve("core.properties");
+
+ Files.createDirectories(coreDir);
+ Properties coreProps = new Properties();
+ coreProps.setProperty(CoreDescriptor.CORE_NAME, "collection1");
+ coreProps.setProperty(CoreDescriptor.CORE_CONFIG, "solrconfig.xml");
+ coreProps.setProperty(CoreDescriptor.CORE_SCHEMA, "schema.xml");
+ coreProps.setProperty(CoreDescriptor.CORE_PROPERTIES, "custom.properties");
+
+ try (Writer out = Files.newBufferedWriter(propFile, StandardCharsets.UTF_8)) {
+ coreProps.store(out, null);
+ }
+ }
+
+ private static void writeCustomProperties(Properties props) throws Exception {
+ Path coreDir = solrHomeDirectory.resolve("collection1");
+ Path propFile = coreDir.resolve("custom.properties");
+
+ Files.createDirectories(coreDir);
+
+ try (Writer out = Files.newBufferedWriter(propFile, StandardCharsets.UTF_8)) {
+ props.store(out, null);
}
}
}
diff --git a/solr/server/etc/security.policy b/solr/server/etc/security.policy
index bc95bc46fae..d6cdc107fbb 100644
--- a/solr/server/etc/security.policy
+++ b/solr/server/etc/security.policy
@@ -42,9 +42,6 @@ grant {
permission java.io.FilePermission "${user.home}${/}.ivy2${/}cache${/}-", "read";
permission java.io.FilePermission "${tests.linedocsfile}", "read";
- // DirectoryFactoryTest messes with these (wtf?)
- permission java.io.FilePermission "/tmp/inst1/conf/solrcore.properties", "read";
- permission java.io.FilePermission "/path/to/myinst/conf/solrcore.properties", "read";
// TestConfigSets messes with these (wtf?)
permission java.io.FilePermission "/path/to/solr/home/lib", "read";
diff --git a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
index 977b54989cd..c058e7e47c2 100644
--- a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
+++ b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc
@@ -213,6 +213,8 @@ Nowadays, the HTTP request is available via internal APIs: `SolrQueryRequest.get
* The deprecated `LowerCaseTokenizer` and `LowerCaseTokenizerFactory` have been removed. These classes were deprecated in Solr 8 and can be replaced by combining `LetterTokenizerFactory` with `LowerCaseFilterFactory`.
+* The deprecated 'solrcore.properties` configuration method has been removed. The ability to configure a core via a custom properties file using the `core.proprties` "property" setting remains.
+
=== Security
* There is no longer a distinction between trusted and untrusted configSets; all configSets are now considered trusted. To ensure security, Solr should be properly protected using authentication and authorization mechanisms, allowing only authorized users with administrative privileges to publish them.