SOLR-8534: Fix SolrJ APIs to add async support

This commit is contained in:
Varun Thacker 2016-02-10 16:28:13 -08:00
parent 70e61fd9e0
commit 9985a0966b
1 changed files with 150 additions and 100 deletions

View File

@ -45,7 +45,6 @@ import java.util.Properties;
public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q>> extends SolrRequest<CollectionAdminResponse> {
protected CollectionAction action = null;
protected String asyncId;
private static String PROPERTY_PREFIX = "property.";
@ -64,24 +63,12 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
protected abstract Q getThis();
public Q setAsyncId(String asyncId) {
this.asyncId = asyncId;
return getThis();
}
public String getAsyncId() {
return asyncId;
}
@Override
public SolrParams getParams() {
if (action == null) {
throw new RuntimeException( "no action specified!" );
}
ModifiableSolrParams params = new ModifiableSolrParams();
if (asyncId != null) {
params.set(CommonAdminParams.ASYNC, asyncId);
}
params.set(CoreAdminParams.ACTION, action.toString());
return params;
}
@ -106,6 +93,28 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
}
protected abstract static class AsyncCollectionAdminRequest <T extends CollectionAdminRequest<T>> extends CollectionAdminRequest<T> {
protected String asyncId = null;
public final T setAsyncId(String asyncId) {
this.asyncId = asyncId;
return getThis();
}
public String getAsyncId() {
return asyncId;
}
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
if (asyncId != null) {
params.set(CommonAdminParams.ASYNC, asyncId);
}
return params;
}
}
//---------------------------------------------------------------------------------------
//
//---------------------------------------------------------------------------------------
@ -130,6 +139,28 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
}
protected abstract static class CollectionSpecificAsyncAdminRequest<T extends CollectionAdminRequest<T>> extends CollectionSpecificAdminRequest<T> {
protected String asyncId = null;
public final T setAsyncId(String asyncId) {
this.asyncId = asyncId;
return getThis();
}
public String getAsyncId() {
return asyncId;
}
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
if (asyncId != null) {
params.set(CommonAdminParams.ASYNC, asyncId);
}
return params;
}
}
protected abstract static class CollectionShardAdminRequest <T extends CollectionAdminRequest<T>> extends CollectionAdminRequest<T> {
protected String shardName = null;
protected String collection = null;
@ -157,9 +188,6 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
params.set(CoreAdminParams.COLLECTION, collection);
params.set(CoreAdminParams.SHARD, shardName);
if (asyncId != null) {
params.set(CommonAdminParams.ASYNC, asyncId);
}
return params;
}
@ -172,10 +200,31 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
}
protected abstract static class CollectionAdminRoleRequest <T extends CollectionAdminRequest<T>> extends CollectionAdminRequest<T> {
protected abstract static class CollectionShardAsyncAdminRequest<T extends CollectionAdminRequest<T>> extends CollectionShardAdminRequest<T> {
protected String asyncId = null;
public final T setAsyncId(String asyncId) {
this.asyncId = asyncId;
return getThis();
}
public String getAsyncId() {
return asyncId;
}
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
if (asyncId != null) {
params.set(CommonAdminParams.ASYNC, asyncId);
}
return params;
}
}
protected abstract static class CollectionAdminRoleRequest <T extends CollectionAdminRequest<T>> extends AsyncCollectionAdminRequest<T> {
protected String node;
protected String role;
public T setNode(String node) {
this.node = node;
return getThis();
@ -207,7 +256,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
/** Specific Collection API call implementations **/
// CREATE request
public static class Create extends CollectionSpecificAdminRequest<Create> {
public static class Create extends CollectionSpecificAsyncAdminRequest<Create> {
protected String configName = null;
protected String createNodeSet = null;
protected String routerName;
@ -298,7 +347,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// RELOAD request
public static class Reload extends CollectionSpecificAdminRequest<Reload> {
public static class Reload extends CollectionSpecificAsyncAdminRequest<Reload> {
public Reload() {
action = CollectionAction.RELOAD;
}
@ -316,7 +365,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// DELETE request
public static class Delete extends CollectionSpecificAdminRequest<Delete> {
public static class Delete extends CollectionSpecificAsyncAdminRequest<Delete> {
public Delete() {
action = CollectionAction.DELETE;
@ -335,7 +384,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// CREATESHARD request
public static class CreateShard extends CollectionShardAdminRequest<CreateShard> {
public static class CreateShard extends CollectionShardAsyncAdminRequest<CreateShard> {
protected String nodeSet;
protected Properties properties;
@ -380,7 +429,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// SPLITSHARD request
public static class SplitShard extends CollectionShardAdminRequest<SplitShard> {
public static class SplitShard extends CollectionShardAsyncAdminRequest<SplitShard> {
protected String ranges;
protected String splitKey;
@ -432,7 +481,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// DELETESHARD request
public static class DeleteShard extends CollectionShardAdminRequest<DeleteShard> {
public static class DeleteShard extends CollectionShardAsyncAdminRequest<DeleteShard> {
public DeleteShard() {
action = CollectionAction.DELETESHARD;
}
@ -531,7 +580,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// CREATEALIAS request
public static class CreateAlias extends CollectionAdminRequest<CreateAlias> {
public static class CreateAlias extends AsyncCollectionAdminRequest<CreateAlias> {
protected String aliasName;
protected String aliasedCollections;
@ -581,7 +630,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// DELETEALIAS request
public static class DeleteAlias extends CollectionAdminRequest<DeleteAlias> {
public static class DeleteAlias extends AsyncCollectionAdminRequest<DeleteAlias> {
protected String aliasName;
public DeleteAlias() {
@ -607,7 +656,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// ADDREPLICA request
public static class AddReplica extends CollectionShardAdminRequest<AddReplica> {
public static class AddReplica extends CollectionShardAsyncAdminRequest<AddReplica> {
protected String node;
protected String routeKey;
protected String instanceDir;
@ -695,7 +744,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// DELETEREPLICA request
public static class DeleteReplica extends CollectionShardAdminRequest<DeleteReplica> {
public static class DeleteReplica extends CollectionShardAsyncAdminRequest<DeleteReplica> {
protected String replica;
protected Boolean onlyIfDown;
@ -781,7 +830,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// MIGRATE request
public static class Migrate extends CollectionAdminRequest<Migrate> {
public static class Migrate extends AsyncCollectionAdminRequest<Migrate> {
private String collection;
private String targetCollection;
private String splitKey;
@ -884,7 +933,8 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// OVERSEERSTATUS request
public static class OverseerStatus extends CollectionAdminRequest<OverseerStatus> {
public static class OverseerStatus extends AsyncCollectionAdminRequest<OverseerStatus> {
public OverseerStatus () {
action = CollectionAction.OVERSEERSTATUS;
}
@ -967,7 +1017,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// ADDREPLICAPROP request
public static class AddReplicaProp extends CollectionShardAdminRequest<AddReplicaProp> {
public static class AddReplicaProp extends CollectionShardAsyncAdminRequest<AddReplicaProp> {
private String replica;
private String propertyName;
private String propertyValue;
@ -1034,7 +1084,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// DELETEREPLICAPROP request
public static class DeleteReplicaProp extends CollectionShardAdminRequest<DeleteReplicaProp> {
public static class DeleteReplicaProp extends CollectionShardAsyncAdminRequest<DeleteReplicaProp> {
private String replica;
private String propertyName;
@ -1075,7 +1125,7 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// MIGRATECLUSTERSTATE request
public static class MigrateClusterState extends CollectionShardAdminRequest<MigrateClusterState> {
public static class MigrateClusterState extends CollectionShardAsyncAdminRequest<MigrateClusterState> {
public MigrateClusterState() {
this.action = CollectionAction.MIGRATESTATEFORMAT;
@ -1098,11 +1148,11 @@ public abstract class CollectionAdminRequest <Q extends CollectionAdminRequest<Q
}
// BALANCESHARDUNIQUE request
public static class BalanceShardUnique extends CollectionAdminRequest<BalanceShardUnique> {
private String collection;
private String propertyName;
private Boolean onlyActiveNodes;
private Boolean shardUnique;
public static class BalanceShardUnique extends AsyncCollectionAdminRequest<BalanceShardUnique> {
protected String collection;
protected String propertyName;
protected Boolean onlyActiveNodes;
protected Boolean shardUnique;
public BalanceShardUnique() {
this.action = CollectionAction.BALANCESHARDUNIQUE;