Package Ganga :: Package GPIDev :: Package Adapters :: Module IMonitoringService
[hide private]
[frames] | no frames]

Source Code for Module Ganga.GPIDev.Adapters.IMonitoringService

  1   
2 -class IMonitoringService:
3 """ Interface of the monitoring service. 4 Each method correponds to particular events which occur at ganga client or job wrapper (worker node). 5 The event() method is retained for backwards compatibility and other methods by default use it. 6 However it will be removed in the future. 7 """ 8
9 - def __init__(self, job_info, config_info=None):
10 """Initialize the monitoring service. 11 12 If the monitoring service is created in the Ganga client then job_info 13 is the original job object, and config_info is the original config\ 14 object returned by getConfig(). 15 16 If the monitoring service is created on the worker node then job_info is 17 the return value of getJobInfo(), and config_info is the return value of 18 getConfig().getEffectiveOptions(), i.e. a dictionary. 19 20 In order to support existing monitoring classes, which do not use 21 config_info, if getConfig() returns None, the constructor is called with 22 only the job_info argument. 23 """ 24 self.job_info = job_info 25 self.config_info = config_info
26
27 - def start(self, **opts):
28 """Application is about to start on the worker node. 29 Called by: job wrapper. 30 """ 31 return self.event('start')
32
33 - def progress(self,**opts):
34 """Application execution is in progress (called periodically, several times a second). 35 Called by: job wrapper. """ 36 return self.event('progress')
37
38 - def stop(self,exitcode,**opts):
39 """Application execution finished. 40 Called by: job wrapper. """ 41 return self.event('end',{'exitcode':exitcode})
42
43 - def prepare(self,**opts):
44 """Preparation of a job. 45 Called by: ganga client. """ 46 return self.event('prepare',{'job':self.job_info})
47
48 - def submitting(self,**opts):
49 """Just before the submission of a job. 50 Called by: ganga client. """ 51 return self.event('submitting',{'job':self.job_info})
52
53 - def submit(self,**opts):
54 """Submission of a job. 55 Called by: ganga client. """ 56 return self.event('submit',{'job':self.job_info})
57
58 - def complete(self,**opts):
59 """Completion of a job. 60 Called by: ganga client. """ 61 return self.event('complete',{'job':self.job_info})
62
63 - def fail(self,**opts):
64 """Failure of a job. 65 Called by: ganga client. """ 66 return self.event('fail',{'job':self.job_info})
67
68 - def kill(self,**opts):
69 """Killing of a job. 70 Called by: ganga client. """ 71 return self.event('kill',{'job':self.job_info})
72
73 - def rollback(self,**opts):
74 """Rollback of a job to new state (caused by error during submission). 75 Called by: ganga client. """ 76 return self.event('rollback',{'job':self.job_info})
77
78 - def getSandboxModules(self):
79 """ Get the list of module dependencies of this monitoring module. 80 Called by: ganga client. 81 82 Returns a list of modules which are imported by this module and 83 therefore must be shipped automatically to the worker node. The list 84 should include the module where this class is defined plus all modules 85 which represent the parent packages. The module containing the 86 IMonitoringService class is added automatically by the call to the 87 base class sandBoxModule() method. An example for a class defined in 88 the module Ganga/Lib/MonitoringServices/DummyMS/DummyMS.py which does 89 not have any further dependencies: 90 91 import Ganga.Lib.MonitoringServices.DummyMS 92 return IMonitoringService.getSandboxModules(self) + [ 93 Ganga, 94 Ganga.Lib, 95 Ganga.Lib.MonitoringServices, 96 Ganga.Lib.MonitoringServices.DummyMS, 97 Ganga.Lib.MonitoringServices.DummyMS.DummyMS 98 ] 99 Note, that it should be possible to import all parent modules without side effects (so without importing automatically their other children). 100 """ 101 import Ganga.GPIDev.Adapters 102 return [ Ganga, Ganga.GPIDev, Ganga.GPIDev.Adapters, Ganga.GPIDev.Adapters.IMonitoringService ]
103
104 - def getJobInfo(self):
105 """ Return a static info object which static information about the job 106 at submission time. Called by: ganga client. 107 108 The info object is passed to the contructor. Info 109 object may only contain the standard python types (such as lists, 110 dictionaries, int, strings). """ 111 112 return None
113
114 - def getConfig():
115 """Return the config object for this class. 116 117 By default this method returns None. If it is overridden to 118 return a Config object then the configuration is made available 119 consistently in the Ganga client and on the worker node via the instance 120 variable config_info. See __init__(). 121 122 For example, in your IMonitoringService implementation you could add:: 123 def getConfig(): 124 from Ganga.Utility import Config 125 return Config.getConfig("MyMS") 126 getConfig = staticmethod(getConfig) 127 128 N.B. this is a static method. 129 """ 130 return None
131 getConfig = staticmethod(getConfig) 132
134 """ Return a line of python source code which creates the instance of the monitoring service object to be used in the job wrapper script. This method should not be overriden. 135 """ 136 config = self.__class__.getConfig() 137 if config is None: 138 text = "def createMonitoringObject(): from %s import %s; return %s(%s)\n" % (self._mod_name,self.__class__.__name__,self.__class__.__name__,self.getJobInfo()) 139 else: 140 text = "def createMonitoringObject(): from %s import %s; return %s(%s, %s)\n" % (self._mod_name,self.__class__.__name__,self.__class__.__name__,self.getJobInfo(),config.getEffectiveOptions()) 141 142 return text
143 144 145 ### COMPATIBILITY INTERFACE - INTERNAL AND OBSOLETE 146
147 - def event(self,what='',values={}):
148 """Obsolete method. """ 149 pass
150