1 |
spiga |
1.1 |
from crab_util import *
|
2 |
|
|
import common
|
3 |
|
|
import time
|
4 |
|
|
|
5 |
farinafa |
1.14 |
import traceback
|
6 |
|
|
from xml.dom import minidom
|
7 |
|
|
from ServerCommunicator import ServerCommunicator
|
8 |
|
|
from ServerConfig import *
|
9 |
|
|
|
10 |
|
|
from StatusServer import *
|
11 |
|
|
from GetOutput import *
|
12 |
|
|
|
13 |
|
|
class GetOutputServer(StatusServer, GetOutput):
|
14 |
|
|
|
15 |
|
|
def __init__(self, *args):
|
16 |
|
|
self.cfg_params = args[0]
|
17 |
|
|
self.jobs = args[1]
|
18 |
|
|
|
19 |
|
|
self.server_name = None
|
20 |
|
|
self.server_port = None
|
21 |
|
|
|
22 |
|
|
self.storage_name = None
|
23 |
|
|
self.storage_path = None
|
24 |
|
|
self.storage_proto = None
|
25 |
|
|
self.storage_port = None
|
26 |
mcinquil |
1.2 |
|
27 |
farinafa |
1.14 |
self.srvCfg = {}
|
28 |
|
|
|
29 |
|
|
try:
|
30 |
|
|
self.srvCfg = ServerConfig(self.cfg_params['CRAB.server_name']).config()
|
31 |
|
|
self.server_name = str(self.srvCfg['serverName'])
|
32 |
|
|
self.server_port = int(self.srvCfg['serverPort'])
|
33 |
|
|
self.storage_name = str(self.srvCfg['storageName'])
|
34 |
|
|
self.storage_path = str(self.srvCfg['storagePath'])
|
35 |
|
|
self.storage_proto = str(self.srvCfg['storageProtocol'])
|
36 |
|
|
self.storage_port = str(self.srvCfg['storagePort'])
|
37 |
spiga |
1.3 |
except KeyError:
|
38 |
farinafa |
1.14 |
msg = 'No server selected or port specified.'
|
39 |
|
|
msg = msg + 'Please specify a server in the crab cfg file'
|
40 |
|
|
raise CrabException(msg)
|
41 |
|
|
|
42 |
|
|
if self.storage_path[0]!='/':
|
43 |
|
|
self.storage_path = '/'+self.storage_path
|
44 |
spiga |
1.1 |
return
|
45 |
farinafa |
1.14 |
|
46 |
spiga |
1.1 |
def run(self):
|
47 |
|
|
common.logger.debug(5, "GetOutput server::run() called")
|
48 |
|
|
start = time.time()
|
49 |
|
|
common.scheduler.checkProxy()
|
50 |
|
|
|
51 |
farinafa |
1.14 |
# get updated status from server #inherited from StatusServer
|
52 |
|
|
self.resynchClientSide()
|
53 |
mcinquil |
1.2 |
|
54 |
farinafa |
1.14 |
# understand whether the required output are available
|
55 |
|
|
self.checkBeforeGet()
|
56 |
|
|
filesToRetrieve = self.list_id
|
57 |
|
|
|
58 |
|
|
# create the list with the actual filenames
|
59 |
|
|
taskuuid = str(common._db.queryTask('name'))
|
60 |
|
|
remotedir = os.path.join(self.storage_path, taskuuid)
|
61 |
|
|
|
62 |
|
|
osbTemplate = self.storage_proto + '://'+ self.storage_name +\
|
63 |
|
|
':' + self.storage_port + remotedir + '/out_%s.tgz'
|
64 |
|
|
osbFiles = [ osbTemplate%str(jid) for jid in filesToRetrieve ]
|
65 |
|
|
|
66 |
|
|
copyHere = common.work_space.resDir() # MATT
|
67 |
|
|
if "USER.outputdir" in self.cfg_params.keys() and os.path.isdir(self.cfg_params["USER.outputdir"]):
|
68 |
|
|
copyHere = self.cfg_params["USER.outputdir"] + "/"
|
69 |
|
|
destTemplate = 'file://'+copyHere+'/out_%s.tgz'
|
70 |
|
|
destFiles = [ destTemplate%str(jid) for jid in filesToRetrieve ]
|
71 |
|
|
|
72 |
|
|
# retrieve them from SE #TODO replace this with SE-API
|
73 |
|
|
for i in xrange(len(filesToRetrieve)):
|
74 |
farinafa |
1.15 |
try:
|
75 |
|
|
cmd = 'lcg-cp --vo cms %s %s'%(osbFiles[i], destFiles[i])
|
76 |
|
|
out = os.system(cmd +' >& /dev/null')
|
77 |
|
|
common.logger.debug(5, cmd)
|
78 |
|
|
if out != 0:
|
79 |
|
|
print "Unable to retrieve output file %s"%osbFiles[i]
|
80 |
|
|
del filesToRetrieve[i]
|
81 |
|
|
continue
|
82 |
|
|
|
83 |
|
|
##
|
84 |
|
|
## TODO check if sizes are ok/the transfer was safe. Simpler with the API
|
85 |
|
|
##
|
86 |
|
|
|
87 |
|
|
## clean-up SE
|
88 |
|
|
cmd = 'lcg-del --vo cms %s'%osbFiles[i]
|
89 |
|
|
out = os.system(cmd +' >& /dev/null')
|
90 |
|
|
common.logger.debug(5, cmd)
|
91 |
|
|
if out != 0:
|
92 |
|
|
print "Unable to clean up SE for output file %s. The deletion will be performed by the server"%osbFiles[i]
|
93 |
|
|
continue
|
94 |
|
|
|
95 |
|
|
except Exception, e:
|
96 |
|
|
print "Unable to retrieve output file %s"%osbFiles[i]
|
97 |
|
|
del filesToRetrieve[i]
|
98 |
|
|
continue
|
99 |
farinafa |
1.14 |
|
100 |
|
|
# notify to the server that output have been retrieved successfully. proxy from StatusServer
|
101 |
farinafa |
1.15 |
if len(filesToRetrieve) > 0:
|
102 |
|
|
common.logger.debug(5, "List of retrieved files notified to server: %s"%str(filesToRetrieve) )
|
103 |
|
|
csCommunicator = ServerCommunicator(self.server_name, self.server_port, self.cfg_params, self.proxy)
|
104 |
|
|
csCommunicator.outputRetrieved(taskuuid, filesToRetrieve)
|
105 |
spiga |
1.1 |
|
106 |
farinafa |
1.14 |
return
|
107 |
spiga |
1.1 |
|
108 |
|
|
|