Commit a971382c authored by Vincent Pelletier's avatar Vincent Pelletier

Make admin node send a "not ready" error when requested to do something which...

Make admin node send a "not ready" error when requested to do something which requires acces to primary master node and the connection is not established.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1038 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 31c25e4c
......@@ -114,11 +114,6 @@ class Application(object):
Note that I do not accept any connection from non-master nodes
at this stage."""
# First of all, make sure that I have no connection.
for conn in self.em.getConnectionList():
if not conn.isListeningConnection():
conn.close()
# search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, protocol.ADMIN_NODE_TYPE,
self.uuid, self.server)
......@@ -139,8 +134,6 @@ class Application(object):
# passive handler
self.master_conn.setHandler(self.master_event_handler)
# XXX: Use an initialization module to ensure all nodes and the whole
# partition table are received before process neoctl requests.
self.master_conn.ask(protocol.askNodeInformation())
self.master_conn.ask(protocol.askPartitionTable([]))
......
......@@ -26,6 +26,10 @@ from neo.util import dump
class AdminEventHandler(EventHandler):
"""This class deals with events for administrating cluster."""
def __notConnected(self, conn, packet):
conn.answer(protocol.notReady('Not connected to a primary master.'),
packet)
def connectionAccepted(self, conn, s, addr):
"""Called when a connection is accepted."""
# we only accept connection from command tool
......@@ -37,12 +41,16 @@ class AdminEventHandler(EventHandler):
# check we have one pt otherwise ask it to PMN
if app.pt is None:
master_conn = self.app.master_conn
p = protocol.askPartitionTable([])
msg_id = master_conn.ask(p)
app.dispatcher.register(msg_id, conn, {'min_offset' : min_offset,
'max_offset' : max_offset,
'uuid' : uuid,
'msg_id' : packet.getId()})
if master_conn is None:
self.__notConnected(conn, packet)
else:
p = protocol.askPartitionTable([])
msg_id = master_conn.ask(p)
app.dispatcher.register(msg_id, conn,
{'min_offset' : min_offset,
'max_offset' : max_offset,
'uuid' : uuid,
'msg_id' : packet.getId()})
else:
app.sendPartitionTable(conn, min_offset, max_offset, uuid, packet.getId())
......@@ -77,16 +85,22 @@ class AdminEventHandler(EventHandler):
return
# forward to primary master node
master_conn = self.app.master_conn
p = protocol.setNodeState(uuid, state, modify_partition_table)
msg_id = master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
if master_conn is None:
self.__notConnected(conn, packet)
else:
p = protocol.setNodeState(uuid, state, modify_partition_table)
msg_id = master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
def handleSetClusterState(self, conn, packet, state):
# forward to primary
master_conn = self.app.master_conn
p = protocol.setClusterState(state)
msg_id = master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
if master_conn is None:
self.__notConnected(conn, packet)
else:
p = protocol.setClusterState(state)
msg_id = master_conn.ask(p)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
def handleAddPendingNodes(self, conn, packet, uuid_list):
uuids = ', '.join([dump(uuid) for uuid in uuid_list])
......@@ -95,14 +109,21 @@ class AdminEventHandler(EventHandler):
node = self.app.nm.getNodeByUUID(uuid)
# forward the request to primary
master_conn = self.app.master_conn
msg_id = master_conn.ask(protocol.addPendingNodes(uuid_list))
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
if master_conn is None:
self.__notConnected(conn, packet)
else:
msg_id = master_conn.ask(protocol.addPendingNodes(uuid_list))
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
def handleAskClusterState(self, conn, packet):
if self.app.cluster_state is None:
# required it from PMN first
msg_id = self.app.master_conn.ask(protocol.askClusterState())
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
master_conn = self.app.master_conn
if master_conn is None:
self.__notConnected(conn, packet)
else:
msg_id = master_conn.ask(protocol.askClusterState())
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
return
conn.answer(protocol.answerClusterState(self.app.cluster_state), packet)
......@@ -111,6 +132,11 @@ class MasterEventHandler(EventHandler):
""" This class is just used to dispacth message to right handler"""
def _connectionLost(self, conn):
app = self.app
assert app.master_conn is conn
app.master_conn = None
app.master_node = None
app.uuid = None
raise PrimaryFailure
def connectionFailed(self, conn):
......
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