compute/cmd/mgr/node/node.go
2025-03-01 18:41:36 +01:00

48 lines
924 B
Go

package node
import (
"encoding/json"
"fmt"
"io"
"log"
"deevirt.fr/compute/pkg/api/proto"
"deevirt.fr/compute/pkg/config"
"deevirt.fr/compute/pkg/raft"
"deevirt.fr/compute/pkg/schema"
)
type Node struct {
Config *config.Config
Store *raft.Store
proto.UnimplementedNodeServer
}
func (n *Node) Alive(stream proto.Node_AliveServer) error {
println("Alive")
for {
req, err := stream.Recv()
if err == io.EOF || err != nil {
log.Println("Client closed the connection")
return nil
}
log.Printf("Received heartbeat: %v", req)
cluster := schema.NodeStore{}
println("on reçit une demande")
res, _ := n.Store.Get("/etc/libvirt/cluster")
json.Unmarshal(res, &cluster)
fmt.Printf("%v\n", res)
cluster[n.Config.NodeID].LastUpdate = req.Timestamp
d, _ := json.Marshal(cluster)
n.Store.Set("/etc/libvirt/cluster", d)
stream.Send(&proto.NodeAliveQemuResponse{
Nodes: res,
})
}
}