Skip to content

Development node last seen #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 1, 2025
42 changes: 34 additions & 8 deletions node-registrar/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type nodeCfg struct {
twinID uint64
status string
healthy bool
online *bool
lastSeen *int64
Location Location
Resources Resources
Interfaces []Interface
Expand Down Expand Up @@ -100,6 +102,18 @@ func ListNodesWithHealthy() ListNodeOpts {
}
}

func ListNodesWithOnline(online bool) ListNodeOpts {
return func(n *nodeCfg) {
n.online = &online
}
}

func ListNodesWithLastSeen(minutes int64) ListNodeOpts {
return func(n *nodeCfg) {
n.lastSeen = &minutes
}
}

func ListNodesWithTwinID(id uint64) ListNodeOpts {
return func(n *nodeCfg) {
n.twinID = id
Expand Down Expand Up @@ -240,7 +254,9 @@ func (c *RegistrarClient) registerNode(
}{}

err = json.NewDecoder(resp.Body).Decode(&result)

if err != nil {
return 0, errors.Wrap(err, "failed to decode response body")
}
c.nodeID = result.NodeID
return result.NodeID, err
}
Expand Down Expand Up @@ -483,13 +499,15 @@ func (c *RegistrarClient) parseUpdateNodeOpts(node Node, opts []UpdateNodeOpts)

func parseListNodeOpts(opts []ListNodeOpts) map[string]any {
cfg := nodeCfg{
nodeID: 0,
twinID: 0,
farmID: 0,
status: "",
healthy: false,
size: 50,
page: 1,
nodeID: 0,
twinID: 0,
farmID: 0,
status: "",
healthy: false,
online: nil,
lastSeen: nil,
size: 50,
page: 1,
}

for _, opt := range opts {
Expand Down Expand Up @@ -518,6 +536,14 @@ func parseListNodeOpts(opts []ListNodeOpts) map[string]any {
data["healthy"] = cfg.healthy
}

if cfg.online != nil {
data["online"] = *cfg.online
}

if cfg.lastSeen != nil {
data["last_seen"] = *cfg.lastSeen
}

data["size"] = cfg.size
data["page"] = cfg.page

Expand Down
4 changes: 2 additions & 2 deletions node-registrar/client/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func TestUpdateNode(t *testing.T) {
request = updateNodeSendUptimeReport

report := UptimeReport{
Uptime: 40 * time.Minute,
Timestamp: time.Now(),
Uptime: 40 * 60,
Timestamp: time.Now().Unix(),
}
err = c.ReportUptime(report)
require.NoError(err)
Expand Down
6 changes: 4 additions & 2 deletions node-registrar/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ type Node struct {
Virtualized bool `json:"virtualized"`
SerialNumber string `json:"serial_number"`
UptimeReports []UptimeReport `json:"uptime"`
LastSeen *time.Time `json:"last_seen"`
Online bool `json:"online"`
Approved bool
}

type UptimeReport struct {
Uptime time.Duration `json:"uptime"`
Timestamp time.Time `json:"timestamp"`
Uptime uint64 `json:"uptime"` // in seconds
Timestamp int64 `json:"timestamp"` // in seconds since epoch
}

type ZosVersion struct {
Expand Down
Loading
Loading