action

package
v0.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package action defines a base action (actions get born a result of policy diff calculation), as well as context which gets passed to all actions during apply phase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectMetricsFor added in v0.1.15

func CollectMetricsFor(action Interface, start time.Time, err error)

CollectMetricsFor collects metrics for the given action, start time and resulting error

Types

type ApplyFunction added in v0.1.14

type ApplyFunction func(Interface) error

ApplyFunction is a function which applies an action

func Noop added in v0.1.14

func Noop() ApplyFunction

Noop returns a function that does nothing and returns nil

func WrapParallelWithLimit added in v0.1.15

func WrapParallelWithLimit(maxConcurrentGoRoutines int, fn ApplyFunction) ApplyFunction

WrapParallelWithLimit allows to run the provided function in parallel, but in no more than maxConcurrentGoRoutines concurrent go routines

func WrapSequential added in v0.1.14

func WrapSequential(fn ApplyFunction) ApplyFunction

WrapSequential wraps apply function to be sequential

type ApplyResult added in v0.1.14

type ApplyResult struct {
	Success uint32
	Failed  uint32
	Skipped uint32
	Total   uint32
}

ApplyResult is a result of applying actions

type ApplyResultUpdater added in v0.1.14

type ApplyResultUpdater interface {
	SetTotal(actions uint32)
	AddSuccess()
	AddFailed()
	AddSkipped()
	Done() *ApplyResult
}

ApplyResultUpdater is an interface for handling revision progress stats (# of processed actions) when applying action plan

type ApplyResultUpdaterImpl added in v0.1.14

type ApplyResultUpdaterImpl struct {
	Result *ApplyResult
}

ApplyResultUpdaterImpl is a default thread-safe implementation of ApplyResultUpdater

func NewApplyResultUpdaterImpl added in v0.1.14

func NewApplyResultUpdaterImpl() *ApplyResultUpdaterImpl

NewApplyResultUpdaterImpl creates a new default thread-safe implementation ApplyResultUpdaterImpl of ApplyResultUpdater

func (*ApplyResultUpdaterImpl) AddFailed added in v0.1.14

func (updater *ApplyResultUpdaterImpl) AddFailed()

AddFailed safely increments the number of failed actions

func (*ApplyResultUpdaterImpl) AddSkipped added in v0.1.14

func (updater *ApplyResultUpdaterImpl) AddSkipped()

AddSkipped safely increments the number of skipped actions

func (*ApplyResultUpdaterImpl) AddSuccess added in v0.1.14

func (updater *ApplyResultUpdaterImpl) AddSuccess()

AddSuccess safely increments the number of successfully executed actions

func (*ApplyResultUpdaterImpl) Done added in v0.1.14

func (updater *ApplyResultUpdaterImpl) Done() *ApplyResult

Done does nothing except doing an integrity check for default implementation

func (*ApplyResultUpdaterImpl) SetTotal added in v0.1.14

func (updater *ApplyResultUpdaterImpl) SetTotal(total uint32)

SetTotal safely sets the total number of actions

type Context

type Context struct {
	DesiredPolicy      *lang.Policy
	DesiredState       *resolve.PolicyResolution
	ActualStateUpdater actual.StateUpdater
	ExternalData       *external.Data
	Plugins            plugin.Registry
	EventLog           *event.Log
}

Context is a data struct that will be passed into all state update actions, giving actions access to desired policy/state, and actual state and a way to updatae it, list of plugins, event log, etc

func NewContext

func NewContext(desiredPolicy *lang.Policy, desiredState *resolve.PolicyResolution, actualStateUpdater actual.StateUpdater, externalData *external.Data, plugins plugin.Registry, eventLog *event.Log) *Context

NewContext creates a new instance of Context

type GraphNode added in v0.1.14

type GraphNode struct {
	// Key is unique identifier of the node
	Key string

	// Before is a map of actions which have to be executed before main actions of this node. If one of them fails,
	// main actions will not be executed
	Before []*GraphNode

	// BeforeRev is the opposite to Before, indicating which actions have to be executed after this node finishes
	// execution
	BeforeRev []*GraphNode

	// Main actions which have to be executed sequentially. If one fails, the rest will not be executed
	Actions []Interface
}

GraphNode represents a node in the graph of apply actions

func NewGraphNode added in v0.1.14

func NewGraphNode(key string) *GraphNode

NewGraphNode creates a new GraphNode of apply actions

func (*GraphNode) AddAction added in v0.1.14

func (node *GraphNode) AddAction(action Interface, actualState *resolve.PolicyResolution, avoidDuplicates bool)

AddAction adds an action to the list of main actions. If avoidDuplicates is true, then duplicate actions will not be added (e.g. update action)

func (*GraphNode) AddBefore added in v0.1.14

func (node *GraphNode) AddBefore(that *GraphNode)

AddBefore adds an action to be executed before the list of main actions

type Interface added in v0.1.15

type Interface interface {
	runtime.Storable
	Apply(*Context) error
	DescribeChanges() util.NestedParameterMap
}

Interface interface for all actions which perform actual state updates

type Metadata

type Metadata struct {
	Name string
}

Metadata is an object metadata for all state update actions

func NewMetadata

func NewMetadata(kind string, keys ...string) *Metadata

NewMetadata creates new Metadata

func (*Metadata) GetName

func (meta *Metadata) GetName() string

GetName returns an action name

func (*Metadata) GetNamespace

func (meta *Metadata) GetNamespace() string

GetNamespace returns a namespace for an action (it's always a system namespace)

func (*Metadata) String

func (meta *Metadata) String() string

type Plan added in v0.1.14

type Plan struct {
	// NodeMap is a map from key to a graph of actions, which must to be executed in order to get from actual state to
	// desired state. Key in the map corresponds to the key of the GraphNode
	NodeMap map[string]*GraphNode
}

Plan is a plan of actions

func NewPlan added in v0.1.14

func NewPlan() *Plan

NewPlan creates a new Plan

func (*Plan) Apply added in v0.1.14

func (plan *Plan) Apply(fn ApplyFunction, resultUpdater ApplyResultUpdater) *ApplyResult

Apply applies the action plan. It may call fn in multiple go routines, executing the plan in parallel

func (*Plan) AsText added in v0.1.14

func (plan *Plan) AsText() *PlanAsText

AsText returns the action plan as array of actions, each represented as text via NestedParameterMap

func (*Plan) GetActionGraphNode added in v0.1.14

func (plan *Plan) GetActionGraphNode(key string) *GraphNode

GetActionGraphNode returns an action graph node for a given component instance key

func (*Plan) NumberOfActions added in v0.1.14

func (plan *Plan) NumberOfActions() uint32

NumberOfActions returns the total number of actions that is expected to be executed in the whole action graph

type PlanAsText added in v0.1.14

type PlanAsText struct {
	Actions []util.NestedParameterMap
}

PlanAsText is a plan of actions, represented as text

func NewPlanAsText added in v0.1.14

func NewPlanAsText() *PlanAsText

NewPlanAsText returns new PlanAsText

func (*PlanAsText) String added in v0.1.15

func (t *PlanAsText) String() string

ToString returns human-readable version of the plan

Directories

Path Synopsis
Package component defines all component-specific actions, which get generated by the policy diff when component changes occur for specific component instances.
Package component defines all component-specific actions, which get generated by the policy diff when component changes occur for specific component instances.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL