Commit bed32b02 authored by Aurel's avatar Aurel

- setCell will automatically remove cell in DISCARDED_STATE so remove

useless code
- catch exception in case of node known without any address
- rewrite way to handle node information message to retrieve node both
by uuid and/or address


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@575 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 5f547613
...@@ -20,7 +20,7 @@ import logging ...@@ -20,7 +20,7 @@ import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import INVALID_UUID, RUNNING_STATE, BROKEN_STATE, \ from neo.protocol import INVALID_UUID, RUNNING_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \ MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
ADMIN_NODE_TYPE, DISCARDED_STATE, TEMPORARILY_DOWN_STATE ADMIN_NODE_TYPE, DISCARDED_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE
from neo.node import MasterNode, StorageNode, ClientNode from neo.node import MasterNode, StorageNode, ClientNode
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo import protocol from neo import protocol
...@@ -90,7 +90,11 @@ class AdminEventHandler(BaseEventHandler): ...@@ -90,7 +90,11 @@ class AdminEventHandler(BaseEventHandler):
node_list = self.app.nm.getNodeList(node_filter) node_list = self.app.nm.getNodeList(node_filter)
node_information_list = [] node_information_list = []
for node in node_list: for node in node_list:
ip, port = node.getServer() try:
ip, port = node.getServer()
except TypeError:
ip = "0.0.0.0"
port = 0
node_information_list.append((node.getNodeType(), ip, port, node.getUUID(), node.getState())) node_information_list.append((node.getNodeType(), ip, port, node.getUUID(), node.getState()))
p = protocol.answerNodeList(node_information_list) p = protocol.answerNodeList(node_information_list)
conn.ask(p) conn.ask(p)
...@@ -343,16 +347,13 @@ class MonitoringEventHandler(BaseEventHandler): ...@@ -343,16 +347,13 @@ class MonitoringEventHandler(BaseEventHandler):
if uuid != app.uuid: if uuid != app.uuid:
node.setState(TEMPORARILY_DOWN_STATE) node.setState(TEMPORARILY_DOWN_STATE)
nm.add(node) nm.add(node)
if state == DISCARDED_STATE: pt.setCell(offset, node, state)
pt.removeCell(offset, node)
else:
pt.setCell(offset, node, state)
pt.log() pt.log()
@identification_required @identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list): def handleNotifyNodeInformation(self, conn, packet, node_list):
logging.warning("handleNotifyNodeInformation") logging.info("handleNotifyNodeInformation")
uuid = conn.getUUID() uuid = conn.getUUID()
app = self.app app = self.app
nm = app.nm nm = app.nm
...@@ -365,11 +366,23 @@ class MonitoringEventHandler(BaseEventHandler): ...@@ -365,11 +366,23 @@ class MonitoringEventHandler(BaseEventHandler):
dump(uuid)) dump(uuid))
return return
for node_type, ip_address, port, uuid, state in node_list: for node_type, ip_address, port, uuid, state in node_list:
# Register new nodes. logging.info("got node info %s %s %s" %(ip_address, port, state))
# Register/update nodes.
addr = (ip_address, port) addr = (ip_address, port)
# Try to retrieve it from nm
if node_type == MASTER_NODE_TYPE: n = nm.getNodeByUUID(uuid)
if n is None:
n = nm.getNodeByServer(addr) n = nm.getNodeByServer(addr)
if n is not None:
# node only exists by address, remove it
nm.remove(n)
n = None
elif n.getServer() != addr:
# same uuid but different address, remove it
nm.remove(n)
n = None
if node_type == MASTER_NODE_TYPE:
if n is None: if n is None:
n = MasterNode(server = addr) n = MasterNode(server = addr)
nm.add(n) nm.add(n)
...@@ -382,7 +395,6 @@ class MonitoringEventHandler(BaseEventHandler): ...@@ -382,7 +395,6 @@ class MonitoringEventHandler(BaseEventHandler):
if uuid == INVALID_UUID: if uuid == INVALID_UUID:
# No interest. # No interest.
continue continue
n = nm.getNodeByUUID(uuid)
if n is None: if n is None:
if node_type == STORAGE_NODE_TYPE: if node_type == STORAGE_NODE_TYPE:
n = StorageNode(server = addr, uuid = uuid) n = StorageNode(server = addr, uuid = uuid)
...@@ -391,11 +403,11 @@ class MonitoringEventHandler(BaseEventHandler): ...@@ -391,11 +403,11 @@ class MonitoringEventHandler(BaseEventHandler):
elif node_type == ADMIN_NODE_TYPE: elif node_type == ADMIN_NODE_TYPE:
n = AdminNode(server = addr, uuid = uuid) n = AdminNode(server = addr, uuid = uuid)
nm.add(n) nm.add(n)
else:
n.setServer(addr)
else: else:
logging.warning("unknown node type %s" %(node_type))
continue continue
n.setState(state) n.setState(state)
self.app.notified = True self.app.notified = True
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