|
def | __init__ (self, base_url=None, max_connections=10, retries=3) |
|
def | set_authentication (self, user, password, basic=True) |
|
def | request (self, method, url, message=None, *args, **argk) |
|
def | get_globalTags (self) |
|
def | has_globalTag (self, name) |
|
def | get_globalTagInfo (self, name) |
|
def | get_globalTagType (self, name) |
|
def | create_globalTag (self, name, description, user) |
|
def | get_all_iovs (self, globalTag, exp=None, run=None, message=None) |
|
def | get_payloads (self, global_tag=None) |
|
def | check_payloads (self, payloads, information="payloadId") |
|
def | get_revisions (self, entries) |
|
def | create_payload (self, module, filename, checksum=None) |
|
def | create_iov (self, globalTagId, payloadId, firstExp, firstRun, finalExp, finalRun) |
|
def | get_iovs (self, globalTagName, payloadName=None) |
|
def | upload (self, filename, global_tag, normalize=False, ignore_existing=False, nprocess=1, uploaded_entries=None) |
|
def | staging_request (self, filename, normalize, data, password) |
|
|
list | BASE_URLS = ["http://belle2db.sdcc.bnl.gov/b2s/rest/"] |
| base url to the conditions db to be used if no custom url is given
|
|
|
| _session |
| session object to get keep-alive support and connection pooling
|
|
| _base_url |
| base url to be prepended to all requests
|
|
Class to interface conditions db REST interface
Definition at line 144 of file __init__.py.
◆ __init__()
def __init__ |
( |
|
self, |
|
|
|
base_url = None , |
|
|
|
max_connections = 10 , |
|
|
|
retries = 3 |
|
) |
| |
Create a new instance of the interface
Args:
base_url (string): base url of the rest interface
max_connections (int): number of connections to keep open, mostly useful for threaded applications
retries (int): number of retries in case of connection problems
Definition at line 186 of file __init__.py.
186 def __init__(self, base_url=None, max_connections=10, retries=3):
188 Create a new instance of the interface
191 base_url (string): base url of the rest interface
192 max_connections (int): number of connections to keep open, mostly useful for threaded applications
193 retries (int): number of retries in case of connection problems
197 self._session = requests.Session()
199 adapter = requests.adapters.HTTPAdapter(
200 pool_connections=max_connections, pool_maxsize=max_connections,
201 max_retries=retries, pool_block=
True
203 self._session.mount(
"http://", adapter)
204 self._session.mount(
"https://", adapter)
206 if "BELLE2_CONDB_PROXY" in os.environ:
207 self._session.proxies = {
208 "http": os.environ.get(
"BELLE2_CONDB_PROXY"),
209 "https": os.environ.get(
"BELLE2_CONDB_PROXY"),
212 base_url_list = ConditionsDB.get_base_urls(base_url)
214 for url
in base_url_list:
216 self._base_url = url.rstrip(
"/") +
"/"
218 req = self._session.request(
"HEAD", self._base_url +
"v2/globalTags")
219 req.raise_for_status()
220 except requests.RequestException
as e:
221 B2WARNING(f
"Problem connecting to {url}:\n {e}\n Trying next server ...")
225 B2FATAL(
"No working database servers configured, giving up")
231 self._session.headers.update({
"Accept":
"application/json",
"Cache-Control":
"no-cache"})
◆ check_payloads()
def check_payloads |
( |
|
self, |
|
|
|
payloads, |
|
|
|
information = "payloadId" |
|
) |
| |
Check for the existence of payloads in the database.
Arguments:
payloads (list((str,str))): A list of payloads to check for. Each
payload needs to be a tuple of the name of the payload and the
md5 checksum of the payload file.
information (str): The information to be extracted from the
payload dictionary
Returns:
A dictionary with the payload identifiers (name, checksum) as keys
and the requested information as values for all payloads which are already
present in the database.
Definition at line 436 of file __init__.py.
◆ create_globalTag()
def create_globalTag |
( |
|
self, |
|
|
|
name, |
|
|
|
description, |
|
|
|
user |
|
) |
| |
◆ create_iov()
def create_iov |
( |
|
self, |
|
|
|
globalTagId, |
|
|
|
payloadId, |
|
|
|
firstExp, |
|
|
|
firstRun, |
|
|
|
finalExp, |
|
|
|
finalRun |
|
) |
| |
Create an iov.
Args:
globalTagId (int): id of the globaltag, obtain with get_globalTagId()
payloadId (int): id of the payload, obtain from create_payload() or get_payloads()
firstExp (int): first experiment for which this iov is valid
firstRun (int): first run for which this iov is valid
finalExp (int): final experiment for which this iov is valid
finalRun (int): final run for which this iov is valid
Returns:
payloadIovId of the created iov, None if creation was not successful
Definition at line 532 of file __init__.py.
◆ create_payload()
def create_payload |
( |
|
self, |
|
|
|
module, |
|
|
|
filename, |
|
|
|
checksum = None |
|
) |
| |
Create a new payload
Args:
module (str): name of the module
filename (str): name of the file
checksum (str): md5 hexdigest of the file. Will be calculated automatically if not given
Definition at line 489 of file __init__.py.
◆ get_all_iovs()
def get_all_iovs |
( |
|
self, |
|
|
|
globalTag, |
|
|
|
exp = None , |
|
|
|
run = None , |
|
|
|
message = None |
|
) |
| |
Return list of all payloads in the given globaltag where each element is
a `PayloadInformation` instance
Parameters:
gobalTag (str): name of the globaltag
exp (int): if given limit the list of payloads to the ones valid for
the given exp,run combination
run (int): if given limit the list of payloads to the ones valid for
the given exp,run combination
message (str): additional message to show when downloading the
payload information. Will be directly appended to
"Obtaining lists of iovs for globaltag {globalTag}"
Warning:
Both, exp and run, need to be given at the same time. Just supplying
an experiment or a run number will not work
Definition at line 370 of file __init__.py.
◆ get_base_urls()
def get_base_urls |
( |
|
given_url | ) |
|
|
static |
Resolve the list of server urls. If a url is given just return it.
Otherwise return servers listed in BELLE2_CONDB_SERVERLIST or the
builtin defaults
Arguments:
given_url (str): Explicit base_url. If this is not None it will be
returned as is in a list of length 1
Returns:
a list of urls to try for database connectivity
Definition at line 155 of file __init__.py.
◆ get_globalTagInfo()
def get_globalTagInfo |
( |
|
self, |
|
|
|
name |
|
) |
| |
Get the id of the globaltag with the given name. Returns either the
id or None if the tag was not found
Definition at line 326 of file __init__.py.
◆ get_globalTags()
def get_globalTags |
( |
|
self | ) |
|
Get a list of all globaltags. Returns a dictionary with the globaltag
names and the corresponding ids in the database
Definition at line 300 of file __init__.py.
◆ get_globalTagType()
def get_globalTagType |
( |
|
self, |
|
|
|
name |
|
) |
| |
Get the dictionary describing the given globaltag type (currently
one of DEV or RELEASE). Returns None if tag type was not found.
Definition at line 338 of file __init__.py.
◆ get_iovs()
def get_iovs |
( |
|
self, |
|
|
|
globalTagName, |
|
|
|
payloadName = None |
|
) |
| |
Return existing iovs for a given tag name. It returns a dictionary
which maps (payloadId, first runId, final runId) to iovId
Parameters:
globalTagName(str): Global tag name.
payloadName(str): Payload name (if None, selection by name is
not performed.
Definition at line 567 of file __init__.py.
◆ get_payloads()
def get_payloads |
( |
|
self, |
|
|
|
global_tag = None |
|
) |
| |
Get a list of all defined payloads (for the given global_tag or by default for all).
Returns a dictionary which maps (module, checksum) to the payload id.
Definition at line 412 of file __init__.py.
◆ get_revisions()
def get_revisions |
( |
|
self, |
|
|
|
entries |
|
) |
| |
Get the revision numbers of payloads in the database.
Arguments:
entries (list): A list of payload entries.
Each entry must have the attributes module and checksum.
Returns:
True if successful.
Definition at line 468 of file __init__.py.
◆ has_globalTag()
def has_globalTag |
( |
|
self, |
|
|
|
name |
|
) |
| |
Check whether the globaltag with the given name exists.
Definition at line 316 of file __init__.py.
◆ request()
def request |
( |
|
self, |
|
|
|
method, |
|
|
|
url, |
|
|
|
message = None , |
|
|
* |
args, |
|
|
** |
argk |
|
) |
| |
Request function, similar to requests.request but adding the base_url
Args:
method (str): GET, POST, etc.
url (str): url for the request, base_url will be prepended
message (str): message to show when starting the request and if it fails
All other arguments will be forwarded to requests.request.
Definition at line 245 of file __init__.py.
◆ set_authentication()
def set_authentication |
( |
|
self, |
|
|
|
user, |
|
|
|
password, |
|
|
|
basic = True |
|
) |
| |
Set authentication credentials when talking to the database
Args:
user (str): username
password (str): password
basic (bool): if True us HTTP Basic authentication, otherwise HTTP Digest
Definition at line 233 of file __init__.py.
◆ staging_request()
def staging_request |
( |
|
self, |
|
|
|
filename, |
|
|
|
normalize, |
|
|
|
data, |
|
|
|
password |
|
) |
| |
Upload a testing payload storage to a staging globaltag and create or update a jira issue
Parameters:
filename (str): filename of the testing payload storage file that should be uploaded
normalize (bool/str): if True the payload root files will be
normalized to have the same checksum for the same content, if
normalize is a string in addition the file name in the root file
metadata will be set to it
data (dict): a dictionary with the information provided by the user:
* task: category of globaltag, either master, online, prompt, data, mc, or analysis
* tag: the globaltage name
* request: type of request, either Update, New, or Modification. The latter two imply task == master because
if new payload classes are introduced or payload classes are modified then they will first be included in
the master globaltag. Here a synchronization of code and payload changes has to be managed.
If new or modified payload classes should be included in other globaltags they must already be in a release.
* pull-request: number of the pull request containing new or modified payload classes,
only for request == New or Modified
* backward-compatibility: description of what happens if the old payload is encountered by the updated code,
only for request == Modified
* forward-compatibility: description of what happens if a new payload is encountered by the existing code,
only for request == Modified
* release: the required release version
* reason: the reason for the request
* description: a detailed description for the globaltag manager
* issue: identifier of an existing jira issue (optional)
* user: name of the user
* time: time stamp of the request
password: the password for access to jira or the access token and secret for oauth access
Returns:
True if the upload and jira issue creation/upload was successful
Definition at line 743 of file __init__.py.
◆ upload()
def upload |
( |
|
self, |
|
|
|
filename, |
|
|
|
global_tag, |
|
|
|
normalize = False , |
|
|
|
ignore_existing = False , |
|
|
|
nprocess = 1 , |
|
|
|
uploaded_entries = None |
|
) |
| |
Upload a testing payload storage to the conditions database.
Parameters:
filename (str): filename of the testing payload storage file that should be uploaded
global_tage (str): name of the globaltag to which the data should be uploaded
normalize (bool/str): if True the payload root files will be normalized to have the same checksum for the same content,
if normalize is a string in addition the file name in the root file metadata will be set to it
ignore_existing (bool): if True do not upload payloads that already exist
nprocess (int): maximal number of parallel uploads
uploaded_entries (list): the list of successfully uploaded entries
Returns:
True if the upload was successful
Definition at line 598 of file __init__.py.
The documentation for this class was generated from the following file: