Skip to content

antoniogalluzzi/hazelcast-demo-spring-boot

Repository files navigation

🚀 Hazelcast Demo Project

Demo completo di Spring Boot + Hazelcast + PostgreSQL per cache distribuita enterprise

Java Spring Boot Hazelcast License

⚡ Quick Start (30 secondi)

# 1. Clone del progetto
git clone https://github.com/antoniogalluzzi/hazelcast-demo-spring-boot.git
cd hazelcast-demo-spring-boot

# 2. Avvio rapido
./mvnw spring-boot:run

# 3. Test funzionamento
curl http://localhost:8080/actuator/health

🎯 App disponibile su: http://localhost:8080
📖 API Docs: http://localhost:8080/swagger-ui.html
🗄️ H2 Console: http://localhost:8080/h2-console

🎯 Cosa Fa Questo Progetto

  • Cache Distribuita: Hazelcast in-memory cache
  • API REST: CRUD utenti con validazione
  • Database: PostgreSQL (prod) + H2 (dev)
  • Cloud Native: Deploy OpenShift/Kubernetes
  • Monitoring: Metriche complete + Health checks
  • Testing: Suite completa API/Performance

📚 Documentazione Completa

Tutto quello che serve in un unico posto:

🏃‍♂️ Setup Rapido per Ruolo

👨‍💻 Sviluppatore

./mvnw spring-boot:run  # Avvio con H2
# → http://localhost:8080/swagger-ui.html

🚀 DevOps

.\scripts\setup\setup-dev-environment.ps1     # Setup sviluppo locale
.\scripts\setup\setup-openshift-local.ps1     # Setup OpenShift Local
.\scripts\build\build-and-deploy.ps1          # Build e deploy automatico

🧪 Tester

curl -X POST http://localhost:8080/user -H "Content-Type: application/json" -d '{"name":"Test","email":"test@example.com"}'
curl http://localhost:8080/user/1  # Cache hit

📊 Status Progetto

✅ Funzionalità Implementate

  • Cache distribuita - Hazelcast cluster multi-nodo
  • API REST complete - CRUD + validazione
  • Deploy production-ready - OpenShift + script automatici
  • Testing suite - Unit, Integration, Performance
  • Monitoring enterprise - 40+ metriche personalizzate
  • Documentazione completa - Guide step-by-step

🔧 Ambienti Supportati

Ambiente Database Discovery Status
Development H2 In-Memory Multicast ✅ Ready
OpenShift Local PostgreSQL Kubernetes ✅ Ready
Cloud (AWS/Azure/GCP) PostgreSQL/RDS Kubernetes ✅ Ready

🎯 Demo Live

🧪 Test Cache Distribuita

# Crea utente (va in database + cache)
curl -X POST http://localhost:8080/user \
  -H "Content-Type: application/json" \
  -d '{"name": "Mario Rossi", "email": "mario@example.com"}'

# Recupera utente (dalla cache - veloce!)
curl http://localhost:8080/user/1

# Statistiche cache
curl http://localhost:8080/cache/stats

Risultato atteso:

{
  "cacheSize": 1,
  "hitCount": 1,
  "missCount": 0,
  "hitRate": 1.0,
  "clusterSize": 1
}

🚀 Deploy Produzione

OpenShift Local (⭐ Raccomandato)

# Setup completo automatico - Windows
.\setup-openshift-local.ps1

# Setup completo automatico - Linux/Mac
./setup-openshift-local.sh

Il script automaticamente:

  1. ✅ Verifica prerequisiti
  2. ✅ Deploy PostgreSQL
  3. ✅ Build e deploy app (2 repliche)
  4. ✅ Configura networking e DNS
  5. ✅ Esegue test funzionali

Cloud Providers

  • AWS EKS: eksctl create cluster --name hazelcast-demo
  • Azure AKS: az aks create --name hazelcast-demo-aks
  • Google GKE: gcloud container clusters create hazelcast-demo

Dettagli completi: DOCUMENTATION.md#deployment

🏆 Highlights Tecnici

🎯 Performance

  • Response Time: < 50ms (cache hit)
  • Throughput: 1000+ req/sec
  • Cache Hit Rate: > 90%
  • Cluster Scaling: Auto-discovery membri

📊 Monitoring

  • Health Checks: Liveness + Readiness probes
  • Metriche: JVM, HTTP, Cache, Database
  • Observability: Logs strutturati + tracing
  • Alerts: Configurabili via Actuator

🔐 Security & Best Practices

  • RBAC: Service accounts + role bindings
  • Validation: Input sanitization + constraints
  • Secrets: Environment-based configuration
  • Network: Service mesh ready

�️ Script di Automazione

📁 Nuova Struttura Script Modulari

La nuova collezione di script PowerShell modulari sostituisce completamente i vecchi script monolitici:

scripts/
├── 📖 README.md                    # Documentazione completa script
├── utilities/
│   ├── 🔧 common-functions.ps1     # Libreria funzioni condivise  
│   └── ✅ environment-check.ps1    # Verifica prerequisiti
├── setup/
│   ├── 🚀 setup-dev-environment.ps1      # Setup sviluppo locale
│   └── 🔴 setup-openshift-local.ps1      # Setup OpenShift Local
├── development/
│   ├── 🎯 cluster-manager.ps1            # Gestione cluster locale
│   └── 🧪 test-api-endpoints.ps1         # Testing API completo
└── build/
    └── 🏗️ build-and-deploy.ps1           # Build e deploy automatico

🎯 Quick Commands

# Setup completo ambiente sviluppo
.\scripts\setup\setup-dev-environment.ps1

# Test completo API con metriche performance  
.\scripts\development\test-api-endpoints.ps1 -TestLevel comprehensive

# Gestione cluster multi-istanza
.\scripts\development\cluster-manager.ps1 -Action start-cluster -Instances 3

# Build e deploy multi-ambiente
.\scripts\build\build-and-deploy.ps1 -Environment prod -Target kubernetes

# Setup OpenShift Local completo
.\scripts\setup\setup-openshift-local.ps1 -Action all

Caratteristiche Scripts

  • Modulari: Funzioni comuni condivise, specializzazione per funzionalità
  • Robusti: Retry logic, checkpoint/recovery, gestione errori avanzata
  • Flessibili: Multi-ambiente, multi-target, parametri configurabili
  • Completi: Copertura totale ciclo sviluppo e deployment
  • Documentati: Help integrato, logging dettagliato, esempi d'uso

📖 Guida Completa Scripts →

�📞 Supporto e Contributi

👤 Autore

Antonio Galluzzi

🤝 Come Contribuire

  1. Fork del repository
  2. Crea feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Apri Pull Request

🐛 Issue & Feature Request

📄 Licenza

Distribuito sotto Apache License 2.0. Vedi LICENSE per dettagli.

Copyright 2025 Antonio Galluzzi

Licensed under the Apache License, Version 2.0

Ti piace il progetto? Lascia una stella!

📖 Vai alla Documentazione Completa →

📋 Registro delle Modifiche

Vedi CHANGELOG.md per il registro completo delle modifiche e aggiornamenti del progetto.

Prerequisiti

Ambiente di Sviluppo

  • Java Development Kit (JDK) 17 ⚠️ (NON Java 21 - incompatibile con OpenShift Local)
  • Maven 3.6+ (wrapper incluso nel progetto)
  • Docker (per container locali)
  • Git (per controllo versione)

Ambiente OpenShift Local

  • OpenShift Local (CRC) versione 2.53.0+
  • OpenShift CLI (oc) versione 4.19.3+
  • RAM: 16GB minimum (32GB raccomandati)
  • CPU: 6 cores minimum (8+ raccomandati)
  • Storage: 35GB spazio libero

Ambiente Cloud (Opzionale)

  • AWS CLI + EKS CLI (per AWS EKS)
  • Azure CLI (per AKS)
  • gcloud CLI (per GKE)
  • Helm 3.x (per deployment Kubernetes)

Strumenti di Testing (Opzionali)

  • cURL o Postman (per test API)
  • Apache Bench o JMeter (per test performance)
  • jq (per parsing JSON nei test)

Sistema Operativo Supportato

  • Windows 10/11 Pro (con PowerShell)
  • macOS 10.15+
  • Linux (Ubuntu 18.04+, RHEL/CentOS 8+)

💻 Sviluppo Locale con H2

Per lo sviluppo locale, il progetto utilizza H2 Database (database in-memory) invece di PostgreSQL per semplicità e velocità.

Configurazione H2

Il profilo dev configura automaticamente H2 con le seguenti impostazioni:

