lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject lucene-solr:master: SOLR:8976: Add SolrJ support for REBALANCELEADERS Collections API
Date Wed, 13 Apr 2016 19:10:52 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 478a2a4c7 -> 689e9664c


SOLR:8976: Add SolrJ support for REBALANCELEADERS Collections API


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

Branch: refs/heads/master
Commit: 689e9664c51d4701300a1b843e6a430b7d90e67c
Parents: 478a2a4
Author: Anshum Gupta <anshum@apache.org>
Authored: Wed Apr 13 12:10:00 2016 -0700
Committer: Anshum Gupta <anshum@apache.org>
Committed: Wed Apr 13 12:10:26 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../apache/solr/cloud/TestRebalanceLeaders.java | 18 +++++-
 .../solrj/request/CollectionAdminRequest.java   | 61 ++++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/689e9664/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b379716..b2b7ecd 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -91,6 +91,8 @@ New Features
 
 * SOLR-8938: Add optional -excluderegex argument to ZkCLI. (Christine Poerschke)
 
+* SOLR-8976: Add SolrJ support for REBALANCELEADERS Collections API (Anshum Gupta)
+
 Bug Fixes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/689e9664/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java
index 9208229..798a8a8 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.Slice;
@@ -276,7 +277,21 @@ public class TestRebalanceLeaders extends AbstractFullDistribZkTestBase
{
       fail("Waited for timeout for preferredLeader assignments to be made and they werent.");
     }
     //fillExpectedWithCurrent();
-    // Now rebalance the leaders
+    // Now rebalance the leaders randomly using SolrJ or direct call
+    if(random().nextBoolean())
+      rebalanceLeaderUsingSolrJAPI();
+    else
+      rebalanceLeaderUsingDirectCall();
+
+  }
+
+  private void rebalanceLeaderUsingSolrJAPI() throws IOException, SolrServerException {
+    CollectionAdminRequest.RebalanceLeaders rebalanceLeaders = CollectionAdminRequest.rebalanceLeaders(COLLECTION_NAME);
+    rebalanceLeaders.setMaxAtOnce(10)
+        .process(cloudClient);
+  }
+
+  private void rebalanceLeaderUsingDirectCall() throws IOException, SolrServerException {
     ModifiableSolrParams params = new ModifiableSolrParams();
     params.set("action", CollectionParams.CollectionAction.REBALANCELEADERS.toString());
 
@@ -286,6 +301,7 @@ public class TestRebalanceLeaders extends AbstractFullDistribZkTestBase
{
     SolrRequest request = new QueryRequest(params);
     request.setPath("/admin/collections");
     cloudClient.request(request);
+
   }
 
   void issuePreferred(String slice, Replica rep) throws IOException, SolrServerException,
InterruptedException {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/689e9664/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
index 0c25e09..ac829f1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
@@ -490,6 +490,67 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
     }
   }
 
+  /*
+   * Returns a RebalanceLeaders object to rebalance leaders for a collection
+   */
+  public static RebalanceLeaders rebalanceLeaders(String collection) {
+    return new RebalanceLeaders(collection);
+  }
+
+  public static class RebalanceLeaders extends AsyncCollectionAdminRequest {
+
+    protected Integer maxAtOnce;
+    protected Integer maxWaitSeconds;
+    protected String collection;
+
+    public RebalanceLeaders setMaxAtOnce(Integer maxAtOnce) {
+      this.maxAtOnce = maxAtOnce;
+      return this;
+    }
+
+    public RebalanceLeaders setMaxWaitSeconds(Integer maxWaitSeconds) {
+      this.maxWaitSeconds = maxWaitSeconds;
+      return this;
+    }
+
+    public Integer getMaxAtOnce() {
+      return maxAtOnce;
+    }
+
+    public Integer getMaxWaitSeconds() {
+      return maxWaitSeconds;
+    }
+
+    public RebalanceLeaders(String collection) {
+      super(CollectionAction.REBALANCELEADERS);
+      this.collection = collection;
+    }
+
+    @Override
+    public RebalanceLeaders setAsyncId(String id) {
+      this.asyncId = id;
+      return this;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+
+      params.set(CoreAdminParams.COLLECTION, collection);
+
+      if(this.maxWaitSeconds != null) {
+        params.set("maxWaitSeconds", this.maxWaitSeconds);
+      }
+
+      if(this.maxAtOnce != null) {
+        params.set("maxAtOnce", this.maxAtOnce);
+      }
+
+      return params;
+    }
+
+  }
+
   /**
    * Returns a SolrRequest to delete a collection
    */


Mime
View raw message