You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2020/09/16 06:36:42 UTC
[lucene-solr] 07/07: all tests pass
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch jira/solr14871
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit b2a6060615fd7134bdca293e1e78534dcfaf6124
Author: noblepaul <no...@gmail.com>
AuthorDate: Wed Sep 16 16:36:01 2020 +1000
all tests pass
---
.../java/org/apache/solr/core/CoreContainer.java | 2 +-
.../java/org/apache/solr/handler/ClusterAPI.java | 23 +++++---
.../solr/handler/admin/CollectionsHandler.java | 63 ++++++++++++----------
.../solr/handler/admin/TestCollectionAPIs.java | 10 ++++
4 files changed, 60 insertions(+), 38 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index e060896..e8fed0c 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -720,7 +720,7 @@ public class CoreContainer {
createHandler(ZK_PATH, ZookeeperInfoHandler.class.getName(), ZookeeperInfoHandler.class);
createHandler(ZK_STATUS_PATH, ZookeeperStatusHandler.class.getName(), ZookeeperStatusHandler.class);
collectionsHandler = createHandler(COLLECTIONS_HANDLER_PATH, cfg.getCollectionsHandlerClass(), CollectionsHandler.class);
- ClusterAPI clusterAPI = new ClusterAPI(this);
+ ClusterAPI clusterAPI = new ClusterAPI(collectionsHandler);
containerHandlers.getApiBag().registerObject(clusterAPI);
containerHandlers.getApiBag().registerObject(clusterAPI.commands);
/*
diff --git a/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java b/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
index d47aa80..8d1fcae 100644
--- a/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
+++ b/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
@@ -28,7 +28,7 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.annotation.JsonProperty;
import org.apache.solr.common.cloud.ClusterProperties;
import org.apache.solr.common.params.DefaultSolrParams;
-import org.apache.solr.common.params.MapSolrParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ReflectMapWriter;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreContainer;
@@ -49,11 +49,13 @@ import static org.apache.solr.security.PermissionNameProvider.Name.COLL_READ_PER
public class ClusterAPI {
private final CoreContainer coreContainer;
+ private final CollectionsHandler collectionsHandler;
public final Commands commands = new Commands();
- public ClusterAPI(CoreContainer coreContainer) {
- this.coreContainer = coreContainer;
+ public ClusterAPI(CollectionsHandler ch) {
+ this.collectionsHandler = ch;
+ this.coreContainer = ch.getCoreContainer();
}
@@ -87,7 +89,12 @@ public class ClusterAPI {
@SuppressWarnings({"unchecked", "rawtypes"})
public static SolrQueryRequest wrapParams(SolrQueryRequest req, Map m) {
- DefaultSolrParams dsp = new DefaultSolrParams(req.getParams(), new MapSolrParams(m));
+ ModifiableSolrParams solrParams = new ModifiableSolrParams();
+ m.forEach((k, v) -> {
+ if(v == null) return;
+ solrParams.add(k.toString(), String.valueOf(v));
+ });
+ DefaultSolrParams dsp = new DefaultSolrParams(req.getParams(),solrParams);
req.setParams(dsp);
return req;
}
@@ -96,7 +103,7 @@ public class ClusterAPI {
path = "/cluster/command-status",
permission = COLL_READ_PERM)
public void getCommandStatus(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- CollectionsHandler.CollectionOperation.REQUESTSTATUS_OP.execute(req, rsp, coreContainer.getCollectionsHandler());
+ CollectionsHandler.CollectionOperation.REQUESTSTATUS_OP.execute(req, rsp, collectionsHandler);
}
@EndPoint(method = GET,
@@ -118,7 +125,7 @@ public class ClusterAPI {
RoleInfo info = obj.get();
Map m = info.toMap(new HashMap<>());
m.put("action", ADDROLE.toString());
- coreContainer.getCollectionsHandler().handleRequestBody(wrapParams(obj.getRequest(), m), obj.getResponse());
+ collectionsHandler.handleRequestBody(wrapParams(obj.getRequest(), m), obj.getResponse());
}
@Command(name = "remove-role")
@@ -127,7 +134,7 @@ public class ClusterAPI {
RoleInfo info = obj.get();
Map m = info.toMap(new HashMap<>());
m.put("action", REMOVEROLE.toString());
- coreContainer.getCollectionsHandler().handleRequestBody(wrapParams(obj.getRequest(), info.toMap(new HashMap<>())), obj.getResponse());
+ collectionsHandler.handleRequestBody(wrapParams(obj.getRequest(),m), obj.getResponse());
}
@@ -150,7 +157,7 @@ public class ClusterAPI {
public void setProperty(PayloadObj<Map<String,String>> obj) throws Exception {
Map m = obj.get();
m.put("action", CLUSTERPROP.toString());
- coreContainer.getCollectionsHandler().handleRequestBody(wrapParams(obj.getRequest(),m ), obj.getResponse());
+ collectionsHandler.handleRequestBody(wrapParams(obj.getRequest(),m ), obj.getResponse());
}
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
index 4ef43cd..3c9e37c 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
@@ -16,6 +16,24 @@
*/
package org.apache.solr.handler.admin;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.io.IOUtils;
@@ -83,24 +101,6 @@ import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.stream.Collectors;
-
import static org.apache.solr.client.solrj.response.RequestStatusState.COMPLETED;
import static org.apache.solr.client.solrj.response.RequestStatusState.FAILED;
import static org.apache.solr.client.solrj.response.RequestStatusState.NOT_FOUND;
@@ -223,17 +223,7 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
// Make sure the cores is enabled
- CoreContainer cores = getCoreContainer();
- if (cores == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Core container instance missing");
- }
-
- // Make sure that the core is ZKAware
- if (!cores.isZooKeeperAware()) {
- throw new SolrException(ErrorCode.BAD_REQUEST,
- "Solr instance is not running in SolrCloud mode.");
- }
+ CoreContainer cores = checkErrors();
// Pick the action
SolrParams params = req.getParams();
@@ -256,6 +246,21 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
rsp.setHttpCaching(false);
}
+ protected CoreContainer checkErrors() {
+ CoreContainer cores = getCoreContainer();
+ if (cores == null) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,
+ "Core container instance missing");
+ }
+
+ // Make sure that the core is ZKAware
+ if (!cores.isZooKeeperAware()) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,
+ "Solr instance is not running in SolrCloud mode.");
+ }
+ return cores;
+ }
+
@SuppressWarnings({"unchecked"})
void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionAction action, CollectionOperation operation) throws Exception {
if (!coreContainer.isZooKeeperAware()) {
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java b/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
index ff298aa..3890d85 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/TestCollectionAPIs.java
@@ -40,6 +40,7 @@ import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.Pair;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreContainer;
+import org.apache.solr.handler.ClusterAPI;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
@@ -84,6 +85,10 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
apiBag = new ApiBag(false);
Collection<Api> apis = collectionsHandler.getApis();
for (Api api : apis) apiBag.register(api, Collections.emptyMap());
+
+ ClusterAPI clusterAPI = new ClusterAPI(collectionsHandler);
+ apiBag.registerObject(clusterAPI);
+ apiBag.registerObject(clusterAPI.commands);
}
//test a simple create collection call
compareOutput(apiBag, "/collections", POST,
@@ -278,6 +283,11 @@ public class TestCollectionAPIs extends SolrTestCaseJ4 {
}
@Override
+ protected CoreContainer checkErrors() {
+ return null;
+ }
+
+ @Override
protected void copyFromClusterProp(Map<String, Object> props, String prop) {
}