예제 #1
0
def makeService(config):
    s = tap.makeService(config)

    bs = s.getServiceNamed('backend')
    cs = s.getServiceNamed('component')

    # Set up XMPP service for subscribing to remote nodes

    if config['backend'] == 'pgsql':
        from idavoll.pgsql_storage import GatewayStorage
        gst = GatewayStorage(bs.storage.dbpool)
    elif config['backend'] == 'memory':
        from idavoll.memory_storage import GatewayStorage
        gst = GatewayStorage()

    ss = RemoteSubscriptionService(config['jid'], gst)
    ss.setHandlerParent(cs)
    ss.startService()

    # Set up web service

    root = resource.Resource()

    # Set up resources that exposes the backend
    root.putChild('create', gateway.CreateResource(bs, config['jid'],
                                                   config['jid']))
    root.putChild('delete', gateway.DeleteResource(bs, config['jid'],
                                                   config['jid']))
    root.putChild('publish', gateway.PublishResource(bs, config['jid'],
                                                     config['jid']))
    root.putChild('list', gateway.ListResource(bs))

    # Set up resources for accessing remote pubsub nodes.
    root.putChild('subscribe', gateway.RemoteSubscribeResource(ss))
    root.putChild('unsubscribe', gateway.RemoteUnsubscribeResource(ss))
    root.putChild('items', gateway.RemoteItemsResource(ss))

    site = server.Site(root)
    w = internet.TCPServer(int(config['webport']), site)
    w.setServiceParent(s)

    # Set up a manhole

    namespace = {'service': s,
                 'component': cs,
                 'backend': bs,
                 'root': root}

    f = getManholeFactory(namespace, admin='admin')
    manholeService = strports.service('2222', f)
    manholeService.setServiceParent(s)

    return s
예제 #2
0
파일: tap_http.py 프로젝트: nfvs/idavoll
def makeService(config):
    s = tap.makeService(config)

    bs = s.getServiceNamed('backend')
    cs = s.getServiceNamed('component')

    # Set up XMPP service for subscribing to remote nodes

    if config['backend'] == 'pgsql':
        from idavoll.pgsql_storage import GatewayStorage
        gst = GatewayStorage(bs.storage.dbpool)
    elif config['backend'] == 'memory':
        from idavoll.memory_storage import GatewayStorage
        gst = GatewayStorage()

    ss = RemoteSubscriptionService(config['jid'], gst)
    ss.setHandlerParent(cs)
    ss.startService()

    # Set up web service

    root = resource.Resource()

    # Set up resources that exposes the backend
    root.child_create = gateway.CreateResource(bs, config['jid'],
                                               config['jid'])
    root.child_delete = gateway.DeleteResource(bs, config['jid'],
                                               config['jid'])
    root.child_publish = gateway.PublishResource(bs, config['jid'],
                                                 config['jid'])
    root.child_list = gateway.ListResource(bs)

    # Set up resources for accessing remote pubsub nodes.
    root.child_subscribe = gateway.RemoteSubscribeResource(ss)
    root.child_unsubscribe = gateway.RemoteUnsubscribeResource(ss)
    root.child_items = gateway.RemoteItemsResource(ss)

    if config["verbose"]:
        root = log.LogWrapperResource(root)

    site = server.Site(root)
    w = internet.TCPServer(int(config['webport']), channel.HTTPFactory(site))

    if config["verbose"]:
        logObserver = log.DefaultCommonAccessLoggingObserver()
        w2s = Web2Service(logObserver)
        w.setServiceParent(w2s)
        w = w2s

    w.setServiceParent(s)

    # Set up a manhole

    namespace = {'service': s,
                 'component': cs,
                 'backend': bs,
                 'root': root}

    f = getManholeFactory(namespace, admin='admin')
    manholeService = strports.service('2222', f)
    manholeService.setServiceParent(s)

    return s