Exemple #1
0
    def makeService(self, options):
        """
        Create a service which will run a scram server.

        @param options: mapping of configuration
        """

        from scram.network import ScramFactory
        from scram.world import (TCP_SERVICE_NAME, SCRAM_SERVICE_NAME,
                                 ScramService, World)

        from twisted.internet import reactor
        from twisted.application.service import MultiService
        from twisted.protocols.policies import TrafficLoggingFactory

        world = World(granularity=60, platformClock=reactor)

        service = MultiService()

        factory = ScramFactory(world)
        if options['log-directory'] is not None:
            factory = TrafficLoggingFactory(
                factory, join(options['log-directory'], 'scram'))

        tcp = TCPServer(options['port'], factory, interface='127.0.0.1')
        tcp.setName(TCP_SERVICE_NAME)
        tcp.setServiceParent(service)

        scram = ScramService(world)
        scram.setName(SCRAM_SERVICE_NAME)
        scram.setServiceParent(service)

        return service
Exemple #2
0
    def makeService(self, options):
        """
        Create a service which will run a scram server.

        @param options: mapping of configuration
        """

        from scram.network import ScramFactory        
        from scram.world import (TCP_SERVICE_NAME, SCRAM_SERVICE_NAME, ScramService, World)

        from twisted.internet import reactor
        from twisted.application.service import MultiService
        from twisted.protocols.policies import TrafficLoggingFactory

        world = World(granularity=60, platformClock=reactor)

        service = MultiService()

        factory = ScramFactory(world)
        if options['log-directory'] is not None:
            factory = TrafficLoggingFactory(
                factory, join(options['log-directory'], 'scram'))

        tcp = TCPServer(options['port'], factory, interface='127.0.0.1')
        tcp.setName(TCP_SERVICE_NAME)
        tcp.setServiceParent(service)

        scram = ScramService(world)
        scram.setName(SCRAM_SERVICE_NAME)
        scram.setServiceParent(service)

        return service
Exemple #3
0
def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_factory.noisy = False
        broadcaster_service = TCPServer(
            config['broadcast-port'],
            broadcaster_factory
        )
        broadcaster_service.setName("Broadcaster")
        broadcaster_service.setServiceParent(broker_service)

        # If we're running a broadcast, we will rebroadcast any events we
        # receive to it.
        config['handlers'].append(EventRelay(broadcaster_factory))

    if config['receive']:
        receiver_factory = VOEventReceiverFactory(
            local_ivo=config['local-ivo'],
            validators=[
                CheckPreviouslySeen(event_db),
                CheckSchema(
                    os.path.join(comet.__path__[0], "schema/VOEvent-v2.0.xsd")
                ),
                CheckIVORN()
            ],
            handlers=config['handlers']
        )
        if log.LEVEL >= log.Levels.INFO: receiver_factory.noisy = False
        whitelisting_factory = WhitelistingFactory(receiver_factory, config['whitelist'])
        if log.LEVEL >= log.Levels.INFO: whitelisting_factory.noisy = False
        receiver_service = TCPServer(config['receive-port'], whitelisting_factory)
        receiver_service.setName("Receiver")
        receiver_service.setServiceParent(broker_service)

    for host, port in config["remotes"]:
        subscriber_factory = VOEventSubscriberFactory(
            local_ivo=config["local-ivo"],
            validators=[CheckPreviouslySeen(event_db)],
            handlers=config['handlers'],
            filters=config['filters']
        )
        if log.LEVEL >= log.Levels.INFO: subscriber_factory.noisy = False
        remote_service = TCPClient(host, port, subscriber_factory)
        remote_service.setName("Remote %s:%d" % (host, port))
        remote_service.setServiceParent(broker_service)

    if not broker_service.services:
        reactor.callWhenRunning(log.warning, "No services requested; stopping.")
        reactor.callWhenRunning(reactor.stop)
    return broker_service
Exemple #4
0
 def _makeSiteService(self, papi_xmlrpc, config):
     """Create the site service."""
     site_root = Resource()
     site_root.putChild("api", papi_xmlrpc)
     site = Site(site_root)
     site_port = config["port"]
     site_interface = config["interface"]
     site_service = TCPServer(site_port, site, interface=site_interface)
     site_service.setName("site")
     return site_service
Exemple #5
0
 def _makeSiteService(self, papi_xmlrpc, config):
     """Create the site service."""
     site_root = Resource()
     site_root.putChild("api", papi_xmlrpc)
     site = Site(site_root)
     site_port = config["port"]
     site_interface = config["interface"]
     site_service = TCPServer(site_port, site, interface=site_interface)
     site_service.setName("site")
     return site_service
Exemple #6
0
 def configure_service(self):
     """
     Instantiation and startup for the RESTful API.
     """
     root = APIResource()
     factory = Site(root)
     
     port = settings.API_PORT
     server = TCPServer(port, factory)
     server.setName("WebAPI")
     self.addService(server)
