Apache Lucene open-source search software
SOLR-5162: Add back core implicit properties
Alan Woodwardb669bf3a7c59
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b85660d5745..509e2c6807d 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -151,8 +151,8 @@ Other ChangesThe solr.clustering.enabled system property is set to 'true' by default.(ehatcher, Dawid Weiss)-* SOLR-4914: Factor out core list persistence and discovery into a- new CoresLocator interface. (Alan Woodward)+* SOLR-4914, SOLR-5162: Factor out core list persistence and discovery into a+ new CoresLocator interface. (Alan Woodward, Shawn Heisey)* SOLR-5056: Improve type safety of ConfigSolr class. (Alan Woodward)diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 80cc43510f3..cba18618b07 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -480,7 +480,7 @@ public class CoreContainer {SolrResourceLoader solrLoader = null;SolrConfig config = null;- solrLoader = new SolrResourceLoader(instanceDir, loader.getClassLoader(), dcore.getCoreProperties());+ solrLoader = new SolrResourceLoader(instanceDir, loader.getClassLoader(), dcore.getSubstitutableProperties());try {config = new SolrConfig(solrLoader, dcore.getConfigName(), null);} catch (Exception e) {@@ -646,7 +646,7 @@ public class CoreContainer {SolrResourceLoader solrLoader;if(zkSys.getZkController() == null) {solrLoader = new SolrResourceLoader(instanceDir.getAbsolutePath(), loader.getClassLoader(),- cd.getCoreProperties());+ cd.getSubstitutableProperties());} else {try {String collection = cd.getCloudDescriptor().getCollectionName();@@ -659,7 +659,7 @@ public class CoreContainer {"Could not find config name for collection:" + collection);}solrLoader = new ZkSolrResourceLoader(instanceDir.getAbsolutePath(), zkConfigName, loader.getClassLoader(),- cd.getCoreProperties(), zkSys.getZkController());+ cd.getSubstitutableProperties(), zkSys.getZkController());} catch (KeeperException e) {log.error("", e);throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.javaindex fb94ab16101..71e1a7c8926 100644--- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java+++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java@@ -119,6 +119,9 @@ public class CoreDescriptor {/** The properties for this core, as available through getProperty() */protected final Properties coreProperties = new Properties();+ /** The properties for this core, substitutable by resource loaders */+ protected final Properties substitutableProperties = new Properties();+/*** Create a new CoreDescriptor.* @param container the CoreDescriptor's container@@ -160,6 +163,7 @@ public class CoreDescriptor {}loadExtraProperties();+ buildSubstitutableProperties();// TODO maybe make this a CloudCoreDescriptor subclass?if (container.isZooKeeperAware()) {@@ -201,6 +205,20 @@ public class CoreDescriptor {}}+ /**+ * Create the properties object used by resource loaders, etc, for property+ * substitution. The default solr properties are prefixed with 'solr.core.', so,+ * e.g., 'name' becomes 'solr.core.name'+ */+ protected void buildSubstitutableProperties() {+ for (String propName : coreProperties.stringPropertyNames()) {+ String propValue = coreProperties.getProperty(propName);+ if (!isUserDefinedProperty(propName))+ propName = "solr.core." + propName;+ substitutableProperties.setProperty(propName, propValue);+ }+ }+protected File resolvePaths(String filepath) {File file = new File(filepath);if (file.isAbsolute())@@ -336,11 +354,11 @@ public class CoreDescriptor {}/**- * Returns all properties defined on this CoreDescriptor- * @return all properties defined on this CoreDescriptor+ * Returns all substitutable properties defined on this CoreDescriptor+ * @return all substitutable properties defined on this CoreDescriptor*/- public Properties getCoreProperties() {- return coreProperties;+ public Properties getSubstitutableProperties() {+ return substitutableProperties;}@Overridediff --git a/solr/core/src/java/org/apache/solr/core/ZkContainer.java b/solr/core/src/java/org/apache/solr/core/ZkContainer.javaindex 7440dba7c8a..ab349612045 100644--- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java+++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java@@ -227,7 +227,7 @@ public class ZkContainer {"Could not find config name for collection:" + collection);}solrLoader = new ZkSolrResourceLoader(instanceDir, zkConfigName,- loader.getClassLoader(), dcore.getCoreProperties(), zkController);+ loader.getClassLoader(), dcore.getSubstitutableProperties(), zkController);config = getSolrConfigFromZk(zkConfigName, dcore.getConfigName(),solrLoader);schema = IndexSchemaFactory.buildIndexSchema(dcore.getSchemaName(),diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xmlnew file mode 100644index 00000000000..ddd8e5cc3f7--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml@@ -0,0 +1,75 @@+<?xml version="1.0" encoding="UTF-8" ?>++<!--+ 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.+ -->++ <!-- For testing, I need to create some custom directories on the fly, particularly for some of the new+ discovery-based core configuration. Trying a minimal configuration to cut down the setup time.+ use in conjunction with schema-minimal.xml perhaps? -->+<config>+ <luceneMatchVersion>LUCENE_41</luceneMatchVersion>++ <dataDir>${solr.data.dir:}</dataDir>++ <directoryFactory name="DirectoryFactory"+ class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/>++ <xi:include href="./solrconfig.snippet.randomindexconfig.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>++ <jmx/>+ <updateHandler class="solr.DirectUpdateHandler2">+ <!--updateLog>+ <str name="dir">${solr.ulog.dir:}</str>+ </updateLog-->+ </updateHandler>++ <query>+ <enableLazyFieldLoading>true</enableLazyFieldLoading>+ <queryResultWindowSize>20</queryResultWindowSize>+ <queryResultMaxDocsCached>20</queryResultMaxDocsCached>++ <useColdSearcher>true</useColdSearcher>++ <maxWarmingSearchers>1</maxWarmingSearchers>++ </query>++ <requestHandler name="/admin/" class="solr.admin.AdminHandlers" />++ <requestDispatcher handleSelect="false">+ <httpCaching never304="true"/>+ </requestDispatcher>++ <requestHandler name="/select" class="solr.SearchHandler">+ <lst name="defaults">+ <str name="echoParams">all</str>+ <str name="df">text</str>+ <str name="dummyParam">${solr.core.name}</str>+ </lst>++ </requestHandler>+ <requestHandler name="/update" class="solr.UpdateRequestHandler">+ </requestHandler>++ <queryResponseWriter name="json" class="solr.JSONResponseWriter">+ <!-- For the purposes of the tutorial, JSON responses are written as+ plain text so that they are easy to read in *any* browser.+ If you expect a MIME type of "application/json" just remove this override.+ -->+ <str name="content-type">text/plain; charset=UTF-8</str>+ </queryResponseWriter>+</config>diff --git a/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java b/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.javanew file mode 100644index 00000000000..8c6e30ee22d--- /dev/null+++ b/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java@@ -0,0 +1,40 @@+package org.apache.solr.core;++import org.apache.solr.SolrTestCaseJ4;+import org.junit.Test;++/**+ * Copyright (c) 2013 Lemur Consulting Ltd.+ * <p/>+ * Licensed 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+ * <p/>+ * http://www.apache.org/licenses/LICENSE-2.0+ * <p/>+ * 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.+ */+public class TestImplicitCoreProperties extends SolrTestCaseJ4 {++ public static final String SOLRXML =+ "<solr><cores><core name=\"collection1\" instanceDir=\"collection1\" config=\"solrconfig-implicitproperties.xml\"/></cores></solr>";++ @Test+ public void testImplicitPropertiesAreSubstitutedInSolrConfig() {++ CoreContainer cc = createCoreContainer(TEST_HOME(), SOLRXML);+ try {+ cc.load();+ assertQ(req("q", "*:*"), "//str[@name='dummyParam'][.='collection1']");+ }+ finally {+ cc.shutdown();+ }++ }++}