Exemple #1
0
def initializeDataLoggingHandler( serviceInfo ):
  """ handler initialisation """
  global gDataLoggingDB
  gDataLoggingDB = DataLoggingDB()

  res = gDataLoggingDB._connect()
  if not res['OK']:
    return res
  res = gDataLoggingDB._checkTable()
  if not res['OK'] and not res['Message'] == 'The requested table already exist':
    return res
  return S_OK()
def initializeDataLoggingHandler( serviceInfo ):
  """ handler initialisation """
  global gDataLoggingDB
  gDataLoggingDB = DataLoggingDB()

  res = gDataLoggingDB._connect()
  if not res['OK']:
    return res
  res = gDataLoggingDB._checkTable()
  if not res['OK'] and not res['Message'] == 'The requested table already exist':
    return res
  return S_OK()
def initializeDataLoggingHandler(serviceInfo):
    """ handler initialisation """
    global logDB
    logDB = DataLoggingDB()

    res = logDB._connect()
    if not res["OK"]:
        return res
    res = logDB._checkTable()
    if not res["OK"] and not res["Message"] == "The requested table already exist":
        return res

    return S_OK()
Exemple #4
0
def initializeDataLoggingHandler(serviceInfo):

    global dataPath
    global logDB
    logDB = DataLoggingDB()

    monitoringSection = PathFinder.getServiceSection(
        "DataManagement/DataLogging")
    #Get data location
    retDict = gConfig.getOption("%s/DataLocation" % monitoringSection,
                                "dataLoggingPlots")
    if not retDict['OK']:
        return retDict
    dataPath = retDict['Value'].strip()
    if "/" != dataPath[0]:
        dataPath = os.path.realpath(
            "%s/%s" %
            (gConfig.getValue('/LocalSite/InstancePath', rootPath), dataPath))
    gLogger.info("Data will be written into %s" % dataPath)
    try:
        os.makedirs(dataPath)
    except:
        pass
    try:
        testFile = "%s/mon.jarl.test" % dataPath
        fd = file(testFile, "w")
        fd.close()
        os.unlink(testFile)
    except IOError:
        gLogger.fatal("Can't write to %s" % dataPath)
        return S_ERROR("Data location is not writable")
    return S_OK()
Exemple #5
0
    def setUp(self):
        """ set up

    :param self: self reference
    """
        self.log = gLogger.getSubLogger(self.__class__.__name__)

        if not self.__db:
            gConfig.setOptionValue("/DIRAC/Setup", "Test")
            gConfig.setOptionValue("/DIRAC/Setups/Test/DataManagement", "Test")
            spath = "/Systems/DataManagement/Test/Databases/DataLoggingDB"
            gConfig.setOptionValue("%s/%s" % (spath, "Host"), "127.0.0.1")
            gConfig.setOptionValue("%s/%s" % (spath, "DBName"), "AccountingDB")
            gConfig.setOptionValue("%s/%s" % (spath, "User"), "Dirac")
            gConfig.setOptionValue("%s/%s" % (spath, "Password"), "Dirac")
            self.__db = DataLoggingDB()
  def setUp( self ):
    """ set up

    :param self: self reference
    """
    self.log = gLogger.getSubLogger( self.__class__.__name__ )

    if not self.__db:
      gConfig.setOptionValue( "/DIRAC/Setup", "Test" )
      gConfig.setOptionValue( "/DIRAC/Setups/Test/DataManagement", "Test" )
      spath = "/Systems/DataManagement/Test/Databases/DataLoggingDB" 
      gConfig.setOptionValue( "%s/%s" % ( spath, "Host" ), "127.0.0.1" )
      gConfig.setOptionValue( "%s/%s" % ( spath, "DBName" ), "AccountingDB" )
      gConfig.setOptionValue( "%s/%s" % ( spath, "User" ), "Dirac" )
      gConfig.setOptionValue( "%s/%s" % ( spath, "Password" ), "Dirac" )
      self.__db = DataLoggingDB()
