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 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

◆ __init__()

def o2olib.O2OJobMgr.__init__ (   self)

Reimplemented from o2olib.O2OMgr.

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 

Member Function Documentation

◆ add()

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

Definition at line 174 of file o2olib.py.

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 

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

Referenced by o2olib.O2OJobMgr.migrateConfig(), counter.Counter.register(), SequenceTypes.Task.remove(), SequenceTypes.Task.replace(), and o2olib.O2OJobMgr.setConfig().

◆ connect()

def o2olib.O2OJobMgr.connect (   self,
  service,
  args 
)

Definition at line 162 of file o2olib.py.

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

Referenced by o2o_db_cfgmap.DbManagerDAQ.update_hashmap().

◆ dumpConfig()

def o2olib.O2OJobMgr.dumpConfig (   self,
  jname,
  versionIndex,
  configFile 
)

Definition at line 295 of file o2olib.py.

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 

References relativeConstraints.error, createfilelist.int, print(), querying.connection.session, o2olib.O2OJobMgr.session, and str.

Referenced by Types.SecSource.configValue().

◆ listConfig()

def o2olib.O2OJobMgr.listConfig (   self,
  jname 
)

Definition at line 273 of file o2olib.py.

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 

References relativeConstraints.error, info(), print(), querying.connection.session, o2olib.O2OJobMgr.session, and str.

◆ listJobs()

def o2olib.O2OJobMgr.listJobs (   self)

Definition at line 252 of file o2olib.py.

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 

References python.cmstools.all(), o2olib.print_table(), querying.connection.session, o2olib.O2OJobMgr.session, and str.

Referenced by o2olib.O2OTool.execute().

◆ migrateConfig()

def o2olib.O2OJobMgr.migrateConfig (   self)

Definition at line 238 of file o2olib.py.

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 

References o2olib.O2OJobMgr.add(), info(), querying.connection.session, and o2olib.O2OJobMgr.session.

◆ readConfiguration()

def o2olib.O2OJobMgr.readConfiguration (   self,
  config_filename 
)

Definition at line 146 of file o2olib.py.

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 

References relativeConstraints.error.

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

◆ runManager()

def o2olib.O2OJobMgr.runManager (   self)

Definition at line 171 of file o2olib.py.

171  def runManager( self ):
172  return O2ORunMgr( self.db_connection, self.session, O2OMgr.logger( self ) )
173 

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

◆ set()

def o2olib.O2OJobMgr.set (   self,
  job_name,
  en_flag 
)

Definition at line 193 of file o2olib.py.

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 

References relativeConstraints.error, info(), querying.connection.session, and o2olib.O2OJobMgr.session.

◆ setConfig()

def o2olib.O2OJobMgr.setConfig (   self,
  job_name,
  config_filename 
)

Definition at line 209 of file o2olib.py.

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 

References o2olib.O2OJobMgr.add(), relativeConstraints.error, info(), o2olib.O2OJobMgr.readConfiguration(), querying.connection.session, and o2olib.O2OJobMgr.session.

Referenced by o2olib.O2OTool.execute().

◆ setInterval()

def o2olib.O2OJobMgr.setInterval (   self,
  job_name,
  int_val 
)

Definition at line 225 of file o2olib.py.

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 

References relativeConstraints.error, info(), querying.connection.session, and o2olib.O2OJobMgr.session.

Referenced by o2olib.O2OTool.execute().

Member Data Documentation

◆ conf_dict

o2olib.O2OJobMgr.conf_dict

Definition at line 143 of file o2olib.py.

Referenced by o2olib.O2ORunMgr.executeJob().

◆ db_connection

o2olib.O2OJobMgr.db_connection

Definition at line 142 of file o2olib.py.

Referenced by o2olib.O2OJobMgr.runManager().

◆ session

o2olib.O2OJobMgr.session

◆ verbose

o2olib.O2OJobMgr.verbose
o2olib.print_table
def print_table(headers, table)
Definition: o2olib.py:68
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
relativeConstraints.error
error
Definition: relativeConstraints.py:53
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
query
Definition: query.py:1
str
#define str(s)
Definition: TestProcessor.cc:51
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
createfilelist.int
int
Definition: createfilelist.py:10
DBConfiguration_cff.connect
connect
Definition: DBConfiguration_cff.py:18
Herwig7_Dummy_Matchbox_90X_ppToee.dumpConfig
dumpConfig
Definition: Herwig7_Dummy_Matchbox_90X_ppToee.py:8
merge
Definition: merge.py:1