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
|
* SOLR-5973: Pluggable Ranking Collectors and Merge Strategies
|
||||||
(Joel Bernstein)
|
(Joel Bernstein)
|
||||||
|
|
||||||
|
* SOLR-6108: Add support for 'addreplica' Collection API in SolrJ. (shalin)
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -1210,53 +1210,46 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void addReplicaTest()throws Exception{
|
|
||||||
|
private void addReplicaTest() throws Exception {
|
||||||
String collectionName = "addReplicaColl";
|
String collectionName = "addReplicaColl";
|
||||||
CloudSolrServer client = createCloudClient(null);
|
CloudSolrServer client = createCloudClient(null);
|
||||||
try {
|
try {
|
||||||
createCollection(collectionName, client,2,2);
|
createCollection(collectionName, client, 2, 2);
|
||||||
String newReplicaName = Assign.assignNode(collectionName , client.getZkStateReader().getClusterState() );
|
String newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
|
||||||
ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());
|
ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());
|
||||||
Collections.shuffle(nodeList);
|
Collections.shuffle(nodeList);
|
||||||
Map m = makeMap(
|
CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
|
||||||
"action", CollectionAction.ADDREPLICA.toString(),
|
addReplica.setCollectionName(collectionName);
|
||||||
ZkStateReader.COLLECTION_PROP, collectionName,
|
addReplica.setShardName("shard1");
|
||||||
ZkStateReader.SHARD_ID_PROP, "shard1",
|
addReplica.setNode(nodeList.get(0));
|
||||||
"node", nodeList.get(0));
|
client.request(addReplica);
|
||||||
|
|
||||||
SolrRequest request = new QueryRequest(new MapSolrParams(m));
|
|
||||||
request.setPath("/admin/collections");
|
|
||||||
client.request(request);
|
|
||||||
|
|
||||||
long timeout = System.currentTimeMillis() + 3000;
|
long timeout = System.currentTimeMillis() + 3000;
|
||||||
Replica newReplica = null;
|
Replica newReplica = null;
|
||||||
|
|
||||||
for(; System.currentTimeMillis()<timeout;){
|
for (; System.currentTimeMillis() < timeout; ) {
|
||||||
Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
|
Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
|
||||||
newReplica = slice.getReplica(newReplicaName);
|
newReplica = slice.getReplica(newReplicaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNotNull(newReplica);
|
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",
|
assertEquals("Replica should be created on the right node",
|
||||||
client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));
|
client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));
|
||||||
|
|
||||||
newReplicaName = Assign.assignNode(collectionName , client.getZkStateReader().getClusterState() );
|
newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
|
||||||
m = makeMap(
|
addReplica = new CollectionAdminRequest.AddReplica();
|
||||||
"action", CollectionAction.ADDREPLICA.toString(),
|
addReplica.setCollectionName(collectionName);
|
||||||
ZkStateReader.COLLECTION_PROP, collectionName,
|
addReplica.setShardName("shard2");
|
||||||
ZkStateReader.SHARD_ID_PROP, "shard2");
|
client.request(addReplica);
|
||||||
|
|
||||||
request = new QueryRequest(new MapSolrParams(m));
|
|
||||||
request.setPath("/admin/collections");
|
|
||||||
client.request(request);
|
|
||||||
|
|
||||||
timeout = System.currentTimeMillis() + 3000;
|
timeout = System.currentTimeMillis() + 3000;
|
||||||
newReplica = null;
|
newReplica = null;
|
||||||
|
|
||||||
for(; System.currentTimeMillis()<timeout;){
|
for (; System.currentTimeMillis() < timeout; ) {
|
||||||
Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard2");
|
Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard2");
|
||||||
newReplica = slice.getReplica(newReplicaName);
|
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.SolrServer;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
|
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.cloud.ZkStateReader;
|
||||||
import org.apache.solr.common.params.CollectionParams.CollectionAction;
|
import org.apache.solr.common.params.CollectionParams.CollectionAction;
|
||||||
import org.apache.solr.common.params.CoreAdminParams;
|
import org.apache.solr.common.params.CoreAdminParams;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
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.params.SolrParams;
|
||||||
import org.apache.solr.common.util.ContentStream;
|
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()
|
public CollectionAdminRequest()
|
||||||
{
|
{
|
||||||
super( METHOD.GET, "/admin/collections" );
|
super( METHOD.GET, "/admin/collections" );
|
||||||
|
|
Loading…
Reference in New Issue