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 2017/07/26 11:45:47 UTC

[1/2] lucene-solr:branch_7x: SOLR-11130: V2Request is SolrJ should return the correct collection name

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 <no...@apache.org>
Authored: Wed Jul 26 21:10:21 2017 +0930
Committer: Noble Paul <no...@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());
+
   }
 
 }


[2/2] lucene-solr:branch_7x: SOLR-11130: V2Request in SolrJ should return the correct collection name so that the request is forwarded to the correct node

Posted by no...@apache.org.
SOLR-11130: V2Request in SolrJ should return the correct collection name so that the request is forwarded to the correct node


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

Branch: refs/heads/branch_7x
Commit: c1c731af09cd75e50c5b80e61047520ca2d0134e
Parents: c167e0d
Author: Noble Paul <no...@apache.org>
Authored: Wed Jul 26 21:13:53 2017 +0930
Committer: Noble Paul <no...@apache.org>
Committed: Wed Jul 26 21:15:23 2017 +0930

----------------------------------------------------------------------
 solr/CHANGES.txt | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c1c731af/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index aec45d8..c216eda 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -2315,6 +2315,9 @@ Bug Fixes
 * SOLR-9391: LBHttpSolrClient.request now correctly returns Rsp.server when
   previously skipped servers were successfully tried. (Christine Poerschke)
 
+* SOLR-11130: V2Request in SolrJ should return the correct collection name so that the request is forwarded to the
+  correct node (noble)
+
 Optimizations
 ----------------------