|
43 | 43 | from .decoder import (
|
44 | 44 | Connector,
|
45 | 45 | get_step,
|
46 |
| - get_step_prior_step_plumbing, |
| 46 | + get_step_link_prefix_variables, |
| 47 | + get_step_prior_step_connections, |
47 | 48 | get_step_workflow_variable_connections,
|
48 | 49 | )
|
49 | 50 |
|
@@ -77,10 +78,15 @@ def __init__(
|
77 | 78 | *,
|
78 | 79 | wapi_adapter: WorkflowAPIAdapter,
|
79 | 80 | instance_launcher: InstanceLauncher,
|
| 81 | + step_link_prefix: str = ".instance-", |
80 | 82 | ):
|
| 83 | + """Initialiser, given a Workflow API adapter, Instance laucnher, |
| 84 | + and a step (directory) link prefix (the directory prefix the DM uses to hard-link |
| 85 | + prior step instanes into the next step, typically '.instance-')""" |
81 | 86 | # Keep the dependent objects
|
82 | 87 | self._wapi_adapter = wapi_adapter
|
83 | 88 | self._instance_launcher = instance_launcher
|
| 89 | + self._step_link_prefix = step_link_prefix |
84 | 90 |
|
85 | 91 | def handle_message(self, msg: Message) -> None:
|
86 | 92 | """Expect Workflow and Pod messages.
|
@@ -393,7 +399,7 @@ def _prepare_step(
|
393 | 399 | our_inputs: dict[str, Any] = job_defintion_decoder.get_inputs(
|
394 | 400 | our_job_definition
|
395 | 401 | )
|
396 |
| - our_plumbing: dict[str, list[Connector]] = get_step_prior_step_plumbing( |
| 402 | + our_plumbing: dict[str, list[Connector]] = get_step_prior_step_connections( |
397 | 403 | step_definition=step_definition
|
398 | 404 | )
|
399 | 405 | step_is_combiner: bool = False
|
@@ -483,60 +489,40 @@ def _prepare_step(
|
483 | 489 | assert connector.in_ in rwf_variables
|
484 | 490 | variables[connector.out] = rwf_variables[connector.in_]
|
485 | 491 |
|
| 492 | + # Process the step's "plumbing" relating to link-prefix variables. |
| 493 | + # |
| 494 | + # This will be a set of variable names. We just set each one |
| 495 | + # to the built-in step link prefix. |
| 496 | + for link_variable in get_step_link_prefix_variables( |
| 497 | + step_definition=step_definition |
| 498 | + ): |
| 499 | + variables[link_variable] = self._step_link_prefix |
| 500 | + |
486 | 501 | # Now process variables (in the "plumbing" block)
|
487 | 502 | # that relate to values used in prior steps.
|
488 | 503 | #
|
489 | 504 | # The decoder gives us a map indexed by prior step name that's a list of
|
490 |
| - # "in" "out" connectors as above. If this is a combiner step remember |
| 505 | + # "in"/"out" connectors as above. If this is a combiner step remember |
491 | 506 | # that the combiner_input_variable is a used as a list.
|
492 |
| - prior_step_plumbing: dict[str, list[Connector]] = get_step_prior_step_plumbing( |
493 |
| - step_definition=step_definition |
| 507 | + prior_step_plumbing: dict[str, list[Connector]] = ( |
| 508 | + get_step_prior_step_connections(step_definition=step_definition) |
494 | 509 | )
|
495 | 510 | for prior_step_name, connections in prior_step_plumbing.items():
|
496 |
| - if step_is_combiner and prior_step_name == step_name_being_combined: |
497 |
| - assert combiner_input_variable |
498 |
| - input_source_list: list[str] = [] |
499 |
| - for replica in range(num_step_recplicas_being_combined): |
500 |
| - prior_step, _ = ( |
501 |
| - self._wapi_adapter.get_running_workflow_step_by_name( |
502 |
| - name=prior_step_name, |
503 |
| - replica=replica, |
504 |
| - running_workflow_id=rwf_id, |
505 |
| - ) |
506 |
| - ) |
507 |
| - # Copy "in" value to "out"... |
508 |
| - # accumulating thiose for the 'combining' variable, |
509 |
| - # which will be set as a list when we're done. |
510 |
| - for connector in connections: |
511 |
| - assert connector.in_ in prior_step["variables"] |
512 |
| - if connector.out == combiner_input_variable: |
513 |
| - # Each instance may have a different value |
514 |
| - input_source_list.append( |
515 |
| - prior_step["variables"][connector.in_] |
516 |
| - ) |
517 |
| - elif replica == 0: |
518 |
| - # Only the first instance value are of interest, |
519 |
| - # the rest wil be the same - only one variable |
520 |
| - # is a list of different values. |
521 |
| - variables[connector.out] = prior_step["variables"][ |
522 |
| - connector.in_ |
523 |
| - ] |
524 |
| - # Now we have accumulated the prior steps values (files) |
525 |
| - # set the combiner's corresponding input variable... |
526 |
| - variables[combiner_input_variable] = input_source_list |
527 |
| - else: |
528 |
| - # Not a preior step for a combiner, |
529 |
| - # or not a step being combined in a combiner. |
530 |
| - # |
531 |
| - # Retrieve the prior "running" step |
532 |
| - # in order to get the variables that were set there... |
533 |
| - prior_step, _ = self._wapi_adapter.get_running_workflow_step_by_name( |
534 |
| - name=prior_step_name, running_workflow_id=rwf_id |
535 |
| - ) |
536 |
| - # Copy "in" value to "out"... |
537 |
| - for connector in connections: |
538 |
| - assert connector.in_ in prior_step["variables"] |
539 |
| - variables[connector.out] = prior_step["variables"][connector.in_] |
| 511 | + # Retrieve the first prior "running" step in order to get the variables |
| 512 | + # that were used for it. |
| 513 | + # |
| 514 | + # For a combiner step we only need to inspect the first instance of |
| 515 | + # the prior step (the default replica value is '0'). |
| 516 | + # We assume all the combiner's prior (parallel) instances |
| 517 | + # have the same variables and values. |
| 518 | + prior_step, _ = self._wapi_adapter.get_running_workflow_step_by_name( |
| 519 | + name=prior_step_name, |
| 520 | + running_workflow_id=rwf_id, |
| 521 | + ) |
| 522 | + # Copy "in" value to "out"... |
| 523 | + for connector in connections: |
| 524 | + assert connector.in_ in prior_step["variables"] |
| 525 | + variables[connector.out] = prior_step["variables"][connector.in_] |
540 | 526 |
|
541 | 527 | # All variables are set ...
|
542 | 528 | # is this enough to satisfy the setp's Job command?
|
|
0 commit comments