Browse Source

HUE-7201 [importer] 'Config' object has no attribute 'get' when Solr is not installed

Romain Rigaux 8 years ago
parent
commit
1589644231

+ 1 - 3
desktop/libs/indexer/src/indexer/solr_client.py

@@ -26,9 +26,7 @@ from django.utils.translation import ugettext as _
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import smart_str
 from libsolr.api import SolrApi
-from libsentry.conf import is_enabled as is_sentry_enabled
 from libzookeeper.models import ZookeeperClient
-from search.conf import SOLR_URL, SECURITY_ENABLED
 
 from indexer.conf import CORE_INSTANCE_DIR, get_solr_ensemble
 from indexer.utils import copy_configs
@@ -56,7 +54,7 @@ class SolrClient(object):
 
   def __init__(self, user, api=None):
     self.user = user
-    self.api = api if api is not None else SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
+    self.api = api if api is not None else SolrApi(user=self.user)
 
 
   def get_indexes(self, include_cores=False):

+ 17 - 15
desktop/libs/libsolr/src/libsolr/api.py

@@ -53,26 +53,28 @@ class SolrApi(object):
   http://wiki.apache.org/solr/CoreAdmin#CoreAdminHandler
   """
   def __init__(self, solr_url=None, user=None, security_enabled=False, ssl_cert_ca_verify=SSL_CERT_CA_VERIFY.get()):
-    if solr_url is None:
+    if solr_url is None and hasattr(SOLR_URL, 'get'):
       solr_url = SOLR_URL.get()
-    self._url = solr_url
-    self._user = user
-    self._client = HttpClient(self._url, logger=LOG)
-    self.security_enabled = security_enabled or SECURITY_ENABLED.get()
 
-    if self.security_enabled:
-      self._client.set_kerberos_auth()
+    if solr_url:
+      self._url = solr_url
+      self._user = user
+      self._client = HttpClient(self._url, logger=LOG)
+      self.security_enabled = security_enabled or SECURITY_ENABLED.get()
 
-    self._client.set_verify(ssl_cert_ca_verify)
+      if self.security_enabled:
+        self._client.set_kerberos_auth()
 
-    self._root = resource.Resource(self._client)
+      self._client.set_verify(ssl_cert_ca_verify)
 
-    # The Kerberos handshake requires two requests in order to authenticate,
-    # but if our first request is a PUT/POST, it might flat-out reject the
-    # first request if the body is too large. So, connect here in order to get
-    # a cookie so future PUT/POSTs will be pre-authenticated.
-    if self.security_enabled:
-      self._root.invoke('HEAD', '/')
+      self._root = resource.Resource(self._client)
+
+      # The Kerberos handshake requires two requests in order to authenticate,
+      # but if our first request is a PUT/POST, it might flat-out reject the
+      # first request if the body is too large. So, connect here in order to get
+      # a cookie so future PUT/POSTs will be pre-authenticated.
+      if self.security_enabled:
+        self._root.invoke('HEAD', '/')
 
 
   def query(self, collection, query):