ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Publisher.py
(Generate patch)

Comparing COMP/CRAB/python/Publisher.py (file contents):
Revision 1.11.4.1 by fanzago, Fri Jul 4 14:01:01 2008 UTC vs.
Revision 1.41 by fanzago, Tue Sep 22 15:15:36 2009 UTC

# Line 3 | Line 3 | import common
3   import time, glob
4   from Actor import *
5   from crab_util import *
6 from crab_logger import Logger
6   from crab_exceptions import *
7   from ProdCommon.FwkJobRep.ReportParser import readJobReport
8 + from ProdCommon.FwkJobRep.ReportState import checkSuccess
9   from ProdCommon.MCPayloads.WorkflowSpec import WorkflowSpec
10   from ProdCommon.DataMgmt.DBS.DBSWriter import DBSWriter
11   from ProdCommon.DataMgmt.DBS.DBSErrors import DBSWriterError, formatEx,DBSReaderError
12   from ProdCommon.DataMgmt.DBS.DBSReader import DBSReader
13   from ProdCommon.DataMgmt.DBS.DBSWriter import DBSWriter,DBSWriterObjects
14   import sys
15 + from DBSAPI.dbsApiException import DbsException
16 + from DBSAPI.dbsApi import DbsApi
17  
18   class Publisher(Actor):
19      def __init__(self, cfg_params):
# Line 23 | Line 25 | class Publisher(Actor):
25          - publishes output data on DBS and DLS
26          """
27  
28 <        try:
29 <            self.processedData = cfg_params['USER.publish_data_name']
30 <        except KeyError:
28 >        self.cfg_params=cfg_params
29 >      
30 >        if not cfg_params.has_key('USER.publish_data_name'):
31              raise CrabException('Cannot publish output data, because you did not specify USER.publish_data_name parameter in the crab.cfg file')
32 +        self.userprocessedData = cfg_params['USER.publish_data_name']
33 +        self.processedData = None
34  
35 <        try:
36 <            if (int(cfg_params['USER.copy_data']) != 1): raise KeyError
37 <        except KeyError:
38 <            raise CrabException('You can not publish data because you did not selected *** copy_data = 1  *** in the crab.cfg file')
39 <        try:
40 <            self.pset = cfg_params['CMSSW.pset']
41 <        except KeyError:
35 >        if (not cfg_params.has_key('USER.copy_data') or int(cfg_params['USER.copy_data']) != 1 ) or \
36 >            (not cfg_params.has_key('USER.publish_data') or int(cfg_params['USER.publish_data']) != 1 ):
37 >            msg  = 'You can not publish data because you did not selected \n'
38 >            msg += '\t*** copy_data = 1 and publish_data = 1  *** in the crab.cfg file'
39 >            raise CrabException(msg)
40 >
41 >        if not cfg_params.has_key('CMSSW.pset'):
42              raise CrabException('Cannot publish output data, because you did not specify the psetname in [CMSSW] of your crab.cfg file')
43 <        try:
44 <            self.globalDBS=cfg_params['CMSSW.dbs_url']
45 <        except KeyError:
46 <            self.globalDBS="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
47 <        try:
44 <            self.DBSURL=cfg_params['USER.dbs_url_for_publication']
45 <            common.logger.message('<dbs_url_for_publication> = '+self.DBSURL)
46 <            if (self.DBSURL == "http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet") or (self.DBSURL == "https://cmsdbsprod.cern.ch:8443/cms_dbs_prod_global_writer/servlet/DBSServlet"):
47 <                msg = "You can not publish your data in the globalDBS = " + self.DBSURL + "\n"
48 <                msg = msg + "Please write your local one in the [USER] section 'dbs_url_for_publication'"
49 <                raise CrabException(msg)
50 <        except KeyError:
43 >        self.pset = cfg_params['CMSSW.pset']
44 >
45 >        self.globalDBS=cfg_params.get('CMSSW.dbs_url',"http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet")
46 >
47 >        if not cfg_params.has_key('USER.dbs_url_for_publication'):
48              msg = "Warning. The [USER] section does not have 'dbs_url_for_publication'"
49              msg = msg + " entry, necessary to publish the data.\n"
50              msg = msg + "Use the command **crab -publish -USER.dbs_url_for_publication=dbs_url_for_publication*** \nwhere dbs_url_for_publication is your local dbs instance."
51              raise CrabException(msg)
52 +
53 +        self.DBSURL=cfg_params['USER.dbs_url_for_publication']
54 +        common.logger.info('<dbs_url_for_publication> = '+self.DBSURL)
55 +        if (self.DBSURL == "http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet") or (self.DBSURL == "https://cmsdbsprod.cern.ch:8443/cms_dbs_prod_global_writer/servlet/DBSServlet"):
56 +            msg = "You can not publish your data in the globalDBS = " + self.DBSURL + "\n"
57 +            msg = msg + "Please write your local one in the [USER] section 'dbs_url_for_publication'"
58 +            raise CrabException(msg)
59              
60          self.content=file(self.pset).read()
61          self.resDir = common.work_space.resDir()
# Line 70 | Line 74 | class Publisher(Actor):
74                  dataset=string.strip(dataset)
75                  self.dataset_to_import.append(dataset)
76          ###        
77 <                
77 >            
78 >        self.import_all_parents = cfg_params.get('USER.publish_with_import_all_parents',1)
79 >        self.skipOcheck=cfg_params.get('CMSSW.publish_zero_event',0)
80 >    
81          self.SEName=''
82          self.CMSSW_VERSION=''
83          self.exit_status=''
# Line 81 | Line 88 | class Publisher(Actor):
88          
89      def importParentDataset(self,globalDBS, datasetpath):
90          """
91 <        """
91 >        """
92          dbsWriter = DBSWriter(self.DBSURL,level='ERROR')
93          
94          try:
95 <            dbsWriter.importDatasetWithoutParentage(globalDBS, self.datasetpath, self.DBSURL)
95 >            if (self.import_all_parents==1):
96 >                common.logger.info("--->>> Importing all parents level")
97 >                ### to skip the ProdCommon api exception in the case of block without location
98 >                ### skipNoSiteError=True
99 >                dbsWriter.importDataset(globalDBS, datasetpath, self.DBSURL, skipNoSiteError=True)
100 >            else:
101 >                common.logger.info("--->>> Importing only the datasetpath " + datasetpath)
102 >                dbsWriter.importDatasetWithoutParentage(globalDBS, datasetpath, self.DBSURL, skipNoSiteError=True)
103          except DBSWriterError, ex:
104              msg = "Error importing dataset to be processed into local DBS\n"
105              msg += "Source Dataset: %s\n" % datasetpath
106              msg += "Source DBS: %s\n" % globalDBS
107              msg += "Destination DBS: %s\n" % self.DBSURL
108 <            common.logger.message(msg)
108 >            common.logger.info(msg)
109 >            common.logger.debug(str(ex))
110              return 1
111          return 0
112 <          
112 >        """
113 >        print " patch for importParentDataset: datasetpath = ", datasetpath
114 >        try:
115 >            args={}
116 >            args['url']=self.DBSURL
117 >            args['mode']='POST'
118 >            block = ""
119 >            api = DbsApi(args)
120 >            #api.migrateDatasetContents(srcURL, dstURL, path, block , False)
121 >            api.migrateDatasetContents(globalDBS, self.DBSURL, datasetpath, block , False)
122 >
123 >        except DbsException, ex:
124 >            print "Caught API Exception %s: %s "  % (ex.getClassName(), ex.getErrorMessage() )
125 >            if ex.getErrorCode() not in (None, ""):
126 >                print "DBS Exception Error Code: ", ex.getErrorCode()
127 >            return 1
128 >        print "Done"
129 >        return 0
130 >        """  
131      def publishDataset(self,file):
132          """
133          """
# Line 104 | Line 137 | class Publisher(Actor):
137          except IndexError:
138              self.exit_status = '1'
139              msg = "Error: Problem with "+file+" file"  
140 <            common.logger.message(msg)
140 >            common.logger.info(msg)
141              return self.exit_status
142  
143          if (len(self.dataset_to_import) != 0):
144             for dataset in self.dataset_to_import:
145 <               common.logger.message("--->>> Importing parent dataset in the dbs: " +dataset)
145 >               common.logger.info("--->>> Importing parent dataset in the dbs: " +dataset)
146                 status_import=self.importParentDataset(self.globalDBS, dataset)
147                 if (status_import == 1):
148 <                   common.logger.message('Problem with parent '+ dataset +' import from the global DBS '+self.globalDBS+ 'to the local one '+self.DBSURL)
148 >                   common.logger.info('Problem with parent '+ dataset +' import from the global DBS '+self.globalDBS+ 'to the local one '+self.DBSURL)
149                     self.exit_status='1'
150                     return self.exit_status
151                 else:    
152 <                   common.logger.message('Import ok of dataset '+dataset)
152 >                   common.logger.info('Import ok of dataset '+dataset)
153              
154          #// DBS to contact
155          dbswriter = DBSWriter(self.DBSURL)                        
# Line 126 | Line 159 | class Publisher(Actor):
159          except IndexError:
160              self.exit_status = '1'
161              msg = "Error: No file to publish in xml file"+file+" file"  
162 <            common.logger.message(msg)
162 >            common.logger.info(msg)
163              return self.exit_status
164  
165          datasets=fileinfo.dataset
166 <        common.logger.debug(6,"FileInfo = " + str(fileinfo))
167 <        common.logger.debug(6,"DatasetInfo = " + str(datasets))
166 >        common.logger.log(10-1,"FileInfo = " + str(fileinfo))
167 >        common.logger.log(10-1,"DatasetInfo = " + str(datasets))
168 >        if len(datasets)<=0:
169 >           self.exit_status = '1'
170 >           msg = "Error: No info about dataset in the xml file "+file
171 >           common.logger.info(msg)
172 >           return self.exit_status
173          for dataset in datasets:
174              #### for production data
175 +            self.processedData = dataset['ProcessedDataset']
176              if (dataset['PrimaryDataset'] == 'null'):
177 <                dataset['PrimaryDataset'] = dataset['ProcessedDataset']
178 <                
177 >                #dataset['PrimaryDataset'] = dataset['ProcessedDataset']
178 >                dataset['PrimaryDataset'] = self.userprocessedData
179 >            #else: # add parentage from input dataset
180 >            elif self.datasetpath.upper() != 'NONE':
181 >                dataset['ParentDataset']= self.datasetpath
182 >    
183              dataset['PSetContent']=self.content
184              cfgMeta = {'name' : self.pset , 'Type' : 'user' , 'annotation': 'user cfg', 'version' : 'private version'} # add real name of user cfg
185 <            common.logger.message("PrimaryDataset = %s"%dataset['PrimaryDataset'])
186 <            common.logger.message("ProcessedDataset = %s"%dataset['ProcessedDataset'])
187 <            common.logger.message("<User Dataset Name> = /"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER")
185 >            common.logger.info("PrimaryDataset = %s"%dataset['PrimaryDataset'])
186 >            common.logger.info("ProcessedDataset = %s"%dataset['ProcessedDataset'])
187 >            common.logger.info("<User Dataset Name> = /"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER")
188 >            self.dataset_to_check="/"+dataset['PrimaryDataset']+"/"+dataset['ProcessedDataset']+"/USER"
189              
190 <            common.logger.debug(6,"--->>> Inserting primary: %s processed : %s"%(dataset['PrimaryDataset'],dataset['ProcessedDataset']))
190 >            common.logger.log(10-1,"--->>> Inserting primary: %s processed : %s"%(dataset['PrimaryDataset'],dataset['ProcessedDataset']))
191              
192              primary = DBSWriterObjects.createPrimaryDataset( dataset, dbswriter.dbs)
193 <            common.logger.debug(6,"Primary:  %s "%primary)
193 >            common.logger.log(10-1,"Primary:  %s "%primary)
194              
195              algo = DBSWriterObjects.createAlgorithm(dataset, cfgMeta, dbswriter.dbs)
196 <            common.logger.debug(6,"Algo:  %s "%algo)
196 >            common.logger.log(10-1,"Algo:  %s "%algo)
197  
198              processed = DBSWriterObjects.createProcessedDataset(primary, algo, dataset, dbswriter.dbs)
199 <            common.logger.debug(6,"Processed:  %s "%processed)
199 >            common.logger.log(10-1,"Processed:  %s "%processed)
200              
201 <            common.logger.debug(6,"Inserted primary %s processed %s"%(primary,processed))
201 >            common.logger.log(10-1,"Inserted primary %s processed %s"%(primary,processed))
202              
203 <        common.logger.debug(6,"exit_status = %s "%self.exit_status)
203 >        common.logger.log(10-1,"exit_status = %s "%self.exit_status)
204          return self.exit_status    
205  
206      def publishAJobReport(self,file,procdataset):
# Line 181 | Line 225 | class Publisher(Actor):
225              elif (file['LFN'] == ''):
226                  self.noLFN.append(file['PFN'])
227              else:
228 <                if int(file['TotalEvents']) != 0 :
229 <                    file.lumisections = {}
228 >                if  self.skipOcheck==0:
229 >                    if int(file['TotalEvents']) != 0:
230 >                        #file.lumisections = {}
231 >                        # lumi info are now in run hash
232 >                        file.runs = {}
233 >                        for ds in file.dataset:
234 >                            ### Fede for production
235 >                            if (ds['PrimaryDataset'] == 'null'):
236 >                                #ds['PrimaryDataset']=procdataset
237 >                                ds['PrimaryDataset']=self.userprocessedData
238 >                        filestopublish.append(file)
239 >                    else:
240 >                        self.noEventsFiles.append(file['LFN'])
241 >                else:
242 >                    file.runs = {}
243                      for ds in file.dataset:
187                        ds['ProcessedDataset']=procdataset
244                          ### Fede for production
245                          if (ds['PrimaryDataset'] == 'null'):
246 <                            ds['PrimaryDataset']=procdataset
246 >                            #ds['PrimaryDataset']=procdataset
247 >                            ds['PrimaryDataset']=self.userprocessedData
248                      filestopublish.append(file)
249 <                else:
193 <                    self.noEventsFiles.append(file['LFN'])
249 >      
250          jobReport.files = filestopublish
251          ### if all files of FJR have number of events = 0
252          if (len(filestopublish) == 0):
# Line 202 | Line 258 | class Publisher(Actor):
258          Blocks=None
259          try:
260              Blocks=dbswriter.insertFiles(jobReport)
261 <            common.logger.message("Blocks = %s"%Blocks)
261 >            common.logger.info("Inserting file in blocks = %s"%Blocks)
262          except DBSWriterError, ex:
263 <            common.logger.message("Insert file error: %s"%ex)
263 >            common.logger.info("Insert file error: %s"%ex)
264          return Blocks
265  
266      def run(self):
# Line 213 | Line 269 | class Publisher(Actor):
269          """
270          
271          file_list = glob.glob(self.resDir+"crab_fjr*.xml")
272 <        common.logger.debug(6, "file_list = "+str(file_list))
273 <        common.logger.debug(6, "len(file_list) = "+str(len(file_list)))
272 >        ## Select only those fjr that are succesfull
273 >        if (len(file_list)==0):
274 >            common.logger.info("--->>> "+self.resDir+" empty: no file to publish on DBS")
275 >            self.exit_status = '1'
276 >            return self.exit_status
277 >
278 >        good_list=[]
279 >        for fjr in file_list:
280 >            reports = readJobReport(fjr)
281 >            if len(reports)>0:
282 >               if reports[0].status == "Success":
283 >                  good_list.append(fjr)
284 >        file_list=good_list
285 >        ##
286 >        common.logger.log(10-1, "file_list = "+str(file_list))
287 >        common.logger.log(10-1, "len(file_list) = "+str(len(file_list)))
288              
289          if (len(file_list)>0):
290              BlocksList=[]
291 <            common.logger.message("--->>> Start dataset publication")
291 >            common.logger.info("--->>> Start dataset publication")
292              self.exit_status=self.publishDataset(file_list[0])
293              if (self.exit_status == '1'):
294                  return self.exit_status
295 <            common.logger.message("--->>> End dataset publication")
295 >            common.logger.info("--->>> End dataset publication")
296  
297  
298 <            common.logger.message("--->>> Start files publication")
298 >            common.logger.info("--->>> Start files publication")
299              for file in file_list:
300 <                common.logger.message("file = "+file)
300 >                common.logger.debug( "file = "+file)
301                  Blocks=self.publishAJobReport(file,self.processedData)
302                  if Blocks:
303 <                    [BlocksList.append(x) for x in Blocks]
303 >                    for x in Blocks: # do not allow multiple entries of the same block
304 >                        if x not in BlocksList:
305 >                           BlocksList.append(x)
306                      
307              # close the blocks
308 <            common.logger.debug(6, "BlocksList = %s"%BlocksList)
308 >            common.logger.log(10-1, "BlocksList = %s"%BlocksList)
309              # dbswriter = DBSWriter(self.DBSURL,level='ERROR')
310              dbswriter = DBSWriter(self.DBSURL)
311              
312              for BlockName in BlocksList:
313                  try:  
314                      closeBlock=dbswriter.manageFileBlock(BlockName,maxFiles= 1)
315 <                    common.logger.debug(6, "closeBlock %s"%closeBlock)
315 >                    common.logger.log(10-1, "closeBlock %s"%closeBlock)
316                      #dbswriter.dbs.closeBlock(BlockName)
317                  except DBSWriterError, ex:
318 <                    common.logger.message("Close block error %s"%ex)
318 >                    common.logger.info("Close block error %s"%ex)
319  
320              if (len(self.noEventsFiles)>0):
321 <                common.logger.message("--->>> WARNING: "+str(len(self.noEventsFiles))+" files not published because they contain 0 events are:")
321 >                common.logger.info("--->>> WARNING: "+str(len(self.noEventsFiles))+" files not published because they contain 0 events are:")
322                  for lfn in self.noEventsFiles:
323 <                    common.logger.message("------ LFN: %s"%lfn)
323 >                    common.logger.info("------ LFN: %s"%lfn)
324              if (len(self.noLFN)>0):
325 <                common.logger.message("--->>> WARNING: there are "+str(len(self.noLFN))+" files not published because they have empty LFN")
325 >                common.logger.info("--->>> WARNING: there are "+str(len(self.noLFN))+" files not published because they have empty LFN")
326                  for pfn in self.noLFN:
327 <                    common.logger.message("------ pfn: %s"%pfn)
327 >                    common.logger.info("------ pfn: %s"%pfn)
328              if (len(self.problemFiles)>0):
329 <                common.logger.message("--->>> WARNING: "+str(len(self.problemFiles))+" files not published because they had problem with copy to SE")
329 >                common.logger.info("--->>> WARNING: "+str(len(self.problemFiles))+" files not published because they had problem with copy to SE")
330                  for lfn in self.problemFiles:
331 <                    common.logger.message("------ LFN: %s"%lfn)
332 <            common.logger.message("--->>> End files publication")
333 <            common.logger.message("--->>> To check data publication please use: InspectDBS2.py --DBSURL=<dbs_url_for_publication> --datasetPath=<User Dataset Name>")
331 >                    common.logger.info("------ LFN: %s"%lfn)
332 >            common.logger.info("--->>> End files publication")
333 >          
334 >            self.cfg_params['USER.dataset_to_check']=self.dataset_to_check
335 >            from InspectDBS import InspectDBS
336 >            check=InspectDBS(self.cfg_params)
337 >            check.checkPublication()
338              return self.exit_status
339  
340          else:
341 <            common.logger.message("--->>> "+self.resDir+" empty: no file to publish on DBS")
341 >            common.logger.info("--->>> No valid files to publish on DBS. Your jobs do not report exit codes = 0")
342              self.exit_status = '1'
343              return self.exit_status
344      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines