Skip to content

Commit

Permalink
VTAdmin(web): Initiate MoveTables workflow create screen (#16707)
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Co-authored-by: Rohit Nayak <[email protected]>
  • Loading branch information
beingnoble03 and rohit-nayak-ps authored Sep 23, 2024
1 parent 9563fcb commit 32edb28
Show file tree
Hide file tree
Showing 25 changed files with 2,563 additions and 1,105 deletions.
2,261 changes: 1,173 additions & 1,088 deletions go/vt/proto/vtadmin/vtadmin.pb.go

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions go/vt/proto/vtadmin/vtadmin_grpc.pb.go

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

205 changes: 205 additions & 0 deletions go/vt/proto/vtadmin/vtadmin_vtproto.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 @@ -424,6 +424,7 @@ func (api *API) Handler() http.Handler {
router.HandleFunc("/workflow/{cluster_id}/{keyspace}/{name}/status", httpAPI.Adapt(vtadminhttp.GetWorkflowStatus)).Name("API.GetWorkflowStatus")
router.HandleFunc("/workflow/{cluster_id}/{keyspace}/{name}/start", httpAPI.Adapt(vtadminhttp.StartWorkflow)).Name("API.StartWorkflow")
router.HandleFunc("/workflow/{cluster_id}/{keyspace}/{name}/stop", httpAPI.Adapt(vtadminhttp.StopWorkflow)).Name("API.StopWorkflow")
router.HandleFunc("/workflow/{cluster_id}/movetables", httpAPI.Adapt(vtadminhttp.MoveTablesCreate)).Name("API.MoveTablesCreate").Methods("POST")

experimentalRouter := router.PathPrefix("/experimental").Subrouter()
experimentalRouter.HandleFunc("/tablet/{tablet}/debug/vars", httpAPI.Adapt(experimental.TabletDebugVarsPassthrough)).Name("API.TabletDebugVarsPassthrough")
Expand Down Expand Up @@ -1845,6 +1846,25 @@ func (api *API) LaunchSchemaMigration(ctx context.Context, req *vtadminpb.Launch
return c.LaunchSchemaMigration(ctx, req.Request)
}

// MoveTablesCreate is part of the vtadminpb.VTAdminServer interface.
func (api *API) MoveTablesCreate(ctx context.Context, req *vtadminpb.MoveTablesCreateRequest) (*vtctldatapb.WorkflowStatusResponse, error) {
span, ctx := trace.NewSpan(ctx, "API.MoveTablesCreate")
defer span.Finish()

span.Annotate("cluster_id", req.ClusterId)

if !api.authz.IsAuthorized(ctx, req.ClusterId, rbac.WorkflowResource, rbac.CreateAction) {
return nil, fmt.Errorf("%w: cannot create workflow in %s", errors.ErrUnauthorized, req.ClusterId)
}

c, err := api.getClusterForRequest(req.ClusterId)
if err != nil {
return nil, err
}

return c.Vtctld.MoveTablesCreate(ctx, req.Request)
}

// PingTablet is part of the vtadminpb.VTAdminServer interface.
func (api *API) PingTablet(ctx context.Context, req *vtadminpb.PingTabletRequest) (*vtadminpb.PingTabletResponse, error) {
span, ctx := trace.NewSpan(ctx, "API.PingTablet")
Expand Down
28 changes: 28 additions & 0 deletions go/vt/vtadmin/http/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ package http

import (
"context"
"encoding/json"

"vitess.io/vitess/go/vt/vtadmin/errors"

vtadminpb "vitess.io/vitess/go/vt/proto/vtadmin"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

// GetWorkflow implements the http wrapper for the VTAdminServer.GetWorkflow
Expand Down Expand Up @@ -117,3 +121,27 @@ func StopWorkflow(ctx context.Context, r Request, api *API) *JSONResponse {

return NewJSONResponse(res, err)
}

// MoveTablesCreate implements the http wrapper for the VTAdminServer.MoveTablesCreate
// method.
//
// Its route is /workflow/{cluster_id}/movetables
func MoveTablesCreate(ctx context.Context, r Request, api *API) *JSONResponse {
vars := r.Vars()
decoder := json.NewDecoder(r.Body)
defer r.Body.Close()

var req vtctldatapb.MoveTablesCreateRequest
if err := decoder.Decode(&req); err != nil {
return NewJSONResponse(nil, &errors.BadRequest{
Err: err,
})
}

res, err := api.server.MoveTablesCreate(ctx, &vtadminpb.MoveTablesCreateRequest{
ClusterId: vars["cluster_id"],
Request: &req,
})

return NewJSONResponse(res, err)
}
Loading

0 comments on commit 32edb28

Please sign in to comment.