Exemplo n.º 1
0
 def proc_cmd_kill(self, backend, cmd, echo_evt):
     # FIXME: are there any running tasks? - expects kill --force
     # FIXME: [optional] broadcast SIGINT to children
     # FIXME: [optional] add timeout - if there are still some backends
     # running, close anyway...
     self.killed = True
     self.generate_evt(event.Event('bye', message='killed'), to_all=True)
     self.on_killed()
Exemplo n.º 2
0
 def proc_input(self, cmd):
     """Process data(Event) received from Controller - forward to Backend"""
     if self.backend:
         try:
             self.backend.proc_evt(event.Event(cmd))
         except KilledException:
             # FIXME: kill?
             print "Server was killed, should also die..."
             self.transport.loseConnection()
             raise
Exemplo n.º 3
0
 def proc_input(self, cmd):
     """Process data(Event) received from Task - forward to Controller"""
     if not cmd:
         return
     if self.controller:
         try:
             evt = event.Event(cmd)
             evt.origin().update(self.origin)
         except:
             evt = event.lose_item(data=cmd, origin=dict(self.origin))
         self.controller.proc_evt(self, evt)
Exemplo n.º 4
0
    def same_as(self, cmd):
        """
        Compare commands.

        This ignores id, which will be (usually) different.
        """
        if not isinstance(cmd, Command):
            cmd = Command(cmd)
        if self.command() != cmd.command():
            return False
        if self.command() == 'forward':
            a = self.args()
            ca = cmd.args()
            for k in a.keys():
                if k == 'event':
                    if not event.Event(a['event']).same_as(
                            event.Event(ca.get('event', None))):
                        return False
                else:
                    if a[k] != ca.get(k, None):
                        return False
            return True
        return self.args() == cmd.args()
Exemplo n.º 5
0
 def stop_remote(self, dest):
     dest_s = '%s:%s' % dest
     rb = self.__remotes.get(dest_s, None)
     if rb:
         if not rb.idle():
             log.warning(
                 "Can not stop RemoteBackend for %s, which is not idle!",
                 dest_s)
         else:
             log.info("Closing RemoteBackend for %s.", dest_s)
             rb.proc_evt_bye(event.Event('bye', message='Idle timeout.'))
             del self.__remotes[dest_s]
     else:
         log.warning("No RemoteBackend for %s", dest_s)
Exemplo n.º 6
0
    def testEvent(self):

        def make_evt(*args, **kwargs):
            return list(event.Event(*args, **kwargs))

        self.failUnlessEqual(['Event', 'ping', '99', {}, None, {}], make_evt('ping', id='99'))
        self.failUnlessRaises(TypeError, make_evt, 1)
        self.failUnlessEqual(['Event', 'ping', '99', {}, None, {}], make_evt(evt='ping', id='99'))
        self.failUnlessRaises(TypeError, make_evt, evt=1)
        self.failUnlessRaises(TypeError, make_evt, evt='ping', origin={}, timestamp='')
        self.failUnlessEqual(['Event', 'ping', '99', {}, None, {'value':1}], make_evt(evt='ping', value=1, id='99'))
        self.failUnlessEqual(['Event', 'ping', '99', {}, None, {'value':1}], make_evt(**{'evt':'ping', 'value':1, 'id':'99'}))
        self.failUnlessEqual(['Event', 'ping', '99', {}, None, {'value':1}], make_evt(value=1, evt='ping', id='99'))
        self.failUnlessEqual(['Event', 'ping', '99', {}, None, {'value':1}], make_evt(**{'value':1, 'evt':'ping', 'id':'99'}))
        evt = event.Event(evt='file_write', id='99', data='DATA', file_id='FID')
        self.failUnlessIsInstance(evt, event.file_write_)
        self.failUnlessEqual(['Event', 'file_write', '99', {}, None, {'file_id':'FID', 'data':'DATA'}], evt)
Exemplo n.º 7
0
    def proc_cmd_dump(self, backend, cmd, echo_evt):
        answ = ""

        answ += "\n== Backends ==\n"
        if self.backends:
            for be in self.backends:
                if be:
                    str = " "
                else:
                    str = "-"
                answ += "%s %s\n" % (str, be)
        else:
            answ += "None\n"

        answ += "\n== Tasks ==\n"
        if self.masters:
            for master in self.masters.values():
                answ += master.dump(indent='', verbose=True) + "\n"
        else:
            answ += "None\n"

        answ += "\n=== Connections ===\n"
        if self.tasks:
            for t in self.tasks:
                answ += "%s\n" % t
        else:
            answ += "None\n"

        if self.conf:
            answ += "\n== Config ==\n%s\n" % (self.conf,)

        if self.runtime.vars:
            answ += "\n== Variables ==\n"
            for k in sorted(self.runtime.vars.keys()):
                answ += "%r=%r\n" % (k, self.runtime.vars[k])

        if self.killed:
            answ += "\n== Killed ==\nTrue\n"

        evt = event.Event('dump', message=answ)
        log.debug("Controller: backend.proc_evt(%r)", evt)
        backend.proc_evt(evt, explicit=True)

        log.info('%s', answ)
Exemplo n.º 8
0
 def proc_cmd_PING(self, backend, cmd, echo_evt):
     self.generate_evt(event.Event('PONG', message=cmd.arg('message', None)))
Exemplo n.º 9
0
 def proc_cmd_ping(self, backend, cmd, echo_evt):
     evt = event.Event('pong', message=cmd.arg('message', None))
     log.debug("Controller: backend.proc_evt(%r)", evt)
     backend.proc_evt(evt, explicit=True)
Exemplo n.º 10
0
 def test_constructors(e):
     test_copy(e, event.Event(e))
     test_copy(e, event.Event(list(e)))
     test_copy(e, event.event(list(e)))
     if isinstance(e, event.Event):
         self.failUnless(e is event.event(e))
Exemplo n.º 11
0
 def make_evt(*args, **kwargs):
     return list(event.Event(*args, **kwargs))