Beispiel #1
0
    def getHLTGlobalTag(self):
        """
        Returns the Global Tag used for the last run completed by HLT.
        """
        try:
            command_line = "edmConfigFromDB --orcoff --runNumber " + str(
                self._lastStoppedRun)
            args = shlex.split(command_line)
            p = subprocess.Popen(args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            result = p.communicate()[0]
            resList = result.strip().split("\n")
            logging.debug("HLT configuration file for run \"%d\": %s",
                          self._lastStoppedRun, resList)
            resGT = [l.strip() for l in resList if l.find("globaltag") != -1]
            logging.debug("Global Tag configuration fragment: %s", resGT)
            globalTag = [
                l.strip().replace("::All", "") for l in resGT[0].split("\"")
                if l.find("::All") != -1
            ][0]
            return globalTag
        except IndexError as i:
            raise conditionError.ConditionError(
                "Configuration for run \"%d\" not found." %
                (self._lastStoppedRun, ))
        except OSError as o:
            raise conditionError.ConditionError(
                """Unable to load HLT configuration for run \"%d\".
The reason is: %s """ % (self._lastStoppedRun, o))
def getValidConnectionDictionaryFromConnectionString(connectionString):
    # first we parse the connection string in order to get the service name and the account name
    protocolDictionary = service.getProtocolServiceAndAccountFromConnectionString(
        connectionString)
    if not protocolDictionary:
        raise conditionError.ConditionError(
            "Invalid connection string: \"%s\"" % (connectionString, ))
    # next, we check whether the connection string is valid
    connectionDictionary = getValidConnectionDictionary(protocolDictionary)
    if not connectionDictionary:  #the oracle or frontier service provided was not found
        raise conditionError.ConditionError(
            "The service provided in the connection string \"%s\" was not found in the available ones."
            % (connectionString, ))
    return connectionDictionary
def frontierToOracle(connectionString, updatesOnOracle=False):
    """
    Transforms a frontier connection string into an Oracle one.
    Parameters:
    connectionString: string for connecting to a condition Database account;
    updatesOnOracle: boolean, default False, if set to True the connection string will contain an Oracle service name allowing for updates.
    @returns: Oracle connection string, raises exception if parsing error or update not allowed.
    """
    connectionDictionary = getValidConnectionDictionaryFromConnectionString(
        connectionString)

    if updatesOnOracle and connectionDictionary[
            'service_type'] == 'OfflineProduction':
        # The offline production service is read-only, so if we want to perform updates, we need a connection to the Online production
        for serviceDict in serviceList:
            if serviceDict['service_type'] == 'OnlineProduction':
                connectionDictionary['service_type'] = 'OnlineProduction'
                connectionDictionary['db_name'] = serviceDict['oracle'][0]
                connectionDictionary['frontier_name'] = serviceDict[
                    'frontier'][0]

    # Moreover, the offline archive is read-only and frozen, so no updates are allowed
    if updatesOnOracle and connectionDictionary[
            'service_type'] == 'OfflineArchive':
        raise conditionError.ConditionError(
            "The data stored in the Oracle Database accessed through the service \"%s\" and through frontier servlet \"%s\" for service type OfflineArchive are read-only and cannot be modified."
            % (connectionDictionary['db_name'],
               connectionDictionary['frontier_name']))

    return service.getOracleConnectionString(connectionDictionary)
    def initGT(self, globalTagName, connectionString=None, authPath=None):
        """
        Initiates the connection to the GT database, or re-initiates it in case one of the connection parameters is changed, and loads the Global Tag.
        Parameters:
        globalTagName: name of the Global Tag;
        connectionString: connection string for connecting to the account hosting Global Tags (default None if unchanged w.r.t. c'tor);
        authPath: path to authentication key (default None if unchanged w.r.t. c'tor).
        @returns: a boolean set to True if the connection has been (re-)opened; raises if the connection cannot be established.
        """
        isReconnected = False
        if authPath != None and self._authPath != authPath:
            self._authPath = authPath
            self._dbStarted = False
        if connectionString != None and self._connectionString != connectionString:
            checkConnectionString(connectionString)
            self._connectionString = connectionString
            self._dbStarted = False
        if self._globalTagName == globalTagName and self._dbStarted:
            return isReconnected
        if self._globalTagName != globalTagName:
            self._globalTagName = globalTagName
            self._dbStarted = False
        try:
            self._rdbms = condDB.RDBMS(self._authPath)
            self._globalTag = self._rdbms.globalTag(
                self._connectionString, "::".join([self._globalTagName,
                                                   "All"]), "", "")
            self._dbStarted = True
            isReconnected = True
        except RuntimeError as err:
            raise conditionError.ConditionError(
                """Cannot connect to Global Tag \"%s\" on account \"%s\" for RDBMS in \"%s\".
The CMSSW exception is: %s""" % (self._globalTagName, self._connectionString,
                                 self._authPath, err))
        return isReconnected
    def _initDB(self, connectionString, authPath=None):
        """
        Initiates the connection to the database, or re-initiates it in case one of the connection parameters is changed.
        Parameters:
        connectionString: connection string for connecting to the account specified by the connection string;
        authPath: path to authentication key  (default None if unchanged w.r.t. c'tor).
        @returns: a boolean set to True if the connection has been (re-)opened; raises if the connection cannot be established.
        """
        isReconnected = False
        if authPath != None and self._authPath != authPath:
            self._authPath = authPath
            self._dbStarted = False
        if self._connectionString == connectionString and self._dbStarted:
            return isReconnected
        if self._connectionString != connectionString:
            checkConnectionString(connectionString)
            self._connectionString = str(
                connectionString
            )  # ensure we pass on a string even if we get a unicode object
            self._dbStarted = False
        try:
            self._rdbms = condDB.RDBMS(self._authPath)
            self._db = self._rdbms.getReadOnlyDB(
                str(self._connectionString)
            )  # ensure we pass on a string even if we get a unicode object
            isReconnected = True
            self._dbStarted = True
        except RuntimeError as err:
            raise conditionError.ConditionError(
                """Cannot connect to condition database \"%s\" for RDBMS in \"%s\".
The CMSSW exception is: %s""" % (self._connectionString, self._authPath, err))
        return isReconnected
    def payloadContainer(self):
        try:
            return self.payloadClasses()[0]
        except KeyError:
            raise conditionError.ConditionError(
                """IOV tag \"%s\" does not contain any payloads.
Please check the status of this tag and inform Condition DB experts if the issue is not solved."""
                % (self._tag, ))
    def size(self):
        iovSize = self._iovSequence.size()
        if not iovSize:
            raise conditionError.ConditionError(
                """IOV tag \"%s\" does not contain any IOV elements.
Please check the status of this tag and inform Condition DB experts if the issue is not solved."""
                % (self._tag, ))
        return iovSize
    def getAllSinceValues(self):
        elementList = [elem.since() for elem in self._iovSequence.elements]
        if not elementList:
            raise conditionError.ConditionError(
                """IOV tag \"%s\" does not contain any IOV elements.
Please check the status of this tag and inform Condition DB experts if the issue is not solved."""
                % (self._tag, ))
        return elementList
    def load(self, tag):
        self._tag = str(
            tag)  # ensure we pass on a string even if we get a unicode object
        try:
            self._db.startReadOnlyTransaction()
            self._iovSequence = self._db.iov(self._tag)
            self._db.commitTransaction()
        except RuntimeError as err:
            raise conditionError.ConditionError(
                """Cannot retrieve the IOV sequence associated to tag \"%s\".
The CMSSW exception is: %s""" % (self._tag, err))
def checkConnectionString(connectionString, forUpdating=False):
    if connectionString.startswith('sqlite_file:'):
        # todo FIXME: check that the file is existing
        return True
    protocolDictionary = service.getProtocolServiceAndAccountFromConnectionString(
        connectionString)
    if not protocolDictionary:
        raise conditionError.ConditionError(
            "Invalid connection string: \"%s\"" % (connectionString, ))
    if forUpdating and protocolDictionary['protocol'] == "frontier":
        # we are explicitly excluding Frontier services, as they are read-only
        return False
    connectionDictionary = getValidConnectionDictionary(protocolDictionary)
    if not connectionDictionary:
        raise conditionError.ConditionError(
            "The service provided in the connection string \"%s\" was not found in the available ones."
            % (connectionString, ))
    if forUpdating and (
            connectionDictionary['service_type'] == "OfflineProduction"
            or connectionDictionary['service_type'] == "OfflineArchive"):
        # we are explicitly excluding read-only services
        return False
    return True
    def getAllTags(self):
        """
        @returns: list of all IOV tags available in the account, raises if no tags are there, or if the file is not correct.
        """
        if not self._dbStarted:
            self._initDB(self._connectionString, self._authPath)
        try:
            self._db.startReadOnlyTransaction()
            tags = self._db.allTags().strip().split()
            self._db.commitTransaction()
            return tags
        except RuntimeError as err:
            raise conditionError.ConditionError(
                """Cannot retrieve tags from condition database \"%s\" for RDBMS in \"%s\"
The CMSSW exception is: %s""" % (self._connectionString, self._authPath, err))
Beispiel #12
0
 def getWorkflowForTagAndDB( self, dbName, tagName, productionGTsDict ):
     """
     Checks whether a given tag and the corresponding connection string are in the production Global Tags.
     The check is done for the connection string to Oracle.
     Parameters:
     dbName: connection string;
     tagName: name of the tag to be checked;
     productionGTsDict: dictionary for the Global Tags in the production workflows, in the form {'hlt' : hltGT, 'express' : expressGT, 'prompt' : promptGT }.
     @returns: a string with the name of the production worklow where the input DB and tag pair is used, None the DB/tag is not used in any of them. In case it is included in more than one Global Tags, hlt wins over express, express over prompt.
     Raises if the dictionary for production workflows is malformed.
     """
     #first check if the dictionary contains the workflows
     if len( productionGTsDict ) != 3:
         raise conditionError.ConditionError( "The input dictionary for the Global Tags in the production worklows is not correct." )
     workflows = ( 'hlt', 'express', 'prompt' )
     for productionGTWorkflow in productionGTsDict.keys():
         if productionGTWorkflow not in workflows:
             raise conditionError.ConditionError( "The input dictionary for the Global Tags in the production worklows does not contain workflow \"%s\"" %( productionGTWorkflow, ) )
     #now check if the db/tag are in any of the production GTs
     for workflow in workflows:
         self._gt.initGT( productionGTsDict[ workflow ] )
         if self._gt.checkTag( dbName, tagName, True ):
                 return workflow
     return None
    def checkTag(self, dbName, tagName, updatesOnOracle=False):
        """
        Checks whether a given tag and the corresponding connection string are in the loaded Global Tag.
        The check is done for the connection string to Oracle.
        Parameters:
        dbName: connection string;
        tagName: name of the tag to be checked;
        updatesOnOracle: boolean, default False, if set to True the chech is done w.r.t. a connection string for an Oracle service name allowing for updates.
        @returns: True if db/tag are in, False elsewhere.
        Raises if there is an error in parsing the input connection string, and, when updatesOnOracle is set True, if the connection string points to a service where updates are not allowed.
        """
        if self._globalTagName is None:
            raise conditionError.ConditionError(
                """The Global Tag on account \"%s\" for RDBMS in \"%s\" has not yet been initialized.
Please run the GlobalTagChecker.initGT function.""" %
                (self._connectionString, self._authPath))
        if not self._dbStarted:
            self.initGT(self._globalTagName)
        listTag = [(frontierToOracle(x.pfn, updatesOnOracle), x.tag)
                   for x in self._globalTag.elements]
        if (frontierToOracle(dbName, updatesOnOracle), tagName) in listTag:
            return True
        return False
#!/usr/bin/env python
import DLFCN
import os
import sys
import time

import conditionError
import service

sys.setdlopenflags(DLFCN.RTLD_GLOBAL + DLFCN.RTLD_LAZY)

try:
    import pluginCondDBPyInterface as condDB
except ImportError:
    raise conditionError.ConditionError(
        """Unable to import the Condition Python API for accessing condition data.
Please check if the CMSSW environment is correctly initialized.""")

serviceList = [{
    'service_type': 'OnlineProduction',
    'oracle': ['cms_orcon_prod'],
    'frontier': ['FrontierOnProd']
}, {
    'service_type': 'OfflineProduction',
    'oracle': ['cms_orcon_adg'],
    'frontier': ['PromptProd', 'FrontierProd']
}, {
    'service_type': 'OfflineIntegration',
    'oracle': ['cms_orcoff_int'],
    'frontier': ['FrontierInt']
}, {