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

VTAdmin(API): Add MoveTablesCreate endpoint #16690

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,247 changes: 1,166 additions & 1,081 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.

206 changes: 206 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}/move_tables", 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 @@ -1830,6 +1831,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}/move_tables
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
Loading