Esempio n. 1
0
    def _load_proxy_server(self, server):
        hosts = self._load_config_item('hosts', server, required=False)
        ports = [
            str(s)
            for s in self._load_config_item('ports', server, required=True)
        ]
        healthcheck_route = self._load_config_item('healthcheck_route',
                                                   server,
                                                   required=False)
        routes = self._load_config_item('routes', server, required=False)
        proxy_routes = self._load_proxy_routes(routes)
        streams = self._load_config_item('streams', server, required=False)
        proxy_streams = self._load_proxy_streams(streams)

        msg = None
        if not routes and not streams:
            msg = 'At least one ProxyStream or ProxyRoute required.'
        if routes and streams:
            msg = 'HTTP and TCP balancing not supported at the same time.'
        if msg:
            raise AurProxyConfigException(msg)

        context = self._load_config_item('context',
                                         server,
                                         required=False,
                                         default={})
        return ProxyServer(hosts, ports, healthcheck_route, proxy_routes,
                           proxy_streams, context)
Esempio n. 2
0
 def __init__(self,
              signal_update_fn=None,
              share_updater_factories=None,
              **kwargs):
     super(StaticProxySource, self).__init__(signal_update_fn,
                                             share_updater_factories)
     self._name = kwargs.get('name')
     self._host = kwargs.get('host')
     self._port = kwargs.get('port')
     self._endpoint = SourceEndpoint(self._host, self._port)
     err_fmt = '"{0}" required on StaticProxySource'
     if not self._name:
         raise AurProxyConfigException(err_fmt.format('name'))
     if not self._host:
         raise AurProxyConfigException(err_fmt.format('host'))
     if not self._port:
         raise AurProxyConfigException(err_fmt.format('port'))
Esempio n. 3
0
    def _load_config_item(self,
                          name,
                          config_container,
                          default=None,
                          required=True):
        if required and name not in config_container:
            raise AurProxyConfigException('\'{0}\' required.'.format(name))

        return config_container.get(name, default)
Esempio n. 4
0
def load_mirror_updater(source, ports, max_qps, max_update_frequency,
                        command_template_path, pid_path):
    """
  Load a MirrorUpdater.

  Args:
    source - JSON string or ProxySource - Source whose endpoints describe gor
      repeaters.
    ports - string of comma seperated integers- Local ports to mirror.
      Example: "8080,8081"
    max_qps - integer - Max QPS to mirror to gor repeater.
    max_update_frequency - integer - number of seconds between updates of
      mirror configuration.
    command_template_path - str - path to command template to be rendered.

  Returns:
    A MirrorUpdater instance.
  """
    if not source:
        raise AurProxyConfigException('source_config required!')
    if not ports:
        raise AurProxyConfigException('ports required!')
    if not max_qps:
        raise AurProxyConfigException('max_qps required!')
    if not os.path.isfile(command_template_path):
        msg = '"{0}" doesn\'t exist!'.format(command_template_path)
        raise AurProxyConfigException(msg)
    ports = [int(p) for p in ports.split(',')]

    if not isinstance(source, ProxySource):
        source_dict = json.loads(source)
        source = load_klass_plugin(source_dict,
                                   klass_field_name='source_class')

    return MirrorUpdater(source, ports, max_qps, max_update_frequency,
                         command_template_path, pid_path)
Esempio n. 5
0
    def __init__(self,
                 signal_update_fn=None,
                 share_adjuster_factories=None,
                 **kwargs):
        """

    :param signal_update_fn:
    :param share_adjuster_factories:
    :param kwargs:
    """
        super(StaticListProxySource, self).__init__(signal_update_fn,
                                                    share_adjuster_factories)
        self._server_set = []
        server_list = kwargs.get('server_list')
        logger.info('ServerList: {0}'.format(server_list))
        err_fmt = '"{0}" required on StaticListProxySource'
        for idx, server_info in enumerate(server_list):
            _host = server_info.get('host')
            _port = server_info.get('port')
            _share = server_info.get('share') if server_info.get(
                'share') else 1.0
            _context = {
                'source':
                "{0}.{1}.{2}.{3}.{4}".format(kwargs.get('cluster'),
                                             kwargs.get('role'),
                                             kwargs.get('environment'),
                                             kwargs.get('job'), idx)
            }
            if not _host:
                raise AurProxyConfigException(err_fmt.format('host'))
            if not _port:
                raise AurProxyConfigException(err_fmt.format('port'))
            self._server_set.append(
                ShareEndpoint(_host, _port, _share, 1.0, _context))
        if self._server_set.count == 0:
            raise AurProxyConfigException(err_fmt.format('server_list'))
Esempio n. 6
0
 def __init__(self,
              name,
              source_whitelist=_DEFAULT_SOURCE_WHITELIST,
              signal_update_fn=None,
              share_adjuster_factories=None):
   """
   Args:
     name - Required str name of this API source. Should be unique per
       aurproxy task instance.
     source_whitelist - Optional list(str) of source class paths that are
       allowed to be instantiated.
     signal_update_fn - Optional callback fn - used to signal need to update.
     share_adjuster_factories - Optional list of ShareAdjuster factories.
   """
   super(ApiSource, self).__init__(signal_update_fn, share_adjuster_factories)
   if not name:
     raise AurProxyConfigException(name)
   self._name = name
   self._source_whitelist = source_whitelist
   self._source_map = defaultdict(dict)
   self._blueprint = self._build_blueprint(name)
Esempio n. 7
0
 def register(klass):
     global _backends
     if klass.NAME in _backends:
         msg = 'Backend "{0}" already registered'.format(klass.NAME)
         raise AurProxyConfigException(msg)
     _backends[klass.NAME] = klass