spring:
  datasource:
    url: jdbc:h2:mem:testdb
    driverClassName: org.h2.Driver
    username: sa
    password:  # (vuoto)
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    show-sql: true
    hibernate:
      ddl-auto: create-drop
  h2:
    console:
      enabled: true

Avvio in Modalità Sviluppo

Per Linux/Mac (Bash)

# Avvia l'applicazione con profilo dev (H2)
./mvnw spring-boot:run -Dspring-boot.run.profiles=dev

Per Windows (PowerShell)

# Avvia l'applicazione con profilo dev (H2)
./maven/bin/mvn.cmd spring-boot:run "-Dspring-boot.run.profiles=dev"

Accesso alla Console H2

Una volta avviata l'applicazione, la console H2 è disponibile su:

  • URL: http://localhost:8080/h2-console
  • JDBC URL: jdbc:h2:mem:testdb
  • Username: sa
  • Password: (lascia vuoto)

Caratteristiche H2 per Sviluppo

  • In-Memory: I dati vengono persi al riavvio dell'applicazione
  • Auto-Create: Le tabelle vengono create automaticamente da Hibernate
  • SQL Logging: Le query SQL vengono mostrate nei log
  • Console Web: Interfaccia grafica per interrogare il database
  • Rapido: Nessuna dipendenza esterna da installare

Test delle API con H2

# Crea un utente
curl -X POST http://localhost:8080/user \
  -H "Content-Type: application/json" \
  -d '{"name":"Mario Rossi"}'

# Recupera l'utente (dalla cache)
curl http://localhost:8080/user/1

# Verifica health con metriche dettagliate
curl http://localhost:8080/actuator/health

# Visualizza metriche via Actuator
curl http://localhost:8080/actuator/metrics | head -20

# Accedi alla console H2
open http://localhost:8080/h2-console

Monitoraggio Locale

Durante lo sviluppo, puoi monitorare l'applicazione localmente:

# Metriche JVM in tempo reale
watch -n 5 'curl -s http://localhost:8080/actuator/metrics | head -n 50'

# Health check continuo
watch -n 10 'curl -s http://localhost:8080/actuator/health | jq .'

# Log strutturati JSON
tail -f logs/spring.log

Transizione Produzione

Quando si passa alla produzione, il profilo cambia automaticamente a PostgreSQL:

  • Dev: H2 in-memory (profilo dev)
  • Staging: PostgreSQL containerizzato (profilo staging)
  • Prod: PostgreSQL su OpenShift (profilo prod)

Build

Per Linux/Mac (Bash)

mvn clean package -DskipTests

Per Windows (PowerShell)

mvnw.cmd clean package -DskipTests

Docker

Costruisci l'immagine Docker:

Per Linux/Mac (Bash)

docker build -t hazelcast-demo .
docker tag hazelcast-demo <registry>/hazelcast-demo:latest
docker push <registry>/hazelcast-demo:latest

Per Windows (PowerShell)

docker build -t hazelcast-demo .
docker tag hazelcast-demo <registry>/hazelcast-demo:latest
docker push <registry>/hazelcast-demo:latest

Monitoraggio

L'app espone metriche tramite Spring Boot Actuator quando il profilo è abilitato; per verificarle, usa gli endpoint Actuator (es. /actuator/metrics).

Setup Manuale

Per Linux/Mac (Bash)

./setup-openshift-local.sh start     # Avvia CRC e configura ambiente
./setup-openshift-local.sh deploy    # Deploy completo (DB + App)
./setup-openshift-local.sh test      # Test automatici dell'applicazione
./setup-openshift-local.sh info      # Mostra info applicazione
./setup-openshift-local.sh cleanup   # Pulizia completa

Per Windows (PowerShell)

# Setup completo ambiente sviluppo
.\scripts\setup\setup-dev-environment.ps1

# Setup OpenShift Local automatico
.\scripts\setup\setup-openshift-local.ps1 -Action all

# Deploy solo applicazione (CRC già configurato)
.\scripts\setup\setup-openshift-local.ps1 -Action deploy

# Test API completo
.\scripts\development\test-api-endpoints.ps1 -TestLevel comprehensive

# Status cluster e monitoring
.\scripts\setup\setup-openshift-local.ps1 -Action status

