1 |
|
#!/usr/bin/env python |
2 |
< |
|
3 |
< |
import sys, getopt, string |
4 |
< |
import os, popen2 |
2 |
> |
import sys, os |
3 |
> |
try: |
4 |
> |
import json |
5 |
> |
except: |
6 |
> |
import simplejson as json |
7 |
|
from ProdCommon.Storage.SEAPI.SElement import SElement, FullPath |
8 |
|
from ProdCommon.Storage.SEAPI.SBinterface import * |
9 |
< |
|
9 |
> |
from ProdCommon.Storage.SEAPI.Exceptions import * |
10 |
|
|
11 |
|
|
12 |
|
class cmscp: |
13 |
< |
def __init__(self, argv): |
13 |
> |
def __init__(self, args): |
14 |
|
""" |
15 |
|
cmscp |
16 |
< |
|
15 |
< |
safe copy of local file in current directory to remote SE via lcg_cp/srmcp, |
16 |
> |
safe copy of local file to/from remote SE via lcg_cp/srmcp, |
17 |
|
including success checking version also for CAF using rfcp command to copy the output to SE |
18 |
|
input: |
19 |
|
$1 middleware (CAF, LSF, LCG, OSG) |
21 |
|
$3 if needed: file name (the output file name) |
22 |
|
$5 remote SE (complete endpoint) |
23 |
|
$6 srm version |
24 |
+ |
--for_lfn $LFNBaseName |
25 |
|
output: |
26 |
|
return 0 if all ok |
27 |
|
return 60307 if srmcp failed |
28 |
|
return 60303 if file already exists in the SE |
29 |
|
""" |
30 |
< |
#set default |
30 |
> |
self.params = {"source":'', "destination":'','destinationDir':'', "inputFileList":'', "outputFileList":'', \ |
31 |
> |
"protocol":'', "option":'', "middleware":'', "srm_version":'srmv2', "for_lfn":'', "se_name":'', "surl_for_grid":''} |
32 |
|
self.debug = 0 |
33 |
< |
self.source = '' |
34 |
< |
self.destination = '' |
35 |
< |
self.file_to_copy = [] |
36 |
< |
self.remote_file_name = [] |
37 |
< |
self.protocol = '' |
38 |
< |
self.middleware = '' |
39 |
< |
self.srmv = '' |
40 |
< |
|
41 |
< |
# default for stage out approach To be used with "middleware" |
42 |
< |
self.lcgOpt='-b -D srmv2 --vo cms -t 2400 --verbose' |
43 |
< |
self.srmOpt='-debug=true -report ./srmcp.report -retry_timeout 480000 -retry_num 3' |
44 |
< |
self.rfioOpt='' |
42 |
< |
# default to be used with protocol |
43 |
< |
self.opt='' |
44 |
< |
|
45 |
< |
try: |
46 |
< |
opts, args = getopt.getopt(argv, "", ["source=", "destination=", "inputFileList=", "outputFileList=", \ |
47 |
< |
"protocol=", "middleware=", "srm_version=", "debug", "help"]) |
48 |
< |
except getopt.GetoptError: |
49 |
< |
print self.usage() |
50 |
< |
sys.exit(2) |
51 |
< |
|
52 |
< |
self.setAndCheck(opts) |
33 |
> |
#### for fallback copy |
34 |
> |
self.local_stage = 0 |
35 |
> |
self.params.update( args ) |
36 |
> |
## timeout needed for subprocess command of SEAPI |
37 |
> |
## they should be a bit higher then the corresponding passed by command line |
38 |
> |
## default values |
39 |
> |
self.subprocesstimeout = { \ |
40 |
> |
'copy': 3600, \ |
41 |
> |
'exists': 1200, \ |
42 |
> |
'delete': 1200, \ |
43 |
> |
'size': 1200 \ |
44 |
> |
} |
45 |
|
|
46 |
|
return |
47 |
|
|
48 |
< |
def setAndCheck( self, opts ): |
48 |
> |
def processOptions( self ): |
49 |
|
""" |
50 |
< |
Set and check command line parameter |
50 |
> |
check command line parameter |
51 |
|
""" |
52 |
< |
if not opts : |
53 |
< |
print self.usage() |
54 |
< |
sys.exit() |
63 |
< |
for opt, arg in opts : |
64 |
< |
if opt == "--help" : |
65 |
< |
print self.usage() |
66 |
< |
sys.exit() |
67 |
< |
elif opt == "--debug" : |
68 |
< |
self.debug = 1 |
69 |
< |
elif opt == "--source" : |
70 |
< |
self.source = arg |
71 |
< |
elif opt == "--destination": |
72 |
< |
self.destination = arg |
73 |
< |
elif opt == "--inputFileList": |
74 |
< |
infile = arg |
75 |
< |
elif opt == "--outputFileList": |
76 |
< |
out_file |
77 |
< |
elif opt == "--protocol": |
78 |
< |
self.protocol = arg |
79 |
< |
elif opt == "--middleware": |
80 |
< |
self.middleware = arg |
81 |
< |
elif opt == "--srm_version": |
82 |
< |
self.srmv = arg |
52 |
> |
if 'help' in self.params.keys(): HelpOptions() |
53 |
> |
if 'debug' in self.params.keys(): self.debug = 1 |
54 |
> |
if 'local_stage' in self.params.keys(): self.local_stage = 1 |
55 |
|
|
56 |
|
# source and dest cannot be undefined at same time |
57 |
< |
if self.source == '' and self.destination == '': |
58 |
< |
print self.usage() |
87 |
< |
sys.exit() |
57 |
> |
if not self.params['source'] and not self.params['destination'] : |
58 |
> |
HelpOptions() |
59 |
|
# if middleware is not defined --> protocol cannot be empty |
60 |
< |
if self.middleware == '' and self.protocol == '': |
61 |
< |
print self.usage() |
62 |
< |
sys.exit() |
60 |
> |
if not self.params['middleware'] and not self.params['protocol'] : |
61 |
> |
HelpOptions() |
62 |
> |
|
63 |
|
# input file must be defined |
64 |
< |
if infile == '': |
65 |
< |
print self.usage() |
95 |
< |
sys.exit() |
64 |
> |
if not self.params['inputFileList'] : |
65 |
> |
HelpOptions() |
66 |
|
else: |
67 |
< |
if infile.find(','): |
68 |
< |
[self.file_to_copy.append(x.strip()) for x in infile.split(',')] |
67 |
> |
file_to_copy=[] |
68 |
> |
if self.params['inputFileList'].find(','): |
69 |
> |
[file_to_copy.append(x.strip()) for x in self.params['inputFileList'].split(',')] |
70 |
|
else: |
71 |
< |
self.file_to_copy.append(infile) |
71 |
> |
file_to_copy.append(self.params['inputFileList']) |
72 |
> |
self.params['inputFileList'] = file_to_copy |
73 |
|
|
74 |
< |
## TO DO: |
75 |
< |
#### add check for outFiles |
104 |
< |
#### add map {'inFileNAME':'outFileNAME'} to change out name |
105 |
< |
|
106 |
< |
return |
74 |
> |
if not self.params['for_lfn'] and self.local_stage == 1 : HelpOptions() |
75 |
> |
|
76 |
|
|
77 |
|
def run( self ): |
78 |
|
""" |
79 |
|
Check if running on UI (no $middleware) or |
80 |
|
on WN (on the Grid), and take different action |
81 |
|
""" |
82 |
< |
if self.middleware : |
83 |
< |
results = self.stager() |
82 |
> |
self.processOptions() |
83 |
> |
if self.debug: print 'calling run() : \n' |
84 |
> |
# stage out from WN |
85 |
> |
if self.params['middleware'] : |
86 |
> |
results = self.stager(self.params['middleware'],self.params['inputFileList']) |
87 |
> |
self.writeJsonFile(results) |
88 |
> |
self.finalReport(results) |
89 |
> |
# Local interaction with SE |
90 |
|
else: |
91 |
< |
results = self.copy( self.file_to_copy, self.protocol , self.opt) |
92 |
< |
|
93 |
< |
self.finalReport(results,self.middleware) |
94 |
< |
|
91 |
> |
results = self.copy(self.params['inputFileList'], self.params['protocol'], self.params['option'] ) |
92 |
> |
self.writeJsonFile(results) |
93 |
> |
return results |
94 |
> |
|
95 |
> |
def writeJsonFile( self, results ): |
96 |
> |
""" |
97 |
> |
write a json file containing copy results for each file |
98 |
> |
""" |
99 |
> |
if self.debug: |
100 |
> |
print 'in writeJsonFile() : \n' |
101 |
> |
print "---->>>> in writeJsonFile results = ", results |
102 |
> |
fp = open('resultCopyFile', 'w') |
103 |
> |
json.dump(results, fp) |
104 |
> |
fp.close() |
105 |
> |
if self.debug: |
106 |
> |
print ' reading resultCopyFile : \n' |
107 |
> |
lp = open('resultCopyFile', "r") |
108 |
> |
inputDict = json.load(lp) |
109 |
> |
lp.close() |
110 |
> |
print " inputDict = ", inputDict |
111 |
|
return |
112 |
|
|
113 |
< |
def setProtocol( self ): |
113 |
> |
def checkLcgUtils( self ): |
114 |
> |
""" |
115 |
> |
_checkLcgUtils_ |
116 |
> |
check the lcg-utils version and report |
117 |
> |
""" |
118 |
> |
import commands |
119 |
> |
cmd = "lcg-cp --version | grep lcg_util" |
120 |
> |
status, output = commands.getstatusoutput( cmd ) |
121 |
> |
num_ver = -1 |
122 |
> |
if output.find("not found") == -1 or status == 0: |
123 |
> |
temp = output.split("-") |
124 |
> |
version = "" |
125 |
> |
if len(temp) >= 2: |
126 |
> |
version = output.split("-")[1] |
127 |
> |
temp = version.split(".") |
128 |
> |
if len(temp) >= 1: |
129 |
> |
num_ver = int(temp[0])*10 |
130 |
> |
num_ver += int(temp[1]) |
131 |
> |
return num_ver |
132 |
> |
|
133 |
> |
def setProtocol( self, middleware ): |
134 |
|
""" |
135 |
|
define the allowed potocols based on $middlware |
136 |
|
which depend on scheduler |
137 |
|
""" |
138 |
< |
if self.middleware.lower() in ['osg','lcg']: |
139 |
< |
supported_protocol = ['srm-lcg','srmv2'] |
140 |
< |
self.OptMap = {'srm-lcg': self.lcgOpt, |
141 |
< |
'srmv2': self.srmOpt } |
142 |
< |
elif self.middleware.lower() in ['lsf','caf']: |
143 |
< |
supported_protocol = ['rfio'] |
144 |
< |
self.OptMap = {'rfio': self.rfioOpt } |
138 |
> |
# default To be used with "middleware" |
139 |
> |
if self.debug: |
140 |
> |
print 'setProtocol() :\n' |
141 |
> |
print '\tmiddleware = %s utils \n'%middleware |
142 |
> |
|
143 |
> |
lcgOpt={'srmv1':'-b -D srmv1 -t 2400 --verbose', |
144 |
> |
'srmv2':'-b -D srmv2 -t 2400 --verbose'} |
145 |
> |
if self.checkLcgUtils() >= 17: |
146 |
> |
lcgOpt={'srmv1':'-b -D srmv1 --srm-timeout 2400 --sendreceive-timeout 2400 --connect-timeout 300 --verbose', |
147 |
> |
'srmv2':'-b -D srmv2 --srm-timeout 2400 --sendreceive-timeout 2400 --connect-timeout 300 --verbose'} |
148 |
> |
|
149 |
> |
srmOpt={'srmv1':' -report ./srmcp.report -retry_timeout 480000 -retry_num 3 -streams_num=1 ', |
150 |
> |
'srmv2':' -report=./srmcp.report -retry_timeout=480000 -retry_num=3 -storagetype=permanent '} |
151 |
> |
rfioOpt='' |
152 |
> |
|
153 |
> |
supported_protocol = None |
154 |
> |
if middleware.lower() in ['osg','lcg','condor','sge']: |
155 |
> |
supported_protocol = [('srm-lcg',lcgOpt[self.params['srm_version']]),\ |
156 |
> |
(self.params['srm_version'],srmOpt[self.params['srm_version']])] |
157 |
> |
elif middleware.lower() in ['lsf','caf']: |
158 |
> |
supported_protocol = [('rfio',rfioOpt)] |
159 |
> |
elif middleware.lower() in ['pbs']: |
160 |
> |
supported_protocol = [('rfio',rfioOpt),('local','')] |
161 |
> |
elif middleware.lower() in ['arc']: |
162 |
> |
supported_protocol = [('srmv2','-debug'),('srmv1','-debug')] |
163 |
|
else: |
164 |
|
## here we can add support for any kind of protocol, |
165 |
|
## maybe some local schedulers need something dedicated |
166 |
|
pass |
167 |
|
return supported_protocol |
168 |
|
|
169 |
< |
def stager( self ): |
169 |
> |
|
170 |
> |
def checkCopy (self, copy_results, len_list_files, prot): |
171 |
> |
""" |
172 |
> |
Checks the status of copy and update result dictionary |
173 |
> |
""" |
174 |
> |
|
175 |
> |
list_retry = [] |
176 |
> |
list_not_existing = [] |
177 |
> |
list_already_existing = [] |
178 |
> |
list_fallback = [] |
179 |
> |
list_ok = [] |
180 |
> |
|
181 |
> |
if self.debug: |
182 |
> |
print 'in checkCopy() :\n' |
183 |
> |
|
184 |
> |
for file, dict in copy_results.iteritems(): |
185 |
> |
er_code = dict['erCode'] |
186 |
> |
if er_code == '0': |
187 |
> |
list_ok.append(file) |
188 |
> |
reason = 'Copy succedeed with %s utils'%prot |
189 |
> |
dict['reason'] = reason |
190 |
> |
elif er_code == '60308': |
191 |
> |
list_fallback.append( file ) |
192 |
> |
reason = 'Copy succedeed with %s utils'%prot |
193 |
> |
dict['reason'] = reason |
194 |
> |
elif er_code == '60302': |
195 |
> |
list_not_existing.append( file ) |
196 |
> |
elif er_code == '60303': |
197 |
> |
list_already_existing.append( file ) |
198 |
> |
else : |
199 |
> |
list_retry.append( file ) |
200 |
> |
|
201 |
> |
if self.debug: |
202 |
> |
print "\t file %s \n"%file |
203 |
> |
print "\t dict['erCode'] %s \n"%dict['erCode'] |
204 |
> |
print "\t dict['reason'] %s \n"%dict['reason'] |
205 |
> |
|
206 |
> |
upDict = self.updateReport(file, er_code, dict['reason']) |
207 |
> |
|
208 |
> |
copy_results.update(upDict) |
209 |
> |
|
210 |
> |
msg = '' |
211 |
> |
if len(list_ok) != 0: |
212 |
> |
msg += '\tCopy of %s succedeed with %s utils\n'%(str(list_ok),prot) |
213 |
> |
if len(list_ok) != len_list_files : |
214 |
> |
if len(list_fallback)!=0: |
215 |
> |
msg += '\tCopy of %s succedeed with %s utils in the fallback SE\n'%(str(list_fallback),prot) |
216 |
> |
if len(list_retry)!=0: |
217 |
> |
msg += '\tCopy of %s failed using %s for files \n'%(str(list_retry),prot) |
218 |
> |
if len(list_not_existing)!=0: |
219 |
> |
msg += '\tCopy of %s failed using %s : files not found \n'%(str(list_not_existing),prot) |
220 |
> |
if len(list_already_existing)!=0: |
221 |
> |
msg += '\tCopy of %s failed using %s : files already existing\n'%(str(list_already_existing),prot) |
222 |
> |
if self.debug : print msg |
223 |
> |
return copy_results, list_ok, list_retry, list_fallback |
224 |
> |
|
225 |
> |
def check_for_retry_localSE (self, copy_results): |
226 |
> |
""" |
227 |
> |
Checks the status of copy and create the list of file to copy to CloseSE |
228 |
> |
""" |
229 |
> |
list_retry_localSE = [] |
230 |
> |
|
231 |
> |
if self.debug: |
232 |
> |
print 'in check_for_retry_localSE() :\n' |
233 |
> |
print "\t results in check local = ", copy_results |
234 |
> |
for file, dict in copy_results.iteritems(): |
235 |
> |
er_code = dict['erCode'] |
236 |
> |
if er_code != '0' and er_code != '60302' and er_code != '60308': |
237 |
> |
list_retry_localSE.append( file ) |
238 |
> |
|
239 |
> |
if self.debug: |
240 |
> |
print "\t file %s \n"%file |
241 |
> |
print "\t dict['erCode'] %s \n"%dict['erCode'] |
242 |
> |
print "\t dict['reason'] %s \n"%dict['reason'] |
243 |
> |
|
244 |
> |
return list_retry_localSE |
245 |
> |
|
246 |
> |
|
247 |
> |
def LocalCopy(self, list_retry, results): |
248 |
> |
""" |
249 |
> |
Tries the stage out to the CloseSE |
250 |
> |
""" |
251 |
> |
if self.debug: |
252 |
> |
print 'in LocalCopy() :\n' |
253 |
> |
print '\t list_retry %s utils \n'%list_retry |
254 |
> |
print '\t len(list_retry) %s \n'%len(list_retry) |
255 |
> |
|
256 |
> |
list_files = list_retry |
257 |
> |
self.params['inputFileList']=list_files |
258 |
> |
|
259 |
> |
### copy backup |
260 |
> |
from ProdCommon.FwkJobRep.SiteLocalConfig import loadSiteLocalConfig |
261 |
> |
siteCfg = loadSiteLocalConfig() |
262 |
> |
catalog = siteCfg.localStageOut.get("catalog", None) |
263 |
> |
tfc = siteCfg.trivialFileCatalog() |
264 |
> |
seName = siteCfg.localStageOutSEName() |
265 |
> |
if seName is None: |
266 |
> |
seName = "" |
267 |
> |
option = siteCfg.localStageOutOption() |
268 |
> |
if option is None: |
269 |
> |
option = "" |
270 |
> |
implName = siteCfg.localStageOutCommand() |
271 |
> |
if implName is None: |
272 |
> |
implName = "" |
273 |
> |
|
274 |
> |
if (implName == 'srm'): |
275 |
> |
protocol = 'srmv2' |
276 |
> |
elif (implName == 'srmv2-lcg'): |
277 |
> |
protocol = 'srm-lcg' |
278 |
> |
option = option + ' -b -D srmv2 ' |
279 |
> |
elif (implName == 'rfcp-CERN'): |
280 |
> |
protocol = 'rfio' |
281 |
> |
elif (implName == 'rfcp'): |
282 |
> |
protocol = 'rfio' |
283 |
> |
elif (implName == 'cp'): |
284 |
> |
protocol = 'local' |
285 |
> |
else: protocol = implName |
286 |
> |
|
287 |
> |
self.params['protocol']=protocol |
288 |
> |
self.params['option']=option |
289 |
> |
|
290 |
> |
if self.debug: |
291 |
> |
print '\t siteCFG %s \n'%siteCfg |
292 |
> |
print '\t catalog %s \n'%catalog |
293 |
> |
print '\t tfc %s '%tfc |
294 |
> |
print '\t fallback seName %s \n'%seName |
295 |
> |
print "\t fallback protocol %s \n"%protocol |
296 |
> |
print "\t fallback option %s \n"%option |
297 |
> |
print "\t self.params['inputFileList'] %s \n"%self.params['inputFileList'] |
298 |
> |
|
299 |
> |
if (str(self.params['for_lfn']).find("/store/") == 0): |
300 |
> |
temp = str(self.params['for_lfn']).replace("/store/","/store/temp/",1) |
301 |
> |
self.params['for_lfn']= temp |
302 |
> |
|
303 |
> |
if ( self.params['for_lfn'][-1] != '/' ) : self.params['for_lfn'] = self.params['for_lfn'] + '/' |
304 |
> |
|
305 |
> |
file_backup=[] |
306 |
> |
file_backup_surlgrid=[] |
307 |
> |
for input in self.params['inputFileList']: |
308 |
> |
file = self.params['for_lfn'] + os.path.basename(input) |
309 |
> |
surl = tfc.matchLFN(tfc.preferredProtocol, file) |
310 |
> |
|
311 |
> |
###### FEDE TEST_FOR_SURL_GRID |
312 |
> |
surl_for_grid = tfc.matchLFN('srmv2', file) |
313 |
> |
if (surl_for_grid == None): |
314 |
> |
surl_for_grid = tfc.matchLFN('srmv2-lcg', file) |
315 |
> |
if (surl_for_grid == None): |
316 |
> |
surl_for_grid = tfc.matchLFN('srm', file) |
317 |
> |
if surl_for_grid: |
318 |
> |
file_backup_surlgrid.append(surl_for_grid) |
319 |
> |
###### |
320 |
> |
|
321 |
> |
file_backup.append(surl) |
322 |
> |
if self.debug: |
323 |
> |
print '\t for_lfn %s \n'%self.params['for_lfn'] |
324 |
> |
print '\t file %s \n'%file |
325 |
> |
print '\t surl %s \n'%surl |
326 |
> |
|
327 |
> |
destination=os.path.dirname(file_backup[0]) |
328 |
> |
if ( destination[-1] != '/' ) : destination = destination + '/' |
329 |
> |
self.params['destination']=destination |
330 |
> |
|
331 |
> |
self.params['se_name']=seName |
332 |
> |
|
333 |
> |
###### |
334 |
> |
if (len(file_backup_surlgrid)>0) : |
335 |
> |
surl_for_grid=os.path.dirname(file_backup_surlgrid[0]) |
336 |
> |
if ( surl_for_grid[-1] != '/' ) : surl_for_grid = surl_for_grid + '/' |
337 |
> |
else: |
338 |
> |
surl_for_grid='' |
339 |
> |
|
340 |
> |
print "surl_for_grid = ", surl_for_grid |
341 |
> |
self.params['surl_for_grid']=surl_for_grid |
342 |
> |
##### |
343 |
> |
|
344 |
> |
if self.debug: |
345 |
> |
print '\tIn LocalCopy trying the stage out with: \n' |
346 |
> |
print "\tself.params['destination'] %s \n"%self.params['destination'] |
347 |
> |
print "\tself.params['protocol'] %s \n"%self.params['protocol'] |
348 |
> |
print "\tself.params['option'] %s \n"%self.params['option'] |
349 |
> |
|
350 |
> |
localCopy_results = self.copy( self.params['inputFileList'], self.params['protocol'], self.params['option'], backup='yes' ) |
351 |
> |
|
352 |
> |
if localCopy_results.keys() == [''] or localCopy_results.keys() == '' : |
353 |
> |
results.update(localCopy_results) |
354 |
> |
else: |
355 |
> |
localCopy_results, list_ok, list_retry, list_fallback = self.checkCopy(localCopy_results, len(list_files), self.params['protocol']) |
356 |
> |
|
357 |
> |
results.update(localCopy_results) |
358 |
> |
if self.debug: |
359 |
> |
print "\t localCopy_results = %s \n"%localCopy_results |
360 |
> |
return results |
361 |
> |
|
362 |
> |
def stager( self, middleware, list_files ): |
363 |
|
""" |
364 |
|
Implement the logic for remote stage out |
365 |
|
""" |
366 |
< |
protocols = self.setProtocol() |
367 |
< |
count=0 |
368 |
< |
list_files = self.file_to_copy |
366 |
> |
|
367 |
> |
if self.debug: |
368 |
> |
print 'stager() :\n' |
369 |
> |
print '\tmiddleware %s\n'%middleware |
370 |
> |
print '\tlist_files %s\n'%list_files |
371 |
> |
|
372 |
|
results={} |
373 |
< |
for prot in protocols: |
374 |
< |
if self.debug: print 'Trying stage out with %s utils \n'%prot |
375 |
< |
copy_results = self.copy( list_files, prot, self.OptMap[prot] ) |
376 |
< |
list_retry = [] |
377 |
< |
list_existing = [] |
378 |
< |
list_ok = [] |
379 |
< |
for file, dict in copy_results.iteritems(): |
380 |
< |
er_code = dict['erCode'] |
156 |
< |
if er_code == '60307': list_retry.append( file ) |
157 |
< |
elif er_code == '60303': list_existing.append( file ) |
158 |
< |
else: |
159 |
< |
list_ok.append(file) |
160 |
< |
reason = 'Copy succedeed with %s utils'%prot |
161 |
< |
upDict = self.updateReport(file, er_code, reason) |
162 |
< |
copy_results.update(upDict) |
163 |
< |
results.update(copy_results) |
164 |
< |
if len(list_ok) != 0: |
165 |
< |
msg = 'Copy of %s succedeed with %s utils\n'%(str(list_ok),prot) |
166 |
< |
# print msg |
167 |
< |
if len(list_ok) == len(list_files) : |
168 |
< |
break |
373 |
> |
for prot, opt in self.setProtocol( middleware ): |
374 |
> |
if self.debug: |
375 |
> |
print '\tTrying the stage out with %s utils \n'%prot |
376 |
> |
print '\tand options %s\n'%opt |
377 |
> |
|
378 |
> |
copy_results = self.copy( list_files, prot, opt ) |
379 |
> |
if copy_results.keys() == [''] or copy_results.keys() == '' : |
380 |
> |
results.update(copy_results) |
381 |
|
else: |
382 |
< |
# print 'Copy of files %s failed using %s...\n'%(str(list_retry)+str(list_existing),prot) |
383 |
< |
if len(list_retry): list_files = list_retry |
382 |
> |
copy_results, list_ok, list_retry, list_fallback = self.checkCopy(copy_results, len(list_files), prot) |
383 |
> |
results.update(copy_results) |
384 |
> |
if len(list_ok) == len(list_files) : |
385 |
> |
break |
386 |
> |
if len(list_retry): |
387 |
> |
list_files = list_retry |
388 |
|
else: break |
173 |
– |
count =+1 |
389 |
|
|
390 |
< |
#### TODO Daniele |
391 |
< |
#check is something fails and created related dict |
392 |
< |
# backup = self.analyzeResults(results) |
393 |
< |
|
394 |
< |
# if backup : |
395 |
< |
# msg = 'WARNING: backup logic is under implementation\n' |
396 |
< |
# #backupDict = self.backup() |
397 |
< |
# ### NOTE: IT MUST RETURN a DICT contains also LFN and SE Name |
398 |
< |
# results.update(backupDict) |
184 |
< |
# print msg |
390 |
> |
if self.local_stage: |
391 |
> |
list_retry_localSE = self.check_for_retry_localSE(results) |
392 |
> |
if len(list_retry_localSE): |
393 |
> |
if self.debug: |
394 |
> |
print "\t list_retry_localSE %s \n"%list_retry_localSE |
395 |
> |
results = self.LocalCopy(list_retry_localSE, results) |
396 |
> |
|
397 |
> |
if self.debug: |
398 |
> |
print "\t results %s \n"%results |
399 |
|
return results |
400 |
|
|
401 |
|
def initializeApi(self, protocol ): |
402 |
|
""" |
403 |
|
Instantiate storage interface |
404 |
|
""" |
405 |
< |
source_prot = protocol |
406 |
< |
dest_prot = protocol |
407 |
< |
if self.source == '' : source_prot = 'local' |
408 |
< |
Source_SE = self.storageInterface( self.source, source_prot ) |
409 |
< |
if self.destination == '' : dest_prot = 'local' |
410 |
< |
Destination_SE = self.storageInterface( self.destination, dest_prot ) |
405 |
> |
if self.debug : print 'initializeApi() :\n' |
406 |
> |
self.source_prot = protocol |
407 |
> |
self.dest_prot = protocol |
408 |
> |
if not self.params['source'] : self.source_prot = 'local' |
409 |
> |
Source_SE = self.storageInterface( self.params['source'], self.source_prot ) |
410 |
> |
if not self.params['destination'] : |
411 |
> |
self.dest_prot = 'local' |
412 |
> |
Destination_SE = self.storageInterface( self.params['destinationDir'], self.dest_prot ) |
413 |
> |
else: |
414 |
> |
Destination_SE = self.storageInterface( self.params['destination'], self.dest_prot ) |
415 |
|
|
416 |
|
if self.debug : |
417 |
< |
print '(source=%s, protocol=%s)'%(self.source, source_prot) |
418 |
< |
print '(destination=%s, protocol=%s)'%(self.destination, dest_prot) |
417 |
> |
msg = '\t(source=%s, protocol=%s)'%(self.params['source'], self.source_prot) |
418 |
> |
msg += '\t(destination=%s, protocol=%s)'%(self.params['destination'], self.dest_prot) |
419 |
> |
msg += '\t(destinationDir=%s, protocol=%s)'%(self.params['destinationDir'], self.dest_prot) |
420 |
> |
print msg |
421 |
|
|
422 |
|
return Source_SE, Destination_SE |
423 |
|
|
424 |
< |
def copy( self, list_file, protocol, opt): |
424 |
> |
def copy( self, list_file, protocol, options, backup='no' ): |
425 |
|
""" |
426 |
|
Make the real file copy using SE API |
427 |
|
""" |
428 |
+ |
msg = "" |
429 |
+ |
results = {} |
430 |
|
if self.debug : |
431 |
< |
print 'copy(): using %s protocol'%protocol |
432 |
< |
Source_SE, Destination_SE = self.initializeApi( protocol ) |
433 |
< |
|
434 |
< |
# create remote dir |
435 |
< |
if protocol in ['gridftp','rfio']: |
436 |
< |
self.createDir( Destination_SE, protocol ) |
437 |
< |
|
431 |
> |
msg = 'copy() :\n' |
432 |
> |
msg += '\tusing %s protocol\n'%protocol |
433 |
> |
msg += '\tusing %s options\n'%options |
434 |
> |
msg += '\tlist_file %s\n'%list_file |
435 |
> |
print msg |
436 |
> |
try: |
437 |
> |
Source_SE, Destination_SE = self.initializeApi( protocol ) |
438 |
> |
except Exception, ex: |
439 |
> |
for filetocopy in list_file: |
440 |
> |
results.update( self.updateReport(filetocopy, '-1', str(ex))) |
441 |
> |
return results |
442 |
> |
|
443 |
> |
self.hostname = Destination_SE.hostname |
444 |
> |
if Destination_SE.protocol in ['gridftp','rfio','srmv2','hadoop','local']: |
445 |
> |
try: |
446 |
> |
self.createDir( Destination_SE, Destination_SE.protocol ) |
447 |
> |
except OperationException, ex: |
448 |
> |
for filetocopy in list_file: |
449 |
> |
results.update( self.updateReport(filetocopy, '60316', str(ex))) |
450 |
> |
return results |
451 |
> |
## when the client commands are not found (wrong env or really missing) |
452 |
> |
except MissingCommand, ex: |
453 |
> |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
454 |
> |
for filetocopy in list_file: |
455 |
> |
results.update( self.updateReport(filetocopy, '10041', msg)) |
456 |
> |
return results |
457 |
> |
except Exception, ex: |
458 |
> |
msg = "ERROR %s" %(str(ex)) |
459 |
> |
for filetocopy in list_file: |
460 |
> |
results.update( self.updateReport(filetocopy, '-1', msg)) |
461 |
> |
return results |
462 |
|
## prepare for real copy ## |
463 |
< |
sbi = SBinterface( Source_SE, Destination_SE ) |
464 |
< |
sbi_dest = SBinterface(Destination_SE) |
463 |
> |
try : |
464 |
> |
sbi = SBinterface( Source_SE, Destination_SE ) |
465 |
> |
sbi_dest = SBinterface(Destination_SE) |
466 |
> |
sbi_source = SBinterface(Source_SE) |
467 |
> |
except ProtocolMismatch, ex: |
468 |
> |
msg = "ERROR : Unable to create SBinterface with %s protocol"%protocol |
469 |
> |
msg += str(ex) |
470 |
> |
for filetocopy in list_file: |
471 |
> |
results.update( self.updateReport(filetocopy, '-1', msg)) |
472 |
> |
return results |
473 |
|
|
474 |
< |
results = {} |
474 |
> |
|
475 |
|
## loop over the complete list of files |
476 |
|
for filetocopy in list_file: |
477 |
< |
if self.debug : print 'start real copy for %s'%filetocopy |
478 |
< |
ErCode, msg = self.checkFileExist( sbi_dest, os.path.basename(filetocopy) ) |
477 |
> |
if self.debug : print '\tStart real copy for %s'%filetocopy |
478 |
> |
try : |
479 |
> |
ErCode, msg = self.checkFileExist( sbi_source, sbi_dest, filetocopy, options ) |
480 |
> |
except Exception, ex: |
481 |
> |
ErCode = '60307' |
482 |
> |
msg = str(ex) |
483 |
|
if ErCode == '0': |
484 |
< |
ErCode, msg = self.makeCopy( sbi, filetocopy , opt) |
485 |
< |
if self.debug : print 'Copy results for %s is %s'%( os.path.basename(filetocopy) ,ErCode) |
484 |
> |
ErCode, msg = self.makeCopy( sbi, filetocopy , options, protocol,sbi_dest ) |
485 |
> |
if (ErCode == '0') and (backup == 'yes'): |
486 |
> |
ErCode = '60308' |
487 |
> |
if self.debug : print '\tCopy results for %s is %s'%( os.path.basename(filetocopy), ErCode) |
488 |
|
results.update( self.updateReport(filetocopy, ErCode, msg)) |
489 |
|
return results |
490 |
|
|
231 |
– |
def updateReport(self, file, erCode, reason, lfn='', se='' ): |
232 |
– |
""" |
233 |
– |
Update the final stage out infos |
234 |
– |
""" |
235 |
– |
jobStageInfo={} |
236 |
– |
jobStageInfo['erCode']=erCode |
237 |
– |
jobStageInfo['reason']=reason |
238 |
– |
jobStageInfo['lfn']=lfn |
239 |
– |
jobStageInfo['se']=se |
240 |
– |
|
241 |
– |
report = { file : jobStageInfo} |
242 |
– |
return report |
243 |
– |
|
244 |
– |
def finalReport( self , results, middleware ): |
245 |
– |
""" |
246 |
– |
It should return a clear list of LFNs for each SE where data are stored. |
247 |
– |
allow "crab -copyLocal" or better "crab -copyOutput". TO_DO. |
248 |
– |
""" |
249 |
– |
if middleware: |
250 |
– |
outFile = open('cmscpReport.sh',"a") |
251 |
– |
cmscp_exit_status = 0 |
252 |
– |
txt = '' |
253 |
– |
for file, dict in results.iteritems(): |
254 |
– |
if dict['lfn']=='': |
255 |
– |
lfn = '$LFNBaseName/'+os.path.basename(file) |
256 |
– |
se = '$SE' |
257 |
– |
else: |
258 |
– |
lfn = dict['lfn']+os.pat.basename(file) |
259 |
– |
se = dict['se'] |
260 |
– |
#dict['lfn'] # to be implemented |
261 |
– |
txt += 'echo "Report for File: '+file+'"\n' |
262 |
– |
txt += 'echo "LFN: '+lfn+'"\n' |
263 |
– |
txt += 'echo "StorageElement: '+se+'"\n' |
264 |
– |
txt += 'echo "StageOutExitStatusReason ='+dict['reason']+'" | tee -a $RUNTIME_AREA/$repo\n' |
265 |
– |
txt += 'echo "StageOutSE = '+se+'" >> $RUNTIME_AREA/$repo\n' |
266 |
– |
if dict['erCode'] != '0': |
267 |
– |
cmscp_exit_status = dict['erCode'] |
268 |
– |
txt += '\n' |
269 |
– |
txt += 'export StageOutExitStatus='+str(cmscp_exit_status)+'\n' |
270 |
– |
txt += 'echo "StageOutExitStatus = '+str(cmscp_exit_status)+'" | tee -a $RUNTIME_AREA/$repo\n' |
271 |
– |
outFile.write(str(txt)) |
272 |
– |
outFile.close() |
273 |
– |
else: |
274 |
– |
for file, code in results.iteritems(): |
275 |
– |
print 'error code = %s for file %s'%(code,file) |
276 |
– |
return |
491 |
|
|
492 |
|
def storageInterface( self, endpoint, protocol ): |
493 |
|
""" |
494 |
|
Create the storage interface. |
495 |
|
""" |
496 |
+ |
if self.debug : print 'storageInterface():\n' |
497 |
|
try: |
498 |
|
interface = SElement( FullPath(endpoint), protocol ) |
499 |
< |
except Exception, ex: |
500 |
< |
msg = '' |
501 |
< |
if self.debug : msg = str(ex)+'\n' |
502 |
< |
msg += "ERROR : Unable to create interface with %s protocol\n"%protocol |
288 |
< |
print msg |
499 |
> |
except ProtocolUnknown, ex: |
500 |
> |
msg = "ERROR : Unable to create interface with %s protocol"%protocol |
501 |
> |
msg += str(ex) |
502 |
> |
raise Exception(msg) |
503 |
|
|
504 |
|
return interface |
505 |
|
|
292 |
– |
def checkDir(self, Destination_SE, protocol): |
293 |
– |
''' |
294 |
– |
ToBeImplemented NEEDED for castor |
295 |
– |
''' |
296 |
– |
return |
297 |
– |
|
506 |
|
def createDir(self, Destination_SE, protocol): |
507 |
|
""" |
508 |
< |
Create remote dir for gsiftp/rfio REALLY TEMPORARY |
508 |
> |
Create remote dir for gsiftp REALLY TEMPORARY |
509 |
|
this should be transparent at SE API level. |
510 |
|
""" |
511 |
< |
ErCode = '0' |
512 |
< |
msg_1 = '' |
511 |
> |
if self.debug : print 'createDir():\n' |
512 |
> |
msg = '' |
513 |
|
try: |
514 |
|
action = SBinterface( Destination_SE ) |
515 |
|
action.createDir() |
516 |
< |
if self.debug: print "The directory has been created using protocol %s\n"%protocol |
517 |
< |
except Exception, ex: |
518 |
< |
msg = '' |
519 |
< |
if self.debug : msg = str(ex)+'\n' |
520 |
< |
msg_1 = "ERROR: problem with the directory creation using %s protocol \n"%protocol |
521 |
< |
msg += msg_1 |
522 |
< |
ErCode = '60316' |
523 |
< |
#print msg |
524 |
< |
|
525 |
< |
return ErCode, msg_1 |
516 |
> |
if self.debug: print "\tThe directory has been created using protocol %s"%protocol |
517 |
> |
except TransferException, ex: |
518 |
> |
msg = "ERROR: problem with the directory creation using %s protocol "%protocol |
519 |
> |
msg += str(ex) |
520 |
> |
if self.debug : |
521 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
522 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
523 |
> |
print dbgmsg |
524 |
> |
raise Exception(msg) |
525 |
> |
except OperationException, ex: |
526 |
> |
msg = "ERROR: problem with the directory creation using %s protocol "%protocol |
527 |
> |
msg += str(ex) |
528 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
529 |
> |
raise Exception(msg) |
530 |
> |
except MissingDestination, ex: |
531 |
> |
msg = "ERROR: problem with the directory creation using %s protocol "%protocol |
532 |
> |
msg += str(ex) |
533 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
534 |
> |
raise Exception(msg) |
535 |
> |
except AlreadyExistsException, ex: |
536 |
> |
if self.debug: print "\tThe directory already exist" |
537 |
> |
pass |
538 |
> |
except Exception, ex: |
539 |
> |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
540 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
541 |
> |
raise Exception(msg) |
542 |
> |
return msg |
543 |
|
|
544 |
< |
def checkFileExist(self, sbi, filetocopy): |
544 |
> |
def checkFileExist( self, sbi_source, sbi_dest, filetocopy, option ): |
545 |
|
""" |
546 |
< |
Check if file to copy already exist |
546 |
> |
Check both if source file exist AND |
547 |
> |
if destination file ALREADY exist. |
548 |
|
""" |
549 |
< |
try: |
324 |
< |
check = sbi.checkExists(filetocopy) |
325 |
< |
except Exception, ex: |
326 |
< |
msg = '' |
327 |
< |
if self.debug : msg = str(ex)+'\n' |
328 |
< |
msg += "ERROR: problem with check File Exist using %s protocol \n"%protocol |
329 |
< |
# print msg |
549 |
> |
if self.debug : print 'checkFileExist():\n' |
550 |
|
ErCode = '0' |
551 |
|
msg = '' |
552 |
+ |
f_tocopy=filetocopy |
553 |
+ |
if self.source_prot != 'local':f_tocopy = os.path.basename(filetocopy) |
554 |
+ |
try: |
555 |
+ |
checkSource = sbi_source.checkExists( f_tocopy , opt=option, tout = self.subprocesstimeout['exists'] ) |
556 |
+ |
if self.debug : print '\tCheck for local file %s exist succeded \n'%f_tocopy |
557 |
+ |
except OperationException, ex: |
558 |
+ |
msg ='ERROR: problems checkig if source file %s exist'%filetocopy |
559 |
+ |
msg += str(ex) |
560 |
+ |
if self.debug : |
561 |
+ |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
562 |
+ |
dbgmsg += '\t'+str(ex.output)+'\n' |
563 |
+ |
print dbgmsg |
564 |
+ |
raise Exception(msg) |
565 |
+ |
except WrongOption, ex: |
566 |
+ |
msg ='ERROR problems checkig if source file % exist'%filetocopy |
567 |
+ |
msg += str(ex) |
568 |
+ |
if self.debug : |
569 |
+ |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
570 |
+ |
dbgmsg += '\t'+str(ex.output)+'\n' |
571 |
+ |
print dbgmsg |
572 |
+ |
raise Exception(msg) |
573 |
+ |
except MissingDestination, ex: |
574 |
+ |
msg ='ERROR problems checkig if source file % exist'%filetocopy |
575 |
+ |
msg += str(ex) |
576 |
+ |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
577 |
+ |
raise Exception(msg) |
578 |
+ |
## when the client commands are not found (wrong env or really missing) |
579 |
+ |
except MissingCommand, ex: |
580 |
+ |
ErCode = '10041' |
581 |
+ |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
582 |
+ |
return ErCode, msg |
583 |
+ |
if not checkSource : |
584 |
+ |
ErCode = '60302' |
585 |
+ |
msg = "ERROR file %s do not exist"%os.path.basename(filetocopy) |
586 |
+ |
return ErCode, msg |
587 |
+ |
f_tocopy=os.path.basename(filetocopy) |
588 |
+ |
try: |
589 |
+ |
check = sbi_dest.checkExists( f_tocopy, opt=option, tout = self.subprocesstimeout['exists'] ) |
590 |
+ |
if self.debug : print '\tCheck for remote file %s exist done \n'%f_tocopy |
591 |
+ |
if self.debug : print '\twith exit code = %s \n'%check |
592 |
+ |
except OperationException, ex: |
593 |
+ |
msg = 'ERROR: problems checkig if file %s already exist'%filetocopy |
594 |
+ |
msg += str(ex) |
595 |
+ |
if self.debug : |
596 |
+ |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
597 |
+ |
dbgmsg += '\t'+str(ex.output)+'\n' |
598 |
+ |
print dbgmsg |
599 |
+ |
raise Exception(msg) |
600 |
+ |
except WrongOption, ex: |
601 |
+ |
msg = 'ERROR problems checkig if file % already exist'%filetocopy |
602 |
+ |
msg += str(ex) |
603 |
+ |
if self.debug : |
604 |
+ |
msg += '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
605 |
+ |
msg += '\t'+str(ex.output)+'\n' |
606 |
+ |
raise Exception(msg) |
607 |
+ |
except MissingDestination, ex: |
608 |
+ |
msg ='ERROR problems checkig if source file % exist'%filetocopy |
609 |
+ |
msg += str(ex) |
610 |
+ |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
611 |
+ |
raise Exception(msg) |
612 |
+ |
## when the client commands are not found (wrong env or really missing) |
613 |
+ |
except MissingCommand, ex: |
614 |
+ |
ErCode = '10041' |
615 |
+ |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
616 |
+ |
return ErCode, msg |
617 |
|
if check : |
618 |
|
ErCode = '60303' |
619 |
< |
msg = "file %s already exist"%filetocopy |
335 |
< |
print msg |
619 |
> |
msg = "file %s already exist"%os.path.basename(filetocopy) |
620 |
|
|
621 |
< |
return ErCode,msg |
621 |
> |
return ErCode, msg |
622 |
|
|
623 |
< |
def makeCopy(self, sbi, filetocopy, opt ): |
623 |
> |
def makeCopy(self, sbi, filetocopy, option, protocol, sbi_dest ): |
624 |
|
""" |
625 |
|
call the copy API. |
626 |
|
""" |
627 |
+ |
if self.debug : print 'makeCopy():\n' |
628 |
|
path = os.path.dirname(filetocopy) |
629 |
|
file_name = os.path.basename(filetocopy) |
630 |
|
source_file = filetocopy |
631 |
|
dest_file = file_name ## to be improved supporting changing file name TODO |
632 |
< |
if self.source == '' and path == '': |
632 |
> |
if self.params['source'] == '' and path == '': |
633 |
|
source_file = os.path.abspath(filetocopy) |
634 |
< |
elif self.destination =='': |
635 |
< |
dest_file = os.path.join(os.getcwd(),file_name) |
636 |
< |
elif self.source != '' and self.destination != '' : |
634 |
> |
elif self.params['destination'] =='': |
635 |
> |
destDir = self.params.get('destinationDir',os.getcwd()) |
636 |
> |
dest_file = os.path.join(destDir,file_name) |
637 |
> |
elif self.params['source'] != '' and self.params['destination'] != '' : |
638 |
|
source_file = file_name |
639 |
+ |
|
640 |
|
ErCode = '0' |
641 |
|
msg = '' |
642 |
|
|
643 |
+ |
copy_option = option |
644 |
+ |
if self.params['option'].find('space_token')>=0: |
645 |
+ |
space_token=self.params['option'].split('=')[1] |
646 |
+ |
if protocol == 'srmv2': copy_option = '%s -space_token=%s'%(option,space_token) |
647 |
+ |
if protocol == 'srm-lcg': copy_option = '%s -S %s'%(option,space_token) |
648 |
|
try: |
649 |
< |
pippo = sbi.copy( source_file , dest_file , opt = opt) |
650 |
< |
if self.protocol == 'srm' : self.checkSize( sbi, filetocopy ) |
651 |
< |
except Exception, ex: |
652 |
< |
msg = '' |
653 |
< |
if self.debug : msg = str(ex)+'\n' |
654 |
< |
msg = "Problem copying %s file" % filetocopy |
649 |
> |
sbi.copy( source_file , dest_file , opt = copy_option, tout = self.subprocesstimeout['copy']) |
650 |
> |
except TransferException, ex: |
651 |
> |
msg = "Problem copying %s file" % filetocopy |
652 |
> |
msg += str(ex) |
653 |
> |
if self.debug : |
654 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
655 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
656 |
> |
print dbgmsg |
657 |
|
ErCode = '60307' |
658 |
< |
#print msg |
659 |
< |
|
658 |
> |
except WrongOption, ex: |
659 |
> |
msg = "Problem copying %s file" % filetocopy |
660 |
> |
msg += str(ex) |
661 |
> |
if self.debug : |
662 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
663 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
664 |
> |
print dbgmsg |
665 |
> |
except SizeZeroException, ex: |
666 |
> |
msg = "Problem copying %s file" % filetocopy |
667 |
> |
msg += str(ex) |
668 |
> |
if self.debug : |
669 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
670 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
671 |
> |
print dbgmsg |
672 |
> |
ErCode = '60307' |
673 |
> |
## when the client commands are not found (wrong env or really missing) |
674 |
> |
except MissingCommand, ex: |
675 |
> |
ErCode = '10041' |
676 |
> |
msg = "Problem copying %s file" % filetocopy |
677 |
> |
msg += str(ex) |
678 |
> |
if self.debug : |
679 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
680 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
681 |
> |
print dbgmsg |
682 |
> |
except AuthorizationException, ex: |
683 |
> |
ErCode = '60307' |
684 |
> |
msg = "Problem copying %s file" % filetocopy |
685 |
> |
msg += str(ex) |
686 |
> |
if self.debug : |
687 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
688 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
689 |
> |
print dbgmsg |
690 |
> |
except SEAPITimeout, ex: |
691 |
> |
ErCode = '60317' |
692 |
> |
msg = "Problem copying %s file" % filetocopy |
693 |
> |
msg += str(ex) |
694 |
> |
if self.debug : |
695 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
696 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
697 |
> |
print dbgmsg |
698 |
> |
|
699 |
> |
if ErCode == '0' and protocol.find('srmv') == 0: |
700 |
> |
remote_file_size = -1 |
701 |
> |
local_file_size = os.path.getsize( source_file ) |
702 |
> |
try: |
703 |
> |
remote_file_size = sbi_dest.getSize( dest_file, opt=option, tout = self.subprocesstimeout['size'] ) |
704 |
> |
if self.debug : print '\t Check of remote size succeded for file %s\n'%dest_file |
705 |
> |
except TransferException, ex: |
706 |
> |
msg = "Problem checking the size of %s file" % filetocopy |
707 |
> |
msg += str(ex) |
708 |
> |
if self.debug : |
709 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
710 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
711 |
> |
print dbgmsg |
712 |
> |
ErCode = '60307' |
713 |
> |
except WrongOption, ex: |
714 |
> |
msg = "Problem checking the size of %s file" % filetocopy |
715 |
> |
msg += str(ex) |
716 |
> |
if self.debug : |
717 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
718 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
719 |
> |
print dbgmsg |
720 |
> |
ErCode = '60307' |
721 |
> |
if local_file_size != remote_file_size: |
722 |
> |
msg = "File size dosn't match: local size = %s ; remote size = %s " % (local_file_size, remote_file_size) |
723 |
> |
ErCode = '60307' |
724 |
> |
|
725 |
> |
if ErCode != '0': |
726 |
> |
try : |
727 |
> |
self.removeFile( sbi_dest, dest_file, option ) |
728 |
> |
except Exception, ex: |
729 |
> |
msg += '\n'+str(ex) |
730 |
|
return ErCode, msg |
731 |
|
|
732 |
< |
''' |
733 |
< |
def checkSize() |
732 |
> |
def removeFile( self, sbi_dest, filetocopy, option ): |
733 |
> |
""" |
734 |
> |
""" |
735 |
> |
if self.debug : print 'removeFile():\n' |
736 |
> |
f_tocopy=filetocopy |
737 |
> |
if self.dest_prot != 'local':f_tocopy = os.path.basename(filetocopy) |
738 |
> |
try: |
739 |
> |
sbi_dest.delete( f_tocopy, opt=option, tout = self.subprocesstimeout['delete'] ) |
740 |
> |
if self.debug : '\t deletion of file %s succeeded\n'%str(filetocopy) |
741 |
> |
except OperationException, ex: |
742 |
> |
msg ='ERROR: problems removing partially staged file %s'%filetocopy |
743 |
> |
msg += str(ex) |
744 |
> |
if self.debug : |
745 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
746 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
747 |
> |
print dbgmsg |
748 |
> |
raise Exception(msg) |
749 |
> |
|
750 |
> |
return |
751 |
> |
|
752 |
> |
def updateReport(self, file, erCode, reason): |
753 |
|
""" |
754 |
< |
Using srm needed a check of the ouptut file size. |
754 |
> |
Update the final stage out infos |
755 |
|
""" |
756 |
+ |
jobStageInfo={} |
757 |
+ |
jobStageInfo['erCode']=erCode |
758 |
+ |
jobStageInfo['reason']=reason |
759 |
+ |
if not self.params['for_lfn']: self.params['for_lfn']='' |
760 |
+ |
if not self.params['se_name']: self.params['se_name']='' |
761 |
+ |
if not self.hostname: self.hostname='' |
762 |
+ |
if (erCode != '0') and (erCode != '60308'): |
763 |
+ |
jobStageInfo['for_lfn']='/copy_problem/' |
764 |
+ |
else: |
765 |
+ |
jobStageInfo['for_lfn']=self.params['for_lfn'] |
766 |
+ |
jobStageInfo['se_name']=self.params['se_name'] |
767 |
+ |
jobStageInfo['endpoint']=self.hostname |
768 |
+ |
### ADDING SURLFORGRID FOR COPYDATA |
769 |
+ |
if not self.params['surl_for_grid']: self.params['surl_for_grid']='' |
770 |
+ |
jobStageInfo['surl_for_grid']=self.params['surl_for_grid'] |
771 |
+ |
##### |
772 |
+ |
report = { file : jobStageInfo} |
773 |
+ |
return report |
774 |
|
|
775 |
< |
echo "--> remoteSize = $remoteSize" |
776 |
< |
## for local file |
777 |
< |
localSize=$(stat -c%s "$path_out_file") |
778 |
< |
echo "--> localSize = $localSize" |
378 |
< |
if [ $localSize != $remoteSize ]; then |
379 |
< |
echo "Local fileSize $localSize does not match remote fileSize $remoteSize" |
380 |
< |
echo "Copy failed: removing remote file $destination" |
381 |
< |
srmrm $destination |
382 |
< |
cmscp_exit_status=60307 |
383 |
< |
|
384 |
< |
|
385 |
< |
echo "Problem copying $path_out_file to $destination with srmcp command" |
386 |
< |
StageOutExitStatusReason='remote and local file dimension not match' |
387 |
< |
echo "StageOutReport = `cat ./srmcp.report`" |
388 |
< |
''' |
389 |
< |
def backup(self): |
390 |
< |
""" |
391 |
< |
Check infos from TFC using existing api obtaining: |
392 |
< |
1)destination |
393 |
< |
2)protocol |
775 |
> |
def finalReport( self , results ): |
776 |
> |
""" |
777 |
> |
It a list of LFNs for each SE where data are stored. |
778 |
> |
allow "crab -copyLocal" or better "crab -copyOutput". TO_DO. |
779 |
|
""" |
780 |
+ |
outFile = open('cmscpReport.sh',"a") |
781 |
+ |
cmscp_exit_status = 0 |
782 |
+ |
txt = '' |
783 |
+ |
for file, dict in results.iteritems(): |
784 |
+ |
reason = str(dict['reason']) |
785 |
+ |
if str(reason).find("'") > -1: |
786 |
+ |
reason = " ".join(reason.split("'")) |
787 |
+ |
reason="'%s'"%reason |
788 |
+ |
if file: |
789 |
+ |
if dict['for_lfn']=='': |
790 |
+ |
lfn = '${LFNBaseName}'+os.path.basename(file) |
791 |
+ |
se = '$SE' |
792 |
+ |
LFNBaseName = '$LFNBaseName' |
793 |
+ |
else: |
794 |
+ |
lfn = dict['for_lfn']+os.path.basename(file) |
795 |
+ |
se = dict['se_name'] |
796 |
+ |
LFNBaseName = os.path.dirname(lfn) |
797 |
+ |
if (LFNBaseName[-1] != '/'): |
798 |
+ |
LFNBaseName = LFNBaseName + '/' |
799 |
+ |
|
800 |
+ |
|
801 |
+ |
txt += 'echo "Report for File: '+file+'"\n' |
802 |
+ |
txt += 'echo "LFN: '+lfn+'"\n' |
803 |
+ |
txt += 'echo "StorageElement: '+se+'"\n' |
804 |
+ |
txt += 'echo "StageOutExitStatusReason = %s" | tee -a $RUNTIME_AREA/$repo\n'%reason |
805 |
+ |
txt += 'echo "StageOutSE = '+se+'" >> $RUNTIME_AREA/$repo\n' |
806 |
+ |
|
807 |
+ |
|
808 |
+ |
if dict['erCode'] != '0': |
809 |
+ |
cmscp_exit_status = dict['erCode'] |
810 |
+ |
else: |
811 |
+ |
txt += 'echo "StageOutExitStatusReason = %s" | tee -a $RUNTIME_AREA/$repo\n'%reason |
812 |
+ |
cmscp_exit_status = dict['erCode'] |
813 |
+ |
txt += '\n' |
814 |
+ |
txt += 'export StageOutExitStatus='+str(cmscp_exit_status)+'\n' |
815 |
+ |
txt += 'echo "StageOutExitStatus = '+str(cmscp_exit_status)+'" | tee -a $RUNTIME_AREA/$repo\n' |
816 |
+ |
outFile.write(str(txt)) |
817 |
+ |
outFile.close() |
818 |
|
return |
819 |
|
|
397 |
– |
def usage(self): |
820 |
|
|
821 |
< |
msg=""" |
400 |
< |
required parameters: |
401 |
< |
--source :: REMOTE : |
402 |
< |
--destination :: REMOTE : |
403 |
< |
--debug : |
404 |
< |
--inFile :: absPath : or name NOT RELATIVE PATH |
405 |
< |
--outFIle :: onlyNAME : NOT YET SUPPORTED |
821 |
> |
def usage(): |
822 |
|
|
823 |
< |
optional parameters |
824 |
< |
""" |
825 |
< |
return msg |
823 |
> |
msg=""" |
824 |
> |
cmscp: |
825 |
> |
safe copy of local file to/from remote SE via lcg_cp/srmcp, |
826 |
> |
including success checking version also for CAF using rfcp command to copy the output to SE |
827 |
> |
|
828 |
> |
accepted parameters: |
829 |
> |
source = |
830 |
> |
destination = |
831 |
> |
inputFileList = |
832 |
> |
outputFileList = |
833 |
> |
protocol = |
834 |
> |
option = |
835 |
> |
middleware = |
836 |
> |
srm_version = |
837 |
> |
destinationDir = |
838 |
> |
lfn= = |
839 |
> |
local_stage = activate stage fall back |
840 |
> |
debug = activate verbose print out |
841 |
> |
help = print on line man and exit |
842 |
> |
|
843 |
> |
mandatory: |
844 |
> |
* "source" and/or "destination" must always be defined |
845 |
> |
* either "middleware" or "protocol" must always be defined |
846 |
> |
* "inputFileList" must always be defined |
847 |
> |
* if "local_stage" = 1 also "lfn" must be defined |
848 |
> |
""" |
849 |
> |
print msg |
850 |
> |
|
851 |
> |
return |
852 |
> |
|
853 |
> |
def HelpOptions(opts=[]): |
854 |
> |
""" |
855 |
> |
Check otps, print help if needed |
856 |
> |
prepare dict = { opt : value } |
857 |
> |
""" |
858 |
> |
dict_args = {} |
859 |
> |
if len(opts): |
860 |
> |
for opt, arg in opts: |
861 |
> |
dict_args[opt.split('--')[1]] = arg |
862 |
> |
if opt in ('-h','-help','--help') : |
863 |
> |
usage() |
864 |
> |
sys.exit(0) |
865 |
> |
return dict_args |
866 |
> |
else: |
867 |
> |
usage() |
868 |
> |
sys.exit(0) |
869 |
|
|
870 |
|
if __name__ == '__main__' : |
871 |
+ |
|
872 |
+ |
import getopt |
873 |
+ |
|
874 |
+ |
allowedOpt = ["source=", "destination=", "inputFileList=", "outputFileList=", \ |
875 |
+ |
"protocol=","option=", "middleware=", "srm_version=", \ |
876 |
+ |
"destinationDir=", "for_lfn=", "local_stage", "debug", "help", "se_name="] |
877 |
+ |
try: |
878 |
+ |
opts, args = getopt.getopt( sys.argv[1:], "", allowedOpt ) |
879 |
+ |
except getopt.GetoptError, err: |
880 |
+ |
print err |
881 |
+ |
HelpOptions() |
882 |
+ |
sys.exit(2) |
883 |
+ |
|
884 |
+ |
dictArgs = HelpOptions(opts) |
885 |
|
try: |
886 |
< |
cmscp_ = cmscp(sys.argv[1:]) |
886 |
> |
cmscp_ = cmscp(dictArgs) |
887 |
|
cmscp_.run() |
888 |
< |
except: |
889 |
< |
pass |
888 |
> |
except Exception, ex : |
889 |
> |
print str(ex) |
890 |
|
|