mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 11:02:54 +00:00
refactor: Extract carrier setup logic into separate file and remove unnecessary comments
- Move SetupCarriers method from selection_integration.go to new setup_carriers.go file - Remove redundant comments from SelectionIntegration struct and methods - Clean up inline comments in RunDemo method while preserving functionality
This commit is contained in:
@@ -6,14 +6,12 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/config"
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/handlers"
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/service"
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/smdp"
|
||||
)
|
||||
|
||||
// SelectionIntegration wires together the carrier selection components
|
||||
type SelectionIntegration struct {
|
||||
manager *smdp.SMDPManager
|
||||
selectionService *service.SelectionService
|
||||
@@ -22,7 +20,6 @@ type SelectionIntegration struct {
|
||||
server *http.Server
|
||||
}
|
||||
|
||||
// NewSelectionIntegration creates a new selection integration
|
||||
func NewSelectionIntegration(repo *repository.PostgresProfileStore) *SelectionIntegration {
|
||||
// Create SMDP manager with default configuration
|
||||
config := &smdp.ManagerConfig{
|
||||
@@ -49,131 +46,6 @@ func NewSelectionIntegration(repo *repository.PostgresProfileStore) *SelectionIn
|
||||
}
|
||||
}
|
||||
|
||||
// SetupCarriers configures default carriers for demonstration
|
||||
func (si *SelectionIntegration) SetupCarriers() error {
|
||||
// Configure sample carriers with different characteristics
|
||||
carriers := []*smdp.Carrier{
|
||||
{
|
||||
ID: "att-us",
|
||||
Name: "AT&T US",
|
||||
MCC: "310",
|
||||
MNC: "410",
|
||||
CountryCode: "US",
|
||||
IsActive: true,
|
||||
Priority: 90,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.att.com",
|
||||
APIKey: "demo-key-att",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{"bulk_download", "remote_provisioning"},
|
||||
MaxConcurrentRequests: 100,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 1000,
|
||||
SuccessfulRequests: 980,
|
||||
FailedRequests: 20,
|
||||
AverageResponseTime: 150 * time.Millisecond,
|
||||
RequestRate: 10.5,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "verizon-us",
|
||||
Name: "Verizon US",
|
||||
MCC: "311",
|
||||
MNC: "480",
|
||||
CountryCode: "US",
|
||||
IsActive: true,
|
||||
Priority: 85,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.verizon.com",
|
||||
APIKey: "demo-key-verizon",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{"bulk_download"},
|
||||
MaxConcurrentRequests: 80,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 800,
|
||||
SuccessfulRequests: 790,
|
||||
FailedRequests: 10,
|
||||
AverageResponseTime: 120 * time.Millisecond,
|
||||
RequestRate: 8.2,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "tmobile-de",
|
||||
Name: "T-Mobile Germany",
|
||||
MCC: "262",
|
||||
MNC: "01",
|
||||
CountryCode: "DE",
|
||||
IsActive: true,
|
||||
Priority: 75,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.t-mobile.de",
|
||||
APIKey: "demo-key-tmobile",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational"},
|
||||
Features: []string{"remote_provisioning"},
|
||||
MaxConcurrentRequests: 60,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 600,
|
||||
SuccessfulRequests: 570,
|
||||
FailedRequests: 30,
|
||||
AverageResponseTime: 200 * time.Millisecond,
|
||||
RequestRate: 6.8,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "orange-fr",
|
||||
Name: "Orange France",
|
||||
MCC: "208",
|
||||
MNC: "01",
|
||||
CountryCode: "FR",
|
||||
IsActive: true,
|
||||
Priority: 70,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.orange.fr",
|
||||
APIKey: "demo-key-orange",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{},
|
||||
MaxConcurrentRequests: 50,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 400,
|
||||
SuccessfulRequests: 380,
|
||||
FailedRequests: 20,
|
||||
AverageResponseTime: 180 * time.Millisecond,
|
||||
RequestRate: 4.5,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Add carriers to the manager
|
||||
for _, carrier := range carriers {
|
||||
if err := si.manager.AddCarrier(carrier); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Added %d carriers to the selection manager", len(carriers))
|
||||
return nil
|
||||
}
|
||||
|
||||
// StartServer starts the HTTP server with all endpoints
|
||||
func (si *SelectionIntegration) StartServer(port string) error {
|
||||
// Create HTTP multiplexer
|
||||
@@ -225,25 +97,19 @@ func (si *SelectionIntegration) Shutdown(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunDemo runs a demonstration of the carrier selection capabilities
|
||||
func (si *SelectionIntegration) RunDemo(ctx context.Context) error {
|
||||
log.Println("Starting carrier selection demonstration...")
|
||||
|
||||
// Setup carriers
|
||||
if err := si.SetupCarriers(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Start health checking
|
||||
si.StartHealthChecking(ctx)
|
||||
|
||||
// Wait a moment for health checks to initialize
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Demonstrate intelligent carrier selection
|
||||
log.Println("Demonstrating intelligent carrier selection...")
|
||||
|
||||
// Test different selection scenarios
|
||||
scenarios := []struct {
|
||||
name string
|
||||
criteria *smdp.SelectionCriteria
|
||||
@@ -300,7 +166,6 @@ func (si *SelectionIntegration) RunDemo(ctx context.Context) error {
|
||||
log.Println("---")
|
||||
}
|
||||
|
||||
// Demonstrate analytics
|
||||
log.Println("Generating carrier analytics...")
|
||||
analytics, err := si.selectionService.GetCarrierAnalytics(ctx)
|
||||
if err != nil {
|
||||
@@ -311,7 +176,6 @@ func (si *SelectionIntegration) RunDemo(ctx context.Context) error {
|
||||
log.Printf("Overall success rate: %.1f%%", analytics.Summary.OverallSuccessRate)
|
||||
}
|
||||
|
||||
// Demonstrate optimization recommendations
|
||||
log.Println("Generating optimization recommendations...")
|
||||
optimization, err := si.selectionService.OptimizeCarrierSelection(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/config"
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/smdp"
|
||||
)
|
||||
|
||||
// SetupCarriers configures default carriers for demonstration
|
||||
func (si *SelectionIntegration) SetupCarriers() error {
|
||||
// Configure sample carriers with different characteristics
|
||||
carriers := []*smdp.Carrier{
|
||||
{
|
||||
ID: "att-us",
|
||||
Name: "AT&T US",
|
||||
MCC: "310",
|
||||
MNC: "410",
|
||||
CountryCode: "US",
|
||||
IsActive: true,
|
||||
Priority: 90,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.att.com",
|
||||
APIKey: "demo-key-att",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{"bulk_download", "remote_provisioning"},
|
||||
MaxConcurrentRequests: 100,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 1000,
|
||||
SuccessfulRequests: 980,
|
||||
FailedRequests: 20,
|
||||
AverageResponseTime: 150 * time.Millisecond,
|
||||
RequestRate: 10.5,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "verizon-us",
|
||||
Name: "Verizon US",
|
||||
MCC: "311",
|
||||
MNC: "480",
|
||||
CountryCode: "US",
|
||||
IsActive: true,
|
||||
Priority: 85,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.verizon.com",
|
||||
APIKey: "demo-key-verizon",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{"bulk_download"},
|
||||
MaxConcurrentRequests: 80,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 800,
|
||||
SuccessfulRequests: 790,
|
||||
FailedRequests: 10,
|
||||
AverageResponseTime: 120 * time.Millisecond,
|
||||
RequestRate: 8.2,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "tmobile-de",
|
||||
Name: "T-Mobile Germany",
|
||||
MCC: "262",
|
||||
MNC: "01",
|
||||
CountryCode: "DE",
|
||||
IsActive: true,
|
||||
Priority: 75,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.t-mobile.de",
|
||||
APIKey: "demo-key-tmobile",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational"},
|
||||
Features: []string{"remote_provisioning"},
|
||||
MaxConcurrentRequests: 60,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 600,
|
||||
SuccessfulRequests: 570,
|
||||
FailedRequests: 30,
|
||||
AverageResponseTime: 200 * time.Millisecond,
|
||||
RequestRate: 6.8,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "orange-fr",
|
||||
Name: "Orange France",
|
||||
MCC: "208",
|
||||
MNC: "01",
|
||||
CountryCode: "FR",
|
||||
IsActive: true,
|
||||
Priority: 70,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.orange.fr",
|
||||
APIKey: "demo-key-orange",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{},
|
||||
MaxConcurrentRequests: 50,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 400,
|
||||
SuccessfulRequests: 380,
|
||||
FailedRequests: 20,
|
||||
AverageResponseTime: 180 * time.Millisecond,
|
||||
RequestRate: 4.5,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Add carriers to the manager
|
||||
for _, carrier := range carriers {
|
||||
if err := si.manager.AddCarrier(carrier); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Added %d carriers to the selection manager", len(carriers))
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user