Add data ingestion service proxy routes and update configs
- Add proxy routes for data ingestion service in API gateway - Register data-ingestion-service in SERVICES config - Update docker-compose to include data-ingestion-service and sensor-service dependencies - Fix import typo in sensor-service (contextual -> contextlib) - Update FTP credentials and environment variables for data-ingestion-service
This commit is contained in:
@@ -68,45 +68,51 @@ auth_middleware = AuthMiddleware()
|
||||
SERVICES = {
|
||||
"token-service": ServiceConfig(
|
||||
name="token-service",
|
||||
base_url="http://localhost:8001",
|
||||
base_url=os.getenv("TOKEN_SERVICE_URL", "http://energy-token-service:8001"),
|
||||
health_endpoint="/health",
|
||||
auth_required=False
|
||||
),
|
||||
"battery-service": ServiceConfig(
|
||||
name="battery-service",
|
||||
base_url="http://localhost:8002",
|
||||
base_url=os.getenv("BATTERY_SERVICE_URL", "http://energy-battery-service:8002"),
|
||||
health_endpoint="/health",
|
||||
auth_required=True
|
||||
),
|
||||
"demand-response-service": ServiceConfig(
|
||||
name="demand-response-service",
|
||||
base_url="http://localhost:8003",
|
||||
base_url=os.getenv("DEMAND_RESPONSE_SERVICE_URL", "http://energy-demand-response-service:8003"),
|
||||
health_endpoint="/health",
|
||||
auth_required=True
|
||||
),
|
||||
"p2p-trading-service": ServiceConfig(
|
||||
name="p2p-trading-service",
|
||||
base_url="http://localhost:8004",
|
||||
base_url=os.getenv("P2P_TRADING_SERVICE_URL", "http://energy-p2p-trading-service:8004"),
|
||||
health_endpoint="/health",
|
||||
auth_required=True
|
||||
),
|
||||
"forecasting-service": ServiceConfig(
|
||||
name="forecasting-service",
|
||||
base_url="http://localhost:8005",
|
||||
base_url=os.getenv("FORECASTING_SERVICE_URL", "http://energy-forecasting-service:8005"),
|
||||
health_endpoint="/health",
|
||||
auth_required=True
|
||||
),
|
||||
"iot-control-service": ServiceConfig(
|
||||
name="iot-control-service",
|
||||
base_url="http://localhost:8006",
|
||||
base_url=os.getenv("IOT_CONTROL_SERVICE_URL", "http://energy-iot-control-service:8006"),
|
||||
health_endpoint="/health",
|
||||
auth_required=True
|
||||
),
|
||||
"sensor-service": ServiceConfig(
|
||||
name="sensor-service",
|
||||
base_url="http://localhost:8007",
|
||||
base_url=os.getenv("SENSOR_SERVICE_URL", "http://energy-sensor-service:8007"),
|
||||
health_endpoint="/health",
|
||||
auth_required=True
|
||||
),
|
||||
"data-ingestion-service": ServiceConfig(
|
||||
name="data-ingestion-service",
|
||||
base_url=os.getenv("DATA_INGESTION_SERVICE_URL", "http://energy-data-ingestion-service:8008"),
|
||||
health_endpoint="/health",
|
||||
auth_required=False
|
||||
)
|
||||
}
|
||||
|
||||
@@ -216,6 +222,22 @@ async def sensor_service_proxy(request: Request, path: str):
|
||||
"""Proxy requests to sensor service"""
|
||||
return await proxy_request(request, "sensor-service", f"/{path}")
|
||||
|
||||
# Data Ingestion Service Routes (SA4CPS FTP Monitoring)
|
||||
@app.api_route("/api/v1/ingestion/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
||||
async def data_ingestion_service_proxy(request: Request, path: str):
|
||||
"""Proxy requests to data ingestion service"""
|
||||
return await proxy_request(request, "data-ingestion-service", f"/{path}")
|
||||
|
||||
@app.api_route("/api/v1/sources/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
||||
async def data_sources_proxy(request: Request, path: str):
|
||||
"""Proxy requests to data ingestion service for data sources"""
|
||||
return await proxy_request(request, "data-ingestion-service", f"/sources/{path}")
|
||||
|
||||
@app.get("/api/v1/sources")
|
||||
async def data_sources_list_proxy(request: Request):
|
||||
"""Proxy requests to data ingestion service for sources list"""
|
||||
return await proxy_request(request, "data-ingestion-service", "/sources")
|
||||
|
||||
@app.api_route("/api/v1/rooms/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
||||
async def room_service_proxy(request: Request, path: str):
|
||||
"""Proxy requests to sensor service for room management"""
|
||||
|
||||
@@ -52,6 +52,8 @@ services:
|
||||
- mongodb
|
||||
- redis
|
||||
- token-service
|
||||
- sensor-service
|
||||
- data-ingestion-service
|
||||
# - battery-service
|
||||
# - demand-response-service
|
||||
networks:
|
||||
@@ -67,7 +69,7 @@ services:
|
||||
ports:
|
||||
- "8001:8001"
|
||||
environment:
|
||||
- MONGO_URL=mongodb://admin:password123@mongodb:27017/energy_dashboard_tokens?authSource=admin
|
||||
- MONGO_URL=mongodb://admin:password123@localhost:27017/energy_dashboard_tokens?authSource=admin
|
||||
- JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production
|
||||
depends_on:
|
||||
- mongodb
|
||||
@@ -177,16 +179,15 @@ services:
|
||||
ports:
|
||||
- "8008:8008"
|
||||
environment:
|
||||
- MONGO_URL=mongodb://admin:password123@mongodb:27017/energy_dashboard_ingestion?authSource=admin
|
||||
- REDIS_URL=redis://redis:6379
|
||||
- MONGO_URL=mongodb://admin:password123@mongodb:27017/
|
||||
- FTP_SA4CPS_HOST=ftp.sa4cps.pt
|
||||
- FTP_SA4CPS_PORT=21
|
||||
- FTP_SA4CPS_USERNAME=anonymous
|
||||
- FTP_SA4CPS_PASSWORD=
|
||||
- FTP_SA4CPS_USERNAME=curvascarga@sa4cps.pt
|
||||
- FTP_SA4CPS_PASSWORD=n$WFtz9+bleN
|
||||
- FTP_SA4CPS_REMOTE_PATH=/
|
||||
- FTP_CHECK_INTERVAL=21600
|
||||
depends_on:
|
||||
- mongodb
|
||||
- redis
|
||||
networks:
|
||||
- energy-network
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from fastapi import FastAPI, HTTPException, Depends, WebSocket, WebSocketDisconnect, Query, BackgroundTasks
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from contextual import asynccontextmanager
|
||||
from contextlib import asynccontextmanager
|
||||
import logging
|
||||
from typing import List, Optional, Dict, Any
|
||||
import json
|
||||
|
||||
Reference in New Issue
Block a user