List:Commits« Previous MessageNext Message »
From:Dyre Tjeldvoll Date:October 4 2012 12:16pm
Subject:bzr push into mysql-5.5-cluster-7.2 branch (Dyre.Tjeldvoll:4084 to 4085)
View as plain text  
 4085 Dyre Tjeldvoll	2012-10-04
      Adding shutdown command and test client script

    added:
      storage/ndb/mcc/tst/tstcli.py
    modified:
      storage/ndb/mcc/request_handler.py
 4084 Dyre Tjeldvoll	2012-10-04
      Adding SocketServer.ThreadingMixIn as base class to make the backend web server multi-threaded

    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 07:08:54 +0000
+++ b/storage/ndb/mcc/request_handler.py	2012-10-04 12:15:31 +0000
@@ -45,12 +45,17 @@ import webbrowser
 import zipfile
 import tempfile
 import threading
+import random
+import stat
 
 import util
 from clusterhost import produce_ABClusterHost 
 
 _logger = logging.getLogger(__name__)
 
+class ShutdownException(Exception):
+    pass
+
 class ReplyJsonEncoder(json.JSONEncoder):
     """Specialized encoder for which will serialize the folliowing types, 
     in addition to those handled by JSONEncoder:
@@ -255,6 +260,13 @@ def handle_removeClusterReq(req, body):
     directories belonging to the cluster."""
     pass
 
+def handle_shutdownServerReq(req, body):
+    """x"""
+    if body.has_key('deathkey') and int(body['deathkey']) == deathkey:
+        raise ShutdownException("Shutdown request received")
+    return make_rep(req, 'incorrect death key')
+
+
 def log_thread_name():
     cur_thread = threading.current_thread()
     _logger.debug("cur_thread="+str(cur_thread.name))
@@ -313,6 +325,8 @@ class ConfiguratorHandler(BaseHTTPServer
             rep = make_rep(msg)
             try: 
                 rep = handle_req(msg)
+            except ShutdownException:
+                self.server.shutdown()
             except:
                 #traceback.print_exc()
                 self.server.logger.exception('POST request failed:')       
@@ -372,6 +386,7 @@ class ConfiguratorServer(SocketServer.Th
 
 configdir = None
 basedir = None
+deathkey = None
         
 def main(prefix, cfgdir):
     """Server's main-function which parses the command line and starts up the server accordingly.
@@ -453,6 +468,13 @@ def main(prefix, cfgdir):
     else:
         print 'The application should now be running in your browser.\n(Alternatively you can navigate to '+url+' to start it)'
     httpsrv = None
+    global deathkey
+    deathkey = random.randint(100000, 1000000)
+    print 'deathkey='+str(deathkey)
+    dkf = open('deathkey.txt','w')
+    dkf.write(str(deathkey))
+    dkf.close()
+    os.chmod('deathkey.txt', stat.S_IRUSR)
     try:
         httpsrv = ConfiguratorServer(srvopts)
         if not options.no_browser:
@@ -465,5 +487,5 @@ def main(prefix, cfgdir):
     finally:
         if httpsrv:
             httpsrv.socket.close()
-
+        os.remove('deathkey.txt')
 

=== added file 'storage/ndb/mcc/tst/tstcli.py'
--- a/storage/ndb/mcc/tst/tstcli.py	1970-01-01 00:00:00 +0000
+++ b/storage/ndb/mcc/tst/tstcli.py	2012-10-04 12:15:31 +0000
@@ -0,0 +1,20 @@
+#! /usr/bin/env python
+
+import sys
+import socket
+
+def cmd_wrap(c, b):
+    return '{ "head": { "seq": 0, "cmd": "'+c+'"}, "body": { "ssh": {}, '+b+'}, "reply": null }'
+
+if __name__ == '__main__':
+    jss = sys.stdin.read()
+    cmd = cmd_wrap(sys.argv[3], jss)
+    c = socket.create_connection((sys.argv[1], sys.argv[2]))
+    req = 'POST foo HTTP/1.0\nFrom: foo@stripped\nUser-Agent: tstcli.py\nContent-Type: application/json\nContent-Length: '+str(len(cmd))+'\n\n'+cmd
+    print '<-- '+req
+    try:
+        c.sendall(req)
+        f = c.makefile()
+        print '--> '+f.read()
+    finally:
+        c.close()

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster-7.2 branch (Dyre.Tjeldvoll:4084 to 4085) Dyre Tjeldvoll4 Oct