Commit 4865e8f6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Revert r1812 & r1814 (node manager as a singleton).

Singeltons can not be used in NEO because client side process may deals with
multiple NEO cluster. Add a callback on connection when linked with a node to
update node's connection property at connection closure.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1826 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2ed974e6
...@@ -52,13 +52,12 @@ class Application(object): ...@@ -52,13 +52,12 @@ class Application(object):
def __init__(self, config): def __init__(self, config):
NodeManager.init()
# always use default connector for now # always use default connector for now
self.connector_handler = getConnectorHandler() self.connector_handler = getConnectorHandler()
# Internal attributes. # Internal attributes.
self.em = EventManager() self.em = EventManager()
self.nm = NodeManager self.nm = NodeManager()
self.name = config.getCluster() self.name = config.getCluster()
self.server = config.getBind() self.server = config.getBind()
......
...@@ -100,8 +100,6 @@ class Application(object): ...@@ -100,8 +100,6 @@ class Application(object):
"""The client node application.""" """The client node application."""
def __init__(self, master_nodes, name, connector=None, **kw): def __init__(self, master_nodes, name, connector=None, **kw):
NodeManager.init()
# Start polling thread # Start polling thread
self.em = EventManager() self.em = EventManager()
self.poll_thread = ThreadedPoll(self.em) self.poll_thread = ThreadedPoll(self.em)
...@@ -110,7 +108,7 @@ class Application(object): ...@@ -110,7 +108,7 @@ class Application(object):
self.name = name self.name = name
self.connector_handler = getConnectorHandler(connector) self.connector_handler = getConnectorHandler(connector)
self.dispatcher = Dispatcher() self.dispatcher = Dispatcher()
self.nm = NodeManager self.nm = NodeManager()
self.cp = ConnectionPool(self) self.cp = ConnectionPool(self)
self.pt = None self.pt = None
self.master_conn = None self.master_conn = None
......
...@@ -202,6 +202,7 @@ class Connection(BaseConnection): ...@@ -202,6 +202,7 @@ class Connection(BaseConnection):
self._queue = [] self._queue = []
self._expected = deque() self._expected = deque()
self._next_handler = None self._next_handler = None
self._on_close = None
BaseConnection.__init__(self, event_manager, handler, BaseConnection.__init__(self, event_manager, handler,
connector = connector, addr = addr, connector = connector, addr = addr,
connector_handler = connector_handler) connector_handler = connector_handler)
...@@ -219,6 +220,10 @@ class Connection(BaseConnection): ...@@ -219,6 +220,10 @@ class Connection(BaseConnection):
else: else:
self.handler = handler self.handler = handler
def setOnClose(self, callback):
assert self._on_close is None
self._on_close = callback
def isAborted(self): def isAborted(self):
return self.aborted return self.aborted
...@@ -245,10 +250,9 @@ class Connection(BaseConnection): ...@@ -245,10 +250,9 @@ class Connection(BaseConnection):
BaseConnection.close(self) BaseConnection.close(self)
for event in self.event_dict.itervalues(): for event in self.event_dict.itervalues():
self.em.removeIdleEvent(event) self.em.removeIdleEvent(event)
from neo.node import NodeManager if self._on_close is not None:
node = NodeManager.getByUUID(self.getUUID()) self._on_close()
if node is not None: self._on_close = None
node.setConnection(None)
self.event_dict.clear() self.event_dict.clear()
self.write_buf = "" self.write_buf = ""
self.read_buf = "" self.read_buf = ""
......
...@@ -42,13 +42,12 @@ class Application(object): ...@@ -42,13 +42,12 @@ class Application(object):
def __init__(self, config): def __init__(self, config):
NodeManager.init()
# always use default connector for now # always use default connector for now
self.connector_handler = getConnectorHandler() self.connector_handler = getConnectorHandler()
# Internal attributes. # Internal attributes.
self.em = EventManager() self.em = EventManager()
self.nm = NodeManager self.nm = NodeManager()
self.tm = TransactionManager() self.tm = TransactionManager()
self.name = config.getCluster() self.name = config.getCluster()
......
...@@ -36,7 +36,6 @@ class StorageServiceHandler(BaseServiceHandler): ...@@ -36,7 +36,6 @@ class StorageServiceHandler(BaseServiceHandler):
def nodeLost(self, conn, node): def nodeLost(self, conn, node):
logging.info('storage node lost') logging.info('storage node lost')
assert not node.isRunning(), node.getState() assert not node.isRunning(), node.getState()
node.setConnection(None)
if not self.app.pt.operational(): if not self.app.pt.operational():
raise OperationFailure, 'cannot continue operation' raise OperationFailure, 'cannot continue operation'
......
...@@ -106,7 +106,6 @@ class RecoveryManager(MasterHandler): ...@@ -106,7 +106,6 @@ class RecoveryManager(MasterHandler):
assert node is not None assert node is not None
if node.getState() == new_state: if node.getState() == new_state:
return return
node.setConnection(None)
node.setState(new_state) node.setState(new_state)
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
......
...@@ -249,7 +249,6 @@ class VerificationManager(BaseServiceHandler): ...@@ -249,7 +249,6 @@ class VerificationManager(BaseServiceHandler):
pass pass
def nodeLost(self, conn, node): def nodeLost(self, conn, node):
node.setConnection(None)
if not self.app.pt.operational(): if not self.app.pt.operational():
raise VerificationFailure, 'cannot continue verification' raise VerificationFailure, 'cannot continue verification'
...@@ -77,9 +77,15 @@ class Node(object): ...@@ -77,9 +77,15 @@ class Node(object):
def getUUID(self): def getUUID(self):
return self._uuid return self._uuid
def onConnectionClosed(self):
assert self._connection is not None
self._connection = None
def setConnection(self, connection): def setConnection(self, connection):
assert self._connection is None or connection is None assert connection is not None
assert self._connection is None
self._connection = connection self._connection = connection
connection.setOnClose(self.onConnectionClosed)
def getConnection(self): def getConnection(self):
assert self._connection is not None assert self._connection is not None
...@@ -429,5 +435,3 @@ class NodeManager(object): ...@@ -429,5 +435,3 @@ class NodeManager(object):
logging.debug(' * %32s | %8s | %22s | %s' % ( logging.debug(' * %32s | %8s | %22s | %s' % (
uuid, node.getType(), address, node.getState())) uuid, node.getType(), address, node.getState()))
# pseudo singleton
NodeManager = NodeManager()
...@@ -38,8 +38,6 @@ class Application(object): ...@@ -38,8 +38,6 @@ class Application(object):
"""The storage node application.""" """The storage node application."""
def __init__(self, config): def __init__(self, config):
NodeManager.init()
# always use default connector for now # always use default connector for now
self.connector_handler = getConnectorHandler() self.connector_handler = getConnectorHandler()
...@@ -48,7 +46,7 @@ class Application(object): ...@@ -48,7 +46,7 @@ class Application(object):
# Internal attributes. # Internal attributes.
self.em = EventManager() self.em = EventManager()
self.nm = NodeManager self.nm = NodeManager()
self.tm = TransactionManager(self) self.tm = TransactionManager(self)
self.dm = buildDatabaseManager(config.getAdapter(), config.getDatabase()) self.dm = buildDatabaseManager(config.getAdapter(), config.getDatabase())
......
...@@ -125,7 +125,7 @@ class NodesTests(NeoTestBase): ...@@ -125,7 +125,7 @@ class NodesTests(NeoTestBase):
class NodeManagerTests(NeoTestBase): class NodeManagerTests(NeoTestBase):
def setUp(self): def setUp(self):
self.manager = nm = NodeManager.__class__() self.manager = nm = NodeManager()
self.storage = StorageNode(nm, ('127.0.0.1', 1000), self.getNewUUID()) self.storage = StorageNode(nm, ('127.0.0.1', 1000), self.getNewUUID())
self.master = MasterNode(nm, ('127.0.0.1', 2000), self.getNewUUID()) self.master = MasterNode(nm, ('127.0.0.1', 2000), self.getNewUUID())
self.client = ClientNode(nm, None, self.getNewUUID()) self.client = ClientNode(nm, None, self.getNewUUID())
......
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