chore: align slurp config and scaffolding
This commit is contained in:
@@ -7,39 +7,39 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"chorus/pkg/dht"
|
||||
"chorus/pkg/crypto"
|
||||
"chorus/pkg/election"
|
||||
"chorus/pkg/config"
|
||||
"chorus/pkg/ucxl"
|
||||
"chorus/pkg/crypto"
|
||||
"chorus/pkg/dht"
|
||||
"chorus/pkg/election"
|
||||
slurpContext "chorus/pkg/slurp/context"
|
||||
"chorus/pkg/ucxl"
|
||||
)
|
||||
|
||||
// DistributionCoordinator orchestrates distributed context operations across the cluster
|
||||
type DistributionCoordinator struct {
|
||||
mu sync.RWMutex
|
||||
config *config.Config
|
||||
dht *dht.DHT
|
||||
roleCrypto *crypto.RoleCrypto
|
||||
election election.Election
|
||||
distributor ContextDistributor
|
||||
replicationMgr ReplicationManager
|
||||
conflictResolver ConflictResolver
|
||||
gossipProtocol GossipProtocol
|
||||
networkMgr NetworkManager
|
||||
|
||||
mu sync.RWMutex
|
||||
config *config.Config
|
||||
dht dht.DHT
|
||||
roleCrypto *crypto.RoleCrypto
|
||||
election election.Election
|
||||
distributor ContextDistributor
|
||||
replicationMgr ReplicationManager
|
||||
conflictResolver ConflictResolver
|
||||
gossipProtocol GossipProtocol
|
||||
networkMgr NetworkManager
|
||||
|
||||
// Coordination state
|
||||
isLeader bool
|
||||
leaderID string
|
||||
coordinationTasks chan *CoordinationTask
|
||||
distributionQueue chan *DistributionRequest
|
||||
roleFilters map[string]*RoleFilter
|
||||
healthMonitors map[string]*HealthMonitor
|
||||
|
||||
isLeader bool
|
||||
leaderID string
|
||||
coordinationTasks chan *CoordinationTask
|
||||
distributionQueue chan *DistributionRequest
|
||||
roleFilters map[string]*RoleFilter
|
||||
healthMonitors map[string]*HealthMonitor
|
||||
|
||||
// Statistics and metrics
|
||||
stats *CoordinationStatistics
|
||||
performanceMetrics *PerformanceMetrics
|
||||
|
||||
stats *CoordinationStatistics
|
||||
performanceMetrics *PerformanceMetrics
|
||||
|
||||
// Configuration
|
||||
maxConcurrentTasks int
|
||||
healthCheckInterval time.Duration
|
||||
@@ -49,14 +49,14 @@ type DistributionCoordinator struct {
|
||||
|
||||
// CoordinationTask represents a task for the coordinator
|
||||
type CoordinationTask struct {
|
||||
TaskID string `json:"task_id"`
|
||||
TaskType CoordinationTaskType `json:"task_type"`
|
||||
Priority Priority `json:"priority"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
RequestedBy string `json:"requested_by"`
|
||||
Payload interface{} `json:"payload"`
|
||||
Context context.Context `json:"-"`
|
||||
Callback func(error) `json:"-"`
|
||||
TaskID string `json:"task_id"`
|
||||
TaskType CoordinationTaskType `json:"task_type"`
|
||||
Priority Priority `json:"priority"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
RequestedBy string `json:"requested_by"`
|
||||
Payload interface{} `json:"payload"`
|
||||
Context context.Context `json:"-"`
|
||||
Callback func(error) `json:"-"`
|
||||
}
|
||||
|
||||
// CoordinationTaskType represents different types of coordination tasks
|
||||
@@ -74,55 +74,55 @@ const (
|
||||
|
||||
// DistributionRequest represents a request for context distribution
|
||||
type DistributionRequest struct {
|
||||
RequestID string `json:"request_id"`
|
||||
ContextNode *slurpContext.ContextNode `json:"context_node"`
|
||||
TargetRoles []string `json:"target_roles"`
|
||||
Priority Priority `json:"priority"`
|
||||
RequesterID string `json:"requester_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Options *DistributionOptions `json:"options"`
|
||||
Callback func(*DistributionResult, error) `json:"-"`
|
||||
RequestID string `json:"request_id"`
|
||||
ContextNode *slurpContext.ContextNode `json:"context_node"`
|
||||
TargetRoles []string `json:"target_roles"`
|
||||
Priority Priority `json:"priority"`
|
||||
RequesterID string `json:"requester_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Options *DistributionOptions `json:"options"`
|
||||
Callback func(*DistributionResult, error) `json:"-"`
|
||||
}
|
||||
|
||||
// DistributionOptions contains options for context distribution
|
||||
type DistributionOptions struct {
|
||||
ReplicationFactor int `json:"replication_factor"`
|
||||
ConsistencyLevel ConsistencyLevel `json:"consistency_level"`
|
||||
EncryptionLevel crypto.AccessLevel `json:"encryption_level"`
|
||||
TTL *time.Duration `json:"ttl,omitempty"`
|
||||
PreferredZones []string `json:"preferred_zones"`
|
||||
ExcludedNodes []string `json:"excluded_nodes"`
|
||||
ConflictResolution ResolutionType `json:"conflict_resolution"`
|
||||
ReplicationFactor int `json:"replication_factor"`
|
||||
ConsistencyLevel ConsistencyLevel `json:"consistency_level"`
|
||||
EncryptionLevel crypto.AccessLevel `json:"encryption_level"`
|
||||
TTL *time.Duration `json:"ttl,omitempty"`
|
||||
PreferredZones []string `json:"preferred_zones"`
|
||||
ExcludedNodes []string `json:"excluded_nodes"`
|
||||
ConflictResolution ResolutionType `json:"conflict_resolution"`
|
||||
}
|
||||
|
||||
// DistributionResult represents the result of a distribution operation
|
||||
type DistributionResult struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Success bool `json:"success"`
|
||||
DistributedNodes []string `json:"distributed_nodes"`
|
||||
ReplicationFactor int `json:"replication_factor"`
|
||||
ProcessingTime time.Duration `json:"processing_time"`
|
||||
Errors []string `json:"errors"`
|
||||
ConflictResolved *ConflictResolution `json:"conflict_resolved,omitempty"`
|
||||
CompletedAt time.Time `json:"completed_at"`
|
||||
RequestID string `json:"request_id"`
|
||||
Success bool `json:"success"`
|
||||
DistributedNodes []string `json:"distributed_nodes"`
|
||||
ReplicationFactor int `json:"replication_factor"`
|
||||
ProcessingTime time.Duration `json:"processing_time"`
|
||||
Errors []string `json:"errors"`
|
||||
ConflictResolved *ConflictResolution `json:"conflict_resolved,omitempty"`
|
||||
CompletedAt time.Time `json:"completed_at"`
|
||||
}
|
||||
|
||||
// RoleFilter manages role-based filtering for context access
|
||||
type RoleFilter struct {
|
||||
RoleID string `json:"role_id"`
|
||||
AccessLevel crypto.AccessLevel `json:"access_level"`
|
||||
AllowedCompartments []string `json:"allowed_compartments"`
|
||||
FilterRules []*FilterRule `json:"filter_rules"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
RoleID string `json:"role_id"`
|
||||
AccessLevel crypto.AccessLevel `json:"access_level"`
|
||||
AllowedCompartments []string `json:"allowed_compartments"`
|
||||
FilterRules []*FilterRule `json:"filter_rules"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
}
|
||||
|
||||
// FilterRule represents a single filtering rule
|
||||
type FilterRule struct {
|
||||
RuleID string `json:"rule_id"`
|
||||
RuleType FilterRuleType `json:"rule_type"`
|
||||
Pattern string `json:"pattern"`
|
||||
Action FilterAction `json:"action"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
RuleID string `json:"rule_id"`
|
||||
RuleType FilterRuleType `json:"rule_type"`
|
||||
Pattern string `json:"pattern"`
|
||||
Action FilterAction `json:"action"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
|
||||
// FilterRuleType represents different types of filter rules
|
||||
@@ -139,10 +139,10 @@ const (
|
||||
type FilterAction string
|
||||
|
||||
const (
|
||||
FilterActionAllow FilterAction = "allow"
|
||||
FilterActionDeny FilterAction = "deny"
|
||||
FilterActionModify FilterAction = "modify"
|
||||
FilterActionAudit FilterAction = "audit"
|
||||
FilterActionAllow FilterAction = "allow"
|
||||
FilterActionDeny FilterAction = "deny"
|
||||
FilterActionModify FilterAction = "modify"
|
||||
FilterActionAudit FilterAction = "audit"
|
||||
)
|
||||
|
||||
// HealthMonitor monitors the health of a specific component
|
||||
@@ -160,10 +160,10 @@ type HealthMonitor struct {
|
||||
type ComponentType string
|
||||
|
||||
const (
|
||||
ComponentTypeDHT ComponentType = "dht"
|
||||
ComponentTypeReplication ComponentType = "replication"
|
||||
ComponentTypeGossip ComponentType = "gossip"
|
||||
ComponentTypeNetwork ComponentType = "network"
|
||||
ComponentTypeDHT ComponentType = "dht"
|
||||
ComponentTypeReplication ComponentType = "replication"
|
||||
ComponentTypeGossip ComponentType = "gossip"
|
||||
ComponentTypeNetwork ComponentType = "network"
|
||||
ComponentTypeConflictResolver ComponentType = "conflict_resolver"
|
||||
)
|
||||
|
||||
@@ -190,13 +190,13 @@ type CoordinationStatistics struct {
|
||||
|
||||
// PerformanceMetrics tracks detailed performance metrics
|
||||
type PerformanceMetrics struct {
|
||||
ThroughputPerSecond float64 `json:"throughput_per_second"`
|
||||
LatencyPercentiles map[string]float64 `json:"latency_percentiles"`
|
||||
ErrorRateByType map[string]float64 `json:"error_rate_by_type"`
|
||||
ResourceUtilization map[string]float64 `json:"resource_utilization"`
|
||||
NetworkMetrics *NetworkMetrics `json:"network_metrics"`
|
||||
StorageMetrics *StorageMetrics `json:"storage_metrics"`
|
||||
LastCalculated time.Time `json:"last_calculated"`
|
||||
ThroughputPerSecond float64 `json:"throughput_per_second"`
|
||||
LatencyPercentiles map[string]float64 `json:"latency_percentiles"`
|
||||
ErrorRateByType map[string]float64 `json:"error_rate_by_type"`
|
||||
ResourceUtilization map[string]float64 `json:"resource_utilization"`
|
||||
NetworkMetrics *NetworkMetrics `json:"network_metrics"`
|
||||
StorageMetrics *StorageMetrics `json:"storage_metrics"`
|
||||
LastCalculated time.Time `json:"last_calculated"`
|
||||
}
|
||||
|
||||
// NetworkMetrics tracks network-related performance
|
||||
@@ -210,24 +210,24 @@ type NetworkMetrics struct {
|
||||
|
||||
// StorageMetrics tracks storage-related performance
|
||||
type StorageMetrics struct {
|
||||
TotalContexts int64 `json:"total_contexts"`
|
||||
StorageUtilization float64 `json:"storage_utilization"`
|
||||
CompressionRatio float64 `json:"compression_ratio"`
|
||||
TotalContexts int64 `json:"total_contexts"`
|
||||
StorageUtilization float64 `json:"storage_utilization"`
|
||||
CompressionRatio float64 `json:"compression_ratio"`
|
||||
ReplicationEfficiency float64 `json:"replication_efficiency"`
|
||||
CacheHitRate float64 `json:"cache_hit_rate"`
|
||||
CacheHitRate float64 `json:"cache_hit_rate"`
|
||||
}
|
||||
|
||||
// NewDistributionCoordinator creates a new distribution coordinator
|
||||
func NewDistributionCoordinator(
|
||||
config *config.Config,
|
||||
dht *dht.DHT,
|
||||
dhtInstance dht.DHT,
|
||||
roleCrypto *crypto.RoleCrypto,
|
||||
election election.Election,
|
||||
) (*DistributionCoordinator, error) {
|
||||
if config == nil {
|
||||
return nil, fmt.Errorf("config is required")
|
||||
}
|
||||
if dht == nil {
|
||||
if dhtInstance == nil {
|
||||
return nil, fmt.Errorf("DHT instance is required")
|
||||
}
|
||||
if roleCrypto == nil {
|
||||
@@ -238,14 +238,14 @@ func NewDistributionCoordinator(
|
||||
}
|
||||
|
||||
// Create distributor
|
||||
distributor, err := NewDHTContextDistributor(dht, roleCrypto, election, config)
|
||||
distributor, err := NewDHTContextDistributor(dhtInstance, roleCrypto, election, config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create context distributor: %w", err)
|
||||
}
|
||||
|
||||
coord := &DistributionCoordinator{
|
||||
config: config,
|
||||
dht: dht,
|
||||
dht: dhtInstance,
|
||||
roleCrypto: roleCrypto,
|
||||
election: election,
|
||||
distributor: distributor,
|
||||
@@ -264,9 +264,9 @@ func NewDistributionCoordinator(
|
||||
LatencyPercentiles: make(map[string]float64),
|
||||
ErrorRateByType: make(map[string]float64),
|
||||
ResourceUtilization: make(map[string]float64),
|
||||
NetworkMetrics: &NetworkMetrics{},
|
||||
StorageMetrics: &StorageMetrics{},
|
||||
LastCalculated: time.Now(),
|
||||
NetworkMetrics: &NetworkMetrics{},
|
||||
StorageMetrics: &StorageMetrics{},
|
||||
LastCalculated: time.Now(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ func (dc *DistributionCoordinator) CoordinateReplication(
|
||||
CreatedAt: time.Now(),
|
||||
RequestedBy: dc.config.Agent.ID,
|
||||
Payload: map[string]interface{}{
|
||||
"address": address,
|
||||
"address": address,
|
||||
"target_factor": targetFactor,
|
||||
},
|
||||
Context: ctx,
|
||||
@@ -398,14 +398,14 @@ func (dc *DistributionCoordinator) GetClusterHealth() (*ClusterHealth, error) {
|
||||
defer dc.mu.RUnlock()
|
||||
|
||||
health := &ClusterHealth{
|
||||
OverallStatus: dc.calculateOverallHealth(),
|
||||
NodeCount: len(dc.dht.GetConnectedPeers()) + 1, // +1 for current node
|
||||
HealthyNodes: 0,
|
||||
UnhealthyNodes: 0,
|
||||
ComponentHealth: make(map[string]*ComponentHealth),
|
||||
LastUpdated: time.Now(),
|
||||
Alerts: []string{},
|
||||
Recommendations: []string{},
|
||||
OverallStatus: dc.calculateOverallHealth(),
|
||||
NodeCount: len(dc.healthMonitors) + 1, // Placeholder count including current node
|
||||
HealthyNodes: 0,
|
||||
UnhealthyNodes: 0,
|
||||
ComponentHealth: make(map[string]*ComponentHealth),
|
||||
LastUpdated: time.Now(),
|
||||
Alerts: []string{},
|
||||
Recommendations: []string{},
|
||||
}
|
||||
|
||||
// Calculate component health
|
||||
@@ -582,7 +582,7 @@ func (dc *DistributionCoordinator) initializeComponents() error {
|
||||
func (dc *DistributionCoordinator) initializeRoleFilters() {
|
||||
// Initialize role filters based on configuration
|
||||
roles := []string{"senior_architect", "project_manager", "devops_engineer", "backend_developer", "frontend_developer"}
|
||||
|
||||
|
||||
for _, role := range roles {
|
||||
dc.roleFilters[role] = &RoleFilter{
|
||||
RoleID: role,
|
||||
@@ -598,8 +598,8 @@ func (dc *DistributionCoordinator) initializeHealthMonitors() {
|
||||
components := map[string]ComponentType{
|
||||
"dht": ComponentTypeDHT,
|
||||
"replication": ComponentTypeReplication,
|
||||
"gossip": ComponentTypeGossip,
|
||||
"network": ComponentTypeNetwork,
|
||||
"gossip": ComponentTypeGossip,
|
||||
"network": ComponentTypeNetwork,
|
||||
"conflict_resolver": ComponentTypeConflictResolver,
|
||||
}
|
||||
|
||||
@@ -682,8 +682,8 @@ func (dc *DistributionCoordinator) executeDistribution(ctx context.Context, requ
|
||||
Success: false,
|
||||
DistributedNodes: []string{},
|
||||
ProcessingTime: 0,
|
||||
Errors: []string{},
|
||||
CompletedAt: time.Now(),
|
||||
Errors: []string{},
|
||||
CompletedAt: time.Now(),
|
||||
}
|
||||
|
||||
// Execute distribution via distributor
|
||||
@@ -703,14 +703,14 @@ func (dc *DistributionCoordinator) executeDistribution(ctx context.Context, requ
|
||||
|
||||
// ClusterHealth represents overall cluster health
|
||||
type ClusterHealth struct {
|
||||
OverallStatus HealthStatus `json:"overall_status"`
|
||||
NodeCount int `json:"node_count"`
|
||||
HealthyNodes int `json:"healthy_nodes"`
|
||||
UnhealthyNodes int `json:"unhealthy_nodes"`
|
||||
ComponentHealth map[string]*ComponentHealth `json:"component_health"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Alerts []string `json:"alerts"`
|
||||
Recommendations []string `json:"recommendations"`
|
||||
OverallStatus HealthStatus `json:"overall_status"`
|
||||
NodeCount int `json:"node_count"`
|
||||
HealthyNodes int `json:"healthy_nodes"`
|
||||
UnhealthyNodes int `json:"unhealthy_nodes"`
|
||||
ComponentHealth map[string]*ComponentHealth `json:"component_health"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Alerts []string `json:"alerts"`
|
||||
Recommendations []string `json:"recommendations"`
|
||||
}
|
||||
|
||||
// ComponentHealth represents individual component health
|
||||
@@ -736,14 +736,14 @@ func (dc *DistributionCoordinator) getDefaultDistributionOptions() *Distribution
|
||||
return &DistributionOptions{
|
||||
ReplicationFactor: 3,
|
||||
ConsistencyLevel: ConsistencyEventual,
|
||||
EncryptionLevel: crypto.AccessMedium,
|
||||
EncryptionLevel: crypto.AccessLevel(slurpContext.AccessMedium),
|
||||
ConflictResolution: ResolutionMerged,
|
||||
}
|
||||
}
|
||||
|
||||
func (dc *DistributionCoordinator) getAccessLevelForRole(role string) crypto.AccessLevel {
|
||||
// Placeholder implementation
|
||||
return crypto.AccessMedium
|
||||
return crypto.AccessLevel(slurpContext.AccessMedium)
|
||||
}
|
||||
|
||||
func (dc *DistributionCoordinator) getAllowedCompartments(role string) []string {
|
||||
@@ -796,13 +796,13 @@ func (dc *DistributionCoordinator) updatePerformanceMetrics() {
|
||||
|
||||
func (dc *DistributionCoordinator) priorityFromSeverity(severity ConflictSeverity) Priority {
|
||||
switch severity {
|
||||
case SeverityCritical:
|
||||
case ConflictSeverityCritical:
|
||||
return PriorityCritical
|
||||
case SeverityHigh:
|
||||
case ConflictSeverityHigh:
|
||||
return PriorityHigh
|
||||
case SeverityMedium:
|
||||
case ConflictSeverityMedium:
|
||||
return PriorityNormal
|
||||
default:
|
||||
return PriorityLow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user