A microservice for tracking trainer monthly workload in the Gym CRM System.
Workload Service accepts information about trainings (add/delete) and calculates the total working hours for each trainer by month. Data is stored in an in-memory structure for fast access.
- β REST API for adding/deleting trainer workload
- β In-memory data storage (ConcurrentHashMap)
- β JWT Bearer Token authorization
- β Eureka Discovery Service registration
- β Two-level logging (Transaction + Operation)
- β Circuit Breaker (Resilience4j)
- β Actuator endpoints for monitoring
- β Prometheus metrics
- Java 17
- Spring Boot 3.5.3
- Spring Cloud (Eureka Client)
- Spring Security + JWT
- Resilience4j
- Lombok
- SLF4J/Logback
workload-service/
βββ src/main/java/abu/epam/com/workloadservice/
β βββ config/ # Configuration (Security)
β βββ controller/ # REST Controllers
β βββ dto/ # Data Transfer Objects
β βββ filter/ # Filters (Logging, Transaction)
β βββ model/ # Data Models
β βββ security/ # JWT components
β βββ service/ # Business Logic
βββ src/main/resources/
βββ application.yml # Application configuration
βββ logback-spring.xml # Logging configuration
POST /api/workload
Authorization: Bearer <JWT_TOKEN>
Content-Type: application/json
{
"username": "john.doe",
"firstName": "John",
"lastName": "Doe",
"isActive": true,
"trainingDate": "2024-02-08",
"trainingDuration": 60,
"actionType": "ADD"
}Field Descriptions:
username- Trainer's unique usernamefirstName- Trainer's first namelastName- Trainer's last nameisActive- Trainer's active statustrainingDate- Training datetrainingDuration- Training duration (in minutes)actionType- Action type:ADDorDELETE
Response:
200 OK- Workload updated successfully400 Bad Request- Validation error401 Unauthorized- Missing or invalid JWT token
GET /api/workload/{username}
Authorization: Bearer <JWT_TOKEN>Response:
{
"username": "john.doe",
"firstName": "John",
"lastName": "Doe",
"isActive": true,
"years": {
"2024": {
"months": {
"1": {
"totalDuration": 120
},
"2": {
"totalDuration": 180
}
}
}
}
}GET /api/workload
Authorization: Bearer <JWT_TOKEN>- Application:
8082 - Eureka Server:
8761(default)
Default: MySecretKeyForJWTTokenGenerationAndValidationPurpose12345
To change, update in application.yml:
jwt:
secret: YOUR_SECRET_KEYeureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/- JDK 17+
- Maven 3.6+
- Eureka Server (should be running on port 8761)
# Build the project
mvn clean package
# Run the application
mvn spring-boot:run
# Or run the JAR file
java -jar target/workload-service-0.0.1-SNAPSHOT.jarAccess interactive API documentation at:
- Swagger UI:
http://localhost:8082/swagger-ui.html - OpenAPI Spec:
http://localhost:8082/v3/api-docs
The Swagger UI provides:
- Interactive API testing
- Request/response examples
- Schema definitions
- JWT authentication testing (click "Authorize" button and enter your JWT token)
- Health:
http://localhost:8082/actuator/health - Metrics:
http://localhost:8082/actuator/metrics - Prometheus:
http://localhost:8082/actuator/prometheus
HTTP request/response logging with unique transactionId generation:
2024-02-08 10:30:45.123 [http-nio-8082-exec-1] INFO [TxId: abc-123-def] [TRANSACTION] START - Method: POST, URI: /api/workload
2024-02-08 10:30:45.456 [http-nio-8082-exec-1] INFO [TxId: abc-123-def] [TRANSACTION] END - Status: 200, Duration: 333ms
Detailed logging of operations within the transaction:
2024-02-08 10:30:45.234 [http-nio-8082-exec-1] DEBUG [TxId: abc-123-def] [OPERATION] Request Body: {...}
2024-02-08 10:30:45.345 [http-nio-8082-exec-1] INFO [TxId: abc-123-def] Processing workload for trainer: john.doe
Logs are saved to:
- Console output
logs/workload-service.log- Rotation: daily, retention 30 days
Resilience4j Circuit Breaker configured with:
- Sliding Window Size: 10 requests
- Failure Rate Threshold: 50%
- Wait Duration in Open State: 5 seconds
- Minimum Number of Calls: 5
Workload Service is designed to be called from the main Gym-CRM-system when:
- Creating a new training (actionType: ADD)
- Deleting a training (actionType: DELETE)
All API endpoints (except actuator) are protected with JWT authentication.
For access:
- Obtain JWT token from the main Gym-CRM-system
- Add token to header:
Authorization: Bearer <token>
# Add training
curl -X POST http://localhost:8082/api/workload \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"username": "john.doe",
"firstName": "John",
"lastName": "Doe",
"isActive": true,
"trainingDate": "2024-02-08",
"trainingDuration": 60,
"actionType": "ADD"
}'
# Get trainer workload
curl -X GET http://localhost:8082/api/workload/john.doe \
-H "Authorization: Bearer YOUR_JWT_TOKEN"- Check that Eureka Server is running on
localhost:8761 - Check logs for connection errors
- Ensure
eureka.client.register-with-eureka=true
- Ensure you're using the correct secret key
- Check token format:
Bearer <token> - Verify token expiration
The service uses in-memory storage. All data is lost on restart. This is expected behavior according to requirements.
Developed as part of EPAM Specialization Program.