273 def load(self) -> dict[str, Any]:
274 credentials: dict[str,Any] = ConfigDBLoader.getConnectionParameters(self.dbalias)
277 log.error(
"No TriggerDB connections found for %s", self.dbalias)
278 raise RuntimeError(f
"No TriggerDB connections found for {self.dbalias}")
280 svc = coral.ConnectionService()
281 svcconfig = svc.configuration()
282 svcconfig.disablePoolAutomaticCleanUp()
283 svcconfig.setConnectionTimeOut(0)
286 for credential
in credentials:
287 log.debug(
"Trying credentials %s",credential)
290 session = svc.connect(credential, coral.access_ReadOnly)
291 except Exception
as e:
292 log.warning(
"Failed to establish connection: %s",e)
293 failureMode =
max(1, failureMode)
297 if 'FRONTIER_SERVER' in os.environ
and os.environ[
'FRONTIER_SERVER']:
298 svcconfig.setConnectionRetrialPeriod(300)
299 svcconfig.setConnectionRetrialTimeOut(3600)
301 svcconfig.setConnectionRetrialPeriod(1)
302 svcconfig.setConnectionRetrialTimeOut(1)
305 session.transaction().
start(
True)
306 self.schema = ConfigDBLoader.getSchema(credential)
307 qdict = {
"schema" : self.schema,
"dbkey" : self.dbkey }
310 schemaVersion = ConfigDBLoader.readSchemaVersion(qdict, session)
311 qstr = self.getQueryDefinition(schemaVersion)
313 query = ConfigDBLoader.getCoralQuery(session, qstr, qdict)
314 cursor = query.execute()
316 except Exception
as e:
317 log.warning(f
"DB query on {credential} failed to execute.")
318 log.warning(
"Exception message: %r", e)
319 failureMode =
max(2, failureMode)
323 if not cursor.next():
325 log.warning(f
"DB query on {credential} returned empty result, likely due to non-existing key {self.dbkey}")
329 configblob = cursor.currentRow()[0].
data()
330 if type(configblob)
is not str:
331 configblob = configblob.readline()
332 config = json.loads(configblob)
333 session.transaction().
commit()
335 self.confirmConfigType(config)
339 log.error(
"TriggerDB query: could not connect to any source for %s", self.configType.basename)
340 log.error(
"Considered sources: %s",
", ".
join(credentials))
341 raise RuntimeError(
"TriggerDB query: could not connect to any source", self.configType.basename)
343 log.error(
"Query failed due to wrong definition for %s", self.configType.basename)
344 log.error(
"DB query was: %s", qstr.format(**qdict))
345 raise RuntimeError(
"Query failed due to wrong definition", self.configType.basename)
346 elif failureMode == 3:
347 log.error(
"DB key %s does not exist for %s", self.dbkey, self.configType.basename)
348 raise KeyError(
"DB key does not exist", self.dbkey, self.configType.basename)
350 raise RuntimeError(
"Query failed for unknown reason")