lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r909019 - in /lucene/solr/branches/cloud/src: common/org/apache/solr/common/params/ java/org/apache/solr/cloud/ java/org/apache/solr/core/ java/org/apache/solr/handler/admin/
Date Thu, 11 Feb 2010 15:17:58 GMT
Author: yonik
Date: Thu Feb 11 15:17:56 2010
New Revision: 909019

URL: http://svn.apache.org/viewvc?rev=909019&view=rev
Log:
allow passing cloud params when creating core

Modified:
    lucene/solr/branches/cloud/src/common/org/apache/solr/common/params/CoreAdminParams.java
    lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/CloudDescriptor.java
    lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
    lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java
    lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java

Modified: lucene/solr/branches/cloud/src/common/org/apache/solr/common/params/CoreAdminParams.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/common/org/apache/solr/common/params/CoreAdminParams.java?rev=909019&r1=909018&r2=909019&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/common/org/apache/solr/common/params/CoreAdminParams.java
(original)
+++ lucene/solr/branches/cloud/src/common/org/apache/solr/common/params/CoreAdminParams.java
Thu Feb 11 15:17:56 2010
@@ -57,6 +57,12 @@
    * The directories are specified by multiple indexDir parameters. */
   public final static String INDEX_DIR = "indexDir";
 
+  /** The collection name in solr cloud */
+  public final static String COLLECTION = "collection";
+
+  /** The shard id in solr cloud */
+  public final static String SHARD = "shard";
+
   public enum CoreAdminAction {
     STATUS,  
     LOAD,

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/CloudDescriptor.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/CloudDescriptor.java?rev=909019&r1=909018&r2=909019&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/CloudDescriptor.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/CloudDescriptor.java Thu Feb
11 15:17:56 2010
@@ -1,5 +1,12 @@
 package org.apache.solr.cloud;
 
+import org.apache.solr.common.params.MapSolrParams;
+import org.apache.solr.common.params.SolrParams;
+
+import java.util.Collections;
+import java.util.HashMap;
+
+
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -18,9 +25,9 @@
  */
 
 public class CloudDescriptor {
-
   private String shardId;
   private String collectionName;
+  private SolrParams params;
 
   public void setShardId(String shardId) {
     this.shardId = shardId;
@@ -37,4 +44,13 @@
   public void setCollectionName(String collectionName) {
     this.collectionName = collectionName;
   }
+
+  /** Optional parameters that can change how a core is created. */
+  public SolrParams getParams() {
+    return params;
+  }
+
+  public void setParams(SolrParams params) {
+    this.params = params;
+  }
 }

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java?rev=909019&r1=909018&r2=909019&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java Thu Feb 11
15:17:56 2010
@@ -20,11 +20,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -34,6 +30,7 @@
 
 import org.apache.solr.cloud.SolrZkClient.OnReconnect;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.SolrParams;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.WatchedEvent;
@@ -798,30 +795,49 @@
     }
   }
 
