diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 3ba5609c003..6687631b590 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -198,6 +198,10 @@ Bug Fixes * SOLR-5532: SolrJ Content-Type validation is too strict for some webcontainers / proxies. (Jakob Furrer, hossman, Shawn Heisey, Uwe Schindler, Mark Miller) + +* SOLR-5547: Creating a collection alias using SolrJ's CollectionAdminRequest + sets the alias name and the collections to alias to the same value. + (Aaron Schram, Mark Miller) Optimizations ---------------------- diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java index 16d9b48467d..293c31d9ad5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -27,8 +27,10 @@ import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.impl.CloudSolrServer; import org.apache.solr.client.solrj.impl.HttpSolrServer; +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.client.solrj.response.CollectionAdminResponse; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; @@ -241,23 +243,38 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { assertTrue(sawException); } - private void createAlias(String alias, String collections) throws SolrServerException, IOException { - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("collections", collections); - params.set("name", alias); - params.set("action", CollectionAction.CREATEALIAS.toString()); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); - NamedList result = createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0))).request(request); + private void createAlias(String alias, String collections) + throws SolrServerException, IOException { + if (random().nextBoolean()) { + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("collections", collections); + params.set("name", alias); + params.set("action", CollectionAction.CREATEALIAS.toString()); + QueryRequest request = new QueryRequest(params); + request.setPath("/admin/collections"); + NamedList result = createNewSolrServer("", + getBaseUrl((HttpSolrServer) clients.get(0))).request(request); + } else { + CollectionAdminResponse resp = CollectionAdminRequest.CreateAlias + .createAlias(alias, collections, createNewSolrServer("", + getBaseUrl((HttpSolrServer) clients.get(0)))); + } } - private void deleteAlias(String alias) throws SolrServerException, IOException { - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("name", alias); - params.set("action", CollectionAction.DELETEALIAS.toString()); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); - NamedList result = createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0))).request(request); + private void deleteAlias(String alias) throws SolrServerException, + IOException { + if (random().nextBoolean()) { + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("name", alias); + params.set("action", CollectionAction.DELETEALIAS.toString()); + QueryRequest request = new QueryRequest(params); + request.setPath("/admin/collections"); + NamedList result = createNewSolrServer("", + getBaseUrl((HttpSolrServer) clients.get(0))).request(request); + } else { + CollectionAdminResponse resp = CollectionAdminRequest.deleteAlias(alias, + createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0)))); + } } protected void indexDoc(List skipServers, Object... fields) throws IOException, 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 c48d73562bd..cc149ce4957 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 @@ -197,7 +197,7 @@ public class CollectionAdminRequest extends SolrRequest @Override public SolrParams getParams() { ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); - params.set( "collections", collection ); + params.set( "collections", aliasedCollections ); return params; }