converge: github.com/asteris-llc/converge/resource Index | Files | Directories

package resource

import "github.com/asteris-llc/converge/resource"

Index

Package Files

field_extractor.go health_status.go preparer.go resource.go status.go thunktask.go

Variables

var (
    // ErrNilStruct is returned if there is an attempt to introspect a nil value
    ErrNilStruct = errors.New("cannot inspect types with a nil value")

    // ErrNonStructIntrospection is returned when attempting to introspect fields
    // on a non-struct type.
    ErrNonStructIntrospection = errors.New("cannot extract fields for types other than struct")

    // ErrFieldIndexOutOfBounds is returned when a field index is beyond the
    // number of fields in the struct type
    ErrFieldIndexOutOfBounds = errors.New("struct field index is out of bounds")

    // ErrDuplicateFieldName is returned if there is a duplicate reference name in
    // an exported field slice during map construction
    ErrDuplicateFieldName = errors.New("detected duplicate field name")
)
var (
    // ErrStatusCantChange is returned when an error is not set but the level is
    // StatusCantChange
    ErrStatusCantChange = errors.New("resource cannot change because of an error")

    // ErrStatusFatal is returned when an error is not set but the level is
    // StatusFatal
    ErrStatusFatal = errors.New("resource encountered an error")
)

error messages

func AddTextDiff Uses

func AddTextDiff(m map[string]Diff, name, original, current, defaultVal string) map[string]Diff

AddTextDiff inserts a new TextDiff into a map of names to Diffs

func AnyChanges Uses

func AnyChanges(diffs map[string]Diff) bool

AnyChanges takes a diff map and returns true if any of the diffs in the map have changes.

func ExportedFields Uses

func ExportedFields(input interface{}) (exported []*ExportedField, err error)

ExportedFields returns a slice of fields that have been exported from a struct; including embedded fields

type Diff Uses

type Diff interface {
    Original() string
    Current() string
    Changes() bool
}

Diff represents a difference

type ExportedField Uses

type ExportedField struct {
    FieldName     string
    ReferenceName string
    StructField   *reflect.StructField
    Value         reflect.Value
}

ExportedField represents an exported field, including the containing struct, offset, field name, and lookup name

type FieldMap Uses

type FieldMap map[string]interface{}

FieldMap represents a map of field names to interfaces

func GenerateLookupMap Uses

func GenerateLookupMap(fields []*ExportedField) (FieldMap, error)

GenerateLookupMap takes an exported field list and generates a map of lookup names to values

func LookupMapFromInterface Uses

func LookupMapFromInterface(input interface{}) (FieldMap, error)

LookupMapFromInterface gets the concrete implementation of an interface and then gets the struct fields from it

func LookupMapFromStruct Uses

func LookupMapFromStruct(input interface{}) (FieldMap, error)

LookupMapFromStruct generates a lookup map from a struct

type HealthStatus Uses

type HealthStatus struct {
    TaskStatus
    WarningLevel HealthStatusCode
    DisplayLevel *HealthStatusCode
    FailingDeps  map[string]string
}

HealthStatus contains a status level, display threshold, and status message

func (*HealthStatus) Changes Uses

func (h *HealthStatus) Changes() map[string]Diff

Changes returns changes from the underlying TaskStatus diffs

func (*HealthStatus) Error Uses

func (h *HealthStatus) Error() error

Error returns nil on success. If the health checks or it's dedencies are failing an appropriate error is returned.

func (*HealthStatus) HasChanges Uses

func (h *HealthStatus) HasChanges() bool

HasChanges returns true if the status indicates that there are changes

func (*HealthStatus) HasFailingDeps Uses

func (h *HealthStatus) HasFailingDeps() bool

HasFailingDeps returns true of FailingDeps is not empty

func (*HealthStatus) IsError Uses

func (h *HealthStatus) IsError() bool

IsError returns true if the warning level is StatusError

func (*HealthStatus) IsWarning Uses

func (h *HealthStatus) IsWarning() bool

IsWarning returns true if the warning level is StatusWarning

func (*HealthStatus) Messages Uses

func (h *HealthStatus) Messages() []string

Messages returns health status messages

func (*HealthStatus) ShouldDisplay Uses

func (h *HealthStatus) ShouldDisplay() bool

ShouldDisplay returns true if the warning level is at least the display level

func (*HealthStatus) UpgradeWarning Uses

func (h *HealthStatus) UpgradeWarning(level HealthStatusCode)

UpgradeWarning will increase the warning level to at least `level`, but will not decrease it if it's already higher.