Exemple #7
0
class DataLoggingDBTestCase(unittest.TestCase):
    """
  .. class:: DataLoggingDBTests
  
  """
    ## db ref
    __db = None

    def setUp(self):
        """ set up

    :param self: self reference
    """
        self.log = gLogger.getSubLogger(self.__class__.__name__)

        if not self.__db:
            gConfig.setOptionValue("/DIRAC/Setup", "Test")
            gConfig.setOptionValue("/DIRAC/Setups/Test/DataManagement", "Test")
            spath = "/Systems/DataManagement/Test/Databases/DataLoggingDB"
            gConfig.setOptionValue("%s/%s" % (spath, "Host"), "127.0.0.1")
            gConfig.setOptionValue("%s/%s" % (spath, "DBName"), "AccountingDB")
            gConfig.setOptionValue("%s/%s" % (spath, "User"), "Dirac")
            gConfig.setOptionValue("%s/%s" % (spath, "Password"), "Dirac")
            self.__db = DataLoggingDB()

    def test_01_ctor(self):
        """ DataLoggingDB.__init__

    :param self: self reference
    """
        self.assertEqual(self.__db != None, True)
        self.assertEqual(isinstance(self.__db, DataLoggingDB), True)
        self.assertEqual(self.__db._connect()["OK"], True)

    def test_02_createTable(self):
        """ DataLoggingDB._createTable

    :param self: self reference
    """
        self.assertEqual(self.__db._createTable()["OK"], True)

    def test_03_api(self):
        """ DataLoggingDB API

    :param self: self reference
    """

        lfns = ['/Test/00001234/File1', '/Test/00001234/File2']
        fileTuples = tuple([(lfn, "TestStatus", "MinorStatus", Time.toString(),
                             Time.dateTime(), "Somewhere") for lfn in lfns])

        result = self.__db.addFileRecord(lfns,
                                         "TestStatus",
                                         date='2012-04-28 09:49:02.545466')
        self.assertEqual(result["OK"], True)
        self.assertEqual(result["Value"], 2)
        self.assertEqual(result["lastRowId"], 2)

        result = self.__db.addFileRecords(fileTuples)
        self.assertEqual(result["OK"], True)

        result = self.__db.getFileLoggingInfo(lfns[0])
        self.assertEqual(result["OK"], True)
        self.assertEqual(len(result["Value"]), 2)

        result = self.__db.getFileLoggingInfo(lfns[1])
        self.assertEqual(result["OK"], True)
        self.assertEqual(len(result["Value"]), 2)

        result = self.__db.getUniqueStates()
        self.assertEqual(result["OK"], True)
        self.assertEqual(result["Value"], ["TestStatus"])

        result = self.__db._update('DROP TABLE `%s`' % self.__db.tableName)
        self.assertEqual(result["OK"], True)
class DataLoggingDBTestCase(unittest.TestCase):
  """
  .. class:: DataLoggingDBTests
  
  """
  ## db ref
  __db = None

  def setUp( self ):
    """ set up

    :param self: self reference
    """
    self.log = gLogger.getSubLogger( self.__class__.__name__ )

    if not self.__db:
      gConfig.setOptionValue( "/DIRAC/Setup", "Test" )
      gConfig.setOptionValue( "/DIRAC/Setups/Test/DataManagement", "Test" )
      spath = "/Systems/DataManagement/Test/Databases/DataLoggingDB" 
      gConfig.setOptionValue( "%s/%s" % ( spath, "Host" ), "127.0.0.1" )
      gConfig.setOptionValue( "%s/%s" % ( spath, "DBName" ), "AccountingDB" )
      gConfig.setOptionValue( "%s/%s" % ( spath, "User" ), "Dirac" )
      gConfig.setOptionValue( "%s/%s" % ( spath, "Password" ), "Dirac" )
      self.__db = DataLoggingDB()

  def test_01_ctor( self ):
    """ DataLoggingDB.__init__

    :param self: self reference
    """
    self.assertEqual( self.__db != None, True  )
    self.assertEqual( isinstance( self.__db, DataLoggingDB ), True )
    self.assertEqual( self.__db._connect()["OK"], True )

  def test_02_createTable( self ):
    """ DataLoggingDB._createTable

    :param self: self reference
    """
    self.assertEqual( self.__db._createTable()["OK"], True )
   
  def test_03_api( self ):
    """ DataLoggingDB API

    :param self: self reference
    """
    
    lfns = [ '/Test/00001234/File1', '/Test/00001234/File2' ] 
    fileTuples = tuple( [ ( lfn, "TestStatus", "MinorStatus", Time.toString(), Time.dateTime(), "Somewhere" ) 
                          for lfn in lfns ] )
    
    result = self.__db.addFileRecord( lfns, "TestStatus", date = '2012-04-28 09:49:02.545466' )
    self.assertEqual( result["OK"], True ) 
    self.assertEqual( result["Value"], 2 )
    self.assertEqual( result["lastRowId"], 2 )

    result = self.__db.addFileRecords( fileTuples )
    self.assertEqual( result["OK"], True )

    result = self.__db.getFileLoggingInfo( lfns[0] )
    self.assertEqual( result["OK"], True )
    self.assertEqual( len( result["Value"] ), 2 )

    result = self.__db.getFileLoggingInfo( lfns[1] )
    self.assertEqual( result["OK"], True )
    self.assertEqual( len( result["Value"] ), 2 )

    result = self.__db.getUniqueStates()
    self.assertEqual( result["OK"], True )
    self.assertEqual( result["Value"], [ "TestStatus" ] )

    result = self.__db._update( 'DROP TABLE `%s`' % self.__db.tableName )
    self.assertEqual( result["OK"], True )