Datablocks
calculate_md5_checksum(filename, chunksize=1024 * 1025)
Calculate an md5 hash of a file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
Path
|
absolute or relative path to file |
required |
chunksize
|
int
|
default chunk size to calculate hash on. Defaults to 1024*1025. |
1024 * 1025
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
hash as str |
Source code in backend/archiver/utils/datablocks.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
copy_file_to_folder(src_file, dst_folder)
Copies a file to a destination folder (does not need to exist)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_file
|
Path
|
Source file |
required |
dst_folder
|
Path
|
destination folder - needs to exist |
required |
Raises:
Type | Description |
---|---|
SystemError
|
raises if operation fails |
Source code in backend/archiver/utils/datablocks.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
create_datablock_entries(dataset_id, folder, origDataBlocks, tar_infos)
Create datablock entries compliant with schema provided by scicat
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_id
|
str
|
Dataset identifier |
required |
folder
|
Path
|
description |
required |
origDataBlocks
|
List[OrigDataBlock]
|
description |
required |
tarballs
|
List[Path]
|
description |
required |
Returns:
Type | Description |
---|---|
List[DataBlock]
|
List[DataBlock]: description |
Source code in backend/archiver/utils/datablocks.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
create_tarballs(dataset_id, src_folder, dst_folder, target_size=300 * 1024 ** 2)
Create datablocks, i.e. .tar.gz files, from files in a folder. The files will be named according to the dataset they belong to. The target size of the created files is 300 MB by default
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_id
|
str
|
|
required |
folder
|
Path
|
description |
required |
target_size
|
int
|
description. Defaults to 300(1024*2). |
300 * 1024 ** 2
|
Returns:
Type | Description |
---|---|
List[TarInfo]
|
List[Path]: description |
Source code in backend/archiver/utils/datablocks.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
download_object_from_s3(client, bucket, folder, object_name, target_path)
Download an object from S3 storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket
|
Bucket
|
Bucket to look for file |
required |
folder
|
Path
|
s3 prefix for object |
required |
object_name
|
str
|
object name, no prefix |
required |
target_path
|
Path
|
absolute or relative path for the file to be created |
required |
Source code in backend/archiver/utils/datablocks.py
119 120 121 122 123 124 125 126 127 128 129 130 |
|
download_objects_from_s3(client, prefix, bucket, destination_folder)
Download objects form s3 storage to folder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
Path
|
S3 prefix |
required |
bucket
|
Bucket
|
s3 bucket |
required |
destination_folder
|
Path
|
Target folder. Will be created if it does not exist. |
required |
Returns:
Type | Description |
---|---|
List[Path]
|
List[Path]: List of paths of created files |
Source code in backend/archiver/utils/datablocks.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
list_datablocks(client, prefix, bucket)
List all objects in s3 bucket and path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
minio_prefix
|
Path
|
prefix for files to be listed |
required |
bucket
|
Bucket
|
s3 bucket |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
List[ListedObject]
|
Iterator to objects |
Source code in backend/archiver/utils/datablocks.py
133 134 135 136 137 138 139 140 141 142 143 144 |
|
sufficient_free_space_on_lts()
Checks for free space on configured LTS storage with respect to configured free space percentage.
Returns:
Name | Type | Description |
---|---|---|
boolean |
condition of eneough free space satisfied |
Source code in backend/archiver/utils/datablocks.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
wait_for_file_accessible(file, timeout_s=360)
async
Returns:
Source code in backend/archiver/utils/datablocks.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
wait_for_free_space()
async
Asynchronous wait until there is enough free space. Waits in linear intervals to check for free space
TODO: add exponential backoff for waiting time
Returns:
Name | Type | Description |
---|---|---|
boolean |
Returns True once there is enough free space |
Source code in backend/archiver/utils/datablocks.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|