Skip to content

Commit

Permalink
Enforce dataset_lifetime column to be integer and not null
Browse files Browse the repository at this point in the history
ensure move and custodial are not None; fix order of db constraints

address some of Valentins concerns

add docstring and extra comment for the param/validation
  • Loading branch information
amaltaro committed May 2, 2022
1 parent a260091 commit 356a00c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/python/WMComponent/DBS3Buffer/MySQL/Create.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, logger=None, dbi=None, params=None):
subscribed INTEGER DEFAULT 0,
phedex_group VARCHAR(100),
delete_blocks INTEGER,
dataset_lifetime INTEGER DEFAULT 0,
dataset_lifetime INTEGER DEFAULT 0 NOT NULL,
PRIMARY KEY (id),
CONSTRAINT uq_dbs_dat_sub UNIQUE (dataset_id, site, custodial, auto_approve, move, priority))"""

Expand Down
32 changes: 23 additions & 9 deletions src/python/WMComponent/DBS3Buffer/MySQL/NewSubscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class NewSubscription(DBFormatter):
"""

def _createPhEDExSubBinds(self, datasetID, subscriptionInfo, custodialFlag):
"""
Creates the database binds for both custodial and non custodial data
placements.
:param datasetID: integer with the dataset id
:param subscriptionInfo: dictionary object from the request spec
:param custodialFlag: boolean flag defining whether it's custodial or not
:return: a list of dictionary binds
"""
# NOTE: the subscription information is already validated upstream, at
# the request factory. Thus, there is no need to cast/validate anything
# at this level.

# DeleteFromSource is not supported for move subscriptions
delete_blocks = None
Expand All @@ -40,15 +52,17 @@ def _createPhEDExSubBinds(self, datasetID, subscriptionInfo, custodialFlag):

binds = []
for site in sites:
binds.append({'id': datasetID,
'site': site,
'custodial': custodialFlag,
'auto_approve': 1 if site in subscriptionInfo['AutoApproveSites'] else 0,
'move': isMove,
'priority': subscriptionInfo['Priority'],
'phedex_group': phedex_group,
'delete_blocks': delete_blocks,
'dataset_lifetime': subscriptionInfo['DatasetLifetime']})
bind = {'id': datasetID,
'site': site,
'custodial': 1 if custodialFlag else 0,
'auto_approve': 1 if site in subscriptionInfo['AutoApproveSites'] else 0,
'move': isMove,
'priority': subscriptionInfo['Priority'],
'phedex_group': phedex_group,
'delete_blocks': delete_blocks}
if subscriptionInfo['DatasetLifetime'] is not None:
bind.update(dict(dataset_lifetime=subscriptionInfo['DatasetLifetime']))
binds.append(bind)
return binds

def execute(self, datasetID, subscriptionInfo, conn=None, transaction=False):
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMComponent/DBS3Buffer/Oracle/Create.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, logger = None, dbi = None, params = None):
subscribed INTEGER DEFAULT 0,
phedex_group VARCHAR(100),
delete_blocks INTEGER,
dataset_lifetime INTEGER DEFAULT 0,
dataset_lifetime INTEGER DEFAULT 0 NOT NULL,
PRIMARY KEY (id),
CONSTRAINT uq_dbs_dat_sub UNIQUE (dataset_id, site, custodial, auto_approve, move, priority)
)"""
Expand Down

0 comments on commit 356a00c

Please sign in to comment.