type HealthStatusCode Uses

type HealthStatusCode int

HealthStatusCode is a status indicator for health level. It should be one of:

StatusHealth
StatusWarning
StatusError
const (
    // StatusHealthy indicates a passing health check
    StatusHealthy HealthStatusCode = iota
    // StatusWarning indicates a change is needed
    StatusWarning
    // StatusError indicates that a module is non-functional
    StatusError
)

type Preparer Uses

type Preparer struct {
    Source      map[string]interface{}
    Destination Resource
}

Preparer wraps and implements resource.Resource in order to deserialize into regular Preparers

func NewPreparer Uses

func NewPreparer(r Resource) *Preparer

NewPreparer wraps a given resource in this preparer

func NewPreparerWithSource Uses

func NewPreparerWithSource(r Resource, source map[string]interface{}) *Preparer

NewPreparerWithSource creates a new preparer with the source included

func (*Preparer) Prepare Uses

func (p *Preparer) Prepare(ctx context.Context, r Renderer) (Task, error)

Prepare the destination to prepare itself.

type Renderer Uses

type Renderer interface {
    GetID() string
    Value() (value Value, present bool)
    Render(name, content string) (string, error)
}

Renderer is passed to resources

type Resource Uses

type Resource interface {
    Prepare(context.Context, Renderer) (Task, error)
}

Resource adds metadata about the executed tasks

type Status Uses

type Status struct {
    // Differences contains the things that will change as a part of this
    // Status. This will be used almost exclusively in the Check phase of
    // operations on resources. Use `NewStatus` to get a Status with this
    // initialized properly.
    Differences map[string]Diff

    // Output is the human-consumable fields on this struct. Output will be
    // returned as the Status' messages
    Output []string

    // Level indicates the change level of the status. Level is a gradation (see
    // the Status* contsts above.)
    Level StatusLevel
    // contains filtered or unexported fields
}

Status is the default TaskStatus implementation

func NewStatus Uses

func NewStatus() *Status

NewStatus returns a Status with all fields initialized

func (*Status) AddDifference Uses

func (t *Status) AddDifference(name, original, current, defaultVal string)

AddDifference adds a TextDiff to the Differences map

func (*Status) AddMessage Uses

func (t *Status) AddMessage(message ...string)

AddMessage adds a human-readable message(s) to the output

func (*Status) Diffs Uses

func (t *Status) Diffs() map[string]Diff

Diffs returns the internal differences

func (*Status) Error Uses

func (t *Status) Error() error

Error returns an error, if set. If the level is StatusCantChange or StatusFatal and an error is not set, Error will generate an appropriate error message.

func (*Status) ExportedFields Uses

func (t *Status) ExportedFields() FieldMap

ExportedFields returns the exported fields from the status

func (*Status) FailingDep Uses

func (t *Status) FailingDep(id string, stat TaskStatus)

FailingDep tracks a new failing dependency

func (*Status) HasChanges Uses

func (t *Status) HasChanges() bool

HasChanges returns the WillChange value

func (*Status) HealthCheck Uses

func (t *Status) HealthCheck() (status *HealthStatus, err error)

HealthCheck provides a default health check implementation for statuses

func (*Status) Messages Uses

func (t *Status) Messages() []string

Messages returns the current output slice

func (*Status) RaiseLevel Uses

func (t *Status) RaiseLevel(level StatusLevel)

RaiseLevel raises the status level to the given level

func (*Status) RaiseLevelForDiffs Uses

func (t *Status) RaiseLevelForDiffs()

RaiseLevelForDiffs raises the status level to StatusWillChange if there are differences in the Differences map

func (*Status) SetError Uses

func (t *Status) SetError(err error)

SetError sets an error on a status

func (*Status) SetWarning Uses

func (t *Status) SetWarning(warning string)

SetWarning sets a warning on a status

func (*Status) StatusCode Uses

func (t *Status) StatusCode() StatusLevel

StatusCode returns the current warning level

func (*Status) UpdateExportedFields Uses

func (t *Status) UpdateExportedFields(input Task) error

UpdateExportedFields sets the exported fields in the status

func (*Status) Warning Uses

func (t *Status) Warning() string

Warning returns the warning message, if set.

type StatusLevel Uses

type StatusLevel uint32

StatusLevel will be used as a level in Status. It indicates if a resource needs to be changed, as well as fatal conditions.

