Commit 6edf3466 authored by Alexandre Fayolle's avatar Alexandre Fayolle
Browse files

allow CW to act as a Pyro Server without registering the server to a Pyro...

allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)

This is achieved by configuring the pyro-ns-host to __NO_PYRONS__ (which is an illegal value for a host name)

The Pyro URI for the server can be retrieved by reading the pyro_uri attribute of the Repository

branch : stable
parent 110f38b322ef
......@@ -325,7 +325,8 @@ class CubicWebNoAppConfiguration(ConfigurationMixIn):
{'type' : 'string',
'default': '',
'help': 'Pyro name server\'s host. If not set, will be detected by a \
broadcast query. It may contains port information using <host>:<port> notation.',
broadcast query. It may contains port information using <host>:<port> notation. \
Use "NO_PYRONS" to create a Pyro server but not register to a pyro nameserver',
'group': 'pyro', 'level': 1,
......@@ -102,11 +102,14 @@ def get_repository(method, database=None, config=None, vreg=None):
return Repository(config, vreg=vreg)
else: # method == 'pyro'
# resolve the Pyro object
from logilab.common.pyro_ext import ns_get_proxy
from logilab.common.pyro_ext import ns_get_proxy, get_proxy
pyroid = database or config['pyro-instance-id'] or config.appid
return ns_get_proxy(pyroid, defaultnsgroup=config['pyro-ns-group'],
if config['pyro-ns-host'] == 'NO_PYRONS':
return get_proxy(pyroid)
return ns_get_proxy(pyroid, defaultnsgroup=config['pyro-ns-group'],
except Exception, ex:
raise ConnectionError(str(ex))
......@@ -59,6 +59,7 @@ from cubicweb.server.session import Session, InternalSession, InternalManager, \
from cubicweb.server.ssplanner import EditedEntity
def prefill_entity_caches(entity, relations):
session = entity._cw
# prefill entity relation caches
......@@ -134,6 +135,7 @@ class Repository(object):
vreg = cwvreg.CubicWebVRegistry(config)
self.vreg = vreg
self.pyro_registered = False
self.pyro_uri = None'starting repository from %s', self.config.apphome)
# dictionary of opened sessions
self._sessions = {}
......@@ -415,7 +417,9 @@ class Repository(object):
self.exception('error while closing %s' % pool)
if self.pyro_registered:
if self._use_pyrons():
self.pyro_uri = None
hits, misses = self.querier.cache_hit, self.querier.cache_miss
try:'rql st cache hit/miss: %s/%s (%s%% hits)', hits, misses,
......@@ -1419,20 +1423,32 @@ class Repository(object):
config['pyro-instance-id'] = appid
return appid
def _use_pyrons(self):
"""return True if the pyro-ns-host is set to something else
than NO_PYRONS, meaning we want to go through a pyro
return self.config['pyro-ns-host'] != 'NO_PYRONS'
def pyro_register(self, host=''):
"""register the repository as a pyro object"""
from logilab.common import pyro_ext as pyro
daemon = pyro.register_object(self, self.pyro_appid,
use_pyrons=self._use_pyrons())'repository registered as a pyro object %s', self.pyro_appid)
self.pyro_uri = pyro.get_object_uri(self.pyro_appid)'pyro uri is: %s', self.pyro_uri)
self.pyro_registered = True
# register a looping task to regularly ensure we're still registered
# into the pyro name server
self.looping_task(60*10, self._ensure_pyro_ns)
if self._use_pyrons():
self.looping_task(60*10, self._ensure_pyro_ns)
return daemon
def _ensure_pyro_ns(self):
if not self._use_pyrons():
from logilab.common import pyro_ext as pyro
pyro.ns_reregister(self.pyro_appid, nshost=self.config['pyro-ns-host'])'repository re-registered as a pyro object %s',
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment