CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
conddb_version_mgr.conddb_tool Class Reference
Inheritance diagram for conddb_version_mgr.conddb_tool:

Public Member Functions

def __init__ (self)
 
def connect (self)
 
def insert_boost_run (self)
 
def list_boost_run (self)
 
def process_tag_boost_version (self, t, timetype, tagBoostVersion, minIov, timeCut, validate)
 
def show_tag_boost_version (self)
 
def update_tag_boost_version_in_db (self, t, tagBoostVersion, minIov, update)
 
def update_tags (self)
 
def validate_boost_version (self, t, timetype, tagBoostVersion)
 

Public Attributes

 args
 
 db
 
 iovs
 
 logger
 
 version_db
 
 versionIovs
 

Detailed Description

Definition at line 139 of file conddb_version_mgr.py.

Constructor & Destructor Documentation

def conddb_version_mgr.conddb_tool.__init__ (   self)

Definition at line 140 of file conddb_version_mgr.py.

140  def __init__( self ):
141  self.db = None
142  self.version_db = None
143  self.args = None
144  self.logger = logging.getLogger()
145  self.logger.setLevel(logLevel)
146  consoleHandler = logging.StreamHandler(sys.stdout)
147  consoleHandler.setFormatter(logFormatter)
148  self.logger.addHandler(consoleHandler)
149  self.iovs = None
150  self.versionIovs = None
151 

Member Function Documentation

def conddb_version_mgr.conddb_tool.connect (   self)

Definition at line 152 of file conddb_version_mgr.py.

References conddb_version_mgr.version_db.db, conddb_version_mgr.conddb_tool.db, HcalLutManager.db, and relativeConstraints.keys.

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().

152  def connect( self ):
153  if self.args.db is None:
154  self.args.db = 'pro'
155  if self.args.db == 'dev' or self.args.db == 'oradev' :
156  db_service = dev_db_service
157  elif self.args.db == 'orapro':
158  db_service = adg_db_service
159  elif self.args.db != 'onlineorapro' or self.args.db != 'pro':
160  db_service = prod_db_service
161  else:
162  raise Exception("Database '%s' is not known." %args.db )
163  if self.args.accessType not in db_service[1].keys():
164  raise Exception('The specified database connection %s does not support the requested action.' %db_service[0])
165  service = db_service[1][self.args.accessType]
166  creds = auth.get_credentials( authPathEnvVar, service, self.args.auth )
167  if creds is None:
168  raise Exception("Could not find credentials for service %s" %service)
169  (username, account, pwd) = creds
170  connStr = '%s/%s@%s' %(username,pwd,db_service[0])
171  self.db = cx_Oracle.connect(connStr)
172  logging.info('Connected to %s as user %s' %(db_service[0],username))
173  self.db.current_schema = schema_name
174 
def conddb_version_mgr.conddb_tool.insert_boost_run (   self)

Definition at line 368 of file conddb_version_mgr.py.

References conddb_version_mgr.version_db.db, conddb_version_mgr.conddb_tool.db, HcalLutManager.db, and conddb_version_mgr.conddb_tool.version_db.

368  def insert_boost_run( self ):
369  cursor = self.db.cursor()
370  self.version_db = version_db( self.db )
371  self.version_db.insert_boost_run_range( self.args.since, self.args.label )
372  self.db.commit()
373  logging.info('boost version %s inserted with since %s' %(self.args.label,self.args.since))
374 
def conddb_version_mgr.conddb_tool.list_boost_run (   self)

Definition at line 375 of file conddb_version_mgr.py.

References conddb_version_mgr.version_db.db, conddb_version_mgr.conddb_tool.db, HcalLutManager.db, conddb_version_mgr.print_table(), and conddb_version_mgr.conddb_tool.version_db.

375  def list_boost_run( self ):
376  cursor = self.db.cursor()
377  self.version_db = version_db( self.db )
378  self.version_db.fetch_boost_run_map()
379  headers = ['Run','Run start time','Boost Version','Insertion time']
380  print_table( headers, self.version_db.boost_run_map )
381 
def print_table(headers, table)
def conddb_version_mgr.conddb_tool.process_tag_boost_version (   self,
  t,
  timetype,
  tagBoostVersion,
  minIov,
  timeCut,
  validate 
)

Definition at line 175 of file conddb_version_mgr.py.

References conddb_version_mgr.conddb_tool.iovs, str, and conddb_version_mgr.conddb_tool.versionIovs.

