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    /// CEL condition controlling whether the step runs.
29    pub condition: Option<String>,
30    /// Evaluated parameters for the step.
31    pub params: HashMap<String, String>, // CEL 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    /// Retry policy for this step.
54    pub retry: Option<RetryPolicy>,
55    /// Timeout duration.
56    pub timeout: Option<String>,
57    /// Whether failure of this step should be ignored.
58    pub allow_failure: Option<bool>,
59    /// Log marker indicating the start of a section.
60    pub start_marker: Option<String>,
61    /// Log marker indicating the end of a section.
62    pub end_marker: Option<String>,
63    /// Extraction rules to capture output values.
64    pub outputs: Vec<OutputExtraction>,
65    /// Test reports to collect.
66    #[serde(default)]
67    pub reports: Vec<TestReport>,
68    /// Specific artifacts to collect for this step.
69    #[serde(default)]
70    pub artifacts: Option<Vec<String>>,
71}
72
73/// Definition for capturing a test report.
74#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
75pub struct TestReport {
76    /// Name of the report.
77    pub name: String,
78    /// Path to the report file.
79    pub path: String,
80    /// Format of the report (e.g., 'junit').
81    pub format: String, // e.g., "junit"
82}
83
84/// Aggregation rule for map/reduce patterns.
85#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
86pub struct Aggregation {
87    /// Name of the aggregation.
88    pub name: String,
89    /// Optional description.
90    pub description: Option<String>,
91    /// CEL Expression for aggregation.
92    pub value: String, // CEL Expression
93}
94
95/// Rule for extracting outputs from logs or files.
96#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
97pub struct OutputExtraction {
98    /// Output key name.
99    pub name: String,
100    /// Source to extract from (e.g., 'stdout', 'file').
101    pub source: String,
102    /// Optional marker string.
103    pub marker: Option<String>,
104    /// Data format (e.g., 'json', 'regex').
105    pub format: Option<String>,
106    /// Regular expression to match.
107    pub regex: Option<String>,
108    /// Regex capture group index.
109    pub group: Option<u32>,
110    /// Whether the extracted output is sensitive.
111    pub sensitive: Option<bool>,
112}
113
114/// Step retry policy definition.
115#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
116pub struct RetryPolicy {
117    /// Number of retry attempts.
118    pub count: u32,
119    /// Backoff strategy ('fixed', 'exponential').
120    pub backoff: String,
121    /// Maximum backoff delay.
122    pub max_delay: Option<String>,
123}