stormchaser_model/dsl/workflow.rs
1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::HashMap;
5
6use super::{Handler, Step, Storage};
7
8/// Root structure representing a parsed workflow definition.
9#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10pub struct Workflow {
11 /// Indicates if this workflow is a reusable template.
12 #[serde(default)]
13 pub is_template: bool,
14 /// The version of the Stormchaser DSL used.
15 pub dsl_version: String,
16 /// The name of the workflow.
17 pub name: String,
18 /// Optional description of the workflow.
19 pub description: Option<String>,
20 /// Optional cron schedule for triggering the workflow.
21 pub cron: Option<String>,
22 /// External reusable workflows or templates imported.
23 pub libraries: Vec<Library>,
24 /// Custom step definitions imported for this workflow.
25 #[serde(default)]
26 pub step_libraries: Vec<StepLibrary>,
27 /// Sub-workflows included for execution.
28 #[serde(default)]
29 pub includes: Vec<Include>,
30 /// Execution strategy and constraints for the workflow.
31 pub strategy: Option<Strategy>,
32 /// Resource quotas applied to the entire workflow run.
33 pub quotas: Option<Quotas>,
34 /// Aliases defined for the workflow.
35 #[serde(default)]
36 pub aliases: HashMap<String, String>,
37 /// Storage configurations to provision.
38 pub storage: Vec<Storage>,
39 /// Expected inputs for the workflow.
40 pub inputs: Vec<Input>,
41 /// Dynamic queries.
42 #[serde(default)]
43 pub queries: Vec<Query>,
44 /// Compiled JSON schema for inputs.
45 #[serde(default)]
46 pub inputs_schema: Option<serde_json::Value>,
47 /// View configuration for inputs.
48 #[serde(default)]
49 pub inputs_view: Option<InputView>,
50 /// Outputs to be produced by the workflow.
51 pub outputs: Vec<Output>,
52 /// Event handlers for system or custom events.
53 pub handlers: Vec<Handler>,
54 /// The sequential or parallel steps to execute.
55 pub steps: Vec<Step>,
56 /// Steps to execute if the main workflow fails.
57 pub on_failure: Option<Vec<Step>>,
58 /// Steps to execute regardless of success or failure.
59 pub finally: Option<Vec<Step>>,
60}
61
62/// Import definition for external workflow templates.
63#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
64pub struct Library {
65 /// Alias to use when referencing this library.
66 pub name: String,
67 /// Source URI of the library.
68 pub source: String,
69 /// Specific version or reference of the library.
70 pub version: String,
71 /// Checksum to verify the library's integrity.
72 pub checksum: String,
73}
74
75use super::RetryPolicy;
76
77/// Import definition for external step types.
78#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
79pub struct StepLibrary {
80 /// Alias to use for the imported step type.
81 pub name: String,
82 /// The base step type being imported.
83 pub r#type: String,
84 /// Default parameters applied to the step.
85 #[serde(default)]
86 pub params: HashMap<String, String>,
87 /// Step specification override.
88 #[serde(default)]
89 pub spec: Value,
90 /// Default timeout for the step.
91 pub timeout: Option<String>,
92 /// Whether failures are ignored by default.
93 pub allow_failure: Option<bool>,
94 /// Default retry policy.
95 pub retry: Option<RetryPolicy>,
96}
97
98/// Defines an inclusion of another workflow.
99#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
100pub struct Include {
101 /// Name of the inclusion block.
102 pub name: String,
103 /// Reference to the workflow to include.
104 pub workflow: String,
105 /// Input variables to pass to the included workflow.
106 #[serde(default)]
107 pub inputs: HashMap<String, String>,
108}
109
110/// Execution strategy settings (e.g., parallelism, affinity).
111#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
112pub struct Strategy {
113 /// Runner affinity rules.
114 pub affinity: Option<String>,
115 /// Whether to abort all parallel steps if one fails.
116 pub fail_fast: Option<bool>,
117 /// Maximum number of parallel executions.
118 pub max_parallel: Option<u32>,
119 /// List of allowed processes or capabilities.
120 pub process_allow_list: Option<Vec<String>>,
121}
122
123/// Resource quotas for a run.
124#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
125pub struct Quotas {
126 /// Maximum concurrent steps.
127 pub max_concurrency: Option<u32>,
128 /// Maximum CPU limit.
129 pub max_cpu: Option<String>,
130 /// Maximum memory limit.
131 pub max_memory: Option<String>,
132 /// Maximum storage limit.
133 pub max_storage: Option<String>,
134 /// Maximum duration.
135 pub timeout: Option<String>,
136}
137
138/// Workflow input parameter definition.
139#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
140pub struct Input {
141 /// Name of the input variable.
142 pub name: String,
143 /// Data type of the input.
144 pub r#type: String,
145 /// Description of the input.
146 pub description: Option<String>,
147 /// Default value if not provided.
148 pub default: Option<Value>,
149 /// Regex or validation rule for the input.
150 pub validation: Option<String>,
151 /// Allowed options for enum-like inputs.
152 pub options: Option<Vec<String>>,
153}
154
155/// Dynamic query definition.
156#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]
157pub struct Query {
158 /// Name of the query variable.
159 pub name: String,
160 /// Type of the query.
161 pub r#type: String,
162 /// Parameters for the query.
163 #[serde(default)]
164 pub params: HashMap<String, String>,
165}
166
167/// Workflow output value definition.
168#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
169pub struct Output {
170 /// Name of the output variable.
171 pub name: String,
172 /// HCL Expression to evaluate the output value.
173 pub value: String, // HCL Expression
174}
175
176/// Describes the visual layout and presentation of inputs.
177#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]
178pub struct InputView {
179 /// Explicit ordering of input fields. Fields not listed are appended.
180 #[serde(default)]
181 pub ui_order: Vec<String>,
182}