network/pkg/rqlite/discovery_manager.go
anonpenguin23 b3b1905fb2 feat: refactor API gateway and CLI utilities for improved functionality
- Updated the API gateway documentation to reflect changes in architecture and functionality, emphasizing its role as a multi-functional entry point for decentralized services.
- Refactored CLI commands to utilize utility functions for better code organization and maintainability.
- Introduced new utility functions for handling peer normalization, service management, and port validation, enhancing the overall CLI experience.
- Added a new production installation script to streamline the setup process for users, including detailed dry-run summaries for better visibility.
- Enhanced validation mechanisms for configuration files and swarm keys, ensuring robust error handling and user feedback during setup.
2025-12-31 10:16:26 +02:00

62 lines
1.3 KiB
Go

package rqlite
import (
"fmt"
"time"
)
// SetDiscoveryService sets the cluster discovery service
func (r *RQLiteManager) SetDiscoveryService(service *ClusterDiscoveryService) {
r.discoveryService = service
}
// SetNodeType sets the node type
func (r *RQLiteManager) SetNodeType(nodeType string) {
if nodeType != "" {
r.nodeType = nodeType
}
}
// UpdateAdvertisedAddresses overrides advertised addresses
func (r *RQLiteManager) UpdateAdvertisedAddresses(raftAddr, httpAddr string) {
if r == nil || r.discoverConfig == nil {
return
}
if raftAddr != "" && r.discoverConfig.RaftAdvAddress != raftAddr {
r.discoverConfig.RaftAdvAddress = raftAddr
}
if httpAddr != "" && r.discoverConfig.HttpAdvAddress != httpAddr {
r.discoverConfig.HttpAdvAddress = httpAddr
}
}
func (r *RQLiteManager) validateNodeID() error {
for i := 0; i < 5; i++ {
nodes, err := r.getRQLiteNodes()
if err != nil {
if i < 4 {
time.Sleep(500 * time.Millisecond)
continue
}
return nil
}
expectedID := r.discoverConfig.RaftAdvAddress
if expectedID == "" || len(nodes) == 0 {
return nil
}
for _, node := range nodes {
if node.Address == expectedID {
if node.ID != expectedID {
return fmt.Errorf("node ID mismatch: %s != %s", expectedID, node.ID)
}
return nil
}
}
return nil
}
return nil
}