def setUp(self): super().setUp() self.tenant_uuid = SUB_TENANT self.tenant_name = 'mytenant' bus_port = self.service_port(5672, 'rabbitmq') bus = BusClient.from_connection_fields(host='localhost', port=bus_port) until.true(bus.is_up, timeout=5) bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( username='******', password='******', host='localhost', port=bus_port) connection = kombu.Connection(bus_url) connection.connect() marshaler = Marshaler('the-xivo-uuid') exchange = kombu.Exchange('xivo', type='topic') producer = kombu.Producer(connection, exchange=exchange, auto_declare=True) self.publisher = Publisher(producer, marshaler) self.mock_auth_client = MockAuthClient('localhost', self.service_port(9497, 'auth')) def wait_for_dird_bus_connection(): response = self.client.status.get() assert_that(response, has_entries(bus_consumer={'status': 'ok'})) until.assert_(wait_for_dird_bus_connection, timeout=6)
def __init__(self, name, uuid, consul_config, service_discovery_config, bus_config): super(NotifyingRegisterer, self).__init__(name, uuid, consul_config, service_discovery_config) self._bus_config = bus_config self._marshaler = Marshaler(uuid) try: self._bus_url = bus_config.get('uri') or self.bus_uri_pattern.format(**bus_config) except KeyError as e: raise MissingConfigurationError(str(e))
def _make_publisher(self): bus_url = self.config['uri'] bus_connection = Connection(bus_url) bus_exchange = Exchange(self.config['exchange_name'], type=self.config['exchange_type']) bus_producer = Producer(bus_connection, exchange=bus_exchange, auto_declare=True) bus_marshaler = Marshaler(self._uuid) return LongLivedPublisher(bus_producer, bus_marshaler)
def _make_publisher(self): bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( **self.config) bus_connection = Connection(bus_url) bus_exchange = Exchange(self.config['exchange_name'], type=self.config['exchange_type']) bus_producer = Producer(bus_connection, exchange=bus_exchange, auto_declare=True) bus_marshaler = Marshaler(self._uuid) return Publisher(bus_producer, bus_marshaler)
def _new_publisher(self, config): bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format(**config['bus']) bus_connection = Connection(bus_url) bus_exchange = Exchange( config['bus']['exchange_name'], type=config['bus']['exchange_type'] ) bus_producer = Producer( bus_connection, exchange=bus_exchange, auto_declare=True ) bus_marshaler = Marshaler(config['uuid']) return LongLivedPublisher(bus_producer, bus_marshaler)
def from_config(cls, bus_config, wazo_uuid): bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( **bus_config) bus_connection = kombu.Connection(bus_url) bus_exchange = kombu.Exchange(bus_config['exchange_name'], type=bus_config['exchange_type']) bus_producer = kombu.Producer(bus_connection, exchange=bus_exchange, auto_declare=True) bus_marshaler = Marshaler(wazo_uuid) bus_publisher = FailFastPublisher(bus_producer, bus_marshaler) return cls(bus_publisher)
def __init__(self, global_config): bus_config = global_config['bus'] self._enabled = bus_config['enabled'] if self._enabled: self._bus_url = self._bus_url_tpl.format(**bus_config) self._marshaler = Marshaler(global_config.get('uuid')) self._exchange_name = bus_config['exchange_name'] self._exchange_type = bus_config['exchange_type'] self._bus_thread = threading.Thread(target=self._start_consuming) self._queues_and_callbacks = [] self._consumer = None self._publisher = None
def _publish_user_deleted_event(self, uuid): event = DeleteUserEvent(42, uuid) marshaler = Marshaler('the-xivo-uuid') message = { 'data': event.marshal(), **marshaler.metadata(event), } self.bus.publish( message, headers={'name': DeleteUserEvent.name}, routing_key=event.routing_key, )
def flush(self): exchange = Exchange(self.exchange_name, self.exchange_type) marshaler = Marshaler(self.uuid) with Connection(self.url) as connection: producer = Producer(connection, exchange=exchange, auto_declare=True) publish = connection.ensure(producer, producer.publish, errback=self.publish_error, max_retries=3, interval_start=1) self.send_messages(marshaler, publish)
def _run(config): _init_signal() xivo_uuid = config['uuid'] agent_dao = AgentDAOAdapter(orig_agent_dao) queue_dao = QueueDAOAdapter(orig_queue_dao) auth_client = AuthClient(**config['auth']) token_renewer = TokenRenewer(auth_client) token_renewer.subscribe_to_token_change(auth_client.set_token) with _new_ami_client(config) as ami_client: with _new_bus_connection(config) as producer_conn, _new_bus_connection( config) as consumer_conn: bus_exchange = Exchange(config['bus']['exchange_name'], type=config['bus']['exchange_type']) bus_producer = Producer(producer_conn, exchange=bus_exchange, auto_declare=True) bus_marshaler = Marshaler(xivo_uuid) bus_publisher = Publisher(bus_producer, bus_marshaler) queue_log_manager = QueueLogManager(queue_log_dao) add_to_queue_action = AddToQueueAction(ami_client, agent_status_dao) login_action = LoginAction(ami_client, queue_log_manager, agent_status_dao, line_dao, user_dao, bus_publisher) logoff_action = LogoffAction(ami_client, queue_log_manager, agent_status_dao, user_dao, bus_publisher) pause_action = PauseAction(ami_client) remove_from_queue_action = RemoveFromQueueAction( ami_client, agent_status_dao) update_penalty_action = UpdatePenaltyAction( ami_client, agent_status_dao) add_member_manager = AddMemberManager(add_to_queue_action, ami_client, agent_status_dao, queue_member_dao) login_manager = LoginManager(login_action, agent_status_dao, context_dao) logoff_manager = LogoffManager(logoff_action, agent_status_dao) on_agent_deleted_manager = OnAgentDeletedManager( logoff_manager, agent_status_dao) on_agent_updated_manager = OnAgentUpdatedManager( add_to_queue_action, remove_from_queue_action, update_penalty_action, agent_status_dao) on_queue_added_manager = OnQueueAddedManager( add_to_queue_action, agent_status_dao) on_queue_deleted_manager = OnQueueDeletedManager(agent_status_dao) on_queue_updated_manager = OnQueueUpdatedManager( add_to_queue_action, remove_from_queue_action, agent_status_dao) on_queue_agent_paused_manager = OnQueueAgentPausedManager( agent_status_dao, user_dao, bus_publisher) pause_manager = PauseManager(pause_action) relog_manager = RelogManager(login_action, logoff_action, agent_dao, agent_status_dao) remove_member_manager = RemoveMemberManager( remove_from_queue_action, ami_client, agent_status_dao, queue_member_dao) service_proxy = ServiceProxy() service_proxy.login_handler = LoginHandler(login_manager, agent_dao) service_proxy.logoff_handler = LogoffHandler( logoff_manager, agent_status_dao) service_proxy.membership_handler = MembershipHandler( add_member_manager, remove_member_manager, agent_dao, queue_dao) service_proxy.on_agent_handler = OnAgentHandler( on_agent_deleted_manager, on_agent_updated_manager, agent_dao) service_proxy.on_queue_handler = OnQueueHandler( on_queue_added_manager, on_queue_updated_manager, on_queue_deleted_manager, on_queue_agent_paused_manager, queue_dao, agent_dao) service_proxy.pause_handler = PauseHandler(pause_manager, agent_status_dao) service_proxy.relog_handler = RelogHandler(relog_manager) service_proxy.status_handler = StatusHandler( agent_dao, agent_status_dao, xivo_uuid) amqp_iface = amqp.AMQPInterface(consumer_conn, bus_exchange, service_proxy) http_iface = http.HTTPInterface(config, service_proxy, auth_client) amqp_iface.start() try: with token_renewer: with ServiceCatalogRegistration( 'xivo-agentd', xivo_uuid, config['consul'], config['service_discovery'], config['bus'], partial(self_check, config['rest_api']['https']['port'])): http_iface.run() finally: amqp_iface.stop()
def setup(xivo_uuid): auth_client = new_auth_client() bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format(**config['bus']) bus_connection = Connection(bus_url) bus_exchange = Exchange(config['bus']['exchange_name'], type=config['bus']['exchange_type']) bus_producer = Producer(bus_connection, exchange=bus_exchange, auto_declare=True) bus_marshaler = Marshaler(xivo_uuid) bus_publisher = Publisher(bus_producer, bus_marshaler) bus_listener = BusListener(bus_connection, bus_exchange) same_exchange_arguments_as_collectd = {'arguments': {'auto_delete': True}, 'durable': False} collectd_exchange = Exchange('collectd', type=config['bus']['exchange_type'], **same_exchange_arguments_as_collectd) collectd_producer = Producer(bus_connection, exchange=collectd_exchange, auto_declare=True) collectd_marshaler = CollectdMarshaler(xivo_uuid) collectd_publisher = Publisher(collectd_producer, collectd_marshaler) remote_service_tracker = RemoteServiceTracker(config['consul'], xivo_uuid, config['rest_api']['http']['port']) thread_pool_executor = futures.ThreadPoolExecutor(max_workers=10) context.register('ami_18', AMI_1_8) context.register('ami_callback_handler', AMICallbackHandler.get_instance()) context.register('ami_class', AMIClass) context.register('agent_availability_computer', AgentAvailabilityComputer) context.register('agent_availability_notifier', AgentAvailabilityNotifier) context.register('agent_availability_updater', AgentAvailabilityUpdater) context.register('agent_executor', AgentExecutor) context.register('agent_service_cti_parser', AgentServiceCTIParser) context.register('agent_service_manager', AgentServiceManager) context.register('agent_status_adapter', AgentStatusAdapter) context.register('agent_status_manager', AgentStatusManager) context.register('agent_status_parser', AgentStatusParser) context.register('agent_status_router', AgentStatusRouter) context.register('async_runner', AsyncRunner) context.register('agentd_client', AgentdClient(**config['agentd'])) context.register('bridge_manager', BridgeManager) context.register('bridge_updater', BridgeUpdater) context.register('bridge_notifier', BridgeNotifier) context.register('bus_connection', bus_connection) context.register('bus_exchange', lambda: bus_exchange) context.register('bus_listener', bus_listener) context.register('bus_publisher', bus_publisher) context.register('broadcast_cti_group', new_broadcast_cti_group) context.register('cache_updater', CacheUpdater) context.register('call_form_dispatch_filter', DispatchFilter) context.register('call_form_result_handler', CallFormResultHandler) context.register('call_form_variable_aggregator', VariableAggregator) context.register('call_pickup_tracker', CallPickupTracker) context.register('call_notifier', CallNotifier) context.register('call_receiver', CallReceiver) context.register('call_storage', CallStorage) context.register('call_manager', CallManager) context.register('chat_publisher', ChatPublisher) context.register('channel_updater', ChannelUpdater) context.register('collectd_publisher', collectd_publisher) context.register('confd_client', ConfdClient(**config['confd'])) context.register('cti_group_factory', CTIGroupFactory) context.register('cti_msg_codec', CTIMessageCodec) context.register('cti_provd_client', CTIProvdClient.new_from_config(config['provd'])) context.register('cti_server', CTIServer) context.register('current_call_formatter', CurrentCallFormatter) context.register('current_call_manager', CurrentCallManager) context.register('current_call_notifier', CurrentCallNotifier) context.register('current_call_parser', CurrentCallParser) context.register('delta_computer', DeltaComputer) context.register('device_manager', DeviceManager) context.register('endpoint_status_notifier', EndpointStatusNotifier) context.register('endpoint_status_updater', EndpointStatusUpdater) context.register('endpoint_notifier', EndpointNotifier) context.register('flusher', Flusher) context.register('funckey_manager', FunckeyManager) context.register('innerdata', Safe) context.register('interface_ami', AMI) context.register('main_thread_proxy', MainThreadProxy) context.register('meetme_service_manager', MeetmeServiceManager) context.register('meetme_service_notifier', MeetmeServiceNotifier) context.register('people_cti_adapter', PeopleCTIAdapter) context.register('old_protocol_cti_adapter', OldProtocolCTIAdapter) context.register('presence_service_executor', PresenceServiceExecutor) context.register('presence_service_manager', PresenceServiceManager) context.register('pubsub', Pubsub) context.register('queue_entry_encoder', QueueEntryEncoder) context.register('queue_entry_manager', QueueEntryManager) context.register('queue_entry_notifier', QueueEntryNotifier) context.register('queue_statistics_manager', QueueStatisticsManager) context.register('queue_statistics_producer', QueueStatisticsProducer) context.register('queue_member_cti_subscriber', QueueMemberCTISubscriber) context.register('queue_member_cti_adapter', QueueMemberCTIAdapter) context.register('queue_member_indexer', QueueMemberIndexer) context.register('queue_member_manager', QueueMemberManager) context.register('queue_member_notifier', QueueMemberNotifier) context.register('queue_member_updater', QueueMemberUpdater) context.register('remote_service_tracker', remote_service_tracker) context.register('statistics_notifier', StatisticsNotifier) context.register('statistics_producer_initializer', StatisticsProducerInitializer) context.register('status_forwarder', StatusForwarder) context.register('task_queue', new_task_queue) context.register('task_scheduler', new_task_scheduler) context.register('token_renewer', TokenRenewer(auth_client)) context.register('thread_pool_executor', thread_pool_executor) context.register('user_service_manager', UserServiceManager) context.register('user_service_notifier', UserServiceNotifier) context.register('xivo_uuid', lambda: xivo_uuid)