Ejemplo n.º 1
0
    def algorithm(self, parameters = None):
        """
    	Performs the handleErrors method, looking for each type of failure
    	And deal with it as desired.
        """
        filesCache = {}
        currentTime = time.time()
        pendingASOJobs = self.getJobsAction.execute(state = "asopending")
        
        for job_id in pendingASOJobs:
            workflow = self.getWorkflowNameFromJobId(job_id)
            self.logger.info("Processing %s from %s" % \
                                (job_id, workflow) )

            job = Job( id = job_id )
            job.load()
            jobReport = Report()
            jobReportPath = job['fwjr_path']
            try:
                jobReportPath = jobReportPath.replace("file://","")
                jobReport.load( jobReportPath )
            except Exception, _:
                # if we got here, we must've used to have had a FWJR, knock it back
                # to the JobAccountant, they can deal with it
                logging.info( "ASOTracker: %s has no FWJR, but it should if we got here" % job['id'])
                # FIXME Should find out how to store errors so the outside will see
                self.stateChanger.propagate(job, "complete", "asopending")
                continue
            
            # retrieve all the files for this workflow, if it exists
            if not workflow in filesCache:
                query = { 'startkey' : [workflow, int(self.lastMonitoringTimestamp - 120)],
                          'endkey' : [workflow, int(currentTime) + 1],
                          'reduce' : False }
                monFiles = self.asoMonDB.loadView('UserMonitoring',\
                                                  'FilesByWorkflow',\
                                                  query)
                self.logger.info("Got this for files %s using %s" % (monFiles, query))
                oneCache = {}
                for oneFile in monFiles['rows']:
                    # Store the timestamp for the transferred file
                    
                    #newPfn = self.apply_tfc_to_lfn('%s:%s' % (destination, item['value'].replace('store/temp', 'store', 1)))
                    print "PRESERVE LFN1 %s %s" % (oneFile['value']['lfn'], oneFile['value'].get('preserve_lfn', False))
                    if oneFile['value'].get("preserve_lfn", False) == False:
                        lfn = oneFile['value']['lfn'].replace('store/temp', 'store', 1)
                    else:
                        lfn = oneFile['value']['lfn']

                    oneCache[lfn] = \
                                { 'state' : oneFile['value']['state'],
                                  'lfn'   : lfn,
                                  'location' : self.phedexApi.getNodeSE( oneFile['value']['location'] )}
                      
                filesCache[workflow] = oneCache
                asoFiles = oneCache
            else:
                asoFiles = filesCache[workflow]
                       
            allFiles = jobReport.getAllFileRefs()
            
            # Look through each job state and update it
            filesFailed = False
            asoComplete = True
            for fwjrFile in allFiles:
                print "PRESERVE LFN2 %s %s" % (fwjrFile.lfn, getattr(fwjrFile, 'preserve_lfn', False))
                if getattr(fwjrFile, "preserve_lfn", False) == False:
                    lfn = fwjrFile.lfn.replace('store/temp', 'store', 1)
                else:
                    lfn = fwjrFile.lfn
                #lfn = fwjrFile.lfn
                # if we wanted ASO, ASO is complete and the LFN is there
                if getattr(fwjrFile, "async_dest", None) and \
                    not getattr(fwjrFile, "asyncStatus", None):
                    
                    if not lfn in asoFiles:
                        asoComplete = False
                        continue
                    
                    if asoFiles[lfn]['state'] == 'done':
                        fwjrFile.asyncStatus = 'Success'
                        fwjrFile.lfn = lfn
                        fwjrFile.location    = asoFiles[lfn]['location']
                        jobReport.save( jobReportPath )
                    elif asoFiles[lfn]['state'] == 'failed':
                        # TODO: need to propagate diagnostic info here
                        fwjrFile.asyncStatus = 'Failed'
                        jobReport.save( jobReportPath )
                        filesFailed = True
                    else:
                        asoComplete = False
                    
            
            # Obviously need to change this to query the info from ASO
            #   if a job failed, send it to asofailed instead
            if asoComplete:
                if not filesFailed:
                    self.stateChanger.propagate(job, "complete", "asopending")
                else:
                    self.stateChanger.propagate(job, "asofailed", "asopending")