Referenced by conddb_version_mgr.conddb_tool.show_tag_boost_version(), conddb_version_mgr.conddb_tool.update_tags(), and conddb_version_mgr.conddb_tool.validate_boost_version().

175  def process_tag_boost_version( self, t, timetype, tagBoostVersion, minIov, timeCut, validate ):
176  if self.iovs is None:
177  self.iovs = []
178  cursor = self.db.cursor()
179  stmt = 'SELECT IOV.SINCE SINCE, IOV.INSERTION_TIME INSERTION_TIME, P.STREAMER_INFO STREAMER_INFO FROM TAG, IOV, PAYLOAD P WHERE TAG.NAME = IOV.TAG_NAME AND P.HASH = IOV.PAYLOAD_HASH AND TAG.NAME = :TAG_NAME'
180  params = (t,)
181  if timeCut and tagBoostVersion is not None and not validate:
182  whereClauseOnSince = ' AND IOV.INSERTION_TIME>:TIME_CUT'
183  stmt = stmt + whereClauseOnSince
184  params = params + (timeCut,)
185  stmt = stmt + ' ORDER BY SINCE'
186  logging.debug('Executing: "%s"' %stmt)
187  cursor.execute(stmt,params)
188  for r in cursor:
189  streamer_info = str(r[2].read())
190  self.iovs.append((r[0],r[1],streamer_info))
191  niovs = 0
192  self.versionIovs = []
193  lastBoost = None
194  update = False
195  if tagBoostVersion is not None:
196  update = True
197  for iov in self.iovs:
198  if validate and timeCut is not None and timeCut < iov[1]:
199  continue
200  niovs += 1
201  iovBoostVersion, tagBoostVersion = sm.update_tag_boost_version( tagBoostVersion, minIov, iov[2], iov[0], timetype, self.version_db.boost_run_map )
202  if minIov is None or iov[0]<minIov:
203  minIov = iov[0]
204  logging.debug('iov: %s - inserted on %s - streamer: %s' %(iov[0],iov[1],iov[2]))
205  logging.debug('current tag boost version: %s minIov: %s' %(tagBoostVersion,minIov))
206  if lastBoost is None or lastBoost!=iovBoostVersion:
207  self.versionIovs.append((iov[0],iovBoostVersion))
208  lastBoost = iovBoostVersion
209 
210  if tagBoostVersion is None:
211  if niovs == 0:
212  logging.warning( 'No iovs found. boost version cannot be determined.')
213  return None, None
214  else:
215  logging.error('Could not determine the tag boost version.' )
216  return None, None
217  else:
218  if niovs == 0:
219  logging.info('Tag boost version has not changed.')
220  else:
221  msg = 'Found tag boost version %s ( min iov: %s ) combining payloads from %s iovs' %(tagBoostVersion,minIov,niovs)
222  if timeCut is not None:
223  if update:
224  msg += ' (iov insertion time>%s)' %str(timeCut)
225  else:
226  msg += ' (iov insertion time<%s)' %str(timeCut)
227  logging.info( msg )
228  return tagBoostVersion, minIov
229 
#define str(s)
def process_tag_boost_version(self, t, timetype, tagBoostVersion, minIov, timeCut, validate)
def conddb_version_mgr.conddb_tool.show_tag_boost_version (   self)

Definition at line 382 of file conddb_version_mgr.py.

References conddb_version_mgr.version_db.db, conddb_version_mgr.conddb_tool.db, HcalLutManager.db, conddb_version_mgr.conddb_tool.iovs, edm.print(), conddb_version_mgr.print_table(), conddb_version_mgr.conddb_tool.process_tag_boost_version(), str, conddb_version_mgr.conddb_tool.version_db, and conddb_version_mgr.conddb_tool.versionIovs.

