ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.53
Committed: Mon May 31 13:42:55 2010 UTC (14 years, 11 months ago) by farinafa
Content type: text/x-python
Branch: MAIN
Changes since 1.52: +58 -25 lines
Log Message:
Let's try to reduce the impact of the base64 padding mess

File Contents

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