Cosa include il setup completo:

  • Ambiente OpenShift Local - Installazione e configurazione CRC
  • Database PostgreSQL - Deploy con configurazione ottimizzata
  • Applicazione Spring Boot - Build e deploy con Java 17
  • Cluster Hazelcast Distribuito - 2 pod con cache condivisa
  • RBAC e Sicurezza - Service account e permessi minimi
  • Route Esterne - Accesso HTTP dall'esterno
  • Test di Validazione - Verifica funzionalità complete

🧪 Test e Validazione

Il progetto include una suite completa di test per validare funzionalità e performance.

Test Cache Distribuita Multi-Istanza

✅ Test Completati su OpenShift Local

  • Cluster Distribuito: 2 membri Hazelcast attivi verificati
  • Kubernetes Discovery: Auto-rilevamento pod funzionante
  • Cache Condivisa: Sincronizzazione dati tra pod confermata
  • API REST: Funzionanti su entrambi i pod
  • Load Balancing: Distribuzione automatica richieste

📊 Risultati Test Cluster

# Verifica membri cluster
oc logs deployment/hazelcast-demo | grep "Members {size:2"

# Output atteso:
Members {size:2, ver:2} [
    Member [10.217.0.102]:5701 - 6a618c70-72ca-40a3-9660-ed81543c7810 this
    Member [10.217.0.103]:5701 - 4ad84191-bf2a-400f-adf2-5a2f9c12a4a8
]

🔧 Configurazione Testata

  • Spring Boot 2.7.18 + Java 17 (compatibile CRC)
  • Hazelcast 5.1.7 con Kubernetes discovery
  • PostgreSQL 13 su OpenShift
  • RBAC configurato per discovery automatico
  • Monitoraggio del cluster tramite strumenti esterni (opzionale)

🏗️ Architettura Deployata

Pod Hazelcast-1 ──┐
                  ├── Kubernetes Service
Pod Hazelcast-2 ──┘
         │
         ├── PostgreSQL Database
         │
         └── Monitoring (esterno)

Test API REST

Endpoint Testati

  • GET /actuator/health - Health check
  • POST /user - Creazione utente
  • GET /user/{id} - Recupero utente con cache
  • GET /cache - Test cache

Risultati API Test

# Health Check
GET /actuator/health
✅ Status: {"status":"UP"}

# Creazione Utente
POST /user
✅ Status: 201 Created
✅ Response: {"id":1,"name":"Test User"}

# Recupero da Cache
GET /user/1
✅ Status: 200 OK
✅ Cache Hit: Servito dalla cache distribuita

Test Compilazione e Build

✅ Build Success

mvn clean compile
✅ BUILD SUCCESS
✅ Total time: 3.778 s

📦 Dipendenze Valide

  • ✅ Spring Boot Starter Web
  • ✅ Spring Boot Starter Data JPA
  • ✅ Hazelcast
  • ✅ H2 Database
  • ✅ SpringDoc OpenAPI

Test Logging e Monitoraggio

✅ Logging Strutturato

  • ✅ Log JSON configurato
  • ✅ MDC con contesto pod/namespace
  • ✅ Livelli appropriati (DEBUG/INFO/WARN)

✅ Health Checks

  • ✅ Spring Boot Actuator funzionante
  • ✅ Endpoint /actuator/health disponibile
  • ✅ Metriche esposte via Actuator (es. /actuator/metrics)

Test Database

✅ H2 Database (Sviluppo)

  • ✅ In-memory funzionante
  • ✅ Auto-create tabelle
  • ✅ Console H2 accessibile su /h2-console
  • ✅ JDBC URL: jdbc:h2:mem:testdb

✅ PostgreSQL (Produzione)

  • ✅ Configurazioni per staging/prod
  • ✅ Connection pooling HikariCP
  • ✅ JPA/Hibernate funzionanti

Test Sicurezza e Configurazione

✅ Configurazioni Ambiente

  • application-dev.yml - H2 per sviluppo
  • application-staging.yml - PostgreSQL staging
  • application-prod.yml - PostgreSQL produzione

✅ Hazelcast Configuration

  • ✅ Multicast discovery per sviluppo
  • ✅ Kubernetes discovery per produzione
  • ✅ Cluster name configurato

📚 Documentazione Avanzata

🗂️ Indice Completo: Per una navigazione guidata di tutta la documentazione, consulta DOCS_INDEX.md

API Documentation

Swagger UI