383  cursor = self.db.cursor()
384  tag = self.args.tag_name
385  cursor.execute('SELECT TIME_TYPE FROM TAG WHERE NAME= :TAG_NAME',(tag,))
386  rows = cursor.fetchall()
387  timeType = None
388  t_modificationTime = None
389  for r in rows:
390  timeType = r[0]
391  if timeType is None:
392  raise Exception("Tag %s does not exist in the database." %tag)
393  cursor.execute('SELECT MAX(INSERTION_TIME) FROM IOV WHERE TAG_NAME= :TAG_NAME',(tag,))
394  rows = cursor.fetchall()
395  for r in rows:
396  t_modificationTime = r[0]
397  if t_modificationTime is None:
398  raise Exception("Tag %s does not have any iov stored." %tag)
399  logging.info('Tag %s - timetype: %s' %(tag,timeType))
400  cursor.execute('SELECT MIN_SERIALIZATION_V, MIN_SINCE, MODIFICATION_TIME FROM TAG_METADATA WHERE TAG_NAME= :TAG_NAME',(tag,))
401  rows = cursor.fetchall()
402  tagBoostVersion = None
403  minIov = None
404  v_modificationTime = None
405  for r in rows:
406  tagBoostVersion = r[0]
407  minIov = r[1]
408  v_modificationTime = r[2]
409  if v_modificationTime is not None:
410  if t_modificationTime > v_modificationTime:
411  logging.warning('The minimum boost version stored is out of date.')
412  else:
413  logging.info('The minimum boost version stored is up to date.')
414  mt = '-'
415  if v_modificationTime is not None:
416  mt = str(v_modificationTime)
417  r_tagBoostVersion = None
418  if self.args.rebuild or self.args.full:
419  self.version_db = version_db( self.db )
420  self.version_db.fetch_boost_run_map()
421  timeCut = None
422  logging.info('Calculating minimum boost version for the available iovs...')
423  r_tagBoostVersion, r_minIov = self.process_tag_boost_version( tag, timeType, tagBoostVersion, minIov, timeCut )
424  print('# Currently stored: %s (min iov:%s)' %(tagBoostVersion,minIov))
425  print('# Last update: %s' %mt)
426  print('# Last update on the iovs: %s' %str(t_modificationTime))
427  if self.args.rebuild or self.args.full:
428  print('# Based on the %s available IOVs: %s (min iov:%s)' %(len(self.iovs),r_tagBoostVersion,r_minIov))
429  if self.args.full:
430  headers = ['Run','Boost Version']
431  print_table( headers, self.versionIovs )
432 
def print_table(headers, table)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)
def process_tag_boost_version(self, t, timetype, tagBoostVersion, minIov, timeCut, validate)
def conddb_version_mgr.conddb_tool.update_tag_boost_version_in_db (   self,
  t,
  tagBoostVersion,
  minIov,
  update 
)

Definition at line 271 of file conddb_version_mgr.py.

Referenced by conddb_version_mgr.conddb_tool.update_tags().

271  def update_tag_boost_version_in_db( self, t, tagBoostVersion, minIov, update ):
272  cursor = self.db.cursor()
273  now = datetime.datetime.utcnow()
274  if update:
275  cursor.execute('UPDATE TAG_METADATA SET MIN_SERIALIZATION_V=:BOOST_V, MIN_SINCE=:MIN_IOV, MODIFICATION_TIME=:NOW WHERE TAG_NAME = :NAME',( tagBoostVersion,minIov,now,t))
276  else:
277  cursor.execute('INSERT INTO TAG_METADATA ( TAG_NAME, MIN_SERIALIZATION_V, MIN_SINCE, MODIFICATION_TIME ) VALUES ( :NAME, :BOOST_V, :MIN_IOV, :NOW )',(t, tagBoostVersion,minIov,now))
278  logging.info('Minimum boost version for the tag updated.')
279 
def update_tag_boost_version_in_db(self, t, tagBoostVersion, minIov, update)
def conddb_version_mgr.conddb_tool.update_tags (   self)

Definition at line 280 of file conddb_version_mgr.py.

References conddb_version_mgr.version_db.db, conddb_version_mgr.conddb_tool.db, HcalLutManager.db, conddb_version_mgr.conddb_tool.iovs, conddb_version_mgr.conddb_tool.process_tag_boost_version(), str, conddb_version_mgr.conddb_tool.update_tag_boost_version_in_db(), conddb_version_mgr.conddb_tool.validate_boost_version(), conddb_version_mgr.conddb_tool.version_db, and conddb_version_mgr.conddb_tool.versionIovs.

