Documentation ¶
Overview ¶
Package plan provides an API to interact with a cluster's pending plan. It's mainly structured in two primitives: Track and Stream.
To track a pending plan there's there's a few things to consider other than the cluster ID and the cluster's kind (elasticsearch or kibana).
channel, err := plan.Track(plan.TrackParams{ API: params.API, ID: params.ID, Kind: params.Kind, PollFrequency: time.Second, MaxRetries: 4, }) if err != nil { return err } plan.Stream(channel, params.Output)
Index ¶
- Variables
- func Get(params GetParams) ([]*models.ClusterPlanStepInfo, error)
- func GetLogsFromPlanActivityResponse(res interface{}, pending bool) ([]*models.ClusterPlanStepInfo, error)
- func GetStepName(log []*models.ClusterPlanStepInfo) (string, error)
- func StepErrorOrUnknownError(step *models.ClusterPlanStepInfo) error
- func Stream(channel <-chan TrackResponse, device io.Writer) error
- func StreamFunc(channel <-chan TrackResponse, function func(TrackResponse)) error
- func StreamJSON(channel <-chan TrackResponse, device io.Writer, pretty bool) error
- func Track(params TrackParams) (<-chan TrackResponse, error)
- type GetParams
- type MarshableError
- type TrackParams
- type TrackResponse
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPlanFinished is returned when a cluster has no plan PlanStepInfo ErrPlanFinished = errors.New("finished all the plan steps") )
Functions ¶
func Get ¶
func Get(params GetParams) ([]*models.ClusterPlanStepInfo, error)
Get obtains a cluster's plan logs from a set of parameters.
func GetLogsFromPlanActivityResponse ¶
func GetLogsFromPlanActivityResponse(res interface{}, pending bool) ([]*models.ClusterPlanStepInfo, error)
GetLogsFromPlanActivityResponse takes in a response from `ClusterPlanActivity` and returns the plan steps, either from the current or the pending plan.
func GetStepName ¶
func GetStepName(log []*models.ClusterPlanStepInfo) (string, error)
GetStepName goes over the pending plan logs to locate:
1. Errors that have occurred in the plan
2. Steps that are not "success"
3. If the ID for the last step in the log is plan-completed, it will return the ErrPlanFinished
If none of the above are found, it returns the last step ID with the trackpayload.
func StepErrorOrUnknownError ¶
func StepErrorOrUnknownError(step *models.ClusterPlanStepInfo) error
StepErrorOrUnknownError returns the last step message as an error except when the step InfoLog is empty, in which case it returns errorPlanFailedUnknown.
func Stream ¶
func Stream(channel <-chan TrackResponse, device io.Writer) error
Stream prints a text formatted line on each TrackResponse received by the channel, unless the sender closes the channel when it has finished, calling this function will block execution forever.
func StreamFunc ¶
func StreamFunc(channel <-chan TrackResponse, function func(TrackResponse)) error
StreamFunc is the underlying function used by Stream and StreamJSON. If used directly it allows the user to perform an custom action on each received response. Unless the sender closes the channel when it has finished, calling this function will block execution forever. If the plan failed, it returns the error that made the plan fail.
func StreamJSON ¶
func StreamJSON(channel <-chan TrackResponse, device io.Writer, pretty bool) error
StreamJSON prints a json formatted line for on each TrackResponse received by the channel, if pretty is set to true, the message will be intended with 2 spaces. Unless the sender closes the channel when it has finished, calling this function will block execution forever.
func Track ¶
func Track(params TrackParams) (<-chan TrackResponse, error)
Track iterates over a cluster pending plan and returns timely updates about the status of the plan. When all of the updates have been sent, the channel is automatically closed by the poller function.
Types ¶
type GetParams ¶
type GetParams struct { ID string Kind string *api.API // Only used when MaxRetries is set. Cooldown time.Duration Pending bool // If not set, disables retrying the request upon receiving an error. MaxRetries uint8 // contains filtered or unexported fields }
GetParams is used to obtain the plan activity logs of a cluster. If pending is true, the pending plan logs are obtained, otherwise the current plan logs are.
type MarshableError ¶
type MarshableError struct {
Message string `json:"message,omitempty"`
}
MarshableError wraps any incoming error inside this struct so that it can be correctly marshaled to JSON.
func (MarshableError) Error ¶
func (me MarshableError) Error() string
Error complies with the error interface
type TrackParams ¶
type TrackParams struct { *api.API ID string Kind string PollFrequency time.Duration // If set to > 0, allows up to that number of errors coming from the API. MaxRetries uint8 }
TrackParams is used as a configuration struct to track a cluster's pending plan.
func (TrackParams) Validate ¶
func (params TrackParams) Validate() error
Validate verifies that the parameters are usable by its consumer.
type TrackResponse ¶
type TrackResponse struct { ID string `json:"id,omitempty"` Kind string `json:"kind,omitempty"` Step string `json:"step,omitempty"` Finished bool `json:"finished,omitempty"` Duration time.Duration `json:"duration,omitempty"` Err error `json:"err,omitempty"` }
TrackResponse is returned by Track and indicates the progress of a pending plan.