Repository navigation
Expand file tree
/
Copy pathdemo.sh
More file actions
executable file
Β·240 lines (201 loc) Β· 8.33 KB
/
Copy pathdemo.sh
File metadata and controls
executable file
Β·240 lines (201 loc) Β· 8.33 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
# SlipStream Demo Script
# This script demonstrates the real-time anomaly detection capabilities
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Configuration
DEMO_DURATION=60 # seconds
KAFKA_CONTAINER="kafka"
# Auto-detect Docker/Podman compose command
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
COMPOSE_CMD="docker compose"
echo -e "${BLUE}π³ Using Docker Compose${NC}"
elif command -v podman >/dev/null 2>&1; then
COMPOSE_CMD="podman compose"
echo -e "${BLUE}π Using Podman Compose${NC}"
else
echo -e "${RED}β Neither Docker nor Podman compose found. Please install one of them.${NC}"
exit 1
fi
echo -e "${CYAN}"
cat << "EOF"
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π SLIPSTREAM DEMO π β
β Real-Time Kafka Anomaly Detection System β
β β
β This demo will showcase SlipStream's ability to detect β
β anomalies in transaction streams in real-time β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
EOF
echo -e "${NC}"
echo -e "${BLUE}π Demo Configuration:${NC}"
echo -e " β’ Duration: ${YELLOW}${DEMO_DURATION} seconds${NC}"
echo -e " β’ Kafka Server: ${YELLOW}localhost:9092${NC}"
echo -e " β’ Input Topic: ${YELLOW}transaction-events${NC}"
echo -e " β’ Output Topic: ${YELLOW}anomaly-alerts${NC}"
echo ""
# Function to check if Kafka is running
check_kafka() {
echo -e "${BLUE}π Checking Kafka status...${NC}"
if $COMPOSE_CMD ps kafka 2>/dev/null | grep -q "Up"; then
echo -e "${GREEN}β
Kafka is running${NC}"
return 0
else
echo -e "${RED}β Kafka is not running${NC}"
return 1
fi
}
# Function to start Kafka if not running
start_kafka() {
echo -e "${YELLOW}π Starting Kafka infrastructure...${NC}"
# For Podman, ensure the machine is running
if [[ "$COMPOSE_CMD" == *"podman"* ]]; then
echo -e "${BLUE}π§ Ensuring Podman machine is running...${NC}"
podman machine start 2>/dev/null || true
sleep 2
fi
$COMPOSE_CMD up -d
echo -e "${BLUE}β³ Waiting for Kafka to be ready...${NC}"
# Wait for Kafka to be ready
local retries=30
while [ $retries -gt 0 ]; do
if $COMPOSE_CMD exec kafka kafka-topics --bootstrap-server localhost:9092 --list >/dev/null 2>&1; then
echo -e "${GREEN}β
Kafka is ready!${NC}"
break
fi
echo -e "${YELLOW} Waiting for Kafka... ($retries retries left)${NC}"
sleep 2
retries=$((retries - 1))
done
if [ $retries -eq 0 ]; then
echo -e "${RED}β Failed to start Kafka${NC}"
exit 1
fi
}
# Function to create topics
create_topics() {
echo -e "${BLUE}π Creating Kafka topics...${NC}"
# Create topics if they don't exist
$COMPOSE_CMD exec kafka kafka-topics \
--create --if-not-exists \
--topic transaction-events \
--partitions 3 \
--replication-factor 1 \
--bootstrap-server localhost:9092
$COMPOSE_CMD exec kafka kafka-topics \
--create --if-not-exists \
--topic anomaly-alerts \
--partitions 3 \
--replication-factor 1 \
--bootstrap-server localhost:9092
echo -e "${GREEN}β
Topics created successfully${NC}"
}
# Function to build the application
build_app() {
echo -e "${BLUE}π¨ Building SlipStream application...${NC}"
mvn clean compile -q
if [ $? -eq 0 ]; then
echo -e "${GREEN}β
Build successful${NC}"
else
echo -e "${RED}β Build failed${NC}"
exit 1
fi
}
# Function to start the anomaly consumer in background
start_anomaly_monitor() {
echo -e "${BLUE}π Starting anomaly result monitor...${NC}"
# Start the anomaly consumer in a new terminal if possible, otherwise background
if command -v gnome-terminal >/dev/null 2>&1; then
gnome-terminal --title="Anomaly Monitor" -- bash -c "mvn exec:java -Dexec.mainClass='com.slipstream.demo.AnomalyResultConsumer' -q; read -p 'Press Enter to close...'"
elif command -v osascript >/dev/null 2>&1; then
# macOS Terminal
osascript -e 'tell app "Terminal" to do script "cd \"'$(pwd)'\" && mvn exec:java -Dexec.mainClass=\"com.slipstream.demo.AnomalyResultConsumer\" -q"'
else
# Fallback: run in background
nohup mvn exec:java -Dexec.mainClass='com.slipstream.demo.AnomalyResultConsumer' -q > anomaly-monitor.log 2>&1 &
ANOMALY_MONITOR_PID=$!
echo -e "${YELLOW} Monitor started in background (PID: $ANOMALY_MONITOR_PID)${NC}"
echo -e "${YELLOW} Logs available in: anomaly-monitor.log${NC}"
fi
}
# Function to start SlipStream main application
start_slipstream() {
echo -e "${BLUE}π― Starting SlipStream application...${NC}"
# Start SlipStream in a new terminal if possible, otherwise background
if command -v gnome-terminal >/dev/null 2>&1; then
gnome-terminal --title="SlipStream Core" -- bash -c "mvn exec:java -Dexec.mainClass='com.slipstream.SlipStreamApplication' -q; read -p 'Press Enter to close...'"
elif command -v osascript >/dev/null 2>&1; then
# macOS Terminal
osascript -e 'tell app "Terminal" to do script "cd \"'$(pwd)'\" && mvn exec:java -Dexec.mainClass=\"com.slipstream.SlipStreamApplication\" -q"'
else
# Fallback: run in background
nohup mvn exec:java -Dexec.mainClass='com.slipstream.SlipStreamApplication' -q > slipstream.log 2>&1 &
SLIPSTREAM_PID=$!
echo -e "${YELLOW} SlipStream started in background (PID: $SLIPSTREAM_PID)${NC}"
echo -e "${YELLOW} Logs available in: slipstream.log${NC}"
fi
}
# Function to generate demo transactions
start_demo_transactions() {
echo -e "${BLUE}π Starting transaction generator...${NC}"
echo -e "${YELLOW} Generating transactions for ${DEMO_DURATION} seconds${NC}"
echo -e "${CYAN} Watch the anomaly monitor for real-time detections!${NC}"
echo ""
mvn exec:java -Dexec.mainClass='com.slipstream.demo.TransactionGenerator' -Dexec.args="$DEMO_DURATION" -q
}
# Function to cleanup
cleanup() {
echo -e "\n${YELLOW}π§Ή Cleaning up...${NC}"
# Kill background processes if they exist
if [ ! -z "$ANOMALY_MONITOR_PID" ]; then
kill $ANOMALY_MONITOR_PID 2>/dev/null || true
fi
if [ ! -z "$SLIPSTREAM_PID" ]; then
kill $SLIPSTREAM_PID 2>/dev/null || true
fi
echo -e "${GREEN}β
Demo completed successfully!${NC}"
}
# Set up cleanup trap
trap cleanup EXIT
# Main demo execution
main() {
echo -e "${WHITE}π¬ Starting SlipStream Demo...${NC}"
echo ""
# Step 1: Check and start Kafka
if ! check_kafka; then
start_kafka
fi
# Step 2: Create topics
create_topics
# Step 3: Build application
build_app
# Step 4: Start anomaly monitor
start_anomaly_monitor
sleep 3
# Step 5: Start SlipStream
start_slipstream
sleep 5
echo -e "${GREEN}π All systems ready! Starting demo...${NC}"
echo -e "${CYAN}πΊ This would be perfect for screen recording!${NC}"
echo ""
# Step 6: Generate demo data
start_demo_transactions
echo ""
echo -e "${GREEN}π Demo completed! Check the anomaly monitor for detected anomalies.${NC}"
echo -e "${BLUE}π‘ Tip: You can run individual components separately:${NC}"
echo -e " β’ Transaction Generator: ${YELLOW}mvn exec:java -Dexec.mainClass='com.slipstream.demo.TransactionGenerator'${NC}"
echo -e " β’ Anomaly Monitor: ${YELLOW}mvn exec:java -Dexec.mainClass='com.slipstream.demo.AnomalyResultConsumer'${NC}"
echo -e " β’ SlipStream Core: ${YELLOW}mvn exec:java -Dexec.mainClass='com.slipstream.SlipStreamApplication'${NC}"
}
# Check if script is being run directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi