def __init__(self): """Constructor for MySQLPersister. """ self.__cnx = None self.__check_connection = True assert (self.connection_info is not None) try: self.__cnx = connect_to_mysql(autocommit=True, database=self.database, **self.connection_info) if not self.has_privileges(required_privileges(), ".".join( [self.database, "*"])): _LOGGER.critical( "Current user doesn't have privileges for backing store enough." ) raise Exception("User: %s doesn't have enough (%s) privileges on %s.*" % \ (self.connection_info["user"], ", ".join(required_privileges()), self.database)) except _errors.DatabaseError: pass if self.uuid is None and self.__cnx is not None: _LOGGER.warning( "Backing store does not support UUID (or not configured " "with UUID).") if not (self.event_scheduler and self.__cnx is not None): _LOGGER.warning( "Backing store's event_scheduler is disabled. " "MySQL Fabric uses event_scheduler for deleting log-table.")
def teardown(cls): """Tear down the object persistance system. This should only be called if the persistance database should be removed from the persistance server since it will delete all object tables. """ assert (cls.connection_info is not None) conn = connect_to_mysql(autocommit=True, **cls.connection_info) exec_mysql_stmt(conn, "DROP DATABASE IF EXISTS %s" % (cls.database, ))
def setup(cls): """Setup the object persistance system. Perform initialization, which in this case means creating the database if it does not exist. """ assert (cls.connection_info is not None) conn = connect_to_mysql(autocommit=True, **cls.connection_info) exec_mysql_stmt( conn, "CREATE DATABASE %s DEFAULT CHARSET=utf8" % (cls.database, ))
def setup(cls): """Setup the object persistance system. Perform initialization, which in this case means creating the database if it does not exist. """ assert (cls.connection_info is not None) conn = connect_to_mysql( autocommit=True, **cls.connection_info ) exec_mysql_stmt( conn, "CREATE DATABASE %s DEFAULT CHARSET=utf8" % (cls.database, ) )
def teardown(cls): """Tear down the object persistance system. This should only be called if the persistance database should be removed from the persistance server since it will delete all object tables. """ assert (cls.connection_info is not None) conn = connect_to_mysql( autocommit=True, **cls.connection_info ) exec_mysql_stmt( conn, "DROP DATABASE IF EXISTS %s" % (cls.database, ) )
def __init__(self): """Constructor for MySQLPersister. """ self.__cnx = None self.__check_connection = True assert (self.connection_info is not None) try: self.__cnx = connect_to_mysql(autocommit=True, database=self.database, **self.connection_info) except _errors.DatabaseError: pass if self.uuid is None and self.__cnx is not None: _LOGGER.warning( "Backing store does not support UUID (or not configured " "with UUID).")
def _try_to_fix_connection(self): """Try to get a new connection if the current one is stale. """ for attempt in range(0, self.connection_attempts): try: if self.__cnx: reestablish_mysql_connection(self.__cnx, attempt=1, delay=0) else: self.__cnx = connect_to_mysql(autocommit=True, database=self.database, **self.connection_info) return except _errors.DatabaseError as error: _LOGGER.debug( "Error accessing backing store (%s). Attempt (%s).", error, attempt) time.sleep(self.connection_delay)
def __init__(self): """Constructor for MySQLPersister. """ self.__cnx = None self.__check_connection = True assert (self.connection_info is not None) try: self.__cnx = connect_to_mysql( autocommit=True, database=self.database, **self.connection_info ) except _errors.DatabaseError: pass if self.uuid is None and self.__cnx is not None: _LOGGER.warning( "Backing store does not support UUID (or not configured " "with UUID)." )
def _try_to_fix_connection(self): """Try to get a new connection if the current one is stale. """ for attempt in range(0, self.connection_attempts): try: if self.__cnx: reestablish_mysql_connection( self.__cnx, attempt=1, delay=0 ) else: self.__cnx = connect_to_mysql( autocommit=True, database=self.database, **self.connection_info ) return except _errors.DatabaseError as error: _LOGGER.debug( "Error accessing backing store (%s). Attempt (%s).", error, attempt ) time.sleep(self.connection_delay)
def __init__(self): """Constructor for MySQLPersister. """ self.__cnx = None self.__check_connection = True assert (self.connection_info is not None) try: self.__cnx = connect_to_mysql( autocommit=True, database=self.database, **self.connection_info ) if not self.has_privileges(required_privileges(), ".".join([self.database, "*"])): _LOGGER.critical( "Current user doesn't have privileges for backing store enough." ) raise Exception("User: %s doesn't have enough (%s) privileges on %s.*" % \ (self.connection_info["user"], ", ".join(required_privileges()), self.database)) except _errors.DatabaseError: pass if self.uuid is None and self.__cnx is not None: _LOGGER.warning( "Backing store does not support UUID (or not configured " "with UUID)." ) if not (self.event_scheduler and self.__cnx is not None): _LOGGER.warning( "Backing store's event_scheduler is disabled. " "MySQL Fabric uses event_scheduler for deleting log-table." )