-  public void createCollectionZkNode(String collection) throws KeeperException, InterruptedException,
IOException {
+  public void createCollectionZkNode(CloudDescriptor cd) throws KeeperException, InterruptedException,
IOException {
+    String collection = cd.getCollectionName();
+    
     log.info("Check for collection zkNode:" + collection);
     String collectionPath = COLLECTIONS_ZKNODE + "/" + collection;
     
     try {
       if(!zkClient.exists(collectionPath)) {
         log.info("Creating collection in ZooKeeper:" + collection);
+       SolrParams params = cd.getParams();
+
         try {
-          ZkNodeProps props = new ZkNodeProps();
-          // if we are bootstrapping a collection, default the config for
-          // a new collection to the collection we are bootstrapping
-          if(System.getProperty("bootstrap_confdir") != null) {
-            String confName = System.getProperty("bootstrap_confname", "configuration1");
-            log.info("Setting config for collection:" + collection + " to " + confName);
-            props.put("configName",  confName);
+          ZkNodeProps collectionProps = new ZkNodeProps();
+          // TODO: if bootstrap_confname isn't set, and there isn't already a conf in zk,
just use that?
+          String defaultConfigName = System.getProperty("bootstrap_confname", "configuration1");
+
+          // params passed in - currently only done via core admin (create core commmand).
+          if (params != null) {
+            Iterator<String> iter = params.getParameterNamesIterator();
+            while (iter.hasNext()) {
+              String paramName = iter.next();
+              if (paramName.startsWith("collection.")) {
+                collectionProps.put(paramName.substring("collection.".length()), params.get(paramName));
+              }
+            }
+
+            // if the config name wasn't passed in, use the default
+            if (!collectionProps.containsKey("configName"))
+              collectionProps.put("configName",  defaultConfigName);
+            
+          } else if(System.getProperty("bootstrap_confdir") != null) {
+            // if we are bootstrapping a collection, default the config for
+            // a new collection to the collection we are bootstrapping
+            log.info("Setting config for collection:" + collection + " to " + defaultConfigName);
+            collectionProps.put("configName",  defaultConfigName);
           } else {
             // check for configName
             log.info("Looking for collection configName");
             int retry = 1;
             for (; retry < 6; retry++) {
-              if (zkClient.exists(COLLECTIONS_ZKNODE + "/" + collection)) {
-                ZkNodeProps collectionProps = new ZkNodeProps();
-                collectionProps.load(zkClient.getData(COLLECTIONS_ZKNODE + "/"
-                    + collection, null, null));
+              if (zkClient.exists(collectionPath)) {
+                collectionProps = new ZkNodeProps();
+                collectionProps.load(zkClient.getData(collectionPath, null, null));
                 if (collectionProps.containsKey("configName")) {
                   break;
                 }
@@ -830,14 +846,14 @@
               Thread.sleep(2000);
             }
             if (retry == 6) {
-              log.error("Could not find conigName for collection " + collection);
+              log.error("Could not find configName for collection " + collection);
               throw new ZooKeeperException(
                   SolrException.ErrorCode.SERVER_ERROR,
                   "Could not find conigName for collection " + collection);
             }
           }
           
-          zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection, props.store(), CreateMode.PERSISTENT,
null, true);
+          zkClient.makePath(collectionPath, collectionProps.store(), CreateMode.PERSISTENT,
null, true);
          
           // ping that there is a new collection
           zkClient.setData(COLLECTIONS_ZKNODE, (byte[])null);

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java?rev=909019&r1=909018&r2=909019&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java Thu Feb 11
15:17:56 2010
@@ -588,7 +588,8 @@
     } else {
       try {
         String collection = dcore.getCloudDescriptor().getCollectionName();
-        zkController.createCollectionZkNode(collection);
+        zkController.createCollectionZkNode(dcore.getCloudDescriptor());
+        // zkController.createCollectionZkNode(collection);
         zkConfigName = zkController.readConfigName(collection);
         if (zkConfigName == null) {
           log.error("Could not find config name for collection:" + collection);

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=909019&r1=909018&r2=909019&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
(original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
Thu Feb 11 15:17:56 2010
@@ -17,6 +17,7 @@
 
 package org.apache.solr.handler.admin;
 
+import org.apache.solr.cloud.CloudDescriptor;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CoreAdminParams;
 import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
@@ -243,6 +244,19 @@
       if (opts != null)
         dcore.setDataDir(opts);
 
+      CloudDescriptor cd = dcore.getCloudDescriptor();
+      if (cd != null) {
+        cd.setParams(req.getParams());
+
+        opts = params.get(CoreAdminParams.COLLECTION);
+        if (opts != null)
+          cd.setCollectionName(opts);
+        
+        opts = params.get(CoreAdminParams.SHARD);
+        if (opts != null)
+          cd.setShardId(opts);
+      }
+
       dcore.setCoreProperties(null);
       SolrCore core = coreContainer.create(dcore);
       coreContainer.register(name, core, false);



Mime
View raw message