resolve

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: 19 Imported by: 33

Documentation

Overview

Package resolve is a heart of Aptomi that performs policy resolution, taking policy and consumption claims as input, producing a set of components to be instantiated in the cloud (desired state) as output, along with their discovery parameters, code parameters, and component instance graph.

Index

Constants

View Source
const AllowIngres = "allow_ingress"

AllowIngres is an special key, which is used in DataForPlugins to indicate whether ingress traffic should be allowed for a given component instance

Variables

View Source
var ComponentInstanceObject = &runtime.Info{
	Kind:        "component-instance",
	Storable:    true,
	Versioned:   false,
	Constructor: func() runtime.Object { return &ComponentInstance{} },
}

ComponentInstanceObject is an informational data structure with Kind and Constructor for component instance object

View Source
var MaxConcurrentGoRoutines = sysruntime.NumCPU()

MaxConcurrentGoRoutines is the number of concurrently running goroutines for policy evaluation and processing. We don't necessarily want to run a lot of them due to CPU/memory constraints and due to the fact that there is minimal io wait time in policy processing (goroutines are mostly busy doing calculations as opposed to waiting).

Functions

This section is empty.

Types

type ClaimResolution added in v0.1.15

type ClaimResolution struct {
	// Resolved indicates whether or not claim has been resolved. If it has been resolved,
	// then ComponentInstanceKey will contain where it got resolved. Otherwise, you can filter event log by this
	// claim and find out the associated events leading to an error.
	Resolved bool

	// ComponentInstanceKey holds the reference to component instance, to which claim got resolved
	ComponentInstanceKey string
}

ClaimResolution contains resolution status for a given claim

type ComponentInstance

type ComponentInstance struct {
	runtime.TypeKind `yaml:",inline"`

	// Metadata is an object metadata for component instance
	Metadata *ComponentInstanceMetadata

	// Error means that a critical error happened with a component (e.g. conflict of parameters)
	Error error

	// ClaimKeys is a list of claim keys which are keeping this component instantiated (if claim resolves to this component directly, then the value is 0. otherwise it's depth in policy resolution)
	ClaimKeys map[string]int

	// IsCode means the component is code
	IsCode bool

	// CalculatedLabels is a set of calculated labels for the component, aggregated over all uses
	CalculatedLabels *lang.LabelSet

	// CalculatedDiscovery is a set of calculated discovery parameters for the component (non-conflicting over all uses of this component)
	CalculatedDiscovery util.NestedParameterMap

	// CalculatedCodeParams is a set of calculated code parameters for the component (non-conflicting over all uses of this component)
	CalculatedCodeParams util.NestedParameterMap

	// DataForPlugins is an additional data recorded for use in plugins
	DataForPlugins map[string]string

	// EdgesOut is a set of outgoing graph edges ('key' -> true) from this component instance. Only makes sense as a part of desired state
	EdgesOut map[string]bool

	// CreatedAt is when this component instance was created
	CreatedAt time.Time

	// UpdatedAt is the last time when this component instance was updated
	UpdatedAt time.Time

	// EndpointsUpToDate is true if endpoints are up to date and false otherwise
	EndpointsUpToDate bool

	// Endpoints represents all URLs that could be used to access deployed bundle
	Endpoints map[string]string
}

ComponentInstance is an instance of a particular code component within a bundle, which indicate that this component has to be instantiated and configured in a certain cluster. Policy resolver produces a map of component instances and their parameters in desired state (PolicyResolution) as result of policy resolution.

When a bundle gets instantiated, a special "root" component instance gets created with component name set to Metadata.Key.ComponentName == componentRootName. Then all "child" component instances get created, one per bundle component with type code.

Every ComponentInstance contains full information about for a given component instance - who is consuming this instance, labels, code params, discovery params, in & out graph edges (what component instances we depend on, what component instances depend on us), creation/update times, and endpoints retrieved from the underlying cloud.

func (*ComponentInstance) GetDeployName

func (instance *ComponentInstance) GetDeployName() string

