Skip to content

#29: Migrate RESO Web API Reference Server to MongoDB #1

#29: Migrate RESO Web API Reference Server to MongoDB

#29: Migrate RESO Web API Reference Server to MongoDB #1

Workflow file for this run

name: PR Tests
on:
pull_request:
branches: [ main ]
jobs:
test-all-lookup-types:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Clone and build web-api-commander
run: |
echo "Cloning web-api-commander repository..."
git clone https://github.com/RESOStandards/web-api-commander.git ../web-api-commander
cd ../web-api-commander
echo "Building web-api-commander..."
chmod +x gradlew
./gradlew build -x test
echo "Web-api-commander built successfully"
- name: Install reso-certification-utils
run: |
echo "Installing reso-certification-utils..."
npm install -g RESOStandards/reso-certification-utils
echo "Verifying installation..."
reso-certification-utils --help
- name: Create refServLocal.json configuration
run: |
echo "Creating refServLocal.json for ${{ matrix.user_config.config_name }}..."
cat > refServLocal.json << EOF
{
"providerUoi": "providerUoi",
"configs": [
{
"serviceRootUri": "http://localhost:8080/core/2.0.0/",
"recipientUoi": "recipientUoi",
"providerUsi": "providerUsi",
"token": "reso-test-token"
}
]
}
EOF
- name: Create base environment files
run: |
echo "Creating base .env file..."
cat > .env << 'EOF'
# Database Configuration
DB_TYPE=mongodb
MONGO_SYNC_CONNECTION_STR=mongodb://mongo-db:27017/reso
MONGO_DATABASE=reso
MYSQL_HOST=mysql-db
MYSQL_DATABASE=reso
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_URL=jdbc:mysql://${MYSQL_HOST}:3306/${MYSQL_DATABASE}?autoReconnect=true&maxReconnects=4
# Lookup Configuration
LOOKUP_TYPE=STRING
# Other Configuration
CERT_REPORT_FILENAME=RESODataDictionary-2.0.metadata-report.json
# JWT Secret
JWT_SECRET=${{ secrets.JWT_SECRET }}
EOF
- name: Set environment variables
run: |
echo "WEB_API_COMMANDER_PATH=$GITHUB_WORKSPACE/../web-api-commander" >> $GITHUB_ENV
- name: Build the project
run: |
echo "######################################################"
echo "Starting project build with docker-compose..."
echo "######################################################"
echo "Build started at: $(date)"
echo "Working directory: $(pwd)"
echo "Docker version: $(docker --version)"
echo "Docker compose version: $(docker compose version)"
# Start the build and capture both stdout and stderr
echo "Executing: docker compose -f docker-compose.builder.yml --project-name builder-stack up --build"
if docker compose -f docker-compose.builder.yml --project-name builder-stack up --build; then
echo "✅ BUILD SUCCESS: Docker compose build completed successfully"
echo "Build completed at: $(date)"
# Show what was built
echo "Checking build artifacts..."
ls -la build/libs/ 2>/dev/null || echo "No build/libs directory found yet"
# Show running containers
echo "Running containers:"
docker ps
# Show container logs
echo "Container logs:"
docker compose -f docker-compose.builder.yml --project-name builder-stack logs
else
echo "❌ BUILD FAILED: Docker compose build failed"
echo "Build failed at: $(date)"
echo "Exit code: $?"
# Show container logs for debugging
echo "Container logs for debugging:"
docker compose -f docker-compose.builder.yml --project-name builder-stack logs || true
# Show docker status
echo "Docker status:"
docker ps -a
exit 1
fi
- name: Grant execute permission for gradlew and fix permissions
run: |
chmod +x gradlew
sudo rm -rf .gradle
sudo chown -R $USER:$USER . || true
- name: Verify environment setup
run: |
echo "Verifying .env file contents:"
cat .env
echo "Build artifacts:"
ls -la build/libs/ || echo "No build/libs directory found"
- name: Start server and verify API endpoints
run: |
echo "=== Starting server with docker compose ==="
echo "Server startup initiated at: $(date)"
# Start the server in detached mode
docker compose up -d
echo "Waiting for server to be ready..."
# Wait for health endpoint to return 200
max_attempts=30
attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Health check attempt $attempt/$max_attempts..."
if response=$(curl -s -w "%{http_code}" -o /tmp/health_response.txt http://localhost:8080/core/health 2>/dev/null); then
http_code="${response: -3}"
response_body=$(cat /tmp/health_response.txt)
echo "Health check response code: $http_code"
echo "Health check response body: $response_body"
if [ "$http_code" = "200" ]; then
echo "✅ Health check successful at $(date)"
break
fi
else
echo "Health check request failed"
fi
if [ $attempt -eq $max_attempts ]; then
echo "❌ Health check failed after $max_attempts attempts"
echo "Container logs:"
docker compose logs
exit 1
fi
echo "Waiting 10 seconds before next attempt..."
sleep 10
((attempt++))
done
echo "=== Testing API endpoint ==="
# Test the Property endpoint with bearer token
echo "Making API request to Property endpoint..."
api_response=$(curl -s -w "%{http_code}" -H "Authorization: Bearer reso-test-token" \
-o /tmp/api_response.txt \
"http://localhost:8080/core/2.0.0/Property?\$top=1&\$count=true" 2>/dev/null || echo "000")
api_http_code="${api_response: -3}"
api_response_body=$(cat /tmp/api_response.txt)
echo "API request status code: $api_http_code"
echo "API response body: $api_response_body"
if [ "$api_http_code" = "200" ]; then
echo "✅ API test successful at $(date)"
else
echo "⚠️ API test returned status code: $api_http_code"
echo "This may be expected depending on server configuration"
echo "=== DEBUG INFORMATION ==="
echo "Gathering debug information for MongoDB connection issue..."
echo "--- Docker container status ---"
docker ps -a
echo "--- Environment variables in use ---"
echo "DB_TYPE: $DB_TYPE"
echo "MONGO_DATABASE: $MONGO_DATABASE"
echo "MONGO_SYNC_CONNECTION_STR: $MONGO_SYNC_CONNECTION_STR"
echo "--- Docker compose services ---"
docker compose ps
echo "--- Container environment variables ---"
echo "Current .env file contents:"
cat .env | grep -E "(MONGO|DB_|LOOKUP)" || echo "No matching env vars in .env file"
echo "App container env vars (trying different service names):"
docker compose exec -T odata-manager-app env | grep -E "(MONGO|DB_|LOOKUP)" 2>/dev/null || \
docker compose exec -T app env | grep -E "(MONGO|DB_|LOOKUP)" 2>/dev/null || \
echo "Failed to get app container env vars - service name unknown"
echo "--- MongoDB container logs ---"
docker compose logs mongo-db || echo "No mongo-db container found"
echo "--- App container logs (last 300 lines) ---"
docker compose logs --tail=300 odata-manager-app || \
docker compose logs --tail=300 app || \
echo "Failed to get app container logs"
echo "--- Java system properties and environment inside container ---"
docker compose exec -T odata-manager-app java -XshowSettings:properties -version 2>/dev/null || \
docker compose exec -T app java -XshowSettings:properties -version 2>/dev/null || \
echo "Failed to get Java system properties"
echo "--- MongoDB connection debugging ---"
echo "Checking if MongoDB host is resolvable from app container:"
docker compose exec -T odata-manager-app nslookup mongo-db 2>/dev/null || \
docker compose exec -T app nslookup mongo-db 2>/dev/null || \
echo "DNS lookup failed"
echo "Testing direct MongoDB connection from app container:"
docker compose exec -T odata-manager-app nc -zv mongo-db 27017 2>/dev/null || \
docker compose exec -T app nc -zv mongo-db 27017 2>/dev/null || \
echo "Direct connection test failed"
echo "--- Network connectivity test ---"
echo "Testing connectivity from app to mongo-db..."
docker compose exec -T odata-manager-app ping -c 3 mongo-db 2>/dev/null || \
docker compose exec -T app ping -c 3 mongo-db 2>/dev/null || \
echo "Ping test failed - could not find correct service name"
echo "--- MongoDB connection test ---"
echo "Testing MongoDB connection directly..."
docker compose exec -T mongo-db mongosh --eval "db.adminCommand('ping')" || echo "MongoDB connection test failed"
echo "=== END DEBUG INFORMATION ==="
fi
echo "Server verification completed at: $(date)"
echo "=== Cleaning up server ==="
docker compose down --volumes --remove-orphans
echo "Server cleanup completed at: $(date)"
- name: Run LookupStringTest
run: |
echo "=== LookupStringTest ==="
echo "Test started at: $(date)"
# Update only LOOKUP_TYPE in existing .env file
sed -i 's/LOOKUP_TYPE=.*/LOOKUP_TYPE=STRING/' .env
echo "Updated LOOKUP_TYPE to STRING"
if LOOKUP_TYPE=STRING ./gradlew test --tests org.reso.tests.LookupStringTest --info; then
echo "✅ LookupStringTest PASSED at $(date)"
else
echo "❌ LookupStringTest FAILED at $(date)"
exit 1
fi
- name: Run LookupEnumFlagsTest
run: |
echo "=== LookupEnumFlagsTest ==="
echo "Test started at: $(date)"
# Update only LOOKUP_TYPE in existing .env file
sed -i 's/LOOKUP_TYPE=.*/LOOKUP_TYPE=ENUM_FLAGS/' .env
echo "Updated LOOKUP_TYPE to ENUM_FLAGS"
if LOOKUP_TYPE=ENUM_FLAGS ./gradlew test --tests org.reso.tests.LookupEnumFlagsTest --info; then
echo "✅ LookupEnumFlagsTest PASSED at $(date)"
else
echo "❌ LookupEnumFlagsTest FAILED at $(date)"
exit 1
fi
- name: Run LookupEnumTest
run: |
echo "=== LookupEnumTest ==="
echo "Test started at: $(date)"
# Update only LOOKUP_TYPE in existing .env file
sed -i 's/LOOKUP_TYPE=.*/LOOKUP_TYPE=ENUM_COLLECTION/' .env
echo "Updated LOOKUP_TYPE to ENUM_COLLECTION"
if LOOKUP_TYPE=ENUM_COLLECTION ./gradlew test --tests org.reso.tests.LookupEnumTest --info; then
echo "✅ LookupEnumTest PASSED at $(date)"
else
echo "❌ LookupEnumTest FAILED at $(date)"
exit 1
fi
- name: Final cleanup
if: always()
run: |
echo "Performing final cleanup of Docker containers..."
docker compose down --volumes --remove-orphans || true
echo "Final cleanup completed"
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
build/test-results/
build/reports/
results/
retention-days: 7