From b956f525c7f9ed7038b872c5ae7685724396cfbb Mon Sep 17 00:00:00 2001 From: Susheel Kumar Date: Sun, 29 Jan 2017 23:03:20 -0500 Subject: [PATCH] SOLR-9483 Add SolrJ support for the modify collection API --- .../solrj/request/CollectionAdminRequest.java | 62 +++++++++++++++++++ ...lectionAdminRequestRequiredParamsTest.java | 14 +++++ 2 files changed, 76 insertions(+) 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 94750c0acaeb..89f77d8024d0 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 @@ -87,6 +87,12 @@ protected void addProperties(ModifiableSolrParams params, Properties props) { params.set(PROPERTY_PREFIX + propertyName, props.getProperty(propertyName)); } } + + protected void addAttributes(ModifiableSolrParams params, Properties props) { + for (String propertyName : props.stringPropertyNames()) { + params.set(propertyName, props.getProperty(propertyName)); + } + } /** * Base class for asynchronous collection admin requests @@ -519,7 +525,63 @@ public SolrParams getParams() { } } + + + public static Modify modifyCollection(String collection) + { + return new Modify(collection); + } + + // MODIFY request + public static class Modify extends AsyncCollectionSpecificAdminRequest { + + private Modify(String collection) { + super(CollectionAction.MODIFYCOLLECTION, collection); + } + + private Properties properties; + + @Override + public Modify setCollectionName(String collection) { + return null; + } + public Properties getProperties() { + return properties; + } + + public Modify setProperties(Properties properties) { + this.properties = properties; + return this; + } + + public Modify setProperties(Map properties) { + this.properties = new Properties(); + this.properties.putAll(properties); + return this; + } + + public Modify withProperty(String key, String value) { + if (this.properties == null) + this.properties = new Properties(); + this.properties.setProperty(key, value); + return this; + } + + @Override + public SolrParams getParams() { + ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); + + + if(properties != null) { + addAttributes(params, properties); + } + + return params; + } + + } + /** * Returns a SolrRequest to reload a collection */ 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 50f2d18a15f9..4d6774efc1dc 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 @@ -135,6 +135,20 @@ public void testCreateCollection() { assertContainsParams(request.getParams(), ACTION, NAME); } + public void testModifyCollection() { + + final CollectionAdminRequest.Modify request = CollectionAdminRequest.modifyCollection("collection") + .withProperty("maxShardsPerNode", "2"); + assertContainsParams(request.getParams(), ACTION, NAME, "maxShardsPerNode"); + + final CollectionAdminRequest.Modify request2 = CollectionAdminRequest.modifyCollection("collection") + .withProperty("maxShardsPerNode", "2") + .withProperty("replicationFactor", "1"); + assertContainsParams(request2.getParams(), ACTION, NAME, "maxShardsPerNode","replicationFactor"); + + + } + public void testReloadCollection() { final CollectionAdminRequest.Reload request = new CollectionAdminRequest.Reload() .setCollectionName("collection");