GetDeployName returns a string that could be used as name for deployment inside the cluster

func (*ComponentInstance) GetKey

func (instance *ComponentInstance) GetKey() string

GetKey returns an object key. It's a component instance key, as generated by the engine

func (*ComponentInstance) GetName

func (instance *ComponentInstance) GetName() string

GetName returns object name

func (*ComponentInstance) GetNamespace

func (instance *ComponentInstance) GetNamespace() string

GetNamespace returns an object namespace. It's a system namespace for all component instances

func (*ComponentInstance) GetRunningTime

func (instance *ComponentInstance) GetRunningTime() time.Duration

GetRunningTime returns the total lifetime of a component instance (since it was launched till now)

func (*ComponentInstance) UpdateTimes

func (instance *ComponentInstance) UpdateTimes(createdAt time.Time, updatedAt time.Time)

UpdateTimes updates component creation and update times

type ComponentInstanceKey

type ComponentInstanceKey struct {

	// required fields
	ClusterNameSpace    string // mandatory
	ClusterName         string // mandatory
	TargetSuffix        string // mandatory
	Namespace           string // determined from the service
	ServiceName         string // mandatory
	ContextName         string // mandatory
	KeysResolved        string // mandatory
	ContextNameWithKeys string // calculated
	BundleName          string // determined from the context (included into key for readability)
	ComponentName       string // component name
	// contains filtered or unexported fields
}

ComponentInstanceKey is a key for component instance. During policy resolution every component instance gets assigned a unique string key. It's important to form those keys correctly, so that we can make actual comparison of actual state (components with their keys) and desired state (components with their keys).

Currently, component keys are formed from multiple parameters as follows. Cluster gets included as a part of the key (components running on different clusters must have different keys). Namespace gets included as a part of the key (components from different namespaces must have different keys). Service, Context (with allocation keys), Bundle get included as a part of the key (Bundle must be within the same namespace as Service). ComponentName gets included as a part of the key. For bundle-level component instances, ComponentName is set to componentRootName, while for all component instances within a bundle an actual Component.Name is used.

func NewComponentInstanceKey

func NewComponentInstanceKey(cluster *lang.Cluster, targetSuffix string, service *lang.Service, context *lang.Context, allocationKeysResolved []string, bundle *lang.Bundle, component *lang.BundleComponent) *ComponentInstanceKey

NewComponentInstanceKey creates a new ComponentInstanceKey

func (ComponentInstanceKey) GetDeployName

func (cik ComponentInstanceKey) GetDeployName() string

GetDeployName returns a string that could be used as name for deployment inside the cluster

func (ComponentInstanceKey) GetKey

func (cik ComponentInstanceKey) GetKey() string

GetKey returns a string key

func (*ComponentInstanceKey) GetParentBundleKey added in v0.1.15

func (cik *ComponentInstanceKey) GetParentBundleKey() *ComponentInstanceKey

GetParentBundleKey returns a key for the parent bundle, replacing componentName with componentRootName

func (*ComponentInstanceKey) IsBundle added in v0.1.15

func (cik *ComponentInstanceKey) IsBundle() bool

IsBundle returns 'true' if it's a bundle instance key and we can't go up anymore. And it will return 'false' if it's a component instance key

func (*ComponentInstanceKey) IsComponent

func (cik *ComponentInstanceKey) IsComponent() bool

IsComponent returns 'true' if it's a component instance key and we can go up to the corresponding bundle. And it will return 'false' if it's a bundle instance key

func (*ComponentInstanceKey) MakeCopy

func (cik *ComponentInstanceKey) MakeCopy() *ComponentInstanceKey

MakeCopy creates a copy of ComponentInstanceKey

type ComponentInstanceMetadata

type ComponentInstanceMetadata struct {
	Key *ComponentInstanceKey
}

ComponentInstanceMetadata is object metadata for ComponentInstance

type PolicyResolution

type PolicyResolution struct {
	// Resolved component instances: componentKey -> componentInstance
	ComponentInstanceMap map[string]*ComponentInstance
}

