Chuyển tới nội dung chính

API Reference

Base Configuration

Base URL: http://localhost:8080
Content-Type: application/json
CORS: Enabled for http://localhost:3000


Data Endpoints

GET /api/data

Query city data với pagination và filtering.

Request:

GET /api/data?type=HOT&sensorId=SENSOR_0042&page=0&size=20

Query Parameters:

ParameterTypeRequiredDefaultDescription
typestringNoAllFilter by data type: HOT, WARM, COLD
sensorIdstringNoAllFilter by sensor ID
pageintegerNo0Page number (0-indexed)
sizeintegerNo20Page size (max 100)

Response: 200 OK

{
"data": [
{
"timestamp": "2025-12-04T22:57:00Z",
"sensorId": "SENSOR_0042",
"metricType": "temperature",
"value": 45.5,
"dataType": "HOT",
"location": {
"lat": 21.0285,
"lng": 105.8542
}
}
],
"page": 0,
"size": 20,
"total": 150,
"totalPages": 8
}

Statistics Endpoints

GET /api/stats

Lấy thống kê hệ thống real-time.

Request:

GET /api/stats

Response: 200 OK

{
"hotCount": 14250000,
"warmCount": 0,
"coldCount": 25750000,
"incomingRate": 487.5,
"processedRate": 487.5,
"lastUpdate": "2025-12-04T22:57:00Z"
}

Fields:

FieldTypeDescription
hotCountlongSố lượng messages trong HOT tier (Redis)
warmCountlongSố lượng documents trong WARM tier (MongoDB)
coldCountlongSố lượng documents trong COLD tier (MongoDB)
incomingRatedoubleMessage rate incoming (msg/s)
processedRatedoubleMessage rate processed (msg/s)
lastUpdatestringTimestamp của stats update

Edge Storage Management Endpoints

GET /api/nodes

Liệt kê tất cả Edge Storage nodes với thông tin chi tiết.

Request:

GET /api/nodes

Response: 200 OK

[
{
"id": "subnet-caugiay",
"name": "Subnet-CauGiay",
"host": "rabbit-edge-1",
"port": 5672,
"enabled": true,
"status": "online",
"lastPing": "2025-12-07T23:30:00Z"
},
{
"id": "subnet-thanhxuan",
"name": "Subnet-ThanhXuan",
"host": "rabbit-edge-2",
"port": 5672,
"enabled": true,
"status": "online",
"lastPing": "2025-12-07T23:30:00Z"
}
]

Fields:

FieldTypeDescription
idstringUnique identifier (lowercase, hyphenated)
namestringDisplay name của edge node
hoststringHostname hoặc IP address của RabbitMQ
portintegerPort number của RabbitMQ
enabledbooleanTrạng thái kích hoạt của node
statusstringTrạng thái kết nối: "online" hoặc "offline"
lastPingstringTimestamp của lần ping cuối cùng

POST /api/nodes

Tạo mới một Edge Storage node.

Request:

POST /api/nodes
Content-Type: application/json

{
"name": "Subnet-HaDong",
"host": "rabbit-edge-3",
"port": 5672,
"queueName": "city-data-queue-3",
"username": "edge_user",
"password": "edge_pass"
}

Request Body:

FieldTypeRequiredDescription
namestringYesTên edge node (VD: "Subnet-HaDong")
hoststringYesHostname của RabbitMQ
portintegerYesPort number (thường là 5672)
queueNamestringNoTên queue (auto-generated nếu không cung cấp)
usernamestringNoRabbitMQ username (mặc định từ config)
passwordstringNoRabbitMQ password (mặc định từ config)

Response: 201 Created

{
"id": "subnet-hadong",
"name": "Subnet-HaDong",
"host": "rabbit-edge-3",
"port": 5672,
"status": "online",
"enabled": true
}

Error Response: 409 Conflict

{
"error": "Node with name 'Subnet-HaDong' already exists"
}

PUT /api/nodes/{name}/toggle

Toggle trạng thái enabled/disabled của một edge node.

Request:

PUT /api/nodes/Subnet-CauGiay/toggle

Response: 200 OK

{
"name": "Subnet-CauGiay",
"enabled": false,
"status": "offline"
}

DELETE /api/nodes/{name}

Xóa một edge node khỏi hệ thống.

Request:

DELETE /api/nodes/Subnet-HaDong

Response: 200 OK

{
"message": "Node deleted successfully",
"name": "Subnet-HaDong"
}

Error Response: 404 Not Found

{
"error": "Node 'Subnet-HaDong' not found"
}

System Control Endpoints

POST /api/sync/trigger

Trigger manual data synchronization từ tất cả edge nodes.

Request:

POST /api/sync/trigger

Response: 200 OK

{
"status": "success",
"messagesProcessed": 5247,
"timestamp": "2025-12-04T22:57:00Z"
}

POST /api/system/reset

⚠️ DESTRUCTIVE - Xóa toàn bộ dữ liệu (demo purpose only).

Request:

POST /api/system/reset

Response: 200 OK

{
"status": "success",
"message": "All data cleared successfully",
"timestamp": "2025-12-04T22:57:00Z"
}

Health Check

GET /actuator/health

Spring Boot Actuator health endpoint.

Request:

GET /actuator/health

Response: 200 OK

{
"status": "UP"
}

Error Responses

400 Bad Request

{
"error": "Invalid parameter",
"message": "Page size must be between 1 and 100",
"timestamp": "2025-12-04T22:57:00Z"
}

500 Internal Server Error

{
"error": "Internal server error",
"message": "Failed to connect to MongoDB",
"timestamp": "2025-12-04T22:57:00Z"
}