-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdev
More file actions
executable file
·221 lines (200 loc) · 6.96 KB
/
dev
File metadata and controls
executable file
·221 lines (200 loc) · 6.96 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# Meridian Platform CLI
# Unified entry point for platform operations
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS_DIR="${SCRIPT_DIR}/scripts"
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
show_help() {
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} ${BOLD}Meridian Platform CLI${NC}"
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "${BOLD}Usage:${NC} ./dev <command> [options]"
echo ""
echo -e "${BOLD}Commands:${NC}"
echo -e " ${GREEN}start${NC} Start the platform (tilt up)"
echo -e " ${GREEN}stop${NC} Stop the platform (tilt down)"
echo -e " ${GREEN}status${NC} Show platform status"
echo -e " ${GREEN}demo${NC} Run the comprehensive platform demo"
echo -e " ${GREEN}horizon${NC} Run Horizon Integrity Proof demo (standalone)"
echo -e " ${GREEN}doctor${NC} Check system health and dependencies"
echo -e " ${GREEN}logs${NC} View service logs (requires service name)"
echo -e " ${GREEN}help${NC} Show this help message"
echo ""
echo -e "${BOLD}Examples:${NC}"
echo -e " ./dev start # Start the platform"
echo -e " ./dev demo # Run full demo"
echo -e " ./dev horizon # Run Horizon integrity proof"
echo -e " ./dev doctor # Check dependencies"
echo -e " ./dev logs current-account"
echo ""
}
cmd_start() {
echo -e "${CYAN}Starting Meridian platform...${NC}"
cd "$SCRIPT_DIR"
tilt up "$@"
}
cmd_stop() {
echo -e "${CYAN}Stopping Meridian platform...${NC}"
cd "$SCRIPT_DIR"
tilt down "$@"
}
cmd_status() {
echo -e "${CYAN}Meridian Platform Status${NC}"
echo ""
if tilt get uisession >/dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Tilt is running"
echo ""
echo -e "${BOLD}Services:${NC}"
kubectl get pods 2>/dev/null | grep -E "(current-account|payment-order|position-keeping|financial-accounting)" || echo " No services found"
else
echo -e "${YELLOW}⚠${NC} Tilt is not running"
echo -e " Run: ${CYAN}./dev start${NC}"
fi
}
cmd_demo() {
if [ -f "${SCRIPTS_DIR}/demo.sh" ]; then
exec "${SCRIPTS_DIR}/demo.sh" "$@"
else
echo -e "${RED}✗${NC} Demo script not found: ${SCRIPTS_DIR}/demo.sh"
exit 1
fi
}
cmd_horizon() {
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} ${BOLD}Horizon Integrity Proof${NC}"
echo -e "${BLUE} Demonstrating resilience against phantom transactions${NC}"
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
echo ""
# Check if Tilt is running
if ! tilt get uisession >/dev/null 2>&1; then
echo -e "${YELLOW}⚠${NC} Tilt is not running. Starting..."
cmd_start &
TILT_PID=$!
# Verify Tilt started successfully
sleep 5
if ! kill -0 "$TILT_PID" 2>/dev/null; then
echo -e "${RED}✗${NC} Tilt startup failed"
exit 1
fi
# Wait for services
echo -e "${YELLOW}Waiting for services (this may take 2-3 minutes)...${NC}"
sleep 30
TIMEOUT=180
ELAPSED=30
while [ $ELAPSED -lt $TIMEOUT ]; do
if kubectl get pods 2>/dev/null | grep -q "current-account.*Running"; then
echo -e "${GREEN}✓${NC} Services ready"
break
fi
sleep 10
ELAPSED=$((ELAPSED + 10))
echo -e " ${YELLOW}Waiting... ($ELAPSED seconds)${NC}"
done
if [ $ELAPSED -ge $TIMEOUT ]; then
echo -e "${RED}✗${NC} Timeout waiting for services. Check: tilt status"
exit 1
fi
fi
# Mode selection
echo -e "${BOLD}Select demo mode:${NC}"
echo -e " ${GREEN}1)${NC} Happy Path - Normal operation"
echo -e " ${YELLOW}2)${NC} Unhappy Path - Network failure simulation"
echo -e " ${CYAN}3)${NC} Both"
echo ""
read -r -p "Enter choice [1-3]: " choice
local timeout_args=""
case $choice in
1)
echo -e "\n${CYAN}Running Happy Path...${NC}"
timeout_args="--timeout 5000ms"
;;
2)
echo -e "\n${CYAN}Running Unhappy Path...${NC}"
timeout_args="--timeout 30ms"
;;
3)
echo -e "\n${CYAN}Running Happy Path...${NC}"
cd "$SCRIPT_DIR"
go run ./utilities/horizon-demo --timeout 5000ms --output ./integrity_report_happy.json "$@"
echo ""
echo -e "${YELLOW}Press any key to continue to Unhappy Path...${NC}"
read -n 1 -s -r
echo -e "\n${CYAN}Running Unhappy Path...${NC}"
go run ./utilities/horizon-demo --timeout 30ms --output ./integrity_report_unhappy.json "$@"
return
;;
*)
timeout_args="--timeout 30ms"
;;
esac
cd "$SCRIPT_DIR"
go run ./utilities/horizon-demo "$timeout_args" --output ./integrity_report.json "$@"
}
cmd_doctor() {
if [ -f "${SCRIPTS_DIR}/doctor.sh" ]; then
MERIDIAN_CMD="./dev doctor" exec "${SCRIPTS_DIR}/doctor.sh" "$@"
else
echo -e "${RED}✗${NC} Doctor script not found: ${SCRIPTS_DIR}/doctor.sh"
exit 1
fi
}
cmd_logs() {
local service="$1"
if [ -z "$service" ]; then
echo -e "${YELLOW}Usage:${NC} ./dev logs <service-name>"
echo ""
echo -e "${BOLD}Available services:${NC}"
kubectl get pods --no-headers 2>/dev/null | awk '{print " " $1}' || echo " (none running)"
exit 1
fi
kubectl logs -f -l "app=$service" --all-containers=true "$@"
}
# Main command dispatch
case "${1:-help}" in
start)
shift
cmd_start "$@"
;;
stop)
shift
cmd_stop "$@"
;;
status)
shift
cmd_status "$@"
;;
demo)
shift
cmd_demo "$@"
;;
horizon)
shift
cmd_horizon "$@"
;;
doctor)
shift
cmd_doctor "$@"
;;
logs)
shift
cmd_logs "$@"
;;
help|--help|-h)
show_help
;;
*)
echo -e "${RED}Unknown command:${NC} $1"
echo ""
show_help
exit 1
;;
esac