ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.56
Committed: Tue Apr 3 11:59:44 2012 UTC (13 years, 1 month ago) by belforte
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_9_1, CRAB_2_9_1_pre2, CRAB_2_9_1_pre1, CRAB_2_9_0, CRAB_2_9_0_pre2, CRAB_2_9_0_pre1, CRAB_2_8_8, CRAB_2_8_8_pre1, CRAB_2_8_7_patch3, CRAB_2_8_7_patch2, CRAB_2_8_7_patch1, CRAB_2_8_7, CRAB_2_8_7_pre2, CRAB_2_8_7_pre1, CRAB_2_8_6, CRAB_2_8_6_pre1, CRAB_2_8_5_patch3, CRAB_2_8_5_patch2, CRAB_2_8_5_patch1, CRAB_2_8_5, CRAB_2_8_5_pre5, CRAB_2_8_5_pre4, CRAB_2_8_5_pre3, CRAB_2_8_4_patch3, CRAB_2_8_5_pre2, CRAB_2_8_4_patch2, CRAB_2_8_5_pre1, CRAB_2_8_4_patch1, CRAB_2_8_4, CRAB_2_8_4_pre5, CRAB_2_8_4_pre4, CRAB_2_8_4_pre3, CRAB_2_8_4_pre2, CRAB_2_8_4_pre1, CRAB_2_8_3, CRAB_2_8_3_pre4, CRAB_2_8_3_pre3, CRAB_2_8_3_pre2, CRAB_2_8_3_pre1, CRAB_2_8_2_patch1, CRAB_2_8_2, CRAB_2_8_2_pre5, CRAB_2_8_2_pre4, CRAB_2_8_2_pre3, CRAB_2_8_2_pre2, CRAB_2_8_2_pre1, HEAD
Changes since 1.55: +22 -17 lines
Log Message:
fix for https://savannah.cern.ch/bugs/?93311 : http access to server not possile. Also fix typo, cleanup retry login introducing delays and improve logging

File Contents

# Content
1 from Actor import *
2 from crab_util import *
3 import common
4 from ApmonIf import ApmonIf
5 import time
6
7 import traceback
8 from xml.dom import minidom
9 from ServerCommunicator import ServerCommunicator
10 from Status import Status
11
12 from xml.parsers.expat import *
13
14 import zlib
15
16 class StatusServer(Status):
17
18 def __init__(self, *args):
19
20 Status.__init__(self, *args)
21
22 # init client server params...
23 CliServerParams(self)
24
25 return
26
27 def query(self,display=True):
28
29 warning_msg = self.resynchClientSide()
30
31 upTask = common._db.getTask()
32 self.compute(upTask,display)
33
34 def resynchClientSide(self):
35 """
36 get status from the server and
37 aling back data on client
38 """
39 task = common._db.getTask()
40 self.task_unique_name = str(task['name'])
41
42 # communicator allocation
43 csCommunicator = ServerCommunicator(self.server_name, self.server_port, self.cfg_params)
44
45 # align back data and print
46 reportXML = None
47 warning_msg = None
48
49 max_get_status_tries = 5
50 for retry in xrange(max_get_status_tries):
51 if retry > 0 :
52 delay = pow(2,retry-1)
53 common.logger.info("Server status decoding problem. Try again in %d seconds"%delay)
54 runCommand("/bin/sleep %d"%delay)
55 handledXML = csCommunicator.getStatus( self.task_unique_name )
56 reportXML, warning_msg = self.statusDecoding(handledXML)
57 if reportXML is not None and warning_msg is None:
58 break
59 common.logger.debug(warning_msg)
60
61
62 if warning_msg is not None:
63 warning_msg = "WARNING: Unable to decompress status from server. Please issue crab -status again"
64 common.logger.info(warning_msg)
65 return warning_msg
66
67 try:
68 xmlStatus = minidom.parseString(reportXML)
69 reportList = xmlStatus.getElementsByTagName('Job')
70 common._db.deserXmlStatus(reportList)
71 except Exception, e:
72 warning_msg = "WARNING: Unable to extract status from XML file. Please issue crab -status again"
73 common.logger.info(warning_msg)
74 common.logger.debug("DUMP STATUS XML: %s"%str(reportXML))
75 common.logger.debug( str(e) )
76 common.logger.debug( traceback.format_exc() )
77 return warning_msg
78
79 return warning_msg
80
81 def statusDecoding(self, handledXML):
82 import base64
83 import urllib
84 reportXML, warning_msg = None, None
85
86 # WS channel
87 paddedXML =''
88 try:
89 paddedXML = base64.urlsafe_b64decode(handledXML)
90 except Exception, e:
91 warning_msg = "WARNING: Problem while decoding base64 status. %s" % traceback.format_exc()
92
93 #padding
94 paddedXML += "="*( len(handledXML)%4 )
95 if warning_msg is not None:
96 warning_msg = None
97 try:
98 paddedXML = base64.urlsafe_b64decode(paddedXML)
99 except Exception, e:
100 warning_msg = "WARNING: Padding fallback failed: %s" % traceback.format_exc()
101 return reportXML, warning_msg
102
103 # decompression
104 try:
105 reportXML = zlib.decompress(paddedXML)
106 warning_msg = None
107 except Exception, e:
108 reportXML = None
109 warning_msg = "WARNING: Problem while decompressing status from the server: %s"%str(e)
110
111 if warning_msg is None:
112 return reportXML, warning_msg
113 common.logger.debug("StatusServer failed: "+warning_msg + '\n' + traceback.format_exc() )
114
115 # HTTP channel not usable since firewalled
116 # try:
117 # xmlStatusURL = 'http://%s:8888/visualog/'%self.server_name
118 # xmlStatusURL += '?taskname=%s&logtype=Xmlstatus'%common._db.queryTask('name')
119 # common.logger.debug("Accessing URL for status fallback: %s"%xmlStatusURL)
120 # reportXML = ''.join(urllib.urlopen(xmlStatusURL).readlines())
121 # warning_msg = None
122 # except Exception, e:
123 # reportXML = None
124 # warning_msg = "WARNING: Unable to retrieve status from server. Please issue crab -status again"
125 # common.logger.debug(warning_msg + '\n' + traceback.format_exc() )
126 #
127 return reportXML, warning_msg
128
129 def showWebMon(self):
130 msg = 'You can also check jobs status at: http://%s:8888/logginfo\n'%self.server_name
131 msg += '\t( Your task name is: %s )\n'%common._db.queryTask('name')
132 common.logger.debug(msg)
133 #common.logger.info("Web status at: http://%s:8888/visualog/?taskname=%s&logtype=Status\n"%(self.server_name,self.task_unique_name))