mirror of https://github.com/apache/lucene.git
SOLR-6108: Add support for 'addreplica' Collection API in SolrJ
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1596819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cf5a0caeb6
commit
988df83885
|
@ -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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -1210,53 +1210,46 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
|
|||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -21,10 +21,12 @@ import org.apache.solr.client.solrj.SolrRequest;
|
|||
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 extends SolrRequest
|
|||
}
|
||||
}
|
||||
|
||||
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" );
|
||||
|
|
Loading…
Reference in New Issue