Skip to content

Commit

Permalink
VTAdmin(API): Support for MoveTables complete
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Sep 21, 2024
1 parent 490bb0c commit 71db432
Show file tree
Hide file tree
Showing 10 changed files with 1,887 additions and 1,109 deletions.
2,288 changes: 1,187 additions & 1,101 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 @@ -384,6 +384,7 @@ func (api *API) Handler() http.Handler {
router.HandleFunc("/migration/{cluster_id}/{keyspace}/launch", httpAPI.Adapt(vtadminhttp.LaunchSchemaMigration)).Name("API.LaunchSchemaMigration").Methods("PUT", "OPTIONS")
router.HandleFunc("/migration/{cluster_id}/{keyspace}/retry", httpAPI.Adapt(vtadminhttp.RetrySchemaMigration)).Name("API.RetrySchemaMigration").Methods("PUT", "OPTIONS")
router.HandleFunc("/migrations/", httpAPI.Adapt(vtadminhttp.GetSchemaMigrations)).Name("API.GetSchemaMigrations")
router.HandleFunc("/movetables/{cluster_id}/complete", httpAPI.Adapt(vtadminhttp.MoveTablesComplete)).Name("API.MoveTablesComplete")
router.HandleFunc("/schema/{table}", httpAPI.Adapt(vtadminhttp.FindSchema)).Name("API.FindSchema")
router.HandleFunc("/schema/{cluster_id}/{keyspace}/{table}", httpAPI.Adapt(vtadminhttp.GetSchema)).Name("API.GetSchema")
router.HandleFunc("/schemas", httpAPI.Adapt(vtadminhttp.GetSchemas)).Name("API.GetSchemas")
Expand Down Expand Up @@ -1845,6 +1846,25 @@ func (api *API) LaunchSchemaMigration(ctx context.Context, req *vtadminpb.Launch
return c.LaunchSchemaMigration(ctx, req.Request)
}

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

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

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

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

return c.Vtctld.MoveTablesComplete(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)
}

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

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

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

return NewJSONResponse(res, err)
}
1 change: 1 addition & 0 deletions go/vt/vtadmin/rbac/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func DefaultConfig() *Config {
string(CreateAction),
string(DeleteAction),
string(PutAction),
string(CompleteAction),
string(PingAction),
string(ReloadAction),
string(EmergencyFailoverShardAction),
Expand Down
Loading

0 comments on commit 71db432

Please sign in to comment.