Add remote cloud node support with OAuth2, leader election, and automatic configuration synchronization - #1
Conversation
- Added PeerType enum (LanDiscovered, StaticRemote, CloudRemote) - Added NodeRole enum (Member, CloudGateway) - Added RemotePeerConfiguration class - Extended PeerNode with Type, Role, and IsPersistent properties - Extended IPeerStore interface with remote peer management methods - Implemented remote peer persistence in SqlitePeerStore (RemotePeers table) - Updated test mocks to support new interface methods - All existing tests pass, maintaining backward compatibility Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
- Created ILeaderElectionService interface with LeadershipChangedEventArgs - Implemented BullyLeaderElectionService using Bully algorithm - Leader is node with lexicographically smallest NodeId among LAN peers - Elections run every 5 seconds, automatic re-election on failure - Created CompositeDiscoveryService combining UDP + database remote peers - Remote peers refreshed every 5 minutes from database - Added comprehensive unit tests for leader election (8 tests passing) - All existing tests continue to pass Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
- Created IOAuth2Validator interface and OAuth2ValidationResult - Implemented JwtOAuth2Validator with JWT parsing and validation - Created ITokenProvider interface for token management - Implemented OAuth2ClientCredentialsTokenProvider with token caching - Added OAuth2Configuration for OAuth2 settings - Token provider automatically refreshes tokens before expiration - All 50 tests passing (Core: 27, Network: 8, SQLite: 15) Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
- Created IPeerManagementService interface for peer management - Implemented PeerManagementService with CRUD operations - Added AddCloudPeerAsync() for OAuth2-authenticated peers - Added AddStaticPeerAsync() for simple remote peers - Added Enable/Disable peer functionality - Added GetAllRemotePeersAsync() for listing peers - Moved OAuth2Configuration to Core layer (resolves circular dependency) - All 50 tests passing Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
- Complete overview of remote cloud node support - Detailed architecture diagrams - Usage examples and code samples - Database schema documentation - Security considerations - Future work roadmap - Testing and acceptance criteria status
|
@copilot ho rivisto la PR ma non mi è chiaro se la lista di nodi remoti è condivisa tra i nodi del cluster, altrimenti l'elezione potrebbe essere inefficace (viene eletto un nodo che non conosce il cloud) |
- Created docs/remote-peer-configuration.md with deployment patterns - Added warning about manual configuration consistency requirement - Documented that remote peers are NOT automatically synchronized - Added recommendations for ensuring all nodes have same config - Updated CompositeDiscoveryService and PeerManagementService docs - Added section to IMPLEMENTATION_SUMMARY.md explaining limitation Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Hai ragione - attualmente le configurazioni dei peer remoti NON sono sincronizzate automaticamente tra i nodi del cluster. Ogni nodo mantiene il proprio database SQLite locale. Problema: Se Node-1 aggiunge un peer cloud ma Node-2 viene eletto leader, Node-2 non avrà la configurazione e non si connetterà al cloud. Soluzione attuale: Tutti i nodi del cluster devono essere configurati manualmente con la stessa lista di peer remoti (tramite file di configurazione condiviso o automation). Ho aggiunto documentazione completa in
Ho anche aggiunto note nei commenti XML di Commit: bae84e2 |
|
@copilot bisogna fare in modo che la lista dei peer remoti si sincronizzi. una maniera più semplice possibile da implementare in questa PR è quella di trattare la lista di nodi remoti come Collection di IPeerDatabase |
- Remote peer configurations now stored in synchronized collection (_system_remote_peers) - Added [PrimaryKey] attribute to RemotePeerConfiguration.NodeId - Updated PeerManagementService to use IPeerDatabase instead of IPeerStore - Updated CompositeDiscoveryService to use IPeerDatabase instead of IPeerStore - Remote peers automatically sync across all cluster nodes via normal EntglDB sync - Updated documentation to reflect automatic synchronization - Removed manual configuration consistency warnings - All 50 tests passing Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Fatto! Ho implementato la sincronizzazione automatica usando Modifiche:
Risultato: Aggiungi un peer remoto su qualsiasi nodo → si sincronizza automaticamente a tutti gli altri nodi. Zero configurazione manuale richiesta, leader election sempre efficace. Commit: 4e7d064 |
|
@copilot ok la PR è stata mergiata. apriamo una nuova PR per le fasi 6-7-8 che abbiamo lasciato per futuri sviluppi. |
Description
Implements infrastructure for connecting LAN clusters to remote cloud nodes using OAuth2 authentication. Uses Bully algorithm to elect a single gateway node, reducing cloud connections from N to 1.
✨ Automatic Configuration Synchronization: Remote peer configurations are stored in a synchronized collection (
_system_remote_peers) that automatically replicates across all nodes in the cluster. Add a remote peer on any node, and it syncs to all other nodes automatically through EntglDB's built-in sync infrastructure.Type of change
Architecture
Changes
Core Infrastructure
LanDiscovered,StaticRemote,CloudRemoteMemberfromCloudGatewaynodes[PrimaryKey]attributeType,Role,IsPersistentpropertiesSaveRemotePeerAsync,GetRemotePeersAsync,RemoveRemotePeerAsyncRemotePeerstable with full CRUD operationsLeader Election (Bully Algorithm)
NodeIdOAuth2 Security
Discovery & Management
IPeerDatabase_system_remote_peerssynchronized collectionDocumentation
CompositeDiscoveryServiceandPeerManagementServiceUsage Example
Synchronized Collection Schema
Remote peers are stored in collection
_system_remote_peers:{ "NodeId": "cloud-node-1", "Address": "remote.entgldb.com:9000", "Type": 2, "OAuth2Json": "{...}", "IsEnabled": true }How Has This Been Tested?
Checklist:
Notes
Original prompt
🎯 Obiettivo
Introdurre il supporto per nodi remoti cloud in EntglDB.Net, mantenendo piena compatibilità con l'architettura P2P LAN esistente.
📋 Requisiti
1. Nodi Remoti in Ambiente ASP.NET
2. Autenticazione OAuth2
3. Compatibilità API Esistenti
IPeerStorerimane interfaccia centralePeerDatabaseeCollection<T>invariate4. Persistenza Peer Remoti
IPeerStoreesistente per salvare configurazione peer cloudRemotePeersin SQLite5. Leader Election (Cloud Gateway)
🏗️ Architettura Proposta
Componenti Principali
📦 Modifiche da Implementare
1. Core Layer
File da Creare:
src/EntglDb.Core/Network/PeerType.cssrc/EntglDb.Core/Network/NodeRole.cssrc/EntglDb.Core/Network/RemotePeerConfiguration.csFile da Modificare:
src/EntglDb.Core/Network/PeerNode.csPeerType TypeNodeRole Rolebool IsPersistentsrc/EntglDb.Core/Storage/IPeerStore.csTask SaveRemotePeerAsync(RemotePeerConfiguration peer, CancellationToken ct = default)Task<IEnumerable<RemotePeerConfiguration>> GetRemotePeersAsync(CancellationToken ct = default)Task RemoveRemotePeerAsync(string nodeId, CancellationToken ct = default)2. Persistence Layer (SQLite)
File da Modificare:
src/EntglDb.Persistence.Sqlite/SqlitePeerStore.csRemotePeersnellaInitialize()SaveRemotePeerAsync()GetRemotePeersAsync()RemoveRemotePeerAsync()Schema tabella:
3. Network Layer
File da Creare:
src/EntglDb.Network/CompositeDiscoveryService.csUdpDiscoveryService(LAN) + remote peers dal databaseIPeerStore.GetRemotePeersAsync()GetActivePeers()src/EntglDb.Network/Leadership/ILeaderElectionService.cs