Skip to content

A microservice component of the Cloud Resource Reservation system that processes reservation events, handles webhooks, and manages event notifications. This Spring Boot application serves as an event processor to facilitate real-time updates and integrations for resource reservations.

License

Notifications You must be signed in to change notification settings

netgroup-polito/reservation-event-processor

 
 

Repository files navigation

Reservation Event Processor

License: MIT Java Spring Boot Docker Kubernetes

A Spring Boot service responsible for processing resource reservation events (like start and end times) and dispatching notifications via webhooks.

Note: This service is part of a larger project available at cloud-resource-reservation, which includes the main backend, frontend, Keycloak configuration, and Docker Compose setup to run the complete system.

🎯 Role in the Project

The reservation-event-processor complements the main reservation-be service by handling time-based, asynchronous tasks. It periodically checks the database for resource reservations that are about to start or have just ended and triggers external actions (like sending webhook notifications) based on these events.

✨ Key Features

  • Event Processing: Regularly checks for upcoming and concluded reservation events.
  • Webhook Notifications: Sends notifications for EVENT_START and EVENT_END to configured external services via webhooks. The payload includes batch event information and currently active resources for the user.

For detailed webhook payload examples and documentation, see webhook-payload-examples.md in the root project directory.

  • Scheduling: Uses Spring Scheduler for periodic checks.
  • Persistence: Interacts with the PostgreSQL database using Spring Data JPA.
  • Flexible Configuration: Configurable via environment variables or application.properties/application.yml files.

🛠️ Technology Stack

  • Java 23
  • Spring Boot 3.2.4
  • Spring Data JPA
  • Spring Web (for Actuator)
  • PostgreSQL
  • Maven
  • Lombok
  • Keycloak Admin Client (potentially for fetching user/resource details, though current usage seems limited in the provided code)
  • Docker
  • Kubernetes (configurations provided in k8s/)

🚀 Getting Started

Prerequisites

  • JDK 23 or higher
  • Maven 3.6+
  • Accessible PostgreSQL Database
  • (Optional) Docker
  • (Optional) Access to a Kubernetes cluster

Configuration

The service can be configured using environment variables or an application.properties/application.yml file. Key configuration options include:

  • SPRING_PROFILES_ACTIVE: Active Spring profile (e.g., dev, test, pro).
  • SPRING_DATASOURCE_URL: PostgreSQL database URL.
  • SPRING_DATASOURCE_USERNAME: Database username.
  • SPRING_DATASOURCE_PASSWORD: Database password.
  • KEYCLOAK_AUTH_SERVER_URL: Keycloak server URL.
  • KEYCLOAK_REALM: Keycloak realm.
  • KEYCLOAK_CLIENT_ID: Client ID for service authentication.
  • KEYCLOAK_CLIENT_SECRET: Client secret for service authentication.
  • WEBHOOK_CONFIG_URL: URL to fetch webhook configuration (if applicable).
  • EVENT_PROCESSOR_RATE: Scheduler execution frequency (in milliseconds, e.g., 60000 for 1 minute).
  • APP_DEFAULT_ZONE_ID: Default time zone (e.g., Europe/Rome).
  • LOGGING_LEVEL_ROOT: Global logging level (e.g., INFO, DEBUG).

For Kubernetes, these configurations are managed via ConfigMap and Secret in the k8s/ directory.

Build

To compile the project and create the executable JAR file, use Maven:

./mvnw clean package
# or
# mvn clean package

This will create a JAR file in the target/ directory.

Running

Local Execution

java -jar target/reservation-event-processor-*.jar --spring.profiles.active=dev # or other profiles

Ensure you provide the necessary environment variables or an application-dev.properties file with the required configurations.

Docker

A Dockerfile is provided to build a Docker image.

  1. Build the image:

    docker build -t reservation-event-processor .
  2. Run the container:

    docker run -e SPRING_PROFILES_ACTIVE=pro \
           -e SPRING_DATASOURCE_URL=jdbc:postgresql://your-postgres-host:5432/resourcemgmt \
           -e SPRING_DATASOURCE_USERNAME=your_user \
           -e SPRING_DATASOURCE_PASSWORD=your_password \
           # ... other environment variables ... \
           reservation-event-processor

Kubernetes

Configurations for Kubernetes deployment are located in the k8s/ directory. You need to apply the ConfigMap, Secret, and Deployment manifests.

kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secret.yaml # Ensure secrets are Base64 encoded
kubectl apply -f k8s/deployment.yaml

🔌 API Endpoints

The service primarily exposes Spring Boot Actuator endpoints for monitoring:

  • /actuator/health: Checks the application's health status.
  • Other Actuator endpoints might be available depending on the configuration.

🤝 Contributing

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file in the root project directory for details.

About

A microservice component of the Cloud Resource Reservation system that processes reservation events, handles webhooks, and manages event notifications. This Spring Boot application serves as an event processor to facilitate real-time updates and integrations for resource reservations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 93.3%
  • Shell 5.5%
  • Dockerfile 1.2%