Warning, /swf-testbed/docs/installation.md is written in an unsupported language. File is not indexed.
0001 # Installation Guide
0002
0003 Complete setup instructions for the SWF Testbed.
0004
0005 ## Prerequisites
0006
0007 Before starting, ensure you have:
0008
0009 - **Python 3.9+** with pip
0010 - **Docker Desktop** (for infrastructure services)
0011 - **Git** for repository management
0012 - **Administrative access** (for some package installations)
0013
0014 ## Step 1: Clone the Repositories
0015
0016 Clone all three SWF repositories as siblings in the same parent directory:
0017
0018 ```bash
0019 # Create a directory for the SWF project
0020 mkdir swf-project && cd swf-project
0021
0022 # Clone all repositories
0023 git clone https://github.com/BNLNPPS/swf-testbed.git
0024 git clone https://github.com/BNLNPPS/swf-monitor.git
0025 git clone https://github.com/BNLNPPS/swf-common-lib.git
0026
0027 # Your directory structure should now look like:
0028 # swf-project/
0029 # ├── swf-testbed/
0030 # ├── swf-monitor/
0031 # └── swf-common-lib/
0032 ```
0033
0034 ## Step 2: Environment Configuration
0035
0036 **IMPORTANT FOR BNL/pandaserver02 DEPLOYMENT:**
0037 For deployments on systems with corporate proxies (like BNL pandaserver02), add this to your `~/.env` file:
0038
0039 ```bash
0040 NO_PROXY=localhost,127.0.0.1,0.0.0.0
0041 ```
0042
0043 This prevents proxy interference with local service communications (Django, ActiveMQ, PostgreSQL, WebSocket connections). Other deployment environments may have different proxy requirements.
0044
0045 ## Step 3: Set Up Infrastructure Services
0046
0047 Choose one of the following approaches:
0048
0049 ### Option A: Using Docker (Recommended)
0050
0051 1. **Install Docker Desktop** and ensure it's running
0052 2. **Navigate to swf-testbed:**
0053 ```bash
0054 cd swf-testbed
0055 ```
0056 3. **Start services:**
0057 ```bash
0058 docker-compose up -d
0059 ```
0060
0061 ### Option B: Local Installation (macOS with Homebrew)
0062
0063 1. **Install PostgreSQL and ActiveMQ:**
0064 ```bash
0065 brew install postgresql@14 activemq
0066 ```
0067
0068 2. **Start services:**
0069 ```bash
0070 brew services start postgresql@14
0071 brew services start activemq
0072 ```
0073
0074 3. **Create database:**
0075 ```bash
0076 createdb swfdb
0077 ```
0078
0079 ## Step 4: Configure Environment Variables
0080
0081 ### Core Infrastructure Configuration
0082
0083 The testbed requires environment variables for service coordination. Create/edit `~/.env`:
0084
0085 ```bash
0086 # Export all variables to make them available to subprocesses
0087 export NO_PROXY=localhost,127.0.0.1,0.0.0.0
0088 export no_proxy=localhost,127.0.0.1,0.0.0.0
0089
0090 # Database configuration (PostgreSQL)
0091 export DB_NAME='swfdb'
0092 export DB_USER='your_db_user'
0093 export DB_PASSWORD='your_db_password'
0094 export DB_HOST='localhost'
0095 export DB_PORT='5432'
0096
0097 # ActiveMQ configuration
0098 export ACTIVEMQ_HOST='your_activemq_host'
0099 export ACTIVEMQ_PORT=61612
0100 export ACTIVEMQ_USER='your_activemq_user'
0101 export ACTIVEMQ_PASSWORD='your_activemq_password'
0102 export ACTIVEMQ_HEARTBEAT_TOPIC='epictopic'
0103 export ACTIVEMQ_USE_SSL=True
0104 export ACTIVEMQ_SSL_CA_CERTS='/path/to/full-chain.pem'
0105
0106 # Monitor URLs
0107 export SWF_MONITOR_URL=https://localhost:8443 # Authenticated API calls
0108 export SWF_MONITOR_HTTP_URL=http://localhost:8002 # REST logging (no auth)
0109
0110 # API Authentication
0111 export SWF_API_TOKEN=your_token_here
0112
0113 # Django configuration
0114 export SECRET_KEY='django-insecure-dev-key-for-testing-only-change-for-production'
0115 export DEBUG=True
0116
0117 # Unset proxy variables for localhost connections
0118 unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
0119 ```
0120
0121 ### swf-monitor Configuration
0122
0123 2. **Configure swf-monitor secrets:**
0124 ```bash
0125 cd ../swf-monitor
0126 cp .env.example .env
0127 ```
0128
0129 Edit the `.env` file with your database credentials:
0130 ```env
0131 export DB_PASSWORD='admin' # Match your Docker/local PostgreSQL password
0132 export SECRET_KEY='django-insecure-dev-key-for-testing-only-change-for-production-12345678901234567890'
0133 ```
0134
0135 ## Step 5: Set Up Python Environment and Install Dependencies
0136
0137 You can either use **uv** or plain **pip** to set up the Python environment.
0138
0139 ### Using `uv`
0140
0141 The following commands will create a virtual environment in `.venv` (if needed) and install
0142 `swf-testbed` and all of its dependencies:
0143
0144 ```bash
0145 cd ../swf-testbed
0146 uv sync
0147 source .venv/bin/activate
0148 ```
0149
0150 ### Using `pip`
0151
0152 1. **Navigate to swf-testbed and create virtual environment:**
0153 ```bash
0154 cd ../swf-testbed
0155 python -m venv .venv
0156 source .venv/bin/activate
0157 ```
0158
0159 2. **Install all packages in development mode:**
0160 ```bash
0161 # Install swf-common-lib (shared utilities)
0162 pip install -e ../swf-common-lib
0163
0164 # Install swf-monitor (Django web application)
0165 pip install -e ../swf-monitor
0166
0167 # Install swf-testbed CLI
0168 pip install -e .
0169 ```
0170
0171 ## Step 6: Initialize and Run the Testbed
0172
0173 1. **Initialize the testbed:**
0174 ```bash
0175 swf-testbed init
0176 ```
0177
0178 2. **Set up Django database:**
0179 ```bash
0180 # Run Django migrations and create superuser
0181 python ../swf-monitor/src/manage.py migrate
0182 python ../swf-monitor/src/manage.py createsuperuser
0183 ```
0184
0185 3. **Load sample data (optional):**
0186 ```bash
0187 # Load fake log data to populate the monitoring interface
0188 python ../swf-monitor/scripts/load_fake_logs.py
0189 ```
0190
0191 4. **Start the monitor web interface:**
0192 ```bash
0193 # Start Django monitor with dual HTTP/HTTPS support
0194 ../swf-monitor/start_django_dual.sh
0195 ```
0196
0197 This starts the monitor on:
0198 - **HTTP (port 8002)**: For REST logging from agents (no authentication)
0199 - **HTTPS (port 8443)**: For authenticated API calls (STF files, workflows, runs)
0200
0201 5. **Start the testbed agents:**
0202 ```bash
0203 # If using Docker:
0204 swf-testbed start
0205
0206 # If using local services:
0207 swf-testbed start-local
0208 ```
0209
0210 6. **Check status:**
0211 ```bash
0212 swf-testbed status # or status-local
0213 ```
0214
0215 ## Step 7: Verify Setup
0216
0217 1. **Check web interfaces:**
0218 - **Monitor dashboard**: http://localhost:8002/ (main interface)
0219 - **Monitor HTTPS API**: https://localhost:8443/api/ (authenticated API)
0220 - **Django admin**: http://localhost:8002/admin/ (use superuser credentials created in Step 5)
0221 - **ActiveMQ console**: http://localhost:8161/admin/ (admin/admin)
0222
0223 2. **Run tests:**
0224 ```bash
0225 # Run all tests across all repositories
0226 ./run_all_tests.sh
0227
0228 # Or run tests for individual components
0229 cd swf-monitor && ./run_tests.sh
0230 ```
0231
0232 ## Secrets and Configuration Management
0233
0234 The testbed uses a hierarchical configuration approach:
0235
0236 - **Core infrastructure**: Environment variables in `~/.env` (required - database, messaging, proxy settings)
0237 - **swf-monitor**: Django application secrets in `swf-monitor/.env` (required - core infrastructure)
0238 - **swf-data-agent**: Agent configuration in `swf-data-agent/.env` (if present)
0239 - **swf-processing-agent**: PanDA credentials in `swf-processing-agent/.env` (if present)
0240
0241 ### Setting Up swf-monitor Environment Variables
0242
0243 The Django monitoring application requires database and messaging credentials.
0244 To configure:
0245
0246 1. **Copy the environment template:**
0247 ```bash
0248 cp swf-monitor/.env.example swf-monitor/.env
0249 ```
0250
0251 2. **Edit the `.env` file** with your actual credentials:
0252 - Set `DB_PASSWORD` to match your PostgreSQL setup
0253 - Generate a unique `SECRET_KEY` for Django
0254 - Configure messaging credentials if using external ActiveMQ
0255
0256 3. **Load environment:**
0257 ```bash
0258 source swf-monitor/.env
0259 ```
0260
0261 The Django application will automatically read these values during startup.
0262
0263 ### Security Considerations
0264
0265 **For Development:**
0266 - Use the provided development secrets and database passwords
0267 - The `.env.example` files contain safe defaults for local testing
0268
0269 **For Production:**
0270 - Generate secure, unique passwords for all services
0271 - Use proper SSL certificates (not self-signed)
0272 - Set `DEBUG=False` in Django configuration
0273 - Configure proper `ALLOWED_HOSTS` for Django
0274 - Use environment-specific configuration management
0275
0276 **Secret Storage:**
0277 - Never commit actual secrets to version control
0278 - Use `.env` files (which are `.gitignore`d) for local development
0279 - Consider using dedicated secret management for production deployments
0280
0281 ## Troubleshooting Installation
0282
0283 ### Common Issues
0284
0285 1. **Docker services not starting:**
0286 ```bash
0287 docker-compose ps
0288 docker-compose logs postgresql
0289 docker-compose logs activemq
0290 ```
0291
0292 2. **Virtual environment issues:**
0293 ```bash
0294 # Ensure you're in the right directory and venv is activated
0295 cd swf-testbed
0296 source .venv/bin/activate
0297 which python # Should show .venv/bin/python
0298 ```
0299
0300 3. **Proxy connection issues:**
0301 - Ensure `NO_PROXY` is set in `~/.env`
0302 - Check that proxy variables are unset for localhost
0303
0304 4. **Database connection errors:**
0305 - Check database credentials in `.env` files
0306
0307 5. **Import errors:**
0308 ```bash
0309 # Reinstall packages in correct order
0310 pip install -e ../swf-common-lib ../swf-monitor .
0311 ```
0312
0313 ## Next Steps
0314
0315 After successful installation:
0316 - Review [Architecture Overview](architecture.md) to understand the system
0317 - See [Operations Guide](operations.md) for running and managing services
0318 - Check [Development Guide](development.md) for contributing to the project