Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions Framework/script/RepoCleaner/qcrepocleaner/Ccdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

class ObjectVersion:
'''
A version of an object in the CCDB.
In the CCDB an object can have many versions with different validity intervals.
This class represents a single version.
A version of an object in the CCDB.

In the CCDB an object can have many versions with different validity intervals.
This class represents a single version.
'''

print_details = False

def __init__(self, path: str, validFrom, validTo, createdAt, uuid=None, metadata=None):
'''
Construct an ObjectVersion.
Expand All @@ -27,6 +29,8 @@ def __init__(self, path: str, validFrom, validTo, createdAt, uuid=None, metadata
:param validFrom: validity range smaller limit (in ms)
:param validTo: validity range bigger limit (in ms)
:param createdAt: creation timestamp of the object
:param uuid: unique id of the object
:param metadata: metadata of the object
'''
self.path = path
self.uuid = uuid
Expand All @@ -42,10 +46,14 @@ def __init__(self, path: str, validFrom, validTo, createdAt, uuid=None, metadata
def __repr__(self):
if "Run" in self.metadata or "RunNumber" in self.metadata:
run_number = self.metadata["Run"] if "Run" in self.metadata else self.metadata["RunNumber"]
return f"Version of object {self.path} created at {self.createdAtDt.strftime('%Y-%m-%d %H:%M:%S')}, valid from {self.validFromAsDt.strftime('%Y-%m-%d %H:%M:%S')}, run {run_number} (uuid {self.uuid})"
else:
return f"Version of object {self.path} created at {self.createdAtDt.strftime('%Y-%m-%d %H:%M:%S')}, valid from {self.validFromAsDt.strftime('%Y-%m-%d %H:%M:%S')} (uuid {self.uuid}, " \
f"ts {self.validFrom})"
run_number = "None"

representation = f"Version of object {self.path} created at {self.createdAtDt.strftime('%Y-%m-%d %H:%M:%S')}, valid from" \
f"{self.validFromAsDt.strftime('%Y-%m-%d %H:%M:%S')}, uuid {self.uuid}, run {run_number}"
if ObjectVersion.print_details:
representation += f", metadata: {self.metadata}"
return representation


class Ccdb:
Expand All @@ -58,9 +66,10 @@ class Ccdb:
counter_preserved: int = 0
set_adjustable_eov: bool = False # if True, set the metadata adjustableEOV before change validity

def __init__(self, url):
def __init__(self, url, print_details=False):
logger.info(f"Instantiate CCDB at {url}")
self.url = url
ObjectVersion.print_details = print_details

def getObjectsList(self, added_since: int = 0, path: str = "", no_wildcard: bool = False) -> List[str]:
'''
Expand Down Expand Up @@ -150,7 +159,7 @@ def getVersionsList(self, object_path: str, from_ts: str = "", to_ts: str = "",
@dryable.Dryable()
def deleteVersion(self, version: ObjectVersion):
'''
Delete the specified version of an object.
Delete the specified version of an object.
:param version: The version of the object to delete, as an instance of ObjectVersion.
'''
url_delete = self.url + '/' + version.path + '/' + str(version.validFrom) + '/' + version.uuid
Expand Down Expand Up @@ -203,7 +212,7 @@ def updateValidity(self, version: ObjectVersion, valid_from: int, valid_to: int,
r = requests.put(full_path, headers=headers)
r.raise_for_status()
self.counter_validity_updated += 1
except requests.exceptions.RequestException as e:
except requests.exceptions.RequestException as e:
logging.error(f"Exception in updateValidity: {traceback.format_exc()}")

@dryable.Dryable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def parseArgs():
'only-path points to an object rather than a folder or if subdirectories must be ignored.')
parser.add_argument('--ignore-last-execution', dest='ignore_last_execution', action='store_true', default=False,
help='Do not check when was the last execution, run from timestamp 0.')
parser.add_argument('--print-versions-details', dest='print_versions_details', action='store_true', default=False,
help='Print extra details about the versions if enabled..')
args = parser.parse_args()
dryable.set(args.dry_run)
logging.info(args)
Expand Down Expand Up @@ -373,7 +375,7 @@ def process_object(object_path, rules, ccdb, args):
def run(args, ccdb_url, rules):

# Get list of objects from CCDB
ccdb = Ccdb(ccdb_url)
ccdb = Ccdb(ccdb_url, args.print_versions_details)
ccdb.logger = logging.getLogger
ccdb.set_adjustable_eov = args.set_adjustableEOV
logging.info(f"ccdb.set_adjustable_eov: {ccdb.set_adjustable_eov}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ def parseArgs():
parser.add_argument('--yes', action='store_true', help='Answers yes to all. You should really not use that.')
parser.add_argument('--metadata', dest='metadata', action='store', default="",
help='Delete only versions matching these metadata. Format: "[/key=value]*"')
parser.add_argument('--print-versions-details', dest='print_versions_details', action='store_true', default=False,
help='Print extra details about the versions if enabled..')
args = parser.parse_args()
dryable.set(args.dry_run)
logging.info(args)
return args


def run(args):
ccdb = Ccdb(args.url)
ccdb = Ccdb(args.url, args.print_versions_details)

total_deleted = 0
total_planned = 0
Expand Down