Commit 98c36b14 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Partial revert of commit #1208, the master connection check must not be global

to the method, raise NotReadyError in each method because the master connection
is not always required.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1210 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ce1519a1
...@@ -23,23 +23,16 @@ from neo import protocol ...@@ -23,23 +23,16 @@ from neo import protocol
from neo.exception import PrimaryFailure from neo.exception import PrimaryFailure
from neo.util import dump from neo.util import dump
def master_connection_required(handler):
""" Check if the master connection is established """
def decorator(self, *args, **kwargs):
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
handler(self, *args, **kwargs)
return decorator
class AdminEventHandler(EventHandler): class AdminEventHandler(EventHandler):
"""This class deals with events for administrating cluster.""" """This class deals with events for administrating cluster."""
@master_connection_required
def handleAskPartitionList(self, conn, packet, min_offset, max_offset, uuid): def handleAskPartitionList(self, conn, packet, min_offset, max_offset, uuid):
logging.info("ask partition list from %s to %s for %s" %(min_offset, max_offset, dump(uuid))) logging.info("ask partition list from %s to %s for %s" %(min_offset, max_offset, dump(uuid)))
app = self.app app = self.app
# check we have one pt otherwise ask it to PMN # check we have one pt otherwise ask it to PMN
if app.pt is None: if app.pt is None:
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
p = protocol.askPartitionTable([]) p = protocol.askPartitionTable([])
msg_id = self.app.master_conn.ask(p) msg_id = self.app.master_conn.ask(p)
app.dispatcher.register(msg_id, conn, app.dispatcher.register(msg_id, conn,
...@@ -67,7 +60,6 @@ class AdminEventHandler(EventHandler): ...@@ -67,7 +60,6 @@ class AdminEventHandler(EventHandler):
p = protocol.answerNodeList(node_information_list) p = protocol.answerNodeList(node_information_list)
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
@master_connection_required
def handleSetNodeState(self, conn, packet, uuid, state, modify_partition_table): def handleSetNodeState(self, conn, packet, uuid, state, modify_partition_table):
logging.info("set node state for %s-%s" %(dump(uuid), state)) logging.info("set node state for %s-%s" %(dump(uuid), state))
node = self.app.nm.getNodeByUUID(uuid) node = self.app.nm.getNodeByUUID(uuid)
...@@ -81,27 +73,32 @@ class AdminEventHandler(EventHandler): ...@@ -81,27 +73,32 @@ class AdminEventHandler(EventHandler):
conn.answer(p, packet.getId()) conn.answer(p, packet.getId())
return return
# forward to primary master node # forward to primary master node
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
p = protocol.setNodeState(uuid, state, modify_partition_table) p = protocol.setNodeState(uuid, state, modify_partition_table)
msg_id = self.app.master_conn.ask(p) msg_id = self.app.master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
@master_connection_required
def handleSetClusterState(self, conn, packet, state): def handleSetClusterState(self, conn, packet, state):
# forward to primary # forward to primary
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
p = protocol.setClusterState(state) p = protocol.setClusterState(state)
msg_id = self.app.master_conn.ask(p) msg_id = self.app.master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
@master_connection_required
def handleAddPendingNodes(self, conn, packet, uuid_list): def handleAddPendingNodes(self, conn, packet, uuid_list):
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
logging.info('Add nodes %s' % [dump(uuid) for uuid in uuid_list]) logging.info('Add nodes %s' % [dump(uuid) for uuid in uuid_list])
# forward the request to primary # forward the request to primary
msg_id = self.app.master_conn.ask(protocol.addPendingNodes(uuid_list)) msg_id = self.app.master_conn.ask(protocol.addPendingNodes(uuid_list))
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
@master_connection_required
def handleAskClusterState(self, conn, packet): def handleAskClusterState(self, conn, packet):
if self.app.cluster_state is None: if self.app.cluster_state is None:
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
# required it from PMN first # required it from PMN first
msg_id = self.app.master_conn.ask(protocol.askClusterState()) msg_id = self.app.master_conn.ask(protocol.askClusterState())
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
...@@ -109,8 +106,9 @@ class AdminEventHandler(EventHandler): ...@@ -109,8 +106,9 @@ class AdminEventHandler(EventHandler):
conn.answer(protocol.answerClusterState(self.app.cluster_state), conn.answer(protocol.answerClusterState(self.app.cluster_state),
packet.getId()) packet.getId())
@master_connection_required
def handleAskPrimaryMaster(self, conn, packet): def handleAskPrimaryMaster(self, conn, packet):
if self.app.master_conn is None:
raise protocol.NotReadyError('Not connected to a primary master.')
master_node = self.app.master_node master_node = self.app.master_node
conn.answer(protocol.answerPrimaryMaster(master_node.getUUID(), []), conn.answer(protocol.answerPrimaryMaster(master_node.getUUID(), []),
packet.getId()) packet.getId())
......
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