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

HUE-5116 [indexes] Remove unfinished create collection from a file

Romain Rigaux 8 жил өмнө
parent
commit
40a32bd

+ 18 - 13
desktop/libs/indexer/src/indexer/controller2.py

@@ -17,6 +17,7 @@
 # limitations under the License.
 
 import logging
+import json
 import os
 import shutil
 
@@ -74,9 +75,9 @@ class IndexController(object):
         for name in collections:
           indexes.append({'name': name, 'type': 'collection', 'collections': []})
 
-      solr_cores = self.api.cores()
-      for name in solr_cores:
-        indexes.append({'name': name, 'type': 'core', 'collections': []})
+#       solr_cores = self.api.cores()
+#       for name in solr_cores:
+#         indexes.append({'name': name, 'type': 'core', 'collections': []})
 
       if self.is_solr_cloud_mode():
         try:
@@ -164,18 +165,22 @@ class IndexController(object):
     if not self.is_solr_cloud_mode():
       raise PopupException(_('Cannot remove non-Solr cloud cores.'))
 
-    if self.api.remove_collection(name):
+    result = self.api.delete_collection(name)
+        
+    if result['status'] == 0:
       # Delete instance directory.
-      try:
-        root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
-        with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc:
-          zc.delete_path(root_node)
-      except Exception, e:
-        # Re-create collection so that we don't have an orphan config
-        self.api.add_collection(name)
-        raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
+#       try:
+#         root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
+#         with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc:
+#           zc.delete_path(root_node)
+#       except Exception, e:
+#         # Re-create collection so that we don't have an orphan config
+#         self.api.add_collection(name)
+#         raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
+      pass
     else:
-      raise PopupException(_('Could not remove collection. Check error logs for more info.'))
+      if not 'Cannot unload non-existent core' in json.dumps(result):
+        raise PopupException(_('Could not remove collection: %(message)s') % result)
 
 
   def get_index_schema(self, index_name):

+ 1 - 1
desktop/libs/indexer/src/indexer/templates/collections.mako

