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