You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2014/09/25 19:57:13 UTC
svn commit: r1627576 - in /qpid/dispatch/trunk:
python/qpid_dispatch/management/ python/qpid_dispatch_internal/
python/qpid_dispatch_internal/management/
python/qpid_dispatch_internal/router/ src/ tests/
Author: aconway
Date: Thu Sep 25 17:57:13 2014
New Revision: 1627576
URL: http://svn.apache.org/r1627576
Log:
DISPATCH-56: Remove dead configuration code.
Replace router.configuration with management.agent configuration code.
Modified:
qpid/dispatch/trunk/python/qpid_dispatch/management/entity.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/dispatch_c.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/config.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/router/configuration.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py
qpid/dispatch/trunk/src/dispatch.c
qpid/dispatch/trunk/src/router_private.h
qpid/dispatch/trunk/src/router_pynode.c
qpid/dispatch/trunk/tests/router_engine_test.py
Modified: qpid/dispatch/trunk/python/qpid_dispatch/management/entity.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch/management/entity.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch/management/entity.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch/management/entity.py Thu Sep 25 17:57:13 2014
@@ -38,7 +38,8 @@ class Entity(object):
Attribute access:
- via index operator: entity['foo']
- - as python attributes: entity.foo (only if attribute name is a legal python identitfier)
+ - as python attributes: entity.foo (only if attribute name is a legal python identitfier
+ after replacing '-' with '_')
@ivar attributes: Map of attribute values for this entity.
@@ -47,28 +48,32 @@ class Entity(object):
"""
def __init__(self, attributes=None, **kwargs):
- self.__dict__['attributes'] = dict(attributes or [], **kwargs)
+ self.__dict__['attributes'] = {}
+ if attributes:
+ for k, v in attributes.iteritems():
+ self._set(k, v)
+ for k, v in kwargs.iteritems():
+ self._set(k, v)
def __getitem__(self, name): return self.attributes[name]
- def __setitem__(self, name, value): self.attributes[name] = value
+ def _pyname(self, name): return name.replace('-', '_')
- def __getattr__(self, name):
- try:
- return self.attributes[name]
- except KeyError:
- raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__, name))
-
- def __setattr__(self, name, value):
- if name in self.__dict__:
- super(Entity, self).__setattr__(name, value)
- else:
- self.attributes[name] = value
+ def _set(self, name, value):
+ self.attributes[name] = value
+ self.__dict__[self._pyname(name)] = value
+
+ # Subclasses should override __setitem__ to do extra actions on set,
+ # e.g. validation.
+ def __setitem__(self, name, value): self._set(name, value)
+
+ def __delitem__(self, name, value):
+ del self.attributes[name]
+ del self.__dict__[self._pyname(name)]
+
+ def __setattr__(self, name, value): self.__setitem__(name, value)
def __delattr__(self, name):
- try:
- del self.attributes[name]
- except KeyError:
- super(Entity, self).__delattr__(name)
+ self.__delitem__(name)
def __repr__(self): return "Entity(%r)" % self.attributes
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/dispatch_c.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/dispatch_c.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/dispatch_c.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/dispatch_c.py Thu Sep 25 17:57:13 2014
@@ -63,6 +63,7 @@ class QdDll(ctypes.PyDLL):
self._prototype(self.qd_dispatch_configure_address, None, [self.qd_dispatch_p, py_object])
self._prototype(self.qd_dispatch_configure_waypoint, None, [self.qd_dispatch_p, py_object])
self._prototype(self.qd_dispatch_set_agent, None, [self.qd_dispatch_p, py_object])
+ self._prototype(self.qd_router_setup_late, None, [self.qd_dispatch_p])
self._prototype(self.qd_connection_manager_start, None, [self.qd_dispatch_p])
self._prototype(self.qd_waypoint_activate_all, None, [self.qd_dispatch_p])
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py Thu Sep 25 17:57:13 2014
@@ -301,6 +301,9 @@ class Agent(object):
return entity
+ def find_entity_by_type(self, type):
+ return [e for e in self.entities if e.entity_type.name == type]
+
def delete(self, entity):
try:
self.entities.remove(entity)
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/management/config.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/config.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/config.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/config.py Thu Sep 25 17:57:13 2014
@@ -147,6 +147,11 @@ def configure_dispatch(dispatch, filenam
qd.qd_dispatch_configure_router(dispatch, config.by_type('router').next())
qd.qd_dispatch_prepare(dispatch)
+ # NOTE: Can't import agent till after qd_dispatch_prepare
+ from .agent import Agent
+ qd.qd_dispatch_set_agent(dispatch, Agent(dispatch, config.entities))
+ qd.qd_router_setup_late(dispatch); # Must come after qd_dispatch_set_agent
+
# Note must configure addresses, waypoints, listeners and connectors after qd_dispatch_prepare
for a in config.by_type('fixed-address'): qd.qd_dispatch_configure_address(dispatch, a)
for w in config.by_type('waypoint'): qd.qd_dispatch_configure_waypoint(dispatch, w)
@@ -155,6 +160,3 @@ def configure_dispatch(dispatch, filenam
qd.qd_connection_manager_start(dispatch)
qd.qd_waypoint_activate_all(dispatch)
- # NOTE: Can't import agent till after qd_dispatch_prepare
- from .agent import Agent
- qd.qd_dispatch_set_agent(dispatch, Agent(dispatch, config.entities))
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/router/configuration.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/router/configuration.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/router/configuration.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/router/configuration.py Thu Sep 25 17:57:13 2014
@@ -25,11 +25,7 @@ class Configuration(object):
##
## Load default values
##
- self.values = { 'hello_interval' : 1.0,
- 'hello_max_age' : 3.0,
- 'ra_interval' : 30.0,
- 'remote_ls_max_age' : 60.0,
- 'mobile_addr_max_age' : 60.0 }
+ self.values =
##
## Apply supplied overrides
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py Thu Sep 25 17:57:13 2014
@@ -19,7 +19,6 @@
from time import time
-from configuration import Configuration
from data import MessageHELLO, MessageRA, MessageLSU, MessageMAU, MessageMAR, MessageLSR
from neighbor import NeighborEngine
from link import LinkStateEngine
@@ -59,13 +58,7 @@ class RouterEngine:
self.area = area
self.log(LOG_INFO, "Router Engine Instantiated: area=%s id=%s max_routers=%d" %
(self.area, self.id, self.max_routers))
-
- ##
- ## Setup configuration
- ##
- self.config = Configuration(config_override)
- self.log(LOG_INFO, "Config: %r" % self.config)
-
+ self._config = None # Not yet loaded
##
## Launch the sub-module engines
##
@@ -87,6 +80,14 @@ class RouterEngine:
"""
return self.id
+ @property
+ def config(self):
+ if not self._config:
+ router_type = 'org.apache.qpid.dispatch.router'
+ routers = self.router_adapter.get_agent().find_entity_by_type(router_type)
+ if not routers: raise ValueError("No router configuration found")
+ self._config = routers[0]
+ return self._config
def addressAdded(self, addr):
"""
@@ -298,3 +299,4 @@ class RouterEngine:
def del_remote_router(self, router_bit):
self.log(LOG_DEBUG, "Event: del_remote_router: router_bit=%d" % router_bit)
self.router_adapter.del_remote_router(router_bit)
+
Modified: qpid/dispatch/trunk/src/dispatch.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/dispatch.c?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/dispatch.c (original)
+++ qpid/dispatch/trunk/src/dispatch.c Thu Sep 25 17:57:13 2014
@@ -130,7 +130,6 @@ qd_error_t qd_dispatch_prepare(qd_dispat
qd_alloc_setup_agent(qd);
qd_connection_manager_setup_agent(qd);
qd_container_setup_agent(qd);
- qd_router_setup_late(qd);
return qd_error_code();
}
Modified: qpid/dispatch/trunk/src/router_private.h
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_private.h?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_private.h (original)
+++ qpid/dispatch/trunk/src/router_private.h Thu Sep 25 17:57:13 2014
@@ -234,8 +234,6 @@ struct qd_router_t {
qd_agent_class_t *class_link;
qd_agent_class_t *class_node;
qd_agent_class_t *class_address;
-
- void *py_agent;
};
Modified: qpid/dispatch/trunk/src/router_pynode.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_pynode.c?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_pynode.c (original)
+++ qpid/dispatch/trunk/src/router_pynode.c Thu Sep 25 17:57:13 2014
@@ -462,6 +462,15 @@ static PyObject* qd_unmap_destination(Py
return Py_None;
}
+static PyObject* qd_get_agent(PyObject *self, PyObject *args) {
+ RouterAdapter *adapter = (RouterAdapter*) self;
+ PyObject *agent = adapter->router->qd->py_agent;
+ if (agent) {
+ Py_INCREF(agent);
+ return agent;
+ }
+ Py_RETURN_NONE;
+}
static PyMethodDef RouterAdapter_methods[] = {
{"add_remote_router", qd_add_remote_router, METH_VARARGS, "A new remote/reachable router has been discovered"},
@@ -472,6 +481,7 @@ static PyMethodDef RouterAdapter_methods
{"del_neighbor_router", qd_del_neighbor_router, METH_VARARGS, "We've lost reachability to a neighbor router"},
{"map_destination", qd_map_destination, METH_VARARGS, "Add a newly discovered destination mapping"},
{"unmap_destination", qd_unmap_destination, METH_VARARGS, "Delete a destination mapping"},
+ {"get_agent", qd_get_agent, METH_VARARGS, "Get the management agent"},
{0, 0, 0, 0}
};
@@ -683,3 +693,4 @@ void qd_router_link_lost(qd_router_t *ro
qd_python_unlock();
}
}
+
Modified: qpid/dispatch/trunk/tests/router_engine_test.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/router_engine_test.py?rev=1627576&r1=1627575&r2=1627576&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/router_engine_test.py (original)
+++ qpid/dispatch/trunk/tests/router_engine_test.py Thu Sep 25 17:57:13 2014
@@ -24,8 +24,9 @@ import unittest
sys.path.append(os.path.join(os.environ["SOURCE_DIR"], "python"))
sys.path.append(os.path.join(os.path.dirname(__file__), "mock")) # Mock modules for tests
-from qpid_dispatch_internal.router.engine import NeighborEngine, PathEngine, Configuration, NodeTracker
+from qpid_dispatch_internal.router.engine import NeighborEngine, PathEngine, NodeTracker
from qpid_dispatch_internal.router.data import LinkState, MessageHELLO
+from qpid_dispatch.management.entity import Entity
class Adapter(object):
def __init__(self, domain):
@@ -265,7 +266,13 @@ class NeighborTest(unittest.TestCase):
self.local_link_state = None
self.id = "R1"
self.area = "area"
- self.config = Configuration()
+ # Fake configuration
+ self.config = Entity({
+ 'hello_interval' : 1.0,
+ 'hello_max_age' : 3.0,
+ 'ra_interval' : 30.0,
+ 'remote_ls_max_age' : 60.0,
+ 'mobile_addr_max_age' : 60.0 })
self.neighbors = {}
def test_hello_sent(self):
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org