280  def update_tags( self ):
281  cursor = self.db.cursor()
282  self.version_db = version_db( self.db )
283  self.version_db.fetch_cmssw_boost_map()
284  self.version_db.fetch_boost_run_map()
285  tags = {}
286  wpars = ()
287  if self.args.name is not None:
288  stmt0 = 'SELECT NAME FROM TAG WHERE NAME = :TAG_NAME'
289  wpars = (self.args.name,)
290  cursor.execute(stmt0,wpars);
291  rows = cursor.fetchall()
292  found = False
293  for r in rows:
294  found = True
295  break
296  if not found:
297  raise Exception('Tag %s does not exists in the database.' %self.args.name )
298  tags[self.args.name] = None
299  stmt1 = 'SELECT MIN_SERIALIZATION_V, MIN_SINCE, CAST(MODIFICATION_TIME AS TIMESTAMP(0)) FROM TAG_METADATA WHERE TAG_NAME = :NAME'
300  cursor.execute(stmt1,wpars);
301  rows = cursor.fetchall()
302  for r in rows:
303  tags[self.args.name] = (r[0],r[1],r[2])
304  else:
305  stmt0 = 'SELECT NAME FROM TAG WHERE NAME NOT IN ( SELECT TAG_NAME FROM TAG_METADATA) ORDER BY NAME'
306  nmax = 100
307  if self.args.max is not None:
308  nmax = self.args.max
309  if self.args.all:
310  nmax = -1
311  if nmax >=0:
312  stmt0 = 'SELECT NAME FROM (SELECT NAME FROM TAG WHERE NAME NOT IN ( SELECT TAG_NAME FROM TAG_METADATA ) ORDER BY NAME) WHERE ROWNUM<= :MAXR'
313  wpars = (nmax,)
314  cursor.execute(stmt0,wpars);
315  rows = cursor.fetchall()
316  for r in rows:
317  tags[r[0]] = None
318  stmt1 = 'SELECT T.NAME NAME, TM.MIN_SERIALIZATION_V MIN_SERIALIZATION_V, TM.MIN_SINCE MIN_SINCE, CAST(TM.MODIFICATION_TIME AS TIMESTAMP(0)) MODIFICATION_TIME FROM TAG T, TAG_METADATA TM WHERE T.NAME=TM.TAG_NAME AND CAST(TM.MODIFICATION_TIME AS TIMESTAMP(0)) < (SELECT MAX(INSERTION_TIME) FROM IOV WHERE IOV.TAG_NAME=TM.TAG_NAME) ORDER BY NAME'
319  nmax = nmax-len(tags)
320  if nmax >=0:
321  stmt1 = 'SELECT NAME, MIN_SERIALIZATION_V, MIN_SINCE, MODIFICATION_TIME FROM (SELECT T.NAME NAME, TM.MIN_SERIALIZATION_V MIN_SERIALIZATION_V, TM.MIN_SINCE MIN_SINCE, CAST(TM.MODIFICATION_TIME AS TIMESTAMP(0)) MODIFICATION_TIME FROM TAG T, TAG_METADATA TM WHERE T.NAME=TM.TAG_NAME AND CAST(TM.MODIFICATION_TIME AS TIMESTAMP(0)) < (SELECT MAX(INSERTION_TIME) FROM IOV WHERE IOV.TAG_NAME=TM.TAG_NAME) ORDER BY NAME) WHERE ROWNUM<= :MAXR'
322  wpars = (nmax,)
323  cursor.execute(stmt1,wpars);
324  rows = cursor.fetchall()
325  i = 0
326  for r in rows:
327  i += 1
328  if nmax >=0 and i>nmax:
329  break
330  tags[r[0]] = (r[1],r[2],r[3])
331  logging.info( 'Processing boost version for %s tags' %len(tags))
332  count = 0
333  for t in sorted(tags.keys()):
334  count += 1
335  try:
336  update = False
337  cursor.execute('SELECT TIME_TYPE FROM TAG WHERE NAME= :TAG_NAME',(t,))
338  timetype = cursor.fetchone()[0]
339  self.iovs = None
340  logging.info('************************************************************************')
341  logging.info('Tag [%s] %s - timetype: %s' %(count,t,timetype))
342  tagBoostVersion = None
343  minIov = None
344  timeCut = None
345  if tags[t] is not None:
346  update = True
347  tagBoostVersion = tags[t][0]
348  minIov = tags[t][1]
349  timeCut = tags[t][2]
350  tagBoostVersion, minIov = self.process_tag_boost_version( t, timetype, tagBoostVersion, minIov, timeCut, self.args.validate )
351  if tagBoostVersion is None:
352  continue
353  logging.debug('boost versions in the %s iovs: %s' %(len(self.iovs),str(self.versionIovs)))
354  if self.args.validate:
355  invalid_gts = self.validate_boost_version( t, timetype, tagBoostVersion )
356  if len(invalid_gts)>0:
357  with open('invalid_tags_in_gts.txt','a') as error_file:
358  for gt in invalid_gts:
359  error_file.write('Tag %s (boost %s) is invalid for GT %s ( boost %s) \n' %(t,tagBoostVersion,gt[0],gt[1]))
360  if len(self.iovs):
361  if self.iovs[0][0]<minIov:
362  minIov = self.iovs[0]
363  self.update_tag_boost_version_in_db( t, tagBoostVersion, minIov, update )
364  self.db.commit()
365  except Exception as e:
366  logging.error(str(e))
367 
def validate_boost_version(self, t, timetype, tagBoostVersion)
#define str(s)
def process_tag_boost_version(self, t, timetype, tagBoostVersion, minIov, timeCut, validate)
def update_tag_boost_version_in_db(self, t, tagBoostVersion, minIov, update)
def conddb_version_mgr.conddb_tool.validate_boost_version (   self,
  t,
  timetype,
  tagBoostVersion 
)

