lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject svn commit: r1646350 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
Date Wed, 17 Dec 2014 22:33:39 GMT
Author: anshum
Date: Wed Dec 17 22:33:39 2014
New Revision: 1646350

URL: http://svn.apache.org/r1646350
Log:
SOLR-5922: Add support for adding core properties to SolrJ Collection Admin Request calls

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1646350&r1=1646349&r2=1646350&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Wed Dec 17 22:33:39 2014
@@ -507,6 +507,9 @@ Other Changes
 * SOLR-6861: post.sh from exampledocs directory has been removed as there no longer is a
default update
   URL. (Anshum Gupta)
 
+* SOLR-5922: Add support for adding core properties to SolrJ Collection Admin Request calls.
+  (Varun Thacker via Anshum Gupta).
+
 ==================  4.10.3 ==================
 
 Bug Fixes

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java?rev=1646350&r1=1646349&r2=1646350&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
Wed Dec 17 22:33:39 2014
@@ -17,11 +17,9 @@ package org.apache.solr.cloud;
  * limitations under the License.
  */
 
-import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
-import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
-import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
-
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
 import java.io.File;
 import java.io.IOException;
 import java.lang.management.ManagementFactory;
@@ -36,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
+import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.CompletionService;
 import java.util.concurrent.ExecutorCompletionService;
@@ -44,13 +43,8 @@ import java.util.concurrent.SynchronousQ
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.lucene.util.TestUtil;
-import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServer;
@@ -78,6 +72,7 @@ import org.apache.solr.common.cloud.ZkCo
 import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.CollectionParams.CollectionAction;
+import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.params.MapSolrParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.NamedList;
@@ -93,6 +88,11 @@ import org.apache.solr.util.DefaultSolrT
 import org.junit.Before;
 import org.junit.BeforeClass;
 
+import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
+import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
+import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
+import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
+
 /**
  * Tests the Cloud Collections API.
  */
@@ -199,6 +199,7 @@ public class CollectionsAPIDistributedZk
   @Override
   public void doTest() throws Exception {
     testSolrJAPICalls();
+    testPropertyParamsForCreate();
     testNodesUsedByCreate();
     testCollectionsAPI();
     testCollectionsAPIAddRemoveStress();
@@ -210,12 +211,60 @@ public class CollectionsAPIDistributedZk
     addReplicaTest();
     // last
     deleteCollectionWithDownNodes();
-    
+
     if (DEBUG) {
       super.printLayout();
     }
   }
-  
+
+  private void testPropertyParamsForCreate() throws Exception {
+    String collectionName = "solrj_test_core_props";
+    SolrServer server = createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0)));
+
+    File tmpDir = createTempDir("testPropertyParamsForCreate").toFile();
+    File instanceDir = new File(tmpDir, "instanceDir-" + TestUtil.randomSimpleString(random(),
1, 5));
+    File dataDir = new File(tmpDir, "dataDir-" + TestUtil.randomSimpleString(random(), 1,
5));
+    File ulogDir = new File(tmpDir, "ulogDir-" + TestUtil.randomSimpleString(random(), 1,
5));
+
+    Properties properties = new Properties();
+    properties.put(CoreAdminParams.INSTANCE_DIR, instanceDir.getAbsolutePath());
+    properties.put(CoreAdminParams.DATA_DIR, dataDir.getAbsolutePath());
+    properties.put(CoreAdminParams.ULOG_DIR, ulogDir.getAbsolutePath());
+
+    CollectionAdminRequest.Create createReq = new CollectionAdminRequest.Create();
+    createReq.setCollectionName(collectionName);
+    createReq.setNumShards(1);
+    createReq.setConfigName("conf1");
+    createReq.setProperties(properties);
+
+    CollectionAdminResponse response = createReq.process( server );
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
+    assertEquals(1, coresStatus.size());
+
+    DocCollection testcoll = getCommonCloudSolrServer().getZkStateReader()
+        .getClusterState().getCollection(collectionName);
+
+    Replica replica1 = testcoll.getReplica("core_node1");
+
+    HttpSolrServer replica1Server = new HttpSolrServer(replica1.getStr("base_url"));
+    try {
+      CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), replica1Server);
+      NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
+      String dataDirStr = (String) coreStatus.get("dataDir");
+      String instanceDirStr = (String) coreStatus.get("instanceDir");
+      assertEquals("Instance dir does not match param passed in property.instanceDir syntax",
+          new File(instanceDirStr).getAbsolutePath(), instanceDir.getAbsolutePath());
+      assertEquals("Data dir does not match param given in property.dataDir syntax",
+          new File(dataDirStr).getAbsolutePath(), dataDir.getAbsolutePath());
+
+    } finally {
+      replica1Server.shutdown();
+    }
+
+  }
+
   private void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception {
     
     // we can use this client because we just want base url
@@ -1338,7 +1387,7 @@ public class CollectionsAPIDistributedZk
     System.clearProperty("numShards");
     System.clearProperty("zkHost");
     System.clearProperty("solr.xml.persist");
-    
+
     // insurance
     DirectUpdateHandler2.commitOnClose = true;
   }

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java?rev=1646350&r1=1646349&r2=1646350&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
Wed Dec 17 22:33:39 2014
@@ -17,6 +17,13 @@
 
 package org.apache.solr.client.solrj.request;
 
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
@@ -30,10 +37,6 @@ import org.apache.solr.common.params.Sha
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.ContentStream;
 
