260 credentials: dict[str,Any] = ConfigDBLoader.getConnectionParameters(self.dbalias)
263 log.error(
"No TriggerDB connections found for %s", self.dbalias)
264 raise RuntimeError(f
"No TriggerDB connections found for {self.dbalias}")
266 svc = coral.ConnectionService()
267 svcconfig = svc.configuration()
268 svcconfig.disablePoolAutomaticCleanUp()
269 svcconfig.setConnectionTimeOut(0)
272 for credential
in credentials:
273 log.debug(
"Trying credentials %s",credential)
276 session = svc.connect(credential, coral.access_ReadOnly)
277 except Exception
as e:
278 log.warning(
"Failed to establish connection: %s",e)
279 failureMode =
max(1, failureMode)
283 if 'FRONTIER_SERVER' in os.environ
and os.environ[
'FRONTIER_SERVER']:
284 svcconfig.setConnectionRetrialPeriod(300)
285 svcconfig.setConnectionRetrialTimeOut(3600)
287 svcconfig.setConnectionRetrialPeriod(1)
288 svcconfig.setConnectionRetrialTimeOut(1)
291 session.transaction().
start(
True)
292 self.schema = ConfigDBLoader.getSchema(credential)
293 qdict = {
"schema" : self.schema,
"dbkey" : self.dbkey }
296 schemaVersion = ConfigDBLoader.readSchemaVersion(qdict, session)
297 qstr = self.getQueryDefinition(schemaVersion)
299 query = ConfigDBLoader.getCoralQuery(session, qstr, qdict)
300 cursor = query.execute()
302 except Exception
as e:
303 log.warning(f
"DB query on {credential} failed to execute.")
304 log.warning(
"Exception message: %r", e)
305 failureMode =
max(2, failureMode)
309 if not cursor.next():
311 log.warning(f
"DB query on {credential} returned empty result, likely due to non-existing key {self.dbkey}")
315 configblob = cursor.currentRow()[0].
data()
316 if type(configblob)
is not str:
317 configblob = configblob.readline()
318 config = json.loads(configblob, object_pairs_hook = odict)
319 session.transaction().
commit()
321 self.confirmConfigType(config)
325 log.error(
"TriggerDB query: could not connect to any source for %s", self.configType.basename)
326 log.error(
"Considered sources: %s",
", ".
join(credentials))
327 raise RuntimeError(
"TriggerDB query: could not connect to any source", self.configType.basename)
329 log.error(
"Query failed due to wrong definition for %s", self.configType.basename)
330 log.error(
"DB query was: %s", qstr.format(**qdict))
331 raise RuntimeError(
"Query failed due to wrong definition", self.configType.basename)
332 elif failureMode == 3:
333 log.error(
"DB key %s does not exist for %s", self.dbkey, self.configType.basename)
334 raise KeyError(
"DB key does not exist", self.dbkey, self.configType.basename)
336 raise RuntimeError(
"Query failed for unknown reason")