Changeset 124

Show
Ignore:
Timestamp:
02/20/08 15:04:59 (10 months ago)
Author:
edsuom
Message:

Got node client connecting; working on spawning worker clients independently of node process

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/AsynCluster/trunk/asyncluster/master/control.py

    r123 r124  
    4242    substitution of the message prototype. 
    4343    """ 
    44     msg = "%4s" % nodeID 
     44    msg = "N%04d" % nodeID 
    4545    if args: 
    4646        msg = "%s (%s): %s" % (msg, args[0], msgProto) 
  • projects/AsynCluster/trunk/asyncluster/master/nodes.py

    r122 r124  
    5959 
    6060    def _printableID(self): 
    61         return "%s%4d" % ("WN"[self.nodeClient], self.ID) 
     61        return "%s%04d" % ("WN"[self.nodeClient], self.ID) 
    6262 
    6363    def attached(self, clientRoot): 
     
    7272        """ 
    7373        def responded(acceptanceCode): 
    74             if acceptanceCode is None: 
    75                 return (pb.IPerspective, self, lambda _: None) 
    76             if acceptanceCode is True: 
     74            print "RESPONDED", acceptanceCode 
     75            if acceptanceCode == 'node': 
    7776                self.nodeClient = True 
    7877                d = self.ctl.attachNode(self, clientRoot) 
    79             else
     78            elif acceptanceCode == 'child'
    8079                self.nodeClient = False 
    8180                d = self.ctl.attachWorker(clientRoot) 
     81            else: 
     82                return (pb.IPerspective, self, lambda : None) 
    8283            clientRoot.notifyOnDisconnect(self.detached) 
    8384            return d.addCallback(doneAttaching) 
     
    8788            print "%s: Attached" % self._printableID() 
    8889            return pb.IPerspective, self, self.detached 
    89          
     90 
    9091        serverPassword = self.ctl.config['common']['server password'] 
    9192        d = clientRoot.callRemote('reverseLogin', serverPassword) 
  • projects/AsynCluster/trunk/asyncluster/master/test/mock.py

    r123 r124  
    127127        if called == 'reverseLogin': 
    128128            if args[0] == self.serverPassword: 
    129                 result = True 
     129                result = 'node' 
    130130            else: 
    131131                result = None 
  • projects/AsynCluster/trunk/asyncluster/ndm/client.py

    r123 r124  
    2929 
    3030import os, signal 
    31 from twisted.internet import defer, reactor, threads 
     31from twisted.internet import defer, threads, reactor 
    3232from twisted.cred import credentials 
    3333from twisted.spread import pb 
     
    3636 
    3737PYTHON="/usr/bin/python" 
     38CONFIG_PATH = "/etc/asyncluster.conf" 
    3839 
    3940 
     
    5960 
    6061 
     62class ChildManager(object): 
     63    """ 
     64    I manage child worker clients. Construct one instance of me per child 
     65    worker process. 
     66 
     67    @ivar config: A L{configobj} config object loaded from the config file. 
     68     
     69    """ 
     70    def __init__(self): 
     71        # The config object 
     72        import configobj 
     73        self.config = configobj.ConfigObj(CONFIG_PATH) 
     74        # The session-less client 
     75        self.client = Client(self) 
     76        # Go! 
     77        reactor.callWhenRunning(self.client.connect) 
     78        reactor.run() 
     79 
     80    def shutdown(self): 
     81        d = self.client.disconnect() 
     82        d.addCallback(lambda _: reactor.stop()) 
     83        return d 
     84 
     85 
    6186class ChildRoot(jobs.ChildRoot): 
    6287    """ 
     
    6691    trusted = False 
    6792     
    68     def __init__(self, serverPassword, ID): 
    69         self.serverPassword, self.ID = serverPassword, ID 
     93    def __init__(self, serverPassword): 
     94        self.serverPassword = serverPassword 
    7095 
    7196    def remote_reverseLogin(self, password): 
     
    7499        itself to the client, in this case a child worker client. 
    75100 
    76         If the server is authenticated, returns my unique integer 
    77         ID. Otherwise, returns C{None}. 
     101        If the server is authenticated, returns the string 'child' to identify 
     102        me to the server as a child root. Otherwise, returns C{None}. 
    78103        """ 
    79104        self.trusted = (password == self.serverPassword) 
    80105        if self.trusted: 
    81             return self.ID 
    82  
    83  
    84 class SessionRoot(pb.Root): 
     106            return 'child' 
     107 
     108 
     109class NodeRoot(pb.Root): 
    85110    """ 
    86111    I am the root resource for one NDM client capable of spawning worker 
    87112    clients and managing user sessions. 
    88113    """ 
    89     workerCmd = "from asyncluster.ndm import main; main.BaseManager()" 
     114    workerCmd = "from asyncluster.ndm import client; client.ChildManager()" 
    90115     
    91116    def __init__(self, serverPassword, main): 
     
    98123        itself to the client, in this case a node client. 
    99124 
    100         If the server is authenticated, returns C{True}. Otherwise, returns 
    101         C{None}. 
     125        If the server is authenticated, returns the string 'node' to identify 
     126        me to the server as a node root. Otherwise, returns C{None}. 
    102127        """ 
    103128        self.trusted = (password == self.serverPassword) 
    104129        if self.trusted: 
    105             return True 
     130            return 'node' 
    106131 
    107132    def remote_setTimeLeft(self, hoursLeft): 
     
    226251                return answer 
    227252            raise ConnectionError("Couldn't authorize connection to server") 
    228          
     253 
    229254        cc = self.main.config['client'] 
    230255        # TCP Connection 
     
    236261        serverPassword = self.main.config['common']['server password'] 
    237262        if self.session: 
    238             self.root = SessionRoot(serverPassword, self.main) 
     263            self.root = NodeRoot(serverPassword, self.main) 
    239264        else: 
    240265            self.root = ChildRoot(serverPassword) 
  • projects/AsynCluster/trunk/asyncluster/ndm/gui.py

    r115 r124  
    5757        # Fixed Size and centered (initial) position 
    5858        size = [int(x) for x in self.main.config['display']['size']] 
    59         center = [getattr(self.main.app.desktop().size(), x)()/2 
     59        center = [getattr(self.main.desktop.size(), x)()/2 
    6060                  for x in ('width', 'height')] 
    6161        rect = QtCore.QRect() 
  • projects/AsynCluster/trunk/asyncluster/ndm/test/test_client.py

    r123 r124  
    4141 
    4242 
    43 class Test_SessionRoot(TestCase): 
     43class Test_NodeRoot(TestCase): 
    4444    def setUp(self): 
    45         self.root = client.SessionRoot("foo", None) 
     45        self.root = client.NodeRoot("foo", None) 
    4646        self.root.trusted = True 
    4747 
  • projects/AsynCluster/trunk/asyncluster/test/__init__.py

    r16 r124  
    3232    packagePath = os.path.dirname(packagePath) 
    3333    if packagePath not in sys.path: 
    34         sys.path.insert(0, packagePath) 
     34        sys.path.insert(0, packagePath) 
     35 
     36# Ensure that any helper modules in the "real" test package (containing the 
     37# target file for any symlinks to this file) can be imported by name only 
     38packagePath = os.path.dirname(os.path.realpath(__file__)) 
     39if packagePath not in sys.path: 
     40    sys.path.append(packagePath) 
  • projects/AsynCluster/trunk/ndm

    r89 r124  
    3939    then 
    4040    # Starts the Python interpreter as Xinit's sole X client 
    41     exec python -c \ 
    42         "from asyncluster.ndm import main; main.GuiManager()" \ 
    43         2>/dev/null 
     41    exec python \ 
     42        -c "from asyncluster.ndm import node; node.Manager()" 2>/dev/null 
    4443 
    4544else