Use ZODBConnection class instead of ZEOConnection to handle any ZODB storage for content indexer
authorThierry Florac <thierry.florac@onf.fr>
Thu, 11 Jan 2018 17:21:16 +0100
changeset 35 e413f8bd1ad5
parent 34 a49941e01c4f
child 36 9f851a6477b5
Use ZODBConnection class instead of ZEOConnection to handle any ZODB storage for content indexer
src/pyams_content_es/include.py
src/pyams_content_es/interfaces/__init__.py
src/pyams_content_es/process.py
src/pyams_content_es/utility.py
src/pyams_content_es/zmi/__init__.py
--- a/src/pyams_content_es/include.py	Mon Dec 11 15:26:59 2017 +0100
+++ b/src/pyams_content_es/include.py	Thu Jan 11 17:21:16 2018 +0100
@@ -66,6 +66,7 @@
             process.start()
             if process.is_alive():
                 atexit.register(process_exit_func, process=process)
+                logger.debug('Started content indexer process {0!r} with PID {1}...'.format(process, process.pid))
         finally:
             if process and not process.is_alive():
                 process.terminate()
--- a/src/pyams_content_es/interfaces/__init__.py	Mon Dec 11 15:26:59 2017 +0100
+++ b/src/pyams_content_es/interfaces/__init__.py	Thu Jan 11 17:21:16 2018 +0100
@@ -39,10 +39,10 @@
 class IContentIndexerUtility(Interface):
     """Content indexer utility interface"""
 
-    zeo_connection = Choice(title=_("ZEO connection name"),
-                            description=_("Name of ZEO connection utility defining indexer connection"),
-                            required=False,
-                            vocabulary="PyAMS ZEO connections")
+    zodb_name = Choice(title=_("ZODB connection name"),
+                       description=_("Name of ZODB connection defining indexer connection"),
+                       required=False,
+                       vocabulary="PyAMS ZODB connections")
 
     def index_document(self, document):
         """Index given document"""
--- a/src/pyams_content_es/process.py	Mon Dec 11 15:26:59 2017 +0100
+++ b/src/pyams_content_es/process.py	Thu Jan 11 17:21:16 2018 +0100
@@ -29,7 +29,7 @@
 
 # import packages
 from pyams_utils.registry import set_local_registry, get_utility
-from pyams_utils.zodb import ZEOConnection
+from pyams_utils.zodb import ZODBConnection
 from pyams_zmq.handler import ZMQMessageHandler
 from pyams_zmq.process import ZMQProcess
 from pyramid.threadlocal import manager as threadlocal_manager
@@ -57,19 +57,17 @@
         # Check settings
         settings = self.settings
         logger.debug("Checking index parameters: {0}".format(str(settings)))
-        zeo_settings = settings.get('zeo')
         document_id = settings.get('document')
-        if not (zeo_settings and document_id):
+        if not document_id:
             logger.warning('Bad indexer request: {0}'.format(str(settings)))
             return
-        # Open ZEO connection
+        # Open ZODB connection
         manager = None
-        connection_info = ZEOConnection()
-        connection_info.update(zeo_settings)
-        logger.debug("Opening ZEO connection...")
-        storage, db = connection_info.get_connection(get_storage=True)
+        zodb_name = settings.get('zodb_name')
+        logger.debug("Opening ZODB connection...")
+        zodb = ZODBConnection(name=zodb_name)
+        connection = zodb.get_connection()
         try:
-            connection = db.open()
             root = connection.root()
             logger.debug("Getting connection root {0!r}".format(root))
             application_name = registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME)
@@ -98,7 +96,6 @@
             if manager is not None:
                 manager.abort()
             connection.close()
-            storage.close()
             threadlocal_manager.pop()
 
     def update_index(self, client, document):
--- a/src/pyams_content_es/utility.py	Mon Dec 11 15:26:59 2017 +0100
+++ b/src/pyams_content_es/utility.py	Thu Jan 11 17:21:16 2018 +0100
@@ -17,7 +17,6 @@
 
 # import interfaces
 from pyams_content_es.interfaces import IContentIndexerUtility, INDEXER_HANDLER_KEY
-from pyams_utils.interfaces.zeo import IZEOConnection
 from zope.intid.interfaces import IIntIds
 
 # import packages
@@ -34,7 +33,7 @@
 class ContentIndexerUtility(Persistent, Contained):
     """Content indexer utility"""
 
-    zeo_connection = FieldProperty(IContentIndexerUtility['zeo_connection'])
+    zodb_name = FieldProperty(IContentIndexerUtility['zodb_name'])
 
     def _get_socket(self):
         registry = getGlobalSiteManager()
@@ -47,11 +46,8 @@
         socket = self._get_socket()
         if socket is None:
             return [501, "No socket handler defined in configuration file"]
-        if not self.zeo_connection:
-            return [502, "Missing ZEO connection"]
-        zeo = get_utility(IZEOConnection, self.zeo_connection)
         intids = get_utility(IIntIds)
-        settings = {'zeo': zeo.get_settings(),
+        settings = {'zodb_name': self.zodb_name,
                     'document': intids.register(document)}
         socket.send_json(['index', settings])
         return zmq_response(socket)
@@ -61,11 +57,8 @@
         socket = self._get_socket()
         if socket is None:
             return [501, "No socket handler defined in configuration file"]
-        if not self.zeo_connection:
-            return [502, "Missing ZEO connection"]
-        zeo = get_utility(IZEOConnection, self.zeo_connection)
         intids = get_utility(IIntIds)
-        settings = {'zeo': zeo.get_settings(),
+        settings = {'zodb_name': self.zodb_name,
                     'document': intids.register(document)}
         socket.send_json(['unindex', settings])
         return zmq_response(socket)
@@ -75,7 +68,5 @@
         socket = self._get_socket()
         if socket is None:
             return [501, "No socket handler defined in configuration file"]
-        if not self.zeo_connection:
-            return [502, "Missing ZEO connection"]
         socket.send_json(['test', {}])
         return zmq_response(socket)
--- a/src/pyams_content_es/zmi/__init__.py	Mon Dec 11 15:26:59 2017 +0100
+++ b/src/pyams_content_es/zmi/__init__.py	Thu Jan 11 17:21:16 2018 +0100
@@ -50,7 +50,7 @@
     
     legend = _("Update content indexer properties")
     
-    fields = field.Fields(IContentIndexerUtility).select('zeo_connection')
+    fields = field.Fields(IContentIndexerUtility).select('zodb_name')
 
     ajax_handler = 'properties.json'
     edit_permission = MANAGE_SYSTEM_PERMISSION