You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2013/03/14 14:47:35 UTC
svn commit: r1456433 - in /lucene/dev/trunk/solr/core/src:
java/org/apache/solr/cloud/ java/org/apache/solr/core/ test-files/solr/
test/org/apache/solr/core/
Author: erick
Date: Thu Mar 14 13:47:35 2013
New Revision: 1456433
URL: http://svn.apache.org/r1456433
Log:
Fix for SOLR-4543, setting shardHandlerFactory in solr.xml/solr.properties does not work
Added:
lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.properties (with props)
lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.xml (with props)
lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/MockShardHandlerFactory.java (with props)
lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java (with props)
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlBackCompat.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/CoreContainer.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrProperties.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java?rev=1456433&r1=1456432&r2=1456433&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java Thu Mar 14 13:47:35 2013
@@ -190,7 +190,7 @@ public class ZkCLI {
if (isXml) {
cfg = new ConfigSolrXmlBackCompat(loader, null, is, null, false);
} else {
- cfg = new SolrProperties(null, is, null);
+ cfg = new SolrProperties(null, loader, is, null);
}
} finally {
IOUtils.closeQuietly(is);
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlBackCompat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlBackCompat.java?rev=1456433&r1=1456432&r2=1456433&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlBackCompat.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/ConfigSolrXmlBackCompat.java Thu Mar 14 13:47:35 2013
@@ -25,6 +25,7 @@ import org.apache.solr.schema.IndexSchem
import org.apache.solr.util.DOMUtil;
import org.apache.solr.util.PropertiesUtil;
import org.apache.solr.util.SystemIdResolver;
+import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.zookeeper.KeeperException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@@ -132,9 +133,16 @@ public class ConfigSolrXmlBackCompat ext
m.put("class", HttpShardHandlerFactory.class.getName());
info = new PluginInfo("shardHandlerFactory", m, null, Collections.<PluginInfo>emptyList());
}
- HttpShardHandlerFactory fac = new HttpShardHandlerFactory();
- if (info != null) {
- fac.init(info);
+
+ ShardHandlerFactory fac;
+ try {
+ fac = getResourceLoader().findClass(info.className, ShardHandlerFactory.class).newInstance();
+ } catch (Exception e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error instantiating shardHandlerFactory class " + info.className);
+ }
+ if (fac instanceof PluginInfoInitialized) {
+ ((PluginInfoInitialized) fac).init(info);
}
return fac;
}
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=1456433&r1=1456432&r2=1456433&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 Thu Mar 14 13:47:35 2013
@@ -377,7 +377,7 @@ public class CoreContainer
cfg = new ConfigSolrXmlBackCompat(loader, null, is, null, false);
this.cfg = new ConfigSolrXmlBackCompat(loader, (ConfigSolrXmlBackCompat)cfg);
} else {
- cfg = new SolrProperties(this, is, fileName);
+ cfg = new SolrProperties(this, loader, is, fileName);
this.cfg = new SolrProperties(this, loader, (SolrProperties)cfg);
}
} catch (Exception e) {
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrProperties.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrProperties.java?rev=1456433&r1=1456432&r2=1456433&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrProperties.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrProperties.java Thu Mar 14 13:47:35 2013
@@ -27,6 +27,7 @@ import org.apache.solr.handler.component
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.util.PropertiesUtil;
import org.apache.solr.util.SystemIdResolver;
+import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,13 +105,15 @@ public class SolrProperties implements C
* Create a SolrProperties object from an opened input stream, useful for creating defaults
*
* @param container - the container for this Solr instance. There should be one and only one...
+ * @param loader - Solr resource loader
* @param is - Input stream for loading properties.
* @param fileName - the name for this properties object.
* @throws IOException - It's possible to walk a very deep tree, if that process goes awry, or if reading any
* of the files found doesn't work, you'll get an IO exception
*/
- public SolrProperties(CoreContainer container, InputStream is, String fileName) throws IOException {
+ public SolrProperties(CoreContainer container, SolrResourceLoader loader, InputStream is, String fileName) throws IOException {
origsolrprops.load(is);
+ this.loader = loader;
this.container = container;
init(fileName);
}
@@ -241,29 +244,39 @@ public class SolrProperties implements C
boolean haveHandler = false;
for (String s : solrProperties.stringPropertyNames()) {
String val = solrProperties.getProperty(s);
- if (s.indexOf(SHARD_HANDLER_FACTORY) != -1) {
+ int index = s.indexOf(SHARD_HANDLER_FACTORY);
+ if (index != -1) {
haveHandler = true;
if (SHARD_HANDLER_NAME.equals(s) || SHARD_HANDLER_CLASS.equals(s)) {
- attrs.put(s, val);
+ // remove shardHandlerFactory. prefix
+ attrs.put(s.substring(SHARD_HANDLER_FACTORY.length()+1), val);
} else {
- args.add(s, val);
+ // remove shardHandlerFactory. prefix
+ args.add(s.substring(SHARD_HANDLER_FACTORY.length()+1), val);
}
}
}
if (haveHandler) {
- // public PluginInfo(String type, Map<String, String> attrs ,NamedList initArgs, List<PluginInfo> children) {
-
info = new PluginInfo(SHARD_HANDLER_FACTORY, attrs, args, null);
} else {
Map m = new HashMap();
m.put("class", HttpShardHandlerFactory.class.getName());
info = new PluginInfo("shardHandlerFactory", m, null, Collections.<PluginInfo>emptyList());
}
- HttpShardHandlerFactory fac = new HttpShardHandlerFactory();
- if (info != null) {
- fac.init(info);
+
+ assert loader != null;
+ ShardHandlerFactory fac;
+ try {
+ fac = loader.findClass(info.className, ShardHandlerFactory.class).newInstance();
+ } catch (Exception e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error instantiating shardHandlerFactory class " + info.className);
}
+ if (fac instanceof PluginInfoInitialized) {
+ ((PluginInfoInitialized) fac).init(info);
+ }
+
return fac;
}
Added: lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.properties
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.properties?rev=1456433&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.properties (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.properties Thu Mar 14 13:47:35 2013
@@ -0,0 +1,18 @@
+# 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.
+# solr.properties specifying a custom shard handler factory
+shardHandlerFactory.name=shardHandlerFactory
+shardHandlerFactory.class=org.apache.solr.core.MockShardHandlerFactory
+shardHandlerFactory.myMagicRequiredParameter=myMagicRequiredValue
Added: lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.xml?rev=1456433&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/solr-shardhandler.xml Thu Mar 14 13:47:35 2013
@@ -0,0 +1,29 @@
+<?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.
+-->
+
+<!--
+ solr.xml specifying a custom shardHandlerFactory
+-->
+<solr>
+ <cores>
+ <shardHandlerFactory name="shardHandlerFactory"
+ class="org.apache.solr.core.MockShardHandlerFactory">
+ <str name="myMagicRequiredParameter">myMagicRequiredValue</str>
+ </shardHandlerFactory>
+ </cores>
+</solr>
Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/MockShardHandlerFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/MockShardHandlerFactory.java?rev=1456433&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/MockShardHandlerFactory.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/MockShardHandlerFactory.java Thu Mar 14 13:47:35 2013
@@ -0,0 +1,65 @@
+package org.apache.solr.core;
+
+/*
+ * 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.
+ */
+
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.handler.component.ResponseBuilder;
+import org.apache.solr.handler.component.ShardHandler;
+import org.apache.solr.handler.component.ShardHandlerFactory;
+import org.apache.solr.handler.component.ShardRequest;
+import org.apache.solr.handler.component.ShardResponse;
+import org.apache.solr.util.plugin.PluginInfoInitialized;
+
+/** a fake shardhandler factory that does nothing. */
+public class MockShardHandlerFactory extends ShardHandlerFactory implements PluginInfoInitialized {
+ NamedList args;
+
+ @Override
+ public void init(PluginInfo info) {
+ args = info.initArgs;
+ }
+
+ @Override
+ public ShardHandler getShardHandler() {
+ return new ShardHandler() {
+ @Override
+ public void checkDistributed(ResponseBuilder rb) {}
+
+ @Override
+ public void submit(ShardRequest sreq, String shard,
+ ModifiableSolrParams params) {}
+
+ @Override
+ public ShardResponse takeCompletedIncludingErrors() {
+ return null;
+ }
+
+ @Override
+ public ShardResponse takeCompletedOrError() {
+ return null;
+ }
+
+ @Override
+ public void cancelAll() {}
+ };
+ }
+
+ @Override
+ public void close() {}
+}
Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java?rev=1456433&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/TestShardHandlerFactory.java Thu Mar 14 13:47:35 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.apache.solr.core;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.handler.component.ShardHandlerFactory;
+
+import java.io.File;
+
+/**
+ * Tests specifying a custom ShardHandlerFactory
+ */
+public class TestShardHandlerFactory extends SolrTestCaseJ4 {
+
+ public void testXML() throws Exception {
+ CoreContainer cc = new CoreContainer(TEST_HOME());
+ cc.load(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.xml"));
+ ShardHandlerFactory factory = cc.getShardHandlerFactory();
+ assertTrue(factory instanceof MockShardHandlerFactory);
+ NamedList args = ((MockShardHandlerFactory)factory).args;
+ assertEquals("myMagicRequiredValue", args.get("myMagicRequiredParameter"));
+ factory.close();
+ cc.shutdown();
+ }
+
+ public void testProperties() throws Exception {
+ CoreContainer cc = new CoreContainer(TEST_HOME());
+ cc.load(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler.properties"));
+ ShardHandlerFactory factory = cc.getShardHandlerFactory();
+ assertTrue(factory instanceof MockShardHandlerFactory);
+ NamedList args = ((MockShardHandlerFactory)factory).args;
+ assertEquals("myMagicRequiredValue", args.get("myMagicRequiredParameter"));
+ factory.close();
+ cc.shutdown();
+ }
+}