Эх сурвалжийг харах

HUE-7598 [indexer] Add the collection config to the collection page

Romain Rigaux 8 жил өмнө
parent
commit
42d3375

+ 15 - 0
desktop/libs/indexer/src/indexer/solr_api.py

@@ -176,6 +176,21 @@ def sample_index(request):
   return JsonResponse(response)
 
 
+@require_POST
+@api_error_handler
+def config_index(request):
+  response = {'status': -1}
+
+  name = request.POST.get('name')
+
+  client = SolrClient(user=request.user)
+
+  response['config'] = client.get_config(name)
+  response['status'] = 0
+
+  return JsonResponse(response)
+
+
 @require_POST
 @api_error_handler
 def list_configs(request):

+ 6 - 0
desktop/libs/indexer/src/indexer/solr_client.py

@@ -199,6 +199,10 @@ class SolrClient(object):
     return self.api.select(collection, rows=min(rows, 1000))
 
 
+  def get_config(self, collection):
+    return self.api.config(collection)
+
+
   def list_configs(self):
     return self.api.configs()
 
@@ -260,6 +264,7 @@ class SolrClient(object):
     return _ZOOKEEPER_HOST
 
 
+  # Deprecated
   def _create_cloud_config(self, name, fields, unique_key_field, df):
     with ZookeeperClient(hosts=self.get_zookeeper_host(), read_only=False) as zc:
       tmp_path, solr_config_path = copy_configs(
@@ -287,6 +292,7 @@ class SolrClient(object):
         shutil.rmtree(tmp_path)
 
 
+  # Deprecated
   def _create_non_solr_cloud_index(self, name, fields, unique_key_field, df):
     # Create instance directory locally.
     instancedir = os.path.join(CORE_INSTANCE_DIR.get(), name)

+ 31 - 0
desktop/libs/indexer/src/indexer/templates/indexes.mako

@@ -295,6 +295,7 @@ ${ assist.assistPanel() }
     <li class="active"><a href="#index-overview" data-toggle="tab" data-bind="click: function(){ $root.tab('index-overview'); }">${_('Overview')}</a></li>
     <li><a href="#index-columns" data-toggle="tab" data-bind="click: function(){ $root.tab('index-columns'); }">${_('Fields')} (<span data-bind="text: fields().length"></span>)</a></li>
     <li><a href="#index-sample" data-toggle="tab" data-bind="click: function(){ $root.tab('index-sample'); }">${_('Sample')} (<span data-bind="text: sample().length"></span>)</a></li>
+    <li><a href="#index-config" data-toggle="tab" data-bind="click: function(){ if (!config()) { getConfig(); }; $root.tab('index-config'); }">${_('Config')}</a></li>
   </ul>
 
   <div class="tab-content" style="border: none; overflow: hidden">
@@ -319,6 +320,17 @@ ${ assist.assistPanel() }
       <div class="margin-top-10 margin-left-10">${ _('The index does not contain any data.')}</div>
       <!-- /ko -->
     </div>
+
+    <div class="tab-pane" id="index-config">
+      <!-- ko hueSpinner: { spin: $root.index().loadingConfig, center: true, size: 'xlarge' } --><!-- /ko -->
+
+      <!-- ko if: config() && config().length > 0 -->
+        <span data-bind="text: ko.mapping.toJSON(config)"></span>
+      <!-- /ko -->
+      <!-- ko if: !config() || config().length === 0 -->
+      <div class="margin-top-10 margin-left-10">${ _('The config could not be retrieved.')}</div>
+      <!-- /ko -->
+    </div>
   </div>
 </script>
 
@@ -549,6 +561,7 @@ ${ assist.assistPanel() }
 
       self.dynamicFields = ko.mapping.fromJS(index.schema.dynamicFields);
       self.copyFields = ko.mapping.fromJS(index.schema.copyFields);
+      self.config = ko.observable('');
 
       self.sample = ko.observableArray();
       self.samplePreview = ko.pureComputed(function () {
@@ -556,6 +569,7 @@ ${ assist.assistPanel() }
       });
 
       self.loadingSample = ko.observable(false);
+      self.loadingConfig = ko.observable(false);
 
       self.getSample = function () {
         self.loadingSample(true);
@@ -575,6 +589,23 @@ ${ assist.assistPanel() }
         });
       };
 
+      self.getConfig = function () {
+        self.loadingConfig(true);
+        $.post("${ url('indexer:config_index') }", {
+          name: self.name()
+        }, function (data) {
+          if (data.status == 0) {
+            self.config(data.config);
+          } else {
+            $(document).trigger("error", data.message);
+          }
+        }).fail(function (xhr, textStatus, errorThrown) {
+          $(document).trigger("error", xhr.responseText);
+        }).always(function () {
+          self.loadingConfig(false);
+        });
+      };
+
       self.delete = function () {
         var indexName = self.name();
         $.post("${ url('indexer:delete_indexes') }", {

+ 1 - 0
desktop/libs/indexer/src/indexer/urls.py

@@ -48,6 +48,7 @@ urlpatterns += patterns('indexer.solr_api',
   url(r'^api/indexes/list/$', 'list_indexes', name='list_indexes'),
   url(r'^api/indexes/create/$', 'create_index', name='create_index'),
   url(r'^api/indexes/sample/$', 'sample_index', name='sample_index'),
+  url(r'^api/indexes/config/$', 'config_index', name='config_index'),
   url(r'^api/indexes/delete/$', 'delete_indexes', name='delete_indexes'),
 )
 

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

@@ -358,6 +358,17 @@ class SolrApi(object):
       raise PopupException(e, title=_('Error while accessing Solr'))
 
 
+  def config(self, name):
+    try:
+      params = self._get_params() + (
+          ('wt', 'json'),
+      )
+      response = self._root.get('%s/config' % name, params=params)
+      return self._get_json(response)['config']
+    except RestException, e:
+      raise PopupException(e, title=_('Error while accessing Solr'))
+
+
   def configs(self):
     try:
       params = self._get_params() + (