Exemplo n.º 1
0
def main():
    cti_config.init_cli_config(sys.argv[1:])
    cti_config.init_config_file()
    cti_config.init_auth_config()
    xivo_dao.init_db_from_config(config)
    cti_config.update_db_config()

    user = config.get('user')
    if user:
        change_user(user)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(
        ['amqp', 'urllib3', 'Flask-Cors', 'kombu', 'stevedore.extension'],
        logging.WARNING)

    xivo_uuid = get_xivo_uuid(logger)

    register_class.setup(xivo_uuid)

    ctid = context.get('cti_server')
    ctid.setup()

    with ServiceCatalogRegistration('xivo-ctid', xivo_uuid, config['consul'],
                                    config['service_discovery'], config['bus'],
                                    partial(self_check, config)):
        ctid.run()
Exemplo n.º 2
0
    def run(self):
        self.services = plugin_manager.load_services(
            self.config,
            self.config['enabled_plugins']['services'],
            self._source_manager,
            self.bus,
            self,
        )
        plugin_manager.load_views(
            self.config,
            self.config['enabled_plugins']['views'],
            self.services,
            self.auth_client,
            self.status_aggregator,
        )
        self._source_manager.set_source_service(self.services['source'])
        self.status_aggregator.add_provider(self.bus.provide_status)

        signal.signal(signal.SIGTERM, _signal_handler)
        with self.token_renewer:
            with ServiceCatalogRegistration(
                    *self._service_registration_params):
                self.bus.start()
                try:
                    self.rest_api.run()
                finally:
                    plugin_manager.unload_views()
                    plugin_manager.unload_services()
                    self._source_manager.unload_sources()
                    self.bus.stop()
Exemplo n.º 3
0
 def run(self):
     logger.info('wazo-calld starting...')
     self.token_renewer.subscribe_to_token_change(self.token_status.token_change_callback)
     self.status_aggregator.add_provider(self.ari.provide_status)
     self.status_aggregator.add_provider(self.bus_consumer.provide_status)
     self.status_aggregator.add_provider(self.token_status.provide_status)
     collectd_thread = Thread(target=self.collectd.run, name='collectd_thread')
     collectd_thread.start()
     ari_thread = Thread(target=self.ari.run, name='ari_thread')
     ari_thread.start()
     asyncio_thread = Thread(target=self.asyncio.run, name='asyncio_thread')
     asyncio_thread.start()
     try:
         with self.token_renewer:
             with self.bus_consumer:
                 with ServiceCatalogRegistration(*self._service_registration_params):
                     self.http_server.run()
     finally:
         logger.info('wazo-calld stopping...')
         self._pubsub.publish('stopping', None)
         self.asyncio.stop()
         self.ari.stop()
         self.collectd.stop()
         logger.debug('joining asyncio thread')
         asyncio_thread.join()
         logger.debug('joining ari thread')
         ari_thread.join()
         logger.debug('joining collectd thread')
         collectd_thread.join()
         logger.debug('done joining')
Exemplo n.º 4
0
    def run(self):
        logger.info('wazo-confd running...')
        xivo_dao.init_db_from_config(self.config)
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))

        with self.token_renewer:
            with ServiceCatalogRegistration(*self._service_discovery_args):
                self.http_server.run()
Exemplo n.º 5
0
    def run(self):
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))

        with bus.publisher_thread(self._bus_publisher):
            with ServiceCatalogRegistration(*self._service_discovery_args):
                self._expired_token_remover.run()
                local_token_renewer = self._get_local_token_renewer()
                self._config['local_token_renewer'] = local_token_renewer
                self._rest_api.run()
                local_token_renewer.revoke_token()
Exemplo n.º 6
0
    def run(self):
        logger.info('wazo-chatd starting...')
        self.status_aggregator.add_provider(self.bus_consumer.provide_status)
        self.status_aggregator.add_provider(auth.provide_status)
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))

        with self.thread_manager:
            with self.token_renewer:
                with self.bus_consumer:
                    with ServiceCatalogRegistration(
                            *self._service_discovery_args):
                        self.rest_api.run()
Exemplo n.º 7
0
    def run(self):
        logger.info('wazo-setupd starting...')
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))
        self.stopper_thread.start()
        try:
            with ServiceCatalogRegistration(*self._service_discovery_args):
                self.rest_api.run()

        finally:
            logger.info('wazo-setupd stopping...')
            logger.debug('joining stopper thread')
            self.stopper.cancel()
            self.stopper_thread.join()
