Skip to content
Snippets Groups Projects
Commit 889eeffb authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'master-ATR-22483' into 'master'

Fix frontier access for TriggerDB

Closes ATR-22483

See merge request atlas/athena!38964
parents a603b90a eeafc871
No related branches found
No related tags found
No related merge requests found
...@@ -42,9 +42,30 @@ def testUrl(url): ...@@ -42,9 +42,30 @@ def testUrl(url):
return False return False
return True return True
def resolveUrl(url):
"""
Expects input string to be a URL or $FRONTIER_SERVER
Returns an accessible URL or None"""
import re
if re.match("http://",url): # simple URL specification http://...
return url if testUrl(url) else None
if re.match(r'\(serverurl=(.*?)\)',url): # syntax of FRONTIER_SERVER
for url in getServerUrls(url):
if testUrl(url):
return url
return None
def getFrontierCursor(url, schema, loglevel = logging.INFO): def getFrontierCursor(url, schema, loglevel = logging.INFO):
log = logging.getLogger( "TrigConfFrontier.py" ) log = logging.getLogger( "TrigConfFrontier.py" )
log.setLevel(loglevel) log.setLevel(loglevel)
url = resolveUrl(url)
if url is None:
log.warning("Cannot find a valid frontier connection, will not return a Frontier cursor")
return None
else:
log.info(f"Will use Frontier server at {url}")
if useFrontierClient: if useFrontierClient:
log.info("Using frontier_client from TrigConfDBConnection") log.info("Using frontier_client from TrigConfDBConnection")
return FrontierCursor2( url = url, schema = schema) return FrontierCursor2( url = url, schema = schema)
...@@ -201,8 +222,6 @@ class FrontierCursor(object): ...@@ -201,8 +222,6 @@ class FrontierCursor(object):
queryStart = time.localtime() queryStart = time.localtime()
log.debug("Query started: %s", time.strftime("%m/%d/%y %H:%M:%S %Z", queryStart)) log.debug("Query started: %s", time.strftime("%m/%d/%y %H:%M:%S %Z", queryStart))
print(request)
t1 = time.time() t1 = time.time()
result = urllib.request.urlopen(request,None,10).read().decode() result = urllib.request.urlopen(request,None,10).read().decode()
t2 = time.time() t2 = time.time()
...@@ -308,21 +327,15 @@ def testQuery(query, bindvars): ...@@ -308,21 +327,15 @@ def testQuery(query, bindvars):
from TrigConfigSvc.TrigConfigSvcUtils import interpretConnection from TrigConfigSvc.TrigConfigSvcUtils import interpretConnection
connectionParameters = interpretConnection("TRIGGERDBMC") connectionParameters = interpretConnection("TRIGGERDBMC")
for url in getServerUrls( connectionParameters['url'] ): cursor = getFrontierCursor( url = connectionParameters['url'], schema = connectionParameters['schema'])
if not testUrl(url): cursor.execute(query, bindvars)
log.info("Skipping %s (failing connection test)", url) log.info("Raw response:")
continue print(cursor.result)
log.info("Testing %s", url) cursor.decodeResult()
cursor = getFrontierCursor( url = url, schema = connectionParameters['schema']) log.info("Decoded response:")
cursor.execute(query, bindvars) log.info(cursor.result[0][0])
log.info("Raw response:") if cursor.result[0][0] != 'MC_pp_v7':
print(cursor.result) return 1
cursor.decodeResult()
log.info("Decoded response:")
log.info(cursor.result[0][0])
if cursor.result[0][0] != 'MC_pp_v7':
return 1
break
return 0 return 0
......
...@@ -249,9 +249,10 @@ def getTriggerDBCursor(connection): ...@@ -249,9 +249,10 @@ def getTriggerDBCursor(connection):
schema = connectionParameters["schema"].rstrip('.') + '.' schema = connectionParameters["schema"].rstrip('.') + '.'
elif technology == 'frontier': elif technology == 'frontier':
from TrigConfigSvc.TrigConfFrontier import getFrontierCursor from TrigConfigSvc.TrigConfFrontier import getFrontierCursor
cursor = getFrontierCursor(connectionParameters["url"], connectionParameters["schema"], logging.getLogger("TrigConfigSvcUtils.py").level) schema = connectionParameters["schema"].rstrip('.')
schema = connectionParameters["schema"].rstrip('.') + '.' cursor = getFrontierCursor( url = connectionParameters['url'], schema = schema, loglevel = logging.getLogger("TrigConfigSvcUtils.py").level)
schema = schema + '.'
elif technology == 'mysql': elif technology == 'mysql':
cursor = _get_mysql_cursor(connectionParameters["server"], connectionParameters["dbname"], connectionParameters["user"], connectionParameters["passwd"]),'' cursor = _get_mysql_cursor(connectionParameters["server"], connectionParameters["dbname"], connectionParameters["user"], connectionParameters["passwd"]),''
...@@ -986,7 +987,8 @@ def test(): ...@@ -986,7 +987,8 @@ def test():
####################################""") ####################################""")
def test1():
getMenuNameFromDB("TRIGGERDBMC",321)
def test2(): def test2():
log.setLevel(logging.WARNING) log.setLevel(logging.WARNING)
...@@ -1016,4 +1018,4 @@ def test2(): ...@@ -1016,4 +1018,4 @@ def test2():
if __name__=="__main__": if __name__=="__main__":
import sys import sys
sys.exit(test2()) sys.exit(test1())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment