def __init__( self, dbname, fullname, debug = False ): self.fullname = fullname database_name = dbname self.log = gLogger.getSubLogger( database_name ) result = getDBParameters( fullname ) if not result['OK'] : raise RuntimeError( 'Cannot get database parameters: %s' % result['Message'] ) dbParameters = result[ 'Value' ] self.dbHost = dbParameters[ 'Host' ] self.dbPort = dbParameters[ 'Port' ] self.dbUser = dbParameters[ 'User' ] self.dbPass = dbParameters[ 'Password' ] self.dbName = dbParameters[ 'DBName' ] MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, self.dbPort, debug = debug ) if not self._connected: raise RuntimeError( 'Can not connect to DB %s, exiting...' % self.dbName ) self.log.info( "==================================================" ) #self.log.info("SystemInstance: "+self.system) self.log.info( "User: "******"Host: " + self.dbHost ) self.log.info( "Port: " + str( self.dbPort ) ) #self.log.info("Password: "******"DBName: " + self.dbName ) self.log.info( "==================================================" )
def __init__(self, *args, **kwargs): """Constructor.""" if len(args) == 1: if isinstance(args[0], str): maxQueueSize = 10 if isinstance(args[0], int): maxQueueSize = args[0] elif len(args) == 2: maxQueueSize = args[1] elif len(args) == 0: maxQueueSize = 10 if 'DBin' in kwargs.keys(): dbIn = kwargs['DBin'] if isinstance(dbIn, list): from DIRAC.Core.Utilities.MySQL import MySQL self.db = MySQL('localhost', dbIn[0], dbIn[1], 'ResourceManagementDB') else: self.db = dbIn else: from DIRAC.Core.Base.DB import DB self.db = DB('ResourceManagementDB', 'ResourceStatus/ResourceManagementDB', maxQueueSize) self.mm = MySQLMonkey(self)
def __init__(self, *args, **kwargs): if len(args) == 1: if isinstance(args[0], str): # systemInstance=args[0] maxQueueSize = 10 if isinstance(args[0], int): maxQueueSize = args[0] # systemInstance='Default' elif len(args) == 2: # systemInstance=args[0] maxQueueSize = args[1] elif len(args) == 0: # systemInstance='Default' maxQueueSize = 10 if 'DBin' in kwargs.keys(): DBin = kwargs['DBin'] if isinstance(DBin, list): from DIRAC.Core.Utilities.MySQL import MySQL self.db = MySQL('localhost', DBin[0], DBin[1], 'ResourceManagementDB') else: self.db = DBin else: from DIRAC.Core.Base.DB import DB self.db = DB('ResourceManagementDB', 'ResourceStatus/ResourceManagementDB', maxQueueSize)
def __init__(self, *stArgs, **stKeyArgs): self.gLogger = DIRAC.gLogger.getSubLogger('MyDB') MySQL.__init__(self, *stArgs, **stKeyArgs)
def getDB(host, user, password, dbName, port): """ Return a MySQL object """ return MySQL(host, user, password, dbName, port)
def __init__( self, *stArgs, **stKeyArgs ): self.gLogger = DIRAC.gLogger.getSubLogger( 'MyDB' ) MySQL.__init__( self, *stArgs, **stKeyArgs )
def __init__(self, dbname, fullname, maxQueueSize, debug=False): self.database_name = dbname self.fullname = fullname self.cs_path = getDatabaseSection(fullname) self.log = gLogger.getSubLogger(self.database_name) self.dbHost = "" result = gConfig.getOption(self.cs_path + "/Host") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: Host") self.dbHost = result["Value"] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if self.dbHost != "localhost": localHostName = socket.getfqdn() if localHostName == self.dbHost: self.dbHost = "localhost" self.dbPort = 3306 result = gConfig.getOption(self.cs_path + "/Port") if not result["OK"]: # No individual port number found, try at the common place result = gConfig.getOption("/Systems/Databases/Port") if result["OK"]: self.dbPort = int(result["Value"]) else: self.dbPort = int(result["Value"]) self.dbUser = "" result = gConfig.getOption(self.cs_path + "/User") if not result["OK"]: # No individual user name found, try at the common place result = gConfig.getOption("/Systems/Databases/User") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: User") self.dbUser = result["Value"] self.dbPass = "" result = gConfig.getOption(self.cs_path + "/Password") if not result["OK"]: # No individual password found, try at the common place result = gConfig.getOption("/Systems/Databases/Password") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: Password") self.dbPass = result["Value"] self.dbName = "" result = gConfig.getOption(self.cs_path + "/DBName") if not result["OK"]: raise RuntimeError("Failed to get the configuration parameters: DBName") self.dbName = result["Value"] self.maxQueueSize = maxQueueSize result = gConfig.getOption(self.cs_path + "/MaxQueueSize") if result["OK"]: self.maxQueueSize = int(result["Value"]) MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, self.dbPort, maxQueueSize=maxQueueSize, debug=debug, ) if not self._connected: raise RuntimeError("Can not connect to DB %s, exiting..." % dbname) self.log.info("==================================================") # self.log.info("SystemInstance: "+self.system) self.log.info("User: "******"Host: " + self.dbHost) self.log.info("Port: " + str(self.dbPort)) # self.log.info("Password: "******"DBName: " + self.dbName) self.log.info("MaxQueue: " + str(self.maxQueueSize)) self.log.info("==================================================")
def __init__( self, dbname, fullname, maxQueueSize ): self.database_name = dbname self.fullname = fullname self.cs_path = getDatabaseSection( fullname ) self.log = gLogger.getSubLogger( self.database_name ) self.dbHost = '' result = gConfig.getOption( self.cs_path + '/Host' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Host' ) return self.dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if self.dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == self.dbHost: self.dbHost = 'localhost' self.dbPort = 3306 result = gConfig.getOption( self.cs_path + '/Port' ) if not result['OK']: # No individual port number found, try at the common place result = gConfig.getOption( '/Systems/Databases/Port' ) if result['OK']: self.dbPort = int(result['Value']) else: self.dbPort = int(result['Value']) self.dbUser = '' result = gConfig.getOption( self.cs_path + '/User' ) if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption( '/Systems/Databases/User' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: User' ) return self.dbUser = result['Value'] self.dbPass = '' result = gConfig.getOption( self.cs_path + '/Password' ) if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption( '/Systems/Databases/Password' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Password' ) return self.dbPass = result['Value'] self.dbName = '' result = gConfig.getOption( self.cs_path + '/DBName' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: DBName' ) return self.dbName = result['Value'] self.maxQueueSize = maxQueueSize result = gConfig.getOption( self.cs_path + '/MaxQueueSize' ) if result['OK']: self.maxQueueSize = int( result['Value'] ) MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, self.dbPort, maxQueueSize = maxQueueSize ) if not self._connected: err = 'Can not connect to DB, exiting...' self.log.fatal( err ) sys.exit( err ) self.log.info( "==================================================" ) #self.log.info("SystemInstance: "+self.system) self.log.info( "User: "******"Host: " + self.dbHost ) self.log.info( "Port: " + str(self.dbPort) ) #self.log.info("Password: "******"DBName: " + self.dbName ) self.log.info( "MaxQueue: " + str(self.maxQueueSize) ) self.log.info( "==================================================" )
from DIRAC import gLogger from DIRAC.Core.Utilities import Time from DIRAC.Core.Utilities.MySQL import MySQL if 'PYTHONOPTIMIZE' in os.environ and os.environ['PYTHONOPTIMIZE']: gLogger.info('Unset python optimization "PYTHONOPTIMIZE"') sys.exit(0) gLogger.info('Testing MySQL class...') HOST = '127.0.0.1' USER = '******' PWD = 'Dirac' DB = 'AccountingDB' TESTDB = MySQL(HOST, USER, PWD, DB) assert TESTDB._connect()['OK'] TESTDICT = { 'TestTable': { 'Fields': { 'ID': "INTEGER UNIQUE NOT NULL AUTO_INCREMENT", 'Name': "VARCHAR(255) NOT NULL DEFAULT 'Yo'", 'Surname': "VARCHAR(255) NOT NULL DEFAULT 'Tu'", 'Count': "INTEGER NOT NULL DEFAULT 0", 'Time': "DATETIME", }, 'PrimaryKey': 'ID' } }
def __init__( self, dbname, fullname, maxQueueSize ): self.database_name = dbname self.fullname = fullname self.cs_path = getDatabaseSection( fullname ) self.log = gLogger.getSubLogger( self.database_name ) self.dbHost = '' result = gConfig.getOption( self.cs_path + '/Host' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Host' ) return self.dbHost = result['Value'] # Check if the host is the local one and then set it to 'localhost' to use # a socket connection if self.dbHost != 'localhost': localHostName = socket.getfqdn() if localHostName == self.dbHost: self.dbHost = 'localhost' self.dbUser = '' result = gConfig.getOption( self.cs_path + '/User' ) if not result['OK']: # No individual user name found, try at the common place result = gConfig.getOption( '/Systems/Databases/User' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: User' ) return self.dbUser = result['Value'] self.dbPass = '' result = gConfig.getOption( self.cs_path + '/Password' ) if not result['OK']: # No individual password found, try at the common place result = gConfig.getOption( '/Systems/Databases/Password' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: Password' ) return self.dbPass = result['Value'] self.dbName = '' result = gConfig.getOption( self.cs_path + '/DBName' ) if not result['OK']: self.log.fatal( 'Failed to get the configuration parameters: DBName' ) return self.dbName = result['Value'] self.maxQueueSize = maxQueueSize result = gConfig.getOption( self.cs_path + '/MaxQueueSize' ) if result['OK']: self.maxQueueSize = int( result['Value'] ) MySQL.__init__( self, self.dbHost, self.dbUser, self.dbPass, self.dbName, maxQueueSize = maxQueueSize ) if not self._connected: err = 'Can not connect to DB, exiting...' self.log.fatal( err ) sys.exit( err ) self.log.info( "==================================================" ) #self.log.info("SystemInstance: "+self.system) self.log.info( "User: "******"Host: " + self.dbHost ) #self.log.info("Password: "******"DBName: " + self.dbName ) self.log.info( "MaxQueue: " + str(self.maxQueueSize) ) self.log.info( "==================================================" )
from DIRAC import gLogger from DIRAC.Core.Utilities import Time from DIRAC.Core.Utilities.MySQL import MySQL if 'PYTHONOPTIMIZE' in os.environ and os.environ['PYTHONOPTIMIZE']: gLogger.info( 'Unset python optimization "PYTHONOPTIMIZE"' ) sys.exit( 0 ) gLogger.info( 'Testing MySQL class...' ) HOST = '127.0.0.1' USER = '******' PWD = 'Dirac' DB = 'AccountingDB' TESTDB = MySQL( HOST, USER, PWD, DB ) assert TESTDB._connect()['OK'] TESTDICT = { 'TestTable' : { 'Fields': { 'ID' : "INTEGER UNIQUE NOT NULL AUTO_INCREMENT", 'Name' : "VARCHAR(255) NOT NULL DEFAULT 'Yo'", 'Surname' : "VARCHAR(255) NOT NULL DEFAULT 'Tu'", 'Count' : "INTEGER NOT NULL DEFAULT 0", 'Time' : "DATETIME", }, 'PrimaryKey': 'ID' } } NAME = 'TestTable' FIELDS = [ 'Name', 'Surname' ] NEWVALUES = [ 'Name2', 'Surn2' ]