Commit 76e270d4 authored by Vincent Pelletier's avatar Vincent Pelletier

Merge and simplify admin handler classes to hanle just 2 cases: expected...

Merge and simplify admin handler classes to hanle just 2 cases: expected answer, and the rest. This fixes cluster state notification handling (which used to only log a line because the hadler method was defined twice...).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1202 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent b9b47dd3
...@@ -22,8 +22,8 @@ from neo.node import NodeManager, MasterNode ...@@ -22,8 +22,8 @@ from neo.node import NodeManager, MasterNode
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection from neo.connection import ListeningConnection
from neo.exception import PrimaryFailure from neo.exception import PrimaryFailure
from neo.admin.handler import MasterMonitoringEventHandler, AdminEventHandler, \ from neo.admin.handler import AdminEventHandler, MasterEventHandler, \
MasterEventHandler, MasterRequestEventHandler MasterRequestEventHandler
from neo.connector import getConnectorHandler from neo.connector import getConnectorHandler
from neo.bootstrap import BootstrapManager from neo.bootstrap import BootstrapManager
from neo.pt import PartitionTable from neo.pt import PartitionTable
...@@ -72,7 +72,6 @@ class Application(object): ...@@ -72,7 +72,6 @@ class Application(object):
self.uuid = uuid self.uuid = uuid
self.primary_master_node = None self.primary_master_node = None
self.ptid = None self.ptid = None
self.monitoring_handler = MasterMonitoringEventHandler(self)
self.request_handler = MasterRequestEventHandler(self) self.request_handler = MasterRequestEventHandler(self)
self.master_event_handler = MasterEventHandler(self) self.master_event_handler = MasterEventHandler(self)
self.dispatcher = Dispatcher() self.dispatcher = Dispatcher()
......
...@@ -152,31 +152,50 @@ class MasterEventHandler(EventHandler): ...@@ -152,31 +152,50 @@ class MasterEventHandler(EventHandler):
self._connectionLost(conn) self._connectionLost(conn)
def dispatch(self, conn, packet): def dispatch(self, conn, packet):
if not packet.isResponse(): if packet.isResponse() and \
# not an answer self.app.dispatcher.registered(packet.getId()):
self.app.monitoring_handler.dispatch(conn, packet)
elif self.app.dispatcher.registered(packet.getId()):
# expected answer # expected answer
self.app.request_handler.dispatch(conn, packet) self.app.request_handler.dispatch(conn, packet)
else: else:
# unexpectexd answer, this should be answerNodeInformation or # unexpectexd answers and notifications
# answerPartitionTable from the master node during initialization. super(MasterEventHandler, self).dispatch(conn, packet)
# This will no more exists when the initialization module will be
# implemented for factorize code (as done for bootstrap)
EventHandler.dispatch(self, conn, packet)
def handleAnswerNodeInformation(self, conn, packet, node_list): def handleAnswerNodeInformation(self, conn, packet, node_list):
# XXX: This will no more exists when the initialization module will be
# implemented for factorize code (as done for bootstrap)
logging.debug("handleAnswerNodeInformation") logging.debug("handleAnswerNodeInformation")
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list): def handleAnswerPartitionTable(self, conn, packet, ptid, row_list):
# XXX: This will no more exists when the initialization module will be
# implemented for factorize code (as done for bootstrap)
logging.debug("handleAnswerPartitionTable") logging.debug("handleAnswerPartitionTable")
def handleNotifyClusterInformation(self, conn, packet, cluster_state): def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
logging.debug("handleNotifyClusterInformation") app = self.app
if ptid < app.ptid:
# Ignore this packet.
return
app.ptid = ptid
app.pt.update(ptid, cell_list, app.nm)
class MasterBaseEventHandler(EventHandler): def handleSendPartitionTable(self, conn, packet, ptid, row_list):
""" This is the base class for connection to primary master node""" uuid = conn.getUUID()
app = self.app
nm = app.nm
pt = app.pt
node = app.nm.getNodeByUUID(uuid)
if app.ptid != ptid:
app.ptid = ptid
pt.clear()
for offset, row in row_list:
for uuid, state in row:
node = nm.getNodeByUUID(uuid)
if node is None:
node = StorageNode(uuid = uuid)
node.setState(protocol.TEMPORARILY_DOWN_STATE)
nm.add(node)
pt.setCell(offset, node, state)
pt.log()
def handleNotifyClusterInformation(self, conn, packet, cluster_state): def handleNotifyClusterInformation(self, conn, packet, cluster_state):
self.app.cluster_state = cluster_state self.app.cluster_state = cluster_state
...@@ -190,8 +209,7 @@ class MasterBaseEventHandler(EventHandler): ...@@ -190,8 +209,7 @@ class MasterBaseEventHandler(EventHandler):
# possible (ignore TEMPORARILY_DOWN for example) # possible (ignore TEMPORARILY_DOWN for example)
conn.ask(protocol.askPartitionTable([])) conn.ask(protocol.askPartitionTable([]))
class MasterRequestEventHandler(EventHandler):
class MasterRequestEventHandler(MasterBaseEventHandler):
""" This class handle all answer from primary master node""" """ This class handle all answer from primary master node"""
def __answerNeoCTL(self, msg_id, packet): def __answerNeoCTL(self, msg_id, packet):
...@@ -225,34 +243,3 @@ class MasterRequestEventHandler(MasterBaseEventHandler): ...@@ -225,34 +243,3 @@ class MasterRequestEventHandler(MasterBaseEventHandler):
def handleProtocolError(self, conn, packet, msg): def handleProtocolError(self, conn, packet, msg):
self.__answerNeoCTL(packet.getId(), protocol.protocolError(msg)) self.__answerNeoCTL(packet.getId(), protocol.protocolError(msg))
class MasterMonitoringEventHandler(MasterBaseEventHandler):
"""This class deals with events for monitoring cluster."""
def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
app = self.app
if ptid < app.ptid:
# Ignore this packet.
return
app.ptid = ptid
app.pt.update(ptid, cell_list, app.nm)
def handleSendPartitionTable(self, conn, packet, ptid, row_list):
uuid = conn.getUUID()
app = self.app
nm = app.nm
pt = app.pt
node = app.nm.getNodeByUUID(uuid)
if app.ptid != ptid:
app.ptid = ptid
pt.clear()
for offset, row in row_list:
for uuid, state in row:
node = nm.getNodeByUUID(uuid)
if node is None:
node = StorageNode(uuid = uuid)
node.setState(protocol.TEMPORARILY_DOWN_STATE)
nm.add(node)
pt.setCell(offset, node, state)
pt.log()
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