__user = panda_config.dbuser __passwd = panda_config.dbpasswd __dbname = panda_config.dbname #Instantiate logger _logger = PandaLogger().getLogger('configurator_dbif') #Log the SQL produced by SQLAlchemy __echo = True #Create the SQLAlchemy engine try: __engine = sqlalchemy.create_engine("oracle://%s:%s@%s"%(__user, __passwd, __host), echo=__echo) except exc.SQLAlchemyError: _logger.critical("Could not load the DB engine: %s"%sys.exc_info()) raise def get_session(): return sessionmaker(bind=__engine)() def db_interaction(method): """ NOTE: THIS FUNCTION IS A REMAINDER FROM PREVIOUS DEVELOPMENT AND IS NOT CURRENTLY USED, BUT SHOULD BE ADAPTED TO REMOVE THE BOILERPLATE CODE IN ALL FUNCTIONS BELOW Decorator to wrap a function with the necessary session handling. FIXME: Getting a session has a 50ms overhead. See if there are better ways. FIXME: Note that this method inserts the session as the first parameter of the function. There might be more elegant solutions to do this.
__user = panda_config.dbuser __passwd = panda_config.dbpasswd __dbname = panda_config.dbname #Instantiate logger _logger = PandaLogger().getLogger('configurator_dbif') #Log the SQL produced by SQLAlchemy __echo = False #Create the SQLAlchemy engine try: __engine = sqlalchemy.create_engine("oracle://%s:%s@%s"%(__user, __passwd, __host), echo=__echo) except exc.SQLAlchemyError: _logger.critical("Could not load the DB engine: %s"%sys.exc_info()) raise def get_session(): return sessionmaker(bind=__engine)() # TODO: The performance of all write methods could significantly be improved by writing in bulks. # The current implementation was the fastest way to get it done with the merge method and avoiding # issues with duplicate keys def write_sites_db(session, sites_list): """ Cache the AGIS site information in the PanDA database """ try: _logger.debug("Starting write_sites_db")
# Insert the new data taskBuffer.insertNetworkMatrixData(data_combined) # Do some cleanup of old data taskBuffer.deleteOldNetworkData() return True else: return False if __name__ == "__main__": # If no argument, call the basic configurator if len(sys.argv) == 1: t1 = time.time() configurator = Configurator() if not configurator.run(): _logger.critical("Configurator loop FAILED") t2 = time.time() _logger.debug("Configurator run took {0}s".format(t2-t1)) # If --network argument, call the network configurator elif len(sys.argv) == 2 and sys.argv[1].lower() == '--network': t1 = time.time() network_configurator = NetworkConfigurator() if not network_configurator.run(): _logger.critical("Configurator loop FAILED") t2 = time.time() _logger.debug(" run took {0}s".format(t2-t1)) else: _logger.error("Configurator being called with wrong arguments. Use either no arguments or --network")
# Insert the new data taskBuffer.insertNetworkMatrixData(data_combined) # Do some cleanup of old data taskBuffer.deleteOldNetworkData() return True else: return False if __name__ == "__main__": # If no argument, call the basic configurator if len(sys.argv)==1: t1 = time.time() configurator = Configurator() if not configurator.run(): _logger.critical("Configurator loop FAILED") t2 = time.time() _logger.debug("Configurator run took {0}s".format(t2-t1)) # If --network argument, call the network configurator elif len(sys.argv) == 2 and sys.argv[1].lower() == '--network': t1 = time.time() network_configurator = NetworkConfigurator() if not network_configurator.run(): _logger.critical("Configurator loop FAILED") t2 = time.time() _logger.debug(" run took {0}s".format(t2-t1)) else: _logger.error("Configurator being called with wrong arguments. Use either no arguments or --network")