Skip to content

Commit

Permalink
min_hops within summary endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexadhy committed Jun 1, 2021
1 parent ecd81eb commit 642fa40
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 72 deletions.
8 changes: 2 additions & 6 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ type API interface {
UpdateStatus() (string, error)
RuntimeLogs() (string, error)

GetMinHops() (uint16, error)
SetMinHops(uint16) error
}

Expand Down Expand Up @@ -140,6 +139,7 @@ type Summary struct {
IsHypervisor bool `json:"is_hypervisor,omitempty"`
DmsgStats *dmsgtracker.DmsgClientSummary `json:"dmsg_stats"`
Online bool `json:"online"`
MinHops uint16 `json:"min_hops"`
}

// Summary implements API.
Expand Down Expand Up @@ -178,6 +178,7 @@ func (v *Visor) Summary() (*Summary, error) {
Health: health,
Uptime: uptime,
Routes: extraRoutes,
MinHops: v.conf.Routing.MinHops,
}

return summary, nil
Expand Down Expand Up @@ -738,11 +739,6 @@ func (v *Visor) RuntimeLogs() (string, error) {
return builder.String(), nil
}

// GetMinHops gets min_hops routing config of visor
func (v *Visor) GetMinHops() (uint16, error) {
return v.conf.Routing.MinHops, nil
}

// SetMinHops sets min_hops routing config of visor
func (v *Visor) SetMinHops(in uint16) error {
return v.conf.UpdateMinHops(in)
Expand Down
19 changes: 0 additions & 19 deletions pkg/visor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func (hv *Hypervisor) makeMux() chi.Router {
r.Get("/visors/{pk}/update/available", hv.visorUpdateAvailable())
r.Get("/visors/{pk}/update/available/{channel}", hv.visorUpdateAvailable())
r.Get("/visors/{pk}/runtime-logs", hv.getRuntimeLogs())
r.Get("/visors/{pk}/min-hops", hv.getMinHops())
r.Post("/visors/{pk}/min-hops", hv.postMinHops())
})
})
Expand Down Expand Up @@ -1298,24 +1297,6 @@ func (hv *Hypervisor) getRuntimeLogs() http.HandlerFunc {
})
}

func (hv *Hypervisor) getMinHops() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
hops, err := ctx.API.GetMinHops()
if err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}

hopsResp := struct {
MinHops uint16 `json:"min_hops"`
}{
MinHops: hops,
}

httputil.WriteJSON(w, r, http.StatusOK, hopsResp)
})
}

func (hv *Hypervisor) postMinHops() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
var reqBody struct {
Expand Down
43 changes: 3 additions & 40 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package visor

import (
"encoding/hex"
"errors"
"fmt"
"net/rpc"
Expand Down Expand Up @@ -147,40 +146,11 @@ func newTransportSummary(tm *transport.Manager, tp *transport.ManagedTransport,

// Summary provides an extra summary of the AppNode.
func (r *RPC) Summary(_ *struct{}, out *Summary) (err error) {
overview, err := r.visor.Overview()
if err != nil {
return fmt.Errorf("summary")
}

health, err := r.visor.Health()
if err != nil {
return fmt.Errorf("health")
}

uptime, err := r.visor.Uptime()
if err != nil {
return fmt.Errorf("uptime")
}
defer rpcutil.LogCall(r.log, "Summary", nil)(out, &err)

routes, err := r.visor.RoutingRules()
out, err = r.visor.Summary()
if err != nil {
return fmt.Errorf("routes")
}

extraRoutes := make([]routingRuleResp, 0, len(routes))
for _, route := range routes {
extraRoutes = append(extraRoutes, routingRuleResp{
Key: route.KeyRouteID(),
Rule: hex.EncodeToString(route),
Summary: route.Summary(),
})
}

*out = Summary{
Overview: overview,
Health: health,
Uptime: uptime,
Routes: extraRoutes,
return err
}

return nil
Expand Down Expand Up @@ -547,13 +517,6 @@ func (r *RPC) RuntimeLogs(_ *struct{}, logs *string) (err error) {
return
}

// GetMinHops gets min_hops from visor's routing config
func (r *RPC) GetMinHops(_ *struct{}, hops *uint16) (err error) {
defer rpcutil.LogCall(r.log, "GetMinHops", nil)
*hops, err = r.visor.GetMinHops()
return
}

// SetMinHops sets min_hops from visor's routing config
func (r *RPC) SetMinHops(n *uint16, _ *struct{}) (err error) {
defer rpcutil.LogCall(r.log, "SetMinHops", *n)
Expand Down
7 changes: 0 additions & 7 deletions pkg/visor/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,6 @@ func (rc *rpcClient) RuntimeLogs() (string, error) {
return logs, err
}

// GetMinHops gets min_hops from visor routing config
func (rc *rpcClient) GetMinHops() (uint16, error) {
var hops uint16
err := rc.Call("GetMinHops", &struct{}{}, &hops)
return hops, err
}

// SetMinHops sets the min_hops from visor routing config
func (rc *rpcClient) SetMinHops(hops uint16) error {
err := rc.Call("SetMinHops", &hops, &struct{}{})
Expand Down

0 comments on commit 642fa40

Please sign in to comment.