Documentation
¶
Overview ¶
Package hooks implements pre- and post snapshot hooks.
Plan is a generic executor for ExpectStepReports before and after an activity specified in a callback. It provides a reporting facility that can be polled while the plan is executing to gather progress information.
This package also provides all supported hook type implementations and abstractions around them.
Use For Other Kinds Of ExpectStepReports ¶
This package REQUIRES REFACTORING before it can be used for other activities than snapshots, e.g. pre- and post-replication:
The Hook interface requires a hook to provide a Filesystems() filter, which doesn't make sense for all kinds of activities.
The hook implementations should move out of this package. However, there is a lot of tight coupling which to untangle isn't worth it ATM.
How This Package Is Used By Package Snapper ¶
Deserialize a config.List using ListFromConfig(). Then it MUST filter the list to only contain hooks for a particular filesystem using hooksList.CopyFilteredForFilesystem(fs).
Then create a CallbackHook using NewCallbackHookForFilesystem().
Pass all of the above to NewPlan() which provides a Report() and Run() method:
Plan.Run(ctx context.Context,dryRun bool) executes the plan and take a context as argument that should contain a logger added using hooks.WithLogger()). The value of dryRun is passed through to the hooks' Run() method. Command hooks make it available in the environment variable ZREPL_DRYRUN.
Plan.Report() can be called while Plan.Run() is executing to give an overview of plan execution progress (future use in "zrepl status").
Index ¶
- Constants
- type CallbackHook
- type CallbackHookReport
- type Cmd
- type CommandHook
- func (self *CommandHook) ErrIsFatal() bool
- func (self *CommandHook) Filesystems() zfs.DatasetFilter
- func (self *CommandHook) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, ...) HookReport
- func (self *CommandHook) String() string
- func (self *CommandHook) WithCombinedOutput() *CommandHook
- type CommandHookReport
- type Edge
- type Hook
- type HookJobCallback
- type HookReport
- type List
- type Phase
- type Plan
- type PlanReport
- type Step
- type StepStatus
Constants ¶
const ( PhaseSnapshot = Phase("snapshot") PhaseTesting = Phase("testing") )
const ( Pre = Edge(1 << iota) Callback Post )
const ( EnvType = "ZREPL_HOOKTYPE" EnvDryRun = "ZREPL_DRYRUN" EnvFS = "ZREPL_FS" EnvSnapshot = "ZREPL_SNAPNAME" EnvTimeout = "ZREPL_TIMEOUT" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackHook ¶
type CallbackHook struct {
// contains filtered or unexported fields
}
func NewCallbackHook ¶
func NewCallbackHook(displayString string, cb HookJobCallback, filter zfs.DatasetFilter, ) *CallbackHook
func NewCallbackHookForFilesystem ¶
func NewCallbackHookForFilesystem(displayString string, fs *zfs.DatasetPath, cb HookJobCallback, ) *CallbackHook
func (*CallbackHook) ErrIsFatal ¶
func (h *CallbackHook) ErrIsFatal() bool
func (*CallbackHook) Filesystems ¶
func (h *CallbackHook) Filesystems() zfs.DatasetFilter
func (*CallbackHook) Run ¶
func (h *CallbackHook) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra map[string]string, ) HookReport
func (*CallbackHook) String ¶
func (h *CallbackHook) String() string
type CallbackHookReport ¶
func (*CallbackHookReport) Error ¶
func (r *CallbackHookReport) Error() string
func (*CallbackHookReport) HadError ¶
func (r *CallbackHookReport) HadError() bool
func (*CallbackHookReport) String ¶
func (r *CallbackHookReport) String() string
type Cmd ¶ added in v0.8.10
type Cmd struct {
// contains filtered or unexported fields
}
func NewCommand ¶ added in v0.8.10
func (*Cmd) CombinedOutput ¶ added in v0.8.10
type CommandHook ¶
type CommandHook struct {
// contains filtered or unexported fields
}
func NewCommandHook ¶
func NewCommandHook(in *config.HookCommand) (*CommandHook, error)
func (*CommandHook) ErrIsFatal ¶
func (self *CommandHook) ErrIsFatal() bool
func (*CommandHook) Filesystems ¶
func (self *CommandHook) Filesystems() zfs.DatasetFilter
func (*CommandHook) Run ¶
func (self *CommandHook) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra map[string]string, ) HookReport
func (*CommandHook) String ¶
func (self *CommandHook) String() string
func (*CommandHook) WithCombinedOutput ¶ added in v0.8.10
func (self *CommandHook) WithCombinedOutput() *CommandHook
type CommandHookReport ¶
type CommandHookReport struct { Command string Args []string // currently always empty Env map[string]string Err error CombinedOutput []byte }
func (*CommandHookReport) Error ¶
func (r *CommandHookReport) Error() string
func (*CommandHookReport) HadError ¶
func (r *CommandHookReport) HadError() bool
func (*CommandHookReport) String ¶
func (r *CommandHookReport) String() string
type Hook ¶
type Hook interface { String() string // If true and the Pre edge invocation of Run fails, Post edge will not run // and other Pre edges will not run. ErrIsFatal() bool // Run is invoked by HookPlan for a Pre edge. If HookReport.HadError() == // false, the Post edge will be invoked, too. Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra map[string]string, ) HookReport }
type HookJobCallback ¶
type HookReport ¶
type List ¶
type List []*CommandHook
func ListFromConfig ¶
func ListFromConfig(in []config.HookCommand) (List, error)
func (List) CopyFilteredForFilesystem ¶
func (self List) CopyFilteredForFilesystem(fs *zfs.DatasetPath) (List, error)
func (List) WithCombinedOutput ¶ added in v0.8.10
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
func (*Plan) Report ¶
func (p *Plan) Report() PlanReport
type PlanReport ¶
type PlanReport []Step
func (PlanReport) HadError ¶
func (r PlanReport) HadError() bool
func (PlanReport) HadFatalError ¶
func (r PlanReport) HadFatalError() bool
func (PlanReport) String ¶
func (r PlanReport) String() string
type Step ¶
type Step struct { Hook Hook Edge Edge Status StepStatus Begin, End time.Time // Report may be nil // // FIXME cannot serialize this for client status, but contains interesting // info (like what error happened) Report HookReport }
type StepStatus ¶
type StepStatus int
const ( StepPending StepStatus = 1 << iota StepExec StepOk StepErr StepSkippedDueToFatalErr StepSkippedDueToPreErr )
func StepStatusString ¶
func StepStatusString(s string) (StepStatus, error)
StepStatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func StepStatusValues ¶
func StepStatusValues() []StepStatus
StepStatusValues returns all values of the enum
func (StepStatus) IsAStepStatus ¶
func (i StepStatus) IsAStepStatus() bool
IsAStepStatus returns "true" if the value is listed in the enum definition. "false" otherwise
func (StepStatus) String ¶
func (i StepStatus) String() string