Exemplo n.º 8
0
    def run(self):
        logger.debug('xivo-confd running...')

        xivo_dao.init_db_from_config(self.config)

        app = setup_app(self.config)

        with ServiceCatalogRegistration('xivo-confd', self.config['uuid'],
                                        self.config['consul'],
                                        self.config['service_discovery'],
                                        self.config['bus'],
                                        partial(self_check, self.config)):
            run_server(app)
Exemplo n.º 9
0
    def run(self):
        logger.info('wazo-webhookd starting...')
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))
        bus_consumer_thread = Thread(target=self._bus_consumer.run,
                                     name='bus_consumer_thread')
        bus_consumer_thread.start()
        try:
            with ServiceCatalogRegistration(*self._service_discovery_args):
                self.rest_api.run()
        finally:
            logger.info('wazo-webhookd stopping...')
            self._bus_consumer.should_stop = True
            self._celery_process.terminate()

            logger.debug('waiting for remaining threads/subprocesses...')
            bus_consumer_thread.join()
            self._celery_process.join()
            logger.debug('all threads and subprocesses stopped.')
Exemplo n.º 10
0
def main():
    advertise_address = os.getenv('ADVERTISE_ADDR', 'auto')
    enabled = os.getenv('DISABLED', '0') == '0'
    logger.debug('advertise addr: %s', advertise_address)
    logger.debug('enabled: %s', enabled)

    config = {
        'consul': {
            'host': 'consul',
            'port': 8500,
            'token': 'the_one_ring'
        },
        'service_discovery': {
            'advertise_address': advertise_address,
            'advertise_address_interface': 'eth0',
            'advertise_port': 6262,
            'ttl_interval': 30,
            'refresh_interval': 27,
            'retry_interval': 2,
        },
        'bus': {
            'username': '******',
            'password': '******',
            'host': 'rabbitmq',
            'port': 5672,
            'exchange_name': 'xivo',
            'exchange_type': 'topic',
        },
        'uuid': UUID,
    }

    if not enabled:
        config['service_discovery']['enabled'] = False

    signal.signal(signal.SIGTERM, handler)
    with ServiceCatalogRegistration(
            'myservice',
            config['uuid'],
            config['consul'],
            config['service_discovery'],
            config['bus'],
            self_check,
    ):
        app.run(host="0.0.0.0", port=6262)
Exemplo n.º 11
0
 def run(self):
     logger.info('xivo-ctid-ng starting...')
     self.token_renewer.subscribe_to_token_change(
         self.token_status.token_change_callback)
     self.status_aggregator.add_provider(self.ari.provide_status)
     self.status_aggregator.add_provider(self.bus_consumer.provide_status)
     self.status_aggregator.add_provider(self.token_status.provide_status)
     bus_producer_thread = Thread(target=self.bus_publisher.run,
                                  name='bus_producer_thread')
     bus_producer_thread.start()
     collectd_thread = Thread(target=self.collectd.run,
                              name='collectd_thread')
     collectd_thread.start()
     bus_consumer_thread = Thread(target=self.bus_consumer.run,
                                  name='bus_consumer_thread')
     bus_consumer_thread.start()
     ari_thread = Thread(target=self.ari.run, name='ari_thread')
     ari_thread.start()
     try:
         with self.token_renewer:
             with ServiceCatalogRegistration(
                     *self._service_registration_params):
                 self.rest_api.run()
     finally:
         logger.info('xivo-ctid-ng stopping...')
         self.ari.stop()
         self.bus_consumer.should_stop = True
         self.collectd.stop()
         self.bus_publisher.stop()
         logger.debug('joining ari thread')
         ari_thread.join()
         logger.debug('joining bus consumer thread')
         bus_consumer_thread.join()
         logger.debug('joining collectd thread')
         collectd_thread.join()
         logger.debug('joining bus producer thread')
         bus_producer_thread.join()
         logger.debug('joining rest api threads')
         self.rest_api.join()
         logger.debug('done joining')
