You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/06/02 10:56:32 UTC
[09/38] lucene-solr:jira/solr-8668: SOLR-10757:
delete/refactor/cleanup CollectionAdminRequest deprecations
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ee33f38b/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 6c00b5c..b3d8a3f 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
@@ -33,7 +33,6 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.client.solrj.util.SolrIdentifierValidator;
-import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.ImplicitDocRouter;
import org.apache.solr.common.cloud.Replica;
@@ -68,14 +67,11 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public CollectionAdminRequest(String path, CollectionAction action) {
super(METHOD.GET, path);
- this.action = action;
+ this.action = checkNotNull("action", action);
}
@Override
public SolrParams getParams() {
- if (action == null) {
- throw new RuntimeException( "no action specified!" );
- }
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, action.toString());
return params;
@@ -117,12 +113,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
/**
- * @deprecated Use {@link #processAsync(String, SolrClient)} or {@link #processAsync(SolrClient)}
- */
- @Deprecated
- public AsyncCollectionAdminRequest setAsyncId(String id){return this;};
-
- /**
* Process this request asynchronously, generating and returning a request id
* @param client a Solr client
* @return the request id
@@ -189,12 +179,9 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public AsyncCollectionSpecificAdminRequest(CollectionAction action, String collection) {
super(action);
- this.collection = collection;
+ this.collection = checkNotNull("collection", collection);
}
- @Deprecated
- public abstract AsyncCollectionSpecificAdminRequest setCollectionName(String collection);
-
public String getCollectionName() {
return collection;
}
@@ -202,8 +189,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
- if (collection == null)
- throw new IllegalArgumentException("You must call setCollectionName() on this request");
params.set(CoreAdminParams.NAME, collection);
return params;
}
@@ -216,23 +201,13 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public AsyncShardSpecificAdminRequest(CollectionAction action, String collection, String shard) {
super(action);
- this.collection = collection;
- this.shard = shard;
+ this.collection = checkNotNull("collection",collection);
+ this.shard = checkNotNull("shard",shard);
}
- @Deprecated
- public abstract AsyncShardSpecificAdminRequest setCollectionName(String collection);
-
- @Deprecated
- public abstract AsyncShardSpecificAdminRequest setShardName(String shard);
-
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
- if (collection == null)
- throw new IllegalArgumentException("You must call setCollectionName() on this request");
- if (shard == null)
- throw new IllegalArgumentException("You must call setShardName() on this request");
params.set(CoreAdminParams.COLLECTION, collection);
params.set(CoreAdminParams.SHARD, shard);
return params;
@@ -246,21 +221,14 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public ShardSpecificAdminRequest(CollectionAction action, String collection, String shard) {
super(action);
+ this.collection = checkNotNull("collection",collection);
+ this.shard = checkNotNull("shard",shard);
}
- @Deprecated
- public abstract ShardSpecificAdminRequest setCollectionName(String collection);
-
- @Deprecated
- public abstract ShardSpecificAdminRequest setShardName(String shard);
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
- if (collection == null)
- throw new IllegalArgumentException("You must call setCollectionName() on this request");
- if (shard == null)
- throw new IllegalArgumentException("You must call setShardName() on this request");
params.set(CoreAdminParams.COLLECTION, collection);
params.set(CoreAdminParams.SHARD, shard);
return params;
@@ -284,26 +252,14 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public CollectionAdminRoleRequest(CollectionAction action, String node, String role) {
super(action);
- this.node = node;
- this.role = role;
- }
-
- @Override
- public CollectionAdminRoleRequest setAsyncId(String id) {
- this.asyncId = id;
- return this;
+ this.role = checkNotNull("role",role);
+ this.node = checkNotNull("node",node);
}
- @Deprecated
- public abstract CollectionAdminRoleRequest setNode(String node);
-
public String getNode() {
return this.node;
}
- @Deprecated
- public abstract CollectionAdminRoleRequest setRole(String role);
-
public String getRole() {
return this.role;
}
@@ -341,7 +297,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
* @param numReplicas the replication factor of the collection (same as numNrtReplicas)
*/
public static Create createCollection(String collection, String config, int numShards, int numReplicas) {
- return new Create(collection, config, numShards, numReplicas, 0, 0);
+ return new Create(collection, config, numShards, numReplicas, null, null);
}
/**
@@ -379,10 +335,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
* @param numPullReplicas the number of replicas of type {@link org.apache.solr.common.cloud.Replica.Type#PULL}
*/
public static Create createCollectionWithImplicitRouter(String collection, String config, String shards, int numNrtReplicas, int numTlogReplicas, int numPullReplicas) {
- Create createRequest = new Create(collection, config, shards, numNrtReplicas);
- createRequest.tlogReplicas = numTlogReplicas;
- createRequest.pullReplicas = numPullReplicas;
- return createRequest;
+ return new Create(collection, config, ImplicitDocRouter.NAME, null, checkNotNull("shards",shards), numNrtReplicas, numTlogReplicas, numPullReplicas);
}
// CREATE request
@@ -404,38 +357,34 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
protected Integer stateFormat;
private String[] rule , snitch;
- /**
- * @deprecated Use {@link #createCollection(String, String, int, int, int, int)}
- */
- @Deprecated
- public Create() {
- super(CollectionAction.CREATE, null);
+ /** Constructor intended for typical use cases */
+ protected Create(String collection, String config, Integer numShards, Integer numNrtReplicas, Integer numTlogReplicas, Integer numPullReplicas) { // TODO: maybe add other constructors
+ this(collection, config, null, numShards, null, numNrtReplicas, numTlogReplicas, numPullReplicas);
+ }
+
+ /** Constructor that assumes {@link ImplicitDocRouter#NAME} and an explicit list of <code>shards</code> */
+ protected Create(String collection, String config, String shards, int numNrtReplicas) {
+ this(collection, config, ImplicitDocRouter.NAME, null, checkNotNull("shards",shards), numNrtReplicas, null, null);
}
- private Create(String collection, String config, int numShards, int numNrtReplicas, int numTlogReplicas, int numPullReplicas) { // TODO: maybe add other constructors
+ private Create(String collection, String config, String routerName, Integer numShards, String shards, Integer numNrtReplicas, Integer numTlogReplicas, Integer numPullReplicas) {
super(CollectionAction.CREATE, SolrIdentifierValidator.validateCollectionName(collection));
+ // NOTE: there's very little we can assert about the args because nothing but "collection" is required by the server
+ if ((null != shards) && (null != numShards)) {
+ throw new IllegalArgumentException("Can not specify both a numShards and a list of shards");
+ }
this.configName = config;
+ this.routerName = routerName;
this.numShards = numShards;
+ this.setShards(shards);
this.nrtReplicas = numNrtReplicas;
- this.pullReplicas = numPullReplicas;
this.tlogReplicas = numTlogReplicas;
+ this.pullReplicas = numPullReplicas;
}
- private Create(String collection, String config, String shards, int numNrtReplicas) {
- super(CollectionAction.CREATE, SolrIdentifierValidator.validateCollectionName(collection));
- this.configName = config;
- this.nrtReplicas = numNrtReplicas;
- this.shards = shards;
- this.routerName = ImplicitDocRouter.NAME;
- }
-
- @Deprecated
- public Create setConfigName(String config) { this.configName = config; return this; }
public Create setCreateNodeSet(String nodeSet) { this.createNodeSet = nodeSet; return this; }
public Create setRouterName(String routerName) { this.routerName = routerName; return this; }
public Create setRouterField(String routerField) { this.routerField = routerField; return this; }
- @Deprecated
- public Create setNumShards(Integer numShards) {this.numShards = numShards; return this; }
public Create setMaxShardsPerNode(Integer numShards) { this.maxShardsPerNode = numShards; return this; }
public Create setAutoAddReplicas(boolean autoAddReplicas) { this.autoAddReplicas = autoAddReplicas; return this; }
public Create setNrtReplicas(Integer nrtReplicas) { this.nrtReplicas = nrtReplicas; return this;}
@@ -470,33 +419,15 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
* @throws IllegalArgumentException if any of the shard names contain invalid characters.
*/
public Create setShards(String shards) {
- for (String shard : shards.split(",")) {
- SolrIdentifierValidator.validateShardName(shard);
+ if (null != shards) {
+ for (String shard : shards.split(",")) {
+ SolrIdentifierValidator.validateShardName(shard);
+ }
}
this.shards = shards;
return this;
}
- /**
- * Provide the name of the collection to be created.
- *
- * Collection names must consist entirely of periods, underscores and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the collection name contains invalid characters.
- */
- @Deprecated
- public Create setCollectionName(String collectionName) throws SolrException {
- this.collection = SolrIdentifierValidator.validateCollectionName(collectionName);
- return this;
- }
-
- @Override
- @Deprecated
- public Create setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
public Properties getProperties() {
return properties;
}
@@ -576,31 +507,9 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
// RELOAD request
public static class Reload extends AsyncCollectionSpecificAdminRequest {
- /**
- * @deprecated use {@link #reloadCollection(String)}
- */
- @Deprecated
- public Reload() {
- super(CollectionAction.RELOAD, null);
- }
-
private Reload(String collection) {
super(CollectionAction.RELOAD, collection);
}
-
- @Override
- @Deprecated
- public Reload setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public Reload setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
}
public static class DeleteNode extends AsyncCollectionAdminRequest {
@@ -611,7 +520,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
*/
public DeleteNode(String node) {
super(CollectionAction.DELETENODE);
- this.node = node;
+ this.node = checkNotNull("node",node);
}
@Override
public SolrParams getParams() {
@@ -633,8 +542,8 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
*/
public ReplaceNode(String source, String target) {
super(CollectionAction.REPLACENODE);
- this.source = source;
- this.target = target;
+ this.source = checkNotNull("source",source);
+ this.target = checkNotNull("target",target);
}
public ReplaceNode setParallel(Boolean flag) {
@@ -660,18 +569,18 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public MoveReplica(String collection, String replica, String targetNode) {
super(CollectionAction.MOVEREPLICA);
- this.collection = collection;
- this.replica = replica;
- this.targetNode = targetNode;
+ this.collection = checkNotNull("collection",collection);
+ this.replica = checkNotNull("replica",replica);
+ this.targetNode = checkNotNull("targetNode",targetNode);
this.randomlyMoveReplica = false;
}
public MoveReplica(String collection, String shard, String fromNode, String targetNode) {
super(CollectionAction.MOVEREPLICA);
- this.collection = collection;
- this.shard = shard;
- this.fromNode = fromNode;
- this.targetNode = targetNode;
+ this.collection = checkNotNull("collection",collection);
+ this.shard = checkNotNull("shard",shard);
+ this.fromNode = checkNotNull("fromNode",fromNode);
+ this.targetNode = checkNotNull("targetNode",targetNode);
this.randomlyMoveReplica = true;
}
@@ -724,13 +633,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
public RebalanceLeaders(String collection) {
super(CollectionAction.REBALANCELEADERS);
- this.collection = collection;
- }
-
- @Override
- public RebalanceLeaders setAsyncId(String id) {
- this.asyncId = id;
- return this;
+ this.collection = checkNotNull("collection",collection);
}
@Override
@@ -762,31 +665,10 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
// DELETE request
public static class Delete extends AsyncCollectionSpecificAdminRequest {
- /**
- * @deprecated Use {@link #deleteCollection(String)}
- */
- @Deprecated
- public Delete() {
- super(CollectionAction.DELETE, null);
- }
-
private Delete(String collection) {
super(CollectionAction.DELETE, collection);
}
- @Override
- @Deprecated
- public Delete setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public Delete setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
}
public static Backup backupCollection(String collection, String backupName) {
@@ -807,20 +689,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
this.repositoryName = Optional.empty();
}
- @Override
- @Deprecated
- public Backup setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
- @Deprecated
- public Backup setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
public String getLocation() {
return location;
}
@@ -901,18 +769,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
this.backupName = backupName;
}
- @Override
- public Restore setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
- public Restore setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
public String getLocation() {
return location;
}
@@ -1007,7 +863,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
// This is because the setCollectionName method is deprecated.
static <T> T checkNotNull(String param, T value) {
if (value == null) {
- throw new NullPointerException("Please specify a value for parameter " + param);
+ throw new NullPointerException("Please specify a non-null value for parameter " + param);
}
return value;
}
@@ -1030,12 +886,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- public AsyncCollectionSpecificAdminRequest setCollectionName (String collection) {
- this.collection = checkNotNull(CoreAdminParams.COLLECTION ,collection);
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
params.set(CoreAdminParams.COLLECTION, collection);
@@ -1062,12 +912,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- public AsyncCollectionSpecificAdminRequest setCollectionName (String collection) {
- this.collection = checkNotNull(CoreAdminParams.COLLECTION ,collection);
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
params.set(CoreAdminParams.COLLECTION, collection);
@@ -1087,12 +931,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- public AsyncCollectionSpecificAdminRequest setCollectionName (String collection) {
- this.collection = checkNotNull(CoreAdminParams.COLLECTION ,collection);
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
params.set(CoreAdminParams.COLLECTION, collection);
@@ -1131,47 +969,11 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
return this;
}
- /**
- * @deprecated use {@link #createShard(String, String)}
- */
- @Deprecated
- public CreateShard() {
- super(CollectionAction.CREATESHARD, null, null);
- }
-
private CreateShard(String collection, String shard) {
super(CollectionAction.CREATESHARD, collection, SolrIdentifierValidator.validateShardName(shard));
}
@Override
- @Deprecated
- public CreateShard setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- /**
- * Provide the name of the shard to be created.
- *
- * Shard names must consist entirely of periods, underscores, hyphens, and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the shard name contains invalid characters.
- */
- @Override
- @Deprecated
- public CreateShard setShardName(String shardName) {
- this.shard = SolrIdentifierValidator.validateShardName(shardName);
- return this;
- }
-
- @Override
- @Deprecated
- public CreateShard setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
if (nodeSet != null) {
@@ -1204,15 +1006,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private SplitShard(String collection) {
super(CollectionAction.SPLITSHARD);
- this.collection = collection;
- }
-
- /**
- * @deprecated Use {@link #splitShard(String)}
- */
- @Deprecated
- public SplitShard() {
- super(CollectionAction.SPLITSHARD);
+ this.collection = checkNotNull("collection",collection);
}
public SplitShard setRanges(String ranges) { this.ranges = ranges; return this; }
@@ -1236,32 +1030,15 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
return this;
}
- @Deprecated
- public SplitShard setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
public SplitShard setShardName(String shard) {
this.shard = shard;
return this;
}
@Override
- @Deprecated
- public SplitShard setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
- if(this.collection == null) {
- throw new IllegalArgumentException("You must set collection name for this request.");
- }
-
params.set(CollectionAdminParams.COLLECTION, collection);
if (this.shard == null && this.splitKey == null) {
@@ -1293,14 +1070,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private Boolean deleteInstanceDir;
private Boolean deleteDataDir;
- /**
- * @deprecated Use {@link #deleteShard(String, String)}
- */
- @Deprecated
- public DeleteShard() {
- super(CollectionAction.DELETESHARD, null, null);
- }
-
private DeleteShard(String collection, String shard) {
super(CollectionAction.DELETESHARD, collection, shard);
}
@@ -1324,27 +1093,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- @Deprecated
- public DeleteShard setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public DeleteShard setShardName(String shard) {
- this.shard = shard;
- return this;
- }
-
- @Override
- @Deprecated
- public DeleteShard setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
if (deleteInstanceDir != null) {
@@ -1370,33 +1118,9 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
// FORCELEADER request
public static class ForceLeader extends ShardSpecificAdminRequest {
-
- /**
- * @deprecated Use {@link #forceLeaderElection(String, String)}
- */
- @Deprecated
- public ForceLeader() {
- super(CollectionAction.FORCELEADER, null, null);
- }
-
private ForceLeader(String collection, String shard) {
super(CollectionAction.FORCELEADER, collection, shard);
}
-
- @Override
- @Deprecated
- public ForceLeader setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public ForceLeader setShardName(String shard) {
- this.shard = shard;
- return this;
- }
-
}
/**
@@ -1431,21 +1155,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private RequestStatus(String requestId) {
super(CollectionAction.REQUESTSTATUS);
- this.requestId = requestId;
- }
-
- /**
- * @deprecated Use {@link #requestStatus(String)}
- */
- @Deprecated
- public RequestStatus() {
- super(CollectionAction.REQUESTSTATUS);
- }
-
- @Deprecated
- public RequestStatus setRequestId(String requestId) {
- this.requestId = requestId;
- return this;
+ this.requestId = checkNotNull("requestId",requestId);
}
public String getRequestId() {
@@ -1455,8 +1165,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
@Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
- if (requestId == null)
- throw new IllegalArgumentException("You must call setRequestId() on this request");
params.set(CoreAdminParams.REQUESTID, requestId);
return params;
}
@@ -1492,11 +1200,14 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
* Returns a SolrRequest to delete an asynchronous request status
*/
public static DeleteStatus deleteAsyncId(String requestId) {
- return new DeleteStatus(requestId);
+ return new DeleteStatus(checkNotNull("requestId",requestId), null);
}
+ /**
+ * Returns a SolrRequest to delete a all asynchronous request statuses
+ */
public static DeleteStatus deleteAllAsyncIds() {
- return new DeleteStatus().setFlush(true);
+ return new DeleteStatus(null, true);
}
// DELETESTATUS request
@@ -1505,29 +1216,15 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
protected String requestId = null;
protected Boolean flush = null;
- private DeleteStatus(String requestId) {
+ private DeleteStatus(String requestId, Boolean flush) {
super(CollectionAction.DELETESTATUS);
+ if (requestId == null && flush == null)
+ throw new IllegalArgumentException("Either requestid or flush parameter must be specified.");
+ if (requestId != null && flush != null)
+ throw new IllegalArgumentException("Both requestid and flush parameters can not be specified together.");
+
this.requestId = requestId;
- }
-
- /**
- * @deprecated Use {@link #deleteAsyncId(String)} or {@link #deleteAllAsyncIds()}
- */
- @Deprecated
- public DeleteStatus() {
- super(CollectionAction.DELETESTATUS);
- }
-
- @Deprecated
- public DeleteStatus setRequestId(String requestId) {
- this.requestId = requestId;
- return this;
- }
-
- @Deprecated
- public DeleteStatus setFlush(Boolean flush) {
this.flush = flush;
- return this;
}
public String getRequestId() {
@@ -1541,10 +1238,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
@Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
- if (requestId == null && flush == null)
- throw new IllegalArgumentException("Either requestid or flush parameter must be specified.");
- if (requestId != null && flush != null)
- throw new IllegalArgumentException("Both requestid and flush parameters can not be specified together.");
if (requestId != null)
params.set(CoreAdminParams.REQUESTID, requestId);
if (flush != null)
@@ -1577,52 +1270,18 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private CreateAlias(String aliasName, String aliasedCollections) {
super(CollectionAction.CREATEALIAS);
this.aliasName = SolrIdentifierValidator.validateAliasName(aliasName);
- this.aliasedCollections = aliasedCollections;
- }
-
- /**
- * @deprecated Use {@link #createAlias(String, String)}
- */
- @Deprecated
- public CreateAlias() {
- super(CollectionAction.CREATEALIAS);
- }
-
- /**
- * Provide the name of the alias to be created.
- *
- * Alias names must consist entirely of periods, underscores and alphanumerics. Other characters are not allowed.
- *
- * @throws IllegalArgumentException if the alias name contains invalid characters.
- */
- @Deprecated
- public CreateAlias setAliasName(String aliasName) {
- this.aliasName = SolrIdentifierValidator.validateAliasName(aliasName);
- return this;
+ this.aliasedCollections = checkNotNull("aliasedCollections",aliasedCollections);
}
public String getAliasName() {
return aliasName;
}
- @Deprecated
- public CreateAlias setAliasedCollections(String alias) {
- this.aliasedCollections = alias;
- return this;
- }
-
public String getAliasedCollections() {
return this.aliasedCollections;
}
@Override
- @Deprecated
- public CreateAlias setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
params.set(CoreAdminParams.NAME, aliasName);
@@ -1646,28 +1305,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private DeleteAlias(String aliasName) {
super(CollectionAction.DELETEALIAS);
- this.aliasName = aliasName;
- }
-
- /**
- * @deprecated Use {@link #deleteAlias(String)}
- */
- @Deprecated
- public DeleteAlias() {
- super(CollectionAction.DELETEALIAS);
- }
-
- @Deprecated
- public DeleteAlias setAliasName(String aliasName) {
- this.aliasName = aliasName;
- return this;
- }
-
- @Override
- @Deprecated
- public DeleteAlias setAsyncId(String id) {
- this.asyncId = id;
- return this;
+ this.aliasName = checkNotNull("aliasName",aliasName);
}
@Override
@@ -1676,29 +1314,30 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
params.set(CoreAdminParams.NAME, aliasName);
return params;
}
-
-
}
/**
* Returns a SolrRequest to add a replica of type {@link org.apache.solr.common.cloud.Replica.Type#NRT} to a shard in a collection
+ *
*/
public static AddReplica addReplicaToShard(String collection, String shard) {
return addReplicaToShard(collection, shard, Replica.Type.NRT);
}
/**
- * Returns a SolrRequest to add a replica of the specified type to a shard in a collection
+ * Returns a SolrRequest to add a replica of the specified type to a shard in a collection.
+ * If the replica type is null, the server default will be used.
+ *
*/
public static AddReplica addReplicaToShard(String collection, String shard, Replica.Type replicaType) {
- return new AddReplica(collection, shard, null, replicaType);
+ return new AddReplica(collection, checkNotNull("shard",shard), null, replicaType);
}
/**
* Returns a SolrRequest to add a replica to a collection using a route key
*/
public static AddReplica addReplicaByRouteKey(String collection, String routeKey) {
- return new AddReplica(collection, null, routeKey, Replica.Type.NRT);
+ return new AddReplica(collection, null, checkNotNull("routeKey",routeKey), null);
}
// ADDREPLICA request
@@ -1713,17 +1352,9 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
protected Properties properties;
protected Replica.Type type;
- /**
- * @deprecated Use {@link #addReplicaByRouteKey(String, String)} or {@link #addReplicaToShard(String, String)}
- */
- @Deprecated
- public AddReplica() {
- super(CollectionAction.ADDREPLICA);
- }
-
private AddReplica(String collection, String shard, String routeKey, Replica.Type type) {
super(CollectionAction.ADDREPLICA);
- this.collection = collection;
+ this.collection = checkNotNull("collection",collection);
this.shard = shard;
this.routeKey = routeKey;
this.type = type;
@@ -1758,12 +1389,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
return routeKey;
}
- @Deprecated
- public AddReplica setRouteKey(String routeKey) {
- this.routeKey = routeKey;
- return this;
- }
-
public String getInstanceDir() {
return instanceDir;
}
@@ -1782,25 +1407,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
return this;
}
- @Deprecated
- public AddReplica setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Deprecated
- public AddReplica setShardName(String shard) {
- this.shard = shard;
- return this;
- }
-
- @Override
- @Deprecated
- public AddReplica setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
public AddReplica setType(Replica.Type type) {
this.type = type;
return this;
@@ -1809,18 +1415,14 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
- if (collection == null)
- throw new IllegalArgumentException("You must call setCollection() on this request");
params.add(CoreAdminParams.COLLECTION, collection);
- if (shard == null || shard.isEmpty()) {
- if (routeKey == null) {
- throw new IllegalArgumentException("Either shard or routeKey must be provided");
- }
- params.add(ShardParams._ROUTE_, routeKey);
- }
- else {
+ assert ((null == routeKey) ^ (null == shard));
+ if (null != shard) {
params.add(CoreAdminParams.SHARD, shard);
}
+ if (null != routeKey) {
+ params.add(ShardParams._ROUTE_, routeKey);
+ }
if (node != null) {
params.add("node", node);
}
@@ -1845,14 +1447,14 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
* Returns a SolrRequest to delete a replica from a shard in a collection
*/
public static DeleteReplica deleteReplica(String collection, String shard, String replica) {
- return new DeleteReplica(collection, shard, replica);
+ return new DeleteReplica(collection, checkNotNull("shard",shard), checkNotNull("replica",replica));
}
/**
* Returns a SolrRequest to remove a number of replicas from a specific shard
*/
public static DeleteReplica deleteReplicasFromShard(String collection, String shard, int count) {
- return new DeleteReplica(collection, shard, count);
+ return new DeleteReplica(collection, checkNotNull("shard",shard), count);
}
public static DeleteReplica deleteReplicasFromAllShards(String collection, int count) {
@@ -1870,14 +1472,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private Boolean deleteIndexDir;
private Integer count;
- /**
- * @deprecated Use {@link #deleteReplica(String, String, String)}
- */
- @Deprecated
- public DeleteReplica() {
- super(CollectionAction.DELETEREPLICA, null);
- }
-
private DeleteReplica(String collection, String shard, String replica) {
super(CollectionAction.DELETEREPLICA, collection);
this.shard = shard;
@@ -1895,12 +1489,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
this.count = count;
}
- @Deprecated
- public DeleteReplica setReplica(String replica) {
- this.replica = replica;
- return this;
- }
-
public String getReplica() {
return this.replica;
}
@@ -1915,33 +1503,12 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- @Deprecated
- public DeleteReplica setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Deprecated
- public DeleteReplica setShardName(String shard) {
- this.shard = shard;
- return this;
- }
-
- @Deprecated
- public DeleteReplica setCount(Integer count) {
- this.count = count;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
// AsyncCollectionSpecificAdminRequest uses 'name' rather than 'collection'
// TODO - deal with this inconsistency
params.remove(CoreAdminParams.NAME);
- if (this.collection == null)
- throw new IllegalArgumentException("You must set a collection name for this request");
params.set(ZkStateReader.COLLECTION_PROP, this.collection);
if (this.replica != null)
@@ -1996,7 +1563,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
/**
- * Returns a SolrRequest to set a cluster property
+ * Returns a SolrRequest to set (or unset) a cluster property
*/
public static ClusterProp setClusterProperty(String propertyName, String propertyValue) {
return new ClusterProp(propertyName, propertyValue);
@@ -2008,36 +1575,16 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private String propertyName;
private String propertyValue;
- /**
- * @deprecated Use {@link #setClusterProperty(String, String)}
- */
- @Deprecated
- public ClusterProp() {
- super(CollectionAction.CLUSTERPROP);
- }
-
private ClusterProp(String propertyName, String propertyValue) {
super(CollectionAction.CLUSTERPROP);
- this.propertyName = propertyName;
+ this.propertyName = checkNotNull("propertyName",propertyName);
this.propertyValue = propertyValue;
}
- @Deprecated
- public ClusterProp setPropertyName(String propertyName) {
- this.propertyName = propertyName;
- return this;
- }
-
public String getPropertyName() {
return this.propertyName;
}
- @Deprecated
- public ClusterProp setPropertyValue(String propertyValue) {
- this.propertyValue = propertyValue;
- return this;
- }
-
public String getPropertyValue() {
return this.propertyValue;
}
@@ -2075,47 +1622,21 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private Integer forwardTimeout;
private Properties properties;
- /**
- * @deprecated Use {@link #migrateData(String, String, String)}
- */
- @Deprecated
- public Migrate() {
- super(CollectionAction.MIGRATE);
- }
-
private Migrate(String collection, String targetCollection, String splitKey) {
super(CollectionAction.MIGRATE);
- this.collection = collection;
- this.targetCollection = targetCollection;
- this.splitKey = splitKey;
- }
-
- @Deprecated
- public Migrate setCollectionName(String collection) {
- this.collection = collection;
- return this;
+ this.collection = checkNotNull("collection",collection);
+ this.targetCollection = checkNotNull("targetCollection",targetCollection);
+ this.splitKey = checkNotNull("splitKey",splitKey);
}
public String getCollectionName() {
return collection;
}
- @Deprecated
- public Migrate setTargetCollection(String targetCollection) {
- this.targetCollection = targetCollection;
- return this;
- }
-
public String getTargetCollection() {
return this.targetCollection;
}
- @Deprecated
- public Migrate setSplitKey(String splitKey) {
- this.splitKey = splitKey;
- return this;
- }
-
public String getSplitKey() {
return this.splitKey;
}
@@ -2139,13 +1660,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- @Deprecated
- public Migrate setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
params.set(CoreAdminParams.COLLECTION, collection);
@@ -2173,32 +1687,9 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
// ADDROLE request
public static class AddRole extends CollectionAdminRoleRequest {
-
- /**
- * @deprecated Use {@link #addRole(String, String)}
- */
- @Deprecated
- public AddRole() {
- super(CollectionAction.ADDROLE, null, null);
- }
-
private AddRole(String node, String role) {
super(CollectionAction.ADDROLE, node, role);
}
-
- @Override
- @Deprecated
- public AddRole setNode(String node) {
- this.node = node;
- return this;
- }
-
- @Override
- @Deprecated
- public AddRole setRole(String role) {
- this.role = role;
- return this;
- }
}
/**
@@ -2210,32 +1701,9 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
// REMOVEROLE request
public static class RemoveRole extends CollectionAdminRoleRequest {
-
- /**
- * @deprecated Use {@link #removeRole(String, String)}
- */
- @Deprecated
- public RemoveRole() {
- super(CollectionAction.REMOVEROLE, null, null);
- }
-
private RemoveRole(String node, String role) {
super(CollectionAction.REMOVEROLE, node, role);
}
-
- @Override
- @Deprecated
- public RemoveRole setNode(String node) {
- this.node = node;
- return this;
- }
-
- @Override
- @Deprecated
- public RemoveRole setRole(String role) {
- this.role = role;
- return this;
- }
}
/**
@@ -2252,12 +1720,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
super(CollectionAction.OVERSEERSTATUS);
}
- @Override
- @Deprecated
- public OverseerStatus setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
}
/**
@@ -2377,51 +1839,25 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private String propertyValue;
private Boolean shardUnique;
- /**
- * @deprecated Use {@link #addReplicaProperty(String, String, String, String, String)}
- */
- @Deprecated
- public AddReplicaProp() {
- super(CollectionAction.ADDREPLICAPROP, null, null);
- }
-
private AddReplicaProp(String collection, String shard, String replica, String propertyName, String propertyValue) {
super(CollectionAction.ADDREPLICAPROP, collection, shard);
- this.replica = replica;
- this.propertyName = propertyName;
- this.propertyValue = propertyValue;
+ this.replica = checkNotNull("replica",replica);
+ this.propertyName = checkNotNull("propertyName",propertyName);
+ this.propertyValue = checkNotNull("propertyValue",propertyValue);
}
public String getReplica() {
return replica;
}
- @Deprecated
- public AddReplicaProp setReplica(String replica) {
- this.replica = replica;
- return this;
- }
-
public String getPropertyName() {
return propertyName;
}
- @Deprecated
- public AddReplicaProp setPropertyName(String propertyName) {
- this.propertyName = propertyName;
- return this;
- }
-
public String getPropertyValue() {
return propertyValue;
}
- @Deprecated
- public AddReplicaProp setPropertyValue(String propertyValue) {
- this.propertyValue = propertyValue;
- return this;
- }
-
public Boolean getShardUnique() {
return shardUnique;
}
@@ -2432,27 +1868,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
}
@Override
- @Deprecated
- public AddReplicaProp setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public AddReplicaProp setShardName(String shard) {
- this.shard = shard;
- return this;
- }
-
- @Override
- @Deprecated
- public AddReplicaProp setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
params.set(CoreAdminParams.REPLICA, replica);
@@ -2482,61 +1897,20 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private String replica;
private String propertyName;
- /**
- * @deprecated Use {@link #deleteReplicaProperty(String, String, String, String)}
- */
- @Deprecated
- public DeleteReplicaProp() {
- super(CollectionAction.DELETEREPLICAPROP, null, null);
- }
-
private DeleteReplicaProp(String collection, String shard, String replica, String propertyName) {
super(CollectionAction.DELETEREPLICAPROP, collection, shard);
- this.replica = replica;
- this.propertyName = propertyName;
+ this.replica = checkNotNull("replica",replica);
+ this.propertyName = checkNotNull("propertyName",propertyName);
}
public String getReplica() {
return replica;
}
- @Deprecated
- public DeleteReplicaProp setReplica(String replica) {
- this.replica = replica;
- return this;
- }
-
public String getPropertyName() {
return propertyName;
}
- @Deprecated
- public DeleteReplicaProp setPropertyName(String propertyName) {
- this.propertyName = propertyName;
- return this;
- }
-
- @Override
- @Deprecated
- public DeleteReplicaProp setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public DeleteReplicaProp setShardName(String shard) {
- this.shard = shard;
- return this;
- }
-
- @Override
- @Deprecated
- public DeleteReplicaProp setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
@@ -2564,35 +1938,12 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private MigrateClusterState(String collection) {
super(CollectionAction.MIGRATESTATEFORMAT);
- this.collection = collection;
- }
-
- /**
- * @deprecated Use {@link #migrateCollectionFormat(String)}
- */
- @Deprecated
- public MigrateClusterState() {
- super(CollectionAction.MIGRATESTATEFORMAT);
- }
-
- @Deprecated
- public MigrateClusterState setCollectionName(String collection) {
- this.collection = collection;
- return this;
- }
-
- @Override
- @Deprecated
- public MigrateClusterState setAsyncId(String id) {
- this.asyncId = id;
- return this;
+ this.collection = checkNotNull("collection",collection);
}
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
- if (collection == null)
- throw new IllegalArgumentException("You must call setCollection() on this request");
params.set(CoreAdminParams.COLLECTION, collection);
return params;
}
@@ -2615,28 +1966,14 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
private BalanceShardUnique(String collection, String propertyName) {
super(CollectionAction.BALANCESHARDUNIQUE);
- this.collection = collection;
- this.propertyName = propertyName;
- }
-
- /**
- * @deprecated Use {@link #balanceReplicaProperty(String, String)}
- */
- @Deprecated
- public BalanceShardUnique() {
- super(CollectionAction.BALANCESHARDUNIQUE);
+ this.collection = checkNotNull("collection",collection);
+ this.propertyName = checkNotNull("propertyName",propertyName);
}
public String getPropertyName() {
return propertyName;
}
- @Deprecated
- public BalanceShardUnique setPropertyName(String propertyName) {
- this.propertyName = propertyName;
- return this;
- }
-
public Boolean getOnlyActiveNodes() {
return onlyActiveNodes;
}
@@ -2655,24 +1992,11 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>
return this;
}
- @Deprecated
- public BalanceShardUnique setCollection(String collection) {
- this.collection = collection;
- return this;
- }
-
public String getCollection() {
return collection;
}
@Override
- @Deprecated
- public BalanceShardUnique setAsyncId(String id) {
- this.asyncId = id;
- return this;
- }
-
- @Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
params.set(CoreAdminParams.COLLECTION, collection);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ee33f38b/solr/solrj/src/test/org/apache/solr/client/solrj/CollectionAdminRequestRequiredParamsTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/CollectionAdminRequestRequiredParamsTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/CollectionAdminRequestRequiredParamsTest.java
index 0f9b147..870aa34 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/CollectionAdminRequestRequiredParamsTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/CollectionAdminRequestRequiredParamsTest.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ee33f38b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
index c21e523..29b273e 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java
@@ -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"));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ee33f38b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index 9b8f707..2970a8b 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -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);
}
}