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): ...@@ -119,6 +119,14 @@ class AdminEventHandler(EventHandler):
return return
conn.answer(protocol.answerClusterState(self.app.cluster_state), packet.getId()) 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): 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"""
...@@ -177,7 +185,13 @@ class MasterBaseEventHandler(EventHandler): ...@@ -177,7 +185,13 @@ class MasterBaseEventHandler(EventHandler):
self.app.cluster_state = cluster_state self.app.cluster_state = cluster_state
def handleNotifyNodeInformation(self, conn, packet, node_list): 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): class MasterRequestEventHandler(MasterBaseEventHandler):
......
...@@ -24,6 +24,7 @@ action_dict = { ...@@ -24,6 +24,7 @@ action_dict = {
'pt': 'getPartitionRowList', 'pt': 'getPartitionRowList',
'node': 'getNodeList', 'node': 'getNodeList',
'cluster': 'getClusterState', 'cluster': 'getClusterState',
'primary': 'getPrimaryMaster',
}, },
'set': { 'set': {
'node': 'setNodeState', 'node': 'setNodeState',
...@@ -75,6 +76,9 @@ class TerminalNeoCTL(object): ...@@ -75,6 +76,9 @@ class TerminalNeoCTL(object):
port, state)) port, state))
return '\n'.join(result) return '\n'.join(result)
def formatUUID(self, uuid):
return dump(uuid)
# Actual actions # Actual actions
def getPartitionRowList(self, params): def getPartitionRowList(self, params):
""" """
...@@ -182,6 +186,12 @@ class TerminalNeoCTL(object): ...@@ -182,6 +186,12 @@ class TerminalNeoCTL(object):
assert len(params) == 1 assert len(params) == 1
self.neoctl.dropNode(self.asNode(params[0])) self.neoctl.dropNode(self.asNode(params[0]))
def getPrimaryMaster(self, params):
"""
Get primary master node.
"""
return self.formatUUID(self.neoctl.getPrimaryMaster())
class Application(object): class Application(object):
"""The storage node application.""" """The storage node application."""
......
...@@ -64,3 +64,4 @@ class CommandEventHandler(EventHandler): ...@@ -64,3 +64,4 @@ class CommandEventHandler(EventHandler):
handleAnswerNodeState = __handleAnswer handleAnswerNodeState = __handleAnswer
handleAnswerClusterState = __handleAnswer handleAnswerClusterState = __handleAnswer
handleAnswerNewNodes = __handleAnswer handleAnswerNewNodes = __handleAnswer
handleAnswerPrimaryMaster = __handleAnswer
...@@ -133,3 +133,12 @@ class NeoCTL(object): ...@@ -133,3 +133,12 @@ class NeoCTL(object):
""" """
self.setNodeState(node, protocol.DOWN_STATE, update_partition_table=1) 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