Commit d0ba0475 authored by Vincent Pelletier's avatar Vincent Pelletier

Make it possible to request current primary master from neoctl (neoctl command...

Make it possible to request current primary master from neoctl (neoctl command support & API entry, admin node support).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1135 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 3b9b7979
......@@ -119,6 +119,14 @@ class AdminEventHandler(EventHandler):
return
conn.answer(protocol.answerClusterState(self.app.cluster_state), packet.getId())
def handleAskPrimaryMaster(self, conn, packet):
master_node = self.app.master_node
if master_node is None:
self.__notConnected(conn, packet)
else:
conn.answer(
protocol.answerPrimaryMaster(master_node.getUUID(), []),
packet.getId())
class MasterEventHandler(EventHandler):
""" This class is just used to dispacth message to right handler"""
......@@ -177,7 +185,13 @@ class MasterBaseEventHandler(EventHandler):
self.app.cluster_state = cluster_state
def handleNotifyNodeInformation(self, conn, packet, node_list):
self.app.nm.update(node_list)
app = self.app
app.nm.update(node_list)
if not app.pt.filled():
# Re-ask partition table, in case node change filled it.
# XXX: we should only ask it if received states indicates it is
# possible (ignore TEMPORARILY_DOWN for example)
conn.ask(protocol.askPartitionTable([]))
class MasterRequestEventHandler(MasterBaseEventHandler):
......
......@@ -24,6 +24,7 @@ action_dict = {
'pt': 'getPartitionRowList',
'node': 'getNodeList',
'cluster': 'getClusterState',
'primary': 'getPrimaryMaster',
},
'set': {
'node': 'setNodeState',
......@@ -75,6 +76,9 @@ class TerminalNeoCTL(object):
port, state))
return '\n'.join(result)
def formatUUID(self, uuid):
return dump(uuid)
# Actual actions
def getPartitionRowList(self, params):
"""
......@@ -182,6 +186,12 @@ class TerminalNeoCTL(object):
assert len(params) == 1
self.neoctl.dropNode(self.asNode(params[0]))
def getPrimaryMaster(self, params):
"""
Get primary master node.
"""
return self.formatUUID(self.neoctl.getPrimaryMaster())
class Application(object):
"""The storage node application."""
......
......@@ -64,3 +64,4 @@ class CommandEventHandler(EventHandler):
handleAnswerNodeState = __handleAnswer
handleAnswerClusterState = __handleAnswer
handleAnswerNewNodes = __handleAnswer
handleAnswerPrimaryMaster = __handleAnswer
......@@ -133,3 +133,12 @@ class NeoCTL(object):
"""
self.setNodeState(node, protocol.DOWN_STATE, update_partition_table=1)
def getPrimaryMaster(self):
"""
Return the primary master UUID.
"""
packet = protocol.askPrimaryMaster()
response = self.__ask(packet)
assert response[0] == protocol.ANSWER_PRIMARY_MASTER
return response[1]
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