-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·192 lines (160 loc) · 5.57 KB
/
start.sh
File metadata and controls
executable file
·192 lines (160 loc) · 5.57 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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Script configuration
VENV_DIR="venv"
PYTHON_VERSION="python3.8"
BACKEND_DIR="backend"
FLASK_PORT=5050 # Changed from 5000 to avoid conflict with Control Center
# Print with colors for better readability
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper function to print status messages
print_status() {
echo -e "${GREEN}[LOGICLENS]${NC} $1"
}
print_section() {
echo -e "\n${BLUE}===== $1 =====${NC}"
}
# Check if we're in the project root
if [ ! -d "$BACKEND_DIR" ]; then
echo -e "${RED}Error: Please run this script from the project root directory${NC}"
exit 1
fi
# Make all scripts executable
print_section "PREPARING SCRIPTS"
chmod +x run.sh shutdown.sh test_scripts.sh start.sh
print_status "Made all scripts executable"
# First, ensure there are no running instances
print_section "CLEANING ENVIRONMENT"
print_status "Checking for running instances..."
# Run the shutdown script to ensure clean environment
./shutdown.sh
# Run test scripts to verify functionality and generate test data
print_section "RUNNING TESTS"
print_status "Running test scripts to verify functionality and generate test data..."
# Run tests but skip the startup/shutdown tests since we're about to do that ourselves
cd "$BACKEND_DIR"
# Check if virtual environment exists, create if not
if [ ! -d "$VENV_DIR" ]; then
print_status "Creating virtual environment with $PYTHON_VERSION..."
$PYTHON_VERSION -m venv "$VENV_DIR"
fi
# Activate virtual environment
print_status "Activating virtual environment..."
source "$VENV_DIR/bin/activate"
# Generate test data only (not running full tests to avoid starting/stopping app)
print_status "Generating test data..."
python -c "
import sys
try:
sys.path.append('.')
from app.utils.test_utils import get_test_manager
from app.utils.monitoring import get_monitoring_manager
from app.utils.logger import get_logger
import random
import time
import datetime
import os
# Configure services
logger = get_logger('logiclens', {'store_logs': True})
test_manager = get_test_manager({'persist_results': True})
monitoring_manager = get_monitoring_manager({'persist_metrics': True})
# Log startup sequence
logger.log_event(
component='system',
message='Starting LogicLens master startup sequence',
level='INFO',
details={
'timestamp': datetime.datetime.now().isoformat(),
'port': $FLASK_PORT
}
)
# Create test suites
test_suites = [
'API Tests',
'Frontend Tests',
'Integration Tests',
'Performance Tests'
]
suite_ids = {}
for suite_name in test_suites:
suite_id = test_manager.start_suite(name=suite_name)
suite_ids[suite_name] = suite_id
logger.log_event(
component='test',
message=f'Created test suite: {suite_name}',
level='INFO',
details={'suite_id': suite_id}
)
# Add random test results
for i in range(10):
test_id = f'{suite_name.lower().replace(\" \", \"_\")}_{i}'
test_name = f'Test case {i} for {suite_name}'
status = random.choice(['PASSED', 'PASSED', 'PASSED', 'FAILED', 'SKIPPED'])
duration = random.uniform(0.1, 5.0)
message = f'Test {\"executed successfully\" if status == \"PASSED\" else \"failed with error X\" if status == \"FAILED\" else \"was skipped\"}'
test_result = test_manager.add_test_result(
suite_id=suite_id,
test_id=test_id,
test_name=test_name,
status=status,
duration=duration,
message=message
)
# Simulate test execution time
time.sleep(0.05)
# End the suite
test_manager.end_suite(suite_id)
# Generate system metrics
for i in range(20):
metrics = monitoring_manager.collect_metrics()
metrics['custom'] = {
'random_value': random.uniform(0, 100),
'test_metric': random.randint(1, 1000)
}
monitoring_manager.store_metrics(metrics)
time.sleep(0.1)
# Log completion
logger.log_event(
component='system',
message='Test data generation completed successfully',
level='INFO',
details={
'test_suites': len(test_suites),
'metrics_generated': 20,
'status': 'SUCCESS'
}
)
# Create special log entry for launching app
logger.log_event(
component='system',
message='Launching LogicLens application via master startup script',
level='INFO',
details={
'timestamp': datetime.datetime.now().isoformat(),
'environment': os.environ.get('FLASK_ENV', 'development'),
'python_version': sys.version,
'startup_mode': 'master_script',
'port': $FLASK_PORT
}
)
print('Test data generation complete!')
print(f'Created {len(test_suites)} test suites with 10 tests each')
print('Generated 20 system metric snapshots')
except Exception as e:
print(f'Error generating test data: {e}')
sys.exit(1)
"
# Deactivate virtual environment
deactivate
# Return to project root
cd ..
# Launch the application
print_section "LAUNCHING APPLICATION"
print_status "Starting LogicLens application on port $FLASK_PORT..."
# Run the application
./run.sh