Update demo/orchestrator.py
Browse files- demo/orchestrator.py +145 -160
demo/orchestrator.py
CHANGED
|
@@ -1,178 +1,163 @@
|
|
| 1 |
"""
|
| 2 |
-
Demo
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
class DemoOrchestrator:
|
| 10 |
-
"""
|
| 11 |
|
| 12 |
-
def __init__(self,
|
| 13 |
-
self.
|
| 14 |
-
self.
|
| 15 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
),
|
| 28 |
-
DemoStep(
|
| 29 |
-
title="OSS Analysis",
|
| 30 |
-
scenario="Cache Miss Storm",
|
| 31 |
-
action="oss",
|
| 32 |
-
message="Perfect analysis but requires manual work",
|
| 33 |
-
icon="🤖"
|
| 34 |
-
),
|
| 35 |
-
DemoStep(
|
| 36 |
-
title="Enterprise Magic",
|
| 37 |
-
scenario="Cache Miss Storm",
|
| 38 |
-
action="enterprise",
|
| 39 |
-
message="Watch ARF fix it automatically in minutes",
|
| 40 |
-
icon="⚡"
|
| 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 |
-
def
|
| 83 |
-
"""
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
return {
|
| 91 |
-
"
|
| 92 |
-
"
|
| 93 |
-
"
|
| 94 |
-
"
|
| 95 |
-
"
|
| 96 |
-
"
|
| 97 |
}
|
| 98 |
|
| 99 |
-
def
|
| 100 |
-
"""
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
margin: 15px 0;
|
| 110 |
-
border-left: 5px solid #4ECDC4;
|
| 111 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 112 |
-
'>
|
| 113 |
-
<div style='display: flex; align-items: center; margin-bottom: 10px;'>
|
| 114 |
-
<span style='font-size: 24px; margin-right: 10px;'>{step.icon}</span>
|
| 115 |
-
<h3 style='margin: 0;'>Step {self.current_step}: {step.title}</h3>
|
| 116 |
-
</div>
|
| 117 |
-
<p style='margin: 0 0 10px 0; font-size: 16px;'><b>What to say:</b> "{step.message}"</p>
|
| 118 |
-
<div style='
|
| 119 |
-
background: rgba(255,255,255,0.1);
|
| 120 |
-
padding: 10px;
|
| 121 |
-
border-radius: 5px;
|
| 122 |
-
margin-top: 10px;
|
| 123 |
-
'>
|
| 124 |
-
<span style='font-size: 14px; opacity: 0.9;'>👆 <b>Action:</b> {action_desc}</span>
|
| 125 |
-
</div>
|
| 126 |
-
</div>
|
| 127 |
-
"""
|
| 128 |
|
| 129 |
-
def
|
| 130 |
-
"""
|
| 131 |
return {
|
| 132 |
-
"
|
| 133 |
-
"
|
| 134 |
-
"
|
| 135 |
-
"
|
| 136 |
-
"icon": "🎉",
|
| 137 |
-
"html": """
|
| 138 |
-
<div style='
|
| 139 |
-
padding: 25px;
|
| 140 |
-
background: linear-gradient(135deg, #4ECDC4 0%, #44A08D 100%);
|
| 141 |
-
color: white;
|
| 142 |
-
border-radius: 10px;
|
| 143 |
-
text-align: center;
|
| 144 |
-
margin: 20px 0;
|
| 145 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 146 |
-
'>
|
| 147 |
-
<h2 style='margin: 0 0 15px 0;'>🎉 Demo Complete!</h2>
|
| 148 |
-
<p style='margin: 0; font-size: 18px;'>Ready for investor Q&A</p>
|
| 149 |
-
<div style='
|
| 150 |
-
margin-top: 20px;
|
| 151 |
-
padding: 15px;
|
| 152 |
-
background: rgba(255,255,255,0.1);
|
| 153 |
-
border-radius: 8px;
|
| 154 |
-
text-align: left;
|
| 155 |
-
'>
|
| 156 |
-
<h4 style='margin: 0 0 10px 0;'>Key Metrics Demonstrated:</h4>
|
| 157 |
-
<div style='display: grid; grid-template-columns: 1fr 1fr; gap: 10px;'>
|
| 158 |
-
<div>• 85% faster incident resolution</div>
|
| 159 |
-
<div>• 5.2× average ROI</div>
|
| 160 |
-
<div>• 81.7% auto-heal rate</div>
|
| 161 |
-
<div>• 2-3 month payback</div>
|
| 162 |
-
</div>
|
| 163 |
-
</div>
|
| 164 |
-
</div>
|
| 165 |
-
"""
|
| 166 |
}
|
| 167 |
|
| 168 |
-
def
|
| 169 |
-
"""
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
"
|
| 174 |
-
"
|
| 175 |
-
"
|
| 176 |
-
|
| 177 |
-
}
|
| 178 |
-
return actions.get(action, "Continue with demo")
|
|
|
|
| 1 |
"""
|
| 2 |
+
Demo Orchestrator - Integrates with ARF OSS framework
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import asyncio
|
| 6 |
+
import json
|
| 7 |
+
import datetime
|
| 8 |
+
from typing import Dict, List, Any, Optional, Tuple
|
| 9 |
+
import logging
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
|
| 14 |
class DemoOrchestrator:
|
| 15 |
+
"""Orchestrates the demo workflow using ARF OSS"""
|
| 16 |
|
| 17 |
+
def __init__(self, arf_client=None):
|
| 18 |
+
self.arf_client = arf_client
|
| 19 |
+
self.incident_history = []
|
| 20 |
+
self.execution_history = []
|
| 21 |
+
self.learning_stats = {
|
| 22 |
+
"patterns_detected": 0,
|
| 23 |
+
"similar_incidents_found": 0,
|
| 24 |
+
"healing_intents_created": 0
|
| 25 |
+
}
|
| 26 |
|
| 27 |
+
async def analyze_incident(self, scenario_name: str, scenario_data: Dict) -> Dict:
|
| 28 |
+
"""Analyze incident using ARF OSS"""
|
| 29 |
+
try:
|
| 30 |
+
if self.arf_client and hasattr(self.arf_client, 'analyze_and_recommend'):
|
| 31 |
+
# Use actual ARF OSS analysis
|
| 32 |
+
healing_intent = await self.arf_client.analyze_and_recommend(
|
| 33 |
+
tool_name="analyze",
|
| 34 |
+
component=scenario_data.get("component", "unknown"),
|
| 35 |
+
parameters=scenario_data.get("metrics", {}),
|
| 36 |
+
context={"scenario": scenario_name}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
)
|
| 38 |
+
|
| 39 |
+
self.learning_stats["healing_intents_created"] += 1
|
| 40 |
+
|
| 41 |
+
return {
|
| 42 |
+
"status": "success",
|
| 43 |
+
"healing_intent": healing_intent.to_enterprise_request(),
|
| 44 |
+
"analysis": {
|
| 45 |
+
"confidence": healing_intent.confidence,
|
| 46 |
+
"similar_incidents": healing_intent.similar_incidents,
|
| 47 |
+
"recommendation": healing_intent.justification
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Fallback to mock analysis
|
| 52 |
+
return {
|
| 53 |
+
"status": "success",
|
| 54 |
+
"analysis": {
|
| 55 |
+
"confidence": 0.85,
|
| 56 |
+
"similar_incidents": [
|
| 57 |
+
{"id": "inc_001", "similarity": 0.78, "component": "redis"},
|
| 58 |
+
{"id": "inc_045", "similarity": 0.65, "component": "database"}
|
| 59 |
+
],
|
| 60 |
+
"recommendation": f"Based on 2 similar incidents, recommend action for {scenario_name}"
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
logger.error(f"Analysis failed: {e}")
|
| 66 |
+
return {
|
| 67 |
+
"status": "error",
|
| 68 |
+
"message": str(e)
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
def execute_healing(self, scenario_name: str, healing_intent: Dict,
|
| 72 |
+
mode: str = "autonomous") -> Dict:
|
| 73 |
+
"""Execute healing action"""
|
| 74 |
+
execution_record = {
|
| 75 |
+
"id": f"exec_{len(self.execution_history):03d}",
|
| 76 |
+
"scenario": scenario_name,
|
| 77 |
+
"timestamp": datetime.datetime.now().isoformat(),
|
| 78 |
+
"mode": mode,
|
| 79 |
+
"healing_intent": healing_intent,
|
| 80 |
+
"status": "completed",
|
| 81 |
+
"results": {
|
| 82 |
+
"recovery_time_minutes": 12,
|
| 83 |
+
"cost_saved": 7200,
|
| 84 |
+
"users_impacted": "45,000 → 0"
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
self.execution_history.append(execution_record)
|
| 89 |
+
|
| 90 |
+
# Update learning stats
|
| 91 |
+
self.learning_stats["patterns_detected"] += 1
|
| 92 |
+
|
| 93 |
+
return execution_record
|
| 94 |
|
| 95 |
+
def get_similar_incidents(self, query: str, limit: int = 5) -> List[Dict]:
|
| 96 |
+
"""Find similar incidents"""
|
| 97 |
+
# This would integrate with ARF's RAG memory
|
| 98 |
+
return [
|
| 99 |
+
{
|
| 100 |
+
"id": "inc_001",
|
| 101 |
+
"similarity": 0.92,
|
| 102 |
+
"scenario": "Cache Miss Storm",
|
| 103 |
+
"resolution": "Scaled Redis cluster + circuit breaker",
|
| 104 |
+
"recovery_time": "12 minutes"
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"id": "inc_045",
|
| 108 |
+
"similarity": 0.78,
|
| 109 |
+
"scenario": "Database Connection Pool",
|
| 110 |
+
"resolution": "Increased pool size + monitoring",
|
| 111 |
+
"recovery_time": "18 minutes"
|
| 112 |
+
}
|
| 113 |
+
][:limit]
|
| 114 |
+
|
| 115 |
+
def calculate_roi(self, company_data: Dict) -> Dict:
|
| 116 |
+
"""Calculate ROI based on company data"""
|
| 117 |
+
monthly_incidents = company_data.get("monthly_incidents", 10)
|
| 118 |
+
avg_cost_per_incident = company_data.get("avg_cost_per_incident", 5000)
|
| 119 |
+
team_size = company_data.get("team_size", 3)
|
| 120 |
|
| 121 |
+
annual_impact = monthly_incidents * 12 * avg_cost_per_incident
|
| 122 |
+
team_cost = team_size * 150000 # $150k per engineer
|
| 123 |
+
savings = annual_impact * 0.82 # 82% savings with ARF
|
| 124 |
+
roi_multiplier = savings / team_cost if team_cost > 0 else 0
|
| 125 |
|
| 126 |
return {
|
| 127 |
+
"annual_impact": annual_impact,
|
| 128 |
+
"team_cost": team_cost,
|
| 129 |
+
"potential_savings": savings,
|
| 130 |
+
"roi_multiplier": roi_multiplier,
|
| 131 |
+
"payback_months": (team_cost / (savings / 12)) if savings > 0 else 0,
|
| 132 |
+
"recommendation": self._get_roi_recommendation(roi_multiplier)
|
| 133 |
}
|
| 134 |
|
| 135 |
+
def _get_roi_recommendation(self, roi_multiplier: float) -> str:
|
| 136 |
+
"""Get recommendation based on ROI"""
|
| 137 |
+
if roi_multiplier >= 5.0:
|
| 138 |
+
return "🚀 Excellent fit for ARF Enterprise"
|
| 139 |
+
elif roi_multiplier >= 2.0:
|
| 140 |
+
return "✅ Good ROI with ARF Enterprise"
|
| 141 |
+
elif roi_multiplier >= 1.0:
|
| 142 |
+
return "⚠️ Consider ARF OSS edition first"
|
| 143 |
+
else:
|
| 144 |
+
return "🆓 Start with ARF OSS (free)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
+
def get_audit_trail(self) -> Dict:
|
| 147 |
+
"""Get complete audit trail"""
|
| 148 |
return {
|
| 149 |
+
"incidents": self.incident_history,
|
| 150 |
+
"executions": self.execution_history,
|
| 151 |
+
"learning_stats": self.learning_stats,
|
| 152 |
+
"exported_at": datetime.datetime.now().isoformat()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
+
def reset_demo(self):
|
| 156 |
+
"""Reset demo state"""
|
| 157 |
+
self.incident_history = []
|
| 158 |
+
self.execution_history = []
|
| 159 |
+
self.learning_stats = {
|
| 160 |
+
"patterns_detected": 0,
|
| 161 |
+
"similar_incidents_found": 0,
|
| 162 |
+
"healing_intents_created": 0
|
| 163 |
+
}
|
|
|
|
|
|