// ExecuteHook executes the provided hook locally, and returns the result. func (agent *ActionAgent) ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult { if err := agent.lock(ctx); err != nil { // client gave up return &hook.HookResult{} } defer agent.unlock() // Execute the hooks topotools.ConfigureTabletHook(hk, agent.TabletAlias) hr := hk.Execute() // We never know what the hook did, so let's refresh our state. if err := agent.refreshTablet(ctx, "ExecuteHook"); err != nil { log.Errorf("refreshTablet after ExecuteHook failed: %v", err) } return hr }
// add TABLET_ALIAS to environment 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() }
// ExecuteHook executes the provided hook locally, and returns the result. // Should be called under RPCWrapLockAction. func (agent *ActionAgent) ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult { topotools.ConfigureTabletHook(hk, agent.TabletAlias) return hk.Execute() }
// ConfigureTabletHook configures the right parameters for a hook // running locally on a tablet. func ConfigureTabletHook(hk *hook.Hook, tabletAlias *topodatapb.TabletAlias) { if hk.ExtraEnv == nil { hk.ExtraEnv = make(map[string]string, 1) } hk.ExtraEnv["TABLET_ALIAS"] = topoproto.TabletAliasString(tabletAlias) }