class IndexController(object): """ Glue the models to the views. """ def __init__(self, user): self.user = user self.api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) 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')
def get_autocomplete(self): autocomplete = {} try: api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) autocomplete['collections'] = api.collections2() autocomplete['configs'] = api.configs() except Exception, e: LOG.warn('No Zookeeper servlet running on Solr server: %s' % e)
def get_autocomplete(self): autocomplete = {} try: api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) autocomplete['collections'] = api.collections2() autocomplete['configs'] = api.configs() except Exception, e: LOG.warn('No Zookeeper servlet running on Solr server: %s' % e)
class IndexController(object): """ Glue the models to the views. """ def __init__(self, user): self.user = user self.api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) 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')
def _fetch_collections(request): from libsolr.api import SolrApi from search.conf import SOLR_URL path = request.GET['path'] item = None name = None if path: item = path if '/' in path: item, name = path.split('/') api = SolrApi(SOLR_URL.get(), request.user) if not item: return {"databases": ["collections", "configs", "admin"]} elif item and name: return { "authorizable_link": "/indexer/#edit/%s" % name, "extended_columns": [], "columns": [], "partition_keys": [] } elif item == 'collections': return { "tables_meta": [{ "comment": None, "type": "Table", "name": col } for col in api.collections2()] } elif item == 'configs': return { "tables_meta": [{ "comment": None, "type": "Table", "name": conf } for conf in api.configs()] } elif item == 'admin': return { "tables_meta": [{ "comment": None, "type": "Table", "name": 'collections' }, { "comment": None, "type": "Table", "name": "cores" }] } else: raise PopupException( _('Authorizable %s could not be retrieved') % path)
def execute(self, notebook, snippet): from search.conf import SOLR_URL api = NativeSolrApi(SOLR_URL.get(), self.user.username) collection = self.options.get('collection') or snippet.get('database') if not collection or collection == 'default': collection = api.collections2()[0] response = api.sql(collection, snippet['statement']) info = response['result-set']['docs'].pop( -1) # EOF, RESPONSE_TIME, EXCEPTION if info.get('EXCEPTION'): raise QueryError(info['EXCEPTION']) headers = [] for row in response['result-set']['docs']: for col in list(row.keys()): if col not in headers: headers.append(col) data = [[doc.get(col) for col in headers] for doc in response['result-set']['docs']] has_result_set = bool(data) return { 'sync': True, 'has_result_set': has_result_set, 'modified_row_count': 0, 'result': { 'has_more': False, 'data': data if has_result_set else [], 'meta': [{ 'name': col, 'type': '', 'comment': '' } for col in headers] if has_result_set else [], 'type': 'table' }, 'statement_id': 0, 'has_more_statements': False, 'statements_count': 1 }
def execute(self, notebook, snippet): from search.conf import SOLR_URL api = NativeSolrApi(SOLR_URL.get(), self.user.username) collection = self.options.get('collection') or snippet.get('database') if not collection or collection == 'default': collection = api.collections2()[0] response = api.sql(collection, snippet['statement']) info = response['result-set']['docs'].pop(-1) # EOF, RESPONSE_TIME, EXCEPTION if info.get('EXCEPTION'): raise QueryError(info['EXCEPTION']) headers = [] for row in response['result-set']['docs']: for col in row.keys(): if col not in headers: headers.append(col) data = [[doc.get(col) for col in headers] for doc in response['result-set']['docs']] has_result_set = bool(data) return { 'sync': True, 'has_result_set': has_result_set, 'modified_row_count': 0, 'result': { 'has_more': False, 'data': data if has_result_set else [], 'meta': [{ 'name': col, 'type': '', 'comment': '' } for col in headers] if has_result_set else [], 'type': 'table' }, 'statement_id': 0, 'has_more_statements': False, 'statements_count': 1 }
def _fetch_collections(request): from search.conf import SOLR_URL path = request.GET['path'] item = None name = None if path: item = path if '/' in path: item, name = path.split('/') api = SolrApi(SOLR_URL.get(), request.user) if not item: return {"databases": ["collections", "configs"]} elif item and name: return {"authorizable_link": "/indexer/#edit/%s" % name, "extended_columns": [], "columns": [], "partition_keys": []} elif item == 'collections': return {"tables_meta": [{"comment": None, "type": "Table", "name": col} for col in api.collections2()]} elif item == 'configs': return {"tables_meta": [{"comment": None, "type": "Table", "name": conf} for conf in api.configs()]} else: raise PopupException(_('Authorizable %s could not be retrieved') % path)