Uploadclient
Classes¶
UploadClient ¶
UploadClient(_client=None, logger=None, tracing=True)
Initialize the UploadClient with the necessary configuration to manage file uploads.
This method is used to create a new UploadClient instance that can upload files. It allows the use of an existing Rucio Client, a custom logger, and tracing for debug information during the upload process.
PARAMETER | DESCRIPTION |
---|---|
_client
|
An existing Rucio
TYPE:
|
logger
|
A logger function. If not provided, the default Python logger is used.
TYPE:
|
tracing
|
Indicates whether to enable tracing to capture upload activity details.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InputValidationError
|
If the client account is not found or is invalid, preventing upload setup. |
Functions¶
upload ¶
upload(
items,
summary_file_path=None,
traces_copy_out=None,
ignore_availability=False,
activity=None,
)
Uploads one or more files to an RSE (Rucio Storage Element) and optionally registers them.
An overview of this method's performed actions:
1. Collects and validates file info from the passed items
(directories may be
also included), ensuring valid paths exist on the local filesystem. If an RSE
expression is provided, a single RSE is picked at random from it.
-
Checks the RSE's availability for writing (unless
ignore_availability
is True). -
Optionally registers each file in the Rucio Catalog, handling the DID creation, dataset creation/attachment, and replication rules as needed.
-
Uploads the files using the underlying protocol handlers and verifies checksums if desired/possible. Partial or failed uploads raise exceptions.
-
(Optional) Produces a JSON summary file at
summary_file_path
, listing the final PFNs, checksums, and other info for all successfully uploaded files.
PARAMETER | DESCRIPTION |
---|---|
items
|
A sequence of dictionaries, each describing a file to upload (or a directory to be scanned). For each item, the supported keys are:
TYPE:
|
summary_file_path
|
If specified, a JSON file is created with a summary of each successfully uploaded file, including checksum, PFN, scope, and name entries.
TYPE:
|
traces_copy_out
|
A list reference for collecting the trace dictionaries that Rucio generates while iterating over each file. A new trace dictionary is appended to this list for each file considered (even those ultimately skipped or already on the RSE).
TYPE:
|
ignore_availability
|
If set to True, the RSE's "write availability" is not enforced. By default, this is False, and an RSE marked as unavailable for writing will raise an error.
TYPE:
|
activity
|
If you are uploading files without a parent dataset, this string sets the “activity” on the replication rule that Rucio creates for each file (e.g., "Analysis"), which can affect RSE queue priorities. Note: If your files are uploaded into a dataset, the dataset’s replication rule does not use this activity parameter.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Status code ( |
RAISES | DESCRIPTION |
---|---|
NoFilesUploaded
|
Raised if none of the requested files could be uploaded. |
NotAllFilesUploaded
|
Raised if some files were successfully uploaded, but others failed. |
RSEWriteBlocked
|
Raised if |
InputValidationError
|
Raised if mandatory fields are missing, if conflicting DIDs are found, or if no valid files remain after input parsing. |
Examples:
Example
Upload a single local file to the CERN-PROD RSE and write a JSON summary to
upload_summary.json
:
from rucio.client.uploadclient import UploadClient
upload_client = UploadClient()
items = [
{"path": "/data/file1.txt",
"rse": "CERN-PROD", # target RSE
"did_scope": "user.alice", # optional; defaults to user.<account>
"did_name": "file1.txt"} # optional; defaults to basename
]
upload_client.upload(items, summary_file_path="upload_summary.json")
Recursively upload every file found under /data/dataset
into a new
dataset user.alice:mydataset
on a random RSE that matches the
expression tier=1
; collect per-file trace dictionaries for later
inspection:
traces: list[TraceBaseDict] = []
dir_item = {
"path": "/data/dataset",
"rse": "tier=1", # RSE expression; one will be chosen
"recursive": True,
"dataset_scope": "user.alice",
"dataset_name": "mydataset",
"dataset_meta": {"project": "demo"},
}
upload_client.upload([dir_item], traces_copy_out=traces)
preferred_impl ¶
preferred_impl(rse_settings, domain)
Select a suitable protocol implementation for read, write, and delete operations on the given RSE and domain.
This method checks the local client configuration (under the [upload] preferred_impl
setting) and compares it against the list of protocols declared in rse_settings
.
It attempts to find a protocol that supports the required I/O operations (read,
write, delete) in the specified domain. If multiple preferred protocols are listed
in the config, it iterates in order and returns the first viable match.
PARAMETER | DESCRIPTION |
---|---|
rse_settings
|
A dictionary describing RSE details, including available protocols and their domains.
TYPE:
|
domain
|
The network domain (e.g., 'lan' or 'wan') in which the protocol must support all operations.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[str]
|
The name of a protocol implementation that can handle read/write/delete for the specified domain, or None if no suitable protocol was found. |