Esempio n. 1
0
def readSpecFile(filename):
    """
    _readSpecFile_

    Tool for extracting multiple RequestSpecs from a file

    Returns a list of spec instances found
    """
    result = []
    # ignore failed parsed requests
    ignore = 0

    node = loadIMProvFile(filename)
    node = loadIMProvFile(filename)
    specQ = IMProvQuery("RequestSpec")
    specNodes = specQ(node)

    for snode in specNodes:
        newSpec = RequestSpec()
        try:
            newSpec.load(snode)
            result.append(newSpec)
        except Exception, ex:
            logging.debug(
                'ERROR loading a requestspec, will ignore this requestspec :' +
                str(ex))
            ignore += 1
Esempio n. 2
0
def readSpecFile(filename):
    """
    _readSpecFile_

    Tool for extracting multiple RequestSpecs from a file

    Returns a list of spec instances found
    """
    result = []
    # ignore failed parsed requests
    ignore = 0
  
    node = loadIMProvFile(filename)
    node = loadIMProvFile(filename)
    specQ = IMProvQuery("RequestSpec")
    specNodes = specQ(node)

    for snode in specNodes:
        newSpec = RequestSpec()
        try: 
           newSpec.load(snode)
           result.append(newSpec)
        except Exception,ex:
           logging.debug('ERROR loading a requestspec, will ignore this requestspec :'+str(ex))
           ignore+=1
Esempio n. 3
0
def readJobReport(filename):
    """
    _readJobReport_

    Load an XML FwkJobReport Document into a FwkJobReport instance.
    return the FwkJobReport instances.

    Instantiate a new ContentHandler and run it over the file producing
    a list of FwkJobReport instances

    """
    #handler = FwkJobRepHandler()
    #parser = make_parser()
    #parser.setContentHandler(handler)
    #try:
    #    parser.parse(filename)
    #except SAXParseException, ex:
    #    msg = "Error parsing JobReport File: %s\n" % filename
    #    msg += str(ex)
    #    print msg
    #    return []
    #print handler.results[0]
    #return handler.results

    try:
        improvDoc = loadIMProvFile(filename)
    except Exception, ex:
        return []
Esempio n. 4
0
    def loadPayload(self, payloadFile):
        """
        _loadPayload_

        Load the XML input file

        """
        if not os.path.exists(payloadFile):
            raise RuntimeError, "Payload not found: %s" % payload
        

        improv = loadIMProvFile(payloadFile)
        workflowQ = IMProvQuery("SoupKitchen/WorkflowSpec[text()]")
        workflowFile = workflowQ(improv)[-1]
        logging.info("SoupKitchen: Loading Workflow: %s\n" % workflowFile)
        self.workflow = self.loadWorkflow(workflowFile)

        siteQ = IMProvQuery("SoupKitchen/Site[text()]")
        self.siteName = str(siteQ(improv)[-1])

        dbsUrlQ = IMProvQuery("SoupKitchen/DBSURL[text()]")
        self.dbsUrl = str(dbsUrlQ(improv)[-1])
                              
        
        datasetsQ = IMProvQuery("SoupKitchen/Dataset[text()]")
        datasets = datasetsQ(improv)
        self.datasets = [ str(x) for x in datasets ]
        msg = "Datasets to be scrambled:\n"
        for d in self.datasets:
            msg += "  %s\n" % d
        logging.info(msg)
        return
Esempio n. 5
0
    def loadRelValSpec(self):
        """
        _loadRelValSpec_

        Load the RelVal Spec file.
        Populate the list of tests
        """
        improv = loadIMProvFile(self.relvalSpecFile)
        testQ = IMProvQuery("/RelValSpec/RelValTest")
        testNodes = testQ(improv)

        for test in testNodes:
            for site in self.sites:
                newTest = RelValTest()
                newTest.load(test)
                newTest['Site'] = site
                self.tests.append(newTest)





        logging.info("Loaded %s tests from file:\n %s\n" % (
            len(self.tests),
            self.relvalSpecFile))



        return
