def start_notification_service(port: int = 50052, db_conn: str = None, enable_ha: bool = False, server_uris: str = None, create_table_if_not_exists: bool = True): if db_conn: storage = DbEventStorage(db_conn, create_table_if_not_exists) else: raise Exception( 'Failed to start notification service without database connection info.' ) if enable_ha: if not server_uris: raise Exception("When HA enabled, server_uris must be set.") ha_storage = DbHighAvailabilityStorage(db_conn=db_conn) ha_manager = SimpleNotificationServerHaManager() service = HighAvailableNotificationService(storage, ha_manager, server_uris, ha_storage, 5000) master = NotificationMaster(service=service, port=int(port)) else: master = NotificationMaster(service=NotificationService(storage), port=port) master.run(is_block=True)
def set_up_class(cls): cls.storage = DbEventStorage() cls.master1 = start_ha_master("localhost", 50051) # The server startup is asynchronous, we need to wait for a while # to ensure it writes its metadata to the db. time.sleep(0.1) cls.master2 = start_ha_master("localhost", 50052) time.sleep(0.1) cls.master3 = start_ha_master("localhost", 50053) time.sleep(0.1)
def start_ha_master(host, port): server_uri = host + ":" + str(port) storage = DbEventStorage() ha_manager = SimpleNotificationServerHaManager() ha_storage = DbHighAvailabilityStorage() service = HighAvailableNotificationService(storage, ha_manager, server_uri, ha_storage) master = NotificationMaster(service, port=port) master.run() return master
def __init__(self, backend_store_uri): db_engine = extract_db_engine_from_uri(backend_store_uri) if DBType.value_of(db_engine) == DBType.MONGODB: username, password, host, port, db = parse_mongo_uri( backend_store_uri) super().__init__(storage=MongoEventStorage(host=host, port=int(port), username=username, password=password, db=db)) else: super().__init__(storage=DbEventStorage(backend_store_uri))
def start_master(cls, host, port): port = str(port) server_uri = host + ":" + port storage = DbEventStorage() ha_manager = SimpleNotificationServerHaManager() ha_storage = DbHighAvailabilityStorage(db_conn=_SQLITE_DB_URI) service = HighAvailableNotificationService(storage, ha_manager, server_uri, ha_storage, 5000) master = NotificationMaster(service, port=int(port)) master.run() return master
def from_storage_uri(cls, storage_uri: str) -> 'NotificationService': """ Construct the notification service with the given storage uri :param storage_uri: uri of the backend storage to use :type storage_uri: str :rtype: NotificationService """ db_engine = extract_db_engine_from_uri(storage_uri) if DBType.value_of(db_engine) == DBType.MONGODB: username, password, host, port, db = parse_mongo_uri(storage_uri) storage = MongoEventStorage(host=host, port=int(port), username=username, password=password, db=db) return cls(storage=storage) else: return cls(storage=DbEventStorage(storage_uri))
def set_up_class(cls): cls.storage = DbEventStorage() cls.master = NotificationMaster(NotificationService(cls.storage)) cls.master.run()
def tearDown(self) -> None: store = _get_store(_SQLITE_DB_URI) base.metadata.drop_all(store.db_engine) storage = DbEventStorage(db_conn=_SQLITE_DB_URI, create_table_if_not_exists=False) storage.clean_up()
def setUpClass(cls): cls.storage = DbEventStorage() cls.master1 = None cls.master2 = None cls.master3 = None