Beispiel #1
0
 def install_group_mapper(self, tag, config_parser):
     """
     Configure the component that will be used to map a bare subject to
     groups of interest.
     """
     factory = get_plugin_factory(tag, IGroupMapperFactory)
     if factory is None:
         raise UnknownRouterError(
             "The group mapper identified by tag '{0}' is unknown.".format(
                 tag))
     group_mapper = factory.generate_group_mapper(config_parser)
     group_mapper.log = self.log
     self.group_mapper = group_mapper 
Beispiel #2
0
 def install_router(self, tag, config_parser):
     """
     Configure the component that will be used to route messages to
     provisioner targets.
     """
     factory = get_plugin_factory(tag, IRouterFactory)
     if factory is None:
         raise UnknownRouterError(
             "The router identified by tag '{0}' is unknown.".format(tag))
     factory.log = self.log
     router = factory.generate_router(config_parser)
     router.log = self.log
     self.router = router 
Beispiel #3
0
 def install_attribute_resolver(self, tag, config_parser):
     """
     Configure the component that will be used to perform attribute
     resolution.
     """
     log = self.log
     factory = get_plugin_factory(tag, IAttributeResolverFactory)
     if factory is None:
         raise UnknownAttributeResolverError(
             "The attribute resolver identified by tag '{0}' is unknown.".format(
                 tag))
     factory.log = log
     attrib_resolver = factory.generate_attribute_resolver(config_parser)
     attrib_resolver.log = self.log
     attrib_resolver.reactor = self.reactor
     self.attrib_resolver = attrib_resolver
Beispiel #4
0
 def load_parser_map(self, parser_map_filename):
     """
     Load the parser map.
     """
     log = self.log
     self.parser_mappings = []
     with open(parser_map_filename) as f:
         doc = commentjson.load(f)
     for entry_index, entry in enumerate(doc):
         valid = True
         for required in ('exchange', 'route_key', 'parser'):
             if not required in entry:
                 log.error("Parse map entry {entry_index} missing required field '{required}'.  This entry will be skipped.", 
                     entry_index=entry_index,
                     required=required)
                 valid = False
         if not valid:
             continue
         try:
             exchange = re.compile(entry["exchange"])
         except re.error as ex:
             log.error("Parser map entry {entry_index}: Exchange pattern '{exchange}' is not a valid regular expression.  Error was {regex_error}.",
                 entry_index=entry_index,
                 exchange=entry["exchange"],
                 regex_error=ex)
             valid = False
         try:
             route_key = re.compile(entry["route_key"])
         except re.error as ex:
             log.error("Parser map entry {entry_index}: Route key pattern '{route_key}' is not a valid regular expression.  Error was {regex_error}.",
                 entry_index=entry_index,
                 route_key=entry["route_key"],
                 regex_error=ex)
             valid = False
         parser_tag = entry["parser"]
         parser_args = entry.get("parser_args")
         if parser_args is None:
             parser_args = {}
         factory = get_plugin_factory(parser_tag, IMessageParserFactory)
         if factory is None:
             log.error("Parser map entry {entry_index}: Could not find a matching parser for tag '{parser_tag}'.",
             entry_index=entry_index,
             parser_tag=parser_tag)
             continue
         parser = factory.generate_message_parser(**parser_args)
         matcher = ParserMatcher(exchange, route_key, parser)
         self.parser_mappings.append(matcher)
Beispiel #5
0
 def startService(self):
     """
     Start the service.
     """
     scp = load_config(config_file=self.config,
                       defaults=self.make_config_defaults())
     self.scp = scp
     app_info = section2dict(scp, "APPLICATION")
     log_level = app_info.get("log_level", "INFO")
     log = Logger(observer=self.logObserverFactory(log_level))
     self.log = log
     self.amqp_info = section2dict(scp, "AMQP")
     amqp_rate_limit_ms = self.amqp_info.get("rate_limit_ms", None)
     if not amqp_rate_limit_ms is None:
         self.amqp_rate_limit_ms = int(amqp_rate_limit_ms)
     amqp_log_level = self.amqp_info.get("log_level", log_level)
     self.amqp_log = Logger(
         observer=self.logObserverFactory(amqp_log_level))
     service_state = self.service_state
     service_state.last_update = datetime.datetime.today()
     self.start_amqp_client()
     provisioner_tag = app_info['provisioner']
     log.info("Provisioner tag => '{provisioner}'",
              provisioner=provisioner_tag)
     provisioner_factory = get_plugin_factory(provisioner_tag,
                                              IProvisionerFactory)
     if provisioner_factory is None:
         msg = "No provisioner factory was found!"
         log.error(msg)
         d = self.reactor.callLater(0, self.reactor.stop)
         raise Exception(msg)
     provisioner_factory.log = self.log
     provisioner = provisioner_factory.generateProvisioner()
     provisioner.reactor = self.reactor
     provisioner.service_state = service_state
     provisioner.load_config(self.config, log_level,
                             self.logObserverFactory)
     self.provisioner = provisioner
     web_log_level = log_level
     if scp.has_section("WEB"):
         web_info = section2dict(scp, "WEB")
         web_log_level = web_info.get("log_level", log_level)
     self.web_log = Logger(observer=self.logObserverFactory(web_log_level))
Beispiel #6
0
 def install_group_attribute_resolver(self, tag, config_parser):
     """
     Configure the component that will be used to perform group attribute
     resolution.
     """
     log = self.log
     if tag is None:
         log.info("No Group Attribute resolver was configured.")
         return
     factory = get_plugin_factory(tag, IAttributeResolverFactory)
     if factory is None:
         raise UnknownAttributeResolverError(
             "The attribute resolver identified by tag '{0}' is unknown.".format(
                 tag))
     factory.log = log
     section = "RDBMS Group Attribute Resolver"
     attrib_resolver = factory.generate_attribute_resolver(config_parser, section=section)
     attrib_resolver.log = self.log
     attrib_resolver.reactor = self.reactor
     self.group_attrib_resolver = attrib_resolver
     log.debug("Installed Group Attribute Resolver: {resolver}", resolver=attrib_resolver)