129def indirectOpen(coolstr,readOnly=True,debug=False):
130 """Obtain a connection to the database coolstr (e.g.
131 COOLONL_INDET/OFLP200) using Oracle servers only, bypassing SQLite files
132 and simulating the action of DBReplicaSvc to choose the correct one.
133 Returns None in case a connection cannot be established.
134 debug=True produces debug printout to show servers being tried"""
135 dbSvc=cool.DatabaseSvcFactory.databaseService()
137
138
139 splitname=connstr.split('/')
140 forceSQLite='ATLAS_COOL_FORCESQLITE' in os.environ
141 if (debug and forceSQLite):
142 print ("ATLAS_COOL_FORCESQLITE: Force consideration of SQLite replicas")
143 if (len(splitname)!=2 or readOnly is False or forceSQLite):
144 try:
145 db=dbSvc.openDatabase(connstr,readOnly)
146 except Exception as e:
147
148
149 if (not readOnly and ('attempt to write a readonly database' in e.__repr__())):
150 print ("Writeable open failed - retry in readonly mode")
151 db=dbSvc.openDatabase(connstr,True)
152 else:
153 raise
154 return db
155 if (debug): print ("Trying to establish connection for %s from Oracle" % connstr)
156 schema=splitname[0]
157 dbinst=splitname[1]
158
159 serverlist=replicaList()
160 if (debug): print (serverlist)
161
162 serverlist.reverse()
163 while len(serverlist)>0:
164 server=serverlist.pop()
165
166 if server=='ATLF':
167 if ('FRONTIER_SERVER' in os.environ):
168 connstr='frontier://ATLF/();schema=ATLAS_%s;dbname=%s' % (schema,dbinst)
169 else:
170
171 continue
172 elif server=='atlas_dd': continue
173 else:
174 connstr='oracle://%s;schema=ATLAS_%s;dbname=%s' % (server,schema,dbinst)
175 if (debug): print ("Attempting to open %s" % connstr)
176 try:
177 dbconn=dbSvc.openDatabase(connstr)
178 if (dbconn is not None and dbconn.isOpen()):
179 if (debug): print ("Established connection to %s" % server)
180 return dbconn
181 if (debug): print ("Cannot connect to %s" % server)
182 except Exception:
183 if (debug): print ("Exception connecting to %s" % server)
184
185 print ("All available replicas tried - giving up")
186 return None
187