Пример #1
0
    def __initializeConnection(self, dbPath):
        """
    Collects from the CS all the info needed to connect to the DB.
    This should be in a base class eventually
    """

        result = getDBParameters(dbPath)
        if not result['OK']:
            raise Exception('Cannot get database parameters: %s' %
                            result['Message'])

        dbParameters = result['Value']
        self.log.debug("db parameters: %s" % dbParameters)
        self.host = dbParameters['Host']
        self.port = dbParameters['Port']
        self.user = dbParameters['User']
        self.password = dbParameters['Password']
        self.dbName = dbParameters['DBName']

        self.engine = create_engine(
            'mysql://%s:%s@%s:%s/%s' %
            (self.user, self.password, self.host, self.port, self.dbName),
            pool_recycle=3600,
            echo_pool=True,
            echo=self.log.getLevel() == 'DEBUG')
        self.sessionMaker_o = sessionmaker(bind=self.engine)
        self.inspector = Inspector.from_engine(self.engine)
Пример #2
0
  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']

    super(DB, self).__init__(hostName=self.dbHost,
                             userName=self.dbUser,
                             passwd=self.dbPass,
                             dbName=self.dbName,
                             port=self.dbPort,
                             debug=debug)

    if not self._connected:
      raise RuntimeError("Can not connect to DB '%s', exiting..." % self.dbName)

    self.log.info("===================== MySQL ======================")
    self.log.info("User:           "******"Host:           " + self.dbHost)
    self.log.info("Port:           " + str(self.dbPort))
    #self.log.info("Password:       "******"DBName:         " + self.dbName)
    self.log.info("==================================================")
Пример #3
0
  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( "==================================================" )