Exemple #7
0
    def makeService(self, options):
        """Construct a service."""
        services = MultiService()

        config_file = options["config-file"]
        config = Config.load(config_file)

        log_service = LogService(config["logfile"])
        log_service.setServiceParent(services)

        oops_config = config["oops"]
        oops_dir = oops_config["directory"]
        oops_reporter = oops_config["reporter"]
        oops_service = OOPSService(log_service, oops_dir, oops_reporter)
        oops_service.setServiceParent(services)

        frontend_config = config["frontend"]
        frontend_port = frontend_config["port"]
        frontend_prefix = frontend_config["prefix"]
        frontend_interface = frontend_config["interface"]
        frontend_manager = DeprecatedQueueManager(frontend_prefix)

        broker_config = config["broker"]
        broker_port = broker_config["port"]
        broker_host = broker_config["host"]
        broker_username = broker_config["username"]
        broker_password = broker_config["password"]
        broker_vhost = broker_config["vhost"]

        cb_connected = frontend_manager.connected
        cb_disconnected = frontend_manager.disconnected
        cb_failed = lambda connector_and_reason: (log.err(
            connector_and_reason[1], "Connection failed"))

        client_factory = AMQFactory(broker_username, broker_password,
                                    broker_vhost, cb_connected,
                                    cb_disconnected, cb_failed)
        client_service = TCPClient(broker_host, broker_port, client_factory)
        client_service.setName("amqp")
        client_service.setServiceParent(services)

        frontend_resource = FrontEndAjax(frontend_manager)
        frontend_service = TCPServer(frontend_port,
                                     Site(frontend_resource),
                                     interface=frontend_interface)
        frontend_service.setName("frontend")
        frontend_service.setServiceParent(services)

        return services
Exemple #8
0
def makeService(config):
    '''
    Create service tree. Only one tracker can be used for every protocol!
    @param config: instance of an Options class with configuration parameters.
    @type config: C{twisted.python.usage.Options}
    @return: service collection
    @rtype: C{twisted.application.service.IServiceCollection}
    '''
    from gorynych.receiver.factories import ReceivingFactory
    from gorynych.receiver import protocols, parsers
    from gorynych.receiver.receiver import ReceiverRabbitQueue, ReceiverService, AuditFileLog

    # Set up application.
    application = service.Application("ReceiverServer")
    sc = service.IServiceCollection(application)

    # Prepare receiver.
    audit_log = AuditFileLog('audit_log')
    sender = ReceiverRabbitQueue(host='localhost', port=5672,
        exchange='receiver', exchange_type='fanout')
    parser = getattr(parsers, config['tracker'])()
    sender.setName('RabbitMQReceiverService')
    sender.setServiceParent(sc)
    receiver_service = ReceiverService(sender, audit_log, parser)
    receiver_service.setName('ReceiverService')
    receiver_service.setServiceParent(sc)

    if 'tcp' in config['protocols']:
        receiver_server = TCPServer(config['port'],
            ReceivingFactory(receiver_service))
        protocol = getattr(protocols,
            '_'.join((config['tracker'], 'tcp', 'protocol')))
        receiver_server.args[1].protocol = protocol
        receiver_server.setName(config['tracker'] + '_tcp')
        receiver_server.setServiceParent(sc)

    if 'udp' in config['protocols']:
        protocol = getattr(protocols,
            '_'.join((config['tracker'], 'udp', 'protocol')))(receiver_service)
        receiver_server = UDPServer(config['port'], protocol)
        receiver_server.setName(config['tracker'] + '_udp')
        receiver_server.setServiceParent(sc)
    return sc
Exemple #9
0
    def makeService(self, options):
        """
        Create a service which will run a Gam3 server.

        @param options: mapping of configuration
        """
        from pygame.image import load

        from gam3.network import Gam3Factory
        from gam3.world import (
            TCP_SERVICE_NAME, GAM3_SERVICE_NAME, Gam3Service, World)
        from game.terrain import loadTerrainFromString, loadTerrainFromSurface
        from twisted.python.filepath import FilePath
        from twisted.internet import reactor
        from twisted.application.service import MultiService
        from twisted.protocols.policies import TrafficLoggingFactory

        world = World(granularity=100, platformClock=reactor)
        terrain = options['terrain']
        if terrain:
            if terrain.endswith('.png'):
                voxels = loadTerrainFromSurface(load(terrain)).voxels
            else:
                raw = FilePath(terrain).getContent()
                voxels = loadTerrainFromString(raw)
            world.terrain.set(0, 0, 0, voxels)

        service = MultiService()

        factory = Gam3Factory(world)
        if options['log-directory'] is not None:
            factory = TrafficLoggingFactory(
                factory, join(options['log-directory'], 'gam3'))

        tcp = TCPServer(options['port'], factory)
        tcp.setName(TCP_SERVICE_NAME)
        tcp.setServiceParent(service)

        gam3 = Gam3Service(world)
        gam3.setName(GAM3_SERVICE_NAME)
        gam3.setServiceParent(service)

        return service
