func (ar *ActionRepository) ApplyTabletAction(actionName string, tabletAlias topo.TabletAlias, r *http.Request) *ActionResult { result := &ActionResult{Name: actionName, Parameters: tabletAlias.String()} action, ok := ar.tabletActions[actionName] if !ok { result.error("Unknown tablet action") return result } // check the role if action.role != "" { if err := acl.CheckAccessHTTP(r, action.role); err != nil { result.error("Access denied") return result } } // run the action wr := wrangler.New(logutil.NewConsoleLogger(), ar.ts, *actionTimeout, *lockTimeout) output, err := action.method(wr, tabletAlias, r) if err != nil { result.error(err.Error()) return result } result.Output = output return result }
// RecordTabletTagAction records a new TabletTagAction // into the specified Cleaner func RecordTabletTagAction(cleaner *Cleaner, tabletAlias topo.TabletAlias, name, value string) { cleaner.Record(TabletTagActionName, tabletAlias.String(), &TabletTagAction{ TabletAlias: tabletAlias, Name: name, Value: value, }) }
// FindChangeSlaveTypeActionByTarget finds the first action for the target func FindChangeSlaveTypeActionByTarget(cleaner *Cleaner, tabletAlias topo.TabletAlias) (*ChangeSlaveTypeAction, error) { action, err := cleaner.GetActionByName(ChangeSlaveTypeActionName, tabletAlias.String()) if err != nil { return nil, err } result, ok := action.(*ChangeSlaveTypeAction) if !ok { return nil, fmt.Errorf("Action with wrong type: %v", action) } return result, nil }
// helper method to asynchronously diff a permissions func (wr *Wrangler) diffPermissions(masterPermissions *myproto.Permissions, masterAlias topo.TabletAlias, alias topo.TabletAlias, wg *sync.WaitGroup, er concurrency.ErrorRecorder) { defer wg.Done() log.Infof("Gathering permissions for %v", alias) slavePermissions, err := wr.GetPermissions(alias) if err != nil { er.RecordError(err) return } log.Infof("Diffing permissions for %v", alias) myproto.DiffPermissions(masterAlias.String(), masterPermissions, alias.String(), slavePermissions, er) }
// helper method to asynchronously diff a schema func (wr *Wrangler) diffSchema(masterSchema *myproto.SchemaDefinition, masterTabletAlias, alias topo.TabletAlias, excludeTables []string, includeViews bool, wg *sync.WaitGroup, er concurrency.ErrorRecorder) { defer wg.Done() log.Infof("Gathering schema for %v", alias) slaveSchema, err := wr.GetSchema(alias, nil, excludeTables, includeViews) if err != nil { er.RecordError(err) return } log.Infof("Diffing schema for %v", alias) myproto.DiffSchema(masterTabletAlias.String(), masterSchema, alias.String(), slaveSchema, er) }
// RecordChangeSlaveTypeAction records a new ChangeSlaveTypeAction // into the specified Cleaner func RecordChangeSlaveTypeAction(cleaner *Cleaner, tabletAlias topo.TabletAlias, tabletType topo.TabletType) { cleaner.Record(ChangeSlaveTypeActionName, tabletAlias.String(), &ChangeSlaveTypeAction{ TabletAlias: tabletAlias, TabletType: tabletType, }) }
// ConfigureTabletHook configures the right parameters for a hook // running locally on a tablet. func ConfigureTabletHook(hk *hook.Hook, tabletAlias topo.TabletAlias) { if hk.ExtraEnv == nil { hk.ExtraEnv = make(map[string]string, 1) } hk.ExtraEnv["TABLET_ALIAS"] = tabletAlias.String() }