SOLR-10757: delete/refactor/cleanup CollectionAdminRequest deprecations

This commit is contained in:
Chris Hostetter 2017-05-31 09:49:56 -07:00
parent c680de1f2a
commit ee33f38bd1
30 changed files with 316 additions and 1208 deletions

View File

@ -198,6 +198,8 @@ Other Changes
* SOLR-10755: delete/refactor many solrj deprecations (hossman)
* SOLR-10757: delete/refactor/cleanup CollectionAdminRequest deprecations (hossman)
================== 6.7.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -301,11 +301,8 @@ public class SolrSnapshotsTool implements Closeable {
if (backupRepo.isPresent()) {
backup.setRepositoryName(backupRepo.get());
}
if (asyncReqId.isPresent()) {
backup.setAsyncId(asyncReqId.get());
}
CollectionAdminResponse resp = backup.process(solrClient);
Preconditions.checkState(resp.getStatus() == 0, "The request failed. The status code is " + resp.getStatus());
// if asyncId is null, processAsync will block and throw an Exception with any error
backup.processAsync(asyncReqId.orElse(null), solrClient);
} catch (Exception e) {
log.error("Failed to backup collection meta-data for collection " + collectionName, e);
System.out.println("Failed to backup collection meta-data for collection " + collectionName

View File

@ -87,8 +87,12 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
int replFactor = TestUtil.nextInt(random(), 1, 2);
int numTlogReplicas = TestUtil.nextInt(random(), 0, 1);
int numPullReplicas = TestUtil.nextInt(random(), 0, 1);
CollectionAdminRequest.Create create =
CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas);
CollectionAdminRequest.Create create = isImplicit ?
// NOTE: use shard list with same # of shards as NUM_SHARDS; we assume this later
CollectionAdminRequest.createCollectionWithImplicitRouter(getCollectionName(), "conf1", "shard1,shard2", replFactor, numTlogReplicas, numPullReplicas) :
CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas);
if (NUM_SHARDS * (replFactor + numTlogReplicas + numPullReplicas) > cluster.getJettySolrRunners().size() || random().nextBoolean()) {
create.setMaxShardsPerNode((int)Math.ceil(NUM_SHARDS * (replFactor + numTlogReplicas + numPullReplicas) / cluster.getJettySolrRunners().size()));//just to assert it survives the restoration
if (doSplitShardOperation) {
@ -102,9 +106,6 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
coreProps.put("customKey", "customValue");//just to assert it survives the restoration
create.setProperties(coreProps);
if (isImplicit) { //implicit router
create.setRouterName(ImplicitDocRouter.NAME);
create.setNumShards(null);//erase it. TODO suggest a new createCollectionWithImplicitRouter method
create.setShards("shard1,shard2"); // however still same number as NUM_SHARDS; we assume this later
create.setRouterField("shard_s");
} else {//composite id router
if (random().nextBoolean()) {

View File

@ -24,8 +24,6 @@ import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.Create;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
@ -54,29 +52,19 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
final CloudSolrClient client = cluster.getSolrClient();
RequestStatusState state = new Create()
.setCollectionName("testasynccollectioncreation")
.setNumShards(1)
.setReplicationFactor(1)
.setConfigName("conf1")
RequestStatusState state = CollectionAdminRequest.createCollection("testasynccollectioncreation","conf1",1,1)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateCollection task did not complete!", RequestStatusState.COMPLETED, state);
state = new Create()
.setCollectionName("testasynccollectioncreation")
.setNumShards(1)
.setConfigName("conf1")
state = CollectionAdminRequest.createCollection("testasynccollectioncreation","conf1",1,1)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("Recreating a collection with the same should have failed.", RequestStatusState.FAILED, state);
state = new CollectionAdminRequest.AddReplica()
.setCollectionName("testasynccollectioncreation")
.setShardName("shard1")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
state = CollectionAdminRequest.addReplicaToShard("testasynccollectioncreation", "shard1")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("Add replica did not complete", RequestStatusState.COMPLETED, state);
state = new SplitShard()
.setCollectionName("testasynccollectioncreation")
state = CollectionAdminRequest.splitShard("testasynccollectioncreation")
.setShardName("shard1")
.processAndWait(client, MAX_TIMEOUT_SECONDS * 2);
assertEquals("Shard split did not complete. Last recorded state: " + state, RequestStatusState.COMPLETED, state);
@ -89,12 +77,9 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
final String collection = "testAsyncOperations";
final CloudSolrClient client = cluster.getSolrClient();
RequestStatusState state = new Create()
.setCollectionName(collection)
.setNumShards(1)
RequestStatusState state = CollectionAdminRequest.createCollection(collection,"conf1",1,1)
.setRouterName("implicit")
.setShards("shard1")
.setConfigName("conf1")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateCollection task did not complete!", RequestStatusState.COMPLETED, state);
@ -114,14 +99,11 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
query.set("shards", "shard1");
assertEquals(numDocs, client.query(collection, query).getResults().getNumFound());
state = new CollectionAdminRequest.Reload()
.setCollectionName(collection)
state = CollectionAdminRequest.reloadCollection(collection)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("ReloadCollection did not complete", RequestStatusState.COMPLETED, state);
state = new CollectionAdminRequest.CreateShard()
.setCollectionName(collection)
.setShardName("shard2")
state = CollectionAdminRequest.createShard(collection,"shard2")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateShard did not complete", RequestStatusState.COMPLETED, state);
@ -135,16 +117,11 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
query.set("shards", "shard2");
assertEquals(1, client.query(collection, query).getResults().getNumFound());
state = new CollectionAdminRequest.DeleteShard()
.setCollectionName(collection)
.setShardName("shard2")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
state = CollectionAdminRequest.deleteShard(collection,"shard2").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteShard did not complete", RequestStatusState.COMPLETED, state);
state = new CollectionAdminRequest.AddReplica()
.setCollectionName(collection)
.setShardName("shard1")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
state = CollectionAdminRequest.addReplicaToShard(collection, "shard1")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("AddReplica did not complete", RequestStatusState.COMPLETED, state);
//cloudClient watch might take a couple of seconds to reflect it
@ -157,9 +134,7 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
Thread.sleep(100);
}
state = new CollectionAdminRequest.CreateAlias()
.setAliasName("myalias")
.setAliasedCollections(collection)
state = CollectionAdminRequest.createAlias("myalias",collection)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateAlias did not complete", RequestStatusState.COMPLETED, state);
@ -167,8 +142,7 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
query.set("shards", "shard1");
assertEquals(numDocs, client.query("myalias", query).getResults().getNumFound());
state = new CollectionAdminRequest.DeleteAlias()
.setAliasName("myalias")
state = CollectionAdminRequest.deleteAlias("myalias")
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteAlias did not complete", RequestStatusState.COMPLETED, state);
@ -191,15 +165,11 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {
shard1 = client.getZkStateReader().getClusterState().getSlice(collection, "shard1");
String replicaName = shard1.getReplicas().iterator().next().getName();
state = new CollectionAdminRequest.DeleteReplica()
.setCollectionName(collection)
.setShardName("shard1")
.setReplica(replicaName)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
state = CollectionAdminRequest.deleteReplica(collection, "shard1", replicaName)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteReplica did not complete", RequestStatusState.COMPLETED, state);
state = new CollectionAdminRequest.Delete()
.setCollectionName(collection)
state = CollectionAdminRequest.deleteCollection(collection)
.processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteCollection did not complete", RequestStatusState.COMPLETED, state);
}

View File

@ -267,17 +267,21 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
@Test
public void testClusterProp() throws InterruptedException, IOException, SolrServerException {
// sanity check our expected default
final ClusterProperties props = new ClusterProperties(zkClient());
assertEquals("Expecting prop to default to unset, test needs upated",
props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), null);
CollectionAdminResponse response = CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, "false")
.process(cluster.getSolrClient());
.process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
ClusterProperties props = new ClusterProperties(zkClient());
assertEquals("Cluster property was not set", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, "true"), "false");
assertEquals("Cluster property was not set", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), "false");
// Unset ClusterProp that we set.
CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, null).process(cluster.getSolrClient());
assertEquals("Cluster property was not unset", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, "true"), "true");
assertEquals("Cluster property was not unset", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), null);
}

