Pārlūkot izejas kodu

HUE-6763 [search] Add global default if in cloud mode

Romain Rigaux 8 gadi atpakaļ
vecāks
revīzija
356843f

+ 12 - 11
desktop/libs/indexer/src/indexer/controller2.py

@@ -25,21 +25,25 @@ from django.utils.translation import ugettext as _
 
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import smart_str
-from indexer.conf import CORE_INSTANCE_DIR
-from indexer.controller import get_solr_ensemble
-from indexer.utils import copy_configs
 from libsolr.api import SolrApi
 from libsentry.conf import is_enabled
 from libzookeeper.conf import ENSEMBLE
 from libzookeeper.models import ZookeeperClient
 from search.conf import SOLR_URL, SECURITY_ENABLED
 
+from indexer.conf import CORE_INSTANCE_DIR
+from indexer.controller import get_solr_ensemble
+from indexer.utils import copy_configs
+
 
 LOG = logging.getLogger(__name__)
+
+
 MAX_UPLOAD_SIZE = 100 * 1024 * 1024 # 100 MB
 ALLOWED_FIELD_ATTRIBUTES = set(['name', 'type', 'indexed', 'stored'])
 FLAGS = [('I', 'indexed'), ('T', 'tokenized'), ('S', 'stored'), ('M', 'multivalued')]
 ZK_SOLR_CONFIG_NAMESPACE = 'configs'
+IS_SOLR_CLOUD = None
 
 
 class IndexControllerException(Exception):
@@ -56,14 +60,11 @@ class IndexController(object):
 
 
   def is_solr_cloud_mode(self):
-    if not hasattr(self, '_solr_cloud_mode'):
-      try:
-        self.api.collections2()
-        setattr(self, '_solr_cloud_mode', True)
-      except Exception, e:
-        LOG.info('Non SolrCloud server: %s' % e)
-        setattr(self, '_solr_cloud_mode', False)
-    return getattr(self, '_solr_cloud_mode')
+    global IS_SOLR_CLOUD
+    if IS_SOLR_CLOUD is None:
+      print self.api.info_system()
+      IS_SOLR_CLOUD = self.api.info_system().get('mode', 'solrcloud') == 'solrcloud'
+    return IS_SOLR_CLOUD
 
 
   def get_indexes(self):

+ 11 - 0
desktop/libs/libsolr/src/libsolr/api.py

@@ -607,6 +607,17 @@ class SolrApi(object):
     except RestException, e:
       raise PopupException(e, title=_('Error while accessing Solr'))
 
+  def info_system(self):
+    try:
+      params = self._get_params() + (
+        ('wt', 'json'),
+      )
+
+      response = self._root.get('admin/info/system', params=params)
+      return self._get_json(response)
+    except RestException, e:
+      raise PopupException(e, title=_('Error while accessing Solr'))
+
   def sql(self, collection, statement):
     try:
       if 'limit' not in statement.lower(): # rows is not supported