const (
    // StatusNoChange means no changes are necessary. This status signals that
    // execution of dependent resources can continue.
    StatusNoChange StatusLevel = iota

    // StatusWontChange indicates an acceptable delta that wont be corrected.
    // This status signals that execution of dependent resources can continue.
    StatusWontChange

    // StatusWillChange indicates an unacceptable delta that will be corrected.
    // This status signals that execution of dependent resources can continue.
    StatusWillChange

    // StatusMayChange indicates an unacceptable delta that may be corrected. This
    // is considered a warning state that indicates that the resource needs to
    // change but is likely dependent on the succesful execution of another
    // resource. This status signals that execution of dependent resources can
    // continue.
    StatusMayChange

    // StatusCantChange indicates an unacceptable delta that can't be corrected.
    // This is just like StatusFatal except the user will see that the resource
    // needs to change, but can't because of the condition specified in your
    // messaging. This status halts execution of dependent resources.
    StatusCantChange

    // StatusFatal indicates an error. This is just like StatusCantChange except
    // it does not imply that there are changes to be made. This status halts
    // execution of dependent resources.
    StatusFatal
)

func (StatusLevel) String Uses

func (l StatusLevel) String() string

type Task Uses

type Task interface {
    Check(context.Context, Renderer) (TaskStatus, error)
    Apply(context.Context) (TaskStatus, error)
}

Task controls checks and application inside the system. Check will be called first; if it indicates changes will be made then Apply will also be called. Check will be called again if Apply succeeds with no error to get the final status of the resource.

func ResolveTask Uses

func ResolveTask(w interface{}) (Task, bool)

ResolveTask unwraps Tasker layers until it finds an underlying Task or fails

type TaskStatus Uses

type TaskStatus interface {
    Diffs() map[string]Diff
    StatusCode() StatusLevel
    Messages() []string
    HasChanges() bool
    Error() error
    Warning() string
    UpdateExportedFields(Task) error
    ExportedFields() FieldMap
}

TaskStatus represents the results of Check called during planning or application.

type TaskWrapper Uses

type TaskWrapper struct {
    Task
}

TaskWrapper provides an implementation of render.Tasker for tasks

func WrapTask Uses

func WrapTask(t Task) *TaskWrapper

WrapTask creates a new TaskWrapper

func (*TaskWrapper) GetStatus Uses

func (t *TaskWrapper) GetStatus() TaskStatus

GetStatus returns a nil status for a wrapped task

func (*TaskWrapper) GetTask Uses

func (t *TaskWrapper) GetTask() (Task, bool)

GetTask provides Tasker.GetTask ontop of a task

type Tasker Uses

type Tasker interface {
    GetTask() (Task, bool)
    GetStatus() TaskStatus
}

Tasker is a struct that is or contains an embedded resource.Task and a resource.Status. It's implemented by plan.Result and apply.Result

type TextDiff Uses

type TextDiff struct {
    Default string
    Values  [2]string
}

TextDiff is the default Diff implementation

func (TextDiff) Changes Uses

func (t TextDiff) Changes() bool

Changes is true if the Original and Current values differ

func (TextDiff) Current Uses

func (t TextDiff) Current() string

Current returns the modified value of the diff

func (TextDiff) Original Uses

func (t TextDiff) Original() string

Original returns the unmodified value of the diff

type ThunkTask Uses

type ThunkTask struct {
    Name string
}

ThunkTask represents an abstract task over a thunk, used when we need to serialized a thunked value.

func NewThunkedTask Uses

func NewThunkedTask(name string) *ThunkTask

NewThunkedTask generates a ThunkTask from a PrepareThunk

func (*ThunkTask) Apply Uses

func (t *ThunkTask) Apply(context.Context) (TaskStatus, error)

Apply returns a task status with thunk information

func (*ThunkTask) Check Uses

func (t *ThunkTask) Check(context.Context, Renderer) (TaskStatus, error)

Check returns a task status with thunk information

func (*ThunkTask) ToStatus Uses

func (t *ThunkTask) ToStatus() *Status

ToStatus converts a ThunkStatus to a *Status

type Value Uses

type Value interface{}

Value is anything that can be in a renderer's Value

Directories

PathSynopsis
docker
docker/container
docker/image
docker/network
docker/volume
file/content
file/directory
file/fetch
file/mode
file/owner
group
lvm
lvm/fs
lvm/lowlevel
lvm/lv
lvm/sampledata
lvm/testhelpers
lvm/vg
module
package
package/apt
package/rpm
param
shell
shell/query
systemd/unit
unarchive
user
wait
wait/port

Package resource imports 12 packages (graph) and is imported by 40 packages. Updated 2017-03-14. Refresh now. Tools for package owners.