rs_workflows/payload_generator.md¶
This module contains functions to generate DPR payloads for RS-Server.
build_adfs(storage_configuration, adfs, dpr_process_in)
¶
Build a list of AdfConfig objects from input ADF definitions.
ADFs are grouped by their identifier. If an identifier is associated with a single path, a standard AdfConfig is created. If multiple paths share the same identifier, a single AdfConfig is created using a common folder and a regex pattern to match all corresponding files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_configuration
|
StorageConfig
|
Configuration object used to retrieve default storage parameters. |
required |
adfs
|
list[tuple[str, str, str]]
|
List of (adf_id, adfs_type, path) tuples. |
required |
dpr_process_in
|
DprProcessIn
|
DPR input process definition |
required |
Returns:
| Type | Description |
|---|---|
list[AdfConfig]
|
list[AdfConfig]: List of constructed AdfConfig objects, one per group |
list[AdfConfig]
|
of ADFs. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
build_input_products(unit, dpr_process_in, storage_configuration, catalog_client)
¶
Builds the list of input product configurations for a workflow step.
Each input product is resolved by matching the dpr process definition against the unit configuration and querying the STAC catalog for its asset path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
dict
|
Workflow unit definition containing input product metadata. |
required |
dpr_process_in
|
DprProcessIn
|
Input configuration for the dpr processing prefect flow. |
required |
storage_configuration
|
StorageConfig
|
Storage configuration parameters (S3 credentials, etc.). TODO ! as |
required |
written in the comment from story 800, point 3
|
About the storage_configuration : for the time being, |
required | |
catalog_client
|
CatalogClient
|
Client for querying STAC collections and items. |
required |
Returns:
| Type | Description |
|---|---|
list[InputProduct]
|
list[InputProduct]: A list of input product configuration objects. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If an expected input product or STAC item cannot be found. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
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 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
build_output_products(unit, dpr_process_in, storage_configuration, owner_id, bucket_configuration)
¶
Builds the list of output product configurations for a workflow step.
Each output product is mapped to an appropriate S3 bucket, determined by the owner ID, collection, and product type according to the configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
dict
|
Workflow unit definition containing output product metadata. |
required |
dpr_process_in
|
DprProcessIn
|
Input configuration defining generated outputs. |
required |
storage_configuration
|
StorageConfig
|
Storage configuration parameters (S3 credentials, etc.). TODO ! as |
required |
written in the comment from story 800, point 3
|
About the storage_configuration : for the time being, |
required | |
owner_id
|
str
|
The owner ID for the workflow. |
required |
bucket_configuration
|
list[list[str]]
|
Parsed S3 bucket configuration entries. |
required |
Returns:
| Type | Description |
|---|---|
list[OutputProduct]
|
list[OutputProduct]: A list of output product configuration objects. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If an output mapping or configuration rule cannot be found. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
build_payload(flow_env, unit_list, adfs, dpr_process_in, storage_configuration, bucket_configuration, external_modules=None)
¶
Builds the payload schema from already loaded storage and bucket configurations.
This function does not depend on a Prefect run context, so it can be called outside of Prefect (see scripts/generate_payload_standalone.py).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_env
|
FlowEnv
|
any object providing the 'owner_id' and 'rs_client' attributes (the rs_client is only used to retrieve the input products STAC items from the catalog). |
required |
unit_list
|
list[dict]
|
List of workflow unit definitions. |
required |
adfs
|
list[tuple[str, str, str]]
|
List of (adfs name, adfs type, storage path) tuples. |
required |
dpr_process_in
|
DprProcessIn
|
DPR input process definition. |
required |
storage_configuration
|
StorageConfig
|
Storage configuration. |
required |
bucket_configuration
|
list[list[str]]
|
Output bucket configuration rows. |
required |
external_modules
|
list[dict[str, str]] | None
|
Optional list of external modules. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PayloadSchema |
PayloadSchema
|
the generated payload. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | |
build_workflow_step(unit)
¶
Constructs a WorkflowStep instance from a unit configuration dictionary.
This function parses the given processing unit definition, extracting input products, auxiliary data files (ADFs), and output products. It then returns a WorkflowStep object ready to be integrated into a full processing payload schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
dict
|
A dictionary defining a single workflow unit. Expected keys include: - "name" (str): The unit name. - "module" (str): The module path or identifier. - "input_products" (list[dict], optional): List of input product mappings. - "input_adfs" (list[dict], optional): List of auxiliary data files. - "output_products" (list[dict], optional): List of output product mappings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
WorkflowStep |
A fully initialized workflow step object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required key is missing from the provided unit dictionary. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
fetch_csv_from_endpoint(endpoint)
¶
Fetches a CSV file from rs-osam endpoint and returns it as a list of rows (each row is a list of strings).
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the endpoint cannot be reached |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
find_s3_output_bucket(config_rows, owner_id, output_collection, product_type)
¶
Determines the appropriate S3 output bucket based on owner, collection, and product type. It is based on story 854
The matching logic prioritizes
- Exact owner and collection match.
- Fallback match for owner only.
- Global fallback bucket (all first 3 columns are '*').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_rows
|
list[list[str]]
|
Parsed configuration rows from the configmap file. |
required |
owner_id
|
str
|
Owner identifier of the processing job. |
required |
output_collection
|
str
|
Collection name associated with the output. |
required |
product_type
|
str
|
Product type identifier (e.g., 'S3OLC', 'S3MWR'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resolved S3 bucket name (from the fifth column of the configmap). |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no matching bucket is found in the configuration. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
generate_payload(flow_env, unit_list, adfs, dpr_process_in, external_modules=None)
¶
Assembles and generates a payload schema for a DPR (Data Processing Request) job.
This Prefect task builds the payload definition dynamically based on the provided workflow units, auxiliary data files, and input configuration. It produces a PayloadSchema object compatible with RS-Server DPR jobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
FlowEnv
|
Environment configuration for the Prefect flow, including credentials, tracing, and runtime context. |
required |
unit_list
|
list[dict]
|
List of workflow unit definitions containing I/O specifications and processing parameters. |
required |
adfs
|
list[tuple[str, str, str]]
|
List of auxiliary item tuples, where each tuple includes the adfs name, the adfs type and the s3 storage path. |
required |
dpr_process_in
|
DprProcessIn
|
DPR input process definition containing product paths and parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
PayloadSchema
|
A dictionary representation of the generated PayloadSchema. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required key is missing in one of the unit definitions. |
Exception
|
For any unexpected error during payload assembly. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
get_first_asset_dir(item)
¶
Returns the directory path (local or remote) derived from the href of the first asset in a pystac Item.
Special case
If the first asset is a Zarr store (media_type "application/vnd+zarr"), the full href is returned unchanged, since it already represents a directory-like dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Item
|
The STAC item containing assets. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str | None
|
str | None: The resolved directory path or URL of the first asset, or None if no assets exist. |
|
Examples |
str | None
|
s3://dev-bucket/path/to/folder.zarr -> s3://dev-bucket/path/to/folder.zarr (Zarr store, returned as-is) s3://dev-bucket/path/to/cadu.raw -> s3://dev-bucket/path/to /local/path/to/file.raw -> /local/path/to https://example.com/data/file.tif -> https://example.com/data |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
get_io(unit, dpr_process_in, flow_env, storage_configuration, bucket_configuration)
¶
Builds both input and output product configurations for a given workflow step.
This function integrates configuration data from
- The workflow unit definition ('unit')
- The DPR process input ('dpr_process_in')
- The environment and S3 configuration (via 'flow_env' and configmap)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
dict
|
Workflow unit definition containing I/O product configurations. |
required |
dpr_process_in
|
DprProcessIn
|
DPR input configuration containing product mappings. |
required |
flow_env
|
FlowEnv
|
Environment context holding execution metadata. |
required |
storage_configuration
|
StorageConfig
|
storage configuration info. |
required |
bucket_configuration
|
list[list[str]]
|
list[list[str]]: Parsed S3 bucket configuration entries. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list, list]
|
tuple[list[InputProduct], list[OutputProduct]]: A tuple containing lists of input and output product objects ready for inclusion in a payload schema. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the configuration file cannot be read or an input/output product cannot be resolved. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
resolve_stac_input_path(catalog_client, collection, stac_item_id)
¶
Retrieves the S3 path of the first asset from a STAC item within a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_client
|
CatalogClient
|
Client instance used to query the STAC catalog. |
required |
collection
|
str
|
The collection identifier in the catalog. |
required |
stac_item_id
|
str
|
The STAC item identifier to resolve. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Item, str]
|
tuple[Item, str]: The specified STAC item and the path to its first asset. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the STAC item is missing or contains no assets. |
Source code in docs/rs-client-libraries/rs_workflows/payload_generator.py
wildcard_match(string, pattern)
¶
Checks whether a given string matches a simple wildcard pattern.
The wildcard character '' is treated as a placeholder for any substring. For example: - 'abcdef' matches 'abcdef' and 'abcXYZdef'. - 'xyz' matches 'endxyz'. - '' matches any string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The string to check against the pattern. |
required |
pattern
|
str
|
The wildcard pattern, which may include '*'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the string matches the pattern, False otherwise. |