Esempio n. 6
0
    def loadFromFile(self, filename):
        """
        _loadFromFile_

        Load the configuration saved in the file provided
        into this Config Object
        """
        if not os.path.exists(filename):
            msg = "Error: Attempted to load non-existent file:\n"
            msg += "\t%s\n" % filename
            msg += "Argument must be a valid path\n"
            raise ShREEKException(msg, ClassInstance = self,
                                  MissingFile = filename)

        try:
            result = loadIMProvFile(filename)
        except StandardError, ex:
            msg = "Error Loading Configuration File:\n"
            msg += "\t%s\n" % filename
            msg += "This file must be a valid XML Document\n"
            msg += "Containing a saved ShREEKConfig Object\n"
            msg += str(ex)
            raise ShREEKException(msg, ClassInstance = self,
                                  Filename = filename,
                                  ExceptionInstance = ex)
Esempio n. 7
0
def readJobReport(filename):
    """
    _readJobReport_

    Load an XML FwkJobReport Document into a FwkJobReport instance.
    return the FwkJobReport instances.

    Instantiate a new ContentHandler and run it over the file producing
    a list of FwkJobReport instances

    """
    #handler = FwkJobRepHandler()
    #parser = make_parser()
    #parser.setContentHandler(handler)
    #try:
    #    parser.parse(filename)
    #except SAXParseException, ex:
    #    msg = "Error parsing JobReport File: %s\n" % filename
    #    msg += str(ex)
    #    print msg
    #    return []
    #print handler.results[0]
    #return handler.results

    try:
        improvDoc = loadIMProvFile(filename)
    except Exception, ex:
        return []
Esempio n. 8
0
    def showStatus(self, filepath):
        from IMProv.IMProvLoader import loadIMProvFile
        from IMProv.IMProvQuery import IMProvQuery

        rootag = "TaskTracking"
        headtag = "TaskReport"
        eventag = "Job"

        gotit = loadIMProvFile(filepath)
        param = IMProvQuery(eventag)
        nodiparam = param(gotit)

        html = "<html><body><h2>Staus of task : " + str(self.taskname) + "</h2>\n "
        html += '<table cellspacing="10">\n'

        st = ["Job", "Status", "Action", "Destination", "Job_exit_code", "Exe_exit_code", "Ended"]
        html += "<tr>"
        for s in st:
            html += '<th align="left">%s</b></th>\n' % s
        html += "</tr>"

        for item in nodiparam:
            status = item.attrs.get("status")
            action = item.attrs.get("action")
            site = item.attrs.get("site")
            ended = item.attrs.get("ended")
            jec = item.attrs.get("job_exit")
            eec = item.attrs.get("exe_exit")
            jobid = item.attrs.get("id")
            if ended == "Y":
                ended = "Yes"
            elif ended == "N":
                ended = "No"
            ## temporary workaround
            if action == "Terminated":
                status = "Done"
            if action == "SubRequested":
                status = "Submitting"

            html += "<tr>"
            html += "<td align='left'>%s</td>" % (jobid)
            html += "<td align='left'>%s</td>" % (status)
            html += "<td align='left'>%s</td>" % (action)
            html += "<td align='left'>%s</td>" % (site)
            if jec != "None":
                html += "<td align='left'>%s</td>" % (jec)
            else:
                html += "<td align='left'>&nbsp</td>"
            if eec != "None":
                html += "<td align='left'>%s</td>" % (eec)
            else:
                html += "<td align='left'>&nbsp</td>"
            html += "<td align='left'>%s</td>" % (ended)
            html += "</tr>"

        html += "</table>"
        html += "</body>"

        return html
def queryStatusXML(filename):

    try:
        report = loadIMProvFile(filename)
    except StandardError, ex:
        msg = "Error reading CRAB Status Report: %s\n" % filename
        msg += str(ex)
        raise RuntimeError, msg
def queryStatusXML(filename):

    try:
        report = loadIMProvFile(filename)
    except StandardError, ex:
        msg = "Error reading CRAB Status Report: %s\n" % filename
        msg += str(ex)
        raise RuntimeError, msg
Esempio n. 11
0
    def read(self, filename):
        """
        _read_

        Given the filename, read the contents and populate self

        """
        node = loadIMProvFile(filename)
        self.load(node)
        return
Esempio n. 12
0
    def read(self, filename):
        """
        _read_

        Given the filename, read the contents and populate self

        """
        node = loadIMProvFile(filename)
        self.load(node)
        return
