aboutsummaryrefslogtreecommitdiff
path: root/seaweedfs-rdma-sidecar/scripts/run-mount-rdma-tests.sh
blob: e4237a5a2c7fa0c2dd908254edb8656413999917 (plain)
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash

set -euo pipefail

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Configuration
COMPOSE_FILE="docker-compose.mount-rdma.yml"
PROJECT_NAME="seaweedfs-rdma-mount"

# Function to show usage
show_usage() {
    echo -e "${BLUE}๐Ÿš€ SeaweedFS RDMA Mount Test Runner${NC}"
    echo "===================================="
    echo ""
    echo "Usage: $0 [COMMAND] [OPTIONS]"
    echo ""
    echo "Commands:"
    echo "  start           Start the RDMA mount environment"
    echo "  stop            Stop and cleanup the environment"
    echo "  restart         Restart the environment"
    echo "  status          Show status of all services"
    echo "  logs [service]  Show logs for all services or specific service"
    echo "  test            Run integration tests"
    echo "  perf            Run performance tests"
    echo "  shell           Open shell in mount container"
    echo "  cleanup         Full cleanup including volumes"
    echo ""
    echo "Services:"
    echo "  seaweedfs-master    SeaweedFS master server"
    echo "  seaweedfs-volume    SeaweedFS volume server"
    echo "  seaweedfs-filer     SeaweedFS filer server"
    echo "  rdma-engine         RDMA engine (Rust)"
    echo "  rdma-sidecar        RDMA sidecar (Go)"
    echo "  seaweedfs-mount     SeaweedFS mount with RDMA"
    echo ""
    echo "Examples:"
    echo "  $0 start                    # Start all services"
    echo "  $0 logs seaweedfs-mount     # Show mount logs"
    echo "  $0 test                     # Run integration tests"
    echo "  $0 perf                     # Run performance tests"
    echo "  $0 shell                    # Open shell in mount container"
}

# Function to check if Docker Compose is available
check_docker_compose() {
    if ! command -v docker-compose >/dev/null 2>&1 && ! docker compose version >/dev/null 2>&1; then
        echo -e "${RED}โŒ Docker Compose is not available${NC}"
        echo "Please install Docker Compose to continue"
        exit 1
    fi
    
    # Use docker compose if available, otherwise docker-compose
    if docker compose version >/dev/null 2>&1; then
        DOCKER_COMPOSE="docker compose"
    else
        DOCKER_COMPOSE="docker-compose"
    fi
}

# Function to build required images
build_images() {
    echo -e "${BLUE}๐Ÿ”จ Building required Docker images...${NC}"
    
    # Build SeaweedFS binary first
    echo "Building SeaweedFS binary..."
    cd ..
    make
    cd seaweedfs-rdma-sidecar
    
    # Copy binary for Docker builds
    mkdir -p bin
    if [[ -f "../weed" ]]; then
        cp ../weed bin/
    elif [[ -f "../bin/weed" ]]; then
        cp ../bin/weed bin/
    elif [[ -f "../build/weed" ]]; then
        cp ../build/weed bin/
    else
        echo "Error: Cannot find weed binary"
        find .. -name "weed" -type f
        exit 1
    fi
    
    # Build RDMA sidecar
    echo "Building RDMA sidecar..."
    go build -o bin/demo-server cmd/sidecar/main.go
    
    # Build Docker images
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" build
    
    echo -e "${GREEN}โœ… Images built successfully${NC}"
}

# Function to start services
start_services() {
    echo -e "${BLUE}๐Ÿš€ Starting SeaweedFS RDMA Mount environment...${NC}"
    
    # Build images if needed
    if [[ ! -f "bin/weed" ]] || [[ ! -f "bin/demo-server" ]]; then
        build_images
    fi
    
    # Start services
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" up -d
    
    echo -e "${GREEN}โœ… Services started${NC}"
    echo ""
    echo "Services are starting up. Use '$0 status' to check their status."
    echo "Use '$0 logs' to see the logs."
}

# Function to stop services
stop_services() {
    echo -e "${BLUE}๐Ÿ›‘ Stopping SeaweedFS RDMA Mount environment...${NC}"
    
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" down
    
    echo -e "${GREEN}โœ… Services stopped${NC}"
}

# Function to restart services
restart_services() {
    echo -e "${BLUE}๐Ÿ”„ Restarting SeaweedFS RDMA Mount environment...${NC}"
    
    stop_services
    sleep 2
    start_services
}

# Function to show status
show_status() {
    echo -e "${BLUE}๐Ÿ“Š Service Status${NC}"
    echo "================"
    
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps
    
    echo ""
    echo -e "${BLUE}๐Ÿ” Health Checks${NC}"
    echo "==============="
    
    # Check individual services
    check_service_health "SeaweedFS Master" "http://localhost:9333/cluster/status"
    check_service_health "SeaweedFS Volume" "http://localhost:8080/status"
    check_service_health "SeaweedFS Filer" "http://localhost:8888/"
    check_service_health "RDMA Sidecar" "http://localhost:8081/health"
    
    # Check mount status
    echo -n "SeaweedFS Mount: "
    if docker exec "${PROJECT_NAME}-seaweedfs-mount-1" mountpoint -q /mnt/seaweedfs 2>/dev/null; then
        echo -e "${GREEN}โœ… Mounted${NC}"
    else
        echo -e "${RED}โŒ Not mounted${NC}"
    fi
}

