1 |
< |
#!/usr/bin/env python |
1 |
> |
##!/usr/bin/env python |
2 |
|
|
3 |
|
import sys, os |
4 |
|
from ProdCommon.Storage.SEAPI.SElement import SElement, FullPath |
19 |
|
$3 if needed: file name (the output file name) |
20 |
|
$5 remote SE (complete endpoint) |
21 |
|
$6 srm version |
22 |
+ |
--lfn $LFNBaseName |
23 |
|
output: |
24 |
|
return 0 if all ok |
25 |
|
return 60307 if srmcp failed |
27 |
|
""" |
28 |
|
|
29 |
|
#set default |
30 |
< |
self.params = {"source":'', "destination":'', "inputFileList":'', "outputFileList":'', \ |
31 |
< |
"protocol":'', "option":'', "middleware":'', "srm_version":'srmv2'} |
30 |
> |
self.params = {"source":'', "destination":'','destinationDir':'', "inputFileList":'', "outputFileList":'', \ |
31 |
> |
"protocol":'', "option":'', "middleware":'', "srm_version":'srmv2', "lfn":'' } |
32 |
|
self.debug = 0 |
33 |
|
|
34 |
|
self.params.update( args ) |
39 |
|
""" |
40 |
|
check command line parameter |
41 |
|
""" |
41 |
– |
|
42 |
|
if 'help' in self.params.keys(): HelpOptions() |
43 |
|
if 'debug' in self.params.keys(): self.debug = 1 |
44 |
+ |
if 'backup' in self.params.keys(): self.backup = 1 |
45 |
|
|
46 |
|
# source and dest cannot be undefined at same time |
47 |
|
if not self.params['source'] and not self.params['destination'] : |
48 |
|
HelpOptions() |
48 |
– |
|
49 |
|
# if middleware is not defined --> protocol cannot be empty |
50 |
|
if not self.params['middleware'] and not self.params['protocol'] : |
51 |
|
HelpOptions() |
52 |
|
|
53 |
|
# input file must be defined |
54 |
< |
if not self.params['inputFileList'] : HelpOptions() |
54 |
> |
if not self.params['inputFileList'] : |
55 |
> |
HelpOptions() |
56 |
|
else: |
57 |
|
file_to_copy=[] |
58 |
|
if self.params['inputFileList'].find(','): |
61 |
|
file_to_copy.append(self.params['inputFileList']) |
62 |
|
self.params['inputFileList'] = file_to_copy |
63 |
|
|
64 |
+ |
|
65 |
+ |
if not self.params['lfn'] : HelpOptions() |
66 |
+ |
|
67 |
|
## TO DO: |
68 |
|
#### add check for outFiles |
69 |
|
#### add map {'inFileNAME':'outFileNAME'} to change out name |
70 |
|
|
67 |
– |
return |
71 |
|
|
72 |
|
def run( self ): |
73 |
|
""" |
74 |
|
Check if running on UI (no $middleware) or |
75 |
|
on WN (on the Grid), and take different action |
76 |
|
""" |
74 |
– |
|
77 |
|
self.processOptions() |
78 |
+ |
if self.debug: print 'calling run() : \n' |
79 |
|
# stage out from WN |
80 |
|
if self.params['middleware'] : |
81 |
< |
results = self.stager(self.params['middleware'],self.params['inputFileList']) |
82 |
< |
self.finalReport(results) |
81 |
> |
results = self.stager(self.params['middleware'],self.params['inputFileList']) |
82 |
> |
self.finalReport(results) |
83 |
|
# Local interaction with SE |
84 |
|
else: |
85 |
< |
results = self.copy(self.params['inputFilesList'], self.params['protocol'], self.params['option'] ) |
86 |
< |
return results |
85 |
> |
results = self.copy(self.params['inputFileList'], self.params['protocol'], self.params['option'] ) |
86 |
> |
return results |
87 |
|
|
88 |
|
def setProtocol( self, middleware ): |
89 |
|
""" |
91 |
|
which depend on scheduler |
92 |
|
""" |
93 |
|
# default To be used with "middleware" |
94 |
+ |
if self.debug: |
95 |
+ |
print 'setProtocol() :\n' |
96 |
+ |
print '\tmiddleware = %s utils \n'%middleware |
97 |
+ |
|
98 |
|
lcgOpt={'srmv1':'-b -D srmv1 -t 2400 --verbose', |
99 |
|
'srmv2':'-b -D srmv2 -t 2400 --verbose'} |
100 |
|
srmOpt={'srmv1':' -report ./srmcp.report -retry_timeout 480000 -retry_num 3 -streams_num=1 ', |
101 |
< |
'srmv2':' -report ./srmcp.report -retry_timeout 480000 -retry_num 3 '} |
101 |
> |
'srmv2':' -report=./srmcp.report -retry_timeout=480000 -retry_num=3 '} |
102 |
|
rfioOpt='' |
103 |
|
|
104 |
|
supported_protocol = None |
105 |
< |
if middleware.lower() in ['osg','lcg','condor']: |
105 |
> |
if middleware.lower() in ['osg','lcg','condor','sge']: |
106 |
|
supported_protocol = [('srm-lcg',lcgOpt[self.params['srm_version']]),\ |
107 |
< |
(self.params['srm_version'],srmOpt[self.params['srm_version']])] |
107 |
> |
(self.params['srm_version'],srmOpt[self.params['srm_version']])] |
108 |
|
elif middleware.lower() in ['lsf','caf']: |
109 |
|
supported_protocol = [('rfio',rfioOpt)] |
110 |
|
else: |
113 |
|
pass |
114 |
|
return supported_protocol |
115 |
|
|
116 |
+ |
|
117 |
+ |
def checkCopy (self, copy_results, len_list_files, prot, lfn='', se=''): |
118 |
+ |
""" |
119 |
+ |
Checks the status of copy and update result dictionary |
120 |
+ |
""" |
121 |
+ |
list_retry = [] |
122 |
+ |
list_not_existing = [] |
123 |
+ |
list_ok = [] |
124 |
+ |
|
125 |
+ |
if self.debug: |
126 |
+ |
print 'in checkCopy() :\n' |
127 |
+ |
for file, dict in copy_results.iteritems(): |
128 |
+ |
er_code = dict['erCode'] |
129 |
+ |
if er_code == '0': |
130 |
+ |
list_ok.append(file) |
131 |
+ |
reason = 'Copy succedeed with %s utils'%prot |
132 |
+ |
dict['reason'] = reason |
133 |
+ |
elif er_code == '60302': |
134 |
+ |
list_not_existing.append( file ) |
135 |
+ |
else: |
136 |
+ |
list_retry.append( file ) |
137 |
+ |
|
138 |
+ |
if self.debug: |
139 |
+ |
print "\t file %s \n"%file |
140 |
+ |
print "\t dict['erCode'] %s \n"%dict['erCode'] |
141 |
+ |
print "\t dict['reason'] %s \n"%dict['reason'] |
142 |
+ |
|
143 |
+ |
if (lfn != '') and (se != ''): |
144 |
+ |
upDict = self.updateReport(file, er_code, dict['reason'], lfn, se) |
145 |
+ |
else: |
146 |
+ |
upDict = self.updateReport(file, er_code, dict['reason']) |
147 |
+ |
|
148 |
+ |
copy_results.update(upDict) |
149 |
+ |
|
150 |
+ |
msg = '' |
151 |
+ |
if len(list_ok) != 0: |
152 |
+ |
msg += '\tCopy of %s succedeed with %s utils\n'%(str(list_ok),prot) |
153 |
+ |
if len(list_ok) != len_list_files : |
154 |
+ |
msg += '\tCopy of %s failed using %s for files \n'%(str(list_retry),prot) |
155 |
+ |
msg += '\tCopy of %s failed using %s : files not found \n'%(str(list_not_existing),prot) |
156 |
+ |
if self.debug : print msg |
157 |
+ |
|
158 |
+ |
return copy_results, list_ok, list_retry |
159 |
+ |
|
160 |
+ |
def backupCopy(self, list_retry, results): |
161 |
+ |
""" |
162 |
+ |
Tries the backup copy of output to the CloseSE |
163 |
+ |
""" |
164 |
+ |
if self.debug: |
165 |
+ |
print 'in backup() :\n' |
166 |
+ |
print '\t list_retry %s utils \n'%list_retry |
167 |
+ |
print '\t len(list_retry) %s \n'%len(list_retry) |
168 |
+ |
|
169 |
+ |
list_files = list_retry |
170 |
+ |
self.params['inputFilesList']=list_files |
171 |
+ |
|
172 |
+ |
### copy backup |
173 |
+ |
from ProdCommon.FwkJobRep.SiteLocalConfig import loadSiteLocalConfig |
174 |
+ |
siteCfg = loadSiteLocalConfig() |
175 |
+ |
seName = siteCfg.localStageOut.get("se-name", None) |
176 |
+ |
catalog = siteCfg.localStageOut.get("catalog", None) |
177 |
+ |
implName = siteCfg.localStageOut.get("command", None) |
178 |
+ |
if (implName == 'srm'): |
179 |
+ |
implName='srmv1' |
180 |
+ |
self.params['srm_version']=implName |
181 |
+ |
##### to be improved ############### |
182 |
+ |
if (implName == 'rfcp'): |
183 |
+ |
self.params['middleware']='lsf' |
184 |
+ |
#################################### |
185 |
+ |
|
186 |
+ |
self.params['protocol']=implName |
187 |
+ |
tfc = siteCfg.trivialFileCatalog() |
188 |
+ |
|
189 |
+ |
if self.debug: |
190 |
+ |
print '\t siteCFG %s \n'%siteCfg |
191 |
+ |
print '\t seName %s \n'%seName |
192 |
+ |
print '\t catalog %s \n'%catalog |
193 |
+ |
print "\t self.params['protocol'] %s \n"%self.params['protocol'] |
194 |
+ |
print '\t tfc %s '%tfc |
195 |
+ |
print "\t self.params['inputFilesList'] %s \n"%self.params['inputFilesList'] |
196 |
+ |
|
197 |
+ |
file_backup=[] |
198 |
+ |
for input in self.params['inputFilesList']: |
199 |
+ |
file = self.params['lfn'] + os.path.basename(input) |
200 |
+ |
surl = tfc.matchLFN(tfc.preferredProtocol, file) |
201 |
+ |
file_backup.append(surl) |
202 |
+ |
if self.debug: |
203 |
+ |
print '\t lfn %s \n'%self.params['lfn'] |
204 |
+ |
print '\t file %s \n'%file |
205 |
+ |
print '\t surl %s \n'%surl |
206 |
+ |
|
207 |
+ |
destination=os.path.dirname(file_backup[0]) |
208 |
+ |
self.params['destination']=destination |
209 |
+ |
|
210 |
+ |
if self.debug: |
211 |
+ |
print "\t self.params['destination']%s \n"%self.params['destination'] |
212 |
+ |
print "\t self.params['protocol'] %s \n"%self.params['protocol'] |
213 |
+ |
print "\t self.params['option']%s \n"%self.params['option'] |
214 |
+ |
|
215 |
+ |
for prot, opt in self.setProtocol( self.params['middleware'] ): |
216 |
+ |
if self.debug: print '\tIn backup trying the stage out with %s utils \n'%prot |
217 |
+ |
backup_results = self.copy( self.params['inputFileList'], prot, opt ) |
218 |
+ |
if backup_results.keys() == [''] or backup_results.keys() == '' : |
219 |
+ |
results.update(backup_results) |
220 |
+ |
else: |
221 |
+ |
backup_results, list_ok, list_retry = self.checkCopy(backup_results, len(list_files), prot, self.params['lfn'], seName) |
222 |
+ |
results.update(backup_results) |
223 |
+ |
if len(list_ok) == len(list_files) : |
224 |
+ |
break |
225 |
+ |
if len(list_retry): |
226 |
+ |
list_files = list_retry |
227 |
+ |
else: break |
228 |
+ |
if self.debug: |
229 |
+ |
print "\t backup_results = %s \n"%backup_results |
230 |
+ |
|
231 |
+ |
return results |
232 |
+ |
|
233 |
|
def stager( self, middleware, list_files ): |
234 |
|
""" |
235 |
|
Implement the logic for remote stage out |
236 |
|
""" |
237 |
+ |
|
238 |
+ |
if self.debug: |
239 |
+ |
print 'stager() :\n' |
240 |
+ |
print '\tmiddleware %s\n'%middleware |
241 |
+ |
print '\list_files %s\n'%list_files |
242 |
+ |
|
243 |
|
results={} |
244 |
|
for prot, opt in self.setProtocol( middleware ): |
245 |
< |
if self.debug: print 'Trying stage out with %s utils \n'%prot |
245 |
> |
if self.debug: print '\tTrying the stage out with %s utils \n'%prot |
246 |
|
copy_results = self.copy( list_files, prot, opt ) |
247 |
< |
list_retry = [] |
118 |
< |
list_existing = [] |
119 |
< |
list_ok = [] |
120 |
< |
if copy_results.keys() == '': |
247 |
> |
if copy_results.keys() == [''] or copy_results.keys() == '' : |
248 |
|
results.update(copy_results) |
249 |
|
else: |
250 |
< |
for file, dict in copy_results.iteritems(): |
124 |
< |
er_code = dict['erCode'] |
125 |
< |
if er_code == '0': |
126 |
< |
list_ok.append(file) |
127 |
< |
reason = 'Copy succedeed with %s utils'%prot |
128 |
< |
upDict = self.updateReport(file, er_code, reason) |
129 |
< |
copy_results.update(upDict) |
130 |
< |
elif er_code == '60303': list_existing.append( file ) |
131 |
< |
else: list_retry.append( file ) |
250 |
> |
copy_results, list_ok, list_retry = self.checkCopy(copy_results, len(list_files), prot) |
251 |
|
results.update(copy_results) |
133 |
– |
if len(list_ok) != 0: |
134 |
– |
msg = 'Copy of %s succedeed with %s utils\n'%(str(list_ok),prot) |
135 |
– |
if self.debug : print msg |
252 |
|
if len(list_ok) == len(list_files) : |
253 |
|
break |
254 |
< |
else: |
255 |
< |
if self.debug : print 'Copy of files %s failed using %s...\n'%(str(list_retry)+str(list_existing),prot) |
256 |
< |
if len(list_retry): list_files = list_retry |
257 |
< |
else: break |
258 |
< |
|
259 |
< |
#### TODO Daniele |
260 |
< |
#check is something fails and created related dict |
261 |
< |
# backup = self.analyzeResults(results) |
262 |
< |
|
263 |
< |
# if backup : |
148 |
< |
# msg = 'WARNING: backup logic is under implementation\n' |
149 |
< |
# #backupDict = self.backup() |
150 |
< |
# ### NOTE: IT MUST RETURN a DICT contains also LFN and SE Name |
151 |
< |
# results.update(backupDict) |
152 |
< |
# print msg |
254 |
> |
if len(list_retry): |
255 |
> |
list_files = list_retry |
256 |
> |
else: break |
257 |
> |
|
258 |
> |
if self.backup: |
259 |
> |
if len(list_retry): |
260 |
> |
results = self.backupCopy(list_retry, results) |
261 |
> |
|
262 |
> |
if self.debug: |
263 |
> |
print "\t results %s \n"%results |
264 |
|
return results |
265 |
|
|
266 |
|
def initializeApi(self, protocol ): |
267 |
|
""" |
268 |
|
Instantiate storage interface |
269 |
|
""" |
270 |
+ |
if self.debug : print 'initializeApi() :\n' |
271 |
|
self.source_prot = protocol |
272 |
|
self.dest_prot = protocol |
273 |
|
if not self.params['source'] : self.source_prot = 'local' |
276 |
|
Destination_SE = self.storageInterface( self.params['destination'], self.dest_prot ) |
277 |
|
|
278 |
|
if self.debug : |
279 |
< |
print '(source=%s, protocol=%s)'%(self.params['source'], self.source_prot) |
280 |
< |
print '(destination=%s, protocol=%s)'%(self.params['destination'], self.dest_prot) |
279 |
> |
msg = '\t(source=%s, protocol=%s)'%(self.params['source'], self.source_prot) |
280 |
> |
msg += '\t(destination=%s, protocol=%s)'%(self.params['destination'], self.dest_prot) |
281 |
> |
print msg |
282 |
|
|
283 |
|
return Source_SE, Destination_SE |
284 |
|
|
286 |
|
""" |
287 |
|
Make the real file copy using SE API |
288 |
|
""" |
289 |
+ |
msg = "" |
290 |
|
if self.debug : |
291 |
< |
print 'copy(): using %s protocol'%protocol |
291 |
> |
msg = 'copy() :\n' |
292 |
> |
msg += '\tusing %s protocol\n'%protocol |
293 |
> |
print msg |
294 |
|
try: |
295 |
|
Source_SE, Destination_SE = self.initializeApi( protocol ) |
296 |
|
except Exception, ex: |
297 |
|
return self.updateReport('', '-1', str(ex)) |
298 |
|
|
299 |
|
# create remote dir |
300 |
< |
if protocol in ['gridftp','rfio']: |
300 |
> |
if Destination_SE.protocol in ['gridftp','rfio','srmv2']: |
301 |
|
try: |
302 |
< |
self.createDir( Destination_SE, protocol ) |
302 |
> |
self.createDir( Destination_SE, Destination_SE.protocol ) |
303 |
|
except Exception, ex: |
304 |
|
return self.updateReport('', '60316', str(ex)) |
305 |
|
|
309 |
|
sbi_dest = SBinterface(Destination_SE) |
310 |
|
sbi_source = SBinterface(Source_SE) |
311 |
|
except ProtocolMismatch, ex: |
312 |
< |
msg = str(ex)+'\n' |
313 |
< |
msg += "ERROR : Unable to create SBinterface with %s protocol\n"%protocol |
314 |
< |
return self.updateReport('', '-1', str(ex)) |
312 |
> |
msg = "ERROR : Unable to create SBinterface with %s protocol"%protocol |
313 |
> |
msg += str(ex) |
314 |
> |
return self.updateReport('', '-1', msg) |
315 |
|
|
316 |
|
results = {} |
317 |
|
## loop over the complete list of files |
318 |
|
for filetocopy in list_file: |
319 |
< |
if self.debug : print 'start real copy for %s'%filetocopy |
319 |
> |
if self.debug : print '\tStart real copy for %s'%filetocopy |
320 |
|
try : |
321 |
< |
ErCode, msg = self.checkFileExist( sbi_source, sbi_dest, filetocopy ) |
321 |
> |
ErCode, msg = self.checkFileExist( sbi_source, sbi_dest, filetocopy, options ) |
322 |
|
except Exception, ex: |
323 |
|
ErCode = -1 |
324 |
|
msg = str(ex) |
325 |
|
if ErCode == '0': |
326 |
|
ErCode, msg = self.makeCopy( sbi, filetocopy , options, protocol,sbi_dest ) |
327 |
< |
if self.debug : print 'Copy results for %s is %s'%( os.path.basename(filetocopy), ErCode) |
327 |
> |
if self.debug : print '\tCopy results for %s is %s'%( os.path.basename(filetocopy), ErCode) |
328 |
|
results.update( self.updateReport(filetocopy, ErCode, msg)) |
329 |
|
return results |
330 |
|
|
333 |
|
""" |
334 |
|
Create the storage interface. |
335 |
|
""" |
336 |
+ |
if self.debug : print 'storageInterface():\n' |
337 |
|
try: |
338 |
|
interface = SElement( FullPath(endpoint), protocol ) |
339 |
|
except ProtocolUnknown, ex: |
340 |
< |
msg = '' |
341 |
< |
if self.debug : msg = str(ex)+'\n' |
225 |
< |
msg += "ERROR : Unable to create interface with %s protocol\n"%protocol |
340 |
> |
msg = "ERROR : Unable to create interface with %s protocol"%protocol |
341 |
> |
msg += str(ex) |
342 |
|
raise Exception(msg) |
343 |
|
|
344 |
|
return interface |
348 |
|
Create remote dir for gsiftp REALLY TEMPORARY |
349 |
|
this should be transparent at SE API level. |
350 |
|
""" |
351 |
+ |
if self.debug : print 'createDir():\n' |
352 |
|
msg = '' |
353 |
|
try: |
354 |
|
action = SBinterface( Destination_SE ) |
355 |
|
action.createDir() |
356 |
< |
if self.debug: msg+= "The directory has been created using protocol %s\n"%protocol |
356 |
> |
if self.debug: print "\tThe directory has been created using protocol %s"%protocol |
357 |
|
except TransferException, ex: |
358 |
< |
msg = str(ex) |
358 |
> |
msg = "ERROR: problem with the directory creation using %s protocol "%protocol |
359 |
> |
msg += str(ex) |
360 |
|
if self.debug : |
361 |
< |
msg += str(ex.detail)+'\n' |
362 |
< |
msg += str(ex.output)+'\n' |
363 |
< |
msg += "ERROR: problem with the directory creation using %s protocol \n"%protocol |
364 |
< |
raise Exceptions(msg) |
361 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
362 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
363 |
> |
print dbgmsg |
364 |
> |
raise Exception(msg) |
365 |
|
except OperationException, ex: |
366 |
< |
msg = str(ex) |
367 |
< |
if self.debug : msg += str(ex.detail)+'\n' |
368 |
< |
msg += "ERROR: problem with the directory creation using %s protocol \n"%protocol |
369 |
< |
|
366 |
> |
msg = "ERROR: problem with the directory creation using %s protocol "%protocol |
367 |
> |
msg += str(ex) |
368 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
369 |
> |
raise Exception(msg) |
370 |
> |
except MissingDestination, ex: |
371 |
> |
msg = "ERROR: problem with the directory creation using %s protocol "%protocol |
372 |
> |
msg += str(ex) |
373 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
374 |
> |
raise Exception(msg) |
375 |
> |
except AlreadyExistsException, ex: |
376 |
> |
if self.debug: print "\tThe directory already exist" |
377 |
> |
pass |
378 |
|
return msg |
379 |
|
|
380 |
< |
def checkFileExist( self, sbi_source, sbi_dest, filetocopy ): |
380 |
> |
def checkFileExist( self, sbi_source, sbi_dest, filetocopy, option ): |
381 |
|
""" |
382 |
|
Check both if source file exist AND |
383 |
|
if destination file ALREADY exist. |
384 |
|
""" |
385 |
+ |
if self.debug : print 'checkFileExist():\n' |
386 |
|
ErCode = '0' |
387 |
|
msg = '' |
388 |
|
f_tocopy=filetocopy |
389 |
|
if self.source_prot != 'local':f_tocopy = os.path.basename(filetocopy) |
390 |
|
try: |
391 |
< |
checkSource = sbi_source.checkExists( f_tocopy ) |
391 |
> |
checkSource = sbi_source.checkExists( f_tocopy , opt=option ) |
392 |
> |
if self.debug : print '\tCheck for local file %s exist succeded \n'%f_tocopy |
393 |
|
except OperationException, ex: |
394 |
< |
msg = str(ex) |
394 |
> |
msg ='ERROR: problems checkig if source file %s exist'%filetocopy |
395 |
> |
msg += str(ex) |
396 |
|
if self.debug : |
397 |
< |
msg += str(ex.detail)+'\n' |
398 |
< |
msg += str(ex.output)+'\n' |
399 |
< |
msg +='ERROR: problems checkig if source file %s exist'%filetocopy |
397 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
398 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
399 |
> |
print dbgmsg |
400 |
|
raise Exception(msg) |
401 |
|
except WrongOption, ex: |
402 |
< |
msg = str(ex) |
402 |
> |
msg ='ERROR problems checkig if source file % exist'%filetocopy |
403 |
> |
msg += str(ex) |
404 |
|
if self.debug : |
405 |
< |
msg += str(ex.detail)+'\n' |
406 |
< |
msg += str(ex.output)+'\n' |
407 |
< |
msg +='ERROR problems checkig if source file % exist'%filetocopy |
405 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
406 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
407 |
> |
print dbgmsg |
408 |
> |
raise Exception(msg) |
409 |
> |
except MissingDestination, ex: |
410 |
> |
msg ='ERROR problems checkig if source file % exist'%filetocopy |
411 |
> |
msg += str(ex) |
412 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
413 |
|
raise Exception(msg) |
414 |
|
if not checkSource : |
415 |
|
ErCode = '60302' |
416 |
|
msg = "ERROR file %s do not exist"%os.path.basename(filetocopy) |
417 |
|
return ErCode, msg |
283 |
– |
|
418 |
|
f_tocopy=filetocopy |
419 |
|
if self.dest_prot != 'local':f_tocopy = os.path.basename(filetocopy) |
420 |
|
try: |
421 |
< |
check = sbi_dest.checkExists( f_tocopy ) |
421 |
> |
check = sbi_dest.checkExists( f_tocopy, opt=option ) |
422 |
> |
if self.debug : print '\tCheck for remote file %s exist succeded \n'%f_tocopy |
423 |
|
except OperationException, ex: |
424 |
< |
msg = str(ex) |
424 |
> |
msg = 'ERROR: problems checkig if file %s already exist'%filetocopy |
425 |
> |
msg += str(ex) |
426 |
|
if self.debug : |
427 |
< |
msg += str(ex.detail)+'\n' |
428 |
< |
msg += str(ex.output)+'\n' |
429 |
< |
msg +='ERROR: problems checkig if file %s already exist'%filetocopy |
427 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
428 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
429 |
> |
print dbgmsg |
430 |
|
raise Exception(msg) |
431 |
|
except WrongOption, ex: |
432 |
< |
msg = str(ex) |
432 |
> |
msg = 'ERROR problems checkig if file % already exist'%filetocopy |
433 |
> |
msg += str(ex) |
434 |
|
if self.debug : |
435 |
< |
msg += str(ex.detail)+'\n' |
436 |
< |
msg += str(ex.output)+'\n' |
437 |
< |
msg +='ERROR problems checkig if file % already exist'%filetocopy |
435 |
> |
msg += '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
436 |
> |
msg += '\t'+str(ex.output)+'\n' |
437 |
> |
raise Exception(msg) |
438 |
> |
except MissingDestination, ex: |
439 |
> |
msg ='ERROR problems checkig if source file % exist'%filetocopy |
440 |
> |
msg += str(ex) |
441 |
> |
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
442 |
|
raise Exception(msg) |
443 |
|
if check : |
444 |
|
ErCode = '60303' |
450 |
|
""" |
451 |
|
call the copy API. |
452 |
|
""" |
453 |
+ |
if self.debug : print 'makeCopy():\n' |
454 |
|
path = os.path.dirname(filetocopy) |
455 |
|
file_name = os.path.basename(filetocopy) |
456 |
|
source_file = filetocopy |
458 |
|
if self.params['source'] == '' and path == '': |
459 |
|
source_file = os.path.abspath(filetocopy) |
460 |
|
elif self.params['destination'] =='': |
461 |
< |
dest_file = os.path.join(os.getcwd(),file_name) |
461 |
> |
destDir = self.params.get('destinationDir',os.getcwd()) |
462 |
> |
dest_file = os.path.join(destDir,file_name) |
463 |
|
elif self.params['source'] != '' and self.params['destination'] != '' : |
464 |
|
source_file = file_name |
465 |
|
|
469 |
|
try: |
470 |
|
sbi.copy( source_file , dest_file , opt = option) |
471 |
|
except TransferException, ex: |
472 |
< |
msg = str(ex) |
472 |
> |
msg = "Problem copying %s file" % filetocopy |
473 |
> |
msg += str(ex) |
474 |
|
if self.debug : |
475 |
< |
msg += str(ex.detail)+'\n' |
476 |
< |
msg += str(ex.output)+'\n' |
477 |
< |
msg += "Problem copying %s file" % filetocopy |
475 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
476 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
477 |
> |
print dbgmsg |
478 |
|
ErCode = '60307' |
479 |
|
except WrongOption, ex: |
480 |
< |
msg = str(ex) |
480 |
> |
msg = "Problem copying %s file" % filetocopy |
481 |
> |
msg += str(ex) |
482 |
> |
if self.debug : |
483 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
484 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
485 |
> |
print dbsmsg |
486 |
> |
except SizeZeroException, ex: |
487 |
> |
msg = "Problem copying %s file" % filetocopy |
488 |
> |
msg += str(ex) |
489 |
|
if self.debug : |
490 |
< |
msg += str(ex.detail)+'\n' |
491 |
< |
msg += str(ex.output)+'\n' |
492 |
< |
msg += "Problem copying %s file" % filetocopy |
490 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
491 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
492 |
> |
print dbsmsg |
493 |
|
ErCode = '60307' |
494 |
< |
if ErCode == '0' and protocol.find('srm') == 0: |
494 |
> |
if ErCode == '0' and protocol.find('srmv') == 0: |
495 |
|
remote_file_size = -1 |
496 |
|
local_file_size = os.path.getsize( source_file ) |
497 |
|
try: |
498 |
< |
remote_file_size = sbi_dest.getSize( dest_file ) |
498 |
> |
remote_file_size = sbi_dest.getSize( dest_file, opt=option ) |
499 |
> |
if self.debug : print '\t Check of remote size succeded for file %s\n'%dest_file |
500 |
|
except TransferException, ex: |
501 |
< |
msg = str(ex) |
501 |
> |
msg = "Problem checking the size of %s file" % filetocopy |
502 |
> |
msg += str(ex) |
503 |
|
if self.debug : |
504 |
< |
msg += str(ex.detail)+'\n' |
505 |
< |
msg += str(ex.output)+'\n' |
506 |
< |
msg += "Problem checking the size of %s file" % filetocopy |
504 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
505 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
506 |
> |
print dbgmsg |
507 |
|
ErCode = '60307' |
508 |
|
except WrongOption, ex: |
509 |
< |
msg = str(ex) |
509 |
> |
msg = "Problem checking the size of %s file" % filetocopy |
510 |
> |
msg += str(ex) |
511 |
|
if self.debug : |
512 |
< |
msg += str(ex.detail)+'\n' |
513 |
< |
msg += str(ex.output)+'\n' |
514 |
< |
msg += "Problem checking the size of %s file" % filetocopy |
512 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
513 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
514 |
> |
print dbgmsg |
515 |
|
ErCode = '60307' |
516 |
|
if local_file_size != remote_file_size: |
517 |
|
msg = "File size dosn't match: local size = %s ; remote size = %s " % (local_file_size, remote_file_size) |
518 |
|
ErCode = '60307' |
519 |
|
|
520 |
+ |
if ErCode != '0': |
521 |
+ |
try : |
522 |
+ |
self.removeFile( sbi_dest, dest_file, option ) |
523 |
+ |
except Exception, ex: |
524 |
+ |
msg += '\n'+str(ex) |
525 |
|
return ErCode, msg |
526 |
|
|
527 |
+ |
def removeFile( self, sbi_dest, filetocopy, option ): |
528 |
+ |
""" |
529 |
+ |
""" |
530 |
+ |
if self.debug : print 'removeFile():\n' |
531 |
+ |
f_tocopy=filetocopy |
532 |
+ |
if self.dest_prot != 'local':f_tocopy = os.path.basename(filetocopy) |
533 |
+ |
try: |
534 |
+ |
sbi_dest.delete( f_tocopy, opt=option ) |
535 |
+ |
if self.debug : '\t deletion of file %s succeeded\n'%str(filetocopy) |
536 |
+ |
except OperationException, ex: |
537 |
+ |
msg ='ERROR: problems removing partially staged file %s'%filetocopy |
538 |
+ |
msg += str(ex) |
539 |
+ |
if self.debug : |
540 |
+ |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
541 |
+ |
dbgmsg += '\t'+str(ex.output)+'\n' |
542 |
+ |
print dbgmsg |
543 |
+ |
raise Exception(msg) |
544 |
+ |
|
545 |
+ |
return |
546 |
+ |
|
547 |
|
def backup(self): |
548 |
|
""" |
549 |
|
Check infos from TFC using existing api obtaining: |
581 |
|
else: |
582 |
|
lfn = dict['lfn']+os.path.basename(file) |
583 |
|
se = dict['se'] |
584 |
+ |
|
585 |
|
#dict['lfn'] # to be implemented |
586 |
< |
txt += 'echo "Report for File: '+file+'"\n' |
587 |
< |
txt += 'echo "LFN: '+lfn+'"\n' |
588 |
< |
txt += 'echo "StorageElement: '+se+'"\n' |
586 |
> |
txt += 'echo "Report for File: '+file+'"\n' |
587 |
> |
txt += 'echo "LFN: '+lfn+'"\n' |
588 |
> |
txt += 'echo "StorageElement: '+se+'"\n' |
589 |
|
txt += 'echo "StageOutExitStatusReason ='+dict['reason']+'" | tee -a $RUNTIME_AREA/$repo\n' |
590 |
|
txt += 'echo "StageOutSE = '+se+'" >> $RUNTIME_AREA/$repo\n' |
591 |
+ |
#txt += 'export LFNBaseName='+lfn+'\n' |
592 |
+ |
txt += 'export SE='+se+'\n' |
593 |
+ |
|
594 |
|
if dict['erCode'] != '0': |
595 |
|
cmscp_exit_status = dict['erCode'] |
412 |
– |
cmscp_exit_status = dict['erCode'] |
596 |
|
else: |
597 |
+ |
txt += 'echo "StageOutExitStatusReason ='+dict['reason']+'" | tee -a $RUNTIME_AREA/$repo\n' |
598 |
|
cmscp_exit_status = dict['erCode'] |
599 |
|
cmscp_exit_status = dict['erCode'] |
600 |
|
txt += '\n' |
643 |
|
import getopt |
644 |
|
|
645 |
|
allowedOpt = ["source=", "destination=", "inputFileList=", "outputFileList=", \ |
646 |
< |
"protocol=","option=", "middleware=", "srm_version=", "debug", "help"] |
646 |
> |
"protocol=","option=", "middleware=", "srm_version=", \ |
647 |
> |
"destinationDir=","debug", "help", "lfn="] |
648 |
|
try: |
649 |
|
opts, args = getopt.getopt( sys.argv[1:], "", allowedOpt ) |
650 |
|
except getopt.GetoptError, err: |