Esempio n. 13
0
    def read(self, filename):
        """
        _read_

        load file -> this object
        
        """
        node = loadIMProvFile(filename)
        self.load(node)
        return
Esempio n. 14
0
    def load(self, filename):
        """
        _load_

        Load a saved WorkflowSpec from a File

        """
        node = loadIMProvFile(filename)
        self.loadFromNode(node)
        return
Esempio n. 15
0
    def load(self, filename):
        """
        _load_

        Load a saved WorkflowSpec from a File

        """
        node = loadIMProvFile(filename)
        self.loadFromNode(node)
        return
Esempio n. 16
0
    def load(self, filename):
        """
        _load_

        Load a saved JobSpec object and install its information
        into this instance

        """
        node = loadIMProvFile(filename)
        self.loadFromNode(node)
        return
Esempio n. 17
0
    def load(self, filename):
        """
        _load_

        Load a saved JobSpec object and install its information
        into this instance

        """
        node = loadIMProvFile(filename)
        self.loadFromNode(node)
        return
Esempio n. 18
0
    def loadFromFile(self, filename):
        """
        _loadFromFile_

        Read the file provided to extract the configuration

        """
        try:
            improv = loadIMProvFile(filename)
        except StandardError, ex:
            msg = "Cannot read file: %s\n" % filename
            msg += "Failed to load ProdCommonConfiguration\n"
            raise RuntimeError, msg
Esempio n. 19
0
    def read(self):
        """
        _read_

        Load data from SiteLocal Config file and populate this object

        """
        try:
            node = loadIMProvFile(self.siteConfigFile)
        except StandardError, ex:
            msg = "Unable to read SiteConfigFile: %s\n" % self.siteConfigFile
            msg += str(ex)
            raise SiteConfigError, msg
Esempio n. 20
0
    def read(self):
        """
        _read_

        Load data from SiteLocal Config file and populate this object

        """
        try:
            node = loadIMProvFile(self.siteConfigFile)
        except StandardError, ex:
            msg = "Unable to read SiteConfigFile: %s\n" % self.siteConfigFile
            msg += str(ex)
            raise SiteConfigError, msg
Esempio n. 21
0
    def loadFromFile(self, filename):
        """
        _loadFromFile_

        Read data from File and populate self

        """
        try:
            improv = loadIMProvFile(filename)
        except StandardError, ex:
            msg = "Cannot read file: %s\n" % filename
            msg += "Failed to load ProdAgent PluginConfiguration\n"
            raise RuntimeError, msg
Esempio n. 22
0
def queryStatusXML(filename):

    try:
        report = loadIMProvFile(filename)
    except Exception as ex:
        msg = "Error reading CRAB Status Report: %s\n" % filename
        msg += str(ex)
        raise RuntimeError(msg)

    query = IMProvQuery("Task/TaskJobs/Job/RunningJob")
    Jobs = query(report)

    return Jobs
Esempio n. 23
0
    def loadFromFile(self, filename):
        """
        _loadFromFile_

        Read the file provided to extract the configuration

        """
        try:
            improv = loadIMProvFile(filename)
        except StandardError, ex:
            msg = "Cannot read file: %s\n" % filename
            msg += "Failed to load ProdAgentConfiguration\n"
            raise RuntimeError, msg
Esempio n. 24
0
    def load(self, directory):
        """
        _load_

        For this instance, search for a params file in the dir provided
        using the workflow name in this instance, and if present, load its
        settings

        """
        fname = os.path.join(
            directory,
            "%s-Persist.xml" % self.workflowSpec.workflowName()
            )
        
        node = loadIMProvFile(fname)

        qbase = "/DatasetIterator/%s" % self.workflowSpec.workflowName()
        
        runQ = IMProvQuery("%s/Run[attribute(\"Value\")]" % qbase)
        splitTQ = IMProvQuery("%s/SplitType[attribute(\"Value\")]" % qbase)
        splitSQ = IMProvQuery("%s/SplitSize[attribute(\"Value\")]" % qbase)
        
        runVal = int(runQ(node)[-1])

        splitT = str(splitTQ(node)[-1])
        splitS = int(splitSQ(node)[-1])
      

        self.count = runVal
        self.splitType = splitT
        self.splitSize = splitS
        
        puQ = IMProvQuery("%s/Pileup/*" % qbase)
        puNodes = puQ(node)
        for puNode in puNodes:
            payloadNode = str(puNode.attrs.get("PayloadNode"))
            puDataset = PileupDataset("dummy", 1)
            puDataset.load(puNode)
            self.pileupDatasets[payloadNode] = puDataset

        specQ = IMProvQuery("%s/JobSpecs/*" % qbase)
        specNodes = specQ(node)
        for specNode in specNodes:
            specId = str(specNode.attrs['ID'])
            specFile = str(specNode.chardata).strip()
            self.ownedJobSpecs[specId] = specFile
        return
