def __init__(self, amid_client, ari_client, services, state_factory, state_persistor, xivo_uuid): self.ari = ari_client self.amid = amid_client self.services = services self.xivo_uuid = xivo_uuid self.stasis_start_pubsub = Pubsub() self.stasis_start_pubsub.set_exception_handler(self.invalid_event) self.hangup_pubsub = Pubsub() self.hangup_pubsub.set_exception_handler(self.invalid_event) self.state_factory = state_factory self.state_persistor = state_persistor
def __init__(self, global_config): self._events_pubsub = Pubsub() self._userevent_pubsub = Pubsub() self._events_pubsub.subscribe( 'UserEvent', lambda message: self._userevent_pubsub.publish( message['UserEvent'], message)) self._bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( **global_config['bus']) exchange = Exchange(global_config['bus']['exchange_name'], type=global_config['bus']['exchange_type']) self._queue = kombu.Queue(exchange=exchange, routing_key=self._KEY, exclusive=True)
def __init__(self, bus_config): self._bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( **bus_config) self._exchange = kombu.Exchange(bus_config['subscribe_exchange_name'], type='headers') self._queue = kombu.Queue(exclusive=True) self._pubsub = Pubsub()
def __init__(self, config): self._apps = [] self.config = config self._is_running = False self._should_delay_reconnect = True self._should_stop = False self._pubsub = Pubsub() self.client = ARIClientProxy(**config['connection'])
def __init__(self, global_config): self._events_pubsub = Pubsub() self._bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( **global_config['bus']) self._exchange = Exchange(global_config['bus']['exchange_name'], type=global_config['bus']['exchange_type']) self._queue = kombu.Queue(exclusive=True) self._is_running = False
def __init__(self, state_factory): self.uuid = str(uuid.uuid4()) self._state_factory = state_factory self.relocated_channel = None self.initiator_channel = None self.recipient_channel = None self.initiator = None self.completions = None self.set_state('ready') self._lock = threading.Lock() self.events = Pubsub()
def __init__(self, global_config): self._all_events_pubsub = Pubsub() self._is_running = False self.connection = None self._bus_url = 'amqp://{username}:{password}@{host}:{port}//'.format( **global_config['bus']) self._upstream_exchange = kombu.Exchange( global_config['bus']['exchange_name'], type=global_config['bus']['exchange_type']) self._exchange = kombu.Exchange( global_config['bus']['exchange_headers_name'], type='headers') self._consumers = {} self._new_consumers = deque() self._stale_consumers = deque() self._updated_consumers = deque()
def set_wazo_instance(context, instance_name, instance_config, debug_config): logger.info("Adding instance %s...", instance_name) context.token_pubsub = Pubsub() setup.setup_config(context, instance_config) logger.info('wazo_host: %s', context.wazo_config['wazo_host']) logger.debug("setup ssh client...") setup.setup_ssh_client(context) logger.debug("setup auth token...") setup.setup_auth_token(context) logger.debug("setup agentd client...") setup.setup_agentd_client(context) logger.debug("setup amid client...") setup.setup_amid_client(context) logger.debug("setup ari client...") setup.setup_ari_client(context) logger.debug("setup call logd client...") setup.setup_call_logd_client(context) logger.debug("setup calld client...") setup.setup_calld_client(context) logger.debug("setup chatd client...") setup.setup_chatd_client(context) logger.debug("setup confd client...") setup.setup_confd_client(context) logger.debug("setup dird client...") setup.setup_dird_client(context) logger.debug("setup provd client...") setup.setup_provd_client(context) logger.debug("setup setupd client...") setup.setup_setupd_client(context) logger.debug("setup websocketd client...") setup.setup_websocketd_client(context) logger.debug("setup tenant...") setup.setup_tenant(context) logger.debug("setup consul...") setup.setup_consul(context) logger.debug("setup remote sysutils...") setup.setup_remote_sysutils(context) logger.debug("setup helpers...") setup.setup_helpers(context) logger.debug("setup phone...") setup.setup_phone(context, debug_config['linphone'])
def setUp(self): self.pubsub = Pubsub()
def __init__(self): self.token_pubsub = Pubsub()
def __init__(self, config): engine = create_engine(config['db_uri']) self._Session = scoped_session(sessionmaker()) self._Session.configure(bind=engine) self.pubsub = Pubsub()
class SubscriptionService: # NOTE(sileht): We share the pubsub object, so plugin that instanciate # another service (like push mobile) will continue work. pubsub = Pubsub() def __init__(self, config): self._engine = create_engine(config['db_uri']) self._Session = scoped_session(sessionmaker()) self._Session.configure(bind=self._engine) def close(self): self._Session.close() self._engine.dispose() @contextmanager def rw_session(self): session = self._Session() try: yield session session.commit() except BaseException: session.rollback() raise finally: self._Session.remove() @contextmanager def ro_session(self): session = self._Session() try: yield session finally: self._Session.remove() def list(self, owner_tenant_uuids=None, owner_user_uuid=None, search_metadata=None): with self.ro_session() as session: query = session.query(Subscription) if owner_tenant_uuids: query = query.filter( Subscription.owner_tenant_uuid.in_(owner_tenant_uuids)) if owner_user_uuid: query = query.filter( Subscription.owner_user_uuid == owner_user_uuid) if search_metadata: subquery = (session.query( SubscriptionMetadatum.subscription_uuid).filter( or_(*[ and_( SubscriptionMetadatum.key == key, SubscriptionMetadatum.value == value, ) for key, value in search_metadata.items() ])).group_by( SubscriptionMetadatum.subscription_uuid).having( func.count(distinct(SubscriptionMetadatum.key)) == len(search_metadata))) query = query.filter(Subscription.uuid.in_(subquery)) return query.all() def _get(self, session, subscription_uuid, owner_tenant_uuids=None, owner_user_uuid=None): query = session.query(Subscription) query = query.filter(Subscription.uuid == subscription_uuid) if owner_tenant_uuids: query = query.filter( Subscription.owner_tenant_uuid.in_(owner_tenant_uuids)) if owner_user_uuid: query = query.filter( Subscription.owner_user_uuid == owner_user_uuid) result = query.one_or_none() if result is None: raise NoSuchSubscription(subscription_uuid) return result def get(self, subscription_uuid, owner_tenant_uuids=None, owner_user_uuid=None): with self.ro_session() as session: return self._get(session, subscription_uuid, owner_tenant_uuids, owner_user_uuid) def create(self, new_subscription): with self.rw_session() as session: subscription = Subscription() subscription.from_schema(**new_subscription) subscription = session.merge(subscription) session.flush() session.expire_all() subscription.make_transient() self.pubsub.publish('created', subscription) return subscription def update( self, subscription_uuid, new_subscription, owner_tenant_uuids=None, owner_user_uuid=None, ): with self.rw_session() as session: subscription = self._get(session, subscription_uuid, owner_tenant_uuids, owner_user_uuid) subscription.clear_relations() session.flush() subscription.from_schema(**new_subscription) session.flush() session.expire_all() subscription.make_transient() self.pubsub.publish('updated', subscription) return subscription def delete(self, subscription_uuid, owner_tenant_uuids=None, owner_user_uuid=None): with self.rw_session() as session: subscription = self._get(session, subscription_uuid, owner_tenant_uuids, owner_user_uuid) session.delete(subscription) self.pubsub.publish('deleted', subscription) def get_logs( self, subscription_uuid, from_date=None, limit=None, offset=None, order='started_at', direction='desc', search=None, ): with self.ro_session() as session: query = session.query(SubscriptionLog).filter( SubscriptionLog.subscription_uuid == subscription_uuid) if from_date is not None: query = query.filter(SubscriptionLog.started_at >= from_date) order_column = getattr(SubscriptionLog, order) order_column = (order_column.asc() if direction == 'asc' else order_column.desc()) query = query.order_by(order_column) if limit is not None: query = query.limit(limit) if offset is not None: query = query.offset(offset) if search is not None: # TODO(sileht): search is not implemented yet logger.warning("search parameter have been used while " "not implemented") pass return query.all() def create_hook_log( self, uuid, subscription_uuid, status, attempts, max_attempts, started_at, ended_at, event, detail, ): with self.rw_session() as session: hooklog = SubscriptionLog( uuid=uuid, subscription_uuid=subscription_uuid, status=status, attempts=attempts, max_attempts=max_attempts, started_at=started_at, ended_at=ended_at, event=event, detail=detail, ) session.add(hooklog) try: session.commit() except exc.IntegrityError as e: if "violates foreign key constraint" in str(e): logger.warning( "subscription %s have been deleted in the meantime", subscription_uuid, ) session.rollback() else: raise