コード例 #1
0
ファイル: emitter.py プロジェクト: mx739150/ambari-app
    def __init__(self, config, application_metric_map, stop_handler):
        threading.Thread.__init__(self)
        logger.debug('Initializing Emitter thread.')
        self.lock = threading.Lock()
        self.send_interval = config.get_send_interval()
        self.hostname = config.get_hostname_config()
        self.hostname_hash = self.compute_hash(self.hostname)
        self._stop_handler = stop_handler
        self.application_metric_map = application_metric_map
        self.collector_port = config.get_server_port()
        self.all_metrics_collector_hosts = config.get_metrics_collector_hosts()
        self.is_server_https_enabled = config.is_server_https_enabled()
        self.set_instanceid = config.is_set_instanceid()
        self.instanceid = config.get_instanceid()

        if self.is_server_https_enabled:
            self.ca_certs = config.get_ca_certs()

        # TimedRoundRobinSet
        if config.get_failover_strategy() == ROUND_ROBIN_FAILOVER_STRATEGY:
            self.active_collector_hosts = BlacklistedSet(
                self.all_metrics_collector_hosts,
                float(config.
                      get_failover_strategy_blacklisted_interval_seconds()))
        else:
            raise Exception(
                -1, "Uknown failover strategy {0}".format(
                    config.get_failover_strategy()))
コード例 #2
0
 def test_blacklisted_set(self):
   hosts = ["1", "2", "3", "4"]
   sleep_time = 1
   bs = BlacklistedSet(hosts, sleep_time)
   bs.blacklist("4")
   counter = 0
   for host in bs:
     counter = counter + 1
   self.assertEqual(counter, 3)
   time.sleep(sleep_time)
   counter = 0
   for host in bs:
     counter = counter + 1
   self.assertEqual(counter, 4)
   bs.blacklist("1")
   bs.blacklist("2")
   counter = 0
   for host in bs:
     counter = counter + 1
   self.assertEqual(counter, 2)