rucio 35.7.0__py3-none-any.whl

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 rucio might be problematic. Click here for more details.

Files changed (493) hide show
  1. rucio/__init__.py +17 -0
  2. rucio/alembicrevision.py +15 -0
  3. rucio/client/__init__.py +15 -0
  4. rucio/client/accountclient.py +433 -0
  5. rucio/client/accountlimitclient.py +183 -0
  6. rucio/client/baseclient.py +974 -0
  7. rucio/client/client.py +76 -0
  8. rucio/client/configclient.py +126 -0
  9. rucio/client/credentialclient.py +59 -0
  10. rucio/client/didclient.py +866 -0
  11. rucio/client/diracclient.py +56 -0
  12. rucio/client/downloadclient.py +1785 -0
  13. rucio/client/exportclient.py +44 -0
  14. rucio/client/fileclient.py +50 -0
  15. rucio/client/importclient.py +42 -0
  16. rucio/client/lifetimeclient.py +90 -0
  17. rucio/client/lockclient.py +109 -0
  18. rucio/client/metaconventionsclient.py +140 -0
  19. rucio/client/pingclient.py +44 -0
  20. rucio/client/replicaclient.py +454 -0
  21. rucio/client/requestclient.py +125 -0
  22. rucio/client/rseclient.py +746 -0
  23. rucio/client/ruleclient.py +294 -0
  24. rucio/client/scopeclient.py +90 -0
  25. rucio/client/subscriptionclient.py +173 -0
  26. rucio/client/touchclient.py +82 -0
  27. rucio/client/uploadclient.py +955 -0
  28. rucio/common/__init__.py +13 -0
  29. rucio/common/cache.py +74 -0
  30. rucio/common/config.py +801 -0
  31. rucio/common/constants.py +159 -0
  32. rucio/common/constraints.py +17 -0
  33. rucio/common/didtype.py +189 -0
  34. rucio/common/dumper/__init__.py +335 -0
  35. rucio/common/dumper/consistency.py +452 -0
  36. rucio/common/dumper/data_models.py +318 -0
  37. rucio/common/dumper/path_parsing.py +64 -0
  38. rucio/common/exception.py +1151 -0
  39. rucio/common/extra.py +36 -0
  40. rucio/common/logging.py +420 -0
  41. rucio/common/pcache.py +1408 -0
  42. rucio/common/plugins.py +153 -0
  43. rucio/common/policy.py +84 -0
  44. rucio/common/schema/__init__.py +150 -0
  45. rucio/common/schema/atlas.py +413 -0
  46. rucio/common/schema/belleii.py +408 -0
  47. rucio/common/schema/domatpc.py +401 -0
  48. rucio/common/schema/escape.py +426 -0
  49. rucio/common/schema/generic.py +433 -0
  50. rucio/common/schema/generic_multi_vo.py +412 -0
  51. rucio/common/schema/icecube.py +406 -0
  52. rucio/common/stomp_utils.py +159 -0
  53. rucio/common/stopwatch.py +55 -0
  54. rucio/common/test_rucio_server.py +148 -0
  55. rucio/common/types.py +403 -0
  56. rucio/common/utils.py +2238 -0
  57. rucio/core/__init__.py +13 -0
  58. rucio/core/account.py +496 -0
  59. rucio/core/account_counter.py +236 -0
  60. rucio/core/account_limit.py +423 -0
  61. rucio/core/authentication.py +620 -0
  62. rucio/core/config.py +456 -0
  63. rucio/core/credential.py +225 -0
  64. rucio/core/did.py +3000 -0
  65. rucio/core/did_meta_plugins/__init__.py +252 -0
  66. rucio/core/did_meta_plugins/did_column_meta.py +331 -0
  67. rucio/core/did_meta_plugins/did_meta_plugin_interface.py +165 -0
  68. rucio/core/did_meta_plugins/filter_engine.py +613 -0
  69. rucio/core/did_meta_plugins/json_meta.py +240 -0
  70. rucio/core/did_meta_plugins/mongo_meta.py +216 -0
  71. rucio/core/did_meta_plugins/postgres_meta.py +316 -0
  72. rucio/core/dirac.py +237 -0
  73. rucio/core/distance.py +187 -0
  74. rucio/core/exporter.py +59 -0
  75. rucio/core/heartbeat.py +363 -0
  76. rucio/core/identity.py +300 -0
  77. rucio/core/importer.py +259 -0
  78. rucio/core/lifetime_exception.py +377 -0
  79. rucio/core/lock.py +576 -0
  80. rucio/core/message.py +282 -0
  81. rucio/core/meta_conventions.py +203 -0
  82. rucio/core/monitor.py +447 -0
  83. rucio/core/naming_convention.py +195 -0
  84. rucio/core/nongrid_trace.py +136 -0
  85. rucio/core/oidc.py +1461 -0
  86. rucio/core/permission/__init__.py +119 -0
  87. rucio/core/permission/atlas.py +1348 -0
  88. rucio/core/permission/belleii.py +1077 -0
  89. rucio/core/permission/escape.py +1078 -0
  90. rucio/core/permission/generic.py +1130 -0
  91. rucio/core/permission/generic_multi_vo.py +1150 -0
  92. rucio/core/quarantined_replica.py +223 -0
  93. rucio/core/replica.py +4158 -0
  94. rucio/core/replica_sorter.py +366 -0
  95. rucio/core/request.py +3089 -0
  96. rucio/core/rse.py +1875 -0
  97. rucio/core/rse_counter.py +186 -0
  98. rucio/core/rse_expression_parser.py +459 -0
  99. rucio/core/rse_selector.py +302 -0
  100. rucio/core/rule.py +4483 -0
  101. rucio/core/rule_grouping.py +1618 -0
  102. rucio/core/scope.py +180 -0
  103. rucio/core/subscription.py +364 -0
  104. rucio/core/topology.py +490 -0
  105. rucio/core/trace.py +375 -0
  106. rucio/core/transfer.py +1517 -0
  107. rucio/core/vo.py +169 -0
  108. rucio/core/volatile_replica.py +150 -0
  109. rucio/daemons/__init__.py +13 -0
  110. rucio/daemons/abacus/__init__.py +13 -0
  111. rucio/daemons/abacus/account.py +116 -0
  112. rucio/daemons/abacus/collection_replica.py +124 -0
  113. rucio/daemons/abacus/rse.py +117 -0
  114. rucio/daemons/atropos/__init__.py +13 -0
  115. rucio/daemons/atropos/atropos.py +242 -0
  116. rucio/daemons/auditor/__init__.py +289 -0
  117. rucio/daemons/auditor/hdfs.py +97 -0
  118. rucio/daemons/auditor/srmdumps.py +355 -0
  119. rucio/daemons/automatix/__init__.py +13 -0
  120. rucio/daemons/automatix/automatix.py +293 -0
  121. rucio/daemons/badreplicas/__init__.py +13 -0
  122. rucio/daemons/badreplicas/minos.py +322 -0
  123. rucio/daemons/badreplicas/minos_temporary_expiration.py +171 -0
  124. rucio/daemons/badreplicas/necromancer.py +196 -0
  125. rucio/daemons/bb8/__init__.py +13 -0
  126. rucio/daemons/bb8/bb8.py +353 -0
  127. rucio/daemons/bb8/common.py +759 -0
  128. rucio/daemons/bb8/nuclei_background_rebalance.py +153 -0
  129. rucio/daemons/bb8/t2_background_rebalance.py +153 -0
  130. rucio/daemons/c3po/__init__.py +13 -0
  131. rucio/daemons/c3po/algorithms/__init__.py +13 -0
  132. rucio/daemons/c3po/algorithms/simple.py +134 -0
  133. rucio/daemons/c3po/algorithms/t2_free_space.py +128 -0
  134. rucio/daemons/c3po/algorithms/t2_free_space_only_pop.py +130 -0
  135. rucio/daemons/c3po/algorithms/t2_free_space_only_pop_with_network.py +294 -0
  136. rucio/daemons/c3po/c3po.py +371 -0
  137. rucio/daemons/c3po/collectors/__init__.py +13 -0
  138. rucio/daemons/c3po/collectors/agis.py +108 -0
  139. rucio/daemons/c3po/collectors/free_space.py +81 -0
  140. rucio/daemons/c3po/collectors/jedi_did.py +57 -0
  141. rucio/daemons/c3po/collectors/mock_did.py +51 -0
  142. rucio/daemons/c3po/collectors/network_metrics.py +71 -0
  143. rucio/daemons/c3po/collectors/workload.py +112 -0
  144. rucio/daemons/c3po/utils/__init__.py +13 -0
  145. rucio/daemons/c3po/utils/dataset_cache.py +50 -0
  146. rucio/daemons/c3po/utils/expiring_dataset_cache.py +56 -0
  147. rucio/daemons/c3po/utils/expiring_list.py +62 -0
  148. rucio/daemons/c3po/utils/popularity.py +85 -0
  149. rucio/daemons/c3po/utils/timeseries.py +89 -0
  150. rucio/daemons/cache/__init__.py +13 -0
  151. rucio/daemons/cache/consumer.py +197 -0
  152. rucio/daemons/common.py +415 -0
  153. rucio/daemons/conveyor/__init__.py +13 -0
  154. rucio/daemons/conveyor/common.py +562 -0
  155. rucio/daemons/conveyor/finisher.py +529 -0
  156. rucio/daemons/conveyor/poller.py +404 -0
  157. rucio/daemons/conveyor/preparer.py +205 -0
  158. rucio/daemons/conveyor/receiver.py +249 -0
  159. rucio/daemons/conveyor/stager.py +132 -0
  160. rucio/daemons/conveyor/submitter.py +403 -0
  161. rucio/daemons/conveyor/throttler.py +532 -0
  162. rucio/daemons/follower/__init__.py +13 -0
  163. rucio/daemons/follower/follower.py +101 -0
  164. rucio/daemons/hermes/__init__.py +13 -0
  165. rucio/daemons/hermes/hermes.py +774 -0
  166. rucio/daemons/judge/__init__.py +13 -0
  167. rucio/daemons/judge/cleaner.py +159 -0
  168. rucio/daemons/judge/evaluator.py +185 -0
  169. rucio/daemons/judge/injector.py +162 -0
  170. rucio/daemons/judge/repairer.py +154 -0
  171. rucio/daemons/oauthmanager/__init__.py +13 -0
  172. rucio/daemons/oauthmanager/oauthmanager.py +198 -0
  173. rucio/daemons/reaper/__init__.py +13 -0
  174. rucio/daemons/reaper/dark_reaper.py +278 -0
  175. rucio/daemons/reaper/reaper.py +743 -0
  176. rucio/daemons/replicarecoverer/__init__.py +13 -0
  177. rucio/daemons/replicarecoverer/suspicious_replica_recoverer.py +626 -0
  178. rucio/daemons/rsedecommissioner/__init__.py +13 -0
  179. rucio/daemons/rsedecommissioner/config.py +81 -0
  180. rucio/daemons/rsedecommissioner/profiles/__init__.py +24 -0
  181. rucio/daemons/rsedecommissioner/profiles/atlas.py +60 -0
  182. rucio/daemons/rsedecommissioner/profiles/generic.py +451 -0
  183. rucio/daemons/rsedecommissioner/profiles/types.py +92 -0
  184. rucio/daemons/rsedecommissioner/rse_decommissioner.py +280 -0
  185. rucio/daemons/storage/__init__.py +13 -0
  186. rucio/daemons/storage/consistency/__init__.py +13 -0
  187. rucio/daemons/storage/consistency/actions.py +846 -0
  188. rucio/daemons/tracer/__init__.py +13 -0
  189. rucio/daemons/tracer/kronos.py +536 -0
  190. rucio/daemons/transmogrifier/__init__.py +13 -0
  191. rucio/daemons/transmogrifier/transmogrifier.py +762 -0
  192. rucio/daemons/undertaker/__init__.py +13 -0
  193. rucio/daemons/undertaker/undertaker.py +137 -0
  194. rucio/db/__init__.py +13 -0
  195. rucio/db/sqla/__init__.py +52 -0
  196. rucio/db/sqla/constants.py +201 -0
  197. rucio/db/sqla/migrate_repo/__init__.py +13 -0
  198. rucio/db/sqla/migrate_repo/env.py +110 -0
  199. rucio/db/sqla/migrate_repo/versions/01eaf73ab656_add_new_rule_notification_state_progress.py +70 -0
  200. rucio/db/sqla/migrate_repo/versions/0437a40dbfd1_add_eol_at_in_rules.py +47 -0
  201. rucio/db/sqla/migrate_repo/versions/0f1adb7a599a_create_transfer_hops_table.py +59 -0
  202. rucio/db/sqla/migrate_repo/versions/102efcf145f4_added_stuck_at_column_to_rules.py +43 -0
  203. rucio/db/sqla/migrate_repo/versions/13d4f70c66a9_introduce_transfer_limits.py +91 -0
  204. rucio/db/sqla/migrate_repo/versions/140fef722e91_cleanup_distances_table.py +76 -0
  205. rucio/db/sqla/migrate_repo/versions/14ec5aeb64cf_add_request_external_host.py +43 -0
  206. rucio/db/sqla/migrate_repo/versions/156fb5b5a14_add_request_type_to_requests_idx.py +50 -0
  207. rucio/db/sqla/migrate_repo/versions/1677d4d803c8_split_rse_availability_into_multiple.py +68 -0
  208. rucio/db/sqla/migrate_repo/versions/16a0aca82e12_create_index_on_table_replicas_path.py +40 -0
  209. rucio/db/sqla/migrate_repo/versions/1803333ac20f_adding_provenance_and_phys_group.py +45 -0
  210. rucio/db/sqla/migrate_repo/versions/1a29d6a9504c_add_didtype_chck_to_requests.py +60 -0
  211. rucio/db/sqla/migrate_repo/versions/1a80adff031a_create_index_on_rules_hist_recent.py +40 -0
  212. rucio/db/sqla/migrate_repo/versions/1c45d9730ca6_increase_identity_length.py +140 -0
  213. rucio/db/sqla/migrate_repo/versions/1d1215494e95_add_quarantined_replicas_table.py +73 -0
  214. rucio/db/sqla/migrate_repo/versions/1d96f484df21_asynchronous_rules_and_rule_approval.py +74 -0
  215. rucio/db/sqla/migrate_repo/versions/1f46c5f240ac_add_bytes_column_to_bad_replicas.py +43 -0
  216. rucio/db/sqla/migrate_repo/versions/1fc15ab60d43_add_message_history_table.py +50 -0
  217. rucio/db/sqla/migrate_repo/versions/2190e703eb6e_move_rse_settings_to_rse_attributes.py +134 -0
  218. rucio/db/sqla/migrate_repo/versions/21d6b9dc9961_add_mismatch_scheme_state_to_requests.py +64 -0
  219. rucio/db/sqla/migrate_repo/versions/22cf51430c78_add_availability_column_to_table_rses.py +39 -0
  220. rucio/db/sqla/migrate_repo/versions/22d887e4ec0a_create_sources_table.py +64 -0
  221. rucio/db/sqla/migrate_repo/versions/25821a8a45a3_remove_unique_constraint_on_requests.py +51 -0
  222. rucio/db/sqla/migrate_repo/versions/25fc855625cf_added_unique_constraint_to_rules.py +41 -0
  223. rucio/db/sqla/migrate_repo/versions/269fee20dee9_add_repair_cnt_to_locks.py +43 -0
  224. rucio/db/sqla/migrate_repo/versions/271a46ea6244_add_ignore_availability_column_to_rules.py +44 -0
  225. rucio/db/sqla/migrate_repo/versions/277b5fbb41d3_switch_heartbeats_executable.py +53 -0
  226. rucio/db/sqla/migrate_repo/versions/27e3a68927fb_remove_replicas_tombstone_and_replicas_.py +38 -0
  227. rucio/db/sqla/migrate_repo/versions/2854cd9e168_added_rule_id_column.py +47 -0
  228. rucio/db/sqla/migrate_repo/versions/295289b5a800_processed_by_and__at_in_requests.py +45 -0
  229. rucio/db/sqla/migrate_repo/versions/2962ece31cf4_add_nbaccesses_column_in_the_did_table.py +45 -0
  230. rucio/db/sqla/migrate_repo/versions/2af3291ec4c_added_replicas_history_table.py +57 -0
  231. rucio/db/sqla/migrate_repo/versions/2b69addda658_add_columns_for_third_party_copy_read_.py +45 -0
  232. rucio/db/sqla/migrate_repo/versions/2b8e7bcb4783_add_config_table.py +69 -0
  233. rucio/db/sqla/migrate_repo/versions/2ba5229cb54c_add_submitted_at_to_requests_table.py +43 -0
  234. rucio/db/sqla/migrate_repo/versions/2cbee484dcf9_added_column_volume_to_rse_transfer_.py +42 -0
  235. rucio/db/sqla/migrate_repo/versions/2edee4a83846_add_source_to_requests_and_requests_.py +47 -0
  236. rucio/db/sqla/migrate_repo/versions/2eef46be23d4_change_tokens_pk.py +46 -0
  237. rucio/db/sqla/migrate_repo/versions/2f648fc909f3_index_in_rule_history_on_scope_name.py +40 -0
  238. rucio/db/sqla/migrate_repo/versions/3082b8cef557_add_naming_convention_table_and_closed_.py +67 -0
  239. rucio/db/sqla/migrate_repo/versions/30fa38b6434e_add_index_on_service_column_in_the_message_table.py +44 -0
  240. rucio/db/sqla/migrate_repo/versions/3152492b110b_added_staging_area_column.py +77 -0
  241. rucio/db/sqla/migrate_repo/versions/32c7d2783f7e_create_bad_replicas_table.py +60 -0
  242. rucio/db/sqla/migrate_repo/versions/3345511706b8_replicas_table_pk_definition_is_in_.py +72 -0
  243. rucio/db/sqla/migrate_repo/versions/35ef10d1e11b_change_index_on_table_requests.py +42 -0
  244. rucio/db/sqla/migrate_repo/versions/379a19b5332d_create_rse_limits_table.py +65 -0
  245. rucio/db/sqla/migrate_repo/versions/384b96aa0f60_created_rule_history_tables.py +133 -0
  246. rucio/db/sqla/migrate_repo/versions/3ac1660a1a72_extend_distance_table.py +55 -0
  247. rucio/db/sqla/migrate_repo/versions/3ad36e2268b0_create_collection_replicas_updates_table.py +76 -0
  248. rucio/db/sqla/migrate_repo/versions/3c9df354071b_extend_waiting_request_state.py +60 -0
  249. rucio/db/sqla/migrate_repo/versions/3d9813fab443_add_a_new_state_lost_in_badfilesstatus.py +44 -0
  250. rucio/db/sqla/migrate_repo/versions/40ad39ce3160_add_transferred_at_to_requests_table.py +43 -0
  251. rucio/db/sqla/migrate_repo/versions/4207be2fd914_add_notification_column_to_rules.py +64 -0
  252. rucio/db/sqla/migrate_repo/versions/42db2617c364_create_index_on_requests_external_id.py +40 -0
  253. rucio/db/sqla/migrate_repo/versions/436827b13f82_added_column_activity_to_table_requests.py +43 -0
  254. rucio/db/sqla/migrate_repo/versions/44278720f774_update_requests_typ_sta_upd_idx_index.py +44 -0
  255. rucio/db/sqla/migrate_repo/versions/45378a1e76a8_create_collection_replica_table.py +78 -0
  256. rucio/db/sqla/migrate_repo/versions/469d262be19_removing_created_at_index.py +41 -0
  257. rucio/db/sqla/migrate_repo/versions/4783c1f49cb4_create_distance_table.py +59 -0
  258. rucio/db/sqla/migrate_repo/versions/49a21b4d4357_create_index_on_table_tokens.py +44 -0
  259. rucio/db/sqla/migrate_repo/versions/4a2cbedda8b9_add_source_replica_expression_column_to_.py +43 -0
  260. rucio/db/sqla/migrate_repo/versions/4a7182d9578b_added_bytes_length_accessed_at_columns.py +49 -0
  261. rucio/db/sqla/migrate_repo/versions/4bab9edd01fc_create_index_on_requests_rule_id.py +40 -0
  262. rucio/db/sqla/migrate_repo/versions/4c3a4acfe006_new_attr_account_table.py +63 -0
  263. rucio/db/sqla/migrate_repo/versions/4cf0a2e127d4_adding_transient_metadata.py +43 -0
  264. rucio/db/sqla/migrate_repo/versions/4df2c5ddabc0_remove_temporary_dids.py +55 -0
  265. rucio/db/sqla/migrate_repo/versions/50280c53117c_add_qos_class_to_rse.py +45 -0
  266. rucio/db/sqla/migrate_repo/versions/52153819589c_add_rse_id_to_replicas_table.py +43 -0
  267. rucio/db/sqla/migrate_repo/versions/52fd9f4916fa_added_activity_to_rules.py +43 -0
  268. rucio/db/sqla/migrate_repo/versions/53b479c3cb0f_fix_did_meta_table_missing_updated_at_.py +45 -0
  269. rucio/db/sqla/migrate_repo/versions/5673b4b6e843_add_wfms_metadata_to_rule_tables.py +47 -0
  270. rucio/db/sqla/migrate_repo/versions/575767d9f89_added_source_history_table.py +58 -0
  271. rucio/db/sqla/migrate_repo/versions/58bff7008037_add_started_at_to_requests.py +45 -0
  272. rucio/db/sqla/migrate_repo/versions/58c8b78301ab_rename_callback_to_message.py +106 -0
  273. rucio/db/sqla/migrate_repo/versions/5f139f77382a_added_child_rule_id_column.py +55 -0
  274. rucio/db/sqla/migrate_repo/versions/688ef1840840_adding_did_meta_table.py +50 -0
  275. rucio/db/sqla/migrate_repo/versions/6e572a9bfbf3_add_new_split_container_column_to_rules.py +47 -0
  276. rucio/db/sqla/migrate_repo/versions/70587619328_add_comment_column_for_subscriptions.py +43 -0
  277. rucio/db/sqla/migrate_repo/versions/739064d31565_remove_history_table_pks.py +41 -0
  278. rucio/db/sqla/migrate_repo/versions/7541902bf173_add_didsfollowed_and_followevents_table.py +91 -0
  279. rucio/db/sqla/migrate_repo/versions/7ec22226cdbf_new_replica_state_for_temporary_.py +72 -0
  280. rucio/db/sqla/migrate_repo/versions/810a41685bc1_added_columns_rse_transfer_limits.py +49 -0
  281. rucio/db/sqla/migrate_repo/versions/83f991c63a93_correct_rse_expression_length.py +43 -0
  282. rucio/db/sqla/migrate_repo/versions/8523998e2e76_increase_size_of_extended_attributes_.py +43 -0
  283. rucio/db/sqla/migrate_repo/versions/8ea9122275b1_adding_missing_function_based_indices.py +53 -0
  284. rucio/db/sqla/migrate_repo/versions/90f47792bb76_add_clob_payload_to_messages.py +45 -0
  285. rucio/db/sqla/migrate_repo/versions/914b8f02df38_new_table_for_lifetime_model_exceptions.py +68 -0
  286. rucio/db/sqla/migrate_repo/versions/94a5961ddbf2_add_estimator_columns.py +45 -0
  287. rucio/db/sqla/migrate_repo/versions/9a1b149a2044_add_saml_identity_type.py +94 -0
  288. rucio/db/sqla/migrate_repo/versions/9a45bc4ea66d_add_vp_table.py +54 -0
  289. rucio/db/sqla/migrate_repo/versions/9eb936a81eb1_true_is_true.py +72 -0
  290. rucio/db/sqla/migrate_repo/versions/a08fa8de1545_transfer_stats_table.py +55 -0
  291. rucio/db/sqla/migrate_repo/versions/a118956323f8_added_vo_table_and_vo_col_to_rse.py +76 -0
  292. rucio/db/sqla/migrate_repo/versions/a193a275255c_add_status_column_in_messages.py +47 -0
  293. rucio/db/sqla/migrate_repo/versions/a5f6f6e928a7_1_7_0.py +121 -0
  294. rucio/db/sqla/migrate_repo/versions/a616581ee47_added_columns_to_table_requests.py +59 -0
  295. rucio/db/sqla/migrate_repo/versions/a6eb23955c28_state_idx_non_functional.py +52 -0
  296. rucio/db/sqla/migrate_repo/versions/a74275a1ad30_added_global_quota_table.py +54 -0
  297. rucio/db/sqla/migrate_repo/versions/a93e4e47bda_heartbeats.py +64 -0
  298. rucio/db/sqla/migrate_repo/versions/ae2a56fcc89_added_comment_column_to_rules.py +49 -0
  299. rucio/db/sqla/migrate_repo/versions/b0070f3695c8_add_deletedidmeta_table.py +57 -0
  300. rucio/db/sqla/migrate_repo/versions/b4293a99f344_added_column_identity_to_table_tokens.py +43 -0
  301. rucio/db/sqla/migrate_repo/versions/b5493606bbf5_fix_primary_key_for_subscription_history.py +41 -0
  302. rucio/db/sqla/migrate_repo/versions/b7d287de34fd_removal_of_replicastate_source.py +91 -0
  303. rucio/db/sqla/migrate_repo/versions/b818052fa670_add_index_to_quarantined_replicas.py +40 -0
  304. rucio/db/sqla/migrate_repo/versions/b8caac94d7f0_add_comments_column_for_subscriptions_.py +43 -0
  305. rucio/db/sqla/migrate_repo/versions/b96a1c7e1cc4_new_bad_pfns_table_and_bad_replicas_.py +143 -0
  306. rucio/db/sqla/migrate_repo/versions/bb695f45c04_extend_request_state.py +76 -0
  307. rucio/db/sqla/migrate_repo/versions/bc68e9946deb_add_staging_timestamps_to_request.py +50 -0
  308. rucio/db/sqla/migrate_repo/versions/bf3baa1c1474_correct_pk_and_idx_for_history_tables.py +72 -0
  309. rucio/db/sqla/migrate_repo/versions/c0937668555f_add_qos_policy_map_table.py +55 -0
  310. rucio/db/sqla/migrate_repo/versions/c129ccdb2d5_add_lumiblocknr_to_dids.py +43 -0
  311. rucio/db/sqla/migrate_repo/versions/ccdbcd48206e_add_did_type_column_index_on_did_meta_.py +65 -0
  312. rucio/db/sqla/migrate_repo/versions/cebad904c4dd_new_payload_column_for_heartbeats.py +47 -0
  313. rucio/db/sqla/migrate_repo/versions/d1189a09c6e0_oauth2_0_and_jwt_feature_support_adding_.py +146 -0
  314. rucio/db/sqla/migrate_repo/versions/d23453595260_extend_request_state_for_preparer.py +104 -0
  315. rucio/db/sqla/migrate_repo/versions/d6dceb1de2d_added_purge_column_to_rules.py +44 -0
  316. rucio/db/sqla/migrate_repo/versions/d6e2c3b2cf26_remove_third_party_copy_column_from_rse.py +43 -0
  317. rucio/db/sqla/migrate_repo/versions/d91002c5841_new_account_limits_table.py +103 -0
  318. rucio/db/sqla/migrate_repo/versions/e138c364ebd0_extending_columns_for_filter_and_.py +49 -0
  319. rucio/db/sqla/migrate_repo/versions/e59300c8b179_support_for_archive.py +104 -0
  320. rucio/db/sqla/migrate_repo/versions/f1b14a8c2ac1_postgres_use_check_constraints.py +29 -0
  321. rucio/db/sqla/migrate_repo/versions/f41ffe206f37_oracle_global_temporary_tables.py +74 -0
  322. rucio/db/sqla/migrate_repo/versions/f85a2962b021_adding_transfertool_column_to_requests_.py +47 -0
  323. rucio/db/sqla/migrate_repo/versions/fa7a7d78b602_increase_refresh_token_size.py +43 -0
  324. rucio/db/sqla/migrate_repo/versions/fb28a95fe288_add_replicas_rse_id_tombstone_idx.py +37 -0
  325. rucio/db/sqla/migrate_repo/versions/fe1a65b176c9_set_third_party_copy_read_and_write_.py +43 -0
  326. rucio/db/sqla/migrate_repo/versions/fe8ea2fa9788_added_third_party_copy_column_to_rse_.py +43 -0
  327. rucio/db/sqla/models.py +1740 -0
  328. rucio/db/sqla/sautils.py +55 -0
  329. rucio/db/sqla/session.py +498 -0
  330. rucio/db/sqla/types.py +206 -0
  331. rucio/db/sqla/util.py +543 -0
  332. rucio/gateway/__init__.py +13 -0
  333. rucio/gateway/account.py +339 -0
  334. rucio/gateway/account_limit.py +286 -0
  335. rucio/gateway/authentication.py +375 -0
  336. rucio/gateway/config.py +217 -0
  337. rucio/gateway/credential.py +71 -0
  338. rucio/gateway/did.py +970 -0
  339. rucio/gateway/dirac.py +81 -0
  340. rucio/gateway/exporter.py +59 -0
  341. rucio/gateway/heartbeat.py +74 -0
  342. rucio/gateway/identity.py +204 -0
  343. rucio/gateway/importer.py +45 -0
  344. rucio/gateway/lifetime_exception.py +120 -0
  345. rucio/gateway/lock.py +153 -0
  346. rucio/gateway/meta_conventions.py +87 -0
  347. rucio/gateway/permission.py +71 -0
  348. rucio/gateway/quarantined_replica.py +78 -0
  349. rucio/gateway/replica.py +529 -0
  350. rucio/gateway/request.py +321 -0
  351. rucio/gateway/rse.py +600 -0
  352. rucio/gateway/rule.py +417 -0
  353. rucio/gateway/scope.py +99 -0
  354. rucio/gateway/subscription.py +277 -0
  355. rucio/gateway/vo.py +122 -0
  356. rucio/rse/__init__.py +96 -0
  357. rucio/rse/protocols/__init__.py +13 -0
  358. rucio/rse/protocols/bittorrent.py +184 -0
  359. rucio/rse/protocols/cache.py +122 -0
  360. rucio/rse/protocols/dummy.py +111 -0
  361. rucio/rse/protocols/gfal.py +703 -0
  362. rucio/rse/protocols/globus.py +243 -0
  363. rucio/rse/protocols/gsiftp.py +92 -0
  364. rucio/rse/protocols/http_cache.py +82 -0
  365. rucio/rse/protocols/mock.py +123 -0
  366. rucio/rse/protocols/ngarc.py +209 -0
  367. rucio/rse/protocols/posix.py +250 -0
  368. rucio/rse/protocols/protocol.py +594 -0
  369. rucio/rse/protocols/rclone.py +364 -0
  370. rucio/rse/protocols/rfio.py +136 -0
  371. rucio/rse/protocols/srm.py +338 -0
  372. rucio/rse/protocols/ssh.py +413 -0
  373. rucio/rse/protocols/storm.py +206 -0
  374. rucio/rse/protocols/webdav.py +550 -0
  375. rucio/rse/protocols/xrootd.py +301 -0
  376. rucio/rse/rsemanager.py +764 -0
  377. rucio/tests/__init__.py +13 -0
  378. rucio/tests/common.py +270 -0
  379. rucio/tests/common_server.py +132 -0
  380. rucio/transfertool/__init__.py +13 -0
  381. rucio/transfertool/bittorrent.py +199 -0
  382. rucio/transfertool/bittorrent_driver.py +52 -0
  383. rucio/transfertool/bittorrent_driver_qbittorrent.py +133 -0
  384. rucio/transfertool/fts3.py +1596 -0
  385. rucio/transfertool/fts3_plugins.py +152 -0
  386. rucio/transfertool/globus.py +201 -0
  387. rucio/transfertool/globus_library.py +181 -0
  388. rucio/transfertool/mock.py +90 -0
  389. rucio/transfertool/transfertool.py +221 -0
  390. rucio/vcsversion.py +11 -0
  391. rucio/version.py +38 -0
  392. rucio/web/__init__.py +13 -0
  393. rucio/web/rest/__init__.py +13 -0
  394. rucio/web/rest/flaskapi/__init__.py +13 -0
  395. rucio/web/rest/flaskapi/authenticated_bp.py +27 -0
  396. rucio/web/rest/flaskapi/v1/__init__.py +13 -0
  397. rucio/web/rest/flaskapi/v1/accountlimits.py +236 -0
  398. rucio/web/rest/flaskapi/v1/accounts.py +1089 -0
  399. rucio/web/rest/flaskapi/v1/archives.py +102 -0
  400. rucio/web/rest/flaskapi/v1/auth.py +1644 -0
  401. rucio/web/rest/flaskapi/v1/common.py +426 -0
  402. rucio/web/rest/flaskapi/v1/config.py +304 -0
  403. rucio/web/rest/flaskapi/v1/credentials.py +212 -0
  404. rucio/web/rest/flaskapi/v1/dids.py +2334 -0
  405. rucio/web/rest/flaskapi/v1/dirac.py +116 -0
  406. rucio/web/rest/flaskapi/v1/export.py +75 -0
  407. rucio/web/rest/flaskapi/v1/heartbeats.py +127 -0
  408. rucio/web/rest/flaskapi/v1/identities.py +261 -0
  409. rucio/web/rest/flaskapi/v1/import.py +132 -0
  410. rucio/web/rest/flaskapi/v1/lifetime_exceptions.py +312 -0
  411. rucio/web/rest/flaskapi/v1/locks.py +358 -0
  412. rucio/web/rest/flaskapi/v1/main.py +91 -0
  413. rucio/web/rest/flaskapi/v1/meta_conventions.py +241 -0
  414. rucio/web/rest/flaskapi/v1/metrics.py +36 -0
  415. rucio/web/rest/flaskapi/v1/nongrid_traces.py +97 -0
  416. rucio/web/rest/flaskapi/v1/ping.py +88 -0
  417. rucio/web/rest/flaskapi/v1/redirect.py +365 -0
  418. rucio/web/rest/flaskapi/v1/replicas.py +1890 -0
  419. rucio/web/rest/flaskapi/v1/requests.py +998 -0
  420. rucio/web/rest/flaskapi/v1/rses.py +2239 -0
  421. rucio/web/rest/flaskapi/v1/rules.py +854 -0
  422. rucio/web/rest/flaskapi/v1/scopes.py +159 -0
  423. rucio/web/rest/flaskapi/v1/subscriptions.py +650 -0
  424. rucio/web/rest/flaskapi/v1/templates/auth_crash.html +80 -0
  425. rucio/web/rest/flaskapi/v1/templates/auth_granted.html +82 -0
  426. rucio/web/rest/flaskapi/v1/traces.py +100 -0
  427. rucio/web/rest/flaskapi/v1/types.py +20 -0
  428. rucio/web/rest/flaskapi/v1/vos.py +278 -0
  429. rucio/web/rest/main.py +18 -0
  430. rucio/web/rest/metrics.py +27 -0
  431. rucio/web/rest/ping.py +27 -0
  432. rucio-35.7.0.data/data/rucio/etc/alembic.ini.template +71 -0
  433. rucio-35.7.0.data/data/rucio/etc/alembic_offline.ini.template +74 -0
  434. rucio-35.7.0.data/data/rucio/etc/globus-config.yml.template +5 -0
  435. rucio-35.7.0.data/data/rucio/etc/ldap.cfg.template +30 -0
  436. rucio-35.7.0.data/data/rucio/etc/mail_templates/rule_approval_request.tmpl +38 -0
  437. rucio-35.7.0.data/data/rucio/etc/mail_templates/rule_approved_admin.tmpl +4 -0
  438. rucio-35.7.0.data/data/rucio/etc/mail_templates/rule_approved_user.tmpl +17 -0
  439. rucio-35.7.0.data/data/rucio/etc/mail_templates/rule_denied_admin.tmpl +6 -0
  440. rucio-35.7.0.data/data/rucio/etc/mail_templates/rule_denied_user.tmpl +17 -0
  441. rucio-35.7.0.data/data/rucio/etc/mail_templates/rule_ok_notification.tmpl +19 -0
  442. rucio-35.7.0.data/data/rucio/etc/rse-accounts.cfg.template +25 -0
  443. rucio-35.7.0.data/data/rucio/etc/rucio.cfg.atlas.client.template +42 -0
  444. rucio-35.7.0.data/data/rucio/etc/rucio.cfg.template +257 -0
  445. rucio-35.7.0.data/data/rucio/etc/rucio_multi_vo.cfg.template +234 -0
  446. rucio-35.7.0.data/data/rucio/requirements.server.txt +268 -0
  447. rucio-35.7.0.data/data/rucio/tools/bootstrap.py +34 -0
  448. rucio-35.7.0.data/data/rucio/tools/merge_rucio_configs.py +144 -0
  449. rucio-35.7.0.data/data/rucio/tools/reset_database.py +40 -0
  450. rucio-35.7.0.data/scripts/rucio +2542 -0
  451. rucio-35.7.0.data/scripts/rucio-abacus-account +74 -0
  452. rucio-35.7.0.data/scripts/rucio-abacus-collection-replica +46 -0
  453. rucio-35.7.0.data/scripts/rucio-abacus-rse +78 -0
  454. rucio-35.7.0.data/scripts/rucio-admin +2447 -0
  455. rucio-35.7.0.data/scripts/rucio-atropos +60 -0
  456. rucio-35.7.0.data/scripts/rucio-auditor +205 -0
  457. rucio-35.7.0.data/scripts/rucio-automatix +50 -0
  458. rucio-35.7.0.data/scripts/rucio-bb8 +57 -0
  459. rucio-35.7.0.data/scripts/rucio-c3po +85 -0
  460. rucio-35.7.0.data/scripts/rucio-cache-client +134 -0
  461. rucio-35.7.0.data/scripts/rucio-cache-consumer +42 -0
  462. rucio-35.7.0.data/scripts/rucio-conveyor-finisher +58 -0
  463. rucio-35.7.0.data/scripts/rucio-conveyor-poller +66 -0
  464. rucio-35.7.0.data/scripts/rucio-conveyor-preparer +37 -0
  465. rucio-35.7.0.data/scripts/rucio-conveyor-receiver +43 -0
  466. rucio-35.7.0.data/scripts/rucio-conveyor-stager +76 -0
  467. rucio-35.7.0.data/scripts/rucio-conveyor-submitter +139 -0
  468. rucio-35.7.0.data/scripts/rucio-conveyor-throttler +104 -0
  469. rucio-35.7.0.data/scripts/rucio-dark-reaper +53 -0
  470. rucio-35.7.0.data/scripts/rucio-dumper +160 -0
  471. rucio-35.7.0.data/scripts/rucio-follower +44 -0
  472. rucio-35.7.0.data/scripts/rucio-hermes +54 -0
  473. rucio-35.7.0.data/scripts/rucio-judge-cleaner +89 -0
  474. rucio-35.7.0.data/scripts/rucio-judge-evaluator +137 -0
  475. rucio-35.7.0.data/scripts/rucio-judge-injector +44 -0
  476. rucio-35.7.0.data/scripts/rucio-judge-repairer +44 -0
  477. rucio-35.7.0.data/scripts/rucio-kronos +43 -0
  478. rucio-35.7.0.data/scripts/rucio-minos +53 -0
  479. rucio-35.7.0.data/scripts/rucio-minos-temporary-expiration +50 -0
  480. rucio-35.7.0.data/scripts/rucio-necromancer +120 -0
  481. rucio-35.7.0.data/scripts/rucio-oauth-manager +63 -0
  482. rucio-35.7.0.data/scripts/rucio-reaper +83 -0
  483. rucio-35.7.0.data/scripts/rucio-replica-recoverer +248 -0
  484. rucio-35.7.0.data/scripts/rucio-rse-decommissioner +66 -0
  485. rucio-35.7.0.data/scripts/rucio-storage-consistency-actions +74 -0
  486. rucio-35.7.0.data/scripts/rucio-transmogrifier +77 -0
  487. rucio-35.7.0.data/scripts/rucio-undertaker +76 -0
  488. rucio-35.7.0.dist-info/METADATA +72 -0
  489. rucio-35.7.0.dist-info/RECORD +493 -0
  490. rucio-35.7.0.dist-info/WHEEL +5 -0
  491. rucio-35.7.0.dist-info/licenses/AUTHORS.rst +97 -0
  492. rucio-35.7.0.dist-info/licenses/LICENSE +201 -0
  493. rucio-35.7.0.dist-info/top_level.txt +1 -0
