4087 Dyre Tjeldvoll 2012-10-05
Initial raw versions of mgmd and log file functions
modified:
storage/ndb/mcc/request_handler.py
4086 Dyre Tjeldvoll 2012-10-04
Adding sleep call to shutdown command to simulate hanging requests
modified:
storage/ndb/mcc/request_handler.py
=== modified file 'storage/ndb/mcc/request_handler.py'
--- a/storage/ndb/mcc/request_handler.py 2012-10-04 12:31:23 +0000
+++ b/storage/ndb/mcc/request_handler.py 2012-10-05 12:20:54 +0000
@@ -267,8 +267,96 @@ def handle_shutdownServerReq(req, body):
time.sleep(util.get_val(body, 'sleeptime', 0))
return make_rep(req, 'incorrect death key')
+def handle_getLogTailReq(req, body):
+ """Handler function for getLogTailReq commands. Opens a file on the remote
+ host and adds content to reply
+ req - top level message object
+ body - shortcut to the body part of the message
+ """
+
+ (user, pwd) = get_cred(body)
+ sf = body['logFile']
+ assert (sf.has_key('path') and sf.has_key('name') and sf.has_key('hostName'))
+
+ ch = None
+ logFile = None
+ try:
+ ch = produce_ABClusterHost(sf['hostName'], user, pwd)
+ sp = ch.path_module.join(sf['path'], sf['name'])
+ assert (ch.file_exists(sp)), 'File ' + sp + " does not exist on host " + ch.host
+ logFile = ch.open(sp)
+ rep = make_rep(req, {'tail': logFile.read()})
+ finally:
+ if logFile:
+ logFile.close()
+ if ch:
+ ch.drop()
+
+ return rep
+
+def _parse_until_delim(ctx, fld, delim):
+ i = ctx['str'].find(delim)
+ if (i == -1):
+ return False
+
+ ctx[fld] = ctx['str'][0:i]
+ ctx['str'] = ctx['str'][i+len(delim):]
+ return True
+
+def parse_empty_line(ctx):
+ if ctx['str'].startswith('\n'):
+ ctx['str'] = ctx['str'][1:]
+ return True
+ return False
+
+def parse_property(ctx):
+ if _parse_until_delim(ctx, 'key', ': ') and _parse_until_delim(ctx, 'val', '\n'):
+ ctx['properties'][ctx['key']] = ctx['val']
+ return True
+ return False
+
+def parse_properties(ctx):
+ return parse_property(ctx) and parse_properties(ctx) or parse_empty_line(ctx)
+
+def parse_reply(ctx):
+ return _parse_until_delim(ctx, 'reply_type', '\n') and parse_properties(ctx)
+
+
+class mgmd_reply(dict):
+ def __init__(self, s=None):
+ if (s):
+ ctx = {'str': s, 'properties':self}
+ parse_reply(ctx)
+ self.reply_type = ctx['reply_type']
+
+ def __str__(self):
+ return self.reply_type+'\n'+'\n'.join(['{0}: {1}'.format(str(k), str(self[k])) for k in self.keys()])+'\n'
+
+def handle_runMgmdCommand(req, body):
+ """x"""
+ with socket.create_connection((body['hostname'], body['port'])) as mgmd:
+ mgmd.sendall(body['mgmd_command']+'\n\n')
+ s = mgmd.recv(4096)
+ mgmd.shutdown(socket.SHUT_RDWR)
+
+ status = mgmd_reply(s)
+ sd = {}
+ for nk in status.keys():
+ print 'nk='+nk
+ if 'node.' in nk:
+ (x, n, k) = nk.split('.')
+ if not sd.has_key(n):
+ sd[n] = {}
+ sd[n][k] = status[nk]
+ else:
+ sd[nk] = status[nk]
+
+ return make_rep(req, { 'reply_type': status.reply_type, 'reply_properties':sd})
+
+
def log_thread_name():
+ """x"""
cur_thread = threading.current_thread()
_logger.debug("cur_thread="+str(cur_thread.name))
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-5.5-cluster-7.2 branch (Dyre.Tjeldvoll:4086 to 4087) | Dyre Tjeldvoll | 5 Oct |