ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ReportUploader.py
Revision: 1.5
Committed: Fri Jan 7 15:55:22 2011 UTC (14 years, 3 months ago) by belforte
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_7_7_patch1, CRAB_2_7_7_patch1_pre1, CRAB_2_7_7, CRAB_2_7_7_pre2, CRAB_2_7_7_pre1
Changes since 1.4: +5 -9 lines
Log Message:
add link to CrabServer Logging page, https://savannah.cern.ch/bugs/?74206

File Contents

# User Rev Content
1 mcinquil 1.1 from Actor import *
2     import common
3     from datetime import datetime
4     from crab_report import run_upload
5     from crab_util import *
6     import os
7     import socket
8    
9     class ReportUploader( Actor ):
10    
11 mcinquil 1.4 uploadFileServer = "http://analysisops.cern.ch/cmserrorreports"
12 mcinquil 1.1 dashbtaskmon = 'http://dashb-cms-job-task.cern.ch/taskmon.html'
13 mcinquil 1.3 #centralservermon = 'http://glidein-mon.t2.ucsd.edu:8080/dashboard/ajaxproxy.jsp?p='
14 mcinquil 1.1
15     def __init__(self, cfg_params, jobid = -1):
16     """
17     init class variables
18    
19     - checking if task exists
20     - adding task generic files
21     - adding job specific files
22     """
23    
24     common.logger.debug('Initializing uploader...')
25    
26     self.cfg_params = cfg_params
27    
28 mcinquil 1.3 try:
29     CliServerParams(self)
30     self.requestedserver = 'default'
31     if self.cfg_params.has_key("server_name"):
32     self.requestedserver = self.cfg_params['server_name']
33     except Exception, ex:
34     common.logger.debug("Problem '%s'" % str(ex))
35     self.server_name = 'No server'
36     self.requestedserver = 'No server'
37 mcinquil 1.1
38 mcinquil 1.3
39 mcinquil 1.1 self.taskpath = common.work_space.topDir()
40    
41     if os.path.exists( self.taskpath ) is True:
42    
43     self.filetoup = [ \
44     common.work_space.shareDir() + '/crab.cfg', \
45     common.work_space.logDir() + '/crab.log' \
46     ]
47    
48     if jobid > -1:
49     self.filetoup.append( common.work_space.resDir() + 'CMSSW_%i.stdout' % jobid )
50     self.filetoup.append( common.work_space.jobDir() + 'CMSSW_%i.LoggingInfo' % jobid )
51     self.filetoup.append( common.work_space.resDir() + 'crab_fjr_%i.xml' % jobid )
52    
53     else:
54     raise CrabException( 'Error: task [%s] not found in the path!' % self.taskname )
55    
56    
57     self.taskname = common._db.queryTask('name')
58    
59     self.hostname = socket.getfqdn()
60    
61     self.username = getUserName()
62    
63     self.scheduler = common.scheduler.name()
64    
65 mcinquil 1.3 val = getCentralConfigLink('reportLogURL')
66 mcinquil 1.1 if val is not None and len(val) > 0:
67     self.uploadFileServer = val
68     common.logger.debug('Using %s as remote repository server for uploading logs' % self )
69    
70 mcinquil 1.3 val = getCentralConfigLink('dashbTaskMon')
71 mcinquil 1.1 if val is not None and len(val) > 0:
72     self.dashbtaskmon = val
73     common.logger.debug('Using %s as link for dashboard task monitoring' % self.dashbtaskmon )
74    
75    
76     def __prepareMetadata( self, datafile ):
77     """
78     __prepareMetadata
79    
80     preparing metadata file content for errorreport server
81     """
82    
83     fmeta = open(datafile, 'w')
84 mcinquil 1.3 strmeta = 'username:%s\n' % self.username + \
85     'version:%s\n' % '%s_%s' % (common.prog_name.upper(), common.prog_version_str) + \
86     'jobuuid:%s\n' % self.taskname + \
87 belforte 1.5 'monitoringlink:Dashboard Task Mon,%s%s \n' %(self.dashbtaskmon,self.taskname) # + \
88 mcinquil 1.3 if self.server_name != 'No server':
89 belforte 1.5 cserverStatus = 'http://%s:8888/visualog/?logtype=Status&taskname=%s\n' % (self.server_name, self.taskname)
90     strmeta += 'monitoringlink:CrabServer Status,%s\n' % cserverStatus
91     cserverLog = 'http://%s:8888/visualog/?logtype=Logging&taskname=%s\n' % (self.server_name, self.taskname)
92     strmeta += 'monitoringlink:CrabServer Logging,%s\n' % cserverLog
93 mcinquil 1.3
94     fmeta.write( strmeta )
95 mcinquil 1.1 fmeta.close()
96    
97     common.logger.debug( "Metadatafile created as %s " % fmeta.name )
98    
99     return fmeta.name
100    
101    
102     def __prepareSummary( self, datafile ):
103     """
104     __prepareSummary
105    
106     preparing Summary file for errorreport server
107     """
108    
109     fsummary = open(datafile, 'w')
110     ## version could be replaced by common.prog_name + common.prog_version_str
111     fsummary.write(
112     'username: %s\n' % self.username + \
113     'running on: %s\n' % self.hostname + \
114     'version: %s\n' % os.path.basename(os.path.normpath(os.getenv('CRABDIR'))) + \
115     'user working dir: %s\n' % self.taskname + \
116     'scheduler: %s\n' % self.scheduler + \
117     'requested server: %s\n' % self.requestedserver + \
118     'used server: %s\n' % self.server_name + \
119     'task: %s\n' % self.taskname
120     )
121     fsummary.close()
122    
123     common.logger.debug( "Summary file created as %s " % fsummary.name )
124    
125     return fsummary.name
126    
127     def run( self ):
128     """
129     _run_
130    
131     Method that performs the upload with the various steps:
132     - prepares metadata file
133     - prepare summary info file
134     - checks if the input files exists
135     - prepares the package
136     - uploads the package
137     """
138    
139     common.logger.info("Preparing directory and files to report...")
140    
141     archivereport = self.username + '-' + 'uploader.zip'
142     common.logger.debug("Archivereport %s" % archivereport)
143    
144     basename = os.path.basename(os.path.normpath(self.taskpath))
145     dirname = 'crabreport_' + (str(datetime.today())).replace(' ', '-')
146     self.crabreportdir = self.taskpath + '/' + dirname
147    
148     cmd = 'cd %s; mkdir %s; cd %s; ' % (self.taskpath, dirname, dirname)
149     common.logger.debug("Running '%s' " % cmd)
150     out = runCommand( cmd )
151     common.logger.debug("Result '%s'" % str(out))
152    
153     metadataFile = self.__prepareMetadata(self.crabreportdir + '/__metadata.txt')
154     summaryFile = self.__prepareSummary(self.crabreportdir + '/_summary.txt')
155    
156     cmd = "cd %s;" % self.crabreportdir
157     for filetemp in self.filetoup:
158     if os.path.exists( filetemp ) is True :
159     cmd += 'ln -s %s %s.txt; ' % ( filetemp, os.path.basename( filetemp ) )
160     common.logger.debug("File %s found and added" % filetemp)
161     else:
162     common.logger.debug("File %s not found, skipping it!" % filetemp)
163    
164     common.logger.debug("Running '%s' " % cmd)
165     out = runCommand( cmd )
166     common.logger.debug("Result '%s'" % str(out))
167    
168     common.logger.debug("Zipping...")
169     cmd = 'cd %s; zip -l %s %s/*' % (self.taskpath, archivereport, self.crabreportdir)
170     common.logger.debug("Running '%s' " % cmd)
171     out = runCommand( cmd )
172     common.logger.debug("Result '%s'" % str(out))
173    
174     try:
175     common.logger.info("Starting to upload the report...")
176     link_result = run_upload(server = self.uploadFileServer, path = '%s/%s' % (self.taskpath, archivereport) )
177     if link_result is not None and len(link_result) > 0:
178     common.logger.info("Your report was uploaded to the central repository")
179     common.logger.info("Please include this URL in your bug report or in the support e-mail")
180     common.logger.info( "\t %s\n" % str(link_result))
181     else:
182     common.logger.error("A problem occurred while uploading your report to the central repository!")
183     except Exception, ex:
184     raise CrabException("Problem %s uploading log files to %s" % (str(ex), self.uploadFileServer) )
185     finally:
186     common.logger.debug("Start cleaning report...")
187     cmd = 'rm -rf %s %s/%s' % (self.crabreportdir, self.taskpath, archivereport)
188     common.logger.debug("Running '%s' " % cmd)
189     out = runCommand( cmd )
190     common.logger.debug("Result '%s'" % str(out))
191    
192     common.logger.info("Report upload finished.")
193