Esempio n. 25
0
def loadRunsFile(filename):
    """
    _loadRunsFile_

    Load a file containing a set of run tables as XML
    Returns a list of RunTable instances
    
    """
    improvNode = loadIMProvFile(filename)
    runTableQ = IMProvQuery("RunTable")
    runTables = runTableQ(improvNode)
    result = []
    for runTable in runTables:
        newTable = RunTable()
        newTable.load(runTable)
        result.append(newTable)
    return result
Esempio n. 26
0
def readTFC(filename):
    """
    _readTFC_

    Read the file provided and return a TrivialFileCatalog
    instance containing the details found in it

    """
    if not os.path.exists(filename):
        msg = "TrivialFileCatalog not found: %s" % filename
        raise RuntimeError, msg


    try:
        node = loadIMProvFile(filename)
    except StandardError, ex:
        msg = "Error reading TrivialFileCatalog: %s\n" % filename
        msg += str(ex)
        raise RuntimeError, msg
Esempio n. 27
0
    def load(self, xmlFile):
        """
        _load_

        Load the XML values into this instance

        """
        content = loadIMProvFile(xmlFile)
        for node in content.children:
            name = str(node.name)
            value = node.attrs.get("Value", None)
            if value == None:
                continue
            try:
                intVal = int(value)
            except ValueError:
                continue
            self[name] = intVal

        return
Esempio n. 28
0
    def load(self, xmlFile):
        """
        _load_

        Load the XML values into this instance

        """
        content = loadIMProvFile(xmlFile)
        for node in content.children:
            name = str(node.name)
            value = node.attrs.get("Value", None)
            if value == None:
                continue
            try:
                intVal = int(value)
            except ValueError:
                continue
            self[name] = intVal

        return
Esempio n. 29
0
    def showLogging(self, filepath):
        from IMProv.IMProvLoader import loadIMProvFile
        from IMProv.IMProvQuery import IMProvQuery

        rootag = "InternalLogInfo"
        keystag = "Keys"
        eventag = "Event"

        gotit = loadIMProvFile(filepath)
        k4v = IMProvQuery(keystag)
        nodiparam = k4v(gotit)

        tags = []
        for item in nodiparam:
            tags = eval(item.attrs.get("tags"))

        param = IMProvQuery(eventag)
        nodiparam = param(gotit)

        html = "<html><body><h2>Internal server logging for task: " + str(self.taskname) + "</h2>\n "
        html += '<table cellspacing="10">\n'

        textcolor = ""
        for item in nodiparam:
            if item.attrs.has_key("ev"):
                html += '<tr><td colspan="2">Event: <b>' + item.attrs.get("ev") + "</b></td></tr>\n"
            else:
                html += '<tr><td colspan="2">Event: <b>Unknown</b></td></tr>\n'
            for key in tags:
                value = item.attrs.get(key)
                if key is not "ev" and value is not None and len(str(value)) > 0:
                    if key in ["exc", "error"]:
                        textcolor = "<font color='FF0000'>%s<font>" % (value)
                    else:
                        textcolor = value
                    html += '<tr> <td align="right">%s: </td><td>%s</td></tr>\n' % (key, textcolor)

        html += "</table>"
        html += "</body>"

        return html
Esempio n. 30
0
    def load(self, directory):
        """
        _load_

        Load this instance given the workflow and directory containing
        the persistency file

        """
        fname = os.path.join(
            directory,
            "%s-Persist.xml" % self.workflowSpec.workflowName()
            )

        try:
            node = loadIMProvFile(fname)
        except Exception, ex:
            msg = "ERROR: Corrupted Persistency File:\n"
            msg += "  => %s\n" % fname
            msg += "Cannot be read:\n  => %s\n" % str(ex)
            logging.error(msg)
            return
