This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a rucio client wrapper class && getFileCountDataset from rucio
Check file presence at both systems - Rucio & Phedex Recalculate missing_phedex with corrections for files managed by Rucio. Typo Check filecount on block level, fetch filecount from metadata instead if len(filenames) Adding 'account=unified' in default config && typo Split unified config lists to relval and nonrelval
- Loading branch information
1 parent
5cca7f2
commit 6e337dd
Showing
4 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Encapsulates requests to Rucio API | ||
Requieres: | ||
rucio-client | ||
Environment: | ||
export X509_USER_PROXY=/tmp/x509up_$UID | ||
export RUCIO_HOME=~/.local/ | ||
${RUCIO_HOME}/rucio.cfg | ||
""" | ||
|
||
from rucio.client import Client | ||
|
||
class RucioClient(Client): | ||
""" | ||
A wrapper class for the Rucio client. | ||
""" | ||
def __init__(self, **kwargs): | ||
""" | ||
Default configuration provided directly into the constructor to avoid | ||
the need of an external configuration file. | ||
All arguments passed to the constructor supersede the defaults. | ||
""" | ||
|
||
defaultConfig = { | ||
'rucio_host': 'http://cms-rucio.cern.ch', | ||
'auth_host': 'https://cms-rucio-auth.cern.ch', | ||
'auth_type': 'x509_proxy', | ||
'ca_cert': '/etc/grid-security/certificates/', | ||
'account': 'unified' | ||
} | ||
|
||
defaultConfig.update(kwargs) | ||
|
||
super(RucioClient, self).__init__(**defaultConfig) | ||
self.scope = 'cms' | ||
|
||
def getFileCountDataset(self, dataset): | ||
""" | ||
Returns the number of files registered in Rucio | ||
""" | ||
try: | ||
files = list(self.list_files(self.scope, dataset)) | ||
except Exception as e: | ||
print(str(e)) | ||
return 0 | ||
return len(files) | ||
|
||
def getFileNamesDataset(self, dataset): | ||
""" | ||
Returns a set of file names in a dataset registered in Rucio | ||
""" | ||
try: | ||
files = list(self.list_files(self.scope, dataset)) | ||
except Exception as e: | ||
print(str(e)) | ||
return [] | ||
fileNames = [_file['name'] for _file in files] | ||
return fileNames | ||
|
||
def getBlockNamesDataset(self, dataset): | ||
""" | ||
Returns a set of block names in a dataset registerd in Rucio | ||
""" | ||
try: | ||
blockNames = [block['name'] for block in self.list_content(self.scope, dataset)] | ||
except Exception as e: | ||
print(str(e)) | ||
return [] | ||
return blockNames | ||
|
||
def getFileCountBlock(self, block): | ||
""" | ||
Returns the number of files in a block registered in Rucio | ||
""" | ||
try: | ||
numFiles = self.get_metadata(self.scope, block)['length'] | ||
except Exception as e: | ||
print(str(e)) | ||
return 0 | ||
return numFiles | ||
|
||
def getFileCountPerBlock(self, dataset): | ||
""" | ||
Returns the number of files per block in a dataset registered in Rucio | ||
""" | ||
# we need blocks to be a list of tuples so we can create a set out of this | ||
try: | ||
blocks = [] | ||
for block in self.getBlockNamesDataset(dataset): | ||
blocks.append((block, self.getFileCountBlock(block))) | ||
except Exception as e: | ||
print(str(e)) | ||
return 0 | ||
return blocks | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../RucioClient.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters