lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject [1/2] lucene-solr:branch_7x: SOLR-11130: V2Request is SolrJ should return the correct collection name
Date Wed, 26 Jul 2017 11:45:47 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x ca116ae15 -> c1c731af0


SOLR-11130: V2Request is SolrJ should return the correct collection name


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c167e0da
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c167e0da
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c167e0da

Branch: refs/heads/branch_7x
Commit: c167e0da22491a24a3bd1a5cec0f659ca4f1f291
Parents: ca116ae
Author: Noble Paul <noble@apache.org>
Authored: Wed Jul 26 21:10:21 2017 +0930
Committer: Noble Paul <noble@apache.org>
Committed: Wed Jul 26 21:15:07 2017 +0930

----------------------------------------------------------------------
 .../org/apache/solr/client/solrj/SolrRequest.java |  5 +++++
 .../solr/client/solrj/impl/CloudSolrClient.java   |  8 ++++----
 .../solr/client/solrj/request/V2Request.java      | 18 ++++++++++++++++--
 .../solr/client/solrj/request/TestV2Request.java  |  9 +++++++++
 4 files changed, 34 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c167e0da/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
index fe5c4fc..37bc5e3 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.solr.client.solrj;
 
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.ContentStream;
 
@@ -195,4 +196,8 @@ public abstract class SolrRequest<T extends SolrResponse> implements
Serializabl
     return process(client, null);
   }
 
+  public String getCollection() {
+    return getParams() == null ? null : getParams().get("collection");
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c167e0da/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index eeb96af..7da9d6e 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -786,10 +786,10 @@ public class CloudSolrClient extends SolrClient {
 
   @Override
   public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException,
IOException {
-    SolrParams reqParams = request.getParams();
-
-    if (collection == null)
-      collection = (reqParams != null) ? reqParams.get("collection", getDefaultCollection())
: getDefaultCollection();
+    if (collection == null) {
+      collection = request.getCollection();
+      if (collection == null) collection = defaultCollection;
+    }
     return requestWithRetryOnStaleState(request, 0, collection);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c167e0da/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java
index 39220d1..6694487 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java
@@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.solr.client.solrj.SolrClient;
@@ -38,14 +39,22 @@ import org.apache.solr.common.util.Utils;
 public class V2Request extends SolrRequest<V2Response> {
   //only for debugging purposes
   public static final ThreadLocal<AtomicLong> v2Calls = new ThreadLocal<>();
-  static final Pattern COLL_REQ_PATTERN = Pattern.compile("/(c|collections)/[^/]+/(?!shards)");
+  static final Pattern COLL_REQ_PATTERN = Pattern.compile("/(c|collections)/([^/])+/(?!shards)");
   private InputStream payload;
   private SolrParams solrParams;
   public final boolean useBinary;
+  private String collection;
+  private boolean isPerCollectionRequest = false;
 
   private V2Request(METHOD m, String resource, boolean useBinary) {
     super(m, resource);
+    Matcher matcher = COLL_REQ_PATTERN.matcher(getPath());
+    if (matcher.find()) {
+      this.collection = matcher.group(2);
+      isPerCollectionRequest = true;
+    }
     this.useBinary = useBinary;
+
   }
 
   @Override
@@ -73,7 +82,12 @@ public class V2Request extends SolrRequest<V2Response> {
   }
 
   public boolean isPerCollectionRequest() {
-    return COLL_REQ_PATTERN.matcher(getPath()).find();
+    return isPerCollectionRequest;
+  }
+
+  @Override
+  public String getCollection() {
+    return collection;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c167e0da/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
index 61f771e..566405f 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
@@ -49,6 +49,7 @@ public class TestV2Request extends SolrCloudTestCase {
     assertFalse(new V2Request.Builder("/collections/a/shards").build().isPerCollectionRequest());
     assertFalse(new V2Request.Builder("/collections/a/shards/").build().isPerCollectionRequest());
     assertTrue(new V2Request.Builder("/collections/a/update").build().isPerCollectionRequest());
+    assertEquals("a", new V2Request.Builder("/collections/a/update").build().getCollection());
     assertTrue(new V2Request.Builder("/c/a/update").build().isPerCollectionRequest());
     assertTrue(new V2Request.Builder("/c/a/schema").build().isPerCollectionRequest());
     assertFalse(new V2Request.Builder("/c/a").build().isPerCollectionRequest());
@@ -80,10 +81,18 @@ public class TestV2Request extends SolrCloudTestCase {
             "}").build());
     assertSuccess(client, new V2Request.Builder("/c").build());
     assertSuccess(client, new V2Request.Builder("/c/_introspect").build());
+
+
+    assertSuccess(client, new V2Request.Builder("/c/test/config")
+        .withMethod(SolrRequest.METHOD.POST)
+        .withPayload("{'create-requesthandler' : { 'name' : '/x', 'class': 'org.apache.solr.handler.DumpRequestHandler'
, 'startup' : 'lazy'}}")
+        .build());
+
     assertSuccess(client, new V2Request.Builder("/c/test").withMethod(SolrRequest.METHOD.DELETE).build());
     NamedList<Object> res = client.request(new V2Request.Builder("/c").build());
     List collections = (List) res.get("collections");
     assertEquals(0, collections.size());
+
   }
 
 }


Mime
View raw message