Skip to main content

stormchaser_model/dsl/
step.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::HashMap;
5
6use super::Strategy;
7
8/// Event handler mapping an event to an action.
9#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10pub struct Handler {
11    /// Name of the handler.
12    pub name: String,
13    /// Type of event to match.
14    pub event_type: String,
15    /// Condition expression to filter events.
16    pub condition: Option<String>,
17    /// Action to execute when the event occurs.
18    pub action: String,
19}
20
21/// Execution step definition within a workflow.
22#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
23pub struct Step {
24    /// Name of the step.
25    pub name: String,
26    /// Type of the step.
27    pub r#type: String, // e.g., "GitCheckout", "RunContainer", "Parallel", etc.
28    /// HCL condition controlling whether the step runs.
29    pub condition: Option<String>,
30    /// Evaluated parameters for the step.
31    pub params: HashMap<String, String>, // HCL Expressions
32
33    /// Step-specific specification.
34    /// This allows each step type to define its own structured parameters.
35    /// For "RunContainer" on K8s, this would be a K8sJobSpec.
36    #[serde(default)]
37    pub spec: Value,
38
39    /// Execution strategy overrides for this step.
40    pub strategy: Option<Strategy>,
41    /// Values to aggregate from iterated steps.
42    pub aggregation: Vec<Aggregation>,
43    /// Iteration expression (e.g., a list of items to map over).
44    pub iterate: Option<String>,
45    /// Variable name for the current iteration item.
46    pub iterate_as: Option<String>,
47    /// Child steps if this is a group (e.g., Parallel).
48    pub steps: Option<Vec<Step>>, // For Parallel/Sequential
49    /// Next steps to execute after this one.
50    pub next: Vec<String>,
51    /// Steps to execute if this step fails.
52    pub on_failure: Option<Box<Step>>,
53    /// Aliases defined explicitly for this step.
54    #[serde(default)]
55    pub aliases: HashMap<String, String>,
56    /// Retry policy for this step.
57    pub retry: Option<RetryPolicy>,
58    /// Timeout duration.
59    pub timeout: Option<String>,
60    /// Whether failure of this step should be ignored.
61    pub allow_failure: Option<bool>,
62    /// Log marker indicating the start of a section.
63    pub start_marker: Option<String>,
64    /// Log marker indicating the end of a section.
65    pub end_marker: Option<String>,
66    /// Extraction rules to capture output values.
67    pub outputs: Vec<OutputExtraction>,
68    /// Test reports to collect.
69    #[serde(default)]
70    pub reports: Vec<TestReport>,
71    /// Specific artifacts to collect for this step.
72    #[serde(default)]
73    pub artifacts: Option<Vec<String>>,
74}
75
76/// Definition for capturing a test report.
77#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
78pub struct TestReport {
79    /// Name of the report.
80    pub name: String,
81    /// Path to the report file.
82    pub path: String,
83    /// Format of the report (e.g., 'junit').
84    pub format: String, // e.g., "junit"
85}
86
87/// Aggregation rule for map/reduce patterns.
88#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
89pub struct Aggregation {
90    /// Name of the aggregation.
91    pub name: String,
92    /// Optional description.
93    pub description: Option<String>,
94    /// HCL Expression for aggregation.
95    pub value: String, // HCL Expression
96}
97
98/// Rule for extracting outputs from logs or files.
99#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
100pub struct OutputExtraction {
101    /// Output key name.
102    pub name: String,
103    /// Source to extract from (e.g., 'stdout', 'file').
104    pub source: String,
105    /// Optional marker string.
106    pub marker: Option<String>,
107    /// Data format (e.g., 'json', 'regex').
108    pub format: Option<String>,
109    /// Regular expression to match.
110    pub regex: Option<String>,
111    /// Regex capture group index.
112    pub group: Option<u32>,
113    /// Whether the extracted output is sensitive.
114    pub sensitive: Option<bool>,
115}
116
117/// Step retry policy definition.
118#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
119pub struct RetryPolicy {
120    /// Number of retry attempts.
121    pub count: u32,
122    /// Backoff strategy ('fixed', 'exponential').
123    pub backoff: String,
124    /// Maximum backoff delay.
125    pub max_delay: Option<String>,
126}