ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ApmonIf.py
(Generate patch)

Comparing COMP/CRAB/python/ApmonIf.py (file contents):
Revision 1.8 by corvo, Mon Apr 3 08:58:22 2006 UTC vs.
Revision 1.9 by corvo, Tue Apr 4 16:13:47 2006 UTC

# Line 1 | Line 1
1 < import apmon, sys, common
1 > from DashboardAPI import apmonSend, apmonFree    
2  
3   class ApmonIf:
4      """
5      Provides an interface to the Monalisa Apmon python module
6      """
7 <    def __init__(self, address='http://lxgate35.cern.ch:40808/ApMonConf'):
8 <        self._params = {}
7 >    def __init__(self, taskid=None, jobid=None) :
8 >        self.taskId = taskid
9 >        self.jobId = jobid
10          self.fName = 'mlCommonInfo'
10        self._MLaddress = address
11        self.apm = None
12        self.apm = self.getApmonInstance()
11  
12 <    def fillDict(self, parr):
13 <        """
14 <        Used to fill the dictionary of key/value pair and instantiate the ML client
15 <        """
16 <        self._params = parr
12 >    #def fillDict(self, parr):
13 >    #    """
14 >    #    Obsolete
15 >    #    """
16 >    #    pass
17      
18 <    def sendToML(self):
19 <        self.apm.sendParameters(self._params['taskId'], self._params['jobId'], self._params)
20 <        
21 <    def getApmonInstance(self):
22 <        if self.apm is None :
23 <            try:
24 <                apmonUrls = ["http://lxgate35.cern.ch:40808/ApMonConf", "http://monalisa.cacr.caltech.edu:40808/ApMonConf"]
25 <                apmInstance = apmon.ApMon(apmonUrls, apmon.Logger.FATAL);
26 <                if not apmInstance.initializedOK():
27 <                    print "It seems that ApMon cannot read its configuration. Setting the default destination"
28 <                apmInstance.setDestinations({'lxgate35.cern.ch:58884': {'sys_monitoring':0, 'general_info':0, 'job_monitoring':1, 'job_interval':300}});
29 <            except:
30 <                exctype, value = sys.exc_info()[:2]
31 <                print "ApmonIf::getApmonInstance Exception raised %s Value: %s"%(exctype, value)
32 <                common.logger.message("ApmonIf::getApmonInstance Exception raised: %s %s"%(exctype, value))
33 <                return
34 <        return apmInstance
35 <        
18 >    def sendToML(self, params, jobid=None, taskid=None):
19 >        # Figure out taskId and jobId
20 >        taskId = 'unknown'
21 >        jobId = 'unknown'
22 >        # taskId
23 >        if self.taskId is not None :
24 >            taskId = self.taskId
25 >        if params.has_key('taskId') :
26 >            taskId = params['taskId']
27 >        if taskid is not None :
28 >            taskId = taskid
29 >        # jobId
30 >        if self.jobId is not None :
31 >            jobId = self.jobId
32 >        if params.has_key('jobId') :
33 >            jobId = params['jobId']
34 >        if jobid is not None :
35 >            jobId = jobid
36 >        # Send to Monalisa
37 >        apmonSend(taskId, jobId, params)
38 >            
39      def free(self):
40 <        self.apm.free()
40 >        apmonFree()
41 >
42 > if __name__ == '__main__' :
43 >    apmonIf = ApmonIf()
44 >    apmonIf.sendToML({'taskId' : 'Test-ApmonIf', 'jobId': 'jobid', 'param-to-send':'value-to-send'})
45 >    apmonIf.free()
46 >    apmonIf = ApmonIf('Test-ApmonIf-Constuctor-Argument')
47 >    apmonIf.sendToML({'jobId': 'jobid', 'param-to-send':'value-to-send'})
48 >    apmonIf.sendToML({'param-to-send':'value-to-send'}, 'jobid-method-argument')
49 >    apmonIf.sendToML({'param-to-send':'value-to-send'}, 'jobid-method-argument', 'Test-ApmonIf-Override-Argument')
50 >    apmonIf.sendToML({'taskId': 'Test-ApmonIf-Override-Params','param-to-send':'value-to-send'}, 'jobid-method-argument')
51 >    apmonIf.free()
52 >    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines