lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r1596819 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
Date Thu, 22 May 2014 11:50:32 GMT
Author: shalin
Date: Thu May 22 11:50:31 2014
New Revision: 1596819

URL: http://svn.apache.org/r1596819
Log:
SOLR-6108: Add support for 'addreplica' Collection API in SolrJ

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1596819&r1=1596818&r2=1596819&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu May 22 11:50:31 2014
@@ -116,6 +116,8 @@ New Features
 * SOLR-5973: Pluggable Ranking Collectors and Merge Strategies
   (Joel Bernstein)
 
+* SOLR-6108: Add support for 'addreplica' Collection API in SolrJ. (shalin)
+
 Bug Fixes
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java?rev=1596819&r1=1596818&r2=1596819&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
Thu May 22 11:50:31 2014
@@ -1210,53 +1210,46 @@ public class CollectionsAPIDistributedZk
     }
 
   }
-  private void addReplicaTest()throws Exception{
+
+  private void addReplicaTest() throws Exception {
     String collectionName = "addReplicaColl";
     CloudSolrServer client = createCloudClient(null);
     try {
-      createCollection(collectionName, client,2,2);
-      String newReplicaName = Assign.assignNode(collectionName , client.getZkStateReader().getClusterState()
);
+      createCollection(collectionName, client, 2, 2);
+      String newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
       ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());
       Collections.shuffle(nodeList);
-      Map m = makeMap(
-          "action", CollectionAction.ADDREPLICA.toString(),
-          ZkStateReader.COLLECTION_PROP, collectionName,
-          ZkStateReader.SHARD_ID_PROP, "shard1",
-          "node", nodeList.get(0));
-
-      SolrRequest request = new QueryRequest(new MapSolrParams(m));
-      request.setPath("/admin/collections");
-      client.request(request);
+      CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
+      addReplica.setCollectionName(collectionName);
+      addReplica.setShardName("shard1");
+      addReplica.setNode(nodeList.get(0));
+      client.request(addReplica);
 
       long timeout = System.currentTimeMillis() + 3000;
       Replica newReplica = null;
 
-      for(; System.currentTimeMillis()<timeout;){
+      for (; System.currentTimeMillis() < timeout; ) {
         Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName,
"shard1");
         newReplica = slice.getReplica(newReplicaName);
       }
 
       assertNotNull(newReplica);
 
-      log.info("newReplica {},\n{} ", newReplica,client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)));
-//
+      log.info("newReplica {},\n{} ", newReplica, client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)));
+
       assertEquals("Replica should be created on the right node",
           client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));
 
-      newReplicaName = Assign.assignNode(collectionName , client.getZkStateReader().getClusterState()
);
-      m = makeMap(
-          "action", CollectionAction.ADDREPLICA.toString(),
-          ZkStateReader.COLLECTION_PROP, collectionName,
-          ZkStateReader.SHARD_ID_PROP, "shard2");
-
-      request = new QueryRequest(new MapSolrParams(m));
-      request.setPath("/admin/collections");
-      client.request(request);
+      newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
+      addReplica = new CollectionAdminRequest.AddReplica();
+      addReplica.setCollectionName(collectionName);
+      addReplica.setShardName("shard2");
+      client.request(addReplica);
 
       timeout = System.currentTimeMillis() + 3000;
       newReplica = null;
 
-      for(; System.currentTimeMillis()<timeout;){
+      for (; System.currentTimeMillis() < timeout; ) {
         Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName,
"shard2");
         newReplica = slice.getReplica(newReplicaName);
       }

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java?rev=1596819&r1=1596818&r2=1596819&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
Thu May 22 11:50:31 2014
@@ -21,10 +21,12 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.CollectionParams.CollectionAction;
 import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.ShardParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.ContentStream;
 
@@ -239,6 +241,71 @@ public class CollectionAdminRequest exte
     }
   }
 
+  public static class AddReplica extends CollectionShardAdminRequest {
+    private String node;
+    private String routeKey;
+    private String instanceDir;
+    private String dataDir;
+
+    public AddReplica() {
+      action = CollectionAction.ADDREPLICA;
+    }
+
+    public String getNode() {
+      return node;
+    }
+
+    public void setNode(String node) {
+      this.node = node;
+    }
+
+    public String getRouteKey() {
+      return routeKey;
+    }
+
+    public void setRouteKey(String routeKey) {
+      this.routeKey = routeKey;
+    }
+
+    public String getInstanceDir() {
+      return instanceDir;
+    }
+
+    public void setInstanceDir(String instanceDir) {
+      this.instanceDir = instanceDir;
+    }
+
+    public String getDataDir() {
+      return dataDir;
+    }
+
+    public void setDataDir(String dataDir) {
+      this.dataDir = dataDir;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      if (shardName == null || shardName.isEmpty()) {
+        params.remove("shard");
+        if (routeKey == null) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Either shard or routeKey
must be provided");
+        }
+        params.add(ShardParams._ROUTE_, routeKey);
+      }
+      if (node != null) {
+        params.add("node", node);
+      }
+      if (instanceDir != null)  {
+        params.add("instanceDir", instanceDir);
+      }
+      if (dataDir != null)  {
+        params.add("dataDir", dataDir);
+      }
+      return params;
+    }
+  }
+
   public CollectionAdminRequest()
   {
     super( METHOD.GET, "/admin/collections" );



Mime
View raw message