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