-import java.io.IOException;
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
 /**
  * This class is experimental and subject to change.
  *
@@ -45,6 +48,18 @@ public class CollectionAdminRequest exte
   protected CollectionAction action = null;
   protected String asyncId = null;
 
+  private static String PROPERTY_PREFIX = "property.";
+
+  protected void addProperties(ModifiableSolrParams params, Properties props) {
+    Iterator<Map.Entry<Object, Object>> iter = props.entrySet().iterator();
+    while(iter.hasNext()) {
+      Map.Entry<Object, Object> prop = iter.next();
+      String key = (String) prop.getKey();
+      String value = (String) prop.getValue();
+      params.set(PROPERTY_PREFIX + key, value);
+    }
+  }
+
   protected static class CollectionShardAdminRequest extends CollectionAdminRequest {
     protected String shardName = null;
 
@@ -76,6 +91,8 @@ public class CollectionAdminRequest exte
     protected Integer numShards;
     protected Integer maxShardsPerNode;
     protected Integer replicationFactor;
+
+    private Properties properties;
     protected Boolean autoAddReplicas;
 
 
@@ -102,6 +119,14 @@ public class CollectionAdminRequest exte
     public Integer getReplicationFactor() { return replicationFactor; }
     public Boolean getAutoAddReplicas() { return autoAddReplicas; }
 
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
     @Override
     public SolrParams getParams() {
       ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
@@ -138,6 +163,10 @@ public class CollectionAdminRequest exte
         params.set(ZkStateReader.AUTO_ADD_REPLICAS, autoAddReplicas);
       }
 
+      if(properties != null) {
+        addProperties(params, properties);
+      }
+
       return params;
     }
   }
@@ -159,9 +188,23 @@ public class CollectionAdminRequest exte
   //a create shard collection request
   public static class CreateShard extends CollectionShardAdminRequest {
     protected String nodeSet;
+    private Properties properties;
 
-    public void setNodeSet(String nodeSet) { this.nodeSet = nodeSet; }
-    public String getNodeSet() { return nodeSet; }
+    public void setNodeSet(String nodeSet) {
+      this.nodeSet = nodeSet;
+    }
+
+    public String getNodeSet() {
+      return nodeSet;
+    }
+
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
 
     public CreateShard() {
       action = CollectionAction.CREATESHARD;
@@ -171,6 +214,9 @@ public class CollectionAdminRequest exte
     public SolrParams getParams() {
       ModifiableSolrParams params = getCommonParams();
       params.set( "createNodeSet", nodeSet);
+      if(properties != null) {
+        addProperties(params, properties);
+      }
       return params;
     }
   }
@@ -179,9 +225,19 @@ public class CollectionAdminRequest exte
   public static class SplitShard extends CollectionShardAdminRequest {
     protected String ranges;
 
+    private Properties properties;
+
     public void setRanges(String ranges) { this.ranges = ranges; }
     public String getRanges() { return ranges; }
 
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
     public SplitShard() {
       action = CollectionAction.SPLITSHARD;
     }
@@ -190,6 +246,10 @@ public class CollectionAdminRequest exte
     public SolrParams getParams() {
       ModifiableSolrParams params = getCommonParams();
       params.set( "ranges", ranges);
+
+      if(properties != null) {
+        addProperties(params, properties);
+      }
       return params;
     }
   }
@@ -258,11 +318,20 @@ public class CollectionAdminRequest exte
     private String routeKey;
     private String instanceDir;
     private String dataDir;
+    private Properties properties;
 
     public AddReplica() {
       action = CollectionAction.ADDREPLICA;
     }
 
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
     public String getNode() {
       return node;
     }
@@ -314,6 +383,9 @@ public class CollectionAdminRequest exte
       if (dataDir != null)  {
         params.add("dataDir", dataDir);
       }
+      if (properties != null) {
+        addProperties(params, properties);
+      }
       return params;
     }
   }



Mime
View raw message