Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#7426 from tinyspeck/sarabee-vtadmin-api-c…
Browse files Browse the repository at this point in the history
…lusters

Add /api/clusters endpoint to vtadmin-api
  • Loading branch information
rohit-nayak-ps authored Feb 1, 2021
2 parents 4c9a50b + e3088b4 commit 0ffb8c1
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 44 deletions.
202 changes: 158 additions & 44 deletions go/vt/proto/vtadmin/vtadmin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func NewAPI(clusters []*cluster.Cluster, opts grpcserver.Options, httpOpts vtadm

httpAPI := vtadminhttp.NewAPI(api)

router.HandleFunc("/clusters", httpAPI.Adapt(vtadminhttp.GetClusters)).Name("API.GetClusters")
router.HandleFunc("/gates", httpAPI.Adapt(vtadminhttp.GetGates)).Name("API.GetGates")
router.HandleFunc("/keyspaces", httpAPI.Adapt(vtadminhttp.GetKeyspaces)).Name("API.GetKeyspaces")
router.HandleFunc("/tablets", httpAPI.Adapt(vtadminhttp.GetTablets)).Name("API.GetTablets")
Expand Down Expand Up @@ -113,6 +114,25 @@ func (api *API) ListenAndServe() error {
return api.serv.ListenAndServe()
}

// GetClusters is part of the vtadminpb.VTAdminServer interface.
func (api *API) GetClusters(ctx context.Context, req *vtadminpb.GetClustersRequest) (*vtadminpb.GetClustersResponse, error) {
span, _ := trace.NewSpan(ctx, "API.GetClusters")
defer span.Finish()

vcs := make([]*vtadminpb.Cluster, 0, len(api.clusters))

for _, c := range api.clusters {
vcs = append(vcs, &vtadminpb.Cluster{
Id: c.ID,
Name: c.Name,
})
}

return &vtadminpb.GetClustersResponse{
Clusters: vcs,
}, nil
}

// GetGates is part of the vtadminpb.VTAdminServer interface.
func (api *API) GetGates(ctx context.Context, req *vtadminpb.GetGatesRequest) (*vtadminpb.GetGatesResponse, error) {
span, ctx := trace.NewSpan(ctx, "API.GetGates")
Expand Down
Loading

0 comments on commit 0ffb8c1

Please sign in to comment.