229def interpretConnection(connection, debug=False, resolveAlias=True):
230
231
232
233
234
235
236 log.info("Specified connection string '%s'", connection)
237
238
239
240
241
242
243
244
245 connectionParameters = {}
246 connection = str(connection)
247
248
249 if ':' in connection:
250 connectionParameters = _getConnectionParameters( connection )
251 return connectionParameters
252
253
254 connectionParameters["alias"] = connection
255 if not resolveAlias:
256 return connectionParameters
257
258 connectionServices = _getConnectionServicesForAlias( connection )
259 if connectionServices is None:
260 return connectionParameters
261
262
263 if os.getenv('TRIGGER_USE_FRONTIER',False):
264 connectionServices = filter(lambda conn: not conn.startswith("sqlite_file"), connectionServices)
265 if 'ATLAS_TRIGGERDB_FORCESQLITE' in os.environ:
266 log.fatal("Inconsistent setup: environment variable ATLAS_TRIGGERDB_FORCESQLITE is defined and use of Frontier is requested" )
267
268
269 sqliteconnections = [conn for conn in connectionServices if conn.startswith("sqlite_file")]
270 if len(sqliteconnections)>0:
271 for conn in sqliteconnections:
272 connectionParameters = _getConnectionParameters( conn )
273 if connectionParameters["filename"] is not None:
274 break
275 if connectionParameters["filename"] is not None:
276 log.info("Using sqlite connection %s", connectionParameters)
277 return connectionParameters
278 else:
279 if 'ATLAS_TRIGGERDB_FORCESQLITE' in os.environ:
280 log.fatal("environment ATLAS_TRIGGERDB_FORCESQLITE is defined but non of the sqlite files defined in dblookup.xml exists" )
281 else:
282 if 'ATLAS_TRIGGERDB_FORCESQLITE' in os.environ:
283 log.fatal("environment ATLAS_TRIGGERDB_FORCESQLITE is defined but no sqlite connection defined in dblookup.xml" )
284
285 from CoolConvUtilities.AtlCoolLib import replicaList
286 serverlist=['ATLAS_CONFIG' if s=='ATLAS_COOLPROD' else s for s in replicaList()]
287 log.info("Trying these servers in order %r", serverlist)
288 for server in serverlist:
289 log.info("Trying server %s", server)
290
291 if server=='ATLF':
292 if not os.getenv('TRIGGER_USE_FRONTIER',False):
293 continue
294 frontierconnections = [conn for conn in connectionServices if conn.startswith("frontier")]
295 if len(frontierconnections) == 0:
296 log.debug("FroNTier connection not defined for alias %s in dblookup", connection )
297 continue
298 log.info("Environment FRONTIER_SERVER: %s", os.getenv('FRONTIER_SERVER','not defined'))
299 frontierServer = os.getenv('FRONTIER_SERVER',None)
300 if not frontierServer:
301 log.debug("No environment variable FRONTIER_SERVER" )
302 continue
303 connectionParameters = _getConnectionParameters( frontierconnections[0] )
304 connectionParameters['url'] = frontierServer
305 log.info("Using frontier connection %s", frontierconnections[0])
306
307 break
308 elif server=='atlas_dd':
309 continue
310 else:
311 oracleconnections = [conn for conn in connectionServices if conn.startswith("oracle://%s/" % server)]
312 if len(oracleconnections) == 0:
313 log.debug("Oracle connection not defined for server %s in dblookup", server )
314 continue
315 connectionParameters = _getConnectionParameters( oracleconnections[0] )
316 log.info("Using oracle connection %s", oracleconnections[0])
317 break
318
319 return connectionParameters
320
321