You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2011/08/18 23:13:57 UTC
svn commit: r1159418 - in /lucene/dev/trunk/solr: ./
core/src/java/org/apache/solr/handler/admin/
core/src/test/org/apache/solr/handler/admin/
solrj/src/java/org/apache/solr/common/params/
Author: hossman
Date: Thu Aug 18 21:13:56 2011
New Revision: 1159418
URL: http://svn.apache.org/viewvc?rev=1159418&view=rev
Log:
SOLR-2675: CoreAdminHandler now allows arbitrary properties to be specified when CREATEing a new SolrCore using property.* request params
Added:
lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1159418&r1=1159417&r2=1159418&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Aug 18 21:13:56 2011
@@ -377,6 +377,10 @@ New Features
relevant document of each group matching the query. This feature has the
same impact on the StatsComponent. (Martijn van Groningen)
+* SOLR-2675: CoreAdminHandler now allows arbitrary properties to be
+ specified when CREATEing a new SolrCore using property.* request
+ params. (Yury Kats, hossman)
+
Optimizations
----------------------
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=1159418&r1=1159417&r2=1159418&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java Thu Aug 18 21:13:56 2011
@@ -46,6 +46,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.Date;
+import java.util.Iterator;
+import java.util.Properties;
/**
*
@@ -319,8 +321,20 @@ public class CoreAdminHandler extends Re
if (opts != null)
cd.setShardId(opts);
}
-
- dcore.setCoreProperties(null);
+
+ // Process all property.name=value parameters and set them as name=value core properties
+ Properties coreProperties = new Properties();
+ Iterator<String> parameterNamesIterator = params.getParameterNamesIterator();
+ while (parameterNamesIterator.hasNext()) {
+ String parameterName = parameterNamesIterator.next();
+ if(parameterName.startsWith(CoreAdminParams.PROPERTY_PREFIX)) {
+ String parameterValue = params.get(parameterName);
+ String propertyName = parameterName.substring(CoreAdminParams.PROPERTY_PREFIX.length()); // skip prefix
+ coreProperties.put(propertyName, parameterValue);
+ }
+ }
+ dcore.setCoreProperties(coreProperties);
+
SolrCore core = coreContainer.create(dcore);
coreContainer.register(name, core, false);
rsp.add("core", core.getName());
Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java?rev=1159418&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java Thu Aug 18 21:13:56 2011
@@ -0,0 +1,117 @@
+/**
+ * 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.handler.admin;
+
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.response.SolrQueryResponse;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.xml.xpath.XPathExpressionException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.solr.SolrTestCaseJ4;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig.xml", "schema.xml");
+ }
+
+ @Test
+ public void testCoreAdminHandler() throws Exception {
+ final File workDir = new File(TEMP_DIR, this.getClass().getName());
+
+ if (workDir.exists()) {
+ FileUtils.deleteDirectory(workDir);
+ }
+ assertTrue("Failed to mkdirs workDir", workDir.mkdirs());
+
+ final CoreContainer cores = h.getCoreContainer();
+ cores.setPersistent(false); // we'll do this explicitly as needed
+
+ final CoreAdminHandler admin = new CoreAdminHandler(cores);
+
+ String instDir = null;
+ {
+ SolrCore template = null;
+ try {
+ template = cores.getCore("collection1");
+ instDir = template.getCoreDescriptor().getInstanceDir();
+ } finally {
+ if (null != template) template.close();
+ }
+ }
+
+ final File instDirFile = new File(instDir);
+ assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists());
+ final File instPropFile = new File(workDir, "instProp");
+ FileUtils.copyDirectory(instDirFile, instPropFile);
+
+ // create a new core (using CoreAdminHandler) w/ properties
+
+ SolrQueryResponse resp = new SolrQueryResponse();
+ admin.handleRequestBody
+ (req(CoreAdminParams.ACTION,
+ CoreAdminParams.CoreAdminAction.CREATE.toString(),
+ CoreAdminParams.INSTANCE_DIR, instPropFile.getAbsolutePath(),
+ CoreAdminParams.NAME, "props",
+ CoreAdminParams.PROPERTY_PREFIX + "hoss","man",
+ CoreAdminParams.PROPERTY_PREFIX + "foo","baz"),
+ resp);
+ assertNull("Exception on create", resp.getException());
+
+ // verify props are in persisted file
+
+ final File xml = new File(workDir, "persist-solr.xml");
+ cores.persistFile(xml);
+
+ assertXmlFile
+ (xml
+ ,"/solr/cores/core[@name='props']/property[@name='hoss' and @value='man']"
+ ,"/solr/cores/core[@name='props']/property[@name='foo' and @value='baz']"
+ );
+
+ }
+
+
+ public void assertXmlFile(final File file, String... xpath)
+ throws IOException, SAXException {
+
+ try {
+ String xml = FileUtils.readFileToString(file, "UTF-8");
+ String results = h.validateXPath(xml, xpath);
+ if (null != results) {
+ String msg = "File XPath failure: file=" + file.getPath() + " xpath="
+ + results + "\n\nxml was: " + xml;
+ fail(msg);
+ }
+ } catch (XPathExpressionException e2) {
+ throw new RuntimeException("XPath is invalid", e2);
+ }
+ }
+
+}
Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java?rev=1159418&r1=1159417&r2=1159418&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java Thu Aug 18 21:13:56 2011
@@ -68,6 +68,9 @@ public interface CoreAdminParams
/** The shard id in solr cloud */
public final static String SHARD = "shard";
+
+ /** Prefix for core property name=value pair **/
+ public final static String PROPERTY_PREFIX = "property.";
/** If you unload a core, delete the index too */
public final static String DELETE_INDEX = "deleteIndex";