View File

@ -164,11 +164,8 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {
private void createCollection() {
try {
final CollectionAdminResponse response = new CollectionAdminRequest.Create()
.setCollectionName(collectionName)
.setNumShards(1)
.setReplicationFactor(1)
.setConfigName(configName).process(solrClient);
final CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName,configName,1,1)
.process(solrClient);
if (response.getStatus() != 0) {
addFailure(new RuntimeException("failed to create collection " + collectionName));
}
@ -180,9 +177,8 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {
private void deleteCollection() {
try {
final CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete()
.setCollectionName(collectionName);
final CollectionAdminRequest.Delete deleteCollectionRequest
= CollectionAdminRequest.deleteCollection(collectionName);
final CollectionAdminResponse response = deleteCollectionRequest.process(solrClient);
if (response.getStatus() != 0) {
addFailure(new RuntimeException("failed to delete collection " + collectionName));

View File

@ -120,27 +120,4 @@ public class DeleteStatusTest extends SolrCloudTestCase {
CollectionAdminRequest.requestStatus(id2).process(client).getRequestStatus());
}
@Test
@SuppressWarnings("deprecation")
public void testDeprecatedConstructorValidation() throws Exception {
final CloudSolrClient client = cluster.getSolrClient();
try {
new CollectionAdminRequest.DeleteStatus().process(client);
fail("delete status should have failed");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Either requestid or flush parameter must be specified."));
}
try {
new CollectionAdminRequest.DeleteStatus().setFlush(true)
.setRequestId("foo")
.process(client);
fail("delete status should have failed");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Both requestid and flush parameters can not be specified together."));
}
}
}

View File

@ -152,14 +152,7 @@ public class ForceLeaderTest extends HttpPartitionTest {
} finally {
log.info("Cleaning up after the test.");
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
}
@ -206,15 +199,7 @@ public class ForceLeaderTest extends HttpPartitionTest {
}
} finally {
log.info("Cleaning up after the test.");
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
}
@ -431,10 +416,8 @@ public class ForceLeaderTest extends HttpPartitionTest {
}
private void doForceLeader(SolrClient client, String collectionName, String shard) throws IOException, SolrServerException {
CollectionAdminRequest.ForceLeader forceLeader = new CollectionAdminRequest.ForceLeader();
forceLeader.setCollectionName(collectionName);
forceLeader.setShardName(shard);
client.request(forceLeader);
CollectionAdminRequest.ForceLeader forceLeader = CollectionAdminRequest.forceLeaderElection(collectionName, shard);
client.request(forceLeader);
}
protected int getNumberOfActiveReplicas(ClusterState clusterState, String collection, String sliceId) {

View File

@ -157,13 +157,9 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
CollectionAdminResponse response;
Map<String, NamedList<Integer>> coresStatus;
CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
.setCollectionName("implicit_collection_without_routerfield")
.setRouterName("implicit")
.setNumShards(2)
.setShards("shard1,shard2")
.setReplicationFactor(2)
.setConfigName("conf1");
CollectionAdminRequest.Create createCollectionRequest
= CollectionAdminRequest.createCollectionWithImplicitRouter("implicit_collection_without_routerfield",
"conf1","shard1,shard2",2);
response = createCollectionRequest.process(server);
assertEquals(0, response.getStatus());
@ -285,14 +281,10 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
CollectionAdminResponse response;
Map<String, NamedList<Integer>> coresStatus;
response = new CollectionAdminRequest.Create()
.setCollectionName("compositeid_collection_with_routerfield")
response = CollectionAdminRequest.createCollection("compositeid_collection_with_routerfield","conf1",2,2)
.setRouterName("compositeId")
.setRouterField("routefield_s")
.setNumShards(2)
.setShards("shard1,shard2")
.setReplicationFactor(2)
.setConfigName("conf1")
.process(server);
assertEquals(0, response.getStatus());

View File

@ -37,7 +37,6 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.common.SolrException;
@ -199,13 +198,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
zkClient.delete(znodePath, -1, false);
// try to clean up
try {
new CollectionAdminRequest.Delete()
.setCollectionName(testCollectionName).process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
protected void testMinRf() throws Exception {
@ -387,13 +380,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
log.info("testRf2 succeeded ... deleting the "+testCollectionName+" collection");
// try to clean up
try {
new CollectionAdminRequest.Delete()
.setCollectionName(testCollectionName).process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
protected void testRf3() throws Exception {
@ -443,14 +430,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
log.info("testRf3 succeeded ... deleting the "+testCollectionName+" collection");
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
// test inspired by SOLR-6511
@ -534,14 +514,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
log.info("testLeaderZkSessionLoss succeeded ... deleting the "+testCollectionName+" collection");
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
protected List<Replica> getActiveOrRecoveringReplicas(String testCollectionName, String shardId) throws Exception {
@ -693,4 +666,5 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
log.info("Took {} ms to see replicas [{}] become active.", timer.getTime(), replicasToCheck);
}
}

View File

@ -20,7 +20,6 @@ import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.Replica;
import org.junit.Test;
@ -184,13 +183,6 @@ public class LeaderFailoverAfterPartitionTest extends HttpPartitionTest {
assertDocsExistInAllReplicas(participatingReplicas, testCollectionName, 1, 6);
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
}
}

View File

@ -19,7 +19,6 @@ package org.apache.solr.cloud;
import org.apache.http.NoHttpResponseException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.util.RTimer;
@ -96,14 +95,7 @@ public class LeaderInitiatedRecoveryOnCommitTest extends BasicDistributedZkTest
Thread.sleep(sleepMsBeforeHealPartition);
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
log.info("multiShardTest completed OK");
}
@ -144,14 +136,7 @@ public class LeaderInitiatedRecoveryOnCommitTest extends BasicDistributedZkTest
Thread.sleep(sleepMsBeforeHealPartition);
// try to clean up
try {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
attemptCollectionDelete(cloudClient, testCollectionName);
log.info("oneShardTest completed OK");
}

View File

@ -24,6 +24,7 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.Create;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard;
import org.apache.solr.client.solrj.request.QueryRequest;
@ -31,7 +32,6 @@ import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.junit.Test;
import org.slf4j.Logger;
@ -116,12 +116,7 @@ public class MultiThreadedOCPTest extends AbstractFullDistribZkTestBase {
private void testParallelCollectionAPICalls() throws IOException, SolrServerException {
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
for(int i = 1 ; i <= NUM_COLLECTIONS ; i++) {
new Create()
.setCollectionName("ocptest" + i)
.setNumShards(4)
.setConfigName("conf1")
.setAsyncId(String.valueOf(i))
.process(client);
CollectionAdminRequest.createCollection("ocptest" + i,"conf1",4,1).processAsync(String.valueOf(i), client);
}
boolean pass = false;
@ -158,12 +153,8 @@ public class MultiThreadedOCPTest extends AbstractFullDistribZkTestBase {
"/overseer/collection-queue-work", new Overseer.Stats());
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
Create createCollectionRequest = new Create()
.setCollectionName("ocptest_shardsplit")
.setNumShards(4)
.setConfigName("conf1")
.setAsyncId("1000");
createCollectionRequest.process(client);
Create createCollectionRequest = CollectionAdminRequest.createCollection("ocptest_shardsplit","conf1",4,1);
createCollectionRequest.processAsync("1000",client);
distributedQueue.offer(Utils.toJSON(Utils.makeMap(
"collection", "ocptest_shardsplit",
@ -215,36 +206,21 @@ public class MultiThreadedOCPTest extends AbstractFullDistribZkTestBase {
private void testDeduplicationOfSubmittedTasks() throws IOException, SolrServerException {
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
new Create()
.setCollectionName("ocptest_shardsplit2")
.setNumShards(4)
.setConfigName("conf1")
.setAsyncId("3000")
.process(client);
CollectionAdminRequest.createCollection("ocptest_shardsplit2","conf1",4,1).processAsync("3000",client);
SplitShard splitShardRequest = new SplitShard()
.setCollectionName("ocptest_shardsplit2")
.setShardName(SHARD1)
.setAsyncId("3001");
splitShardRequest.process(client);
splitShardRequest = new SplitShard()
.setCollectionName("ocptest_shardsplit2")
.setShardName(SHARD2)
.setAsyncId("3002");
splitShardRequest.process(client);
SplitShard splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1);
splitShardRequest.processAsync("3001",client);
splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD2);
splitShardRequest.processAsync("3002",client);
// Now submit another task with the same id. At this time, hopefully the previous 3002 should still be in the queue.
splitShardRequest = new SplitShard()
.setCollectionName("ocptest_shardsplit2")
.setShardName(SHARD1)
.setAsyncId("3002");
CollectionAdminResponse response = splitShardRequest.process(client);
NamedList r = response.getResponse();
assertEquals("Duplicate request was supposed to exist but wasn't found. De-duplication of submitted task failed.",
"Task with the same requestid already exists.", r.get("error"));
expectThrows(SolrServerException.class, () -> {
CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1).processAsync("3002",client);
// more helpful assertion failure
fail("Duplicate request was supposed to exist but wasn't found. De-duplication of submitted task failed.");
});
for (int i = 3001; i <= 3002; i++) {
final RequestStatusState state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
assertSame("Task " + i + " did not complete, final state: " + state, RequestStatusState.COMPLETED, state);
@ -271,11 +247,8 @@ public class MultiThreadedOCPTest extends AbstractFullDistribZkTestBase {
indexThread.start();
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
SplitShard splitShardRequest = new SplitShard()
.setCollectionName("collection1")
.setShardName(SHARD1)
.setAsyncId("2000");
splitShardRequest.process(client);
SplitShard splitShardRequest = CollectionAdminRequest.splitShard("collection1").setShardName(SHARD1);
splitShardRequest.processAsync("2000",client);
RequestStatusState state = getRequestState("2000", client);
while (state == RequestStatusState.SUBMITTED) {

View File

@ -65,7 +65,9 @@ public class ReplaceNodeTest extends SolrCloudTestCase {
String emptyNode = l.remove(0);
String node2bdecommissioned = l.get(0);
CollectionAdminRequest.Create create;
create = pickRandom(CollectionAdminRequest.createCollection(coll, "conf1", 5, 2),
// NOTE: always using the createCollection that takes in 'int' for all types of replicas, so we never
// have to worry about null checking when comparing the Create command with the final Slices
create = pickRandom(CollectionAdminRequest.createCollection(coll, "conf1", 5, 2,0,0),
CollectionAdminRequest.createCollection(coll, "conf1", 5, 1,1,0),
CollectionAdminRequest.createCollection(coll, "conf1", 5, 0,1,1),
CollectionAdminRequest.createCollection(coll, "conf1", 5, 1,0,1),

View File

@ -101,9 +101,7 @@ public class ReplicationFactorTest extends AbstractFullDistribZkTestBase {
CollectionAdminResponse resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
if (resp.getResponse().get("failure") != null) {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
CollectionAdminRequest.deleteCollection(testCollectionName).process(cloudClient);
resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);

View File

@ -70,7 +70,7 @@ public class RollingRestartTest extends AbstractFullDistribZkTestBase {
int n = random().nextInt(getShardCount());
String nodeName = cloudJettys.get(n).nodeName;
log.info("Chose {} as overseer designate", nodeName);
new CollectionAdminRequest.AddRole().setRole("overseer").setNode(nodeName).process(cloudClient);
CollectionAdminRequest.addRole(nodeName,"overseer").process(cloudClient);
designates.add(nodeName);
designateJettys.add(cloudJettys.get(n));
}

View File

@ -523,16 +523,12 @@ public class ShardSplitTest extends BasicDistributedZkTest {
log.info("Starting testSplitShardWithRule");
String collectionName = "shardSplitWithRule";
CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create()
.setCollectionName(collectionName)
.setNumShards(1)
.setReplicationFactor(2)
CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collectionName,1,2)
.setRule("shard:*,replica:<2,node:*");
CollectionAdminResponse response = createRequest.process(cloudClient);
assertEquals(0, response.getStatus());
CollectionAdminRequest.SplitShard splitShardRequest = new CollectionAdminRequest.SplitShard()
.setCollectionName(collectionName)
CollectionAdminRequest.SplitShard splitShardRequest = CollectionAdminRequest.splitShard(collectionName)
.setShardName("shard1");
response = splitShardRequest.process(cloudClient);
assertEquals(String.valueOf(response.getErrorMessages()), 0, response.getStatus());

View File

@ -146,12 +146,8 @@ public class SharedFSAutoReplicaFailoverTest extends AbstractFullDistribZkTestBa
// serially
private void testBasics() throws Exception {
String collection1 = "solrj_collection";
Create createCollectionRequest = new Create()
.setCollectionName(collection1)
.setNumShards(2)
.setReplicationFactor(2)
Create createCollectionRequest = CollectionAdminRequest.createCollection(collection1,"conf1",2,2)
.setMaxShardsPerNode(2)
.setConfigName("conf1")
.setRouterField("myOwnField")
.setAutoAddReplicas(true);
CollectionAdminResponse response = createCollectionRequest.process(cloudClient);
@ -161,12 +157,8 @@ public class SharedFSAutoReplicaFailoverTest extends AbstractFullDistribZkTestBa
waitForRecoveriesToFinish(collection1, false);
String collection2 = "solrj_collection2";
createCollectionRequest = new Create()
.setCollectionName(collection2)
.setNumShards(2)
.setReplicationFactor(2)
createCollectionRequest = CollectionAdminRequest.createCollection(collection2,"conf1",2,2)
.setMaxShardsPerNode(2)
.setConfigName("conf1")
.setRouterField("myOwnField")
.setAutoAddReplicas(false);
CollectionAdminResponse response2 = createCollectionRequest.process(getCommonCloudSolrClient());
@ -177,12 +169,8 @@ public class SharedFSAutoReplicaFailoverTest extends AbstractFullDistribZkTestBa
waitForRecoveriesToFinish(collection2, false);
String collection3 = "solrj_collection3";
createCollectionRequest = new Create()
.setCollectionName(collection3)
.setNumShards(5)
.setReplicationFactor(1)
createCollectionRequest = CollectionAdminRequest.createCollection(collection3,"conf1",5,1)
.setMaxShardsPerNode(1)
.setConfigName("conf1")
.setRouterField("myOwnField")
.setAutoAddReplicas(true);
CollectionAdminResponse response3 = createCollectionRequest.process(getCommonCloudSolrClient());
@ -194,12 +182,8 @@ public class SharedFSAutoReplicaFailoverTest extends AbstractFullDistribZkTestBa
// a collection has only 1 replica per a shard
String collection4 = "solrj_collection4";
createCollectionRequest = new Create()
.setCollectionName(collection4)
.setNumShards(5)
.setReplicationFactor(1)
createCollectionRequest = CollectionAdminRequest.createCollection(collection4,"conf1",5,1)
.setMaxShardsPerNode(5)
.setConfigName("conf1")
.setRouterField("text")
.setAutoAddReplicas(true);
CollectionAdminResponse response4 = createCollectionRequest.process(getCommonCloudSolrClient());

View File

@ -39,10 +39,7 @@ public class SimpleCollectionCreateDeleteTest extends AbstractFullDistribZkTestB
}
}
String collectionName = "SimpleCollectionCreateDeleteTest";
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create()
.setCollectionName(collectionName)
.setNumShards(1)
.setReplicationFactor(1)
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName,1,1)
.setCreateNodeSet(overseerNode)
.setStateFormat(2);
@ -51,17 +48,13 @@ public class SimpleCollectionCreateDeleteTest extends AbstractFullDistribZkTestB
if (request.get("success") != null) {
assertTrue(cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false));
CollectionAdminRequest.Delete delete = new CollectionAdminRequest.Delete();
delete.setCollectionName(collectionName);
CollectionAdminRequest delete = CollectionAdminRequest.deleteCollection(collectionName);
cloudClient.request(delete);
assertFalse(cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false));
// create collection again on a node other than the overseer leader
create = new CollectionAdminRequest.Create()
.setCollectionName(collectionName)
.setNumShards(1)
.setReplicationFactor(1)
create = CollectionAdminRequest.createCollection(collectionName,1,1)
.setCreateNodeSet(notOverseerNode)
.setStateFormat(2);
request = create.process(cloudClient).getResponse();

View File

@ -185,13 +185,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
String cname = "clusterStatusZNodeVersion";
try (CloudSolrClient client = createCloudClient(null)) {
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create()
.setCollectionName(cname)
.setMaxShardsPerNode(1)
.setNumShards(1)
.setReplicationFactor(1)
.setConfigName("conf1");
create.process(client);
CollectionAdminRequest.createCollection(cname,"conf1",1,1).setMaxShardsPerNode(1).process(client);
waitForRecoveriesToFinish(cname, true);
@ -213,9 +207,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
Integer znodeVersion = (Integer) collection.get("znodeVersion");
assertNotNull(znodeVersion);
CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica()
.setCollectionName(cname)
.setShardName("shard1");
CollectionAdminRequest.AddReplica addReplica = CollectionAdminRequest.addReplicaToShard(cname, "shard1");
addReplica.process(client);
waitForRecoveriesToFinish(cname, true);
@ -628,13 +620,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
try (CloudSolrClient client = createCloudClient(null)) {
client.connect();
new CollectionAdminRequest.Create()
.setCollectionName("testClusterStateMigration")
.setNumShards(1)
.setReplicationFactor(1)
.setConfigName("conf1")
.setStateFormat(1)
.process(client);
CollectionAdminRequest.createCollection("testClusterStateMigration","conf1",1,1).setStateFormat(1).process(client);
waitForRecoveriesToFinish("testClusterStateMigration", true);
@ -647,9 +633,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
}
client.commit("testClusterStateMigration");
new CollectionAdminRequest.MigrateClusterState()
.setCollectionName("testClusterStateMigration")
.process(client);
CollectionAdminRequest.migrateCollectionFormat("testClusterStateMigration").process(client);
client.getZkStateReader().forceUpdateCollection("testClusterStateMigration");

View File

@ -73,17 +73,11 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
*/
private void testRequestTracking() throws Exception {
new CollectionAdminRequest.Create()
.setCollectionName("a1x2")
.setNumShards(1)
.setReplicationFactor(2)
CollectionAdminRequest.createCollection("a1x2",1,2)
.setCreateNodeSet(nodeNames.get(0) + ',' + nodeNames.get(1))
.process(cloudClient);
new CollectionAdminRequest.Create()
.setCollectionName("b1x1")
.setNumShards(1)
.setReplicationFactor(1)
CollectionAdminRequest.createCollection("b1x1",1,1)
.setCreateNodeSet(nodeNames.get(2))
.process(cloudClient);
@ -134,10 +128,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
private void testQueryAgainstDownReplica() throws Exception {
log.info("Creating collection 'football' with 1 shard and 2 replicas");
new CollectionAdminRequest.Create()
.setCollectionName("football")
.setNumShards(1)
.setReplicationFactor(2)
CollectionAdminRequest.createCollection("football",1,2)
.setCreateNodeSet(nodeNames.get(0) + ',' + nodeNames.get(1))
.process(cloudClient);

View File

@ -72,11 +72,7 @@ public class TestRequestForwarding extends SolrTestCaseJ4 {
private void createCollection(String name, String config) throws Exception {
CollectionAdminResponse response;
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create();
create.setConfigName(config);
create.setCollectionName(name);
create.setNumShards(2);
create.setReplicationFactor(1);
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name,config,2,1);
create.setMaxShardsPerNode(1);
response = create.process(solrCluster.getSolrClient());

View File

@ -174,10 +174,7 @@ public class TestSolrCloudWithKerberosAlt extends LuceneTestCase {
String configName = "solrCloudCollectionConfig";
miniCluster.uploadConfigSet(SolrTestCaseJ4.TEST_PATH().resolve("collection1/conf"), configName);
CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create();
createRequest.setCollectionName(collectionName);
createRequest.setNumShards(NUM_SHARDS);
createRequest.setReplicationFactor(REPLICATION_FACTOR);
CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collectionName,NUM_SHARDS,REPLICATION_FACTOR);
Properties properties = new Properties();
properties.put(CoreDescriptor.CORE_CONFIG, "solrconfig-tlog.xml");
properties.put("solr.tests.maxBufferedDocs", "100000");
@ -216,9 +213,7 @@ public class TestSolrCloudWithKerberosAlt extends LuceneTestCase {
assertEquals(1, rsp.getResults().getNumFound());
// delete the collection we created earlier
CollectionAdminRequest.Delete deleteRequest = new CollectionAdminRequest.Delete();
deleteRequest.setCollectionName(collectionName);
deleteRequest.process(cloudSolrClient);
CollectionAdminRequest.deleteCollection(collectionName).process(cloudSolrClient);
AbstractDistribZkTestBase.waitForCollectionToDisappear(collectionName, zkStateReader, true, true, 330);
}

View File

@ -173,7 +173,7 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
private void create1ShardCollection(String name, String config, MiniSolrCloudCluster solrCluster) throws Exception {
CollectionAdminResponse response;
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create() {
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create(name,config,1,1,0,0) {
@Override
public SolrParams getParams() {
ModifiableSolrParams msp = new ModifiableSolrParams(super.getParams());
@ -181,10 +181,6 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
return msp;
}
};
create.setConfigName(config);
create.setCollectionName(name);
create.setNumShards(1);
create.setReplicationFactor(1);
create.setMaxShardsPerNode(1);
response = create.process(solrCluster.getSolrClient());

View File

@ -62,10 +62,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
CollectionAdminResponse response1;
CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
.setCollectionName(".system")
.setNumShards(1)
.setReplicationFactor(2);
CollectionAdminRequest.Create createCollectionRequest = CollectionAdminRequest.createCollection(".system",1,2);
response1 = createCollectionRequest.process(client);
assertEquals(0, response1.getStatus());
assertTrue(response1.isSuccess());
@ -119,10 +116,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
public static void createSystemCollection(SolrClient client) throws SolrServerException, IOException {
CollectionAdminResponse response1;
CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
.setCollectionName(".system")
.setNumShards(1)
.setReplicationFactor(2);
CollectionAdminRequest.Create createCollectionRequest = CollectionAdminRequest.createCollection(".system",1,2);
response1 = createCollectionRequest.process(client);
assertEquals(0, response1.getStatus());
assertTrue(response1.isSuccess());

View File

@ -196,20 +196,11 @@ public class TestDistribIDF extends SolrTestCaseJ4 {
private void createCollection(String name, String config, String router) throws Exception {
CollectionAdminResponse response;
if (router.equals(ImplicitDocRouter.NAME)) {
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create();
create.setConfigName(config);
create.setCollectionName(name);
create.setReplicationFactor(1);
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollectionWithImplicitRouter(name,config,"a,b,c",1);
create.setMaxShardsPerNode(1);
create.setRouterName(router);
create.setShards("a,b,c");
response = create.process(solrCluster.getSolrClient());
} else {
CollectionAdminRequest.Create create = new CollectionAdminRequest.Create();
create.setConfigName(config);
create.setCollectionName(name);
create.setNumShards(2);
create.setReplicationFactor(1);
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name,config,2,1);
create.setMaxShardsPerNode(1);
response = create.process(solrCluster.getSolrClient());
}

View File

@ -17,6 +17,7 @@
package org.apache.solr.client.solrj;
import static org.apache.solr.common.params.CoreAdminParams.*;
import static org.apache.solr.common.params.CollectionAdminParams.FLUSH;
import java.util.Iterator;
import java.util.Set;
@ -37,135 +38,131 @@ import com.google.common.collect.Sets;
public class CollectionAdminRequestRequiredParamsTest extends LuceneTestCase {
public void testBalanceShardUnique() {
final CollectionAdminRequest.BalanceShardUnique request = new CollectionAdminRequest.BalanceShardUnique()
.setCollection("foo")
.setPropertyName("prop");
CollectionAdminRequest.BalanceShardUnique request = CollectionAdminRequest.balanceReplicaProperty("foo","prop");
assertContainsParams(request.getParams(), ACTION, COLLECTION, "property");
request.setShardUnique(true);
assertContainsParams(request.getParams(), ACTION, COLLECTION, "property","shardUnique");
request.setOnlyActiveNodes(false);
assertContainsParams(request.getParams(), ACTION, COLLECTION, "property","shardUnique","onlyactivenodes");
request.setShardUnique(null);
assertContainsParams(request.getParams(), ACTION, COLLECTION, "property","onlyactivenodes");
}
public void testClusterProp() {
final CollectionAdminRequest.ClusterProp request = new CollectionAdminRequest.ClusterProp()
.setPropertyName("foo")
.setPropertyValue("bar");
CollectionAdminRequest.ClusterProp request = CollectionAdminRequest.setClusterProperty("foo","bar");
assertContainsParams(request.getParams(), ACTION, NAME, "val");
}
public void testAddRole() {
final CollectionAdminRequest.AddRole request = new CollectionAdminRequest.AddRole()
.setNode("node")
.setRole("role");
CollectionAdminRequest.AddRole request = CollectionAdminRequest.addRole("node","role");
assertContainsParams(request.getParams(), ACTION, "node", "role");
}
public void testRemoveRole() {
final CollectionAdminRequest.RemoveRole request = new CollectionAdminRequest.RemoveRole()
.setNode("node")
.setRole("role");
CollectionAdminRequest.RemoveRole request = CollectionAdminRequest.removeRole("node","role");
assertContainsParams(request.getParams(), ACTION, "node", "role");
}
public void testAddReplica() {
// with shard parameter
CollectionAdminRequest.AddReplica request = new CollectionAdminRequest.AddReplica()
.setShardName("shard")
.setCollectionName("collection");
// with shard parameter and "client side" implicit type param
CollectionAdminRequest.AddReplica request = CollectionAdminRequest.addReplicaToShard("collection", "shard");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, ZkStateReader.REPLICA_TYPE);
// with only shard parameter and "server side" implicit type, so no param
request = CollectionAdminRequest.addReplicaToShard("collection", "shard", null);
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);
// with route parameter
request = new CollectionAdminRequest.AddReplica()
.setRouteKey("route")
.setCollectionName("collection");
request = CollectionAdminRequest.addReplicaByRouteKey("collection","route");
assertContainsParams(request.getParams(), ACTION, COLLECTION, ShardParams._ROUTE_);
// with type parameter
request = new CollectionAdminRequest.AddReplica()
.setShardName("shard")
.setCollectionName("collection")
.setType(Replica.Type.NRT);
// with explicit type parameter
request = CollectionAdminRequest.addReplicaToShard("collection", "shard", Replica.Type.NRT);
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, ZkStateReader.REPLICA_TYPE);
}
public void testAddReplicaProp() {
final CollectionAdminRequest.AddReplicaProp request = new CollectionAdminRequest.AddReplicaProp()
.setShardName("shard")
.setCollectionName("collection")
.setReplica("replica")
.setPropertyName("prop")
.setPropertyValue("value");
final CollectionAdminRequest.AddReplicaProp request = CollectionAdminRequest.addReplicaProperty
("collection", "shard", "replica", "prop", "value");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, REPLICA, "property", "property.value");
}
public void testClusterStatus() {
final CollectionAdminRequest.ClusterStatus request = new CollectionAdminRequest.ClusterStatus();
final CollectionAdminRequest.ClusterStatus request = CollectionAdminRequest.getClusterStatus();
assertContainsParams(request.getParams(), ACTION);
request.setCollectionName("foo");
assertContainsParams(request.getParams(), ACTION, COLLECTION);
request.setShardName("foo");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);
request.setRouteKey("foo");
request.setShardName(null);
assertContainsParams(request.getParams(), ACTION, COLLECTION, ShardParams._ROUTE_);
}
public void testCreateShard() {
final CollectionAdminRequest.CreateShard request = new CollectionAdminRequest.CreateShard()
.setCollectionName("collection")
.setShardName("shard");
final CollectionAdminRequest.CreateShard request = CollectionAdminRequest.createShard("collection","shard");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);
}
public void testDeleteReplica() {
final CollectionAdminRequest.DeleteReplica request = new CollectionAdminRequest.DeleteReplica()
.setCollectionName("collection")
.setShardName("shard")
.setReplica("replica");
final CollectionAdminRequest.DeleteReplica request = CollectionAdminRequest.deleteReplica("collection","shard","replica");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, REPLICA);
}
public void testDeleteReplicaProp() {
final CollectionAdminRequest.DeleteReplicaProp request = new CollectionAdminRequest.DeleteReplicaProp()
.setCollectionName("collection")
.setShardName("shard")
.setReplica("replica")
.setPropertyName("foo");
final CollectionAdminRequest.DeleteReplicaProp request = CollectionAdminRequest.deleteReplicaProperty
("collection", "shard", "replica", "foo");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD, REPLICA, "property");
}
public void testDeleteShard() {
final CollectionAdminRequest.DeleteShard request = new CollectionAdminRequest.DeleteShard()
.setCollectionName("collection")
.setShardName("shard");
final CollectionAdminRequest.DeleteShard request = CollectionAdminRequest.deleteShard("collection","shard");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);
}
public void testSplitShard() {
final CollectionAdminRequest.SplitShard request = new CollectionAdminRequest.SplitShard()
.setCollectionName("collection")
final CollectionAdminRequest.SplitShard request = CollectionAdminRequest.splitShard("collection")
.setShardName("shard");
assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);
}
public void testCreateCollection() {
final CollectionAdminRequest.Create request = new CollectionAdminRequest.Create()
.setCollectionName("collection");
assertContainsParams(request.getParams(), ACTION, NAME);
// shortest form
assertContainsParams(CollectionAdminRequest.createCollection("foo", null, 1, 1).getParams(),
ACTION, NAME, ZkStateReader.NUM_SHARDS_PROP,
"replicationFactor", ZkStateReader.NRT_REPLICAS);
// shortest form w/ "explicitly" choosing "implicit" router
assertContainsParams(CollectionAdminRequest.createCollectionWithImplicitRouter("foo", null, "bar", 1).getParams(),
ACTION, NAME, "shards", "router.name",
"replicationFactor", ZkStateReader.NRT_REPLICAS);
}
public void testReloadCollection() {
final CollectionAdminRequest.Reload request = new CollectionAdminRequest.Reload()
.setCollectionName("collection");
final CollectionAdminRequest.Reload request = CollectionAdminRequest.reloadCollection("collection");
assertContainsParams(request.getParams(), ACTION, NAME);
}
public void testDeleteCollection() {
final CollectionAdminRequest.Delete request = new CollectionAdminRequest.Delete()
.setCollectionName("collection");
final CollectionAdminRequest.Delete request = CollectionAdminRequest.deleteCollection("collection");
assertContainsParams(request.getParams(), ACTION, NAME);
}
public void testCreateAlias() {
final CollectionAdminRequest.CreateAlias request = new CollectionAdminRequest.CreateAlias()
.setAliasName("name")
.setAliasedCollections("collections");
final CollectionAdminRequest.CreateAlias request = CollectionAdminRequest.createAlias("name","collections");
assertContainsParams(request.getParams(), ACTION, NAME, "collections");
}
public void testDeleteAlias() {
final CollectionAdminRequest.DeleteAlias request = new CollectionAdminRequest.DeleteAlias()
.setAliasName("name");
final CollectionAdminRequest.DeleteAlias request = CollectionAdminRequest.deleteAlias("name");
assertContainsParams(request.getParams(), ACTION, NAME);
}
@ -175,10 +172,7 @@ public class CollectionAdminRequestRequiredParamsTest extends LuceneTestCase {
}
public void testMigrate() {
final CollectionAdminRequest.Migrate request = new CollectionAdminRequest.Migrate()
.setCollectionName("collection")
.setTargetCollection("target")
.setSplitKey("splitKey");
final CollectionAdminRequest.Migrate request = CollectionAdminRequest.migrateData("collection","targer","splitKey");
assertContainsParams(request.getParams(), ACTION, COLLECTION, "target.collection", "split.key");
}
@ -188,10 +182,21 @@ public class CollectionAdminRequestRequiredParamsTest extends LuceneTestCase {
}
public void testRequestStatus() {
final CollectionAdminRequest.RequestStatus request = new CollectionAdminRequest.RequestStatus()
.setRequestId("request");
final CollectionAdminRequest.RequestStatus request = CollectionAdminRequest.requestStatus("request");
assertContainsParams(request.getParams(), ACTION, REQUESTID);
}
public void testDeleteStatus() {
assertContainsParams(CollectionAdminRequest.deleteAsyncId("foo").getParams(),
ACTION, REQUESTID);
assertContainsParams(CollectionAdminRequest.deleteAllAsyncIds().getParams(),
ACTION, FLUSH);
}
public void testForceLeader() {
assertContainsParams(CollectionAdminRequest.forceLeaderElection("foo","bar").getParams(),
ACTION, COLLECTION, SHARD);
}
private void assertContainsParams(SolrParams solrParams, String... requiredParams) {
final Set<String> requiredParamsSet = Sets.newHashSet(requiredParams);

View File

@ -17,7 +17,7 @@
package org.apache.solr.client.solrj.request;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.Create;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.CreateAlias;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.CreateShard;
import org.apache.solr.common.SolrException;
@ -30,57 +30,57 @@ public class TestCollectionAdminRequest extends LuceneTestCase {
@Test
public void testInvalidCollectionNameRejectedWhenCreatingCollection() {
final Create createRequest = new Create();
try {
createRequest.setCollectionName("invalid$collection@name");
fail();
} catch (SolrException e) {
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid collection"));
assertTrue(exceptionMessage.contains("invalid$collection@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
final SolrException e = expectThrows(SolrException.class, () -> {
CollectionAdminRequest.createCollection("invalid$collection@name", null, 1, 1);
});
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid collection"));
assertTrue(exceptionMessage.contains("invalid$collection@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
@Test
public void testInvalidShardNamesRejectedWhenCreatingCollection() {
final Create createRequest = new Create();
try {
createRequest.setShards("invalid$shard@name");
fail();
} catch (SolrException e) {
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid shard"));
assertTrue(exceptionMessage.contains("invalid$shard@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
public void testInvalidShardNamesRejectedWhenCreatingImplicitCollection() {
final SolrException e = expectThrows(SolrException.class, () -> {
CollectionAdminRequest.createCollectionWithImplicitRouter("fine", "fine", "invalid$shard@name",1,0,0);
});
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid shard"));
assertTrue(exceptionMessage.contains("invalid$shard@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
@Test
public void testInvalidShardNamesRejectedWhenCallingSetShards() {
CollectionAdminRequest.Create request = CollectionAdminRequest.createCollectionWithImplicitRouter("fine",null,"fine",1);
final SolrException e = expectThrows(SolrException.class, () -> {
request.setShards("invalid$shard@name");
});
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid shard"));
assertTrue(exceptionMessage.contains("invalid$shard@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
@Test
public void testInvalidAliasNameRejectedWhenCreatingAlias() {
final CreateAlias createAliasRequest = new CreateAlias();
try {
createAliasRequest.setAliasName("invalid$alias@name");
fail();
} catch (SolrException e) {
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid alias"));
assertTrue(exceptionMessage.contains("invalid$alias@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
final SolrException e = expectThrows(SolrException.class, () -> {
CreateAlias createAliasRequest = CollectionAdminRequest.createAlias("invalid$alias@name","ignored");
});
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid alias"));
assertTrue(exceptionMessage.contains("invalid$alias@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
@Test
public void testInvalidShardNameRejectedWhenCreatingShard() {
final CreateShard createShardRequest = new CreateShard();
try {
createShardRequest.setShardName("invalid$shard@name");
fail();
} catch (SolrException e) {
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid shard"));
assertTrue(exceptionMessage.contains("invalid$shard@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
final SolrException e = expectThrows(SolrException.class, () -> {
CreateShard createShardRequest = CollectionAdminRequest.createShard("ignored","invalid$shard@name");
});
final String exceptionMessage = e.getMessage();
assertTrue(exceptionMessage.contains("Invalid shard"));
assertTrue(exceptionMessage.contains("invalid$shard@name"));
assertTrue(exceptionMessage.contains("must consist entirely of periods, underscores, hyphens, and alphanumerics"));
}
}

View File

@ -1892,8 +1892,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
throws SolrServerException, IOException {
CollectionAdminResponse resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
if (resp.getResponse().get("failure") != null) {
CollectionAdminRequest.Delete req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
CollectionAdminRequest.Delete req = CollectionAdminRequest.deleteCollection(testCollectionName);
req.process(cloudClient);
resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
@ -2158,6 +2157,22 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
/**
* Logs a WARN if collection can't be deleted, but does not fail or throw an exception
* @return true if success, else false
*/
protected static boolean attemptCollectionDelete(CloudSolrClient client, String collectionName) {
// try to clean up
try {
CollectionAdminRequest.deleteCollection(collectionName).process(client);
return true;
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} - ignoring", collectionName);
}
return false;
}
protected void logReplicationDetails(Replica replica, StringBuilder builder) throws IOException {
try (HttpSolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl()).build()) {
ModifiableSolrParams params = new ModifiableSolrParams();
@ -2203,9 +2218,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
static CollectionAdminResponse getStatusResponse(String requestId, SolrClient client) throws SolrServerException, IOException {
CollectionAdminRequest.RequestStatus requestStatusRequest = new CollectionAdminRequest.RequestStatus();
requestStatusRequest.setRequestId(requestId);
return requestStatusRequest.process(client);
return CollectionAdminRequest.requestStatus(requestId).process(client);
}
}