ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ReportUploader.py
Revision: 1.3
Committed: Mon Nov 1 09:46:20 2010 UTC (14 years, 5 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.2: +27 -21 lines
Log Message:
Few fixes: link to central server removed, don't crash with no server mode, using proper central link

File Contents

# Content
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 uploadFileServer = "http://gangamon.cern.ch/django/cmserrorreports/"
12 dashbtaskmon = 'http://dashb-cms-job-task.cern.ch/taskmon.html'
13 #centralservermon = 'http://glidein-mon.t2.ucsd.edu:8080/dashboard/ajaxproxy.jsp?p='
14
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 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
38
39 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 val = getCentralConfigLink('reportLogURL')
66 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 val = getCentralConfigLink('dashbTaskMon')
71 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 #val = getCentralConfigLink('servTaskMon')
76 #if val is not None and len(val) > 0:
77 # self.centralservermon = val
78 #common.logger.debug('Using %s as link for central server monitoring (it allows to bypass cern firewall)' % self.centralservermon )
79
80
81 def __prepareMetadata( self, datafile ):
82 """
83 __prepareMetadata
84
85 preparing metadata file content for errorreport server
86 """
87
88 fmeta = open(datafile, 'w')
89 strmeta = 'username:%s\n' % self.username + \
90 'version:%s\n' % '%s_%s' % (common.prog_name.upper(), common.prog_version_str) + \
91 'jobuuid:%s\n' % self.taskname + \
92 'monitoringlink:Dashboard monitoring,%s%s \n' %(self.dashbtaskmon,self.taskname) # + \
93 if self.server_name != 'No server':
94 cservermon = 'http://%s:8888/visualog/?logtype=Status&taskname=%s\n' % (self.server_name, self.taskname)
95 strmeta += 'monitoringlink:CrabServer monitoring,%s\n' % cservermon # + \
96 #'monitoringlink:CentralServer monitoring,%s%s\n' % (self.centralservermon, cservermon.replace('logtype=Status&', 'logtype=Status|')) + \
97
98 fmeta.write( strmeta )
99 fmeta.close()
100
101 common.logger.debug( "Metadatafile created as %s " % fmeta.name )
102
103 return fmeta.name
104
105
106 def __prepareSummary( self, datafile ):
107 """
108 __prepareSummary
109
110 preparing Summary file for errorreport server
111 """
112
113 fsummary = open(datafile, 'w')
114 ## version could be replaced by common.prog_name + common.prog_version_str
115 fsummary.write(
116 'username: %s\n' % self.username + \
117 'running on: %s\n' % self.hostname + \
118 'version: %s\n' % os.path.basename(os.path.normpath(os.getenv('CRABDIR'))) + \
119 'user working dir: %s\n' % self.taskname + \
120 'scheduler: %s\n' % self.scheduler + \
121 'requested server: %s\n' % self.requestedserver + \
122 'used server: %s\n' % self.server_name + \
123 'task: %s\n' % self.taskname
124 )
125 fsummary.close()
126
127 common.logger.debug( "Summary file created as %s " % fsummary.name )
128
129 return fsummary.name
130
131 def run( self ):
132 """
133 _run_
134
135 Method that performs the upload with the various steps:
136 - prepares metadata file
137 - prepare summary info file
138 - checks if the input files exists
139 - prepares the package
140 - uploads the package
141 """
142
143 common.logger.info("Preparing directory and files to report...")
144
145 archivereport = self.username + '-' + 'uploader.zip'
146 common.logger.debug("Archivereport %s" % archivereport)
147
148 basename = os.path.basename(os.path.normpath(self.taskpath))
149 dirname = 'crabreport_' + (str(datetime.today())).replace(' ', '-')
150 self.crabreportdir = self.taskpath + '/' + dirname
151
152 cmd = 'cd %s; mkdir %s; cd %s; ' % (self.taskpath, dirname, dirname)
153 common.logger.debug("Running '%s' " % cmd)
154 out = runCommand( cmd )
155 common.logger.debug("Result '%s'" % str(out))
156
157 metadataFile = self.__prepareMetadata(self.crabreportdir + '/__metadata.txt')
158 summaryFile = self.__prepareSummary(self.crabreportdir + '/_summary.txt')
159
160 cmd = "cd %s;" % self.crabreportdir
161 for filetemp in self.filetoup:
162 if os.path.exists( filetemp ) is True :
163 cmd += 'ln -s %s %s.txt; ' % ( filetemp, os.path.basename( filetemp ) )
164 common.logger.debug("File %s found and added" % filetemp)
165 else:
166 common.logger.debug("File %s not found, skipping it!" % filetemp)
167
168 common.logger.debug("Running '%s' " % cmd)
169 out = runCommand( cmd )
170 common.logger.debug("Result '%s'" % str(out))
171
172 common.logger.debug("Zipping...")
173 cmd = 'cd %s; zip -l %s %s/*' % (self.taskpath, archivereport, self.crabreportdir)
174 common.logger.debug("Running '%s' " % cmd)
175 out = runCommand( cmd )
176 common.logger.debug("Result '%s'" % str(out))
177
178 try:
179 common.logger.info("Starting to upload the report...")
180 link_result = run_upload(server = self.uploadFileServer, path = '%s/%s' % (self.taskpath, archivereport) )
181 if link_result is not None and len(link_result) > 0:
182 common.logger.info("Your report was uploaded to the central repository")
183 common.logger.info("Please include this URL in your bug report or in the support e-mail")
184 common.logger.info( "\t %s\n" % str(link_result))
185 else:
186 common.logger.error("A problem occurred while uploading your report to the central repository!")
187 except Exception, ex:
188 raise CrabException("Problem %s uploading log files to %s" % (str(ex), self.uploadFileServer) )
189 finally:
190 common.logger.debug("Start cleaning report...")
191 cmd = 'rm -rf %s %s/%s' % (self.crabreportdir, self.taskpath, archivereport)
192 common.logger.debug("Running '%s' " % cmd)
193 out = runCommand( cmd )
194 common.logger.debug("Result '%s'" % str(out))
195
196 common.logger.info("Report upload finished.")
197