Commit af26ef94 authored by Vincent Pelletier's avatar Vincent Pelletier

Separate connection code and packet sending code from "execute" method.

Don't intercept exceptions arising from connection code.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@812 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 4b4ed209
...@@ -137,6 +137,8 @@ action_dict = { ...@@ -137,6 +137,8 @@ action_dict = {
class Application(object): class Application(object):
"""The storage node application.""" """The storage node application."""
conn = None
def __init__(self, ip, port, handler): def __init__(self, ip, port, handler):
self.connector_handler = getConnectorHandler(handler) self.connector_handler = getConnectorHandler(handler)
...@@ -144,30 +146,12 @@ class Application(object): ...@@ -144,30 +146,12 @@ class Application(object):
self.em = EventManager() self.em = EventManager()
self.ptid = INVALID_PTID self.ptid = INVALID_PTID
def execute(self, args): def getConnection(self):
"""Execute the command given.""" if self.conn is None:
# print node type : print list of node of the given type (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...)
# set node uuid state [1|0] : set the node for the given uuid to the state (RUNNING_STATE, DOWN_STATE...)
# and modify the partition if asked
# set cluster name [shutdown|operational] : either shutdown the cluster or mark it as operational
current_action = action_dict
level = 1
while current_action is not None and \
level < len(args) and \
isinstance(current_action, dict):
current_action = current_action.get(args[level])
level += 1
if callable(current_action):
try:
p = current_action(args[level:])
except ActionError, message:
self.result = message
else:
handler = CommandEventHandler(self) handler = CommandEventHandler(self)
# connect to admin node # connect to admin node
conn = None
self.trying_admin_node = False self.trying_admin_node = False
try: conn = None
while 1: while 1:
self.em.poll(1) self.em.poll(1)
if conn is None: if conn is None:
...@@ -178,8 +162,11 @@ class Application(object): ...@@ -178,8 +162,11 @@ 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: self.conn = conn
return "FAIL : %s" %(msg,) return self.conn
def doAction(self, packet):
conn = self.getConnection()
conn.ask(p) conn.ask(p)
self.result = "" self.result = ""
...@@ -187,8 +174,30 @@ class Application(object): ...@@ -187,8 +174,30 @@ class Application(object):
self.em.poll(1) self.em.poll(1)
if len(self.result): if len(self.result):
break break
# close connection
conn.close() def __del__(self):
self.conn.close()
def execute(self, args):
"""Execute the command given."""
# print node type : print list of node of the given type (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...)
# set node uuid state [1|0] : set the node for the given uuid to the state (RUNNING_STATE, DOWN_STATE...)
# and modify the partition if asked
# set cluster name [shutdown|operational] : either shutdown the cluster or mark it as operational
current_action = action_dict
level = 1
while current_action is not None and \
level < len(args) and \
isinstance(current_action, dict):
current_action = current_action.get(args[level])
level += 1
if callable(current_action):
try:
p = current_action(args[level:])
except ActionError, message:
self.result = message
else:
self.doAction(p)
else: else:
self.result = usage('unknown command') self.result = usage('unknown command')
......
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