Una volta avviata l'applicazione, la documentazione interattiva API è disponibile su:

OpenAPI Specification

  • JSON: /v3/api-docs
  • YAML: /v3/api-docs.yaml

Informazioni API Configurate

La documentazione OpenAPI include le seguenti informazioni:

Endpoint Documentati

  • GET /user/{id} - Recupera utente con cache distribuita
  • POST /user - Crea nuovo utente
  • GET /cache - Test cache
  • GET /actuator/health - Health check
  • GET /actuator/metrics - Metriche disponibili via Actuator

Guide Specializzate

🚀 Deployment Guide

  • OPENSHIFT_DEPLOYMENT_GUIDE.md - Guida completa deployment OpenShift Local
    • Setup ambiente step-by-step
    • Configurazione cluster distribuito
    • Troubleshooting avanzato
    • Configurazione DNS e networking

🧪 Testing Guide

  • api-testing.md - Guida completa testing API
    • Test con cURL, Postman, JMeter
    • Test cache distribuita multi-istanza
    • Test performance e load
    • Automazione test

☁️ Cloud Deployment

  • cloud-deployment.md - Guide deployment cloud
    • Amazon EKS
    • Google GKE
    • Microsoft AKS
    • Configurazioni multi-cloud

⚙️ Environment Configuration

  • environment-configs.md - Configurazioni ambiente
    • Profili Spring Boot (dev/staging/prod)
    • Configurazioni Hazelcast
    • Best practices configurazione

📋 Changelog

  • CHANGELOG.md - Registro completo modifiche
    • Cronologia versioni
    • Nuove funzionalità
    • Bug fix e miglioramenti

🎯 Stato del Progetto

✅ Funzionalità Implementate

🏗️ Architettura

  • ✅ Spring Boot 2.7.18 con Java 17
  • ✅ Hazelcast 5.1.7 per cache distribuita
  • ✅ PostgreSQL 13 per persistenza
  • ✅ Docker containerizzato
  • ✅ Kubernetes/OpenShift deployment

📊 Monitoraggio Enterprise

  • ✅ Micrometer instrumentation
  • ✅ JVM, HTTP, Database, Cache metrics
  • ✅ Alert e monitoring in tempo reale

🚀 Deployment Completo

  • ✅ OpenShift Local support completo
  • ✅ Cluster distribuito 2+ membri
  • ✅ RBAC e sicurezza configurati
  • ✅ Route e networking
  • ✅ Health checks e readiness

🧪 Testing Suite

  • ✅ API testing completo (cURL, Postman, JMeter)
  • ✅ Test cache distribuita
  • ✅ Test performance e load
  • ✅ Test sicurezza e validazione
  • ✅ Automazione test

📚 Documentazione

  • ✅ README completo con guide
  • ✅ Deployment guide step-by-step
  • ✅ API testing documentation
  • ✅ Cloud deployment guides
  • ✅ Troubleshooting avanzato

🔧 Configurazioni Ambiente

Ambiente Database Hazelcast Discovery Java Version Status
Development H2 In-Memory Multicast 17 ✅ Completo
OpenShift Local PostgreSQL Kubernetes 17 ✅ Completo
Staging PostgreSQL TCP-IP 17 ✅ Configurato
Production PostgreSQL Kubernetes 17 ✅ Configurato

📈 Metriche Monitoraggio

Il sistema espone 40+ metriche categorizzate:

  • JVM: Memoria, CPU, GC, Thread, Classes
  • HTTP: Requests/sec, Response time, Status codes, Errors
  • Hazelcast: Cache operations, Hit rate, Cluster size, Performance
  • Database: Connections, Pool utilization, Query timing
  • System: CPU/Memory usage, Disk I/O, Application uptime

🎉 Ready for Production

Il progetto è completamente funzionale e pronto per:

  • Deploy in produzione su OpenShift/Kubernetes
  • Scale orizzontale con più repliche
  • Testing automatizzato per CI/CD
  • Documentazione completa per manutenzione

🚀 Prossimi Passi Consigliati:

  1. Deploy su ambiente cloud (AWS EKS, Azure AKS, Google GKE)
  2. Implementare CI/CD pipeline
  3. Aggiungere autenticazione/autorizzazione
  4. Configurare backup database
  5. Implementare logging centralizzato c:\Users\anton\Downloads\hazelcast\README.md

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors