-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan_example.rs
More file actions
118 lines (104 loc) · 3.27 KB
/
plan_example.rs
File metadata and controls
118 lines (104 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Example: Planning and DAG execution
//!
//! Demonstrates:
//! - Creating plans
//! - Compiling to DAG
//! - DAG validation
//! - Topological execution
use oracle_omen_plan::{
compiler::PlanCompiler,
dsl::{BackoffStrategy, FailurePolicy, Plan, PlanStep, ResourceAnnotation, StepType},
validate::PlanValidator,
};
fn main() {
println!("Oracle Omen - Planning Example");
println!("==============================\n");
// Create a plan with dependencies
let mut plan = Plan::new("example_plan");
// Step 1: Read config (no dependencies)
plan.add_step(
PlanStep::new(
"read_config",
StepType::Tool {
name: "config_reader".to_string(),
version: "1.0.0".to_string(),
input: serde_json::json!({"path": "/etc/config.toml"}),
},
)
.requires("fs:read:/etc"),
);
// Step 2: Fetch data (no dependencies, can run parallel with step 1)
plan.add_step(
PlanStep::new(
"fetch_data",
StepType::Tool {
name: "http_fetch".to_string(),
version: "1.0.0".to_string(),
input: serde_json::json!({"url": "https://api.example.com/data"}),
},
)
.requires("network:http:get"),
);
// Step 3: Process data (depends on both)
plan.add_step(
PlanStep::new(
"process_data",
StepType::Tool {
name: "processor".to_string(),
version: "1.0.0".to_string(),
input: serde_json::json!({}),
},
)
.depends_on("read_config")
.depends_on("fetch_data"),
);
// Step 4: Write output (depends on process)
plan.add_step(
PlanStep::new(
"write_output",
StepType::Tool {
name: "file_writer".to_string(),
version: "1.0.0".to_string(),
input: serde_json::json!({"path": "/tmp/output.json"}),
},
)
.depends_on("process_data")
.requires("fs:write:/tmp"),
);
println!("Plan: {}", plan.name);
println!("Steps: {}\n", plan.len());
// Validate plan
match PlanValidator::validate(&plan) {
Ok(()) => println!("Plan validation: PASSED\n"),
Err(e) => {
println!("Plan validation: FAILED - {}\n", e);
return;
}
}
// Compile to DAG
let dag = match PlanCompiler::compile(&plan) {
Ok(dag) => dag,
Err(e) => {
println!("Compilation failed: {}", e);
return;
}
};
println!("DAG compiled: {} nodes\n", dag.len());
// Get topological order
let order = dag.topological_order().unwrap();
println!("Execution order:");
for (i, node_id) in order.iter().enumerate() {
println!(" {}. {}", i + 1, node_id);
// Show dependencies
let deps = dag.dependencies(node_id);
if !deps.is_empty() {
println!(" (depends on: {})", deps.iter().cloned().collect::<Vec<_>>().join(", "));
}
}
println!();
// Validate DAG
match PlanValidator::validate_dag(&dag) {
Ok(()) => println!("DAG validation: PASSED"),
Err(e) => println!("DAG validation: FAILED - {}", e),
}
}