rucio/core/transfer.py ADDED
@@ -0,0 +1,1517 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import datetime
16
+ import logging
17
+ import operator
18
+ import re
19
+ import sys
20
+ import time
21
+ import traceback
22
+ from collections import defaultdict
23
+ from typing import TYPE_CHECKING, cast
24
+
25
+ from dogpile.cache import make_region
26
+ from dogpile.cache.api import NoValue
27
+ from sqlalchemy import select, update
28
+ from sqlalchemy.exc import IntegrityError
29
+
30
+ from rucio.common import constants
31
+ from rucio.common.config import config_get, config_get_list
32
+ from rucio.common.constants import SUPPORTED_PROTOCOLS, RseAttr
33
+ from rucio.common.exception import InvalidRSEExpression, RequestNotFound, RSEProtocolNotSupported, RucioException, UnsupportedOperation
34
+ from rucio.common.utils import construct_non_deterministic_pfn
35
+ from rucio.core import did
36
+ from rucio.core import message as message_core
37
+ from rucio.core import request as request_core
38
+ from rucio.core.account import list_accounts
39
+ from rucio.core.monitor import MetricManager
40
+ from rucio.core.request import DirectTransfer, RequestSource, RequestWithSources, TransferDestination, transition_request_state
41
+ from rucio.core.rse import RseData
42
+ from rucio.core.rse_expression_parser import parse_expression
43
+ from rucio.db.sqla import models
44
+ from rucio.db.sqla.constants import DIDType, RequestState, RequestType, TransferLimitDirection
45
+ from rucio.db.sqla.session import read_session, stream_session, transactional_session
46
+ from rucio.rse import rsemanager as rsemgr
47
+ from rucio.transfertool.bittorrent import BittorrentTransfertool
48
+ from rucio.transfertool.fts3 import FTS3Transfertool
49
+ from rucio.transfertool.globus import GlobusTransferTool
50
+ from rucio.transfertool.mock import MockTransfertool
51
+ from rucio.transfertool.transfertool import TransferStatusReport, Transfertool
52
+
53
+ if TYPE_CHECKING:
54
+ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
55
+ from typing import Any, Optional
56
+
57
+ from sqlalchemy.orm import Session
58
+
59
+ from rucio.common.types import InternalAccount
60
+ from rucio.core.topology import Topology
61
+ from rucio.rse.protocols.protocol import RSEProtocol
62
+
63
+ LoggerFunction = Callable[..., Any]
64
+
65
+ """
66
+ The core transfer.py is specifically for handling transfer-requests, thus requests
67
+ where the external_id is already known.
68
+ Requests accessed by request_id are covered in the core request.py
69
+ """
70
+
71
+ REGION_ACCOUNTS = make_region().configure('dogpile.cache.memory', expiration_time=600)
72
+ METRICS = MetricManager(module=__name__)
73
+
74
+ WEBDAV_TRANSFER_MODE = config_get('conveyor', 'webdav_transfer_mode', False, None)
75
+
76
+ DEFAULT_MULTIHOP_TOMBSTONE_DELAY = int(datetime.timedelta(hours=2).total_seconds())
77
+
78
+ TRANSFERTOOL_CLASSES_BY_NAME: "dict[str, type[Transfertool]]" = {
79
+ FTS3Transfertool.external_name: FTS3Transfertool,
80
+ GlobusTransferTool.external_name: GlobusTransferTool,
81
+ MockTransfertool.external_name: MockTransfertool,
82
+ BittorrentTransfertool.external_name: BittorrentTransfertool,
83
+ }
84
+
85
+
86
+ class ProtocolFactory:
87
+ """
88
+ Creates and caches protocol objects. Allowing to reuse them.
89
+ """
90
+ def __init__(self):
91
+ self.protocols = {}
92
+
93
+ def protocol(self, rse: RseData, scheme: "Optional[str]", operation: str):
94
+ protocol_key = '%s_%s_%s' % (operation, rse.id, scheme)
95
+ protocol = self.protocols.get(protocol_key)
96
+ if not protocol:
97
+ protocol = rsemgr.create_protocol(rse.info, operation, scheme)
98
+ self.protocols[protocol_key] = protocol
99
+ return protocol
100
+
101
+
102
+ class DirectTransferImplementation(DirectTransfer):
103
+ """
104
+ The configuration for a direct (non-multi-hop) transfer. It can be a multi-source transfer.
105
+
106
+ The class wraps the legacy dict-based transfer definition to maintain compatibility with existing code
107
+ during the migration.
108
+ """
109
+ def __init__(self, source: RequestSource, destination: TransferDestination, rws: RequestWithSources,
110
+ protocol_factory: ProtocolFactory, operation_src: str, operation_dest: str):
111
+ super().__init__(sources=[source], rws=rws)
112
+ self.destination = destination
113
+
114
+ self.protocol_factory = protocol_factory
115
+ self.operation_src = operation_src
116
+ self.operation_dest = operation_dest
117
+
118
+ self._dest_url = None
119
+ self._source_urls = {}
120
+
121
+ def __str__(self):
122
+ return '{sources}--{request_id}->{destination}'.format(
123
+ sources=','.join([str(s.rse) for s in self.sources]),
124
+ request_id=self.rws.request_id or '',
125
+ destination=self.dst.rse
126
+ )
127
+
128
+ @property
129
+ def src(self) -> RequestSource:
130
+ return self.sources[0]
131
+
132
+ @property
133
+ def dst(self) -> TransferDestination:
134
+ return self.destination
135
+
136
+ @property
137
+ def dest_url(self) -> str:
138
+ if not self._dest_url:
139
+ self._dest_url = self._generate_dest_url(self.dst, self.rws, self.protocol_factory, self.operation_dest)
140
+ return self._dest_url
141
+
142
+ def source_url(self, source: RequestSource) -> str:
143
+ url = self._source_urls.get(source.rse)
144
+ if not url:
145
+ self._source_urls[source.rse] = url = self._generate_source_url(
146
+ source,
147
+ self.dst,
148
+ rws=self.rws,
149
+ protocol_factory=self.protocol_factory,
150
+ operation=self.operation_src
151
+ )
152
+ return url
153
+
154
+ def dest_protocol(self) -> "RSEProtocol":
155
+ return self.protocol_factory.protocol(self.dst.rse, self.dst.scheme, self.operation_dest)
156
+
157
+ def source_protocol(self, source: RequestSource) -> "RSEProtocol":
158
+ return self.protocol_factory.protocol(source.rse, source.scheme, self.operation_src)
159
+
160
+ @staticmethod
161
+ def __rewrite_source_url(source_url, source_sign_url, dest_sign_url, source_scheme):
162
+ """
163
+ Parametrize source url for some special cases of source and destination schemes
164
+ """
165
+ if dest_sign_url == 'gcs':
166
+ if source_scheme in ['davs', 'https']:
167
+ source_url += '?copy_mode=push'
168
+ elif dest_sign_url == 's3':
169
+ if source_scheme in ['davs', 'https']:
170
+ source_url += '?copy_mode=push'
171
+ elif WEBDAV_TRANSFER_MODE:
172
+ if source_scheme in ['davs', 'https']:
173
+ source_url += '?copy_mode=%s' % WEBDAV_TRANSFER_MODE
174
+
175
+ source_sign_url_map = {'gcs': 'gclouds', 's3': 's3s'}
176
+ if source_sign_url in source_sign_url_map:
177
+ if source_url[:7] == 'davs://':
178
+ source_url = source_sign_url_map[source_sign_url] + source_url[4:]
179
+ if source_url[:8] == 'https://':
180
+ source_url = source_sign_url_map[source_sign_url] + source_url[5:]
181
+
182
+ if source_url[:12] == 'srm+https://':
183
+ source_url = 'srm' + source_url[9:]
184
+ return source_url
185
+
186
+ @staticmethod
187
+ def __rewrite_dest_url(dest_url, dest_sign_url):
188
+ """
189
+ Parametrize destination url for some special cases of destination schemes
190
+ """
191
+ if dest_sign_url == 'gcs':
192
+ dest_url = re.sub('davs', 'gclouds', dest_url)
193
+ dest_url = re.sub('https', 'gclouds', dest_url)
194
+ elif dest_sign_url == 's3':
195
+ dest_url = re.sub('davs', 's3s', dest_url)
196
+ dest_url = re.sub('https', 's3s', dest_url)
197
+
198
+ if dest_url[:12] == 'srm+https://':
199
+ dest_url = 'srm' + dest_url[9:]
200
+ return dest_url
201
+
202
+ @classmethod
203
+ def _generate_source_url(cls, src: RequestSource, dst: TransferDestination, rws: RequestWithSources, protocol_factory: ProtocolFactory, operation: str):
204
+ """
205
+ Generate the source url which will be used as origin to copy the file from request rws towards the given dst endpoint
206
+ """
207
+ # Get source protocol
208
+ protocol = protocol_factory.protocol(src.rse, src.scheme, operation)
209
+
210
+ # Compute the source URL
211
+ source_sign_url = src.rse.attributes.get(RseAttr.SIGN_URL, None)
212
+ dest_sign_url = dst.rse.attributes.get(RseAttr.SIGN_URL, None)
213
+ source_url = list(protocol.lfns2pfns(lfns={'scope': rws.scope.external, 'name': rws.name, 'path': src.file_path}).values())[0]
214
+ source_url = cls.__rewrite_source_url(source_url, source_sign_url=source_sign_url, dest_sign_url=dest_sign_url, source_scheme=src.scheme)
215
+ return source_url
216
+
217
+ @classmethod
218
+ def _generate_dest_url(cls, dst: TransferDestination, rws: RequestWithSources, protocol_factory: ProtocolFactory, operation: str):
219
+ """
220
+ Generate the destination url for copying the file of request rws
221
+ """
222
+ # Get destination protocol
223
+ protocol = protocol_factory.protocol(dst.rse, dst.scheme, operation)
224
+
225
+ if dst.rse.info['deterministic']:
226
+ dest_url = list(protocol.lfns2pfns(lfns={'scope': rws.scope.external, 'name': rws.name}).values())[0]
227
+ else:
228
+ # compute dest url in case of non deterministic
229
+ # naming convention, etc.
230
+ dsn = get_dsn(rws.scope, rws.name, rws.attributes.get('dsn', None))
231
+ # DQ2 path always starts with /, but prefix might not end with /
232
+ naming_convention = dst.rse.attributes.get(RseAttr.NAMING_CONVENTION, None)
233
+ if rws.scope.external is not None:
234
+ dest_path = construct_non_deterministic_pfn(dsn, rws.scope.external, rws.name, naming_convention)
235
+ if dst.rse.is_tape():
236
+ if rws.retry_count or rws.activity == 'Recovery':
237
+ dest_path = '%s_%i' % (dest_path, int(time.time()))
238
+
239
+ dest_url = list(protocol.lfns2pfns(lfns={'scope': rws.scope.external, 'name': rws.name, 'path': dest_path}).values())[0]
240
+
241
+ dest_sign_url = dst.rse.attributes.get(RseAttr.SIGN_URL, None)
242
+ dest_url = cls.__rewrite_dest_url(dest_url, dest_sign_url=dest_sign_url)
243
+ return dest_url
244
+
245
+
246
+ class StageinTransferImplementation(DirectTransferImplementation):
247
+ """
248
+ A definition of a transfer which triggers a stagein operation.
249
+ - The source and destination url are identical
250
+ - must be from TAPE to non-TAPE RSE
251
+ - can only have one source
252
+ """
253
+ def __init__(
254
+ self,
255
+ source: RequestSource,
256
+ destination: TransferDestination,
257
+ rws: RequestWithSources,
258
+ protocol_factory: ProtocolFactory,
259
+ operation_src: str,
260
+ operation_dest: str
261
+ ):
262
+ if not source.rse.is_tape() or destination.rse.is_tape():
263
+ # allow staging_required QoS RSE to be TAPE to TAPE for pin
264
+ if not destination.rse.attributes.get(RseAttr.STAGING_REQUIRED, None):
265
+ raise RucioException("Stageing request {} must be from TAPE to DISK rse. Got {} and {}.".format(rws, source, destination))
266
+ super().__init__(source, destination, rws, protocol_factory, operation_src, operation_dest)
267
+
268
+ @property
269
+ def dest_url(self) -> str:
270
+ if not self._dest_url:
271
+ self._dest_url = self.src.url if self.src.url else self._generate_source_url(self.src,
272
+ self.dst,
273
+ rws=self.rws,
274
+ protocol_factory=self.protocol_factory,
275
+ operation=self.operation_dest)
276
+ return self._dest_url
277
+
278
+ def source_url(self, source: RequestSource) -> str:
279
+ # Source and dest url is the same for stagein requests
280
+ return self.dest_url
281
+
282
+
283
+ def transfer_path_str(transfer_path: "list[DirectTransfer]") -> str:
284
+ """
285
+ an implementation of __str__ for a transfer path, which is a list of direct transfers, so not really an object
286
+ """
287
+ if not transfer_path:
288
+ return 'empty transfer path'
289
+
290
+ multi_tt = False
291
+ if len({hop.rws.transfertool for hop in transfer_path if hop.rws.transfertool}) > 1:
292
+ # The path relies on more than one transfertool
293
+ multi_tt = True
294
+
295
+ if len(transfer_path) == 1:
296
+ return str(transfer_path[0])
297
+
298
+ path_str = str(transfer_path[0].src.rse)
299
+ for hop in transfer_path:
300
+ path_str += '--{request_id}{transfertool}->{destination}'.format(
301
+ request_id=hop.rws.request_id or '',
302
+ transfertool=':{}'.format(hop.rws.transfertool) if multi_tt else '',
303
+ destination=hop.dst.rse,
304
+ )
305
+ return path_str
306
+
307
+
308
+ @transactional_session
309
+ def mark_submitting(
310
+ transfer: "DirectTransfer",
311
+ external_host: str,
312
+ *,
313
+ logger: "Callable",
314
+ session: "Session",
315
+ ):
316
+ """
317
+ Mark a transfer as submitting
318
+
319
+ :param transfer: A transfer object
320
+ :param session: Database session to use.
321
+ """
322
+
323
+ log_str = 'PREPARING REQUEST %s DID %s:%s TO SUBMITTING STATE PREVIOUS %s FROM %s TO %s USING %s ' % (transfer.rws.request_id,
324
+ transfer.rws.scope,
325
+ transfer.rws.name,
326
+ transfer.rws.previous_attempt_id,
327
+ [transfer.source_url(s) for s in transfer.sources],
328
+ transfer.dest_url,
329
+ external_host)
330
+ logger(logging.DEBUG, "%s", log_str)
331
+
332
+ stmt = update(
333
+ models.Request
334
+ ).where(
335
+ models.Request.id == transfer.rws.request_id,
336
+ models.Request.state == RequestState.QUEUED
337
+ ).execution_options(
338
+ synchronize_session=False
339
+ ).values(
340
+ {
341
+ 'state': RequestState.SUBMITTING,
342
+ 'external_id': None,
343
+ 'external_host': external_host,
344
+ 'dest_url': transfer.dest_url,
345
+ 'submitted_at': datetime.datetime.utcnow(),
346
+ }
347
+ )
348
+ rowcount = session.execute(stmt).rowcount
349
+
350
+ if rowcount == 0:
351
+ raise RequestNotFound("Failed to prepare transfer: request %s does not exist or is not in queued state" % transfer.rws)
352
+
353
+
354
+ @transactional_session
355
+ def ensure_db_sources(
356
+ transfer_path: "list[DirectTransfer]",
357
+ *,
358
+ logger: "Callable",
359
+ session: "Session",
360
+ ):
361
+ """
362
+ Ensure the needed DB source objects exist
363
+ """
364
+
365
+ desired_sources = []
366
+ for transfer in transfer_path:
367
+
368
+ for source in transfer.sources:
369
+ common_source_attrs = {
370
+ "scope": transfer.rws.scope,
371
+ "name": transfer.rws.name,
372
+ "rse_id": source.rse.id,
373
+ "dest_rse_id": transfer.dst.rse.id,
374
+ "ranking": source.ranking,
375
+ "bytes": transfer.rws.byte_count,
376
+ "url": transfer.source_url(source),
377
+ "is_using": True,
378
+ }
379
+
380
+ desired_sources.append({'request_id': transfer.rws.request_id, **common_source_attrs})
381
+ if len(transfer_path) > 1 and transfer is not transfer_path[-1]:
382
+ # For multihop transfers, each hop's source is also an initial transfer's source.
383
+ desired_sources.append({'request_id': transfer_path[-1].rws.request_id, **common_source_attrs})
384
+
385
+ for source in desired_sources:
386
+ stmt = update(
387
+ models.Source
388
+ ).where(
389
+ models.Source.request_id == source['request_id'],
390
+ models.Source.rse_id == source['rse_id']
391
+ ).execution_options(
392
+ synchronize_session=False
393
+ ).values(
394
+ is_using=True
395
+ )
396
+ src_rowcount = session.execute(stmt).rowcount
397
+ if src_rowcount == 0:
398
+ models.Source(**source).save(session=session, flush=False)
399
+
400
+
401
+ @transactional_session
402
+ def set_transfers_state(
403
+ transfers,
404
+ state: "RequestState",
405
+ submitted_at: datetime.datetime,
406
+ external_host: str,
407
+ external_id: str,
408
+ transfertool: str,
409
+ *,
410
+ session: "Session",
411
+ logger
412
+ ):
413
+ """
414
+ Update the transfer info of a request.
415
+ :param transfers: Dictionary containing request transfer info.
416
+ :param session: Database session to use.
417
+ """
418
+
419
+ logger(logging.INFO, 'Setting state(%s), transfertool(%s), external_host(%s) and eid(%s) for transfers: %s',
420
+ state.name, transfertool, external_host, external_id, ', '.join(t.rws.request_id for t in transfers))
421
+ try:
422
+ for transfer in transfers:
423
+ rws = transfer.rws
424
+ logger(logging.DEBUG, 'COPYING REQUEST %s DID %s:%s USING %s with state(%s) with eid(%s)' % (rws.request_id, rws.scope, rws.name, external_host, state, external_id))
425
+ stmt = update(
426
+ models.Request
427
+ ).where(
428
+ models.Request.id == transfer.rws.request_id,
429
+ models.Request.state == RequestState.SUBMITTING
430
+ ).execution_options(
431
+ synchronize_session=False
432
+ ).values(
433
+ {
434
+ models.Request.state: state,
435
+ models.Request.external_id: external_id,
436
+ models.Request.external_host: external_host,
437
+ models.Request.source_rse_id: transfer.src.rse.id,
438
+ models.Request.submitted_at: submitted_at,
439
+ models.Request.transfertool: transfertool,
440
+ }
441
+ )
442
+ rowcount = session.execute(stmt).rowcount
443
+
444
+ if rowcount == 0:
445
+ raise RucioException("%s: failed to set transfer state: request doesn't exist or is not in SUBMITTING state" % rws)
446
+
447
+ stmt = select(
448
+ models.DataIdentifier.datatype
449
+ ).where(
450
+ models.DataIdentifier.scope == rws.scope,
451
+ models.DataIdentifier.name == rws.name,
452
+ )
453
+ datatype = session.execute(stmt).scalar_one_or_none()
454
+
455
+ msg = {'request-id': rws.request_id,
456
+ 'request-type': rws.request_type,
457
+ 'scope': rws.scope.external,
458
+ 'name': rws.name,
459
+ 'dataset': None,
460
+ 'datasetScope': None,
461
+ 'src-rse-id': transfer.src.rse.id,
462
+ 'src-rse': transfer.src.rse.name,
463
+ 'dst-rse-id': transfer.dst.rse.id,
464
+ 'dst-rse': transfer.dst.rse.name,
465
+ 'state': state,
466
+ 'activity': rws.activity,
467
+ 'file-size': rws.byte_count,
468
+ 'bytes': rws.byte_count,
469
+ 'checksum-md5': rws.md5,
470
+ 'checksum-adler': rws.adler32,
471
+ 'external-id': external_id,
472
+ 'external-host': external_host,
473
+ 'queued_at': str(submitted_at),
474
+ 'datatype': datatype}
475
+ if rws.scope.vo != 'def':
476
+ msg['vo'] = rws.scope.vo
477
+
478
+ ds_scope = transfer.rws.attributes.get('ds_scope')
479
+ if ds_scope:
480
+ msg['datasetScope'] = ds_scope
481
+ ds_name = transfer.rws.attributes.get('ds_name')
482
+ if ds_name:
483
+ msg['dataset'] = ds_name
484
+
485
+ if msg['request-type']:
486
+ transfer_status = '%s-%s' % (msg['request-type'].name, msg['state'].name)
487
+ else:
488
+ transfer_status = 'transfer-%s' % msg['state']
489
+ transfer_status = transfer_status.lower()
490
+
491
+ message_core.add_message(transfer_status, msg, session=session)
492
+
493
+ except IntegrityError as error:
494
+ raise RucioException(error.args)
495
+
496
+ logger(logging.DEBUG, 'Finished to register transfer state for %s' % external_id)
497
+
498
+
499
+ @transactional_session
500
+ def update_transfer_state(
501
+ tt_status_report: TransferStatusReport,
502
+ stats_manager: request_core.TransferStatsManager,
503
+ *,
504
+ session: "Session",
505
+ logger=logging.log
506
+ ):
507
+ """
508
+ Used by poller and consumer to update the internal state of requests,
509
+ after the response by the external transfertool.
510
+
511
+ :param tt_status_report: The transfertool status update, retrieved via request.query_request().
512
+ :param session: The database session to use.
513
+ :param logger: Optional decorated logger that can be passed from the calling daemons or servers.
514
+ :returns: The number of updated requests
515
+ """
516
+
517
+ request_id = tt_status_report.request_id
518
+ nb_updated = 0
519
+ try:
520
+ fields_to_update = tt_status_report.get_db_fields_to_update(session=session, logger=logger)
521
+ if not fields_to_update:
522
+ request_core.update_request(request_id, raise_on_missing=True, session=session)
523
+ return False
524
+ else:
525
+ logger(logging.INFO, 'UPDATING REQUEST %s FOR %s with changes: %s' % (str(request_id), tt_status_report, fields_to_update))
526
+
527
+ request = request_core.get_request(request_id, session=session)
528
+ updated = transition_request_state(request_id, request=request, session=session, **fields_to_update)
529
+
530
+ if not updated:
531
+ return nb_updated
532
+ nb_updated += 1
533
+
534
+ if tt_status_report.state == RequestState.FAILED:
535
+ if request_core.is_intermediate_hop(request):
536
+ nb_updated += request_core.handle_failed_intermediate_hop(request, session=session)
537
+
538
+ if tt_status_report.state:
539
+ stats_manager.observe(
540
+ src_rse_id=request['source_rse_id'],
541
+ dst_rse_id=request['dest_rse_id'],
542
+ activity=request['activity'],
543
+ state=tt_status_report.state,
544
+ file_size=request['bytes'],
545
+ submitted_at=request.get('submitted_at', None),
546
+ started_at=fields_to_update.get('started_at', None),
547
+ transferred_at=fields_to_update.get('transferred_at', None),
548
+ session=session,
549
+ )
550
+ request_core.add_monitor_message(
551
+ new_state=tt_status_report.state,
552
+ request=request,
553
+ additional_fields=tt_status_report.get_monitor_msg_fields(session=session, logger=logger),
554
+ session=session
555
+ )
556
+ return nb_updated
557
+ except UnsupportedOperation as error:
558
+ logger(logging.WARNING, "Request %s doesn't exist - Error: %s" % (request_id, str(error).replace('\n', '')))
559
+ return 0
560
+ except Exception:
561
+ logger(logging.CRITICAL, "Exception", exc_info=True)
562
+
563
+
564
+ @transactional_session
565
+ def mark_transfer_lost(request, *, session: "Session", logger=logging.log):
566
+ new_state = RequestState.LOST
567
+ reason = "The FTS job lost"
568
+
569
+ err_msg = request_core.get_transfer_error(new_state, reason)
570
+ transition_request_state(request['id'], state=new_state, external_id=request['external_id'], err_msg=err_msg, session=session, logger=logger)
571
+
572
+ request_core.add_monitor_message(new_state=new_state, request=request, additional_fields={'reason': reason}, session=session)
573
+
574
+
575
+ @METRICS.count_it
576
+ @transactional_session
577
+ def touch_transfer(external_host, transfer_id, *, session: "Session"):
578
+ """
579
+ Update the timestamp of requests in a transfer. Fails silently if the transfer_id does not exist.
580
+ :param request_host: Name of the external host.
581
+ :param transfer_id: External transfer job id as a string.
582
+ :param session: Database session to use.
583
+ """
584
+ try:
585
+ # don't touch it if it's already touched in 30 seconds
586
+ stmt = update(
587
+ models.Request
588
+ ).prefix_with(
589
+ "/*+ INDEX(REQUESTS REQUESTS_EXTERNALID_UQ) */", dialect='oracle'
590
+ ).where(
591
+ models.Request.external_id == transfer_id,
592
+ models.Request.state == RequestState.SUBMITTED,
593
+ models.Request.updated_at < datetime.datetime.utcnow() - datetime.timedelta(seconds=30)
594
+ ).execution_options(
595
+ synchronize_session=False
596
+ ).values(
597
+ updated_at=datetime.datetime.utcnow()
598
+ )
599
+ session.execute(stmt)
600
+ except IntegrityError as error:
601
+ raise RucioException(error.args)
602
+
603
+
604
+ def _create_transfer_definitions(
605
+ topology: "Topology",
606
+ protocol_factory: ProtocolFactory,
607
+ rws: RequestWithSources,
608
+ sources: "Iterable[RequestSource]",
609
+ max_sources: int,
610
+ multi_source_sources: "Iterable[RequestSource]",
611
+ limit_dest_schemes: list[str],
612
+ operation_src: str,
613
+ operation_dest: str,
614
+ domain: str,
615
+ *,
616
+ session: "Session",
617
+ ) -> "dict[RseData, list[DirectTransfer]]":
618
+ """
619
+ Find the all paths from sources towards the destination of the given transfer request.
620
+ Create the transfer definitions for each point-to-point transfer (multi-source, when possible)
621
+ """
622
+ shortest_paths = topology.search_shortest_paths(src_nodes=[s.rse for s in sources], dst_node=rws.dest_rse,
623
+ operation_src=operation_src, operation_dest=operation_dest,
624
+ domain=domain, limit_dest_schemes=limit_dest_schemes, session=session)
625
+
626
+ transfers_by_source = {}
627
+ sources_by_rse = {s.rse: s for s in sources}
628
+ paths_by_source = {sources_by_rse[rse]: path for rse, path in shortest_paths.items()}
629
+ for source, list_hops in paths_by_source.items():
630
+ transfer_path = []
631
+ for hop in list_hops:
632
+ hop_src_rse = hop['source_rse']
633
+ hop_dst_rse = hop['dest_rse']
634
+ src = RequestSource(
635
+ rse=hop_src_rse,
636
+ file_path=source.file_path if hop_src_rse == source.rse else None,
637
+ ranking=source.ranking if hop_src_rse == source.rse else 0,
638
+ distance=hop['cumulated_distance'] if hop_src_rse == source.rse else hop['hop_distance'],
639
+ scheme=hop['source_scheme'],
640
+ )
641
+ dst = TransferDestination(
642
+ rse=hop_dst_rse,
643
+ scheme=hop['dest_scheme'],
644
+ )
645
+ hop_definition = DirectTransferImplementation(
646
+ source=src,
647
+ destination=dst,
648
+ operation_src=operation_src,
649
+ operation_dest=operation_dest,
650
+ # keep the current rws for last hop; create a new one for other hops
651
+ rws=rws if hop_dst_rse == rws.dest_rse else RequestWithSources(
652
+ id_=None,
653
+ request_type=rws.request_type,
654
+ rule_id=None,
655
+ scope=rws.scope,
656
+ name=rws.name,
657
+ md5=rws.md5,
658
+ adler32=rws.adler32,
659
+ byte_count=rws.byte_count,
660
+ activity=rws.activity,
661
+ attributes={
662
+ 'activity': rws.activity,
663
+ 'source_replica_expression': None,
664
+ 'lifetime': None,
665
+ 'ds_scope': None,
666
+ 'ds_name': None,
667
+ 'bytes': rws.byte_count,
668
+ 'md5': rws.md5,
669
+ 'adler32': rws.adler32,
670
+ 'priority': None,
671
+ 'allow_tape_source': True
672
+ },
673
+ previous_attempt_id=None,
674
+ dest_rse=hop_dst_rse,
675
+ account=rws.account,
676
+ retry_count=0,
677
+ priority=rws.priority,
678
+ transfertool=rws.transfertool,
679
+ ),
680
+ protocol_factory=protocol_factory,
681
+ )
682
+
683
+ transfer_path.append(hop_definition)
684
+ transfers_by_source[source.rse] = transfer_path
685
+
686
+ # create multi-source transfers: add additional sources if possible
687
+ for transfer_path in transfers_by_source.values():
688
+ if len(transfer_path) == 1 and not transfer_path[0].src.rse.is_tape():
689
+ # Multiple single-hop DISK rses can be used together in "multi-source" transfers
690
+ #
691
+ # Try adding additional single-hop DISK rses sources to the transfer
692
+ main_source_schemes = __add_compatible_schemes(schemes=[transfer_path[0].dst.scheme], allowed_schemes=SUPPORTED_PROTOCOLS)
693
+ added_sources = 0
694
+ for source in sorted(multi_source_sources, key=lambda s: (-s.ranking, s.distance)):
695
+ if added_sources >= max_sources:
696
+ break
697
+
698
+ edge = topology.edge(source.rse, transfer_path[0].dst.rse)
699
+ if not edge:
700
+ # There is no direct connection between this source and the destination
701
+ continue
702
+
703
+ if source.rse == transfer_path[0].src.rse:
704
+ # This is the main source. Don't add a duplicate.
705
+ continue
706
+
707
+ if source.rse.is_tape():
708
+ continue
709
+
710
+ try:
711
+ matching_scheme = rsemgr.find_matching_scheme(
712
+ rse_settings_src=source.rse.info,
713
+ rse_settings_dest=transfer_path[0].dst.rse.info,
714
+ operation_src=operation_src,
715
+ operation_dest=operation_dest,
716
+ domain=domain,
717
+ scheme=main_source_schemes)
718
+ except RSEProtocolNotSupported:
719
+ continue
720
+
721
+ transfer_path[0].sources.append(
722
+ RequestSource(
723
+ rse=source.rse,
724
+ file_path=source.file_path,
725
+ ranking=source.ranking,
726
+ distance=edge.cost,
727
+ scheme=matching_scheme[1],
728
+ )
729
+ )
730
+ added_sources += 1
731
+ return transfers_by_source
732
+
733
+
734
+ def _create_stagein_definitions(
735
+ rws: RequestWithSources,
736
+ sources: "Iterable[RequestSource]",
737
+ limit_dest_schemes: list[str],
738
+ operation_src: str,
739
+ operation_dest: str,
740
+ protocol_factory: ProtocolFactory,
741
+ ) -> "dict[RseData, list[DirectTransfer]]":
742
+ """
743
+ for each source, create a single-hop transfer path with a one stageing definition inside
744
+ """
745
+ transfers_by_source = {
746
+ source.rse: [
747
+ cast(DirectTransfer, StageinTransferImplementation(
748
+ source=RequestSource(
749
+ rse=source.rse,
750
+ file_path=source.file_path,
751
+ url=source.url,
752
+ scheme=limit_dest_schemes, # type: ignore (list passed instead of single scheme)
753
+ ),
754
+ destination=TransferDestination(
755
+ rse=rws.dest_rse,
756
+ scheme=limit_dest_schemes, # type: ignore (list passed instead of single scheme)
757
+ ),
758
+ operation_src=operation_src,
759
+ operation_dest=operation_dest,
760
+ rws=rws,
761
+ protocol_factory=protocol_factory,
762
+ ))
763
+
764
+ ]
765
+ for source in sources
766
+ }
767
+ return transfers_by_source
768
+
769
+
770
+ def get_dsn(scope, name, dsn):
771
+ if dsn:
772
+ return dsn
773
+ # select a containing dataset
774
+ for parent in did.list_parent_dids(scope, name):
775
+ if parent['type'] == DIDType.DATASET:
776
+ return parent['name']
777
+ return 'other'
778
+
779
+
780
+ def __compress_multihops(
781
+ paths_by_source: "Iterable[tuple[RequestSource, Sequence[DirectTransfer]]]",
782
+ sources: "Iterable[RequestSource]",
783
+ ) -> "Iterator[tuple[RequestSource, Sequence[DirectTransfer]]]":
784
+ # Compress multihop transfers which contain other sources as part of itself.
785
+ # For example: multihop A->B->C and B is a source, compress A->B->C into B->C
786
+ source_rses = {s.rse.id for s in sources}
787
+ seen_source_rses = set()
788
+ for source, path in paths_by_source:
789
+ if len(path) > 1:
790
+ # find the index of the first hop starting from the end which is also a source. Path[0] will always be a source.
791
+ last_source_idx = next((idx for idx, hop in reversed(list(enumerate(path))) if hop.src.rse.id in source_rses), (0, None))
792
+ if last_source_idx > 0:
793
+ path = path[last_source_idx:]
794
+
795
+ # Deduplicate paths from same source
796
+ src_rse_id = path[0].src.rse.id
797
+ if src_rse_id not in seen_source_rses:
798
+ seen_source_rses.add(src_rse_id)
799
+ yield source, path
800
+
801
+
802
+ class TransferPathBuilder:
803
+ def __init__(
804
+ self,
805
+ topology: "Topology",
806
+ protocol_factory: ProtocolFactory,
807
+ max_sources: int,
808
+ preparer_mode: bool = False,
809
+ schemes: "Optional[list[str]]" = None,
810
+ failover_schemes: "Optional[list[str]]" = None,
811
+ requested_source_only: bool = False,
812
+ ):
813
+ self.failover_schemes = failover_schemes if failover_schemes is not None else []
814
+ self.schemes = schemes if schemes is not None else []
815
+ self.topology = topology
816
+ self.preparer_mode = preparer_mode
817
+ self.protocol_factory = protocol_factory
818
+ self.max_sources = max_sources
819
+ self.requested_source_only = requested_source_only
820
+
821
+ self.definition_by_request_id = {}
822
+
823
+ def build_or_return_cached(
824
+ self,
825
+ rws: RequestWithSources,
826
+ sources: "Iterable[RequestSource]",
827
+ *,
828
+ logger: "LoggerFunction" = logging.log,
829
+ session: "Session"
830
+ ) -> "Mapping[RseData, Sequence[DirectTransfer]]":
831
+ """
832
+ Warning: The function currently caches the result for the given request and returns it for later calls
833
+ with the same request id. As a result: it can return more (or less) sources than what is provided in the
834
+ `sources` argument. This is done for performance reasons. As of time of writing, this behavior is not problematic
835
+ for the callers of this method.
836
+ """
837
+ definition = self.definition_by_request_id.get(rws.request_id)
838
+ if definition:
839
+ return definition
840
+
841
+ transfer_schemes = self.schemes
842
+ if rws.previous_attempt_id and self.failover_schemes:
843
+ transfer_schemes = self.failover_schemes
844
+
845
+ candidate_sources = sources
846
+ if self.requested_source_only and rws.requested_source:
847
+ candidate_sources = [rws.requested_source] if rws.requested_source in sources else []
848
+
849
+ if rws.request_type == RequestType.STAGEIN:
850
+ definition = _create_stagein_definitions(
851
+ rws=rws,
852
+ sources=sources,
853
+ limit_dest_schemes=transfer_schemes,
854
+ operation_src='read',
855
+ operation_dest='write',
856
+ protocol_factory=self.protocol_factory
857
+ )
858
+ else:
859
+ definition = _create_transfer_definitions(
860
+ topology=self.topology,
861
+ rws=rws,
862
+ sources=candidate_sources,
863
+ max_sources=self.max_sources,
864
+ multi_source_sources=[] if self.preparer_mode else sources,
865
+ limit_dest_schemes=transfer_schemes,
866
+ operation_src='third_party_copy_read',
867
+ operation_dest='third_party_copy_write',
868
+ domain='wan',
869
+ protocol_factory=self.protocol_factory,
870
+ session=session
871
+ )
872
+ self.definition_by_request_id[rws.request_id] = definition
873
+ return definition
874
+
875
+
876
+ class _SkipSource:
877
+ pass
878
+
879
+
880
+ SKIP_SOURCE = _SkipSource()
881
+
882
+
883
+ class RequestRankingContext:
884
+ """
885
+ Helper class used by SourceRankingStrategy. It allows to store additional request-specific
886
+ context data and access it when handling a specific source of the given request.
887
+ """
888
+
889
+ def __init__(self, strategy: "SourceRankingStrategy", rws: "RequestWithSources"):
890
+ self.strategy = strategy
891
+ self.rws = rws
892
+
893
+ def apply(self, source: RequestSource) -> "int | _SkipSource":
894
+ verdict = self.strategy.apply(self, source)
895
+ if verdict is None:
896
+ verdict = sys.maxsize
897
+ return verdict
898
+
899
+
900
+ class SourceRankingStrategy:
901
+ """
902
+ Represents a source ranking strategy. Used to order the sources of a request and decide
903
+ which will be the actual source used for the transfer.
904
+
905
+ If filter_only is True, any value other than SKIP_SOURCE returned by apply() will be ignored.
906
+ """
907
+ filter_only: bool = False
908
+
909
+ def for_request(
910
+ self,
911
+ rws: RequestWithSources,
912
+ sources: "Iterable[RequestSource]",
913
+ *,
914
+ logger: "LoggerFunction" = logging.log,
915
+ session: "Session"
916
+ ) -> "RequestRankingContext":
917
+ return RequestRankingContext(self, rws)
918
+
919
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
920
+ """
921
+ Normally, this function will be called indirectly, via self.for_request(...).apply(source).
922
+
923
+ It is expected to either return SKIP_SOURCE to signal that this source must be ignored;
924
+ or an integer which gives the cost of the given source under the current strategy
925
+ (smaller cost: higher priority).
926
+ If `None` is returned, it will be interpreted as sys.maxsize (i.e. very low priority).
927
+ This is done to avoid requiring an explicit integer in filter-only strategies.
928
+ """
929
+ pass
930
+
931
+ class _ClassNameDescriptor:
932
+ """
933
+ Automatically set the external_name of the strategy to the class name.
934
+ """
935
+ def __get__(self, obj, objtype=None):
936
+ if objtype is not None:
937
+ return objtype.__name__
938
+ return type(obj).__name__
939
+
940
+ external_name = _ClassNameDescriptor()
941
+
942
+
943
+ class SourceFilterStrategy(SourceRankingStrategy):
944
+ filter_only = True
945
+
946
+
947
+ class EnforceSourceRSEExpression(SourceFilterStrategy):
948
+
949
+ class _RankingContext(RequestRankingContext):
950
+ def __init__(self, strategy: "SourceRankingStrategy", rws: "RequestWithSources", allowed_source_rses: "Optional[set[str]]"):
951
+ super().__init__(strategy, rws)
952
+ self.allowed_source_rses = allowed_source_rses
953
+
954
+ def for_request(
955
+ self,
956
+ rws: RequestWithSources,
957
+ sources: "Iterable[RequestSource]",
958
+ *,
959
+ logger: "LoggerFunction" = logging.log,
960
+ session: "Session"
961
+ ) -> "RequestRankingContext":
962
+ # parse source expression
963
+ allowed_source_rses = None
964
+ source_replica_expression = rws.attributes.get('source_replica_expression', None)
965
+ if source_replica_expression:
966
+ try:
967
+ parsed_rses = parse_expression(source_replica_expression, session=session)
968
+ except InvalidRSEExpression as error:
969
+ logger(logging.ERROR, "%s: Invalid RSE exception %s: %s", rws.request_id, source_replica_expression, str(error))
970
+ allowed_source_rses = set()
971
+ else:
972
+ allowed_source_rses = {x['id'] for x in parsed_rses}
973
+ return self._RankingContext(self, rws, allowed_source_rses)
974
+
975
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
976
+ ctx = cast(EnforceSourceRSEExpression._RankingContext, ctx)
977
+ if ctx.allowed_source_rses is not None and source.rse.id not in ctx.allowed_source_rses:
978
+ return SKIP_SOURCE
979
+
980
+
981
+ class SkipRestrictedRSEs(SourceFilterStrategy):
982
+
983
+ def __init__(self, admin_accounts: "Optional[set[InternalAccount]]" = None):
984
+ super().__init__()
985
+ self.admin_accounts = admin_accounts if admin_accounts is not None else []
986
+
987
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
988
+ if source.rse.attributes.get(RseAttr.RESTRICTED_READ) and ctx.rws.account not in self.admin_accounts:
989
+ return SKIP_SOURCE
990
+
991
+
992
+ class SkipBlocklistedRSEs(SourceFilterStrategy):
993
+
994
+ def __init__(self, topology: "Topology"):
995
+ super().__init__()
996
+ self.topology = topology
997
+
998
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
999
+ # Ignore blocklisted RSEs
1000
+ if not source.rse.columns['availability_read'] and not self.topology.ignore_availability:
1001
+ return SKIP_SOURCE
1002
+
1003
+
1004
+ class EnforceStagingBuffer(SourceFilterStrategy):
1005
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1006
+ # For staging requests, the staging_buffer attribute must be correctly set
1007
+ if ctx.rws.request_type == RequestType.STAGEIN and source.rse.attributes.get(RseAttr.STAGING_BUFFER) != ctx.rws.dest_rse.name:
1008
+ return SKIP_SOURCE
1009
+
1010
+
1011
+ class RestrictTapeSources(SourceFilterStrategy):
1012
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1013
+ # Ignore tape sources if they are not desired
1014
+ if source.rse.is_tape_or_staging_required() and not ctx.rws.attributes.get("allow_tape_source", True):
1015
+ return SKIP_SOURCE
1016
+
1017
+
1018
+ class HighestAdjustedRankingFirst(SourceRankingStrategy):
1019
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1020
+ source_ranking_penalty = 1 if source.rse.is_tape_or_staging_required() else 0
1021
+ return - source.ranking + source_ranking_penalty
1022
+
1023
+
1024
+ class PreferDiskOverTape(SourceRankingStrategy):
1025
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1026
+ return int(source.rse.is_tape_or_staging_required()) # rely on the fact that False < True
1027
+
1028
+
1029
+ class PathDistance(SourceRankingStrategy):
1030
+
1031
+ class _RankingContext(RequestRankingContext):
1032
+ def __init__(self, strategy: "SourceRankingStrategy", rws: "RequestWithSources", paths_for_rws: "Mapping[RseData, Sequence[DirectTransfer]]"):
1033
+ super().__init__(strategy, rws)
1034
+ self.paths_for_rws = paths_for_rws
1035
+
1036
+ def __init__(self, transfer_path_builder: TransferPathBuilder):
1037
+ super().__init__()
1038
+ self.transfer_path_builder = transfer_path_builder
1039
+
1040
+ def for_request(
1041
+ self,
1042
+ rws: RequestWithSources,
1043
+ sources: "Iterable[RequestSource]",
1044
+ *,
1045
+ logger: "LoggerFunction" = logging.log,
1046
+ session: "Session"
1047
+ ) -> "RequestRankingContext":
1048
+ paths_for_rws = self.transfer_path_builder.build_or_return_cached(rws, sources, logger=logger, session=session)
1049
+ return PathDistance._RankingContext(self, rws, paths_for_rws)
1050
+
1051
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1052
+ path = cast(PathDistance._RankingContext, ctx).paths_for_rws.get(source.rse)
1053
+ if not path:
1054
+ return SKIP_SOURCE
1055
+ return path[0].src.distance
1056
+
1057
+
1058
+ class PreferSingleHop(PathDistance):
1059
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1060
+ path = cast(PathDistance._RankingContext, ctx).paths_for_rws.get(source.rse)
1061
+ if not path:
1062
+ return SKIP_SOURCE
1063
+ return int(len(path) > 1)
1064
+
1065
+
1066
+ class FailureRate(SourceRankingStrategy):
1067
+ """
1068
+ A source ranking strategy that ranks source nodes based on their failure rates for the past hour. Failure rate is
1069
+ calculated by dividing files failed by files attempted.
1070
+ """
1071
+ class _FailureRateStat:
1072
+ def __init__(self) -> None:
1073
+ self.files_done = 0
1074
+ self.files_failed = 0
1075
+
1076
+ def incorporate_stat(self, stat: "Mapping[str, int]") -> None:
1077
+ self.files_done += stat['files_done']
1078
+ self.files_failed += stat['files_failed']
1079
+
1080
+ def get_failure_rate(self) -> int:
1081
+ files_attempted = self.files_done + self.files_failed
1082
+
1083
+ # If no files have been sent yet, return failure rate as 0
1084
+ if files_attempted == 0:
1085
+ return 0
1086
+
1087
+ return int((self.files_failed / files_attempted) * 10000)
1088
+
1089
+ def __init__(self, stats_manager: "request_core.TransferStatsManager") -> None:
1090
+ super().__init__()
1091
+ self.source_stats = {}
1092
+
1093
+ for stat in stats_manager.load_totals(
1094
+ datetime.datetime.utcnow() - datetime.timedelta(hours=1),
1095
+ by_activity=False
1096
+ ):
1097
+ self.source_stats.setdefault(stat['src_rse_id'], self._FailureRateStat()).incorporate_stat(stat)
1098
+
1099
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1100
+ failure_rate = cast(FailureRate, ctx.strategy).source_stats.get(source.rse.id, self._FailureRateStat()).get_failure_rate()
1101
+ return failure_rate
1102
+
1103
+
1104
+ class SkipSchemeMissmatch(PathDistance):
1105
+ filter_only = True
1106
+
1107
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1108
+ path = cast(PathDistance._RankingContext, ctx).paths_for_rws.get(source.rse)
1109
+ # path == None means that there is no path;
1110
+ # path == [] means that a path exists (according to distances) but cannot be used (scheme mismatch)
1111
+ if path is not None and not path:
1112
+ return SKIP_SOURCE
1113
+
1114
+
1115
+ class SkipIntermediateTape(PathDistance):
1116
+ filter_only = True
1117
+
1118
+ def apply(self, ctx: RequestRankingContext, source: RequestSource) -> "Optional[int | _SkipSource]":
1119
+ # Discard multihop transfers which contain a tape source as an intermediate hop
1120
+ path = cast(PathDistance._RankingContext, ctx).paths_for_rws.get(source.rse)
1121
+ if path and any(transfer.src.rse.is_tape_or_staging_required() for transfer in path[1:]):
1122
+ return SKIP_SOURCE
1123
+
1124
+
1125
+ @transactional_session
1126
+ def build_transfer_paths(
1127
+ topology: "Topology",
1128
+ protocol_factory: "ProtocolFactory",
1129
+ requests_with_sources: "Iterable[RequestWithSources]",
1130
+ admin_accounts: "Optional[set[InternalAccount]]" = None,
1131
+ schemes: "Optional[list[str]]" = None,
1132
+ failover_schemes: "Optional[list[str]]" = None,
1133
+ max_sources: int = 4,
1134
+ transfertools: "Optional[list[str]]" = None,
1135
+ requested_source_only: bool = False,
1136
+ preparer_mode: bool = False,
1137
+ *,
1138
+ session: "Session",
1139
+ logger: "Callable" = logging.log,
1140
+ ):
1141
+ """
1142
+ For each request, find all possible transfer paths from its sources, which respect the
1143
+ constraints enforced by the request (attributes, type, etc) and the arguments of this function
1144
+
1145
+ build a multi-source transfer if possible: The scheme compatibility is important for multi-source transfers.
1146
+ We iterate again over the single-hop sources and build a new transfer definition while enforcing the scheme compatibility
1147
+ with the initial source.
1148
+
1149
+ Each path is a list of hops. Each hop is a transfer definition.
1150
+ """
1151
+ transfer_path_builder = TransferPathBuilder(
1152
+ topology=topology,
1153
+ schemes=schemes,
1154
+ failover_schemes=failover_schemes,
1155
+ protocol_factory=protocol_factory,
1156
+ max_sources=max_sources,
1157
+ preparer_mode=preparer_mode,
1158
+ requested_source_only=requested_source_only,
1159
+ )
1160
+
1161
+ stats_manager = request_core.TransferStatsManager()
1162
+
1163
+ available_strategies = {
1164
+ EnforceSourceRSEExpression.external_name: lambda: EnforceSourceRSEExpression(),
1165
+ SkipBlocklistedRSEs.external_name: lambda: SkipBlocklistedRSEs(topology=topology),
1166
+ SkipRestrictedRSEs.external_name: lambda: SkipRestrictedRSEs(admin_accounts=admin_accounts),
1167
+ EnforceStagingBuffer.external_name: lambda: EnforceStagingBuffer(),
1168
+ RestrictTapeSources.external_name: lambda: RestrictTapeSources(),
1169
+ SkipSchemeMissmatch.external_name: lambda: SkipSchemeMissmatch(transfer_path_builder=transfer_path_builder),
1170
+ SkipIntermediateTape.external_name: lambda: SkipIntermediateTape(transfer_path_builder=transfer_path_builder),
1171
+ HighestAdjustedRankingFirst.external_name: lambda: HighestAdjustedRankingFirst(),
1172
+ PreferDiskOverTape.external_name: lambda: PreferDiskOverTape(),
1173
+ PathDistance.external_name: lambda: PathDistance(transfer_path_builder=transfer_path_builder),
1174
+ PreferSingleHop.external_name: lambda: PreferSingleHop(transfer_path_builder=transfer_path_builder),
1175
+ FailureRate.external_name: lambda: FailureRate(stats_manager=stats_manager),
1176
+ }
1177
+
1178
+ default_strategies = [
1179
+ EnforceSourceRSEExpression.external_name,
1180
+ SkipBlocklistedRSEs.external_name,
1181
+ SkipRestrictedRSEs.external_name,
1182
+ EnforceStagingBuffer.external_name,
1183
+ RestrictTapeSources.external_name,
1184
+ # Without the SkipSchemeMissmatch strategy, requests will never be transitioned to the
1185
+ # RequestState.MISMATCH_SCHEME state. It _MUST_ be placed before the other Path-based strategies.
1186
+ SkipSchemeMissmatch.external_name,
1187
+ SkipIntermediateTape.external_name,
1188
+ HighestAdjustedRankingFirst.external_name,
1189
+ PreferDiskOverTape.external_name,
1190
+ PathDistance.external_name,
1191
+ PreferSingleHop.external_name,
1192
+ ]
1193
+ strategy_names = config_get_list('transfers', 'source_ranking_strategies', default=default_strategies)
1194
+
1195
+ try:
1196
+ strategies = list(available_strategies[name]() for name in strategy_names)
1197
+ except KeyError:
1198
+ logger(logging.ERROR, "One of the configured source_ranking_strategies doesn't exist %s", strategy_names, exc_info=True)
1199
+ raise
1200
+
1201
+ if admin_accounts is None:
1202
+ admin_accounts = set()
1203
+
1204
+ # Do not print full source RSE list for DIDs which have many sources. Otherwise we fill the monitoring
1205
+ # storage with data which has little to no benefit. This log message is unlikely to help debugging
1206
+ # transfers issues when there are many sources, but can be very useful for small number of sources.
1207
+ num_sources_in_logs = 4
1208
+
1209
+ candidate_paths_by_request_id, reqs_no_source, reqs_only_tape_source, reqs_scheme_mismatch = {}, set(), set(), set()
1210
+ reqs_unsupported_transfertool = set()
1211
+ for rws in requests_with_sources:
1212
+
1213
+ rws.dest_rse.ensure_loaded(load_name=True, load_info=True, load_attributes=True, load_columns=True, session=session)
1214
+ all_sources = rws.sources
1215
+ for source in all_sources:
1216
+ source.rse.ensure_loaded(load_name=True, load_info=True, load_attributes=True, load_columns=True, session=session)
1217
+
1218
+ # Assume request doesn't have any sources. Will be removed later if sources are found.
1219
+ reqs_no_source.add(rws.request_id)
1220
+ if not all_sources:
1221
+ logger(logging.INFO, '%s: has no sources. Skipping.', rws)
1222
+ continue
1223
+
1224
+ logger(logging.DEBUG, '%s: Working on %d sources%s: %s%s',
1225
+ rws,
1226
+ len(all_sources),
1227
+ f' (priority {rws.requested_source.rse})' if requested_source_only and rws.requested_source else '',
1228
+ ','.join('{}:{}:{}'.format(src.rse, src.ranking, src.distance) for src in all_sources[:num_sources_in_logs]),
1229
+ '... and %d others' % (len(all_sources) - num_sources_in_logs) if len(all_sources) > num_sources_in_logs else '')
1230
+
1231
+ # Check if destination is blocked
1232
+ if not (topology.ignore_availability or rws.dest_rse.columns['availability_write']):
1233
+ logger(logging.WARNING, '%s: dst RSE is blocked for write. Will skip the submission of new jobs', rws.request_id)
1234
+ continue
1235
+ if rws.account not in admin_accounts and rws.dest_rse.attributes.get(RseAttr.RESTRICTED_WRITE):
1236
+ logger(logging.WARNING, '%s: dst RSE is restricted for write. Will skip the submission', rws.request_id)
1237
+ continue
1238
+
1239
+ if rws.transfertool and transfertools and rws.transfertool not in transfertools:
1240
+ # The request explicitly asks for a transfertool which this submitter doesn't support
1241
+ logger(logging.INFO, '%s: unsupported transfertool. Skipping.', rws.request_id)
1242
+ reqs_unsupported_transfertool.add(rws.request_id)
1243
+ reqs_no_source.remove(rws.request_id)
1244
+ continue
1245
+
1246
+ # For each strategy name, gives the sources which were rejected by it
1247
+ rejected_sources = defaultdict(list)
1248
+ # Cost of each accepted source (lists of ordered costs: one for each ranking strategy)
1249
+ cost_vectors = {s: [] for s in rws.sources}
1250
+ for strategy in strategies:
1251
+ sources = list(cost_vectors)
1252
+ if not sources:
1253
+ # All sources where filtered by previous strategies. It's worthless to continue.
1254
+ break
1255
+ rws_strategy = strategy.for_request(rws, sources, logger=logger, session=session)
1256
+ for source in sources:
1257
+ verdict = rws_strategy.apply(source)
1258
+ if verdict is SKIP_SOURCE:
1259
+ rejected_sources[strategy.external_name].append(source)
1260
+ cost_vectors.pop(source)
1261
+ elif not strategy.filter_only:
1262
+ cost_vectors[source].append(verdict)
1263
+
1264
+ transfers_by_rse = transfer_path_builder.build_or_return_cached(rws, cost_vectors, logger=logger, session=session)
1265
+ candidate_paths = ((s, transfers_by_rse[s.rse]) for s, _ in sorted(cost_vectors.items(), key=operator.itemgetter(1)))
1266
+ if not preparer_mode:
1267
+ candidate_paths = __compress_multihops(candidate_paths, all_sources)
1268
+ candidate_paths = list(candidate_paths)
1269
+
1270
+ ordered_sources_log = ', '.join(
1271
+ f"{s.rse}:{':'.join(str(e) for e in cost_vectors[s])}"
1272
+ f"{'(actual source ' + str(path[0].src.rse) + ')' if s.rse != path[0].src.rse else ''}"
1273
+ f"{'(multihop)' if len(path) > 1 else ''}"
1274
+ for s, path in candidate_paths[:num_sources_in_logs]
1275
+ )
1276
+ if len(candidate_paths) > num_sources_in_logs:
1277
+ ordered_sources_log += '... and %d others' % (len(candidate_paths) - num_sources_in_logs)
1278
+ filtered_rses_log = ''
1279
+ for strategy_name, sources in rejected_sources.items():
1280
+ filtered_rses_log += f'; {len(sources)} dropped by strategy "{strategy_name}": '
1281
+ filtered_rses_log += ','.join(str(s.rse) for s in sources[:num_sources_in_logs])
1282
+ if len(sources) > num_sources_in_logs:
1283
+ filtered_rses_log += '... and %d others' % (len(sources) - num_sources_in_logs)
1284
+ logger(logging.INFO, '%s: %d ordered sources: %s%s', rws, len(candidate_paths), ordered_sources_log, filtered_rses_log)
1285
+
1286
+ if not candidate_paths:
1287
+ # It can happen that some sources are skipped because they are TAPE, and others because
1288
+ # of scheme mismatch. However, we can only have one state in the database. I picked to
1289
+ # prioritize setting only_tape_source without any particular reason.
1290
+ if RestrictTapeSources.external_name in rejected_sources:
1291
+ logger(logging.DEBUG, '%s: Only tape sources found' % rws.request_id)
1292
+ reqs_only_tape_source.add(rws.request_id)
1293
+ reqs_no_source.remove(rws.request_id)
1294
+ elif SkipSchemeMissmatch.external_name in rejected_sources:
1295
+ logger(logging.DEBUG, '%s: Scheme mismatch detected' % rws.request_id)
1296
+ reqs_scheme_mismatch.add(rws.request_id)
1297
+ reqs_no_source.remove(rws.request_id)
1298
+ else:
1299
+ logger(logging.DEBUG, '%s: No candidate path found' % rws.request_id)
1300
+ continue
1301
+
1302
+ candidate_paths_by_request_id[rws.request_id] = [path for _, path in candidate_paths]
1303
+ reqs_no_source.remove(rws.request_id)
1304
+
1305
+ return candidate_paths_by_request_id, reqs_no_source, reqs_scheme_mismatch, reqs_only_tape_source, reqs_unsupported_transfertool
1306
+
1307
+
1308
+ def __add_compatible_schemes(schemes, allowed_schemes):
1309
+ """
1310
+ Add the compatible schemes to a list of schemes
1311
+ :param schemes: Schemes as input.
1312
+ :param allowed_schemes: Allowed schemes, only these can be in the output.
1313
+ :returns: List of schemes
1314
+ """
1315
+
1316
+ return_schemes = []
1317
+ for scheme in schemes:
1318
+ if scheme in allowed_schemes:
1319
+ return_schemes.append(scheme)
1320
+ for scheme_map_scheme in constants.SCHEME_MAP.get(scheme, []):
1321
+ if scheme_map_scheme not in allowed_schemes:
1322
+ continue
1323
+ else:
1324
+ return_schemes.append(scheme_map_scheme)
1325
+ return list(set(return_schemes))
1326
+
1327
+
1328
+ @read_session
1329
+ def list_transfer_admin_accounts(*, session: "Session") -> "set[InternalAccount]":
1330
+ """
1331
+ List admin accounts and cache the result in memory
1332
+ """
1333
+
1334
+ result = REGION_ACCOUNTS.get('transfer_admin_accounts')
1335
+ if isinstance(result, NoValue):
1336
+ result = [acc['account'] for acc in list_accounts(filter_={'admin': True}, session=session)]
1337
+ REGION_ACCOUNTS.set('transfer_admin_accounts', result)
1338
+ return set(result)
1339
+
1340
+
1341
+ def update_transfer_priority(transfers_to_update, logger=logging.log):
1342
+ """
1343
+ Update transfer priority in fts
1344
+
1345
+ :param transfers_to_update: dict {external_host1: {transfer_id1: priority, transfer_id2: priority, ...}, ...}
1346
+ :param logger: decorated logger instance
1347
+ """
1348
+
1349
+ for external_host, priority_by_transfer_id in transfers_to_update.items():
1350
+ transfertool_obj = FTS3Transfertool(external_host=external_host)
1351
+ for transfer_id, priority in priority_by_transfer_id.items():
1352
+ res = transfertool_obj.update_priority(transfer_id=transfer_id, priority=priority)
1353
+ logger(logging.DEBUG, "Updated transfer %s priority in transfertool to %s: %s" % (transfer_id, priority, res['http_message']))
1354
+
1355
+
1356
+ def cancel_transfers(transfers_to_cancel, logger=logging.log):
1357
+ """
1358
+ Cancel transfers in fts
1359
+
1360
+ :param transfers_to_cancel: dict {external_host1: {transfer_id1, transfer_id2}, external_host2: [...], ...}
1361
+ :param logger: decorated logger instance
1362
+ """
1363
+
1364
+ for external_host, transfer_ids in transfers_to_cancel.items():
1365
+ transfertool_obj = FTS3Transfertool(external_host=external_host)
1366
+ for transfer_id in transfer_ids:
1367
+ try:
1368
+ transfertool_obj.cancel(transfer_ids=[transfer_id])
1369
+ logger(logging.DEBUG, "Cancelled FTS3 transfer %s on %s" % (transfer_id, transfertool_obj))
1370
+ except Exception as error:
1371
+ logger(logging.WARNING, 'Could not cancel FTS3 transfer %s on %s: %s' % (transfer_id, transfertool_obj, str(error)))
1372
+
1373
+
1374
+ @METRICS.count_it
1375
+ def cancel_transfer(transfertool_obj, transfer_id):
1376
+ """
1377
+ Cancel a transfer based on external transfer id.
1378
+
1379
+ :param transfertool_obj: Transfertool object to be used for cancellation.
1380
+ :param transfer_id: External-ID as a 32 character hex string.
1381
+ """
1382
+
1383
+ try:
1384
+ transfertool_obj.cancel(transfer_ids=[transfer_id])
1385
+ except Exception:
1386
+ raise RucioException('Could not cancel FTS3 transfer %s on %s: %s' % (transfer_id, transfertool_obj, traceback.format_exc()))
1387
+
1388
+
1389
+ @transactional_session
1390
+ def prepare_transfers(
1391
+ candidate_paths_by_request_id: "dict[str, list[list[DirectTransfer]]]",
1392
+ logger: "LoggerFunction" = logging.log,
1393
+ transfertools: "Optional[list[str]]" = None,
1394
+ *,
1395
+ session: "Session",
1396
+ ) -> tuple[list[str], list[str]]:
1397
+ """
1398
+ Update transfer requests according to preparer settings.
1399
+ """
1400
+
1401
+ reqs_no_transfertool = []
1402
+ updated_reqs = []
1403
+ for request_id, candidate_paths in candidate_paths_by_request_id.items():
1404
+ selected_source = None
1405
+ transfertool = None
1406
+ rws = candidate_paths[0][-1].rws
1407
+
1408
+ for candidate_path in candidate_paths:
1409
+ source = candidate_path[0].src
1410
+ all_hops_ok = True
1411
+ transfertool = None
1412
+ for hop in candidate_path:
1413
+ common_transfertools = get_supported_transfertools(hop.src.rse, hop.dst.rse, transfertools=transfertools, session=session)
1414
+ if not common_transfertools:
1415
+ all_hops_ok = False
1416
+ break
1417
+ # We need the last hop transfertool. Always prioritize fts3 if it exists.
1418
+ transfertool = 'fts3' if 'fts3' in common_transfertools else common_transfertools.pop()
1419
+
1420
+ if all_hops_ok and transfertool:
1421
+ selected_source = source
1422
+ break
1423
+
1424
+ if not selected_source:
1425
+ reqs_no_transfertool.append(request_id)
1426
+ logger(logging.WARNING, '%s: all available sources were filtered', rws)
1427
+ continue
1428
+
1429
+ update_dict: "dict[Any, Any]" = {
1430
+ models.Request.state.name: _throttler_request_state(
1431
+ activity=rws.activity,
1432
+ source_rse=selected_source.rse,
1433
+ dest_rse=rws.dest_rse,
1434
+ session=session,
1435
+ ),
1436
+ models.Request.source_rse_id.name: selected_source.rse.id,
1437
+ }
1438
+ if transfertool:
1439
+ update_dict[models.Request.transfertool.name] = transfertool
1440
+
1441
+ request_core.update_request(rws.request_id, session=session, **update_dict)
1442
+ updated_reqs.append(request_id)
1443
+
1444
+ return updated_reqs, reqs_no_transfertool
1445
+
1446
+
1447
+ @stream_session
1448
+ def applicable_rse_transfer_limits(
1449
+ source_rse: "Optional[RseData]" = None,
1450
+ dest_rse: "Optional[RseData]" = None,
1451
+ activity: "Optional[str]" = None,
1452
+ *,
1453
+ session: "Session",
1454
+ ):
1455
+ """
1456
+ Find all RseTransferLimits which must be enforced for transfers between source and destination RSEs for the given activity.
1457
+ """
1458
+ source_limits = {}
1459
+ if source_rse:
1460
+ source_limits = source_rse.ensure_loaded(load_transfer_limits=True, session=session).transfer_limits.get(TransferLimitDirection.SOURCE, {})
1461
+ dest_limits = {}
1462
+ if dest_rse:
1463
+ dest_limits = dest_rse.ensure_loaded(load_transfer_limits=True, session=session).transfer_limits.get(TransferLimitDirection.DESTINATION, {})
1464
+
1465
+ if activity is not None:
1466
+ limit = source_limits.get(activity)
1467
+ if limit:
1468
+ yield limit
1469
+
1470
+ limit = dest_limits.get(activity)
1471
+ if limit:
1472
+ yield limit
1473
+
1474
+ # get "all_activities" limits
1475
+ limit = source_limits.get(None)
1476
+ if limit:
1477
+ yield limit
1478
+
1479
+ limit = dest_limits.get(None)
1480
+ if limit:
1481
+ yield limit
1482
+
1483
+
1484
+ def _throttler_request_state(activity, source_rse, dest_rse, *, session: "Session") -> RequestState:
1485
+ """
1486
+ Takes request attributes to return a new state for the request
1487
+ based on throttler settings. Always returns QUEUED,
1488
+ if the throttler mode is not set.
1489
+ """
1490
+ limit_found = False
1491
+ if any(applicable_rse_transfer_limits(activity=activity, source_rse=source_rse, dest_rse=dest_rse, session=session)):
1492
+ limit_found = True
1493
+
1494
+ return RequestState.WAITING if limit_found else RequestState.QUEUED
1495
+
1496
+
1497
+ @read_session
1498
+ def get_supported_transfertools(
1499
+ source_rse: "RseData",
1500
+ dest_rse: "RseData",
1501
+ transfertools: "Optional[list[str]]" = None,
1502
+ *,
1503
+ session: "Session",
1504
+ ) -> set[str]:
1505
+
1506
+ if not transfertools:
1507
+ transfertools = list(TRANSFERTOOL_CLASSES_BY_NAME)
1508
+
1509
+ source_rse.ensure_loaded(load_attributes=True, session=session)
1510
+ dest_rse.ensure_loaded(load_attributes=True, session=session)
1511
+
1512
+ result = set()
1513
+ for tt_name in transfertools:
1514
+ tt_class = TRANSFERTOOL_CLASSES_BY_NAME.get(tt_name)
1515
+ if tt_class and tt_class.can_perform_transfer(source_rse, dest_rse):
1516
+ result.add(tt_name)
1517
+ return result