# Function to check service health
check_service_health() {
    local service_name=$1
    local health_url=$2
    
    echo -n "$service_name: "
    if curl -s "$health_url" >/dev/null 2>&1; then
        echo -e "${GREEN}โœ… Healthy${NC}"
    else
        echo -e "${RED}โŒ Unhealthy${NC}"
    fi
}

# Function to show logs
show_logs() {
    local service=$1
    
    if [[ -n "$service" ]]; then
        echo -e "${BLUE}๐Ÿ“‹ Logs for $service${NC}"
        echo "===================="
        $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" logs -f "$service"
    else
        echo -e "${BLUE}๐Ÿ“‹ Logs for all services${NC}"
        echo "======================="
        $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" logs -f
    fi
}

# Function to run integration tests
run_integration_tests() {
    echo -e "${BLUE}๐Ÿงช Running integration tests...${NC}"
    
    # Make sure services are running
    if ! $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps | grep -q "Up"; then
        echo -e "${RED}โŒ Services are not running. Start them first with '$0 start'${NC}"
        exit 1
    fi
    
    # Run integration tests
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" --profile test run --rm integration-test
    
    # Show results
    if [[ -d "./test-results" ]]; then
        echo -e "${BLUE}๐Ÿ“Š Test Results${NC}"
        echo "==============="
        
        if [[ -f "./test-results/overall.result" ]]; then
            local result
            result=$(cat "./test-results/overall.result")
            if [[ "$result" == "SUCCESS" ]]; then
                echo -e "${GREEN}๐ŸŽ‰ ALL TESTS PASSED!${NC}"
            else
                echo -e "${RED}๐Ÿ’ฅ SOME TESTS FAILED!${NC}"
            fi
        fi
        
        echo ""
        echo "Detailed results available in: ./test-results/"
        ls -la ./test-results/
    fi
}

# Function to run performance tests
run_performance_tests() {
    echo -e "${BLUE}๐Ÿ Running performance tests...${NC}"
    
    # Make sure services are running
    if ! $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps | grep -q "Up"; then
        echo -e "${RED}โŒ Services are not running. Start them first with '$0 start'${NC}"
        exit 1
    fi
    
    # Run performance tests
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" --profile performance run --rm performance-test
    
    # Show results
    if [[ -d "./performance-results" ]]; then
        echo -e "${BLUE}๐Ÿ“Š Performance Results${NC}"
        echo "======================"
        echo ""
        echo "Results available in: ./performance-results/"
        ls -la ./performance-results/
        
        if [[ -f "./performance-results/performance_report.html" ]]; then
            echo ""
            echo -e "${GREEN}๐Ÿ“„ HTML Report: ./performance-results/performance_report.html${NC}"
        fi
    fi
}

# Function to open shell in mount container
open_shell() {
    echo -e "${BLUE}๐Ÿš Opening shell in mount container...${NC}"
    
    if ! $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps seaweedfs-mount | grep -q "Up"; then
        echo -e "${RED}โŒ Mount container is not running${NC}"
        exit 1
    fi
    
    docker exec -it "${PROJECT_NAME}-seaweedfs-mount-1" /bin/bash
}

# Function to cleanup everything
cleanup_all() {
    echo -e "${BLUE}๐Ÿงน Full cleanup...${NC}"
    
    # Stop services
    $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" down -v --remove-orphans
    
    # Remove images
    echo "Removing Docker images..."
    docker images | grep "$PROJECT_NAME" | awk '{print $3}' | xargs -r docker rmi -f
    
    # Clean up local files
    rm -rf bin/ test-results/ performance-results/
    
    echo -e "${GREEN}โœ… Full cleanup completed${NC}"
}

# Main function
main() {
    local command=${1:-""}
    
    # Check Docker Compose availability
    check_docker_compose
    
    case "$command" in
        "start")
            start_services
            ;;
        "stop")
            stop_services
            ;;
        "restart")
            restart_services
            ;;
        "status")
            show_status
            ;;
        "logs")
            show_logs "${2:-}"
            ;;
        "test")
            run_integration_tests
            ;;
        "perf")
            run_performance_tests
            ;;
        "shell")
            open_shell
            ;;
        "cleanup")
            cleanup_all
            ;;
        "build")
            build_images
            ;;
        "help"|"-h"|"--help")
            show_usage
            ;;
        "")
            show_usage
            ;;
        *)
            echo -e "${RED}โŒ Unknown command: $command${NC}"
            echo ""
            show_usage
            exit 1
            ;;
    esac
}

# Run main function with all arguments
main "$@"