CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
o2olib.O2OJobMgr Class Reference
Inheritance diagram for o2olib.O2OJobMgr:
o2olib.O2OMgr

Public Member Functions

def __init__ (self)
 
def add (self, job_name, config_filename, int_val, en_flag)
 
def connect (self, service, args)
 
def dumpConfig (self, jname, versionIndex, configFile)
 
def listConfig (self, jname)
 
def listJobs (self)
 
def migrateConfig (self)
 
def readConfiguration (self, config_filename)
 
def runManager (self)
 
def set (self, job_name, en_flag)
 
def setConfig (self, job_name, config_filename)
 
def setInterval (self, job_name, int_val)
 
- Public Member Functions inherited from o2olib.O2OMgr
def __init__ (self)
 
def getSession (self, db_service, auth)
 
def logger (self)
 

Public Attributes

 conf_dict
 
 db_connection
 
 session
 
 verbose
 
- Public Attributes inherited from o2olib.O2OMgr
 eng
 
 logger
 

Detailed Description

Definition at line 138 of file o2olib.py.

Constructor & Destructor Documentation

def o2olib.O2OJobMgr.__init__ (   self)

Definition at line 140 of file o2olib.py.

140  def __init__( self ):
141  O2OMgr.__init__(self)
142  self.db_connection = None
143  self.conf_dict = {}
144 
145 
def __init__(self)
Definition: o2olib.py:140

Member Function Documentation

def o2olib.O2OJobMgr.add (   self,
  job_name,
  config_filename,
  int_val,
  en_flag 
)

Definition at line 174 of file o2olib.py.

References relativeConstraints.error, info(), and o2olib.O2OJobMgr.readConfiguration().

Referenced by counter.Counter.register(), SequenceTypes.Task.remove(), and SequenceTypes.Task.replace().

174  def add( self, job_name, config_filename, int_val, en_flag ):
175  res = self.session.query(O2OJob.enabled).filter_by(name=job_name)
176  enabled = None
177  for r in res:
178  enabled = r
179  if enabled:
180  O2OMgr.logger( self).error( "A job called '%s' exists already.", job_name )
181  return False
182  configJson = self.readConfiguration( config_filename )
183  if configJson == '':
184  return False
185  job = O2OJob(name=job_name,tag_name='-',enabled=en_flag,interval=int_val)
186  config = O2OJobConf( job_name=job_name, insertion_time = datetime.now(), configuration = configJson )
187  self.session.add(job)
188  self.session.add(config)
189  self.session.commit()
190  O2OMgr.logger( self).info( "New o2o job '%s' created.", job_name )
191  return True
192 
static const TGPicture * info(bool iBackgroundIsBlack)
def add(self, job_name, config_filename, int_val, en_flag)
Definition: o2olib.py:174
def readConfiguration(self, config_filename)
Definition: o2olib.py:146
def o2olib.O2OJobMgr.connect (   self,
  service,
  args 
)

Definition at line 162 of file o2olib.py.

Referenced by Vispa.Gui.ZoomableScrollArea.ZoomableScrollArea.__init__(), Vispa.Views.PropertyView.BooleanProperty.__init__(), Vispa.Gui.FindDialog.FindDialog._addScript(), Vispa.Gui.FindDialog.FindDialog._addStringProperty(), Vispa.Main.Application.Application._connectSignals(), Vispa.Plugins.ConfigEditor.CodeTableView.CodeTableView._createItem(), Vispa.Gui.BoxContentDialog.BoxContentDialog.addButton(), Vispa.Gui.ToolBoxContainer.ToolBoxContainer.addWidget(), Vispa.Views.PropertyView.PropertyView.append(), Vispa.Views.PropertyView.PropertyView.appendAddRow(), Vispa.Main.Application.Application.createAction(), Vispa.Views.PropertyView.TextEditWithButtonProperty.createButton(), Vispa.Views.LineDecayView.LineDecayView.createLineDecayContainer(), Vispa.Views.PropertyView.TextEditWithButtonProperty.createLineEdit(), Vispa.Views.LineDecayView.LineDecayContainer.createObject(), Vispa.Views.PropertyView.TextEditWithButtonProperty.createTextEdit(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController.filterDialog(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController.find(), Vispa.Gui.PortWidget.PortWidget.mouseMoveEvent(), Vispa.Views.PropertyView.BooleanProperty.setChecked(), Vispa.Main.SplitterTab.SplitterTab.setController(), Vispa.Plugins.Browser.BrowserTab.BrowserTab.setController(), Vispa.Views.PropertyView.BooleanProperty.setReadOnly(), Vispa.Views.PropertyView.DropDownProperty.setReadOnly(), Vispa.Views.PropertyView.TextEditWithButtonProperty.setReadOnly(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController.setTab(), Vispa.Views.PropertyView.IntegerProperty.setValue(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController.switchCenterView(), o2o_db_cfgmap.DbManagerDAQ.update_hashmap(), Vispa.Plugins.EdmBrowser.EdmBrowserTabController.EdmBrowserTabController.updateViewMenu(), and Vispa.Plugins.ConfigEditor.ConfigEditorTabController.ConfigEditorTabController.updateViewMenu().

162  def connect( self, service, args ):
163  self.session = O2OMgr.getSession( self,service, args.auth )
164  self.verbose = args.verbose
165  if self.session is None:
166  return False
167  else:
168  self.db_connection = coral_tpl %(service[0],schema_name)
169  self.conf_dict['db']=self.db_connection
170  return True
def connect(self, service, args)
Definition: o2olib.py:162
def o2olib.O2OJobMgr.dumpConfig (   self,
  jname,
  versionIndex,
  configFile 
)

Definition at line 295 of file o2olib.py.

References relativeConstraints.error, createfilelist.int, and str.

Referenced by Types.SecSource.configValue().

295  def dumpConfig( self, jname, versionIndex, configFile ):
296  versionIndex = int(versionIndex)
297  res = self.session.query(O2OJob.enabled).filter_by(name=jname)
298  enabled = None
299  for r in res:
300  enabled = r
301  if enabled is None:
302  O2OMgr.logger( self).error( "A job called '%s' does not exist.", jname )
303  return
304  res = self.session.query( O2OJobConf.configuration, O2OJobConf.insertion_time ).filter_by(job_name=jname).order_by(O2OJobConf.insertion_time)
305  configs = []
306  for r in res:
307  configs.append((str(r[0]),r[1]))
308  ind = len(configs)
309  if versionIndex>ind or versionIndex==0:
310  O2OMgr.logger( self ).error("Configuration for job %s with index %s has not been found." %(jname,versionIndex))
311  return
312  print "Configuration #%2d for job '%s'" %(versionIndex,jname)
313  config = configs[versionIndex-1]
314  print '#%2d since %s' %(versionIndex,config[1])
315  print config[0]
316  if configFile is None or configFile == '':
317  configFile = '%s_%s.json' %(jname,versionIndex)
318  with open(configFile,'w') as json_file:
319  json_file.write(config[0])
320 
321 
def dumpConfig(self, jname, versionIndex, configFile)
Definition: o2olib.py:295
#define str(s)
def o2olib.O2OJobMgr.listConfig (   self,
  jname 
)

Definition at line 273 of file o2olib.py.

References relativeConstraints.error, info(), and str.

273  def listConfig( self, jname ):
274  res = self.session.query(O2OJob.enabled).filter_by(name=jname)
275  enabled = None
276  for r in res:
277  enabled = r
278  if enabled is None:
279  O2OMgr.logger( self).error( "A job called '%s' does not exist.", jname )
280  return
281  res = self.session.query( O2OJobConf.configuration, O2OJobConf.insertion_time ).filter_by(job_name=jname).order_by(O2OJobConf.insertion_time)
282  configs = []
283  for r in res:
284  configs.append((str(r[0]),r[1]))
285  ind = len(configs)
286  if ind:
287  print "Configurations for job '%s'" %jname
288  for cf in reversed(configs):
289  print '#%2d since: %s' %(ind,cf[1])
290  print cf[0]
291  ind -= 1
292  else:
293  O2OMgr.logger( self ).info("No configuration found for job '%s'" %jname )
294 
static const TGPicture * info(bool iBackgroundIsBlack)
def listConfig(self, jname)
Definition: o2olib.py:273
#define str(s)
def o2olib.O2OJobMgr.listJobs (   self)

Definition at line 252 of file o2olib.py.

References Vispa.Plugins.EdmBrowser.EdmDataAccessor.all(), o2olib.print_table(), and str.

Referenced by o2olib.O2OTool.execute().

252  def listJobs( self ):
253  runs = {}
254  res = self.session.query(O2ORun.job_name,sqlalchemy.func.max(O2ORun.start_time)).group_by(O2ORun.job_name).order_by(O2ORun.job_name)
255  for r in res:
256  runs[r[0]] = str(r[1])
257  res = self.session.query(O2OJob.name, O2OJob.interval, O2OJob.enabled).order_by(O2OJob.name).all()
258  table = []
259  for r in res:
260  row = []
261  row.append(r[0]),
262  row.append('%5d' %r[1] )
263  enabled = 'Y' if (r[2]==1) else 'N'
264  row.append('%4s' %enabled )
265  lastRun = '-'
266  if r[0] in runs.keys():
267  lastRun = runs[r[0]]
268  row.append( lastRun )
269  table.append(row)
270  headers = ['Job name','Interval','Enabled','Last run start']
271  print_table( headers, table )
272 
def listJobs(self)
Definition: o2olib.py:252
def print_table(headers, table)
Definition: o2olib.py:68
#define str(s)
def o2olib.O2OJobMgr.migrateConfig (   self)

Definition at line 238 of file o2olib.py.

References info().

238  def migrateConfig( self ):
239  res = self.session.query(O2OJob.name,O2OJob.tag_name)
240  for r in res:
241  job_name = r[0]
242  tag = r[1]
243  if tag != '-':
244  configDict = {}
245  configDict['tag']=tag
246  configJson = json.dumps( configDict )
247  config = O2OJobConf( job_name=job_name, insertion_time = datetime.now(), configuration = configJson )
248  self.session.add(config)
249  O2OMgr.logger( self).info( "Configuration for job '%s' inserted.", job_name )
250  self.session.commit()
251 
static const TGPicture * info(bool iBackgroundIsBlack)
def migrateConfig(self)
Definition: o2olib.py:238
def o2olib.O2OJobMgr.readConfiguration (   self,
  config_filename 
)

Definition at line 146 of file o2olib.py.

References relativeConstraints.error.

Referenced by o2olib.O2OJobMgr.add(), and o2olib.O2OJobMgr.setConfig().

146  def readConfiguration( self, config_filename ):
147  config = ''
148  try:
149  with open( config_filename, 'r' ) as config_file:
150  config = config_file.read()
151  if config == '':
152  O2OMgr.logger( self).error( 'The file %s contains an empty string.', config_filename )
153  else:
154  json.loads(config)
155  except IOError as e:
156  O2OMgr.logger( self).error( 'The file %s cannot be open.', config_filename )
157  except ValueError as e:
158  config = ''
159  O2OMgr.logger( self).error( 'The file %s contains an invalid json string.', config_filename )
160  return config
161 
def readConfiguration(self, config_filename)
Definition: o2olib.py:146
def o2olib.O2OJobMgr.runManager (   self)

Definition at line 171 of file o2olib.py.

References o2olib.O2OJobMgr.db_connection, querying.connection.session, and o2olib.O2OJobMgr.session.

171  def runManager( self ):
172  return O2ORunMgr( self.db_connection, self.session, O2OMgr.logger( self ) )
173 
def runManager(self)
Definition: o2olib.py:171
def o2olib.O2OJobMgr.set (   self,
  job_name,
  en_flag 
)

Definition at line 193 of file o2olib.py.

References relativeConstraints.error, and info().

193  def set( self, job_name, en_flag ):
194  res = self.session.query(O2OJob.enabled).filter_by(name=job_name)
195  enabled = None
196  for r in res:
197  enabled = r
198  if enabled is None:
199  O2OMgr.logger( self).error( "A job called '%s' does not exist.", job_name )
200  return
201  job = O2OJob(name=job_name,enabled=en_flag)
202  action = 'enabled'
203  if not en_flag:
204  action = 'disabled'
205  self.session.merge(job)
206  self.session.commit()
207  O2OMgr.logger( self).info( "Job '%s' %s." %(job_name,action) )
208 
static const TGPicture * info(bool iBackgroundIsBlack)
def set(self, job_name, en_flag)
Definition: o2olib.py:193
def o2olib.O2OJobMgr.setConfig (   self,
  job_name,
  config_filename 
)

Definition at line 209 of file o2olib.py.

References relativeConstraints.error, info(), and o2olib.O2OJobMgr.readConfiguration().

Referenced by o2olib.O2OTool.execute().

209  def setConfig( self, job_name, config_filename ):
210  res = self.session.query(O2OJob.enabled).filter_by(name=job_name)
211  enabled = None
212  for r in res:
213  enabled = r
214  if enabled is None:
215  O2OMgr.logger( self).error( "A job called '%s' does not exist.", job_name )
216  return
217  configJson = self.readConfiguration( config_filename )
218  if configJson == '':
219  return False
220  config = O2OJobConf( job_name=job_name, insertion_time = datetime.now(), configuration = configJson )
221  self.session.add(config)
222  self.session.commit()
223  O2OMgr.logger( self).info( "New configuration inserted for job '%s'", job_name )
224 
static const TGPicture * info(bool iBackgroundIsBlack)
def setConfig(self, job_name, config_filename)
Definition: o2olib.py:209
def readConfiguration(self, config_filename)
Definition: o2olib.py:146
def o2olib.O2OJobMgr.setInterval (   self,
  job_name,
  int_val 
)

Definition at line 225 of file o2olib.py.

References relativeConstraints.error, and info().

Referenced by o2olib.O2OTool.execute().

225  def setInterval( self, job_name, int_val ):
226  res = self.session.query(O2OJob.enabled).filter_by(name=job_name)
227  enabled = None
228  for r in res:
229  enabled = r
230  if enabled is None:
231  O2OMgr.logger( self).error( "A job called '%s' does not exist.", job_name )
232  return
233  job = O2OJob(name=job_name,interval=int_val)
234  self.session.merge(job)
235  self.session.commit()
236  O2OMgr.logger( self).info( "The execution interval for job '%s' has been updated.", job_name )
237 
static const TGPicture * info(bool iBackgroundIsBlack)
def setInterval(self, job_name, int_val)
Definition: o2olib.py:225

Member Data Documentation

o2olib.O2OJobMgr.conf_dict

Definition at line 143 of file o2olib.py.

Referenced by o2olib.O2ORunMgr.executeJob().

o2olib.O2OJobMgr.db_connection

Definition at line 142 of file o2olib.py.

Referenced by o2olib.O2OJobMgr.runManager().

o2olib.O2OJobMgr.session

Definition at line 163 of file o2olib.py.

Referenced by o2olib.O2OJobMgr.runManager().

o2olib.O2OJobMgr.verbose