Skip to content
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

Renamed loop to routegroup for hypervisor endpoints, function names, struct types and comments. #207

Merged
merged 10 commits into from
Mar 6, 2020
20 changes: 10 additions & 10 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (hv *Hypervisor) ServeHTTP(w http.ResponseWriter, req *http.Request) {
r.Get("/visors/{pk}/routes/{rid}", hv.getRoute())
r.Put("/visors/{pk}/routes/{rid}", hv.putRoute())
r.Delete("/visors/{pk}/routes/{rid}", hv.deleteRoute())
r.Get("/visors/{pk}/loops", hv.getLoops())
r.Get("/visors/{pk}/routegroups", hv.getRouteGroups())
r.Get("/visors/{pk}/restart", hv.restart())
r.Post("/visors/{pk}/exec", hv.exec())
r.Post("/visors/{pk}/update", hv.update())
Expand Down Expand Up @@ -656,33 +656,33 @@ func (hv *Hypervisor) deleteRoute() http.HandlerFunc {
})
}

type loopResp struct {
type routeGroupResp struct {
routing.RuleConsumeFields
FwdRule routing.RuleForwardFields `json:"resp"`
}

func makeLoopResp(info visor.LoopInfo) loopResp {
func makeRouteGroupResp(info visor.RouteGroupInfo) routeGroupResp {
if len(info.FwdRule) == 0 || len(info.ConsumeRule) == 0 {
return loopResp{}
return routeGroupResp{}
}

return loopResp{
return routeGroupResp{
RuleConsumeFields: *info.ConsumeRule.Summary().ConsumeFields,
FwdRule: *info.FwdRule.Summary().ForwardFields,
}
}

func (hv *Hypervisor) getLoops() http.HandlerFunc {
func (hv *Hypervisor) getRouteGroups() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
loops, err := ctx.RPC.Loops()
routegroups, err := ctx.RPC.RouteGroups()
if err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}

resp := make([]loopResp, len(loops))
for i, l := range loops {
resp[i] = makeLoopResp(l)
resp := make([]routeGroupResp, len(routegroups))
for i, l := range routegroups {
resp[i] = makeRouteGroupResp(l)
}

httputil.WriteJSON(w, r, http.StatusOK, resp)
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (r *router) Close() error {
return nil
}

r.logger.Info("Closing all App connections and Loops")
r.logger.Info("Closing all App connections and RouteGroups")

r.once.Do(func() {
close(r.done)
Expand Down
18 changes: 9 additions & 9 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,21 @@ func (r *RPC) RemoveRoutingRule(key *routing.RouteID, _ *struct{}) (err error) {
}

/*
<<< LOOPS MANAGEMENT >>>
<<< ROUTEGROUPS MANAGEMENT >>>
>>> TODO(evanlinjin): Implement.
*/

// LoopInfo is a human-understandable representation of a loop.
type LoopInfo struct {
// RouteGroupInfo is a human-understandable representation of a RouteGroup.
type RouteGroupInfo struct {
ConsumeRule routing.Rule
FwdRule routing.Rule
}

// Loops retrieves loops via rules of the routing table.
func (r *RPC) Loops(_ *struct{}, out *[]LoopInfo) (err error) {
defer rpcutil.LogCall(r.log, "Loops", nil)(out, &err)
// RouteGroups retrieves routegroups via rules of the routing table.
func (r *RPC) RouteGroups(_ *struct{}, out *[]RouteGroupInfo) (err error) {
defer rpcutil.LogCall(r.log, "RouteGroups", nil)(out, &err)

var loops []LoopInfo
var routegroups []RouteGroupInfo

rules := r.visor.router.Rules()
for _, rule := range rules {
Expand All @@ -453,13 +453,13 @@ func (r *RPC) Loops(_ *struct{}, out *[]LoopInfo) (err error) {
return err
}

loops = append(loops, LoopInfo{
routegroups = append(routegroups, RouteGroupInfo{
ConsumeRule: rule,
FwdRule: rule,
})
}

*out = loops
*out = routegroups
return nil
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/visor/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type RPCClient interface {
SaveRoutingRule(rule routing.Rule) error
RemoveRoutingRule(key routing.RouteID) error

Loops() ([]LoopInfo, error)
RouteGroups() ([]RouteGroupInfo, error)

Restart() error
Exec(command string) ([]byte, error)
Expand Down Expand Up @@ -230,11 +230,11 @@ func (rc *rpcClient) RemoveRoutingRule(key routing.RouteID) error {
return rc.Call("RemoveRoutingRule", &key, &struct{}{})
}

// Loops calls Loops.
func (rc *rpcClient) Loops() ([]LoopInfo, error) {
var loops []LoopInfo
err := rc.Call("Loops", &struct{}{}, &loops)
return loops, err
// RouteGroups calls RouteGroups.
func (rc *rpcClient) RouteGroups() ([]RouteGroupInfo, error) {
var routegroups []RouteGroupInfo
err := rc.Call("RouteGroups", &struct{}{}, &routegroups)
return routegroups, err
}

// Restart calls Restart.
Expand Down Expand Up @@ -580,9 +580,9 @@ func (mc *mockRPCClient) RemoveRoutingRule(key routing.RouteID) error {
return nil
}

// Loops implements RPCClient.
func (mc *mockRPCClient) Loops() ([]LoopInfo, error) {
var loops []LoopInfo
// RouteGroups implements RPCClient.
func (mc *mockRPCClient) RouteGroups() ([]RouteGroupInfo, error) {
var loops []RouteGroupInfo

rules := mc.rt.AllRules()
for _, rule := range rules {
Expand All @@ -595,7 +595,7 @@ func (mc *mockRPCClient) Loops() ([]LoopInfo, error) {
if err != nil {
return nil, err
}
loops = append(loops, LoopInfo{
loops = append(loops, RouteGroupInfo{
ConsumeRule: rule,
FwdRule: fwdRule,
})
Expand Down