You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2013/08/17 20:49:51 UTC

svn commit: r1515032 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/core/ core/src/test-files/solr/collection1/conf/ core/src/test/org/apache/solr/core/

Author: romseygeek
Date: Sat Aug 17 18:49:50 2013
New Revision: 1515032

URL: http://svn.apache.org/r1515032
Log:
SOLR-5162: Add back core implicit properties

Added:
    lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml   (with props)
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java   (with props)
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ZkContainer.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1515032&r1=1515031&r2=1515032&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Sat Aug 17 18:49:50 2013
@@ -151,8 +151,8 @@ Other Changes
   The 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)
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java?rev=1515032&r1=1515031&r2=1515032&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java Sat Aug 17 18:49:50 2013
@@ -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,

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java?rev=1515032&r1=1515031&r2=1515032&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java Sat Aug 17 18:49:50 2013
@@ -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;
   }
 
   @Override

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ZkContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ZkContainer.java?rev=1515032&r1=1515031&r2=1515032&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ZkContainer.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ZkContainer.java Sat Aug 17 18:49:50 2013
@@ -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(),

Added: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml?rev=1515032&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml Sat Aug 17 18:49:50 2013
@@ -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>

Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java?rev=1515032&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestImplicitCoreProperties.java Sat Aug 17 18:49:50 2013
@@ -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();
+    }
+
+  }
+
+}