1 |
< |
##!/usr/bin/env python |
2 |
< |
|
1 |
> |
#!/usr/bin/env python |
2 |
|
import sys, os |
3 |
|
from ProdCommon.Storage.SEAPI.SElement import SElement, FullPath |
4 |
|
from ProdCommon.Storage.SEAPI.SBinterface import * |
9 |
|
def __init__(self, args): |
10 |
|
""" |
11 |
|
cmscp |
12 |
< |
|
14 |
< |
safe copy of local file in current directory to remote SE via lcg_cp/srmcp, |
12 |
> |
safe copy of local file to/from remote SE via lcg_cp/srmcp, |
13 |
|
including success checking version also for CAF using rfcp command to copy the output to SE |
14 |
|
input: |
15 |
|
$1 middleware (CAF, LSF, LCG, OSG) |
17 |
|
$3 if needed: file name (the output file name) |
18 |
|
$5 remote SE (complete endpoint) |
19 |
|
$6 srm version |
20 |
+ |
--lfn $LFNBaseName |
21 |
|
output: |
22 |
|
return 0 if all ok |
23 |
|
return 60307 if srmcp failed |
26 |
|
|
27 |
|
#set default |
28 |
|
self.params = {"source":'', "destination":'','destinationDir':'', "inputFileList":'', "outputFileList":'', \ |
29 |
< |
"protocol":'', "option":'', "middleware":'', "srm_version":'srmv2'} |
29 |
> |
"protocol":'', "option":'', "middleware":'', "srm_version":'srmv2', "lfn":'' } |
30 |
|
self.debug = 0 |
31 |
< |
|
31 |
> |
self.local_stage = 0 |
32 |
|
self.params.update( args ) |
33 |
|
|
34 |
|
return |
37 |
|
""" |
38 |
|
check command line parameter |
39 |
|
""" |
41 |
– |
msg = '' |
40 |
|
if 'help' in self.params.keys(): HelpOptions() |
41 |
|
if 'debug' in self.params.keys(): self.debug = 1 |
42 |
+ |
if 'local_stage' in self.params.keys(): self.local_stage = 1 |
43 |
|
|
44 |
|
# source and dest cannot be undefined at same time |
45 |
|
if not self.params['source'] and not self.params['destination'] : |
46 |
< |
# HelpOptions() |
48 |
< |
msg += 'ERROR: Nor source neither destination are defined\n' |
46 |
> |
HelpOptions() |
47 |
|
# if middleware is not defined --> protocol cannot be empty |
48 |
|
if not self.params['middleware'] and not self.params['protocol'] : |
51 |
– |
msg += 'ERROR: Nor middleware neither protocol are defined\n' |
49 |
|
HelpOptions() |
50 |
|
|
51 |
|
# input file must be defined |
52 |
|
if not self.params['inputFileList'] : |
53 |
< |
#HelpOptions() |
57 |
< |
msg += 'ERROR: Input File List is not defined\n' |
53 |
> |
HelpOptions() |
54 |
|
else: |
55 |
|
file_to_copy=[] |
56 |
|
if self.params['inputFileList'].find(','): |
59 |
|
file_to_copy.append(self.params['inputFileList']) |
60 |
|
self.params['inputFileList'] = file_to_copy |
61 |
|
|
62 |
+ |
if not self.params['lfn'] and self.local_stage == 1 : HelpOptions() |
63 |
+ |
|
64 |
|
## TO DO: |
65 |
|
#### add check for outFiles |
66 |
|
#### add map {'inFileNAME':'outFileNAME'} to change out name |
67 |
|
|
70 |
– |
return msg |
68 |
|
|
69 |
|
def run( self ): |
70 |
|
""" |
71 |
|
Check if running on UI (no $middleware) or |
72 |
|
on WN (on the Grid), and take different action |
73 |
|
""" |
74 |
< |
OptRes = self.processOptions() |
78 |
< |
if OptRes != '': |
79 |
< |
result = self.updateReport( '','60307', OptRes ) |
74 |
> |
self.processOptions() |
75 |
|
if self.debug: print 'calling run() : \n' |
76 |
|
# stage out from WN |
77 |
|
if self.params['middleware'] : |
78 |
< |
if OptRes == '': results = self.stager(self.params['middleware'],self.params['inputFileList']) |
78 |
> |
results = self.stager(self.params['middleware'],self.params['inputFileList']) |
79 |
|
self.finalReport(results) |
80 |
|
# Local interaction with SE |
81 |
|
else: |
82 |
< |
if OptRes == '': results = self.copy(self.params['inputFileList'], self.params['protocol'], self.params['option'] ) |
82 |
> |
results = self.copy(self.params['inputFileList'], self.params['protocol'], self.params['option'] ) |
83 |
|
return results |
84 |
|
|
85 |
+ |
def checkLcgUtils( self ): |
86 |
+ |
""" |
87 |
+ |
_checkLcgUtils_ |
88 |
+ |
check the lcg-utils version and report |
89 |
+ |
""" |
90 |
+ |
import commands |
91 |
+ |
cmd = "lcg-cp --version | grep lcg_util" |
92 |
+ |
status, output = commands.getstatusoutput( cmd ) |
93 |
+ |
num_ver = -1 |
94 |
+ |
if output.find("not found") == -1 or status == 0: |
95 |
+ |
temp = output.split("-") |
96 |
+ |
version = "" |
97 |
+ |
if len(temp) >= 2: |
98 |
+ |
version = output.split("-")[1] |
99 |
+ |
temp = version.split(".") |
100 |
+ |
if len(temp) >= 1: |
101 |
+ |
num_ver = int(temp[0])*10 |
102 |
+ |
num_ver += int(temp[1]) |
103 |
+ |
return num_ver |
104 |
+ |
|
105 |
|
def setProtocol( self, middleware ): |
106 |
|
""" |
107 |
|
define the allowed potocols based on $middlware |
108 |
|
which depend on scheduler |
109 |
|
""" |
110 |
|
# default To be used with "middleware" |
111 |
+ |
if self.debug: |
112 |
+ |
print 'setProtocol() :\n' |
113 |
+ |
print '\tmiddleware = %s utils \n'%middleware |
114 |
+ |
|
115 |
|
lcgOpt={'srmv1':'-b -D srmv1 -t 2400 --verbose', |
116 |
|
'srmv2':'-b -D srmv2 -t 2400 --verbose'} |
117 |
+ |
if self.checkLcgUtils() >= 17: |
118 |
+ |
lcgOpt={'srmv1':'-b -D srmv1 --srm-timeout 2400 --sendreceive-timeout 2400 --connect-timeout 2400 --verbose', |
119 |
+ |
'srmv2':'-b -D srmv2 --srm-timeout 2400 --sendreceive-timeout 2400 --connect-timeout 2400 --verbose'} |
120 |
+ |
|
121 |
|
srmOpt={'srmv1':' -report ./srmcp.report -retry_timeout 480000 -retry_num 3 -streams_num=1 ', |
122 |
< |
'srmv2':' -report=./srmcp.report -retry_timeout=480000 -retry_num=3 '} |
122 |
> |
'srmv2':' -report=./srmcp.report -retry_timeout=480000 -retry_num=3 -storagetype=permanent '} |
123 |
|
rfioOpt='' |
124 |
|
|
125 |
|
supported_protocol = None |
126 |
< |
if middleware.lower() in ['osg','lcg','condor']: |
126 |
> |
if middleware.lower() in ['osg','lcg','condor','sge']: |
127 |
|
supported_protocol = [('srm-lcg',lcgOpt[self.params['srm_version']]),\ |
128 |
|
(self.params['srm_version'],srmOpt[self.params['srm_version']])] |
129 |
|
elif middleware.lower() in ['lsf','caf']: |
130 |
|
supported_protocol = [('rfio',rfioOpt)] |
131 |
+ |
elif middleware.lower() in ['pbs']: |
132 |
+ |
supported_protocol = [('rfio',rfioOpt),('local','')] |
133 |
+ |
elif middleware.lower() in ['arc']: |
134 |
+ |
supported_protocol = [('srmv2','-debug'),('srmv1','-debug')] |
135 |
|
else: |
136 |
|
## here we can add support for any kind of protocol, |
137 |
|
## maybe some local schedulers need something dedicated |
138 |
|
pass |
139 |
|
return supported_protocol |
140 |
|
|
141 |
< |
# def checkCopy(self, copy_results, list_files): |
141 |
> |
|
142 |
> |
def checkCopy (self, copy_results, len_list_files, prot, lfn='', se=''): |
143 |
> |
""" |
144 |
> |
Checks the status of copy and update result dictionary |
145 |
|
""" |
116 |
– |
#results={} |
146 |
|
list_retry = [] |
147 |
< |
list_existing = [] |
147 |
> |
list_retry_localSE = [] |
148 |
> |
list_not_existing = [] |
149 |
|
list_ok = [] |
150 |
< |
if copy_results.keys() == '': |
151 |
< |
self.results.update(copy_results) |
152 |
< |
else: |
153 |
< |
for file, dict in copy_results.iteritems(): |
154 |
< |
er_code = dict['erCode'] |
155 |
< |
if er_code == '0': |
156 |
< |
list_ok.append(file) |
157 |
< |
reason = 'Copy succedeed with %s utils'%prot |
158 |
< |
upDict = self.updateReport(file, er_code, reason) |
159 |
< |
copy_results.update(upDict) |
160 |
< |
elif er_code == '60303': list_existing.append( file ) |
161 |
< |
else: list_retry.append( file ) |
162 |
< |
results.update(copy_results) |
163 |
< |
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 |
136 |
< |
if len(list_ok) == len(list_files) : |
137 |
< |
msg = 'Copy of all files succedeed\n' |
138 |
< |
#break |
150 |
> |
|
151 |
> |
if self.debug: |
152 |
> |
print 'in checkCopy() :\n' |
153 |
> |
for file, dict in copy_results.iteritems(): |
154 |
> |
er_code = dict['erCode'] |
155 |
> |
if er_code == '0': |
156 |
> |
list_ok.append(file) |
157 |
> |
reason = 'Copy succedeed with %s utils'%prot |
158 |
> |
dict['reason'] = reason |
159 |
> |
elif er_code == '60302': |
160 |
> |
list_not_existing.append( file ) |
161 |
> |
elif er_code == '10041': |
162 |
> |
list_retry.append( file ) |
163 |
> |
## WHAT TO DO IN GENERAL FAILURE CONDITION |
164 |
|
else: |
165 |
< |
if self.debug : print 'Copy of files %s failed using %s...\n'%(str(list_retry)+str(list_existing),prot) |
166 |
< |
#if len(list_retry): list_files = list_retry |
167 |
< |
return list_retry, results |
165 |
> |
list_retry_localSE.append( file ) |
166 |
> |
|
167 |
> |
if self.debug: |
168 |
> |
print "\t file %s \n"%file |
169 |
> |
print "\t dict['erCode'] %s \n"%dict['erCode'] |
170 |
> |
print "\t dict['reason'] %s \n"%dict['reason'] |
171 |
> |
|
172 |
> |
if (lfn != '') and (se != ''): |
173 |
> |
upDict = self.updateReport(file, er_code, dict['reason'], lfn, se) |
174 |
> |
else: |
175 |
> |
upDict = self.updateReport(file, er_code, dict['reason']) |
176 |
> |
|
177 |
> |
copy_results.update(upDict) |
178 |
> |
|
179 |
> |
msg = '' |
180 |
> |
if len(list_ok) != 0: |
181 |
> |
msg += '\tCopy of %s succedeed with %s utils\n'%(str(list_ok),prot) |
182 |
> |
if len(list_ok) != len_list_files : |
183 |
> |
msg += '\tCopy of %s failed using %s for files \n'%(str(list_retry),prot) |
184 |
> |
msg += '\tCopy of %s failed using %s : files not found \n'%(str(list_not_existing),prot) |
185 |
> |
if self.debug : print msg |
186 |
> |
|
187 |
> |
return copy_results, list_ok, list_retry, list_retry_localSE |
188 |
> |
|
189 |
> |
def LocalCopy(self, list_retry, results): |
190 |
> |
""" |
191 |
> |
Tries the stage out to the CloseSE |
192 |
> |
""" |
193 |
> |
if self.debug: |
194 |
> |
print 'in LocalCopy() :\n' |
195 |
> |
print '\t list_retry %s utils \n'%list_retry |
196 |
> |
print '\t len(list_retry) %s \n'%len(list_retry) |
197 |
> |
|
198 |
> |
list_files = list_retry |
199 |
> |
self.params['inputFilesList']=list_files |
200 |
> |
|
201 |
> |
### copy backup |
202 |
> |
from ProdCommon.FwkJobRep.SiteLocalConfig import loadSiteLocalConfig |
203 |
> |
siteCfg = loadSiteLocalConfig() |
204 |
> |
seName = siteCfg.localStageOut.get("se-name", None) |
205 |
> |
catalog = siteCfg.localStageOut.get("catalog", None) |
206 |
> |
implName = siteCfg.localStageOut.get("command", None) |
207 |
> |
if (implName == 'srm'): |
208 |
> |
implName='srmv1' |
209 |
> |
self.params['srm_version']=implName |
210 |
> |
##### to be improved ############### |
211 |
> |
if (implName == 'rfcp'): |
212 |
> |
self.params['middleware']='lsf' |
213 |
> |
#################################### |
214 |
> |
|
215 |
> |
self.params['protocol']=implName |
216 |
> |
tfc = siteCfg.trivialFileCatalog() |
217 |
> |
|
218 |
> |
if self.debug: |
219 |
> |
print '\t siteCFG %s \n'%siteCfg |
220 |
> |
print '\t seName %s \n'%seName |
221 |
> |
print '\t catalog %s \n'%catalog |
222 |
> |
print "\t self.params['protocol'] %s \n"%self.params['protocol'] |
223 |
> |
print '\t tfc %s '%tfc |
224 |
> |
print "\t self.params['inputFilesList'] %s \n"%self.params['inputFilesList'] |
225 |
> |
|
226 |
> |
#if (str(self.params['lfn']).find("/store/") != -1): |
227 |
> |
# temp = str(self.params['lfn']).split("/store/") |
228 |
> |
# self.params['lfn']= "/store/temp/" + temp[1] |
229 |
> |
if (str(self.params['lfn']).find("/store/") == 0): |
230 |
> |
temp = str(self.params['lfn']).replace("/store/","/store/temp/",1) |
231 |
> |
self.params['lfn']= temp |
232 |
|
|
233 |
< |
""" |
233 |
> |
if ( self.params['lfn'][-1] != '/' ) : self.params['lfn'] = self.params['lfn'] + '/' |
234 |
> |
|
235 |
> |
file_backup=[] |
236 |
> |
for input in self.params['inputFilesList']: |
237 |
> |
file = self.params['lfn'] + os.path.basename(input) |
238 |
> |
surl = tfc.matchLFN(tfc.preferredProtocol, file) |
239 |
> |
file_backup.append(surl) |
240 |
> |
if self.debug: |
241 |
> |
print '\t lfn %s \n'%self.params['lfn'] |
242 |
> |
print '\t file %s \n'%file |
243 |
> |
print '\t surl %s \n'%surl |
244 |
> |
|
245 |
> |
destination=os.path.dirname(file_backup[0]) |
246 |
> |
if ( destination[-1] != '/' ) : destination = destination + '/' |
247 |
> |
self.params['destination']=destination |
248 |
> |
|
249 |
> |
if self.debug: |
250 |
> |
print "\t self.params['destination']%s \n"%self.params['destination'] |
251 |
> |
print "\t self.params['protocol'] %s \n"%self.params['protocol'] |
252 |
> |
print "\t self.params['option']%s \n"%self.params['option'] |
253 |
> |
|
254 |
> |
for prot, opt in self.setProtocol( self.params['middleware'] ): |
255 |
> |
if self.debug: print '\tIn LocalCopy trying the stage out with %s utils \n'%prot |
256 |
> |
localCopy_results = self.copy( self.params['inputFileList'], prot, opt, backup='yes' ) |
257 |
> |
if localCopy_results.keys() == [''] or localCopy_results.keys() == '' : |
258 |
> |
results.update(localCopy_results) |
259 |
> |
else: |
260 |
> |
localCopy_results, list_ok, list_retry, list_retry_localSE = self.checkCopy(localCopy_results, len(list_files), prot, self.params['lfn'], seName) |
261 |
> |
results.update(localCopy_results) |
262 |
> |
if len(list_ok) == len(list_files) : |
263 |
> |
break |
264 |
> |
if len(list_retry): |
265 |
> |
list_files = list_retry |
266 |
> |
else: break |
267 |
> |
if self.debug: |
268 |
> |
print "\t localCopy_results = %s \n"%localCopy_results |
269 |
> |
|
270 |
> |
return results |
271 |
> |
|
272 |
|
def stager( self, middleware, list_files ): |
273 |
|
""" |
274 |
|
Implement the logic for remote stage out |
275 |
|
""" |
276 |
|
|
277 |
< |
if self.debug: print 'stager() :\n' |
277 |
> |
if self.debug: |
278 |
> |
print 'stager() :\n' |
279 |
> |
print '\tmiddleware %s\n'%middleware |
280 |
> |
print '\tlist_files %s\n'%list_files |
281 |
> |
|
282 |
|
results={} |
283 |
|
for prot, opt in self.setProtocol( middleware ): |
284 |
|
if self.debug: print '\tTrying the stage out with %s utils \n'%prot |
285 |
|
copy_results = self.copy( list_files, prot, opt ) |
155 |
– |
######## to define a new function checkCopy ################ |
156 |
– |
#list_retry, self.results = self.checkCopy(copy_results, list_files) |
157 |
– |
#def checkCopy (self, copy_results): |
158 |
– |
# """ |
159 |
– |
# """ |
160 |
– |
# results={} |
161 |
– |
list_retry = [] |
162 |
– |
list_existing = [] |
163 |
– |
list_ok = [] |
286 |
|
if copy_results.keys() == [''] or copy_results.keys() == '' : |
287 |
|
results.update(copy_results) |
288 |
|
else: |
289 |
< |
for file, dict in copy_results.iteritems(): |
168 |
< |
er_code = dict['erCode'] |
169 |
< |
if er_code == '0': |
170 |
< |
list_ok.append(file) |
171 |
< |
reason = 'Copy succedeed with %s utils'%prot |
172 |
< |
upDict = self.updateReport(file, er_code, reason) |
173 |
< |
copy_results.update(upDict) |
174 |
< |
elif er_code in ['60303','60302']: list_existing.append( file ) |
175 |
< |
else: list_retry.append( file ) |
289 |
> |
copy_results, list_ok, list_retry, list_retry_localSE = self.checkCopy(copy_results, len(list_files), prot) |
290 |
|
results.update(copy_results) |
177 |
– |
msg = '' |
178 |
– |
if len(list_ok) != 0: |
179 |
– |
msg += '\tCopy of %s succedeed with %s utils\n'%(str(list_ok),prot) |
291 |
|
if len(list_ok) == len(list_files) : |
292 |
|
break |
293 |
< |
else: |
294 |
< |
if self.debug: msg += '\tCopy of %s failed using %s...\n'%(str(list_retry)+str(list_existing),prot) |
295 |
< |
if len(list_retry): list_files = list_retry |
296 |
< |
else: break |
297 |
< |
if self.debug : print msg |
298 |
< |
""" |
299 |
< |
if len(list_retry): |
300 |
< |
list_files = list_retry |
301 |
< |
#def backupCopy(list_retry) |
302 |
< |
print "in backup" |
192 |
< |
self.params['inputFilesList']=list_files |
193 |
< |
### copy backup |
194 |
< |
from ProdCommon.FwkJobRep.SiteLocalConfig import loadSiteLocalConfig |
195 |
< |
siteCfg = loadSiteLocalConfig() |
196 |
< |
#print siteCfg |
197 |
< |
seName = siteCfg.localStageOut.get("se-name", None) |
198 |
< |
#print "seName = ", seName |
199 |
< |
self.params['destination']=seName |
200 |
< |
#catalog = siteCfg.localStageOut.get("catalog", None) |
201 |
< |
#print "catalog = ", catalog |
202 |
< |
implName = siteCfg.localStageOut.get("command", None) |
203 |
< |
print "implName = ", implName |
204 |
< |
if (implName == 'srm'): |
205 |
< |
implName='srmv2' |
206 |
< |
self.params['protocol']=implName |
207 |
< |
tfc = siteCfg.trivialFileCatalog() |
208 |
< |
#print "tfc = ", tfc |
209 |
< |
print " self.params['inputFilesList'] = ", self.params['inputFilesList'] |
210 |
< |
file_backup=[] |
211 |
< |
for input in self.params['inputFilesList']: |
212 |
< |
### to add the correct lfn, passed as argument of cmscp function (--lfn xxxx) |
213 |
< |
file = '/store/'+input |
214 |
< |
pfn = tfc.matchLFN(tfc.preferredProtocol, file) |
215 |
< |
print "pfn = ", pfn |
216 |
< |
file_backup.append(pfn) |
217 |
< |
self.params['inputFilesList'] = file_backup |
218 |
< |
print "#########################################" |
219 |
< |
print "self.params['inputFilesList'] = ", self.params['inputFilesList'] |
220 |
< |
print "self.params['protocol'] = ", self.params['protocol'] |
221 |
< |
print "self.params['option'] = ", self.params['option'] |
222 |
< |
self.copy(self.params['inputFilesList'], self.params['protocol'], self.params['option']) |
223 |
< |
print "#########################################" |
224 |
< |
###list_retry, self.results = checkCopy(copy_results) |
225 |
< |
#check is something fails and created related dict |
226 |
< |
# backup = self.analyzeResults(results) |
227 |
< |
# if backup : |
228 |
< |
# msg = 'WARNING: backup logic is under implementation\n' |
229 |
< |
# #backupDict = self.backup() |
230 |
< |
# ### NOTE: IT MUST RETURN a DICT contains also LFN and SE Name |
231 |
< |
# results.update(backupDict) |
232 |
< |
# print msg |
233 |
< |
""" |
234 |
< |
#### TODO Daniele |
235 |
< |
#check is something fails and created related dict |
236 |
< |
# backup = self.analyzeResults(results) |
237 |
< |
|
238 |
< |
# if backup : |
239 |
< |
# msg = 'WARNING: backup logic is under implementation\n' |
240 |
< |
# #backupDict = self.backup() |
241 |
< |
# ### NOTE: IT MUST RETURN a DICT contains also LFN and SE Name |
242 |
< |
# results.update(backupDict) |
243 |
< |
# print msg |
293 |
> |
if len(list_retry): |
294 |
> |
list_files = list_retry |
295 |
> |
else: break |
296 |
> |
|
297 |
> |
if self.local_stage: |
298 |
> |
if len(list_retry_localSE): |
299 |
> |
results = self.LocalCopy(list_retry_localSE, results) |
300 |
> |
|
301 |
> |
if self.debug: |
302 |
> |
print "\t results %s \n"%results |
303 |
|
return results |
304 |
|
|
305 |
|
def initializeApi(self, protocol ): |
321 |
|
|
322 |
|
return Source_SE, Destination_SE |
323 |
|
|
324 |
< |
def copy( self, list_file, protocol, options ): |
324 |
> |
def copy( self, list_file, protocol, options, backup='no' ): |
325 |
|
""" |
326 |
|
Make the real file copy using SE API |
327 |
|
""" |
328 |
+ |
msg = "" |
329 |
|
if self.debug : |
330 |
|
msg = 'copy() :\n' |
331 |
|
msg += '\tusing %s protocol\n'%protocol |
333 |
|
try: |
334 |
|
Source_SE, Destination_SE = self.initializeApi( protocol ) |
335 |
|
except Exception, ex: |
336 |
< |
return self.updateReport('', '-1', str(ex)) |
336 |
> |
for filetocopy in list_file: |
337 |
> |
results.update( self.updateReport(filetocopy, '-1', str(ex))) |
338 |
> |
return results |
339 |
|
|
340 |
|
# create remote dir |
341 |
|
if Destination_SE.protocol in ['gridftp','rfio','srmv2']: |
342 |
|
try: |
343 |
|
self.createDir( Destination_SE, Destination_SE.protocol ) |
344 |
+ |
except OperationException, ex: |
345 |
+ |
for filetocopy in list_file: |
346 |
+ |
results.update( self.updateReport(filetocopy, '60316', str(ex))) |
347 |
+ |
return results |
348 |
+ |
## when the client commands are not found (wrong env or really missing) |
349 |
+ |
except MissingCommand, ex: |
350 |
+ |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
351 |
+ |
for filetocopy in list_file: |
352 |
+ |
results.update( self.updateReport(filetocopy, '10041', msg)) |
353 |
+ |
return results |
354 |
|
except Exception, ex: |
355 |
< |
return self.updateReport('', '60316', str(ex)) |
355 |
> |
msg = "ERROR %s" %(str(ex)) |
356 |
> |
for filetocopy in list_file: |
357 |
> |
results.update( self.updateReport(filetocopy, '-1', msg)) |
358 |
> |
return results |
359 |
|
|
360 |
|
## prepare for real copy ## |
361 |
|
try : |
365 |
|
except ProtocolMismatch, ex: |
366 |
|
msg = "ERROR : Unable to create SBinterface with %s protocol"%protocol |
367 |
|
msg += str(ex) |
368 |
< |
return self.updateReport('', '-1', msg) |
368 |
> |
for filetocopy in list_file: |
369 |
> |
results.update( self.updateReport(filetocopy, '-1', msg)) |
370 |
> |
return results |
371 |
|
|
372 |
|
results = {} |
373 |
|
## loop over the complete list of files |
376 |
|
try : |
377 |
|
ErCode, msg = self.checkFileExist( sbi_source, sbi_dest, filetocopy, options ) |
378 |
|
except Exception, ex: |
379 |
< |
ErCode = -1 |
379 |
> |
ErCode = '60307' |
380 |
|
msg = str(ex) |
381 |
|
if ErCode == '0': |
382 |
|
ErCode, msg = self.makeCopy( sbi, filetocopy , options, protocol,sbi_dest ) |
383 |
+ |
if (ErCode == '0') and (backup == 'yes'): |
384 |
+ |
ErCode = '60308' |
385 |
|
if self.debug : print '\tCopy results for %s is %s'%( os.path.basename(filetocopy), ErCode) |
386 |
|
results.update( self.updateReport(filetocopy, ErCode, msg)) |
387 |
|
return results |
469 |
|
msg += str(ex) |
470 |
|
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
471 |
|
raise Exception(msg) |
472 |
+ |
## when the client commands are not found (wrong env or really missing) |
473 |
+ |
except MissingCommand, ex: |
474 |
+ |
ErCode = '10041' |
475 |
+ |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
476 |
+ |
return ErCode, msg |
477 |
|
if not checkSource : |
478 |
|
ErCode = '60302' |
479 |
|
msg = "ERROR file %s do not exist"%os.path.basename(filetocopy) |
503 |
|
msg += str(ex) |
504 |
|
if self.debug : print '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
505 |
|
raise Exception(msg) |
506 |
+ |
## when the client commands are not found (wrong env or really missing) |
507 |
+ |
except MissingCommand, ex: |
508 |
+ |
ErCode = '10041' |
509 |
+ |
msg = "ERROR %s %s" %(str(ex), str(ex.detail)) |
510 |
+ |
return ErCode, msg |
511 |
|
if check : |
512 |
|
ErCode = '60303' |
513 |
|
msg = "file %s already exist"%os.path.basename(filetocopy) |
534 |
|
ErCode = '0' |
535 |
|
msg = '' |
536 |
|
|
537 |
+ |
if self.params['option'].find('space_token')>0: |
538 |
+ |
space_token=self.params['option'].split('=')[1] |
539 |
+ |
if protocol == 'srmv2': option = '%s -space_token=%s'%(option,space_token) |
540 |
+ |
if protocol == 'srm-lcg': option = '%s -S %s'%(option,space_token) |
541 |
|
try: |
542 |
|
sbi.copy( source_file , dest_file , opt = option) |
543 |
|
except TransferException, ex: |
554 |
|
if self.debug : |
555 |
|
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
556 |
|
dbgmsg += '\t'+str(ex.output)+'\n' |
557 |
< |
print dbsmsg |
557 |
> |
print dbgmsg |
558 |
> |
except SizeZeroException, ex: |
559 |
> |
msg = "Problem copying %s file" % filetocopy |
560 |
> |
msg += str(ex) |
561 |
> |
if self.debug : |
562 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
563 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
564 |
> |
print dbgmsg |
565 |
> |
ErCode = '60307' |
566 |
> |
## when the client commands are not found (wrong env or really missing) |
567 |
> |
except MissingCommand, ex: |
568 |
> |
ErCode = '10041' |
569 |
> |
msg = "Problem copying %s file" % filetocopy |
570 |
> |
msg += str(ex) |
571 |
> |
if self.debug : |
572 |
> |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
573 |
> |
dbgmsg += '\t'+str(ex.output)+'\n' |
574 |
> |
print dbgmsg |
575 |
> |
except AuthorizationException, ex: |
576 |
|
ErCode = '60307' |
577 |
+ |
msg = "Problem copying %s file" % filetocopy |
578 |
+ |
msg += str(ex) |
579 |
+ |
if self.debug : |
580 |
+ |
dbgmsg = '\t'+msg+'\n\t'+str(ex.detail)+'\n' |
581 |
+ |
dbgmsg += '\t'+str(ex.output)+'\n' |
582 |
+ |
print dbgmsg |
583 |
|
if ErCode == '0' and protocol.find('srmv') == 0: |
584 |
|
remote_file_size = -1 |
585 |
|
local_file_size = os.path.getsize( source_file ) |
633 |
|
|
634 |
|
return |
635 |
|
|
519 |
– |
def backup(self): |
520 |
– |
""" |
521 |
– |
Check infos from TFC using existing api obtaining: |
522 |
– |
1)destination |
523 |
– |
2)protocol |
524 |
– |
""" |
525 |
– |
return |
526 |
– |
|
636 |
|
def updateReport(self, file, erCode, reason, lfn='', se='' ): |
637 |
|
""" |
638 |
|
Update the final stage out infos |
655 |
|
cmscp_exit_status = 0 |
656 |
|
txt = '' |
657 |
|
for file, dict in results.iteritems(): |
658 |
+ |
reason = str(dict['reason']) |
659 |
+ |
if str(reason).find("'") > -1: |
660 |
+ |
reason = " ".join(reason.split("'")) |
661 |
+ |
reason="'%s'"%reason |
662 |
|
if file: |
663 |
|
if dict['lfn']=='': |
664 |
< |
lfn = '$LFNBaseName/'+os.path.basename(file) |
664 |
> |
lfn = '${LFNBaseName}'+os.path.basename(file) |
665 |
|
se = '$SE' |
666 |
+ |
LFNBaseName = '$LFNBaseName' |
667 |
|
else: |
668 |
|
lfn = dict['lfn']+os.path.basename(file) |
669 |
|
se = dict['se'] |
670 |
+ |
LFNBaseName = os.path.dirname(lfn) |
671 |
+ |
if (LFNBaseName[-1] != '/'): |
672 |
+ |
LFNBaseName = LFNBaseName + '/' |
673 |
|
#dict['lfn'] # to be implemented |
674 |
< |
txt += 'echo "Report for File: '+file+'"\n' |
675 |
< |
txt += 'echo "LFN: '+lfn+'"\n' |
676 |
< |
txt += 'echo "StorageElement: '+se+'"\n' |
677 |
< |
txt += 'echo "StageOutExitStatusReason ='+dict['reason']+'" | tee -a $RUNTIME_AREA/$repo\n' |
674 |
> |
txt += 'echo "Report for File: '+file+'"\n' |
675 |
> |
txt += 'echo "LFN: '+lfn+'"\n' |
676 |
> |
txt += 'echo "StorageElement: '+se+'"\n' |
677 |
> |
txt += 'echo "StageOutExitStatusReason = %s" | tee -a $RUNTIME_AREA/$repo\n'%reason |
678 |
|
txt += 'echo "StageOutSE = '+se+'" >> $RUNTIME_AREA/$repo\n' |
679 |
+ |
txt += 'export LFNBaseName='+LFNBaseName+'\n' |
680 |
+ |
txt += 'export SE='+se+'\n' |
681 |
+ |
|
682 |
+ |
txt += 'export endpoint='+self.params['destination']+'\n' |
683 |
+ |
|
684 |
|
if dict['erCode'] != '0': |
685 |
|
cmscp_exit_status = dict['erCode'] |
564 |
– |
cmscp_exit_status = dict['erCode'] |
686 |
|
else: |
687 |
< |
txt += 'echo "StageOutExitStatusReason ='+dict['reason']+'" | tee -a $RUNTIME_AREA/$repo\n' |
567 |
< |
cmscp_exit_status = dict['erCode'] |
687 |
> |
txt += 'echo "StageOutExitStatusReason = %s" | tee -a $RUNTIME_AREA/$repo\n'%reason |
688 |
|
cmscp_exit_status = dict['erCode'] |
689 |
|
txt += '\n' |
690 |
|
txt += 'export StageOutExitStatus='+str(cmscp_exit_status)+'\n' |
691 |
< |
txt += 'echo "StageOutExitStatus = '+str(cmscp_exit_status)+'" | tee -a $RUNTIME_AREA/$repo\n' |
691 |
> |
txt += 'echo "StageOutExitStatus = '+str(cmscp_exit_status)+'" | tee -a $RUNTIME_AREA/$repo\n' |
692 |
|
outFile.write(str(txt)) |
693 |
|
outFile.close() |
694 |
|
return |
697 |
|
def usage(): |
698 |
|
|
699 |
|
msg=""" |
700 |
< |
required parameters: |
701 |
< |
--source :: REMOTE : |
702 |
< |
--destination :: REMOTE : |
583 |
< |
--debug : |
584 |
< |
--inFile :: absPath : or name NOT RELATIVE PATH |
585 |
< |
--outFIle :: onlyNAME : NOT YET SUPPORTED |
700 |
> |
cmscp: |
701 |
> |
safe copy of local file to/from remote SE via lcg_cp/srmcp, |
702 |
> |
including success checking version also for CAF using rfcp command to copy the output to SE |
703 |
|
|
704 |
< |
optional parameters |
704 |
> |
accepted parameters: |
705 |
> |
source = |
706 |
> |
destination = |
707 |
> |
inputFileList = |
708 |
> |
outputFileList = |
709 |
> |
protocol = |
710 |
> |
option = |
711 |
> |
middleware = |
712 |
> |
srm_version = |
713 |
> |
destinationDir = |
714 |
> |
lfn= = |
715 |
> |
local_stage = activate stage fall back |
716 |
> |
debug = activate verbose print out |
717 |
> |
help = print on line man and exit |
718 |
> |
|
719 |
> |
mandatory: |
720 |
> |
* "source" and/or "destination" must always be defined |
721 |
> |
* either "middleware" or "protocol" must always be defined |
722 |
> |
* "inputFileList" must always be defined |
723 |
> |
* if "local_stage" = 1 also "lfn" must be defined |
724 |
|
""" |
725 |
|
print msg |
726 |
|
|
749 |
|
|
750 |
|
allowedOpt = ["source=", "destination=", "inputFileList=", "outputFileList=", \ |
751 |
|
"protocol=","option=", "middleware=", "srm_version=", \ |
752 |
< |
"destinationDir=","debug", "help"] |
752 |
> |
"destinationDir=", "lfn=", "local_stage", "debug", "help"] |
753 |
|
try: |
754 |
|
opts, args = getopt.getopt( sys.argv[1:], "", allowedOpt ) |
755 |
|
except getopt.GetoptError, err: |