Exemplo n.º 12
0
 def run(self):
     logger.debug('starting http server')
     signal.signal(signal.SIGTERM, _signal_handler)
     publisher_thread = Thread(target=self._publisher.run)
     publisher_thread.start()
     with ServiceCatalogRegistration(
             'wazo-plugind',
             self._xivo_uuid,
             self._consul_config,
             self._service_discovery_config,
             self._bus_config,
             partial(self_check, self._listen_port),
     ):
         try:
             self._server.start()
         except (KeyboardInterrupt, SystemExit):
             logger.info('Main process stopping')
         finally:
             self._server.stop()
     self._executor.shutdown()
     self._publisher.stop()
     publisher_thread.join()
Exemplo n.º 13
0
    def run(self):
        signal.signal(signal.SIGTERM, partial(_sigterm_handler, self))

        with db_ready(
                timeout=self._config['db_connect_retry_timeout_seconds']):
            self._default_policy_service.update_policies()
            self._all_users_service.update_policies()
            self._default_policy_service.delete_orphan_policies()
            http.init_top_tenant(self.dao)
            if self._config['bootstrap_user_on_startup']:
                bootstrap.create_initial_user(
                    self._config['db_uri'],
                    self._config['bootstrap_user_username'],
                    self._config['bootstrap_user_password'],
                    self._config.get('bootstrap_user_purpose')
                    or bootstrap.PURPOSE,
                    self._config.get('bootstrap_user_policy_slug')
                    or bootstrap.DEFAULT_POLICY_SLUG,
                )

        with bus.publisher_thread(self._bus_publisher):
            with ServiceCatalogRegistration(*self._service_discovery_args):
                self._expired_token_remover.start()
                self._rest_api.run()
Exemplo n.º 14
0
def _run(config):
    _init_signal()
    xivo_uuid = config['uuid']
    agent_dao = AgentDAOAdapter(orig_agent_dao)
    queue_dao = QueueDAOAdapter(orig_queue_dao)
    exten_features_dao = ExtenFeaturesDAOAdapter(asterisk_conf_dao)
    amid_client = AmidClient(**config['amid'])
    auth_client = AuthClient(**config['auth'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(amid_client.set_token)
    token_renewer.subscribe_to_token_change(auth_client.set_token)

    bus_consumer = BusConsumer(**config['bus'])
    bus_publisher = BusPublisherWithQueue(**config['bus'], service_uuid=xivo_uuid)

    blf_manager = BLFManager(amid_client, exten_features_dao)
    queue_log_manager = QueueLogManager(queue_log_dao)

    add_to_queue_action = AddToQueueAction(amid_client, agent_status_dao)
    login_action = LoginAction(
        amid_client,
        queue_log_manager,
        blf_manager,
        agent_status_dao,
        line_dao,
        user_dao,
        agent_dao,
        bus_publisher,
    )
    pause_action = PauseAction(amid_client)
    pause_manager = PauseManager(pause_action, agent_dao)
    logoff_action = LogoffAction(
        amid_client,
        queue_log_manager,
        blf_manager,
        pause_manager,
        agent_status_dao,
        user_dao,
        agent_dao,
        bus_publisher,
    )
    remove_from_queue_action = RemoveFromQueueAction(amid_client, agent_status_dao)
    update_penalty_action = UpdatePenaltyAction(amid_client, agent_status_dao)

    add_member_manager = AddMemberManager(
        add_to_queue_action, amid_client, agent_status_dao, queue_member_dao
    )
    login_manager = LoginManager(login_action, agent_status_dao, context_dao, line_dao)
    logoff_manager = LogoffManager(logoff_action, agent_dao, 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, agent_dao, bus_publisher
    )
    relog_manager = RelogManager(
        login_action, logoff_action, agent_dao, agent_status_dao
    )
    remove_member_manager = RemoveMemberManager(
        remove_from_queue_action, amid_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)

    _init_bus_consume(bus_consumer, service_proxy)

    http_iface = http.HTTPInterface(config, service_proxy, auth_client)

    service_discovery_args = [
        'wazo-agentd',
        xivo_uuid,
        config['consul'],
        config['service_discovery'],
        config['bus'],
        partial(self_check, config['rest_api']),
    ]
    try:
        with token_renewer:
            with bus_consumer, bus_publisher:
                with ServiceCatalogRegistration(*service_discovery_args):
                    http_iface.run()
    finally:
        logger.info('wazo-agentd stopping...')
Exemplo n.º 15
0
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()