PolicyResolution contains resolution data for the policy. It essentially represents the desired state calculated by policy resolver. It contains a calculated map of component instances with their data, with information about resolved claims.

func NewPolicyResolution

func NewPolicyResolution() *PolicyResolution

NewPolicyResolution creates new empty PolicyResolution, given a flag indicating whether it's a desired state (generated by a resolver), or actual state (loaded from the store)

func (*PolicyResolution) AppendData

func (resolution *PolicyResolution) AppendData(ops *PolicyResolution)

AppendData appends data to the current PolicyResolution record by aggregating data over component instances. If there is a conflict (e.g. components have different code parameters), then the corresponding component instances will be marked with errors.

func (*PolicyResolution) GetClaimResolution added in v0.1.15

func (resolution *PolicyResolution) GetClaimResolution(claim *lang.Claim) *ClaimResolution

GetClaimResolution returns resolution status for a particular claim

func (*PolicyResolution) GetComponentInstanceEntry

func (resolution *PolicyResolution) GetComponentInstanceEntry(cik *ComponentInstanceKey) *ComponentInstance

GetComponentInstanceEntry retrieves a component instance entry by key, or creates an new entry if it doesn't exist

func (*PolicyResolution) RecordCodeParams

func (resolution *PolicyResolution) RecordCodeParams(cik *ComponentInstanceKey, codeParams util.NestedParameterMap) error

RecordCodeParams stores calculated code params for component instance

func (*PolicyResolution) RecordDiscoveryParams

func (resolution *PolicyResolution) RecordDiscoveryParams(cik *ComponentInstanceKey, discoveryParams util.NestedParameterMap) error

RecordDiscoveryParams stores calculated discovery params for component instance

func (*PolicyResolution) RecordLabels

func (resolution *PolicyResolution) RecordLabels(cik *ComponentInstanceKey, labels *lang.LabelSet)

RecordLabels stores calculated labels for component instance

func (*PolicyResolution) RecordResolved

func (resolution *PolicyResolution) RecordResolved(cik *ComponentInstanceKey, claim *lang.Claim, depth int, ruleResult *lang.RuleActionResult)

RecordResolved takes a component instance and adds a new claim record into it

func (*PolicyResolution) StoreEdge

func (resolution *PolicyResolution) StoreEdge(src *ComponentInstanceKey, dst *ComponentInstanceKey)

StoreEdge stores incoming/outgoing graph edges for component instance for observability and reporting

func (*PolicyResolution) Validate added in v0.1.2

func (resolution *PolicyResolution) Validate(policy *lang.Policy) error

Validate checks that the state is valid, meaning that all objects references are valid and all components are valid

  • it takes all the instances and verifies that all bundles exist, all clusters exist, etc
  • it also verifies that there are no components with global errors (e.g. conflicting code/discovery params)

type PolicyResolver

type PolicyResolver struct {
	// contains filtered or unexported fields
}

PolicyResolver is a core of Aptomi for policy resolution and translating all claims into a single PolicyResolution object which represents desired state of components running in a cloud.

func NewPolicyResolver

func NewPolicyResolver(policy *lang.Policy, externalData *external.Data, eventLog *event.Log) *PolicyResolver

NewPolicyResolver creates a new policy resolver. You must call policy.Validate() before calling this method, to ensure that the policy is valid.

func (*PolicyResolver) ResolveAllClaims added in v0.1.15

func (resolver *PolicyResolver) ResolveAllClaims() *PolicyResolution

ResolveAllClaims takes policy as input and calculates PolicyResolution (desired state) as output.

The method resolves all recorded claims for consuming services ("instantiate <service> with <labels>"), calculating which components have to be allocated and with which parameters. Once PolicyResolution (desired state) is calculated, it can be rendered by the engine diff/apply by deploying and configuring required components in the cloud.

As a result, status of every claim will be stored in resolution state.

Jump to

Keyboard shortcuts

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