1use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9use std::collections::{HashMap, VecDeque};
10use std::sync::Arc;
11use tokio::sync::RwLock;
12
13use crate::event::StreamEvent;
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct VisualDesignerConfig {
18 pub enable_auto_layout: bool,
19 pub enable_validation: bool,
20 pub enable_optimization: bool,
21 pub max_nodes: usize,
22 pub max_edges: usize,
23 pub enable_real_time_debug: bool,
24 pub debug_buffer_size: usize,
25 pub enable_profiling: bool,
26 pub export_formats: Vec<ExportFormat>,
27}
28
29impl Default for VisualDesignerConfig {
30 fn default() -> Self {
31 Self {
32 enable_auto_layout: true,
33 enable_validation: true,
34 enable_optimization: true,
35 max_nodes: 1000,
36 max_edges: 5000,
37 enable_real_time_debug: true,
38 debug_buffer_size: 10000,
39 enable_profiling: true,
40 export_formats: vec![
41 ExportFormat::Json,
42 ExportFormat::Yaml,
43 ExportFormat::Dot,
44 ExportFormat::Mermaid,
45 ],
46 }
47 }
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
52pub enum ExportFormat {
53 Json,
54 Yaml,
55 Dot, Mermaid, Svg, Png, }
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct PipelineNode {
64 pub id: String,
65 pub name: String,
66 pub node_type: NodeType,
67 pub position: Position,
68 pub config: NodeConfig,
69 pub metadata: NodeMetadata,
70 pub status: NodeStatus,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
75pub enum NodeType {
76 Source(SourceType),
78 Map,
80 Filter,
81 FlatMap,
82 Reduce,
83 Aggregate,
84 Join,
85 Window,
86 Transform(TransformType),
88 MLModel(MLModelType),
90 Sink(SinkType),
92 Router,
94 Splitter,
95 Merger,
96 Breakpoint,
98 Logger,
99 Profiler,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
104pub enum SourceType {
105 Kafka,
106 Nats,
107 Redis,
108 Memory,
109 File,
110 WebSocket,
111 Http,
112 Custom(String),
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
117pub enum TransformType {
118 RdfTransform,
119 SparqlQuery,
120 GraphPattern,
121 Custom(String),
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
126pub enum MLModelType {
127 OnlineLearning,
128 AnomalyDetection,
129 Prediction,
130 Classification,
131 Clustering,
132 Custom(String),
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
137pub enum SinkType {
138 Kafka,
139 Nats,
140 Redis,
141 Memory,
142 Database,
143 File,
144 WebSocket,
145 Http,
146 Custom(String),
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct Position {
152 pub x: f64,
153 pub y: f64,
154 pub z: Option<f64>, }
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct NodeConfig {
160 pub parameters: HashMap<String, ConfigValue>,
161 pub input_ports: Vec<Port>,
162 pub output_ports: Vec<Port>,
163 pub resource_limits: ResourceLimits,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize)]
168#[serde(untagged)]
169pub enum ConfigValue {
170 String(String),
171 Number(f64),
172 Boolean(bool),
173 Array(Vec<ConfigValue>),
174 Object(HashMap<String, ConfigValue>),
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
179pub struct Port {
180 pub id: String,
181 pub name: String,
182 pub port_type: PortType,
183 pub data_type: DataType,
184 pub required: bool,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
189pub enum PortType {
190 Input,
191 Output,
192}
193
194#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
196pub enum DataType {
197 StreamEvent,
198 RdfTriple,
199 SparqlResult,
200 Json,
201 Binary,
202 Custom(String),
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize)]
207pub struct ResourceLimits {
208 pub max_memory_mb: Option<u64>,
209 pub max_cpu_percent: Option<f64>,
210 pub max_execution_time_ms: Option<u64>,
211 pub max_events_per_second: Option<u64>,
212}
213
214#[derive(Debug, Clone, Serialize, Deserialize)]
216pub struct NodeMetadata {
217 pub created_at: DateTime<Utc>,
218 pub updated_at: DateTime<Utc>,
219 pub version: String,
220 pub author: Option<String>,
221 pub description: Option<String>,
222 pub tags: Vec<String>,
223}
224
225#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
227pub enum NodeStatus {
228 Idle,
229 Running,
230 Paused,
231 Error(String),
232 Completed,
233}
234
235#[derive(Debug, Clone, Serialize, Deserialize)]
237pub struct PipelineEdge {
238 pub id: String,
239 pub source_node_id: String,
240 pub source_port_id: String,
241 pub target_node_id: String,
242 pub target_port_id: String,
243 pub edge_type: EdgeType,
244 pub config: EdgeConfig,
245 pub metadata: EdgeMetadata,
246}
247
248#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
250pub enum EdgeType {
251 DataFlow,
252 ControlFlow,
253 Conditional(Condition),
254}
255
256#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
258pub struct Condition {
259 pub expression: String,
260 pub predicate_type: PredicateType,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
265pub enum PredicateType {
266 Equals,
267 NotEquals,
268 GreaterThan,
269 LessThan,
270 Contains,
271 Matches,
272 Custom(String),
273}
274
275#[derive(Debug, Clone, Serialize, Deserialize)]
277pub struct EdgeConfig {
278 pub buffer_size: usize,
279 pub backpressure_strategy: BackpressureStrategy,
280 pub error_handling: ErrorHandling,
281}
282
283#[derive(Debug, Clone, Serialize, Deserialize)]
285pub enum BackpressureStrategy {
286 Drop,
287 Buffer,
288 Block,
289 Exponential,
290 Adaptive,
291}
292
293#[derive(Debug, Clone, Serialize, Deserialize)]
295pub enum ErrorHandling {
296 Propagate,
297 Ignore,
298 Retry { max_attempts: u32 },
299 DeadLetter,
300 Custom(String),
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize)]
305pub struct EdgeMetadata {
306 pub created_at: DateTime<Utc>,
307 pub label: Option<String>,
308 pub style: EdgeStyle,
309}
310
311#[derive(Debug, Clone, Serialize, Deserialize)]
313pub struct EdgeStyle {
314 pub color: String,
315 pub thickness: f64,
316 pub line_type: LineType,
317}
318
319#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
321pub enum LineType {
322 Solid,
323 Dashed,
324 Dotted,
325 Curved,
326}
327
328#[derive(Debug, Clone, Serialize, Deserialize)]
330pub struct VisualPipeline {
331 pub id: String,
332 pub name: String,
333 pub description: Option<String>,
334 pub version: String,
335 pub nodes: HashMap<String, PipelineNode>,
336 pub edges: HashMap<String, PipelineEdge>,
337 pub metadata: PipelineMetadata,
338 pub validation_result: Option<ValidationResult>,
339}
340
341#[derive(Debug, Clone, Serialize, Deserialize)]
343pub struct PipelineMetadata {
344 pub created_at: DateTime<Utc>,
345 pub updated_at: DateTime<Utc>,
346 pub author: Option<String>,
347 pub tags: Vec<String>,
348 pub properties: HashMap<String, String>,
349}
350
351#[derive(Debug, Clone, Serialize, Deserialize)]
353pub struct ValidationResult {
354 pub is_valid: bool,
355 pub errors: Vec<ValidationError>,
356 pub warnings: Vec<ValidationWarning>,
357 pub validated_at: DateTime<Utc>,
358}
359
360#[derive(Debug, Clone, Serialize, Deserialize)]
362pub struct ValidationError {
363 pub error_type: ValidationErrorType,
364 pub message: String,
365 pub node_id: Option<String>,
366 pub edge_id: Option<String>,
367}
368
369#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
371pub enum ValidationErrorType {
372 MissingRequiredPort,
373 IncompatibleDataTypes,
374 CyclicDependency,
375 DisconnectedNode,
376 InvalidConfiguration,
377 ResourceLimitExceeded,
378 DuplicateNodeId,
379}
380
381#[derive(Debug, Clone, Serialize, Deserialize)]
383pub struct ValidationWarning {
384 pub warning_type: ValidationWarningType,
385 pub message: String,
386 pub node_id: Option<String>,
387 pub suggestion: Option<String>,
388}
389
390#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
392pub enum ValidationWarningType {
393 UnusedPort,
394 SuboptimalConfiguration,
395 PerformanceBottleneck,
396 MemoryPressure,
397 DeprecatedNode,
398}
399
400#[derive(Debug)]
402pub struct PipelineDebugger {
403 pub pipeline: VisualPipeline,
404 pub config: DebuggerConfig,
405 pub state: Arc<RwLock<DebuggerState>>,
406 pub breakpoints: Arc<RwLock<HashMap<String, Breakpoint>>>,
407 pub event_history: Arc<RwLock<VecDeque<DebugEvent>>>,
408}
409
410#[derive(Debug, Clone, Serialize, Deserialize)]
412pub struct DebuggerConfig {
413 pub enable_breakpoints: bool,
414 pub enable_event_capture: bool,
415 pub max_event_history: usize,
416 pub enable_time_travel: bool,
417 pub enable_profiling: bool,
418 pub capture_intermediate_results: bool,
419}
420
421impl Default for DebuggerConfig {
422 fn default() -> Self {
423 Self {
424 enable_breakpoints: true,
425 enable_event_capture: true,
426 max_event_history: 10000,
427 enable_time_travel: true,
428 enable_profiling: true,
429 capture_intermediate_results: true,
430 }
431 }
432}
433
434#[derive(Debug, Clone, Serialize, Deserialize)]
436pub struct DebuggerState {
437 pub is_running: bool,
438 pub is_paused: bool,
439 pub current_node_id: Option<String>,
440 pub execution_stack: Vec<String>,
441 pub variables: HashMap<String, DebugVariable>,
442 pub metrics: DebugMetrics,
443}
444
445#[derive(Debug, Clone, Serialize, Deserialize)]
447pub struct DebugVariable {
448 pub name: String,
449 pub value: String,
450 pub var_type: String,
451 pub scope: String,
452}
453
454#[derive(Debug, Clone, Serialize, Deserialize, Default)]
456pub struct DebugMetrics {
457 pub events_processed: u64,
458 pub events_dropped: u64,
459 pub average_latency_ms: f64,
460 pub throughput_per_second: f64,
461 pub memory_usage_mb: f64,
462 pub cpu_usage_percent: f64,
463}
464
465#[derive(Debug, Clone, Serialize, Deserialize)]
467pub struct Breakpoint {
468 pub id: String,
469 pub node_id: String,
470 pub condition: Option<String>,
471 pub enabled: bool,
472 pub hit_count: u64,
473 pub max_hits: Option<u64>,
474}
475
476#[derive(Debug, Clone, Serialize, Deserialize)]
478pub struct DebugEvent {
479 pub timestamp: DateTime<Utc>,
480 pub node_id: String,
481 pub event_type: DebugEventType,
482 pub data: StreamEvent,
483 pub metadata: HashMap<String, String>,
484}
485
486#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
488pub enum DebugEventType {
489 NodeEnter,
490 NodeExit,
491 BreakpointHit,
492 Error,
493 Warning,
494}
495
496#[derive(Debug, Clone, Serialize, Deserialize)]
498pub struct PipelineInfo {
499 pub id: String,
500 pub name: String,
501 pub version: String,
502 pub node_count: usize,
503 pub edge_count: usize,
504 pub created_at: DateTime<Utc>,
505 pub updated_at: DateTime<Utc>,
506}
507
508#[derive(Debug, Clone, Serialize, Deserialize)]
510pub struct OptimizationResult {
511 pub original_metrics: PipelineMetrics,
512 pub suggestions: Vec<OptimizationSuggestion>,
513 pub optimized_at: DateTime<Utc>,
514}
515
516#[derive(Debug, Clone, Serialize, Deserialize)]
518pub struct PipelineMetrics {
519 pub node_count: usize,
520 pub edge_count: usize,
521 pub avg_chain_length: f64,
522 pub max_chain_length: usize,
523 pub parallel_opportunities: usize,
524 pub bottleneck_nodes: Vec<String>,
525}
526
527#[derive(Debug, Clone, Serialize, Deserialize)]
529pub struct OptimizationSuggestion {
530 pub suggestion_type: OptimizationType,
531 pub impact: ImpactLevel,
532 pub description: String,
533 pub estimated_improvement: f64,
534}
535
536#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
538pub enum OptimizationType {
539 ReduceChainLength,
540 IncreaseParallelism,
541 OptimizeBufferSize,
542 ReduceMemoryUsage,
543 ImproveLocality,
544}
545
546#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
548pub enum ImpactLevel {
549 Low,
550 Medium,
551 High,
552 Critical,
553}
554
555pub struct PipelineValidator {
557 pub(crate) config: VisualDesignerConfig,
558}
559
560pub struct PipelineOptimizer {
562 pub(crate) config: VisualDesignerConfig,
563}