Exemple #10
0
    def configure_services(self, configuration):
        read_configuration()

        for section in configuration.sections():
            if section.startswith("world "):
                factory = BravoFactory(section[6:])
                server = TCPServer(factory.port, factory,
                    interface=factory.interface)
                server.setName(factory.name)
                self.addService(server)
            elif section.startswith("irc "):
                try:
                    from bravo.irc import BravoIRC
                except ImportError:
                    log.msg("Couldn't import IRC stuff!")
                else:
                    factory = BravoIRC(self.namedServices, section[4:])
                    client = TCPClient(factory.host, factory.port, factory)
                    client.setName(factory.name)
                    self.addService()
            elif section.startswith("infiniproxy "):
                factory = BetaProxyFactory(section[12:])
                server = TCPServer(factory.port, factory)
                server.setName(factory.name)
                self.addService(server)
            elif section.startswith("infininode "):
                factory = InfiniNodeFactory(section[11:])
                server = TCPServer(factory.port, factory)
                server.setName(factory.name)
                self.addService(server)
Exemple #11
0
    def configure_services(self, configuration):
        read_configuration()

        for section in configuration.sections():
            if section.startswith("world "):
                factory = BravoFactory(section[6:])
                server = TCPServer(factory.port, factory,
                    interface=factory.interface)
                server.setName(factory.name)
                self.addService(server)
                self.factorylist.append(factory)
            elif section == "web":
                try:
                    from bravo.web import bravo_site
                except ImportError:
                    log.msg("Couldn't import web stuff!")
                else:
                    factory = bravo_site(self.namedServices)
                    port = configuration.getint("web", "port")
                    server = TCPServer(port, factory)
                    server.setName("web")
                    self.addService(server)
            elif section.startswith("irc "):
                try:
                    from bravo.irc import BravoIRC
                except ImportError:
                    log.msg("Couldn't import IRC stuff!")
                else:
                    self.irc = True
                    self.ircbots.append(section)
            elif section.startswith("infiniproxy "):
                factory = BetaProxyFactory(section[12:])
                server = TCPServer(factory.port, factory)
                server.setName(factory.name)
                self.addService(server)
            elif section.startswith("infininode "):
                factory = InfiniNodeFactory(section[11:])
                server = TCPServer(factory.port, factory)
                server.setName(factory.name)
                self.addService(server)
        if self.irc:
            for section in self.ircbots:
                factory = BravoIRC(self.factorylist, section[4:])
                client = TCPClient(factory.host, factory.port, factory)
                client.setName(factory.config)
                self.addService(client)
Exemple #12
0
def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_factory.noisy = False
        broadcaster_whitelisting_factory = WhitelistingFactory(
            broadcaster_factory, config['subscriber-whitelist'], "subscription"
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_whitelisting_factory.noisy = False
        broadcaster_service = TCPServer(
            config['broadcast-port'],
            broadcaster_whitelisting_factory
        )
        broadcaster_service.setName("Broadcaster")
        broadcaster_service.setServiceParent(broker_service)

        # If we're running a broadcast, we will rebroadcast any events we
        # receive to it.
        config['handlers'].append(EventRelay(broadcaster_factory))

    if config['receive']:
        receiver_factory = VOEventReceiverFactory(
            local_ivo=config['local-ivo'],
            validators=[
                CheckPreviouslySeen(event_db),
                CheckSchema(
                    os.path.join(comet.__path__[0], "schema/VOEvent-v2.0.xsd")
                ),
                CheckIVOID()
            ],
            handlers=config['handlers']
        )
        if log.LEVEL >= log.Levels.INFO: receiver_factory.noisy = False
        author_whitelisting_factory = WhitelistingFactory(
            receiver_factory, config['author-whitelist'], "submission"
        )
        if log.LEVEL >= log.Levels.INFO: author_whitelisting_factory.noisy = False
        receiver_service = TCPServer(config['receive-port'], author_whitelisting_factory)
        receiver_service.setName("Receiver")
        receiver_service.setServiceParent(broker_service)

    for host, port in config["remotes"]:
        subscriber_factory = VOEventSubscriberFactory(
            local_ivo=config["local-ivo"],
            validators=[CheckPreviouslySeen(event_db)],
            handlers=config['handlers'],
            filters=config['filters']
        )
        if log.LEVEL >= log.Levels.INFO: subscriber_factory.noisy = False
        remote_service = TCPClient(host, port, subscriber_factory)
        remote_service.setName("Remote %s:%d" % (host, port))
        remote_service.setServiceParent(broker_service)

    if not broker_service.services:
        reactor.callWhenRunning(log.warn, "No services requested; stopping.")
        reactor.callWhenRunning(reactor.stop)
    return broker_service