@@ -360,7 +360,7 @@ ${ commonheader(_('Search Indexes'), "indexer", user, request, "90px") | n,unico
     <ul class="nav nav-list">
       <li class="nav-header">${_('Actions')}</li>
       <li><a data-bind="hueLink: '/search/browse/' + collection().name()"><i class="fa fa-search"></i> ${ _('Search') }</a></li>
-      <li><a data-bind="routie: 'edit/' + collection().name() + '/upload'" href="javascript:void(0)"><i class="fa fa-arrow-circle-o-down"></i> ${_('Index file')}</a></li>
+      <li><a data-bind="routie: 'edit/' + collection().name() + '/upload'" href="javascript:void(0)"><i class="fa fa-arrow-circle-o-down"></i> ${_('Add data')}</a></li>
       <li><a data-bind="visible: !collection().isCoreOnly()" href="#deleteCollection" data-toggle="modal"><i class="fa fa-times"></i> ${_('Delete')}</a></li>
     </ul>
   </div>

+ 7 - 0
desktop/libs/indexer/src/indexer/templates/indexer.mako

@@ -457,6 +457,13 @@ ${ assist.assistPanel() }
   <br>
 </script>
 
+<script type="text/html" id="arg-text-delimiter">
+  <label>
+    <div data-bind="text: description"></div>
+    <select data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: value, optionsValue: 'value', optionsText: 'name', attr: {placeholder: description}"></select>
+  </label>
+</script>
+
 <script type="text/html" id="field-preview-header-template">
   <th data-bind="visible: keep, text: name" style="padding-right:60px"></th>
   <!-- ko foreach: operations -->

+ 3 - 71
desktop/libs/indexer/src/indexer/templates/indexes.mako

@@ -18,14 +18,15 @@
   from desktop.views import commonheader, commonfooter, commonshare, commonimportexport
   from django.utils.translation import ugettext as _
 %>
+
 <%namespace name="actionbar" file="actionbar.mako" />
 
-${ commonheader(_("Solr Indexes"), "search", user, request, "60px") | n,unicode }
+${ commonheader(_("Index Browser"), "search", user, request, "60px") | n,unicode }
 
 
 <div class="container-fluid">
   <div class="card card-small">
-  <h1 class="card-heading simple">${ _('Solr Indexes') }</h1>
+  <h1 class="card-heading simple">${ _('Index Browser') }</h1>
 
   <%actionbar:render>
     <%def name="search()">
@@ -43,9 +44,6 @@ ${ commonheader(_("Solr Indexes"), "search", user, request, "60px") | n,unicode
     <%def name="creation()">
       <a href="javascript:void(0)" class="btn" data-bind="click: function() { index.showCreateModal(true) }">
         <i class="fa fa-plus-circle"></i> ${ _('Create index') }
-      </a>
-      <a href="javascript:void(0)" class="btn" data-bind="click: function() { createWizard.show(true) }">
-        <i class="fa fa-plus-circle"></i> ${ _('Create index from a file') }
       </a>      
       <a href="javascript:void(0)" class="btn" data-bind="click: function() { alias.showCreateModal(true) }">
         <i class="fa fa-plus-circle"></i> ${ _('Create alias') }
@@ -125,72 +123,6 @@ ${ commonheader(_("Solr Indexes"), "search", user, request, "60px") | n,unicode
 </script>
 
 
-<!-- ko template: 'create-index-wizard' --><!-- /ko -->
-
-<script type="text/html" id="create-index-wizard">
-  <div class="snippet-settings" data-bind="visible: createWizard.show">
-
-    ${ _('Name') } <input type="text" data-bind="value: createWizard.name"/>
-    
-    <!-- ko if: createWizard.name() -->
-    <select data-bind="options: createWizard.availableWizards, value: createWizard.wizard, optionsText: 'name'" size="5"></select>
-
-    <span data-bind="template: { name: 'create-index-from-file', data: createWizard.wizard }"></span>
-    <span data-bind="template: { name: 'create-index-from-hive', data: createWizard.wizard }"></span>
-    
-    <ul data-bind="foreach: createWizard.wizard().sample">
-      <li>
-        <div data-bind="foreach: $data">
-          <span data-bind="text: $data"></span>
-        </div>
-        <a rel="tooltip" data-placement="bottom" data-bind="css: {'btn': true}" class="btn" data-original-title="Edit">
-          <i class="fa fa-pencil"></i>
-        </a>
-      </li>
-    </ul>
-
-    <a href="javascript:void(0)" class="btn" data-bind="click: createWizard.getSample">
-      <i class="fa fa-list-alt"></i> ${ _('Get Sample') }
-    </a>
-
-    <!-- /ko -->
-
-    <br/>
-
-    <a href="javascript:void(0)" class="btn" data-bind="visible: createWizard.showCreate, click: createWizard.create">
-      <i class="fa fa-plus-circle"></i> ${ _('Create') }
-    </a>
-    <a href="javascript:void(0)" class="btn" data-bind="click: function() { createWizard.show(false) }">
-      <i class="fa fa-plus-circle"></i> ${ _('Cancel') }
-    </a>
-  </div>
-</script>
-
-
-<script type="text/html" id="create-index-from-file">
-  <!-- ko if: name() == 'file' -->
-    <div class="snippet-settings" data-bind="visible: show">
-
-      ${ _('Path') } <input type="text" data-bind="value: path"/>
-      <select data-bind="visible: path, options: availableFormats, value: format" size="5"></select>
-
-    </div>
-  <!-- /ko -->
-</script>
-
-
-<script type="text/html" id="create-index-from-hive">
-  <!-- ko if: name() == 'hive' -->
-    <div class="snippet-settings" data-bind="visible: show">
-
-      ${ _('Database') } <input type="text" data-bind="value: database"/>
-      ${ _('Table') } <input type="text" data-bind="value: table"/>
-
-    </div>
-  <!-- /ko -->
-</script>
-
-
 <div class="hueOverlay" data-bind="visible: isLoading">
   <i class="fa fa-spinner fa-spin big-spinner"></i>
 </div>

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

@@ -442,6 +442,7 @@ class SolrApi(object):
     except RestException, e:
         raise PopupException(e, title=_('Error while accessing Solr'))
 
+  # Deprecated
   def remove_collection(self, name):
     try:
       params = self._get_params() + (
@@ -459,6 +460,28 @@ class SolrApi(object):
     except RestException, e:
       raise PopupException(e, title=_('Error while accessing Solr'))
 
+
+  def delete_collection(self, name):
+    response = {'status': -1, 'message': ''}
+
+    try:
+      params = self._get_params() + (
+        ('action', 'DELETE'),
+        ('name', name),
+        ('wt', 'json')
+      )
+
+      result = self._root.post('admin/collections', params=params, contenttype='application/json')
+      if 'success' in result:
+        response['status'] = 0
+      else:
+        LOG.error("Could not remove collection: %s" % result)
+        response['message'] = result.get('failure')
+    except RestException, e:
+      raise PopupException(e, title=_('Error while accessing Solr'))
+    return response
+    
+
   def remove_core(self, name):
     try:
       params = self._get_params() + (