浏览代码

[indexer] Add Solr path to the ZooKeeper ensemble

Romain Rigaux 10 年之前
父节点
当前提交
6aa5ba2
共有 2 个文件被更改,包括 48 次插入3 次删除
  1. 7 3
      desktop/libs/indexer/src/indexer/controller.py
  2. 41 0
      desktop/libs/indexer/src/indexer/tests.py

+ 7 - 3
desktop/libs/indexer/src/indexer/controller.py

@@ -48,6 +48,10 @@ def get_solrctl_path():
   return solrctl_path
 
 
+def get_solr_ensemble():
+  return '%s/solr' % ENSEMBLE.get()
+
+
 class CollectionManagerController(object):
   """
   Glue the models to the views.
@@ -138,7 +142,7 @@ class CollectionManagerController(object):
       # Create instance directory.
       solrctl_path = get_solrctl_path()
 
-      process = subprocess.Popen([solrctl_path, "--zk", ENSEMBLE.get(), "instancedir", "--create", name, solr_config_path],
+      process = subprocess.Popen([solrctl_path, "--zk", get_solr_ensemble(), "instancedir", "--create", name, solr_config_path],
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
       status = process.wait()
@@ -154,7 +158,7 @@ class CollectionManagerController(object):
       api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
       if not api.create_collection(name):
         # Delete instance directory if we couldn't create a collection.
-        process = subprocess.Popen([solrctl_path, "--zk", ENSEMBLE.get(), "instancedir", "--delete", name],
+        process = subprocess.Popen([solrctl_path, "--zk", get_solr_ensemble(), "instancedir", "--delete", name],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
         if process.wait() != 0:
@@ -188,7 +192,7 @@ class CollectionManagerController(object):
       # Delete instance directory.
       solrctl_path = get_solrctl_path()
 
-      process = subprocess.Popen([solrctl_path, "--zk", ENSEMBLE.get(), "instancedir", "--delete", name],
+      process = subprocess.Popen([solrctl_path, "--zk", get_solr_ensemble(), "instancedir", "--delete", name],
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE
                                  )

+ 41 - 0
desktop/libs/indexer/src/indexer/tests.py

@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from nose.tools import assert_equal
+from desktop.lib.django_test_util import make_logged_in_client
+
+from libzookeeper.conf import ENSEMBLE
+
+from indexer.controller import get_solr_ensemble
+
+
+def test_get_ensemble():
+  c = make_logged_in_client()
+
+  clear = ENSEMBLE.set_for_testing('zoo:2181')
+  try:
+    assert_equal('zoo:2181/solr', get_solr_ensemble())
+  finally:
+    clear()
+
+
+  clear = ENSEMBLE.set_for_testing('zoo:2181,zoo2:2181')
+  try:
+    assert_equal('zoo:2181,zoo2:2181/solr', get_solr_ensemble())
+  finally:
+    clear()