Browse Source

HUE-7585 [core] Tweak config creation to not override the base one

Romain Rigaux 8 years ago
parent
commit
5b0d84fe88

+ 1 - 5
desktop/libs/indexer/src/indexer/indexers/morphline.py

@@ -139,7 +139,7 @@ class MorphlineIndexer(object):
       curr_field = queue.popleft()
       curr_field['type'] = curr_field['type']
       if is_converting_types:
-        self._port_field_types(curr_field)
+        SolrClient._port_field_types(curr_field)
       fields.append(curr_field)
 
       for operation in curr_field["operations"]:
@@ -148,10 +148,6 @@ class MorphlineIndexer(object):
 
     return fields
 
-  def _port_field_types(self, field):
-    if not field['type'].startswith('p'): # Check for automatically converting to new default Solr types
-      field['type'] = field['type'].replace('long', 'plong').replace('double', 'pdouble').replace('date', 'pdate')
-
   def get_kept_field_list(self, field_data):
     return [field for field in self.get_field_list(field_data) if field['keep']]
 

+ 1 - 1
desktop/libs/indexer/src/indexer/solr_api.py

@@ -131,7 +131,7 @@ def delete_indexes(request):
 
     for index in indexes:
       if index['type'] == 'collection':
-        client.delete_index(index['name'])
+        client.delete_index(index['name'], keep_config=False)
       elif index['type'] == 'alias':
         client.delete_alias(index['name'])
       else:

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

@@ -96,17 +96,19 @@ class SolrClient(object):
       if self.is_solr_six_or_more():
         if not config_name:
           config_sets = self.list_configs()
-          if self.is_sentry_protected:
+          if self.is_sentry_protected():
             config_sets = [config for config in config_sets if 'Secure' in config]
           if not config_sets:
-            raise PopupException(_('Solr does not have any predefined (secure: %s) configSets: %s') % (self.is_sentry_protected, self.list_configs()))
+            raise PopupException(_('Solr does not have any predefined (secure: %s) configSets: %s') % (self.is_sentry_protected(), self.list_configs()))
 
           config_name_target = 'managedTemplate'
-          if self.is_sentry_protected:
+          if self.is_sentry_protected():
             config_name_target += 'Secure'
 
           if config_name_target in config_sets:
             config_name = config_name_target
+          elif '_default' in config_sets:
+            config_name = '_default'
           else:
             config_name = config_sets[0]
 
@@ -121,13 +123,13 @@ class SolrClient(object):
               }
             })
 
-        self.api.create_collection2(name, config_name=config_name, shards=shards, replication=replication)
+        self.api.create_collection2(name, config_name=name, shards=shards, replication=replication)
 
         fields = [{
             'name': field['name'],
-            'type': field['type'],
+            'type': SolrClient._port_field_types(field)['type'],
             'stored': field.get('stored', True)
-          } for field in fields
+          } for field in fields if field['name'] != 'id'
         ]
         self.api.add_fields(name, fields)
       else:
@@ -321,6 +323,13 @@ class SolrClient(object):
         _IS_SENTRY_PROTECTED = True
 
 
+  @staticmethod
+  def _port_field_types(field):
+    if not field['type'].startswith('p'): # Check for automatically converting to new default Solr types
+      field['type'] = field['type'].replace('long', 'plong').replace('double', 'pdouble').replace('date', 'pdate')
+    return field
+
+
   def _reset_properties(self):
     global _IS_SOLR_CLOUD
     global _IS_SOLR_6_OR_MORE

+ 3 - 3
desktop/libs/libsolr/src/libsolr/api.py

@@ -373,9 +373,9 @@ class SolrApi(object):
     try:
       params = self._get_params() + (
           ('action', 'CREATE'),
-          ('myConfigSet', name),
+          ('name', name),
           ('baseConfigSet', base_config),
-          ('configSetProp.immutable', 'false' if immutable else 'true'),
+          ('configSetProp.immutable', immutable),
           ('wt', 'json'),
       )
       return self._root.post('admin/configs', params=params, contenttype='application/json')
@@ -393,7 +393,7 @@ class SolrApi(object):
         ('wt', 'json')
       )
 
-      data = self._root.post('admin/configs', params=params, contenttype='application/json')
+      data = self._root.get('admin/configs', params=params)
       if data['responseHeader']['status'] == 0:
         response['status'] = 0
       else: