fc94326b0e
P00 — Re-architecture Foundation (deprecation/migration/test-infra/persona/docs). Deprecation sweep (REQ-068, REQ-072, REQ-089): - Add // Deprecated: doc comments to internal/daemon (R-001), internal/transport (REQ-073), internal/security/ca.go+csr.go (D-101/REQ-076), internal/engine/ dispatcher.go+peer.go (CLI-side scheduler), internal/cli/daemon.go. - orca daemon emits slog.Warn deprecation banner on every run (ungated); fires R-001 + v0.10-P05 drain-and-stop + v0.10-P14 deletion. - orca cert and orca node join (mTLS path) emit deprecation warnings; proxmox SSH path (the v0.9 replacement) does not warn. - Add --no-deprecation-warnings global flag on root command (PersistentPreRunE) for orca upgrade migrations. - 12 new daemon/cert/node deprecation tests in internal/cli/daemon_test.go (cli coverage 81.9%, warnDeprecated 100%). - Add DEPRECATED banners to v0.8 sections of ARCHITECTURE.md (verified the v0.9 supersession section + Supersession Table from prior turn are present). Bash tooling gate (grill C-06, C-15, C-16, C-17, C-18): - scripts/tests/test_helper.bash + example_test.bash — bats framework + helpers. - scripts/lib/orca-log.sh — slog-compatible JSON logging to syslog (C-17). - scripts/orca-verify-render.sh — render-contract validator skeleton (C-16). - scripts/tests/orca-log_test.bash + orca-verify-render_test.bash — 20 bats tests total (happy + failure paths per C-15). - .shellcheckrc — project shellcheck config. - Makefile: test-bash + lint-bash targets (graceful skip if tools missing); wired into test + lint targets. - internal/emit/contract.go + contract_test.go — versioned JSON render contract (orca.emit/v1) between Go emitters and bash appliers (C-16). - .ciagent/BASH_CAPABILITY_MAP_v0.9.md — maps shipped internal/transport capabilities to bash-side equivalents or accepted drops (C-18). - D-186 recorded in PROJECT.md: bash exempt from Go coverage gate; compensating control is bats + shellcheck + shfmt (C-06). verify-reqs: 90 requirements consistent. Build/test/lint/fmt all green. 20 bats tests pass. Go tests pass. No v0.8 code deleted — only marked deprecated (deletion deferred to v0.10-P14 per REQ-090 dual-write window). ---ci--- project: orca phase: P00 milestone: v0.9 status: execute ---/ci---
117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
// Package engine — peer.go implements the peer registry for multi-node
|
|
// scheduling (v0.2 P02). A peer is a remote orca node reachable over
|
|
// mTLS. The registry is in-memory plus optionally SQLite-persisted;
|
|
// for P02 the in-memory map is the source of truth and persistence
|
|
// is best-effort.
|
|
package engine
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sort"
|
|
"sync"
|
|
"time"
|
|
|
|
"git.cloudinit.dev/coreci/orca/internal/store"
|
|
)
|
|
|
|
// Peer is a remote orca node reachable over mTLS.
|
|
//
|
|
// Deprecated: v0.9 re-architecture replaces peer dispatch with a CLI-side
|
|
// scheduler + SSH-push (no orca binary on servers per R-001). The Peer
|
|
// type is retained for the dual-write window and scheduled for deletion
|
|
// in v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006.
|
|
type Peer struct {
|
|
NodeID string
|
|
Address string // host:port (the peer's daemon listener)
|
|
ServerName string // expected SAN on the peer's cert
|
|
CAPath string // path to the CA cert this peer validates against
|
|
LastSeen time.Time
|
|
Capacity *store.NodeCapacity
|
|
}
|
|
|
|
// PeerRegistry tracks known peers. Methods are safe for concurrent
|
|
// use; the underlying map is guarded by a sync.RWMutex.
|
|
//
|
|
// Deprecated: v0.9 re-architecture replaces peer dispatch with a CLI-side
|
|
// scheduler + SSH-push (no orca binary on servers per R-001). The
|
|
// PeerRegistry is retained for the dual-write window and scheduled for
|
|
// deletion in v0.10-P14. See .ciagent/PRD_v0.9.md R-001/R-006.
|
|
type PeerRegistry struct {
|
|
mu sync.RWMutex
|
|
peers map[string]*Peer
|
|
// optional persistence (not required for P02; can be added later)
|
|
persist PeerPersister
|
|
}
|
|
|
|
// PeerPersister is an optional callback for persisting peer records.
|
|
// P02 doesn't use it; it's here for the P03 audit log integration.
|
|
type PeerPersister interface {
|
|
SavePeer(ctx context.Context, p *Peer) error
|
|
}
|
|
|
|
// NewPeerRegistry returns an empty registry.
|
|
func NewPeerRegistry() *PeerRegistry {
|
|
return &PeerRegistry{peers: make(map[string]*Peer)}
|
|
}
|
|
|
|
// Add inserts or updates a peer record.
|
|
func (r *PeerRegistry) Add(p *Peer) error {
|
|
if p == nil {
|
|
return fmt.Errorf("PeerRegistry.Add: nil peer")
|
|
}
|
|
if p.NodeID == "" {
|
|
return fmt.Errorf("PeerRegistry.Add: NodeID is required")
|
|
}
|
|
r.mu.Lock()
|
|
r.peers[p.NodeID] = p
|
|
r.mu.Unlock()
|
|
return nil
|
|
}
|
|
|
|
// Remove deletes a peer by ID. Returns true if a peer was removed.
|
|
func (r *PeerRegistry) Remove(nodeID string) bool {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
_, ok := r.peers[nodeID]
|
|
if ok {
|
|
delete(r.peers, nodeID)
|
|
}
|
|
return ok
|
|
}
|
|
|
|
// Get returns the peer with the given ID, or nil.
|
|
func (r *PeerRegistry) Get(nodeID string) *Peer {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
return r.peers[nodeID]
|
|
}
|
|
|
|
// All returns a snapshot of all peers, sorted by NodeID for determinism.
|
|
func (r *PeerRegistry) All(_ context.Context) ([]*Peer, error) {
|
|
r.mu.RLock()
|
|
out := make([]*Peer, 0, len(r.peers))
|
|
for _, p := range r.peers {
|
|
out = append(out, p)
|
|
}
|
|
r.mu.RUnlock()
|
|
sort.Slice(out, func(i, j int) bool { return out[i].NodeID < out[j].NodeID })
|
|
return out, nil
|
|
}
|
|
|
|
// Len returns the number of registered peers.
|
|
func (r *PeerRegistry) Len() int {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
return len(r.peers)
|
|
}
|
|
|
|
// UpdateLastSeen bumps the LastSeen timestamp on a peer.
|
|
func (r *PeerRegistry) UpdateLastSeen(nodeID string) {
|
|
r.mu.Lock()
|
|
if p, ok := r.peers[nodeID]; ok {
|
|
p.LastSeen = time.Now().UTC()
|
|
}
|
|
r.mu.Unlock()
|
|
}
|