From b007152303cba90a5819075d711fc8e9a0c4b4e7 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Thu, 4 Jun 2009 09:08:01 +0000 Subject: [PATCH] SOLR-1051 -- Fix NPE and change comma separated indexDirs parameter to multiple indexDir parameters git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@781688 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/common/params/CoreAdminParams.java | 2 +- .../solr/handler/admin/CoreAdminHandler.java | 7 ++--- .../solrj/request/CoreAdminRequest.java | 26 ++++++++----------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/common/org/apache/solr/common/params/CoreAdminParams.java b/src/common/org/apache/solr/common/params/CoreAdminParams.java index e198227702a..4c69eaa7205 100644 --- a/src/common/org/apache/solr/common/params/CoreAdminParams.java +++ b/src/common/org/apache/solr/common/params/CoreAdminParams.java @@ -55,7 +55,7 @@ public interface CoreAdminParams /** If you merge indexes, what are the index directories. * The directories are separated by ",". */ - public final static String INDEX_DIRS = "indexDirs"; + public final static String INDEX_DIR = "indexDir"; public enum CoreAdminAction { STATUS, diff --git a/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java index 27319229c1b..7c7e00d889f 100644 --- a/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java +++ b/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java @@ -31,6 +31,7 @@ import org.apache.solr.core.DirectoryFactory; import org.apache.solr.handler.RequestHandlerBase; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryResponse; +import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.util.RefCounted; import org.apache.solr.update.MergeIndexesCommand; @@ -177,8 +178,7 @@ public class CoreAdminHandler extends RequestHandlerBase { try { doPersist = coreContainer.isPersistent(); - String p = required.get(CoreAdminParams.INDEX_DIRS); - String[] dirNames = p.split(","); + String[] dirNames = required.getParams(CoreAdminParams.INDEX_DIR); DirectoryFactory dirFactory = core.getDirectoryFactory(); Directory[] dirs = new Directory[dirNames.length]; @@ -188,8 +188,9 @@ public class CoreAdminHandler extends RequestHandlerBase { UpdateRequestProcessorChain processorChain = core.getUpdateProcessingChain(params.get(UpdateParams.UPDATE_PROCESSOR)); + SolrQueryRequest wrappedReq = new LocalSolrQueryRequest(core, req.getParams()); UpdateRequestProcessor processor = - processorChain.createProcessor(req, rsp); + processorChain.createProcessor(wrappedReq, rsp); processor.processMergeIndexes(new MergeIndexesCommand(dirs)); } finally { core.close(); diff --git a/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java index 1a284c1f008..11d7e8b25c6 100644 --- a/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java +++ b/src/solrj/org/apache/solr/client/solrj/request/CoreAdminRequest.java @@ -19,6 +19,8 @@ package org.apache.solr.client.solrj.request; import java.io.IOException; import java.util.Collection; +import java.util.List; +import java.util.Arrays; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServer; @@ -110,17 +112,17 @@ public class CoreAdminRequest extends SolrRequest } public static class MergeIndexes extends CoreAdminRequest { - protected String indexDirs; + protected List indexDirs; public MergeIndexes() { action = CoreAdminAction.MERGEINDEXES; } - public void setIndexDirs(String indexDirs) { + public void setIndexDirs(List indexDirs) { this.indexDirs = indexDirs; } - public String getIndexDirs() { + public List getIndexDirs() { return indexDirs; } @@ -132,7 +134,11 @@ public class CoreAdminRequest extends SolrRequest ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CoreAdminParams.ACTION, action.toString()); params.set(CoreAdminParams.CORE, core); - params.set(CoreAdminParams.INDEX_DIRS, indexDirs); + if (indexDirs != null) { + for (String indexDir : indexDirs) { + params.set(CoreAdminParams.INDEX_DIR, indexDir); + } + } return params; } } @@ -281,17 +287,7 @@ public class CoreAdminRequest extends SolrRequest IOException { CoreAdminRequest.MergeIndexes req = new CoreAdminRequest.MergeIndexes(); req.setCoreName(name); - String p = null; - if (indexDirs.length == 1) { - p = indexDirs[0]; - } else if (indexDirs.length > 1) { - StringBuilder s = new StringBuilder(indexDirs[0]); - for (int i = 1; i < indexDirs.length; i++) { - s.append(",").append(indexDirs[i]); - } - p = s.toString(); - } - req.setIndexDirs(p); + req.setIndexDirs(Arrays.asList(indexDirs)); return req.process(server); } }