5 from sqlalchemy
import (select, create_engine, MetaData, Table, Column, String,
7 from sqlalchemy.orm
import sessionmaker
8 from sqlalchemy.sql
import and_
10 from DQUtils.sugar
import IOVSet
11 from xml.dom.minidom
import parse
12 from os.path
import exists
14 from future.standard_library
import install_aliases
16 from urllib.parse
import urlparse
20 dom =
parse(file_name)
22 connections = dom.getElementsByTagName(
"connection")
23 desired_conn =
lambda c: c.attributes.get(
"name").value == connection
25 connections =
list(
filter(desired_conn, connections))
27 if len(connections) < 1:
31 for node
in connections[0].childNodes:
32 if node.nodeName ==
"parameter":
33 info[node.getAttribute(
"name")] =
str(node.getAttribute(
"value"))
35 authentication = info[
"user"], info[
"password"]
40 Retrieves authentication information from CORAL_AUTH_PATH authentication.xml
43 from os
import environ
44 from os.path
import join
as pjoin
45 assert "CORAL_AUTH_PATH" in environ,
"CORAL_AUTH_PATH environment var not set"
47 auth_paths = environ[
"CORAL_AUTH_PATH"].
split(
":")
49 for auth_path
in auth_paths + [
"."]:
50 file_name = pjoin(auth_path,
"authentication.xml")
56 raise RuntimeError(
"Unable to locate credentials for %s."
60 "oracle://ATLAS_COOLPROD/ATLAS_COOLONL_GLOBAL"
61 assert connection_string.startswith(
"oracle://"),
"Not a connection string"
62 host = urlparse (connection_string[len(
"oracle:"):]).netloc
64 conn_str =
"oracle://%s:%s@%s" % (username, password, host)
65 engine = create_engine(conn_str, pool_recycle=10*60)
67 metadata.reflect(engine)
68 return engine, metadata
77 "/ATLAS_COOLONL_GLOBAL")
78 Session = sessionmaker(engine)
80 run_table = Table(
"ATLAS_RUN_NUMBER.RUNNUMBER", metadata,
81 Column(
"NAME", String),
82 Column(
"RUNNUMBER", String),
83 Column(
"STARTAT", String),
84 Column(
"DURATION", Integer),
85 Column(
"CREATEDBY", String),
86 Column(
"HOST", String),
87 Column(
"PARTITIONNAME", String),
88 Column(
"CONFIGSCHEMA", Integer),
89 Column(
"CONFIGDATA", String),
90 Column(
"COMMENTS", String),
98 Retrieve a list of ATLAS runs from the database, since first_run
100 from time
import time, strftime, gmtime
103 ordering = t.c.RUNNUMBER.asc()
if ascending
else t.c.RUNNUMBER.desc()
105 this_recent = strftime(
"%Y%m%dT%H%M%S", gmtime(time()-how_recent))
106 condition = and_(t.c.STARTAT >= this_recent, t.c.PARTITIONNAME ==
"ATLAS")
107 rows =
select(run_table).
where(condition).order_by(ordering)
109 return session.execute(rows).fetchall()
113 Retrieve a list of ATLAS runs from the database, since first_run
117 ordering = t.c.RUNNUMBER.asc()
if ascending
else t.c.RUNNUMBER.desc()
119 condition = and_(t.c.RUNNUMBER > first_run, t.c.PARTITIONNAME ==
"ATLAS")
120 rows =
select(run_table).
where(condition).order_by(ordering)
122 return session.execute(rows).fetchall()
125 return (
select(run_table.c.RUNNUMBER)
126 .
where(run_table.c.PARTITIONNAME ==
"ATLAS")
127 .order_by(run_table.c.RUNNUMBER))
130 rows = (
select(run_table.c.RUNNUMBER)
131 .
where(run_table.c.PARTITIONNAME ==
"ATLAS")
132 .order_by(run_table.c.RUNNUMBER.desc()).
limit(n))
135 return [row.RUNNUMBER
for row
in reversed(session.execute(rows).fetchall())]
140 return session.execute(rows).fetchall()
148 rows = rows.where(run_table.c.RUNNUMBER.between(first, last))
151 return [row.RUNNUMBER
for row
in session.execute(rows).fetchall()]
155 iov_runs =
set(iov.since.run
for iov
in iovs)
156 first, last =
min(iov_runs),
max(iov_runs)
159 rows = rows.where(run_table.c.RUNNUMBER.between(first, last))
162 atlas_runs =
set(row.RUNNUMBER
for row
in session.execute(rows).fetchall())
163 keep_runs = atlas_runs.intersection(iov_runs)
165 return IOVSet(iov
for iov
in iovs
if iov.since.run
in keep_runs)