Beispiel #1
0
    def __init__(self, svcbus, **opts):
        EventBus.__init__(self)
        s_storm.Runtime.__init__(self)

        self.addConfDef('svcbus:deftag', asloc='deftag', type='syn:tag', defval=deftag, doc='Default tag for cores')
        self.addConfDef('svcbus:timeout', asloc='svctime', type='int', doc='SvcBus Telepath Link Tufo')

        self.setConfOpts(opts)

        self.svcbus = svcbus
        self.svcprox = s_service.SvcProxy(svcbus, self.svctime)
Beispiel #2
0
    def __init__(self, svcbus, **opts):
        EventBus.__init__(self)

        # a core we use for data model stuff..
        self.core = s_cortex.openurl('ram:///')
        self.onfini(self.core.fini)

        s_storm.Runtime.__init__(self)
        self.setConfOpts(opts)

        self.svcbus = svcbus
        self.svcprox = s_service.SvcProxy(svcbus, self.svctime)
Beispiel #3
0
    def test_service_proxy(self):

        with s_daemon.Daemon() as dmon:

            sbus = s_service.SvcBus()
            dmon.share('syn.svcbus', sbus, fini=True)

            link = dmon.listen('tcp://127.0.0.1:0/')

            port = link[1].get('port')

            with s_telepath.openurl('tcp://127.0.0.1/syn.svcbus',
                                    port=port) as prox:

                woot0 = Woot()
                woot1 = Woot()

                s_service.runSynSvc('woots.woot0', woot0, prox)
                s_service.runSynSvc('woots.woot1',
                                    woot1,
                                    prox,
                                    tags=('foo.bar', ))

                svcp = s_service.SvcProxy(prox)

                foos = svcp.getTagProxy('foo')
                woots = svcp.getTagProxy('woots')

                vals = tuple(sorted(foos.foo(20, y=20)))
                self.eq(vals, (40, ))

                vals = tuple(sorted(woots.foo(10, y=20)))
                self.eq(vals, (30, 30))

                def runNewpMeth():
                    for foo in woots.newp(44, y=33):
                        pass

                self.eq(2, len(svcp.getSynSvcs()))
                self.eq(2, len(svcp.getSynSvcsByTag('woots')))

                woots = svcp.getTagProxy(
                    'class.synapse.tests.test_lib_service.Woot')

                vals = tuple(sorted(woots.foo(10, y=20)))
                self.eq(vals, (30, 30))
Beispiel #4
0
    def __init__(self, svcbus, **info):
        s_eventbus.EventBus.__init__(self)

        self.info = info
        self.auth = info.get('auth')

        self.svcbus = svcbus
        self.svcprox = s_service.SvcProxy(svcbus)

        self.insts = {}
        self.rules = {}

        self.setInstFunc('opts', opts)
        self.setInstFunc('join', join)
        self.setInstFunc('lift', lift)
        self.setInstFunc('must', must)
        self.setInstFunc('cant', cant)
        self.setInstFunc('pivot', pivot)
Beispiel #5
0
    def __init__(self, svcbus, **info):
        s_eventbus.EventBus.__init__(self)

        self.info = info
        self.auth = info.get('auth')

        self.svcbus = svcbus
        self.svcprox = s_service.SvcProxy(svcbus)

        self.rules = {}

        self.operctors = {}

        # add the basic operators
        self.setOperCtor('by', s_opers_basic.ByOper)
        self.setOperCtor('eq', s_opers_basic.EqOper)

        self.setOperCtor('gt', s_opers_basic.GtOper)
        self.setOperCtor('lt', s_opers_basic.LtOper)
        self.setOperCtor('ge', s_opers_basic.GeOper)
        self.setOperCtor('le', s_opers_basic.LeOper)

        self.setOperCtor('re', s_opers_basic.ReOper)

        self.setOperCtor('or', s_opers_basic.OrOper)
        self.setOperCtor('and', s_opers_basic.AndOper)

        self.setOperCtor('has', s_opers_basic.HasOper)

        self.setOperCtor('join', s_opers_basic.JoinOper)
        self.setOperCtor('opts', s_opers_basic.OptsOper)

        self.setOperCtor('load', s_opers_basic.LoadOper)
        self.setOperCtor('save', s_opers_basic.SaveOper)
        self.setOperCtor('clear', s_opers_basic.ClearOper)

        self.setOperCtor('pivot', s_opers_basic.PivotOper)
Beispiel #6
0
    def test_service_proxy_bounce(self):

        with s_daemon.Daemon() as dmon:

            sbus = s_service.SvcBus()
            dmon.share('syn.svcbus', sbus, fini=True)

            link = dmon.listen('tcp://127.0.0.1:0/')

            port = link[1].get('port')
            sprox0 = s_service.SvcProxy(s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port))
            sprox1 = s_service.SvcProxy(s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port))

            woot0 = Woot()
            woot1 = Woot()

            w0 = sprox0.waiter(2, 'syn:svc:init')
            w1 = sprox0.waiter(2, 'syn:svc:init')

            sprox0.runSynSvc('woots.woot0', woot0, tags=('foo.bar',))
            sprox1.runSynSvc('woots.woot1', woot1, tags=('foo.bar',))

            w0.wait(1)
            w1.wait(1)

            # Both SvcProxy objects know about both objects and they are not None
            r = sprox0.getSynSvcsByTag('foo.bar')
            self.len(2, r)
            for svcfo in r:
                self.nn(svcfo)
            r = sprox1.getSynSvcsByTag('foo.bar')
            self.len(2, r)
            for svcfo in r:
                self.nn(svcfo)

            r = [_r for _r in sprox0.callByTag('foo.bar', gentask('foo', 1))]
            self.len(2, r)
            for svcfo, result in r:
                self.eq(result, 11)

            # Tear down sprox1 - it will fini the woots.woot1 service
            w0 = sprox0.waiter(1, 'syn:svc:fini')
            sprox1.fini()
            w0.wait(1)

            r = sprox0.getSynSvcsByTag('foo.bar')
            self.len(1, r)
            for svcfo in r:
                self.nn(svcfo)

            # woots.woot0 is still around
            r = sprox0.callByName('woots.woot0', gentask('foo', 1))
            self.eq(r, 11)
            # Poor woots.woot1 is gone though
            self.raises(NoSuchObj, sprox0.callByName, 'woots.woot1', gentask('foo', 1))

            r = [_r for _r in sprox0.callByTag('foo.bar', gentask('foo', 1))]
            self.len(1, r)
            for svcfo, result in r:
                self.eq(result, 11)

            # We can recreate sprox1, reshare woot1 and use it
            sprox1 = s_service.SvcProxy(s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port))

            w0 = sprox0.waiter(1, 'syn:svc:init')
            w1 = sprox1.waiter(1, 'syn:svc:init')

            sprox1.runSynSvc('woots.woot1', woot1, tags=('foo.bar',))
            w0.wait(1)
            w1.wait(1)

            # Both SvcProxy objects know about both objects
            r = sprox0.getSynSvcsByTag('foo.bar')
            self.len(2, r)
            for svcfo in r:
                self.nn(svcfo)
            r = sprox1.getSynSvcsByTag('foo.bar')
            self.len(2, r)
            for svcfo in r:
                self.nn(svcfo)

            # We can call woots1 from sprox0 again and by name
            r = sprox0.callByName('woots.woot1', gentask('foo', 1))
            self.eq(r, 11)

            sprox0.fini()
            sprox1.fini()