-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_optimized_api.sh
More file actions
241 lines (203 loc) Β· 8.58 KB
/
test_optimized_api.sh
File metadata and controls
241 lines (203 loc) Β· 8.58 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
241
#!/bin/bash
# ArchiMate Optimized API Performance Test
# This script tests both original and optimized methods via API calls
set -e
# Configuration
BASE_URL="http://localhost"
USERNAME="admin"
PASSWORD="admin"
GEMMA_FILE="lib/Settings/GEMMA_release.xml"
OUTPUT_DIR="./performance_test_results"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# Create output directory
mkdir -p "$OUTPUT_DIR"
echo -e "${CYAN}π ARCHIMATE OPTIMIZED API PERFORMANCE TEST${NC}"
echo -e "${CYAN}============================================${NC}"
echo
# Check if GEMMA file exists in container
if ! docker-compose exec -T nextcloud test -f "/var/www/html/apps-extra/softwarecatalog/$GEMMA_FILE"; then
echo -e "${RED}β ERROR: GEMMA file not found in container${NC}"
exit 1
fi
# Get file size
FILE_SIZE=$(docker-compose exec -T nextcloud stat -c%s "/var/www/html/apps-extra/softwarecatalog/$GEMMA_FILE")
FILE_SIZE_MB=$(echo "scale=2; $FILE_SIZE / 1024 / 1024" | bc)
echo -e "${BLUE}π Test file: $GEMMA_FILE (${FILE_SIZE_MB} MB)${NC}"
echo
# Function to test import method
test_import_method() {
local method_name="$1"
local use_optimized="$2"
local output_file="$3"
echo -e "${YELLOW}π Testing $method_name method...${NC}"
# Copy file to temp location in container
docker-compose exec -T nextcloud cp "/var/www/html/apps-extra/softwarecatalog/$GEMMA_FILE" "/tmp/test_gemma.xml"
# Record start time
local start_time=$(date +%s.%3N)
# Make API call
local http_code=$(docker-compose exec -T nextcloud curl -s -w "%{http_code}" \
-o "$output_file" \
-X POST \
-u "$USERNAME:$PASSWORD" \
-F "archiMateFile=@/tmp/test_gemma.xml" \
-F "useOptimized=$use_optimized" \
-F "updateExisting=true" \
-F "preserveIds=true" \
"$BASE_URL/index.php/apps/softwarecatalog/api/archimate/import" 2>/dev/null || echo "000")
# Record end time
local end_time=$(date +%s.%3N)
local duration=$(echo "scale=3; $end_time - $start_time" | bc)
# Clean up temp file
docker-compose exec -T nextcloud rm -f "/tmp/test_gemma.xml"
if [ "$http_code" = "200" ]; then
# Parse response
local success=$(cat "$output_file" | python3 -c "import sys, json; print(json.load(sys.stdin).get('success', False))" 2>/dev/null || echo "false")
if [ "$success" = "True" ] || [ "$success" = "true" ]; then
echo -e "${GREEN}β
$method_name method completed successfully${NC}"
echo -e "${GREEN} β±οΈ Duration: ${duration}s${NC}"
# Extract object count if available
local object_count=$(cat "$output_file" | python3 -c "
import sys, json
data = json.load(sys.stdin)
objects = data.get('performance_metrics', {}).get('objects_processed', 0)
if objects == 0:
objects = data.get('summary', {}).get('total_objects_created', 0)
print(objects)
" 2>/dev/null || echo "0")
if [ "$object_count" -gt 0 ]; then
local objects_per_sec=$(echo "scale=1; $object_count / $duration" | bc)
echo -e "${GREEN} π― Objects: $object_count${NC}"
echo -e "${GREEN} β‘ Speed: ${objects_per_sec} objects/sec${NC}"
fi
# Check if under 60 seconds
local target_check=$(echo "$duration < 60" | bc)
if [ "$target_check" = "1" ]; then
echo -e "${GREEN} π TARGET ACHIEVED! (< 60s)${NC}"
return 0
else
echo -e "${YELLOW} β οΈ Over 60s target${NC}"
return 1
fi
else
local error=$(cat "$output_file" | python3 -c "import sys, json; print(json.load(sys.stdin).get('error', 'Unknown error'))" 2>/dev/null || echo "Parse error")
echo -e "${RED}β $method_name method failed: $error${NC}"
return 2
fi
else
echo -e "${RED}β $method_name method HTTP error: $http_code${NC}"
if [ -f "$output_file" ]; then
echo -e "${RED}Response: $(cat "$output_file")${NC}"
fi
return 2
fi
}
# =============================================================================
# TEST 1: OPTIMIZED METHOD
# =============================================================================
echo -e "${YELLOW}ποΈ TEST 1: OPTIMIZED METHOD${NC}"
echo -e "${YELLOW}$(printf '%*s' 40 '' | tr ' ' '-')${NC}"
optimized_result=0
if test_import_method "OPTIMIZED" "true" "$OUTPUT_DIR/optimized_result.json"; then
optimized_result=1
optimized_time=$(cat "$OUTPUT_DIR/optimized_result.json" | python3 -c "
import sys, json
data = json.load(sys.stdin)
print(data.get('performance_metrics', {}).get('total_time_seconds', 0))
" 2>/dev/null || echo "0")
else
optimized_result=0
fi
echo
# =============================================================================
# TEST 2: ORIGINAL METHOD (for comparison - only if optimized failed)
# =============================================================================
if [ "$optimized_result" = "0" ]; then
echo -e "${YELLOW}π TEST 2: ORIGINAL METHOD (fallback)${NC}"
echo -e "${YELLOW}$(printf '%*s' 40 '' | tr ' ' '-')${NC}"
original_result=0
if test_import_method "ORIGINAL" "false" "$OUTPUT_DIR/original_result.json"; then
original_result=1
original_time=$(cat "$OUTPUT_DIR/original_result.json" | python3 -c "
import sys, json
data = json.load(sys.stdin)
print(data.get('processing_times', {}).get('total_time_seconds', 0))
" 2>/dev/null || echo "0")
fi
echo
fi
# =============================================================================
# RESULTS SUMMARY
# =============================================================================
echo -e "${CYAN}π PERFORMANCE TEST SUMMARY${NC}"
echo -e "${CYAN}$(printf '%*s' 35 '' | tr ' ' '=')${NC}"
if [ "$optimized_result" = "1" ]; then
echo -e "${GREEN}β
OPTIMIZED METHOD: SUCCESS${NC}"
if [ -n "$optimized_time" ] && [ "$optimized_time" != "0" ]; then
echo -e "${GREEN} Time: ${optimized_time}s${NC}"
target_check=$(echo "$optimized_time < 60" | bc)
if [ "$target_check" = "1" ]; then
echo -e "${GREEN}π PERFORMANCE TARGET ACHIEVED!${NC}"
echo -e "${GREEN} Target: 60s, Actual: ${optimized_time}s${NC}"
target_met=true
else
shortfall=$(echo "scale=2; $optimized_time - 60" | bc)
echo -e "${YELLOW}β οΈ Target missed by ${shortfall}s${NC}"
target_met=false
fi
fi
elif [ "$original_result" = "1" ]; then
echo -e "${YELLOW}β οΈ OPTIMIZED METHOD FAILED, ORIGINAL WORKS${NC}"
if [ -n "$original_time" ] && [ "$original_time" != "0" ]; then
echo -e "${YELLOW} Original time: ${original_time}s${NC}"
fi
target_met=false
else
echo -e "${RED}β BOTH METHODS FAILED${NC}"
target_met=false
fi
echo
# =============================================================================
# NEXT STEPS
# =============================================================================
echo -e "${CYAN}π‘ NEXT STEPS${NC}"
echo -e "${CYAN}$(printf '%*s' 15 '' | tr ' ' '=')${NC}"
if [ "$target_met" = "true" ]; then
echo -e "${GREEN}β
Performance optimization successful!${NC}"
echo -e "${GREEN}β’ Deploy optimized method as default${NC}"
echo -e "${GREEN}β’ Update frontend to use optimized API${NC}"
echo -e "${GREEN}β’ Add performance monitoring${NC}"
else
echo -e "${YELLOW}π§ Further optimization needed:${NC}"
echo -e "${YELLOW}β’ Check logs for bottlenecks${NC}"
echo -e "${YELLOW}β’ Implement streaming XML parser${NC}"
echo -e "${YELLOW}β’ Add ReactPHP parallel processing${NC}"
echo -e "${YELLOW}β’ Optimize database operations${NC}"
fi
echo
# Save results summary
cat > "$OUTPUT_DIR/test_summary.txt" << EOF
ArchiMate Performance Test Results
==================================
Date: $(date)
Test File: $GEMMA_FILE ($FILE_SIZE_MB MB)
Optimized Method: $([ "$optimized_result" = "1" ] && echo "SUCCESS" || echo "FAILED")
$([ -n "$optimized_time" ] && echo "Optimized Time: ${optimized_time}s")
Target (60s): $([ "$target_met" = "true" ] && echo "ACHIEVED" || echo "NOT MET")
Test files saved in: $OUTPUT_DIR/
EOF
echo -e "${BLUE}π Results saved to: $OUTPUT_DIR/test_summary.txt${NC}"
echo
# Exit with appropriate code
if [ "$target_met" = "true" ]; then
echo -e "${GREEN}π TEST COMPLETED SUCCESSFULLY - TARGET ACHIEVED${NC}"
exit 0
else
echo -e "${YELLOW}π TEST COMPLETED - FURTHER OPTIMIZATION NEEDED${NC}"
exit 1
fi