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 = {
class Application(object):
"""The storage node application."""
conn = None
def __init__(self, ip, port, handler):
self.connector_handler = getConnectorHandler(handler)
......@@ -144,30 +146,12 @@ class Application(object):
self.em = EventManager()
self.ptid = INVALID_PTID
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:
def getConnection(self):
if self.conn is None:
handler = CommandEventHandler(self)
# connect to admin node
conn = None
self.trying_admin_node = False
try:
conn = None
while 1:
self.em.poll(1)
if conn is None:
......@@ -178,8 +162,11 @@ class Application(object):
connector_handler = self.connector_handler)
if self.trying_admin_node is False:
break
except OperationFailure, msg:
return "FAIL : %s" %(msg,)
self.conn = conn
return self.conn
def doAction(self, packet):
conn = self.getConnection()
conn.ask(p)
self.result = ""
......@@ -187,8 +174,30 @@ class Application(object):
self.em.poll(1)
if len(self.result):
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:
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