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): ...@@ -114,11 +114,6 @@ class Application(object):
Note that I do not accept any connection from non-master nodes Note that I do not accept any connection from non-master nodes
at this stage.""" 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 # search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, self.name, protocol.ADMIN_NODE_TYPE, bootstrap = BootstrapManager(self, self.name, protocol.ADMIN_NODE_TYPE,
self.uuid, self.server) self.uuid, self.server)
...@@ -139,8 +134,6 @@ class Application(object): ...@@ -139,8 +134,6 @@ class Application(object):
# passive handler # passive handler
self.master_conn.setHandler(self.master_event_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.askNodeInformation())
self.master_conn.ask(protocol.askPartitionTable([])) self.master_conn.ask(protocol.askPartitionTable([]))
......
...@@ -26,6 +26,10 @@ from neo.util import dump ...@@ -26,6 +26,10 @@ from neo.util import dump
class AdminEventHandler(EventHandler): class AdminEventHandler(EventHandler):
"""This class deals with events for administrating cluster.""" """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): def connectionAccepted(self, conn, s, addr):
"""Called when a connection is accepted.""" """Called when a connection is accepted."""
# we only accept connection from command tool # we only accept connection from command tool
...@@ -37,12 +41,16 @@ class AdminEventHandler(EventHandler): ...@@ -37,12 +41,16 @@ class AdminEventHandler(EventHandler):
# 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:
master_conn = self.app.master_conn master_conn = self.app.master_conn
p = protocol.askPartitionTable([]) if master_conn is None:
msg_id = master_conn.ask(p) self.__notConnected(conn, packet)
app.dispatcher.register(msg_id, conn, {'min_offset' : min_offset, else:
'max_offset' : max_offset, p = protocol.askPartitionTable([])
'uuid' : uuid, msg_id = master_conn.ask(p)
'msg_id' : packet.getId()}) app.dispatcher.register(msg_id, conn,
{'min_offset' : min_offset,
'max_offset' : max_offset,
'uuid' : uuid,
'msg_id' : packet.getId()})
else: else:
app.sendPartitionTable(conn, min_offset, max_offset, uuid, packet.getId()) app.sendPartitionTable(conn, min_offset, max_offset, uuid, packet.getId())
...@@ -77,16 +85,22 @@ class AdminEventHandler(EventHandler): ...@@ -77,16 +85,22 @@ class AdminEventHandler(EventHandler):
return return
# forward to primary master node # forward to primary master node
master_conn = self.app.master_conn master_conn = self.app.master_conn
p = protocol.setNodeState(uuid, state, modify_partition_table) if master_conn is None:
msg_id = master_conn.ask(p) self.__notConnected(conn, packet)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) 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): def handleSetClusterState(self, conn, packet, state):
# forward to primary # forward to primary
master_conn = self.app.master_conn master_conn = self.app.master_conn
p = protocol.setClusterState(state) if master_conn is None:
msg_id = master_conn.ask(p) self.__notConnected(conn, packet)
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) 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): def handleAddPendingNodes(self, conn, packet, uuid_list):
uuids = ', '.join([dump(uuid) for uuid in uuid_list]) uuids = ', '.join([dump(uuid) for uuid in uuid_list])
...@@ -95,14 +109,21 @@ class AdminEventHandler(EventHandler): ...@@ -95,14 +109,21 @@ class AdminEventHandler(EventHandler):
node = self.app.nm.getNodeByUUID(uuid) node = self.app.nm.getNodeByUUID(uuid)
# forward the request to primary # forward the request to primary
master_conn = self.app.master_conn master_conn = self.app.master_conn
msg_id = master_conn.ask(protocol.addPendingNodes(uuid_list)) if master_conn is None:
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()}) 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): def handleAskClusterState(self, conn, packet):
if self.app.cluster_state is None: if self.app.cluster_state is None:
# required it from PMN first # required it from PMN first
msg_id = self.app.master_conn.ask(protocol.askClusterState()) master_conn = self.app.master_conn
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.askClusterState())
self.app.dispatcher.register(msg_id, conn, {'msg_id' : packet.getId()})
return return
conn.answer(protocol.answerClusterState(self.app.cluster_state), packet) conn.answer(protocol.answerClusterState(self.app.cluster_state), packet)
...@@ -111,6 +132,11 @@ class MasterEventHandler(EventHandler): ...@@ -111,6 +132,11 @@ class MasterEventHandler(EventHandler):
""" This class is just used to dispacth message to right handler""" """ This class is just used to dispacth message to right handler"""
def _connectionLost(self, conn): 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 raise PrimaryFailure
def connectionFailed(self, conn): 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