1 |
spiga |
1.1 |
from Actor import *
|
2 |
|
|
from crab_util import *
|
3 |
|
|
import common
|
4 |
|
|
from ApmonIf import ApmonIf
|
5 |
|
|
import Statistic
|
6 |
|
|
import time
|
7 |
|
|
from ProgressBar import ProgressBar
|
8 |
|
|
from TerminalController import TerminalController
|
9 |
|
|
|
10 |
mcinquil |
1.2 |
import xml.dom.minidom
|
11 |
|
|
import xml.dom.ext
|
12 |
|
|
|
13 |
spiga |
1.1 |
class GetOutputServer(Actor):
|
14 |
|
|
|
15 |
|
|
def __init__(self, cfg_params,):
|
16 |
|
|
self.cfg_params = cfg_params
|
17 |
spiga |
1.3 |
try:
|
18 |
|
|
self.server_name = self.cfg_params['CRAB.server_name'] # gsiftp://pcpg01.cern.ch/data/SEDir/
|
19 |
|
|
except KeyError:
|
20 |
|
|
msg = 'No server selected ...'
|
21 |
|
|
msg = msg + 'Please specify a server in the crab cfg file'
|
22 |
|
|
raise CrabException(msg)
|
23 |
spiga |
1.1 |
return
|
24 |
|
|
|
25 |
|
|
def run(self):
|
26 |
|
|
"""
|
27 |
|
|
The main method of the class: retrieve the output from server
|
28 |
|
|
"""
|
29 |
|
|
common.logger.debug(5, "GetOutput server::run() called")
|
30 |
|
|
|
31 |
|
|
start = time.time()
|
32 |
|
|
|
33 |
|
|
common.scheduler.checkProxy()
|
34 |
|
|
|
35 |
|
|
common.taskDB.load()
|
36 |
|
|
WorkDirName =os.path.basename(os.path.split(common.work_space.topDir())[0])
|
37 |
|
|
projectUniqName = 'crab_'+str(WorkDirName)+'_'+common.taskDB.dict("TasKUUID")
|
38 |
|
|
#Need to add a check on the treashold level
|
39 |
|
|
# and on the task readness TODO
|
40 |
|
|
try:
|
41 |
mcinquil |
1.7 |
### retrieving project from the server
|
42 |
|
|
common.logger.message("Retrieving the project from the server...\n")
|
43 |
mcinquil |
1.2 |
|
44 |
|
|
copyHere = common.work_space.resDir() # MATT
|
45 |
|
|
# print copyHere
|
46 |
|
|
# print self.cfg_params["USER.outputdir"]
|
47 |
|
|
# if os.path.isdir(self.cfg_params["USER.outputdir"]): # MATT
|
48 |
|
|
# copyHere = self.cfg_params["USER.outputdir"] + "/" # MATT
|
49 |
|
|
|
50 |
mcinquil |
1.6 |
cmd = 'lcg-cp --vo cms --verbose gsiftp://' + str(self.server_name) + str(projectUniqName)+'/res/done.tar.gz file://'+copyHere+'done.tar.gz'# MATT
|
51 |
mcinquil |
1.2 |
common.logger.debug(5, cmd)
|
52 |
spiga |
1.1 |
copyOut = os.system(cmd +' >& /dev/null')
|
53 |
|
|
except:
|
54 |
|
|
msg = ("Output not yet available")
|
55 |
|
|
raise CrabException(msg)
|
56 |
|
|
|
57 |
mcinquil |
1.6 |
zipOut = "done.tar.gz"
|
58 |
mcinquil |
1.7 |
if os.path.exists( copyHere + zipOut ):
|
59 |
spiga |
1.1 |
cwd = os.getcwd()
|
60 |
mcinquil |
1.7 |
os.chdir( copyHere )
|
61 |
spiga |
1.1 |
common.logger.debug( 5, 'tar -zxvf ' + zipOut )
|
62 |
spiga |
1.3 |
cmd = 'tar -zxvf ' + zipOut
|
63 |
spiga |
1.5 |
cmd += '; mv .tmpDone/* .; rm -drf .tmpDone/'
|
64 |
spiga |
1.1 |
cmd_out = runCommand(cmd)
|
65 |
|
|
os.chdir(cwd)
|
66 |
mcinquil |
1.7 |
common.logger.debug( 5, 'rm -f '+copyHere+zipOut )
|
67 |
|
|
cmd = 'rm -f '+copyHere+zipOut
|
68 |
spiga |
1.1 |
cmd_out = runCommand(cmd)
|
69 |
|
|
|
70 |
mcinquil |
1.2 |
try:
|
71 |
|
|
file = open(common.work_space.resDir()+"xmlReportFile.xml", "r")
|
72 |
|
|
doc = xml.dom.minidom.parse(common.work_space.resDir()+ "xmlReportFile.xml" )
|
73 |
|
|
|
74 |
|
|
task = doc.childNodes[0].childNodes[1].getAttribute("taskName")
|
75 |
|
|
self.countToTjob = int(doc.childNodes[0].childNodes[1].getAttribute("totJob") )
|
76 |
|
|
|
77 |
mcinquil |
1.7 |
ended = doc.childNodes[0].childNodes[1].getAttribute("ended")
|
78 |
|
|
|
79 |
mcinquil |
1.2 |
addTree = 3
|
80 |
|
|
if doc.childNodes[0].childNodes[3].getAttribute("id") != "all":
|
81 |
|
|
common.jobDB.load()
|
82 |
|
|
for job in range( self.countToTjob ):
|
83 |
|
|
idJob = doc.childNodes[0].childNodes[job+addTree].getAttribute("id")
|
84 |
|
|
status = doc.childNodes[0].childNodes[job+addTree].getAttribute("status")
|
85 |
|
|
cleared = doc.childNodes[0].childNodes[job+addTree].getAttribute("cleared")
|
86 |
mcinquil |
1.4 |
if int(cleared) == 1 and (status == "Done" or status == "Done (Failed)"):
|
87 |
mcinquil |
1.2 |
common.jobDB.setStatus( str(int(idJob)-1), "Y" )
|
88 |
|
|
addTree += 1
|
89 |
|
|
common.jobDB.save()
|
90 |
|
|
except Exception, ex:
|
91 |
|
|
msg = ("problems reading report file: " + str(ex))
|
92 |
|
|
raise CrabException(msg)
|
93 |
|
|
|
94 |
mcinquil |
1.7 |
common.logger.message('Task Completed at '+str(ended)+' %\n')
|
95 |
spiga |
1.1 |
msg='Results of project '+str(WorkDirName)+' succesfuly retrieved from the server \n'
|
96 |
mcinquil |
1.7 |
msg+='and copied in '+copyHere+' \n'
|
97 |
|
|
common.logger.message(msg)
|
98 |
spiga |
1.1 |
else:
|
99 |
|
|
common.logger.message(" Output is not yet ready untill job is not finished (check it with the [status] option).\n")
|
100 |
|
|
|
101 |
|
|
return
|
102 |
|
|
|