dafab-client 4.2.0__tar.gz → 4.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dafab-client might be problematic. Click here for more details.

Files changed (120) hide show
  1. {dafab_client-4.2.0 → dafab_client-4.3.0}/PKG-INFO +1 -1
  2. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_notebooks/dafab_dasi_workflows.ipynb +0 -2
  3. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/demo_imports.py +2 -0
  4. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/Deletion/delete_file_of_scope_name.py +15 -2
  5. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/Deletion/delete_replica_of_scope_name.py +15 -2
  6. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/Workflows/manage_derived_assets.py +35 -26
  7. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/Workflows/manage_original_assets.py +23 -9
  8. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client.egg-info/PKG-INFO +1 -1
  9. {dafab_client-4.2.0 → dafab_client-4.3.0}/docs/releasing.md +1 -1
  10. {dafab_client-4.2.0 → dafab_client-4.3.0}/pyproject.toml +1 -1
  11. {dafab_client-4.2.0 → dafab_client-4.3.0}/LICENSE +0 -0
  12. {dafab_client-4.2.0 → dafab_client-4.3.0}/MANIFEST.in +0 -0
  13. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/__init__.py +0 -0
  14. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/__init__.py +0 -0
  15. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/__init__.py +0 -0
  16. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/accountclient.py +0 -0
  17. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/baseclient.py +0 -0
  18. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/client.py +0 -0
  19. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/credentialclient.py +0 -0
  20. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/didclient.py +0 -0
  21. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/pingclient.py +0 -0
  22. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/replicaclient.py +0 -0
  23. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/rseclient.py +0 -0
  24. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/client/scopeclient.py +0 -0
  25. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/__init__.py +0 -0
  26. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/checksum.py +0 -0
  27. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/client.py +0 -0
  28. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/config.py +0 -0
  29. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/constants.py +0 -0
  30. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/constraints.py +0 -0
  31. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/exception.py +0 -0
  32. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/filter.py +0 -0
  33. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/jsonvalue.py +0 -0
  34. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/metadata_filter.py +0 -0
  35. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/plugins.py +0 -0
  36. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/types.py +0 -0
  37. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/common/utils.py +0 -0
  38. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/dafab_lib.py +0 -0
  39. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/global_utils.py +0 -0
  40. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/overridden_rucio_client.py +0 -0
  41. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/secrets/user_dafab/config +0 -0
  42. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/secrets/user_dafab/rucio_ca_bundle.pem +0 -0
  43. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/vcsversion.py +0 -0
  44. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/_rucio/version.py +0 -0
  45. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/assets/smart_agriculture/S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115/field-boundaries-S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115-10-v3.0.0-dafab-bundle.zip +0 -0
  46. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/assets/smart_agriculture/S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115/field-boundaries-S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115-10-v3.0.0.geojson +0 -0
  47. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/smart_agriculture/agriculture_season/agriculture_season_(bootstrap).json +0 -0
  48. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/smart_agriculture/agriculture_season/agriculture_season_autumn_(bootstrap).json +0 -0
  49. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/smart_agriculture/agriculture_season/agriculture_season_spring_(bootstrap).json +0 -0
  50. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/smart_agriculture/agriculture_season/agriculture_season_summer_(bootstrap).json +0 -0
  51. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/smart_agriculture/agriculture_season/agriculture_season_winter_(bootstrap).json +0 -0
  52. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_anomaly/water_anomaly_(bootstrap).json +0 -0
  53. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_anomaly/water_anomaly_drought_(bootstrap).json +0 -0
  54. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_anomaly/water_anomaly_flood_(bootstrap).json +0 -0
  55. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_anomaly/water_anomaly_normal_(bootstrap).json +0 -0
  56. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_basin/water_basin_(bootstrap).json +0 -0
  57. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_basin/water_basin_ganges_(bootstrap).json +0 -0
  58. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/catalogs/water_analysis/water_basin/water_basin_unclassified_(bootstrap).json +0 -0
  59. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/collections/sentinel_2_l2a/sentinel_2_l2a_(bootstrap).json +0 -0
  60. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/collections/smart_agriculture/smart_agriculture_(bootstrap).json +0 -0
  61. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/collections/water_analysis/water_analysis_(bootstrap).json +0 -0
  62. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/dasi/staged/S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115.json +0 -0
  63. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/dasi/staged/S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115_TCI_20m.jp2 +0 -0
  64. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/items/smart_agriculture/S2B_MSIL2A_20190101T091359_N0500_R050_T34SGH_20221202T002115_smart_agriculture_300_(bootstrap).json +0 -0
  65. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_data/notebook_fixtures/stac_(bootstrap).json +0 -0
  66. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_notebooks/dafab_operator_workflows.ipynb +0 -0
  67. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_notebooks/dafab_simple_user_workflows.ipynb +0 -0
  68. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/example_notebooks/dafab_skim_workflows.ipynb +0 -0
  69. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/System/check_available_accounts.py +0 -0
  70. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/System/check_storage.py +0 -0
  71. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/__init__.py +0 -0
  72. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/check_server_health.py +0 -0
  73. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/container_management/ensure_container.py +0 -0
  74. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/container_management/list_containers.py +0 -0
  75. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/dataset_management/ensure_dataset.py +0 -0
  76. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/dataset_management/list_datasets.py +0 -0
  77. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/dataset_management/scope_management.py +0 -0
  78. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/db_bootstrap/account_manager.py +0 -0
  79. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/did_management/operations.py +0 -0
  80. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/errors.py +0 -0
  81. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/Workflows/original_previews.py +0 -0
  82. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/Workflows/preview_bundle.py +0 -0
  83. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/list_files.py +0 -0
  84. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/file_management/signing.py +0 -0
  85. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/filter_by_bbox.py +0 -0
  86. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/filter_by_bbox_and_timerange.py +0 -0
  87. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/filter_by_enhanced_filter.py +0 -0
  88. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/filter_by_relationships.py +0 -0
  89. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/filter_by_stac_type.py +0 -0
  90. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/filter_by_timerange.py +0 -0
  91. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/filtering/mapper.py +0 -0
  92. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Insertion/set_metadata.py +0 -0
  93. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Operations/common.py +0 -0
  94. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Operations/delete_metadata_for_did.py +0 -0
  95. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Operations/insert_metadata_for_did.py +0 -0
  96. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Operations/update_metadata_for_did.py +0 -0
  97. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Operations/upsert_metadata_for_did.py +0 -0
  98. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Patch/patch_metadata_for_dids.py +0 -0
  99. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Preflight/validate_derived_item_file.py +0 -0
  100. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Preflight/validate_facet_value_catalog_file.py +0 -0
  101. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Preflight/validate_original_item_file.py +0 -0
  102. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Retrieval/Complete/get_metadata_for_scope_name.py +0 -0
  103. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Retrieval/Partial/get_single_metadata_for_scope_name.py +0 -0
  104. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Workflows/delete_derived_item.py +0 -0
  105. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Workflows/sync_spatial_bbox_integrity.py +0 -0
  106. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Workflows/update_derived_item.py +0 -0
  107. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/Workflows/update_original_item.py +0 -0
  108. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/metadata_management/document_api.py +0 -0
  109. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/resources/schemas/Schema_Copernicus_with_dafab.json +0 -0
  110. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/resources/schemas/Schema_DaFab_Facet_Value_Catalog.json +0 -0
  111. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/resources/schemas/dafab-smart_agriculture-item.schema.json +0 -0
  112. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/resources/schemas/dafab-water_analysis-item.schema.json +0 -0
  113. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/resources/schemas/dasi-original-item.schema.json +0 -0
  114. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client/helpers/runtime_paths.py +0 -0
  115. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client.egg-info/SOURCES.txt +0 -0
  116. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client.egg-info/dependency_links.txt +0 -0
  117. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client.egg-info/requires.txt +0 -0
  118. {dafab_client-4.2.0 → dafab_client-4.3.0}/dafab_client.egg-info/top_level.txt +0 -0
  119. {dafab_client-4.2.0 → dafab_client-4.3.0}/readme.md +0 -0
  120. {dafab_client-4.2.0 → dafab_client-4.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dafab_client
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: Python client for the DaFab catalogue of Sentinel-2 imagery and AI-derived water and agriculture products, built on Rucio.
5
5
  Author: DaFab
6
6
  License-Expression: Apache-2.0
@@ -81,7 +81,6 @@
81
81
  "STAGED_DATA_DIR = dc.Path(\"/path/to/staged-originals\")\n",
82
82
  "ORIGINAL_ITEM_FILE = STAGED_DATA_DIR / f\"{ORIGINAL_ITEM_ID}.json\"\n",
83
83
  "STAGED_ASSETS_DIR = STAGED_DATA_DIR\n",
84
- "RUCIO_STORAGE = \"MELUXINA_S3\"\n",
85
84
  "ASSET_NAMES = (\"TCI_20m\",)\n",
86
85
  "\n",
87
86
  "ORIGINAL_ITEM_SOURCE_SCHEMA = \"dasi-original-item.schema.json\"\n",
@@ -330,7 +329,6 @@
330
329
  " asset_path,\n",
331
330
  " asset_key,\n",
332
331
  " scope=STAC_SCOPE,\n",
333
- " storage_name=RUCIO_STORAGE,\n",
334
332
  " )\n",
335
333
  " for asset_key, asset_path in original_asset_paths.items()\n",
336
334
  "]\n",
@@ -37,6 +37,7 @@ from .file_management.Workflows.manage_derived_assets import (
37
37
  list_derived_items_with_missing_assets,
38
38
  list_item_asset_entries,
39
39
  publish_derived_asset,
40
+ storage_for_asset,
40
41
  )
41
42
  from .file_management.Workflows.manage_original_assets import (
42
43
  ensure_original_item_metadata,
@@ -111,6 +112,7 @@ __all__ = [
111
112
  "publish_original_asset",
112
113
  "remove_original_item_parent_links",
113
114
  "set_metadata",
115
+ "storage_for_asset",
114
116
  "sync_derived_collection_extent",
115
117
  "sync_original_collection_extent",
116
118
  "validate_original_asset_publication",
@@ -48,7 +48,13 @@ def _delete_file_via_signed_url(
48
48
  )
49
49
 
50
50
 
51
- def delete_file(fname: str, scope: str = 'dafab', rse: str = 'MELUXINA_S3'):
51
+ def _replica_rses(fname: str, scope: str) -> list[str]:
52
+ """The RSEs that hold a replica of a file."""
53
+ rows = connection_manager().list_replicas(dids=[{'scope': scope, 'name': fname}], all_states=True)
54
+ return sorted({rse for row in rows if isinstance(row, dict) for rse in (row.get('rses') or {})})
55
+
56
+
57
+ def delete_file(fname: str, scope: str = 'dafab', rse: str | None = None):
52
58
  """
53
59
  Remove a file from an RSE in Rucio.
54
60
 
@@ -63,13 +69,20 @@ def delete_file(fname: str, scope: str = 'dafab', rse: str = 'MELUXINA_S3'):
63
69
  scope : str, optional
64
70
  Rucio scope of the file, by default ``'dafab'``.
65
71
  rse : str, optional
66
- Target RSE from which the file is deleted, by default ``'MELUXINA_S3'``.
72
+ RSE from which the file is deleted, by default every RSE that holds a replica of it.
67
73
 
68
74
  Returns
69
75
  -------
70
76
  bool
71
77
  ``True`` if the file was removed or was already absent, ``False`` if it fails at once or after all retry attempts.
72
78
  """
79
+ if rse is None:
80
+ try:
81
+ rses = _replica_rses(fname, scope)
82
+ except Exception as e:
83
+ LOG.warning(f"Listing the replicas of the file '{scope}:{fname}' failed with '{type(e).__name__}': {e}")
84
+ return False
85
+ return all(delete_file(fname, scope, name) for name in rses)
73
86
  max_retries = 5
74
87
  retry_delay = 30 # seconds
75
88
 
@@ -11,7 +11,7 @@ LOG = setup_logger(__name__)
11
11
 
12
12
  def delete_replica(
13
13
  fname: str,
14
- rse: str = 'MELUXINA_S3',
14
+ rse: str | None = None,
15
15
  scope: str = 'dafab',
16
16
  ignore_availability: bool = True,
17
17
  ):
@@ -27,7 +27,7 @@ def delete_replica(
27
27
  fname : str
28
28
  Name of the file whose replica should be removed.
29
29
  rse : str, optional
30
- Target RSE from which to delete the replica, by default ``'MELUXINA_S3'``.
30
+ RSE from which to delete the replica, by default the one RSE that holds a replica of the file.
31
31
  scope : str, optional
32
32
  Rucio scope of the file, by default ``'dafab'``.
33
33
  ignore_availability : bool, optional
@@ -39,6 +39,19 @@ def delete_replica(
39
39
  ``True`` if the replica was successfully removed or was already absent,
40
40
  ``False`` after all retry attempts failed.
41
41
  """
42
+ if rse is None:
43
+ try:
44
+ rows = connection_manager().list_replicas(dids=[{'scope': scope, 'name': fname}], all_states=True)
45
+ rses = sorted({name for row in rows if isinstance(row, dict) for name in (row.get('rses') or {})})
46
+ except Exception as e:
47
+ LOG.warning(f"Listing the replicas of '{scope}:{fname}' failed with '{type(e).__name__}': {e}")
48
+ return False
49
+ if len(rses) > 1:
50
+ LOG.warning(f"'{scope}:{fname}' has replicas on {rses}; name the RSE whose replica to delete.")
51
+ return False
52
+ if not rses:
53
+ return True
54
+ rse = rses[0]
42
55
  max_retries = 5
43
56
  retry_delay = 30 # seconds
44
57
 
@@ -30,7 +30,10 @@ from dafab_client._rucio.global_utils import setup_logger
30
30
  LOG = setup_logger(__name__)
31
31
 
32
32
  DEFAULT_SCOPE = "dafab"
33
- DEFAULT_STORAGE = "MELUXINA_S3"
33
+ # The RSE of each item's bundle of previews, the one storage that the discovery service reads, kept stable
34
+ HOME_STORAGE = "MELUXINA_S3"
35
+ # The RSE of an item's other files, unless a publication names another
36
+ DATA_STORAGE = "MELUXINA_TIER1"
34
37
  DEFAULT_STAC_ROOT = "https://dafab.cern.ch/stac"
35
38
 
36
39
 
@@ -39,6 +42,11 @@ def _has_own_file(asset_key: str) -> bool:
39
42
  return asset_key != THUMBNAIL_KEY
40
43
 
41
44
 
45
+ def storage_for_asset(asset_key: str, data_storage: str = DATA_STORAGE) -> str:
46
+ """The RSE to which an item's asset is published: the home RSE for its bundle of previews, else the data RSE."""
47
+ return HOME_STORAGE if asset_key == BUNDLE_KEY else data_storage
48
+
49
+
42
50
  def _escape_pointer_token(token: str) -> str:
43
51
  return token.replace("~", "~0").replace("/", "~1")
44
52
 
@@ -325,6 +333,16 @@ def _storage_names_for_file(*, scope: str, file_name: str) -> tuple[list[str], s
325
333
  return storage_names_by_file[file_name], error
326
334
 
327
335
 
336
+ def _replica_storage(*, scope: str, file_name: str, preferred: str | None = None) -> str | None:
337
+ """The RSE that holds a file's replica: the preferred RSE if it holds one, else the first that does, else None."""
338
+ storage_names, error = _storage_names_for_file(scope=scope, file_name=file_name)
339
+ if error:
340
+ raise RuntimeError(f"Could not verify replicas for '{scope}:{file_name}': {error}")
341
+ if preferred in storage_names:
342
+ return preferred
343
+ return storage_names[0] if storage_names else None
344
+
345
+
328
346
  def _ensure_file_attached_to_item(
329
347
  *,
330
348
  scope: str,
@@ -459,7 +477,6 @@ def _replacement_delete_plan(
459
477
  scope: str,
460
478
  file_name: str,
461
479
  item_id: str,
462
- storage_name: str,
463
480
  ) -> dict[str, Any]:
464
481
  plan = connection_manager().delete_did_tree(scope=scope, name=file_name, dry_run=True)
465
482
  if not isinstance(plan, dict):
@@ -482,13 +499,13 @@ def _replacement_delete_plan(
482
499
  replicas = plan.get("replicas")
483
500
  if not isinstance(replicas, list):
484
501
  raise RuntimeError(f"Replacement plan for '{scope}:{file_name}' has no valid replica list.")
502
+ # The deletion removes each replica on its own RSE, so the file may be on any RSE
485
503
  unexpected_replicas = [
486
504
  replica
487
505
  for replica in replicas
488
506
  if not isinstance(replica, dict)
489
507
  or str(replica.get("scope")) != scope
490
508
  or str(replica.get("name")) != file_name
491
- or str(replica.get("rse")) != storage_name
492
509
  ]
493
510
  if unexpected_replicas:
494
511
  raise RuntimeError(
@@ -565,24 +582,20 @@ def _preflight_derived_asset_publication(
565
582
  scope=scope,
566
583
  file_name=file_name,
567
584
  item_id=derived_item_id,
568
- storage_name=storage_name,
569
585
  )
570
586
  else:
571
587
  conflict = None
572
588
  storage_names, storage_error = _storage_names_for_file(scope=scope, file_name=file_name)
573
589
  if storage_error:
574
590
  raise RuntimeError(f"Could not verify replicas for '{scope}:{file_name}': {storage_error}")
575
- if storage_name not in storage_names:
576
- conflict = (
577
- f"FILE DID '{scope}:{file_name}' has no registered replica on "
578
- f"'{storage_name}': {storage_names}"
579
- )
591
+ if not storage_names:
592
+ conflict = f"FILE DID '{scope}:{file_name}' has no registered replica."
580
593
  else:
581
594
  try:
582
595
  storage_identity = _remote_file_identity(
583
596
  scope=scope,
584
597
  file_name=file_name,
585
- storage_name=storage_name,
598
+ storage_name=storage_name if storage_name in storage_names else storage_names[0],
586
599
  timeout=timeout,
587
600
  )
588
601
  except FileNotFoundError as exc:
@@ -618,9 +631,8 @@ def _delete_existing_asset_file(
618
631
  item_id: str,
619
632
  file_name: str,
620
633
  expected_identity: dict[str, Any],
621
- storage_name: str,
622
634
  ) -> dict[str, Any]:
623
- _replacement_delete_plan(scope=scope, file_name=file_name, item_id=item_id, storage_name=storage_name)
635
+ _replacement_delete_plan(scope=scope, file_name=file_name, item_id=item_id)
624
636
  current_identity = _catalog_file_identity(file_name, scope=scope)
625
637
  if not (
626
638
  current_identity.get("exists") is True
@@ -664,7 +676,6 @@ def _delete_existing_asset_file(
664
676
  scope=scope,
665
677
  file_name=file_name,
666
678
  item_id=item_id,
667
- storage_name=storage_name,
668
679
  )
669
680
  except Exception as exc:
670
681
  if detached:
@@ -1197,7 +1208,7 @@ def publish_derived_asset(
1197
1208
  *,
1198
1209
  overwrite: bool = False,
1199
1210
  scope: str = DEFAULT_SCOPE,
1200
- storage_name: str = DEFAULT_STORAGE,
1211
+ storage_name: str | None = None,
1201
1212
  stac_root_href: str = DEFAULT_STAC_ROOT,
1202
1213
  asset_title: str | None = None,
1203
1214
  asset_type: str | None = None,
@@ -1212,7 +1223,7 @@ def publish_derived_asset(
1212
1223
  overwrite: Replace a conflicting generated FILE DID and its metadata entry. Exact existing content is
1213
1224
  reused. Stale attachments for the same asset are pruned after successful publication.
1214
1225
  scope: Catalog scope containing the target item.
1215
- storage_name: Storage endpoint used for upload.
1226
+ storage_name: RSE of the upload, by default the home RSE for the bundle of previews and the data RSE for any other asset.
1216
1227
  stac_root_href: STAC root URL used to construct stable asset hrefs.
1217
1228
  asset_title: Optional title override stored in asset metadata.
1218
1229
  asset_type: Optional media type override stored in asset metadata.
@@ -1238,7 +1249,7 @@ def _publish_derived_asset(
1238
1249
  *,
1239
1250
  overwrite: bool = False,
1240
1251
  scope: str = DEFAULT_SCOPE,
1241
- storage_name: str = DEFAULT_STORAGE,
1252
+ storage_name: str | None = None,
1242
1253
  stac_root_href: str = DEFAULT_STAC_ROOT,
1243
1254
  asset_title: str | None = None,
1244
1255
  asset_type: str | None = None,
@@ -1249,6 +1260,7 @@ def _publish_derived_asset(
1249
1260
  raise ValueError("'derived_item_id' must be a non-empty string.")
1250
1261
  if not isinstance(asset_key, str) or not asset_key.strip():
1251
1262
  raise ValueError("'asset_key' must be a non-empty string.")
1263
+ storage_name = storage_name or storage_for_asset(asset_key.strip())
1252
1264
 
1253
1265
  src = Path(asset_path).expanduser().resolve()
1254
1266
  if not src.is_file():
@@ -1275,9 +1287,7 @@ def _publish_derived_asset(
1275
1287
  if overwrite:
1276
1288
  for attached_name in _attached_file_names(derived_item_id.strip(), scope):
1277
1289
  if attached_name != file_name and attached_name.startswith(f"{derived_item_id.strip()}_{asset_key.strip()}."):
1278
- _replacement_delete_plan(
1279
- scope=scope, file_name=attached_name, item_id=derived_item_id.strip(), storage_name=storage_name,
1280
- )
1290
+ _replacement_delete_plan(scope=scope, file_name=attached_name, item_id=derived_item_id.strip())
1281
1291
  stale_identity = _catalog_file_identity(attached_name, scope=scope)
1282
1292
  if stale_identity.get("exists") is not True or stale_identity.get("type") != "FILE":
1283
1293
  raise RuntimeError(f"Stale asset '{scope}:{attached_name}' is not a readable FILE DID.")
@@ -1299,7 +1309,6 @@ def _publish_derived_asset(
1299
1309
  item_id=derived_item_id.strip(),
1300
1310
  file_name=file_name,
1301
1311
  expected_identity=previous_catalog_identity,
1302
- storage_name=storage_name,
1303
1312
  )
1304
1313
  catalog_before = replacement_cleanup["catalog_after_delete"]
1305
1314
  else:
@@ -1416,7 +1425,6 @@ def _publish_derived_asset(
1416
1425
  item_id=derived_item_id.strip(),
1417
1426
  file_name=stale_file,
1418
1427
  expected_identity=stale_identity,
1419
- storage_name=storage_name,
1420
1428
  )
1421
1429
  pruned_files.append({
1422
1430
  "file_name": stale_file,
@@ -1547,7 +1555,7 @@ def download_item_asset(
1547
1555
  *,
1548
1556
  scope: str = DEFAULT_SCOPE,
1549
1557
  destination_dir: str | Path = ".",
1550
- storage_name: str = DEFAULT_STORAGE,
1558
+ storage_name: str | None = None,
1551
1559
  overwrite: bool = False,
1552
1560
  timeout: int = 120,
1553
1561
  verify_tls: bool = True,
@@ -1563,7 +1571,7 @@ def download_item_asset(
1563
1571
  asset_key: Asset key in ``assets``.
1564
1572
  scope: Scope used to resolve metadata and file DIDs.
1565
1573
  destination_dir: Target directory for downloaded content.
1566
- storage_name: Storage endpoint whose LAN file PFN is copied when readable.
1574
+ storage_name: RSE whose LAN file PFN is copied when readable, by default the one that holds the file's replica.
1567
1575
  overwrite: Allow replacing existing local files.
1568
1576
  timeout: Request timeout for URL-based downloads.
1569
1577
  verify_tls: Enable/disable TLS verification for URL-based downloads.
@@ -1611,10 +1619,11 @@ def download_item_asset(
1611
1619
  posix_pfn: str | None = None
1612
1620
  posix_error: str | None = None
1613
1621
  if resolved_file_name:
1622
+ local_storages = [storage_name] if storage_name else _storage_names_for_file(scope=scope, file_name=resolved_file_name)[0]
1614
1623
  posix_path, posix_pfn, posix_error = _local_posix_asset_path(
1615
1624
  scope=scope,
1616
1625
  file_name=resolved_file_name,
1617
- storage_name=storage_name,
1626
+ storage_name=local_storages[0] if local_storages else HOME_STORAGE,
1618
1627
  )
1619
1628
  if posix_path is not None:
1620
1629
  try:
@@ -1692,7 +1701,7 @@ def download_all_derived_item_assets(
1692
1701
  *,
1693
1702
  scope: str = DEFAULT_SCOPE,
1694
1703
  destination_dir: str | Path = ".",
1695
- storage_name: str = DEFAULT_STORAGE,
1704
+ storage_name: str | None = None,
1696
1705
  overwrite: bool = False,
1697
1706
  timeout: int = 120,
1698
1707
  verify_tls: bool = True,
@@ -1706,7 +1715,7 @@ def download_all_derived_item_assets(
1706
1715
  item_id: Derived item identifier.
1707
1716
  scope: Scope used to resolve metadata and file DIDs.
1708
1717
  destination_dir: Target directory for downloaded files.
1709
- storage_name: Storage endpoint whose LAN file PFNs are copied when readable.
1718
+ storage_name: RSE whose LAN file PFNs are copied when readable, by default the one that holds each file's replica.
1710
1719
  overwrite: Allow replacing existing local files.
1711
1720
  timeout: Request timeout for URL-based downloads.
1712
1721
  verify_tls: Enable/disable TLS verification for URL-based downloads.
@@ -18,13 +18,14 @@ from dafab_client.helpers.file_management.signing import signing_service
18
18
  from dafab_client.helpers.file_management.Workflows.manage_derived_assets import (
19
19
  DEFAULT_SCOPE,
20
20
  DEFAULT_STAC_ROOT,
21
- DEFAULT_STORAGE,
22
21
  _asset_pointer,
23
22
  _attached_file_names,
24
23
  _delete_existing_asset_file,
25
24
  _ensure_file_attached_to_item,
25
+ _replica_storage,
26
26
  _upload_via_signed_write_url,
27
27
  build_stable_asset_href,
28
+ storage_for_asset,
28
29
  )
29
30
  from dafab_client.helpers.file_management.Workflows.preview_bundle import BUNDLE_KEY, THUMBNAIL_KEY
30
31
  from dafab_client.helpers.metadata_management.Patch.patch_metadata_for_dids import patch_metadata_for_dids
@@ -187,6 +188,11 @@ def _storage_object_probe_with_retries(
187
188
  return probe
188
189
 
189
190
 
191
+ def _probe_storage(file_name: str, *, scope: str, storage_name: str) -> str:
192
+ """The RSE on which to probe a file: the one that holds its replica, preferring the given RSE, else the given RSE."""
193
+ return _replica_storage(scope=scope, file_name=file_name, preferred=storage_name) or storage_name
194
+
195
+
190
196
  def _extract_server_asset_entry(item_id: str, asset_key: str, *, scope: str) -> dict[str, Any] | None:
191
197
  pointer = _asset_pointer(asset_key)
192
198
  partial = get_bulk_metadata(item_id, scope=scope, paths=[pointer])
@@ -239,7 +245,7 @@ def validate_original_asset_publication(
239
245
  asset_key: str,
240
246
  *,
241
247
  scope: str = DEFAULT_SCOPE,
242
- storage_name: str = DEFAULT_STORAGE,
248
+ storage_name: str | None = None,
243
249
  stac_root_href: str = DEFAULT_STAC_ROOT,
244
250
  ) -> dict[str, Any]:
245
251
  """Validate catalog, storage, attachment, and metadata state for one original asset."""
@@ -257,7 +263,7 @@ def _validate_original_asset_publication(
257
263
  asset_key: str,
258
264
  *,
259
265
  scope: str = DEFAULT_SCOPE,
260
- storage_name: str = DEFAULT_STORAGE,
266
+ storage_name: str | None = None,
261
267
  stac_root_href: str = DEFAULT_STAC_ROOT,
262
268
  ) -> dict[str, Any]:
263
269
  """Run after the caller validates the Item and its exclusive assets dataset."""
@@ -267,7 +273,10 @@ def _validate_original_asset_publication(
267
273
  catalog = _catalog_file_identity(file_name, scope=scope)
268
274
  catalog_matches_local = _identity_matches(local, catalog)
269
275
  storage_probe = (
270
- _storage_object_probe_with_retries(file_name, scope=scope, storage_name=storage_name)
276
+ _storage_object_probe_with_retries(
277
+ file_name, scope=scope,
278
+ storage_name=_probe_storage(file_name, scope=scope, storage_name=storage_name or storage_for_asset(asset_key)),
279
+ )
271
280
  if catalog_matches_local
272
281
  else None
273
282
  )
@@ -296,7 +305,7 @@ def publish_original_asset(
296
305
  asset_key: str,
297
306
  *,
298
307
  scope: str = DEFAULT_SCOPE,
299
- storage_name: str = DEFAULT_STORAGE,
308
+ storage_name: str | None = None,
300
309
  stac_root_href: str = DEFAULT_STAC_ROOT,
301
310
  ) -> dict[str, Any]:
302
311
  """Publish one staged original item asset and upsert its stable DaFab href."""
@@ -314,10 +323,11 @@ def _publish_original_asset(
314
323
  asset_key: str,
315
324
  *,
316
325
  scope: str = DEFAULT_SCOPE,
317
- storage_name: str = DEFAULT_STORAGE,
326
+ storage_name: str | None = None,
318
327
  stac_root_href: str = DEFAULT_STAC_ROOT,
319
328
  ) -> dict[str, Any]:
320
329
  """Run after the caller validates the Item and its exclusive assets dataset."""
330
+ storage_name = storage_name or storage_for_asset(asset_key)
321
331
  src = Path(asset_path).expanduser().resolve()
322
332
  if not src.is_file():
323
333
  raise FileNotFoundError(f"Asset file not found: {src}")
@@ -335,7 +345,9 @@ def _publish_original_asset(
335
345
  if not _identity_matches(local, catalog):
336
346
  upload_needed = True
337
347
  else:
338
- storage_probe = _storage_object_probe_with_retries(file_name, scope=scope, storage_name=storage_name)
348
+ storage_probe = _storage_object_probe_with_retries(
349
+ file_name, scope=scope, storage_name=_probe_storage(file_name, scope=scope, storage_name=storage_name),
350
+ )
339
351
  if not storage_probe.get("ok"):
340
352
  if not storage_probe.get("missing"):
341
353
  raise RuntimeError(f"Could not verify storage object for '{scope}:{file_name}': {storage_probe}")
@@ -343,7 +355,7 @@ def _publish_original_asset(
343
355
  if upload_needed:
344
356
  cleanup_report = _delete_existing_asset_file(
345
357
  scope=scope, item_id=item_id, file_name=file_name,
346
- expected_identity=catalog, storage_name=storage_name,
358
+ expected_identity=catalog,
347
359
  )
348
360
  else:
349
361
  upload_needed = True
@@ -368,7 +380,9 @@ def _publish_original_asset(
368
380
  catalog_after_upload = _catalog_file_identity(file_name, scope=scope)
369
381
  catalog_matches_local = _identity_matches(local, catalog_after_upload)
370
382
  storage_probe = (
371
- _storage_object_probe_with_retries(file_name, scope=scope, storage_name=storage_name)
383
+ _storage_object_probe_with_retries(
384
+ file_name, scope=scope, storage_name=_probe_storage(file_name, scope=scope, storage_name=storage_name),
385
+ )
372
386
  if catalog_matches_local
373
387
  else storage_probe
374
388
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dafab_client
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: Python client for the DaFab catalogue of Sentinel-2 imagery and AI-derived water and agriculture products, built on Rucio.
5
5
  Author: DaFab
6
6
  License-Expression: Apache-2.0
@@ -47,7 +47,7 @@ IMAGE=harbor.dafab-platform.eu/dafab/rucio:publisher-v3.0.0 \
47
47
 
48
48
  The script builds locally without pushing. Rebuilds retain `publisher-v3.0.0`. After publishing and validating the image, the platform maintainer pins its immutable digest.
49
49
 
50
- Each build runs without cached layers on the base image the Dockerfile pins by digest, and installs the client release the Dockerfile pins, `dafab-client[previews]==4.2.0`, from official PyPI. With `CLIENT_WHEEL` naming a built wheel of that release, it installs the wheel instead, for an image built before the release reaches PyPI. The two publisher step scripts come from this checkout. Change the pin with each client release the publisher should carry.
50
+ Each build runs without cached layers on the base image the Dockerfile pins by digest, and installs the client release the Dockerfile pins, `dafab-client[previews]==4.3.0`, from official PyPI. With `CLIENT_WHEEL` naming a built wheel of that release, it installs the wheel instead, for an image built before the release reaches PyPI. The two publisher step scripts come from this checkout. Change the pin with each client release the publisher should carry.
51
51
 
52
52
  The image also installs `libexpat1` from Debian, its only system package. The GDAL inside rasterio's wheel loads it and the slim base no longer carries it, so without it the publisher cannot render the original's previews. The build ends by loading the preview stack inside the new image and fails if it cannot.
53
53
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dafab_client"
7
- version = "4.2.0"
7
+ version = "4.3.0"
8
8
  description = "Python client for the DaFab catalogue of Sentinel-2 imagery and AI-derived water and agriculture products, built on Rucio."
9
9
  readme = "readme.md"
10
10
  requires-python = ">=3.10"
File without changes
File without changes
File without changes
File without changes