2.11. 抽象操作#
抽象操作 (Operation) 与工作流、命令行工具或表达式工具类似,是一种 CWL 流程。作为工作流中的一个步骤,它可以指定输入和输出,但不完全提供具体执行所需的信息。
在开发周期中,工作流准备就绪、可以提交给 CWL 运行程序之前,您可以创建抽象操作,将工作流可视化:
operations.cwl#cwlVersion: v1.2
class: Workflow
inputs:
message: string
outputs: []
steps:
echo:
run: ../echo.cwl
in:
message: message
out: [out]
# Here you know you want an operation that changes the case of
# the previous step, but you do not have an implementation yet.
uppercase:
run:
class: Operation
inputs:
message: string
outputs:
uppercase_message: string
in:
message:
source: echo/out
out: [uppercase_message]
工作流中的 uppercase 步骤是一个操作,可以出现在命令行工具或表达式能出现的任何位置。您还可以用 CWL Viewer 或 cwltool 将它绘制出来:
$ cwltool --print-dot operations.cwl
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.2.20260411152607
INFO Resolved 'operations.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/operations/operations.cwl'
digraph G {
bgcolor="#eeeeee";
clusterrank=local;
labelloc=bottom;
labeljust=right;
"echo" [fillcolor=lightgoldenrodyellow, style=filled, label=echo, shape=record];
"uppercase" [fillcolor=lightgoldenrodyellow, style=dashed, label=uppercase, shape=record];
"echo" -> "uppercase";
subgraph cluster_inputs {
rank=same;
style=dashed;
label="Workflow Inputs";
"message" [fillcolor="#94DDF4", style=filled, label=message, shape=record];
}
"message" -> "echo";
subgraph cluster_outputs {
rank=same;
style=dashed;
label="Workflow Outputs";
labelloc=b;
}
}
The output of the command above can be rendered cwltool --print-dot operations.cwl | dot -Tsvg > operations.svg ; open operations.svg.
用 cwltool 运行该操作文件将会失败,因为 cwltool 缺少执行所需的必要信息:
cwltool 不知道如何运行抽象操作#$ cwltool operations.cwl --message Hello
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.2.20260411152607
INFO Resolved 'operations.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/operations/operations.cwl'
ERROR Workflow error, try again with --debug for more information:
operations.cwl:19:7: Workflow has unrunnable abstract Operation
备注
CWL 运行程序可能安排一些将抽象操作绑定到具体步骤的方法。例如,带有 ID 的抽象操作有可能对映到其他工作流引擎中执行的步骤。