Пример #4
0
  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']

    super(DB, self).__init__(hostName=self.dbHost,
                             userName=self.dbUser,
                             passwd=self.dbPass,
                             dbName=self.dbName,
                             port=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("User:           "******"Host:           " + self.dbHost)
    self.log.info("Port:           " + str(self.dbPort))
    #self.log.info("Password:       "******"DBName:         " + self.dbName)
    self.log.info("==================================================")
Пример #5
0
  def __initializeConnection( self, dbPath ):
    """
    Collects from the CS all the info needed to connect to the DB.
    This should be in a base class eventually
    """

    result = getDBParameters( dbPath )
    if not result[ 'OK' ]:
      raise Exception( 'Cannot get database parameters: %s' % result['Message'] )

    dbParameters = result[ 'Value' ]
    self.log.debug("db parameters: %s" % dbParameters)
    self.host = dbParameters[ 'Host' ]
    self.port = dbParameters[ 'Port' ]
    self.user = dbParameters[ 'User' ]
    self.password = dbParameters[ 'Password' ]
    self.dbName = dbParameters[ 'DBName' ]

    self.engine = create_engine( 'mysql://%s:%s@%s:%s/%s' % ( self.user,
                                                              self.password,
                                                              self.host,
                                                              self.port,
                                                              self.dbName ),
                                 pool_recycle = 3600,
                                 echo_pool = True,
                                 echo = self.log.getLevel() == 'DEBUG')
    self.sessionMaker_o = sessionmaker( bind = self.engine )
    self.inspector = Inspector.from_engine( self.engine )
Пример #6
0
    def _initializeConnection(self, dbPath):
        """
        Collect from the CS all the info needed to connect to the DB.
        """

        result = getDBParameters(dbPath)
        if not result["OK"]:
            raise Exception("Cannot get database parameters: %s" %
                            result["Message"])

        dbParameters = result["Value"]
        self.log.debug("db parameters: %s" % dbParameters)
        self.host = dbParameters["Host"]
        self.port = dbParameters["Port"]
        self.user = dbParameters["User"]
        self.password = dbParameters["Password"]
        self.dbName = dbParameters["DBName"]

        self.engine = create_engine(
            "mysql://%s:%s@%s:%s/%s" %
            (self.user, self.password, self.host, self.port, self.dbName),
            pool_recycle=3600,
            echo_pool=True,
            echo=self.log.getLevel() == "DEBUG",
        )
        self.sessionMaker_o = sessionmaker(bind=self.engine)
        self.inspector = Inspector.from_engine(self.engine)
Пример #7
0
    def __init__(self):

        self.log = gLogger.getSubLogger('PilotsLoggingDB')

        result = getDBParameters('WorkloadManagement/PilotsLoggingDB')
        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']

        # These are the list of tables that will be created.
        # They can be extended in an extension module
        self.tablesList = getattr(
            Utils.voimport(
                'DIRAC.WorkloadManagementSystem.DB.PilotsLoggingDB'),
            'TABLESLIST')

        self.__initializeConnection()
        resp = self.__initializeDB()
        if not resp['OK']:
            raise Exception("Couldn't create tables: " + resp['Message'])
Пример #8
0
    def __init__(self, parentLogger=None):

        if not parentLogger:
            parentLogger = gLogger
        self.log = parentLogger.getSubLogger(self.__class__.__name__)

        result = getDBParameters("WorkloadManagement/PilotsLoggingDB")
        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"]

        # These are the list of tables that will be created.
        # They can be extended in an extension module
        self.tablesList = getattr(Utils.voimport("DIRAC.WorkloadManagementSystem.DB.PilotsLoggingDB"), "TABLESLIST")

        self.__initializeConnection()
        resp = self.__initializeDB()
        if not resp["OK"]:
            raise Exception("Couldn't create tables: " + resp["Message"])
Пример #9
0
  def __getDBConnectionInfo(self, fullname):
    """ Collect from the CS all the info needed to connect to the DB.
        This should be in a base class eventually
    """

    result = getDBParameters(fullname)
    if not result['OK']:
      raise Exception('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']
Пример #10
0
  def __getDBConnectionInfo( self, fullname ):
    """ Collect from the CS all the info needed to connect to the DB.
        This should be in a base class eventually
    """

    result = getDBParameters( fullname )
    if not result[ 'OK' ]:
      raise Exception( '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' ]
Пример #11
0
    def __getDBConnectionInfo(self, fullname):
        """Collect from the CS all the info needed to connect to the DB.
        This should be in a base class eventually
        """

        result = getDBParameters(fullname)
        if not result["OK"]:
            raise Exception("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"]
Пример #12
0
  def __initializeConnection( self, dbPath ):

    result = getDBParameters( dbPath )
    if not result[ 'OK' ]:
      raise Exception( 'Cannot get database parameters: %s' % result['Message'] )

    dbParameters = result[ 'Value' ]
    self.host = dbParameters[ 'Host' ]
    self.port = dbParameters[ 'Port' ]
    self.user = dbParameters[ 'User' ]
    self.password = dbParameters[ 'Password' ]
    self.dbName = dbParameters[ 'DBName' ]

    self.engine = create_engine( 'mysql://%s:%s@%s:%s/%s' % ( self.user, self.password, self.host, self.port, self.dbName ),
                                 pool_recycle = 3600, echo_pool = True)
    self.session = scoped_session( sessionmaker( bind = self.engine ) )
    self.inspector = Inspector.from_engine( self.engine )
Пример #13
0
  def __initializeConnection( self, dbPath ):

    result = getDBParameters( dbPath )
    if not result[ 'OK' ]:
      raise Exception( 'Cannot get database parameters: %s' % result['Message'] )

    dbParameters = result[ 'Value' ]
    self.host = dbParameters[ 'Host' ]
    self.port = dbParameters[ 'Port' ]
    self.user = dbParameters[ 'User' ]
    self.password = dbParameters[ 'Password' ]
    self.dbName = dbParameters[ 'DBName' ]

    self.engine = create_engine( 'mysql://%s:%s@%s:%s/%s' % ( self.user, self.password, self.host, self.port, self.dbName ),
                                 pool_recycle = 3600, echo_pool = True)
    self.session = scoped_session( sessionmaker( bind = self.engine ) )
    self.inspector = Inspector.from_engine( self.engine )
Пример #14
0
    def __initializeConnection(self, dbPath):

        result = getDBParameters(dbPath)
        if not result["OK"]:
            raise Exception("Cannot get database parameters: %s" % result["Message"])

        dbParameters = result["Value"]
        self.host = dbParameters["Host"]
        self.port = dbParameters["Port"]
        self.user = dbParameters["User"]
        self.password = dbParameters["Password"]
        self.dbName = dbParameters["DBName"]

        self.engine = create_engine(
            "mysql://%s:%s@%s:%s/%s" % (self.user, self.password, self.host, self.port, self.dbName),
            pool_recycle=3600,
            echo_pool=True,
        )
        self.session = scoped_session(sessionmaker(bind=self.engine))
        self.inspector = Inspector.from_engine(self.engine)
Пример #15
0
    def __init__(self, dbname, fullname, debug=False, parentLogger=None):

        self.fullname = fullname

        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"]

        super(DB, self).__init__(
            hostName=self.dbHost,
            userName=self.dbUser,
            passwd=self.dbPass,
            dbName=self.dbName,
            port=self.dbPort,
            debug=debug,
            parentLogger=parentLogger,
        )

        if not self._connected:
            raise RuntimeError("Can not connect to DB '%s', exiting..." %
                               self.dbName)

        self.log.info("===================== MySQL ======================")
        self.log.info("User:           "******"Host:           " + self.dbHost)
        self.log.info("Port:           " + str(self.dbPort))
        # self.log.info("Password:       "******"DBName:         " + self.dbName)
        self.log.info("==================================================")
Пример #16
0
  def __init__( self ):

    self.log = gLogger.getSubLogger( 'PilotsLoggingDB' )
    
    result = getDBParameters( 'WorkloadManagement/PilotsLoggingDB' )
    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']

    #These are the list of tables that will be created.
    #They can be extended in an extension module
    self.tablesList = getattr(Utils.voimport( 'DIRAC.WorkloadManagementSystem.DB.PilotsLoggingDB' ),
                              'TABLESLIST')

    self.__initializeConnection()
    resp = self.__initializeDB( )
    if not resp['OK']:
      raise Exception( "Couldn't create tables: " + resp['Message'] )