Definition at line 230 of file conddb_version_mgr.py.

References conddb_version_mgr.conddb_tool.process_tag_boost_version(), and str.

Referenced by conddb_version_mgr.conddb_tool.update_tags().

230  def validate_boost_version( self, t, timetype, tagBoostVersion ):
231  cursor = self.db.cursor()
232  cursor.execute('SELECT GT.NAME, GT.RELEASE, GT.SNAPSHOT_TIME FROM GLOBAL_TAG GT, GLOBAL_TAG_MAP GTM WHERE GT.NAME = GTM.GLOBAL_TAG_NAME AND GTM.TAG_NAME = :TAG_NAME',(t,))
233  rows = cursor.fetchall()
234  invalid_gts = []
235  ngt = 0
236  gts = []
237  for r in rows:
238  gts.append((r[0],r[1],r[2]))
239  if len(gts)>0:
240  logging.info('validating %s gts.' %len(gts))
241  boost_snapshot_map = {}
242  for gt in gts:
243  ngt += 1
244  logging.debug('Validating for GT %s (release %s)' %(gt[0],gt[1]))
245  gtCMSSWVersion = sm.check_cmssw_version( gt[1] )
246  gtBoostVersion = self.version_db.lookup_boost_in_cmssw( gtCMSSWVersion )
247  if sm.cmp_boost_version( gtBoostVersion, tagBoostVersion )<0:
248  logging.warning( 'The boost version computed from all the iovs in the tag (%s) is incompatible with the gt [%s] %s (consuming ver: %s, snapshot: %s)' %(tagBoostVersion,ngt,gt[0],gtBoostVersion,str(gt[2])))
249  if str(gt[2]) not in boost_snapshot_map.keys():
250  tagSnapshotBoostVersion = None
251  minIov = None
252  tagSnapshotBoostVersion, minIov = self.process_tag_boost_version(t, timetype, tagSnapshotBoostVersion, minIov, gt[2])
253  if tagSnapshotBoostVersion is not None:
254  boost_snapshot_map[str(gt[2])] = tagSnapshotBoostVersion
255  else:
256  continue
257  else:
258  tagSnapshotBoostVersion = boost_snapshot_map[str(gt[2])]
259  if sm.cmp_boost_version( gtBoostVersion, tagSnapshotBoostVersion )<0:
260  logging.error('The snapshot from tag used by gt %s (consuming ver: %s) has an incompatible combined boost version %s' %(gt[0],gtBoostVersion,tagSnapshotBoostVersion))
261  invalid_gts.append( ( gt[0], gtBoostVersion ) )
262  if len(invalid_gts)==0:
263  if ngt>0:
264  logging.info('boost version for the tag validated in %s referencing Gts' %(ngt))
265  else:
266  logging.info('No GT referencing this tag found.')
267  else:
268  logging.error( 'boost version for the tag is invalid.')
269  return invalid_gts
270 
def validate_boost_version(self, t, timetype, tagBoostVersion)
#define str(s)
def process_tag_boost_version(self, t, timetype, tagBoostVersion, minIov, timeCut, validate)

Member Data Documentation

conddb_version_mgr.conddb_tool.args

Definition at line 143 of file conddb_version_mgr.py.

conddb_version_mgr.conddb_tool.db
conddb_version_mgr.conddb_tool.iovs
conddb_version_mgr.conddb_tool.logger

Definition at line 144 of file conddb_version_mgr.py.

conddb_version_mgr.conddb_tool.version_db
conddb_version_mgr.conddb_tool.versionIovs