Files
telecom-platform/apps/carrier-connector/routes.go
T
NutcaseandGitHub d61aa93bd5 Multi carriersm dp+ (#61)
* refactor: Rename handler package to handlers in carrier-connector

- Rename internal/handler directory to internal/handlers
- Update handler import path in main.go and routes.go

* feat: Add SM-DP+ handler with multi-carrier management and profile operations

- Add SMDPHandler struct with manager field and NewSMDPHandler constructor
- Add AddCarrier endpoint with JSON binding and carrier configuration support
- Add RemoveCarrier endpoint with carrier ID parameter validation
- Add DownloadProfile endpoint with 30-second timeout and context cancellation
- Add GetCarrierStatus endpoint returning all carriers with timestamp
- Add GetProfileStatus endpoint with EID/ICCID validation

* feat: Add SM-DP+ integration layer with multi-carrier system initialization and route registration

- Add SMDPIntegration struct with service, handler, repository, and logger fields
- Add NewSMDPIntegration constructor with default carrier initialization
- Add InitializeSystem method with carrier health logging and status tracking
- Add RegisterRoutes method with profile, carrier, health, and metrics endpoints
- Add healthHandler with carrier health status aggregation and degraded state detection
- Add metricsHandler

* feat: Add SM-DP+ service layer with multi-carrier management and profile download operations

- Add SMDPService struct with manager, repository, and logger fields
- Add NewSMDPService constructor with default config and background health checking
- Add InitializeDefaultCarriers with AT&T, Verizon, and T-Mobile DE configurations
- Add DownloadProfile method with context support and request logging
- Add GetOptimalCarrier wrapping SelectCarrier for best carrier selection
- Add GetCarrierHealth returning

* feat: Add SM-DP+ manager with multi-carrier load balancing, health checking, and profile operations

- Add DefaultManagerConfig with 30s health checks, 3 retries, and circuit breaker configuration
- Add CarrierConfig struct with ES2 settings, MCC/MNC, priority, and feature support
- Add ToCarrier method converting CarrierConfig to Carrier with metrics and capabilities
- Add HealthChecker with periodic carrier health monitoring and status evaluation
- Add LoadBalancer with weighted round-robin, least
2026-05-01 20:24:34 +03:00

83 lines
2.7 KiB
Go

package main
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
handler "github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/handlers"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/mq"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/webhook"
)
// setupRoutes registers all HTTP routes, wiring the ES2+ client, profile repo, webhook client, and message queue.
func setupRoutes(router *gin.Engine, client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient, messageQueue *mq.MessageQueue) {
api := router.Group("/api/v1")
api.GET("/health", healthHandler)
api.GET("/health/ready", readinessHandler(repo))
api.GET("/health/live", livenessHandler)
api.GET("/metrics", gin.WrapH(promhttp.Handler()))
esim := api.Group("/esim")
{
esim.POST("/profiles", handler.OrderProfileHandlerWithRepo(client, repo, webhookClient, messageQueue))
esim.GET("/profiles", handler.ListProfilesHandlerWithRepo(repo))
esim.GET("/profiles/:profileId", handler.GetProfileHandlerWithRepo(client, repo))
esim.DELETE("/profiles/:profileId", handler.DeleteProfileHandlerWithRepo(client, repo, webhookClient, messageQueue))
}
carrier := api.Group("/carrier")
{
carrier.GET("/info", handler.GetCarrierInfoHandler(client))
carrier.GET("/connectivity", handler.CheckConnectivityHandler(client))
}
}
// healthHandler returns a simple liveness response.
func healthHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "healthy",
"service": "carrier-connector",
"timestamp": time.Now().UTC(),
})
}
// livenessHandler returns a simple liveness check (always healthy if service is running).
func livenessHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "alive",
"service": "carrier-connector",
"timestamp": time.Now().UTC(),
})
}
// readinessHandler checks if the service is ready to accept requests (database connectivity).
func readinessHandler(repo repository.ProfileRepository) gin.HandlerFunc {
return func(c *gin.Context) {
// Check database connectivity
if err := repo.Ping(); err != nil {
c.JSON(http.StatusServiceUnavailable, gin.H{
"status": "not ready",
"service": "carrier-connector",
"timestamp": time.Now().UTC(),
"error": "database connection failed",
"details": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"status": "ready",
"service": "carrier-connector",
"timestamp": time.Now().UTC(),
"checks": gin.H{
"database": "ok",
},
})
}
}