Commit 3d837577 authored by Aurel's avatar Aurel

implement "neoctl print cluster" call


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@710 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent e6ebedf3
...@@ -81,6 +81,7 @@ class Application(object): ...@@ -81,6 +81,7 @@ class Application(object):
self.monitoring_handler = MasterMonitoringEventHandler(self) self.monitoring_handler = MasterMonitoringEventHandler(self)
self.request_handler = MasterRequestEventHandler(self) self.request_handler = MasterRequestEventHandler(self)
self.dispatcher = Dispatcher() self.dispatcher = Dispatcher()
self.cluster_state = None
def run(self): def run(self):
"""Make sure that the status is sane and start a loop.""" """Make sure that the status is sane and start a loop."""
......
...@@ -114,6 +114,14 @@ class AdminEventHandler(BaseEventHandler): ...@@ -114,6 +114,14 @@ class AdminEventHandler(BaseEventHandler):
msg_id = master_conn.ask(protocol.addPendingNodes(uuid_list)) msg_id = 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()})
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()})
return
conn.answer(protocol.answerClusterState(self.app.cluster_state), packet)
class MasterEventHandler(BaseEventHandler): class MasterEventHandler(BaseEventHandler):
""" This class is just used to dispacth message to right handler""" """ This class is just used to dispacth message to right handler"""
...@@ -205,6 +213,10 @@ class MasterBaseEventHandler(BaseEventHandler): ...@@ -205,6 +213,10 @@ class MasterBaseEventHandler(BaseEventHandler):
EventHandler.peerBroken(self, conn) EventHandler.peerBroken(self, conn)
@decorators.identification_required
def handleNotifyClusterInformation(self, con, packet, cluster_state):
self.app.cluster_state = cluster_state
@decorators.identification_required @decorators.identification_required
def handleNotifyNodeInformation(self, conn, packet, node_list): def handleNotifyNodeInformation(self, conn, packet, node_list):
uuid = conn.getUUID() uuid = conn.getUUID()
...@@ -273,6 +285,7 @@ class MasterRequestEventHandler(MasterBaseEventHandler): ...@@ -273,6 +285,7 @@ class MasterRequestEventHandler(MasterBaseEventHandler):
def handleAnswerClusterState(self, conn, packet, state): def handleAnswerClusterState(self, conn, packet, state):
logging.info("handleAnswerClusterState for a conn") logging.info("handleAnswerClusterState for a conn")
self.app.cluster_state = state
client_conn, kw = self.app.dispatcher.retrieve(packet.getId()) client_conn, kw = self.app.dispatcher.retrieve(packet.getId())
client_conn.notify(protocol.answerClusterState(state), kw['msg_id']) client_conn.notify(protocol.answerClusterState(state), kw['msg_id'])
......
# #
# Copyright (C) 2006-2009 Nexedi SA # Copyright (C) 2006-2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -27,7 +27,7 @@ from neo.protocol import TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ ...@@ -27,7 +27,7 @@ from neo.protocol import TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
INVALID_UUID, INVALID_PTID, partition_cell_states, MASTER_NODE_TYPE INVALID_UUID, INVALID_PTID, partition_cell_states, MASTER_NODE_TYPE
from neo.event import EventManager from neo.event import EventManager
from neo.node import NodeManager, MasterNode, StorageNode, ClientNode, AdminNode from neo.node import NodeManager, MasterNode, StorageNode, ClientNode, AdminNode
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.exception import OperationFailure, PrimaryFailure from neo.exception import OperationFailure, PrimaryFailure
from neo.neoctl.handler import CommandEventHandler from neo.neoctl.handler import CommandEventHandler
from neo.connector import getConnectorHandler from neo.connector import getConnectorHandler
...@@ -45,7 +45,7 @@ class Application(object): ...@@ -45,7 +45,7 @@ class Application(object):
self.ptid = INVALID_PTID self.ptid = INVALID_PTID
def execute(self, args): def execute(self, args):
"""Execute the command given.""" """Execute the command given."""
handler = CommandEventHandler(self) handler = CommandEventHandler(self)
# connect to admin node # connect to admin node
...@@ -53,7 +53,7 @@ class Application(object): ...@@ -53,7 +53,7 @@ class Application(object):
self.trying_admin_node = False self.trying_admin_node = False
try: try:
while 1: while 1:
self.em.poll(1) self.em.poll(1)
if conn is None: if conn is None:
self.trying_admin_node = True self.trying_admin_node = True
logging.info('connecting to address %s:%d', *(self.server)) logging.info('connecting to address %s:%d', *(self.server))
...@@ -62,7 +62,7 @@ class Application(object): ...@@ -62,7 +62,7 @@ class Application(object):
connector_handler = self.connector_handler) connector_handler = self.connector_handler)
if self.trying_admin_node is False: if self.trying_admin_node is False:
break break
except OperationFailure, msg: except OperationFailure, msg:
return "FAIL : %s" %(msg,) return "FAIL : %s" %(msg,)
...@@ -98,6 +98,8 @@ class Application(object): ...@@ -98,6 +98,8 @@ class Application(object):
if node_type is None: if node_type is None:
return 'unknown node type' return 'unknown node type'
p = protocol.askNodeList(node_type) p = protocol.askNodeList(node_type)
elif print_type == "cluster":
p = protocol.askClusterState()
else: else:
return "unknown command options" return "unknown command options"
elif command == "set": elif command == "set":
...@@ -121,7 +123,7 @@ class Application(object): ...@@ -121,7 +123,7 @@ class Application(object):
return "unknown cluster state" return "unknown cluster state"
p = protocol.setClusterState(name, state) p = protocol.setClusterState(name, state)
else: else:
return "unknown command options" return "unknown command options"
elif command == "add": elif command == "add":
if len(options) == 1 and options[0] == 'all': if len(options) == 1 and options[0] == 'all':
uuid_list = [] uuid_list = []
...@@ -130,7 +132,7 @@ class Application(object): ...@@ -130,7 +132,7 @@ class Application(object):
p = protocol.addPendingNodes(uuid_list) p = protocol.addPendingNodes(uuid_list)
else: else:
return "unknown command" return "unknown command"
conn.ask(p) conn.ask(p)
self.result = "" self.result = ""
while 1: while 1:
......
# #
# Copyright (C) 2009 Nexedi SA # Copyright (C) 2009 Nexedi SA
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -73,7 +73,7 @@ class CommandEventHandler(EventHandler): ...@@ -73,7 +73,7 @@ class CommandEventHandler(EventHandler):
for uuid, state in cell_list: for uuid, state in cell_list:
data += "%s - %s |" %(dump(uuid), state) data += "%s - %s |" %(dump(uuid), state)
self.app.result = data self.app.result = data
def handleAnswerNodeList(self, conn, packet, node_list): def handleAnswerNodeList(self, conn, packet, node_list):
data = "" data = ""
if len(node_list) == 0: if len(node_list) == 0:
...@@ -82,7 +82,7 @@ class CommandEventHandler(EventHandler): ...@@ -82,7 +82,7 @@ class CommandEventHandler(EventHandler):
for node_type, ip, port, uuid, state in node_list: for node_type, ip, port, uuid, state in node_list:
data += "\n%s - %s - %s:%s - %s" %(node_type, dump(uuid), ip, port, state) data += "\n%s - %s - %s:%s - %s" %(node_type, dump(uuid), ip, port, state)
self.app.result = data self.app.result = data
def handleAnswerNodeState(self, conn, packet, uuid, state): def handleAnswerNodeState(self, conn, packet, uuid, state):
self.app.result = "Node %s set to state %s" %(dump(uuid), state) self.app.result = "Node %s set to state %s" %(dump(uuid), state)
......
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