def __init__(self, store, tenant_id, scaling_group_id): self.log = log.bind(system='otter.rest.policies', tenant_id=tenant_id, scaling_group_id=scaling_group_id) self.store = store self.tenant_id = tenant_id self.scaling_group_id = scaling_group_id
def __init__(self, store, tenant_id, group_id): self.log = log.bind(system='otter.rest.config', tenant_id=tenant_id, scaling_group_id=group_id) self.store = store self.tenant_id = tenant_id self.group_id = group_id
def __init__(self, store, tenant_id, group_id): self.log = log.bind(system='otter.rest.launch', tenant_id=tenant_id, scaling_group_id=group_id) self.store = store self.tenant_id = tenant_id self.group_id = group_id
def __init__(self, store, tenant_id, group_id, dispatcher): self.log = log.bind(system='otter.rest.config', tenant_id=tenant_id, scaling_group_id=group_id) self.store = store self.tenant_id = tenant_id self.group_id = group_id self.dispatcher = dispatcher
def __init__(self, store, tenant_id, region, es_host=None): self.log = log.bind(system='otter.log.history', tenant_id=tenant_id) self.store = store self.tenant_id = tenant_id self.region = region self.es_host = es_host
def __init__(self, store, capability_version, capability_hash, dispatcher): self.log = log.bind(system='otter.rest.execute', capability_version=capability_version, capability_hash=capability_hash) self.store = store self.capability_version = capability_version self.capability_hash = capability_hash self.dispatcher = dispatcher
def __init__(self, store, tenant_id, scaling_group_id, dispatcher): self.log = log.bind(system='otter.rest.group.servers', tenant_id=tenant_id, scaling_group_id=scaling_group_id) self.store = store self.tenant_id = tenant_id self.scaling_group_id = scaling_group_id self.dispatcher = dispatcher
def __init__(self, store, tenant_id, group_id, policy_id): self.log = log.bind(system='otter.rest.webhooks', tenant_id=tenant_id, scaling_group_id=group_id, policy_id=policy_id) self.store = store self.tenant_id = tenant_id self.group_id = group_id self.policy_id = policy_id
def makeService(config): """ Set up the otter-api service. """ set_config_data(dict(config)) if not config_value('mock'): seed_endpoints = [ clientFromString(reactor, str(host)) for host in config_value('cassandra.seed_hosts') ] cassandra_cluster = LoggingCQLClient( RoundRobinCassandraCluster(seed_endpoints, config_value('cassandra.keyspace')), log.bind(system='otter.silverberg')) set_store(CassScalingGroupCollection(cassandra_cluster)) bobby_url = config_value('bobby_url') if bobby_url is not None: set_bobby(BobbyClient(bobby_url)) cache_ttl = config_value('identity.cache_ttl') if cache_ttl is None: # FIXME: Pick an arbitrary cache ttl value based on absolutely no # science. cache_ttl = 300 authenticator = CachingAuthenticator( reactor, ImpersonatingAuthenticator(config_value('identity.username'), config_value('identity.password'), config_value('identity.url'), config_value('identity.admin_url')), cache_ttl) supervisor = Supervisor(authenticator.authenticate_tenant, coiterate) set_supervisor(supervisor) s = MultiService() site = Site(root) site.displayTracebacks = False api_service = service(str(config_value('port')), site) api_service.setServiceParent(s) if config_value('scheduler') and not config_value('mock'): scheduler_service = SchedulerService( int(config_value('scheduler.batchsize')), int(config_value('scheduler.interval')), cassandra_cluster) scheduler_service.setServiceParent(s) return s
def makeService(config): """ Set up the otter-api service. """ set_config_data(dict(config)) if not config_value('mock'): seed_endpoints = [ clientFromString(reactor, str(host)) for host in config_value('cassandra.seed_hosts')] cassandra_cluster = LoggingCQLClient(RoundRobinCassandraCluster( seed_endpoints, config_value('cassandra.keyspace')), log.bind(system='otter.silverberg')) set_store(CassScalingGroupCollection(cassandra_cluster)) bobby_url = config_value('bobby_url') if bobby_url is not None: set_bobby(BobbyClient(bobby_url)) cache_ttl = config_value('identity.cache_ttl') if cache_ttl is None: # FIXME: Pick an arbitrary cache ttl value based on absolutely no # science. cache_ttl = 300 authenticator = CachingAuthenticator( reactor, ImpersonatingAuthenticator( config_value('identity.username'), config_value('identity.password'), config_value('identity.url'), config_value('identity.admin_url')), cache_ttl) supervisor = Supervisor(authenticator.authenticate_tenant, coiterate) set_supervisor(supervisor) s = MultiService() site = Site(root) site.displayTracebacks = False api_service = service(str(config_value('port')), site) api_service.setServiceParent(s) if config_value('scheduler') and not config_value('mock'): scheduler_service = SchedulerService(int(config_value('scheduler.batchsize')), int(config_value('scheduler.interval')), cassandra_cluster) scheduler_service.setServiceParent(s) return s
def __init__(self, reactor, authenticator, ttl): self._reactor = reactor self._authenticator = authenticator self._ttl = ttl self._waiters = {} self._cache = {} self._log = log.bind(system='otter.auth.cache', authenticator=authenticator, cache_ttl=ttl)
def __init__(self, store, tenant_id, scaling_group_id, policy_id, dispatcher): self.log = log.bind(system='otter.log.policy', tenant_id=tenant_id, scaling_group_id=scaling_group_id, policy_id=policy_id) self.store = store self.tenant_id = tenant_id self.scaling_group_id = scaling_group_id self.policy_id = policy_id self.dispatcher = dispatcher
def _(self, request, *args, **kwargs): transaction_id = generate_transaction_id() request.setHeader('X-Response_Id', transaction_id) bound_log = log.bind(system=reflect.fullyQualifiedName(f), transaction_id=transaction_id) bound_log.bind(method=request.method, uri=request.uri, clientproto=request.clientproto, referer=request.getHeader('referer'), useragent=request.getHeader('user-agent')).msg( 'Recieved request') return f(self, request, bound_log, *args, **kwargs)
def _(request, *args, **kwargs): transaction_id = generate_transaction_id() request.setHeader('X-Response-Id', transaction_id) bound_log = log.bind(system=reflect.fullyQualifiedName(f), transaction_id=transaction_id) bound_log.bind(method=request.method, uri=request.uri, clientproto=request.clientproto, referer=request.getHeader("referer"), useragent=request.getHeader("user-agent")).msg( "Received request") return bind_log(f)(request, bound_log, *args, **kwargs)
def _(self, request, *args, **kwargs): transaction_id = generate_transaction_id() request.setHeader('X-Response-Id', transaction_id) bound_log = log.bind( system=reflect.fullyQualifiedName(f), transaction_id=transaction_id) bound_log.bind( method=request.method, uri=request.uri, clientproto=request.clientproto, referer=request.getHeader("referer"), useragent=request.getHeader("user-agent") ).msg("Received request") return bind_log(f)(self, request, bound_log, *args, **kwargs)
def __init__(self, batchsize, interval, slv_client, clock=None): """ Initializes the scheduler service with batch size and interval :param int batchsize: number of events to fetch on each iteration :param int interval: time between each iteration :param slv_client: a :class:`silverberg.client.CQLClient` or :class:`silverberg.cluster.RoundRobinCassandraCluster` instance used to get lock :param clock: An instance of IReactorTime provider that defaults to reactor if not provided """ from otter.models.cass import LOCK_TABLE_NAME self.lock = BasicLock(slv_client, LOCK_TABLE_NAME, 'schedule', max_retry=0) TimerService.__init__(self, interval, self.check_for_events, batchsize) self.clock = clock self.log = otter_log.bind(system='otter.scheduler')
def __init__(self, dispatcher, batchsize, store, partitioner_factory, threshold=60): """ Initialize the scheduler service :param dispatcher: Effect dispatcher :param int batchsize: number of events to fetch on each iteration :param store: cassandra store :param partitioner_factory: Callable of (log, callback) -> :obj:`Partitioner` """ MultiService.__init__(self) self.store = store self.threshold = threshold self.log = otter_log.bind(system="otter.scheduler") self.partitioner = partitioner_factory(self.log, partial(self._check_events, batchsize)) self.partitioner.setServiceParent(self) self.dispatcher = dispatcher
def __init__(self, batchsize, interval, store, kz_client, zk_partition_path, time_boundary, buckets, clock=None, threshold=60): """ Initialize the scheduler service :param int batchsize: number of events to fetch on each iteration :param int interval: time between each iteration :param kz_client: `TxKazooClient` instance :param buckets: an iterable containing the buckets which contains scheduled events :param zk_partition_path: Partiton path used by kz_client to partition the buckets :param time_boundary: Time to wait for partition to become stable :param clock: An instance of IReactorTime provider that defaults to reactor if not provided """ TimerService.__init__(self, interval, self.check_events, batchsize) self.store = store self.clock = clock self.kz_client = kz_client self.buckets = buckets self.zk_partition_path = zk_partition_path self.time_boundary = time_boundary self.kz_partition = None self.threshold = threshold self.log = otter_log.bind(system='otter.scheduler')
def __init__(self, dispatcher, batchsize, store, partitioner_factory, threshold=60): """ Initialize the scheduler service :param dispatcher: Effect dispatcher :param int batchsize: number of events to fetch on each iteration :param store: cassandra store :param partitioner_factory: Callable of (log, callback) -> :obj:`Partitioner` """ MultiService.__init__(self) self.store = store self.threshold = threshold self.log = otter_log.bind(system='otter.scheduler') self.partitioner = partitioner_factory( self.log, partial(self._check_events, batchsize)) self.partitioner.setServiceParent(self) self.dispatcher = dispatcher
def __init__(self, store, tenant_id): self.log = log.bind(system='otter.log.limits', tenant_id=tenant_id) self.store = store self.tenant_id = tenant_id
def __init__(self, store, tenant_id, dispatcher): self.log = log.bind(system='otter.rest.groups', tenant_id=tenant_id) self.store = store self.tenant_id = tenant_id self.dispatcher = dispatcher
def _(request, log, *args, **kwargs): bound_log = log.bind(**kwargs) return f(request, bound_log, *args, **kwargs)
def makeService(config): """ Set up the otter-api service. """ set_config_data(dict(config)) s = MultiService() region = config_value('region') seed_endpoints = [ clientFromString(reactor, str(host)) for host in config_value('cassandra.seed_hosts')] cassandra_cluster = LoggingCQLClient( TimingOutCQLClient( reactor, RoundRobinCassandraCluster( seed_endpoints, config_value('cassandra.keyspace')), config_value('cassandra.timeout') or 30), log.bind(system='otter.silverberg')) get_consistency = partial( get_consistency_level, default=config_value('cassandra.default_consistency'), exceptions=config_value('cassandra.consistency_exceptions')) store = CassScalingGroupCollection(cassandra_cluster, reactor, get_consistency) admin_store = CassAdmin(cassandra_cluster, get_consistency) bobby_url = config_value('bobby_url') if bobby_url is not None: set_bobby(BobbyClient(bobby_url)) cache_ttl = config_value('identity.cache_ttl') if cache_ttl is None: # FIXME: Pick an arbitrary cache ttl value based on absolutely no # science. cache_ttl = 300 authenticator = CachingAuthenticator( reactor, RetryingAuthenticator( reactor, ImpersonatingAuthenticator( config_value('identity.username'), config_value('identity.password'), config_value('identity.url'), config_value('identity.admin_url')), max_retries=config_value('identity.max_retries'), retry_interval=config_value('identity.retry_interval')), cache_ttl) supervisor = SupervisorService(authenticator.authenticate_tenant, region, coiterate) supervisor.setServiceParent(s) set_supervisor(supervisor) health_checker = HealthChecker(reactor, { 'store': getattr(store, 'health_check', None), 'kazoo': store.kazoo_health_check, 'supervisor': supervisor.health_check }) # Setup cassandra cluster to disconnect when otter shuts down if 'cassandra_cluster' in locals(): s.addService(FunctionalService(stop=partial(call_after_supervisor, cassandra_cluster.disconnect, supervisor))) otter = Otter(store, region, health_checker.health_check, es_host=config_value('elasticsearch.host')) site = Site(otter.app.resource()) site.displayTracebacks = False api_service = service(str(config_value('port')), site) api_service.setServiceParent(s) # Setup admin service admin_port = config_value('admin') if admin_port: admin = OtterAdmin(admin_store) admin_site = Site(admin.app.resource()) admin_site.displayTracebacks = False admin_service = service(str(admin_port), admin_site) admin_service.setServiceParent(s) # Setup Kazoo client if config_value('zookeeper'): threads = config_value('zookeeper.threads') or 10 kz_client = TxKazooClient(hosts=config_value('zookeeper.hosts'), threads=threads, txlog=log.bind(system='kazoo')) d = kz_client.start() def on_client_ready(_): # Setup scheduler service after starting scheduler = setup_scheduler(s, store, kz_client) health_checker.checks['scheduler'] = scheduler.health_check otter.scheduler = scheduler # Set the client after starting # NOTE: There is small amount of time when the start is not finished # and the kz_client is not set in which case policy execution and group # delete will fail store.kz_client = kz_client # Setup kazoo to stop when shutting down s.addService(FunctionalService(stop=partial(call_after_supervisor, kz_client.stop, supervisor))) d.addCallback(on_client_ready) d.addErrback(log.err, 'Could not start TxKazooClient') return s
def _(self, request, log, *args, **kwargs): bound_log = log.bind(**kwargs) return f(self, request, bound_log, *args, **kwargs)
def __init__(self, store): """ Initialize OtterMetrics with a data store and log. """ self.log = log.bind(system='otter.rest.metrics') self.store = store
def __init__(self, store, tenant_id): self.log = log.bind(system='otter.log.history', tenant_id=tenant_id) self.store = store self.tenant_id = tenant_id
""" Start this service by starting internal TimerService """ Service.startService(self) return self._service.startService() def stopService(self): """ Stop service by stopping the timerservice and disconnecting cass client """ Service.stopService(self) d = self._service.stopService() return d.addCallback(lambda _: self._client.disconnect()) metrics_log = otter_log.bind(system='otter.metrics') def makeService(config): """ Set up the otter-metrics service. """ from twisted.internet import reactor return MetricsService(reactor, dict(config), metrics_log) if __name__ == '__main__': config = json.load(open(sys.argv[1])) # TODO: Take _print as cmd-line arg and pass it. task.react(collect_metrics, (config, metrics_log, None, None, True))
def makeService(config): """ Set up the otter-api service. """ config = dict(config) set_config_data(config) parent = MultiService() region = config_value('region') seed_endpoints = [ clientFromString(reactor, str(host)) for host in config_value('cassandra.seed_hosts')] cassandra_cluster = LoggingCQLClient( TimingOutCQLClient( reactor, RoundRobinCassandraCluster( seed_endpoints, config_value('cassandra.keyspace'), disconnect_on_cancel=True), config_value('cassandra.timeout') or 30), log.bind(system='otter.silverberg')) store = CassScalingGroupCollection( cassandra_cluster, reactor, config_value('limits.absolute.maxGroups')) admin_store = CassAdmin(cassandra_cluster) bobby_url = config_value('bobby_url') if bobby_url is not None: set_bobby(BobbyClient(bobby_url)) service_configs = get_service_configs(config) authenticator = generate_authenticator(reactor, config['identity']) supervisor = SupervisorService(authenticator, region, coiterate, service_configs) supervisor.setServiceParent(parent) set_supervisor(supervisor) health_checker = HealthChecker(reactor, { 'store': getattr(store, 'health_check', None), 'kazoo': store.kazoo_health_check, 'supervisor': supervisor.health_check }) # Setup cassandra cluster to disconnect when otter shuts down if 'cassandra_cluster' in locals(): parent.addService(FunctionalService(stop=partial( call_after_supervisor, cassandra_cluster.disconnect, supervisor))) otter = Otter(store, region, health_checker.health_check) site = Site(otter.app.resource()) site.displayTracebacks = False api_service = service(str(config_value('port')), site) api_service.setServiceParent(parent) # Setup admin service admin_port = config_value('admin') if admin_port: admin = OtterAdmin(admin_store) admin_site = Site(admin.app.resource()) admin_site.displayTracebacks = False admin_service = service(str(admin_port), admin_site) admin_service.setServiceParent(parent) # setup cloud feed cf_conf = config.get('cloudfeeds', None) if cf_conf is not None: id_conf = deepcopy(config['identity']) id_conf['strategy'] = 'single_tenant' add_to_fanout(CloudFeedsObserver( reactor=reactor, authenticator=generate_authenticator(reactor, id_conf), tenant_id=cf_conf['tenant_id'], region=region, service_configs=service_configs)) # Setup Kazoo client if config_value('zookeeper'): threads = config_value('zookeeper.threads') or 10 disable_logs = config_value('zookeeper.no_logs') threadpool = ThreadPool(maxthreads=threads) sync_kz_client = KazooClient( hosts=config_value('zookeeper.hosts'), # Keep trying to connect until the end of time with # max interval of 10 minutes connection_retry=dict(max_tries=-1, max_delay=600), logger=None if disable_logs else TxLogger(log.bind(system='kazoo')) ) kz_client = TxKazooClient(reactor, threadpool, sync_kz_client) # Don't timeout. Keep trying to connect forever d = kz_client.start(timeout=None) def on_client_ready(_): dispatcher = get_full_dispatcher(reactor, authenticator, log, get_service_configs(config), kz_client, store, supervisor, cassandra_cluster) # Setup scheduler service after starting scheduler = setup_scheduler(parent, dispatcher, store, kz_client) health_checker.checks['scheduler'] = scheduler.health_check otter.scheduler = scheduler # Give dispatcher to Otter REST object otter.dispatcher = dispatcher # Set the client after starting # NOTE: There is small amount of time when the start is # not finished and the kz_client is not set in which case # policy execution and group delete will fail store.kz_client = kz_client # Setup kazoo to stop when shutting down parent.addService(FunctionalService( stop=partial(call_after_supervisor, kz_client.stop, supervisor))) setup_converger( parent, kz_client, dispatcher, config_value('converger.interval') or 10, config_value('converger.build_timeout') or 3600, config_value('converger.limited_retry_iterations') or 10, config_value('converger.step_limits') or {}) d.addCallback(on_client_ready) d.addErrback(log.err, 'Could not start TxKazooClient') return parent
def __init__(self, store, tenant_id): self.log = log.bind(system='otter.rest.groups', tenant_id=tenant_id) self.store = store self.tenant_id = tenant_id