Files
rustytorch/crates/specialized/rtx-platform/src/lib.rs
T
2026-03-04 00:08:42 +00:00

122 lines
3.7 KiB
Rust

//! # RustyTorch++ Platform - Global Multi-Tenant Platform
//!
//! This crate provides a comprehensive multi-tenant platform for RustyTorch++,
//! including multi-region orchestration, tenant isolation, billing, federation,
//! and SLA monitoring capabilities.
pub mod billing;
pub mod error;
pub mod federation;
pub mod metrics;
pub mod region;
pub mod security;
pub mod slo;
pub mod tenant;
pub use error::{PlatformError, PlatformResult};
/// Platform configuration
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PlatformConfig {
/// Database connection URL
pub database_url: String,
/// Redis cluster connection
pub redis_urls: Vec<String>,
/// Kafka brokers
pub kafka_brokers: Vec<String>,
/// Prometheus metrics endpoint
pub metrics_endpoint: String,
/// Regional configurations
pub regions: std::collections::HashMap<String, region::RegionConfig>,
/// Global SLA targets
pub sla_targets: slo::SlaTargets,
}
/// Main platform orchestrator
#[derive(Debug)]
pub struct Platform {
config: PlatformConfig,
region_manager: region::RegionManager,
tenant_manager: tenant::TenantManager,
billing_pipeline: billing::BillingPipeline,
federation_manager: federation::FederationManager,
slo_monitor: slo::SloMonitor,
}
impl Platform {
/// Create new platform instance
pub async fn new(config: PlatformConfig) -> PlatformResult<Self> {
let region_manager = region::RegionManager::new(&config).await?;
let tenant_manager = tenant::TenantManager::new(&config).await?;
let billing_pipeline = billing::BillingPipeline::new(&config).await?;
let privacy_config = federation::PrivacyConfig {
epsilon: 1.0,
delta: 1e-5,
noise_multiplier: 1.1,
max_grad_norm: 4.0,
secure_aggregation: true,
homomorphic_encryption: true,
minimum_participants: 2,
consent_required: true,
};
let federation_manager =
federation::FederationManager::new(&config, privacy_config).await?;
let slo_monitor = slo::SloMonitor::new(&config).await?;
Ok(Self {
config,
region_manager,
tenant_manager,
billing_pipeline,
federation_manager,
slo_monitor,
})
}
/// Start platform services
pub async fn start(&mut self) -> PlatformResult<()> {
tracing::info!("Starting RustyTorch++ Platform");
// Start all components in parallel
let (region_res, tenant_res, billing_res, federation_res, slo_res) = tokio::join!(
self.region_manager.start(),
self.tenant_manager.start(),
self.billing_pipeline.start(),
self.federation_manager.start(),
self.slo_monitor.start(),
);
region_res?;
tenant_res?;
billing_res?;
federation_res?;
slo_res?;
tracing::info!("RustyTorch++ Platform started successfully");
Ok(())
}
/// Shutdown platform services
pub async fn shutdown(&mut self) -> PlatformResult<()> {
tracing::info!("Shutting down RustyTorch++ Platform");
// Shutdown all components in reverse order
let (slo_res, federation_res, billing_res, tenant_res, region_res) = tokio::join!(
self.slo_monitor.shutdown(),
self.federation_manager.shutdown(),
self.billing_pipeline.shutdown(),
self.tenant_manager.shutdown(),
self.region_manager.shutdown(),
);
slo_res?;
federation_res?;
billing_res?;
tenant_res?;
region_res?;
tracing::info!("RustyTorch++ Platform shutdown complete");
Ok(())
}
}