def __init__(self, config, cluster='main'): # Support multiple versions of carbon, the API changed in 0.10. args = inspect.getargspec(ConsistentHashingRouter.__init__).args if 'replication_factor' in args: r = ConsistentHashingRouter(config.replication_factor(cluster)) else: class Settings(object): REPLICATION_FACTOR = config.replication_factor(cluster) DIVERSE_REPLICAS = False ROUTER_HASH_TYPE = None r = ConsistentHashingRouter(Settings()) # 'hash_type' was added only in carbon 1.0.2 or master args = inspect.getargspec(ConsistentHashRing.__init__).args if 'hash_type' in args: r.ring = ConsistentHashRing(nodes=[], hash_type=config.hashing_type(cluster)) self.ring = r try: dest_list = config.destinations(cluster) self.destinations = util.parseDestinations(dest_list) except ValueError as e: raise SystemExit("Unable to parse destinations!" + str(e)) for d in self.destinations: self.ring.addDestination(d)
def __init__(self, config, cluster='main', aggregation_rules=None): relay_method = config.relay_method(cluster=cluster) if relay_method == "consistent-hashing": # Support multiple versions of carbon, the API changed in 0.10. args = inspect.getargspec(ConsistentHashingRouter.__init__).args if 'replication_factor' in args: r = ConsistentHashingRouter(config.replication_factor(cluster)) else: class Settings(object): REPLICATION_FACTOR = config.replication_factor(cluster) DIVERSE_REPLICAS = False r = ConsistentHashingRouter(Settings()) # 'hash_type' was added only in carbon 1.0.2 or master args = inspect.getargspec(ConsistentHashRing.__init__).args if 'hash_type' in args: r.ring = ConsistentHashRing( hash_type=config.hashing_type(cluster)) elif relay_method == "aggregated-consistent-hashing": if aggregation_rules: RuleManager.read_from(aggregation_rules) r = AggregatedConsistentHashingRouter( RuleManager, config.replication_factor(cluster)) self.ring = r try: dest_list = config.destinations(cluster) self.destinations = util.parseDestinations(dest_list) except ValueError as e: raise SystemExit("Unable to parse destinations!" + str(e)) for d in self.destinations: self.ring.addDestination(d)