Esempio n. 31
0
    def loadRunResDB(self):
        """
        _loadRunResDB_

        If the RunResDB file exists, load it

        """
        if not os.path.exists(self.runresdb):
            return
        improvNode = loadIMProvFile(self.runresdb)
        self._RunResDB = RunResComponent()
        self._RunResDB.children = improvNode.children
        self.runresLoaded = True

        dbDict = self._RunResDB.toDictionary()
        self.taskAttrs['Name'] = dbDict.keys()[0]
        tName = self.taskAttrs['Name']

        self.taskAttrs['WorkflowSpecID'] = \
                 dbDict[tName]['WorkflowSpecID'][0]
        self.taskAttrs['JobSpecID'] = \
                 dbDict[tName]['JobSpecID'][0]
        self.taskAttrs['JobType'] = \
                      dbDict[tName]['JobType'][0]

        if not dbDict[tName].has_key('SizeBasedMerge'):
            return
        doSizeMerge = dbDict[tName]['SizeBasedMerge'].get("DoSizeMerge", [])
        if len(doSizeMerge) > 0:
            if str(doSizeMerge[0]).lower() == "true":
                self.taskAttrs["DoSizeMerge"] = True

        mergeSize = dbDict[tName]['SizeBasedMerge'].get("MinMergeFileSize", [])
        if len(mergeSize) > 0:
            size = int(mergeSize[0])
            self.taskAttrs["MinMergeFileSize"] = size


        return
Esempio n. 32
0
    def load(self, url):
        """
        _load_

        Read a tfc into this instance

        """
        self.lfnToPfn = []
        self.pfnToLfn = []
        self.preferredProtocol = tfcProtocol(url)
        filename = tfcFilename(url)
        
        if not os.path.exists(filename):
            msg = "TrivialFileCatalog not found: %s" % filename
            raise RuntimeError, msg

        try:
            node = loadIMProvFile(filename)
        except StandardError, ex:
            msg = "Error reading TrivialFileCatalog: %s\n" % filename
            msg += str(ex)
            raise RuntimeError, msg
Esempio n. 33
0
    def load(self, url):
        """
        _load_

        Read a tfc into this instance

        """
        self.lfnToPfn = []
        self.pfnToLfn = []
        self.preferredProtocol = tfcProtocol(url)
        filename = tfcFilename(url)

        if not os.path.exists(filename):
            msg = "TrivialFileCatalog not found: %s" % filename
            raise RuntimeError, msg

        try:
            node = loadIMProvFile(filename)
        except StandardError, ex:
            msg = "Error reading TrivialFileCatalog: %s\n" % filename
            msg += str(ex)
            raise RuntimeError, msg
Esempio n. 34
0
    def loadRunResDB(self):
        """
        _loadRunResDB_

        If the RunResDB file exists, load it

        """
        if not os.path.exists(self.runresdb):
            return
        improvNode = loadIMProvFile(self.runresdb)
        self._RunResDB = RunResComponent()
        self._RunResDB.children = improvNode.children
        self.runresLoaded = True

        dbDict = self._RunResDB.toDictionary()
        self.taskAttrs['Name'] = dbDict.keys()[0]
        tName = self.taskAttrs['Name']

        self.taskAttrs['WorkflowSpecID'] = \
                 dbDict[tName]['WorkflowSpecID'][0]
        self.taskAttrs['JobSpecID'] = \
                 dbDict[tName]['JobSpecID'][0]
        self.taskAttrs['JobType'] = \
                      dbDict[tName]['JobType'][0]

        if not dbDict[tName].has_key('SizeBasedMerge'):
            return
        doSizeMerge = dbDict[tName]['SizeBasedMerge'].get("DoSizeMerge", [])
        if len(doSizeMerge) > 0:
            if str(doSizeMerge[0]).lower() == "true":
                self.taskAttrs["DoSizeMerge"] = True

        mergeSize = dbDict[tName]['SizeBasedMerge'].get("MinMergeFileSize", [])
        if len(mergeSize) > 0:
            size = int(mergeSize[0])
            self.taskAttrs["MinMergeFileSize"] = size

        return