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 urllib.parse
import urlparse
18 dom =
parse(file_name)
20 connections = dom.getElementsByTagName(
"connection")
21 desired_conn =
lambda c: c.attributes.get(
"name").value == connection
23 connections =
list(
filter(desired_conn, connections))
25 if len(connections) < 1:
29 for node
in connections[0].childNodes:
30 if node.nodeName ==
"parameter":
31 info[node.getAttribute(
"name")] =
str(node.getAttribute(
"value"))
33 authentication = info[
"user"], info[
"password"]
38 Retrieves authentication information from CORAL_AUTH_PATH authentication.xml
41 from os
import environ
42 from os.path
import join
as pjoin
43 assert "CORAL_AUTH_PATH" in environ,
"CORAL_AUTH_PATH environment var not set"
45 auth_paths = environ[
"CORAL_AUTH_PATH"].
split(
":")
47 for auth_path
in auth_paths + [
"."]:
48 file_name = pjoin(auth_path,
"authentication.xml")
54 raise RuntimeError(
"Unable to locate credentials for %s."
58 "oracle://ATLAS_COOLPROD/ATLAS_COOLONL_GLOBAL"
59 assert connection_string.startswith(
"oracle://"),
"Not a connection string"
60 host = urlparse (connection_string[len(
"oracle:"):]).netloc
62 conn_str =
"oracle://%s:%s@%s" % (username, password, host)
63 engine = create_engine(conn_str, pool_recycle=10*60)
65 metadata.reflect(engine)
66 return engine, metadata
75 "/ATLAS_COOLONL_GLOBAL")
76 Session = sessionmaker(engine)
78 run_table = Table(
"ATLAS_RUN_NUMBER.RUNNUMBER", metadata,
79 Column(
"NAME", String),
80 Column(
"RUNNUMBER", String),
81 Column(
"STARTAT", String),
82 Column(
"DURATION", Integer),
83 Column(
"CREATEDBY", String),
84 Column(
"HOST", String),
85 Column(
"PARTITIONNAME", String),
86 Column(
"CONFIGSCHEMA", Integer),
87 Column(
"CONFIGDATA", String),
88 Column(
"COMMENTS", String),
96 Retrieve a list of ATLAS runs from the database, since first_run
98 from time
import time, strftime, gmtime
101 ordering = t.c.RUNNUMBER.asc()
if ascending
else t.c.RUNNUMBER.desc()
103 this_recent = strftime(
"%Y%m%dT%H%M%S", gmtime(
time()-how_recent))
104 condition = and_(t.c.STARTAT >= this_recent, t.c.PARTITIONNAME ==
"ATLAS")
105 rows =
select(run_table).
where(condition).order_by(ordering)
107 return session.execute(rows).fetchall()
111 Retrieve a list of ATLAS runs from the database, since first_run
115 ordering = t.c.RUNNUMBER.asc()
if ascending
else t.c.RUNNUMBER.desc()
117 condition = and_(t.c.RUNNUMBER > first_run, t.c.PARTITIONNAME ==
"ATLAS")
118 rows =
select(run_table).
where(condition).order_by(ordering)
120 return session.execute(rows).fetchall()
123 return (
select(run_table.c.RUNNUMBER)
124 .
where(run_table.c.PARTITIONNAME ==
"ATLAS")
125 .order_by(run_table.c.RUNNUMBER))
128 rows = (
select(run_table.c.RUNNUMBER)
129 .
where(run_table.c.PARTITIONNAME ==
"ATLAS")
130 .order_by(run_table.c.RUNNUMBER.desc()).
limit(n))
133 return [row.RUNNUMBER
for row
in reversed(session.execute(rows).fetchall())]
138 return session.execute(rows).fetchall()
146 rows = rows.where(run_table.c.RUNNUMBER.between(first, last))
149 return [row.RUNNUMBER
for row
in session.execute(rows).fetchall()]
153 iov_runs =
set(iov.since.run
for iov
in iovs)
154 first, last =
min(iov_runs),
max(iov_runs)
157 rows = rows.where(run_table.c.RUNNUMBER.between(first, last))
160 atlas_runs =
set(row.RUNNUMBER
for row
in session.execute(rows).fetchall())
161 keep_runs = atlas_runs.intersection(iov_runs)
163 return IOVSet(iov
for iov
in iovs
if iov.since.run
in keep_runs)