Browse Source

HUE-5304 [solr] Guess config path in ZooKeeper depending on Solr distribution

Romain Rigaux 8 years ago
parent
commit
1a1dc64
2 changed files with 28 additions and 16 deletions
  1. 5 15
      desktop/libs/indexer/src/indexer/conf.py
  2. 23 1
      desktop/libs/libsolr/src/libsolr/conf.py

+ 5 - 15
desktop/libs/indexer/src/indexer/conf.py

@@ -23,6 +23,7 @@ from django.utils.translation import ugettext_lazy as _t
 
 from desktop.lib.conf import Config
 
+
 LOG = logging.getLogger(__name__)
 
 
@@ -44,24 +45,13 @@ def zkensemble():
   ZooKeeper Ensemble
   """
   try:
-    from libzookeeper.conf import ENSEMBLE
-    parsed = urlparse(ENSEMBLE.get())
-    if parsed.port == 9983:
-      return ENSEMBLE.get()
-#     elif clusters['default'].HOST_PORTS.get() != 'localhost:2181':
-#       return '%s/solr' % clusters['default'].HOST_PORTS.get()
-      #return "%s:2181/" % (parsed.hostname or 'localhost')
+    from zookeeper.conf import CLUSTERS
+    clusters = CLUSTERS.get()
+    if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
+      return '%s/solr' % clusters['default'].HOST_PORTS.get()
   except:
     LOG.warn('Failed to get Zookeeper ensemble')
 
-#   try:
-#     from zookeeper.conf import CLUSTERS
-#     clusters = CLUSTERS.get()
-#     if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
-#       return '%s/solr' % clusters['default'].HOST_PORTS.get()
-#   except:
-#     LOG.warn('Failed to get Zookeeper ensemble')
-
   try:
     from search.conf import SOLR_URL
     parsed = urlparse(SOLR_URL.get())

+ 23 - 1
desktop/libs/libsolr/src/libsolr/conf.py

@@ -15,10 +15,17 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import logging
+from urlparse import urlparse
+
 from django.utils.translation import ugettext_lazy as _t
 
 from desktop.lib.conf import Config, coerce_bool
 from desktop.conf import default_ssl_validate
+from libzookeeper.conf import ENSEMBLE
+
+
+LOG = logging.getLogger(__name__)
 
 
 SSL_CERT_CA_VERIFY = Config(
@@ -28,9 +35,24 @@ SSL_CERT_CA_VERIFY = Config(
   type=coerce_bool
 )
 
+
+def zkensemble_path():
+  """
+  Try to guess Solr path in ZooKeeper.
+  """
+  try:
+    parsed = urlparse(ENSEMBLE.get())
+    if parsed.port == 9983:
+      return ENSEMBLE.get()
+  except:
+    LOG.warn('Failed to get Zookeeper ensemble path')
+
+  return '/solr'
+
+
 SOLR_ZK_PATH = Config(
   key="solr_zk_path",
   help=_t("Default path to Solr in ZooKeeper"),
-  default='/solr',
+  dynamic_default=zkensemble_path,
   type=str
 )