model

package
v0.0.0-...-128afb8 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package model contains Datastore entities definition.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupOldEntities

func CleanupOldEntities(ctx context.Context) error

CleanupOldEntities deletes old entities to keep datastore tidy.

func EqualStrSlice

func EqualStrSlice(a, b []string) bool

EqualStrSlice compares two string slices.

func ExpireActuations

func ExpireActuations(ctx context.Context) error

ExpireActuations moves expired actuations into EXPIRED state.

func IntendedMatchesReported

func IntendedMatchesReported(intended, reported *modelpb.AssetState) bool

IntendedMatchesReported is true if the intended state matches the reported state.

States must be non-erroneous and be valid per ValidateIntendedState and ValidateReportedState.

func IsActuateDecision

func IsActuateDecision(d modelpb.ActuationDecision_Decision) bool

IsActuateDecision returns true for ACTUATE_* decisions.

func IsActuationEnabed

func IsActuationEnabed(cfg *modelpb.AssetConfig, dep *modelpb.DeploymentConfig) bool

IsActuationEnabed checks if the actuation for an asset is enabled.

func IsSameState

func IsSameState(a, b *modelpb.AssetState) bool

IsSameState compares `state` portion of AssetState.

Ignores all other fields. If any of the states is erroneous (with no `state` field), returns false.

func IsUpToDate

func IsUpToDate(inteded, reported, applied *modelpb.AssetState) bool

IsUpToDate returns true if an asset is up-to-date and should not be actuated.

An asset is considered up-to-date if its reported state matches the intended state, and the intended state hasn't changed since the last successful actuation.

func Txn

func Txn(ctx context.Context, cb func(context.Context) error) error

Txn runs the callback in a datastore transaction.

Transient-tagged errors trigger a transaction retry. If all retries are exhausted, returns a transient-tagged error itself.

func ValidateIntendedState

func ValidateIntendedState(assetID string, state *modelpb.AssetState) error

ValidateIntendedState checks AssetState proto matches the asset kind.

Checks all `intended_state` fields are populated. Purely erronous states (with no state and non-zero status code) are considered valid.

func ValidateReportedState

func ValidateReportedState(assetID string, state *modelpb.AssetState) error

ValidateReportedState checks AssetState proto matches the asset kind.

Checks all `captured_state` fields are populated. Purely erronous states (with no state and non-zero status code) are considered valid.

Types

type Actuation

type Actuation struct {

	// ID is the unique ID of the actuation matching Actuation.Id.
	ID string `gae:"$id"`
	// Actuation contains all details about the actuation.
	Actuation *modelpb.Actuation
	// Decisions is what the backend decided to do with the actuated assets.
	Decisions *modelpb.ActuationDecisions

	// State matches Actuation.State, exposed for indexing.
	State modelpb.Actuation_State
	// Created matches Actuation.Created, exposed for indexing.
	Created time.Time
	// Expiry matches Actuation.Expiry, exposed for indexing.
	Expiry time.Time
	// contains filtered or unexported fields
}

Actuation is an inflight or finished actuation of some deployment.

func (*Actuation) ActuatedAssetIDs

func (a *Actuation) ActuatedAssetIDs() []string

ActuatedAssetIDs is a sorted list of asset IDs that are being actuated.

Only returns assets with ACTUATE_* decisions.

func (*Actuation) AssetIDs

func (a *Actuation) AssetIDs() []string

AssetIDs is a sorted list of asset IDs reported in this actuation.

Returns assets with any actuation decision, including all SKIP_* decisions.

type ActuationBeginOp

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

ActuationBeginOp collects changes to transactionally apply to the datastore to begin a new actuation.

func NewActuationBeginOp

func NewActuationBeginOp(ctx context.Context, assets []string, actuation *modelpb.Actuation) (*ActuationBeginOp, error)

NewActuationBeginOp starts a datastore operation to create an actuation.

Takes ownership of `actuation` mutating it.

func (*ActuationBeginOp) Apply

Apply stores all updated or created datastore entities.

Must be called only after all per-asset MakeDecision calls. Returns the mapping with recorded decisions.

func (*ActuationBeginOp) MakeDecision

func (op *ActuationBeginOp) MakeDecision(ctx context.Context, assetID string, asset *rpcpb.AssetToActuate)

MakeDecision decides what to do with an asset and records this decision.

Must be called once for every asset passed to NewActuationBeginOp. Takes ownership of `asset` mutating it. AssetToActuate fields must already be validated at this point.

type ActuationEndOp

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

ActuationEndOp collects changes to transactionally apply to the datastore to end an existing actuation.

func NewActuationEndOp

func NewActuationEndOp(ctx context.Context, actuation *Actuation) (*ActuationEndOp, error)

NewActuationEndOp starts a datastore operation to finish an actuation.

Takes ownership of `actuation` mutating it.

func (*ActuationEndOp) Apply

func (op *ActuationEndOp) Apply(ctx context.Context) error

Apply stores all updated or created datastore entities.

func (*ActuationEndOp) Expire

func (op *ActuationEndOp) Expire(ctx context.Context)

Expire marks the actuation as expired.

func (*ActuationEndOp) HandleActuatedState

func (op *ActuationEndOp) HandleActuatedState(ctx context.Context, assetID string, asset *rpcpb.ActuatedAsset)

HandleActuatedState is called to report the post-actuation asset state.

Ignores assets not associated with this actuation anymore. Takes ownership of `asset` mutating it.

func (*ActuationEndOp) UpdateActuationStatus

func (op *ActuationEndOp) UpdateActuationStatus(ctx context.Context, status *statuspb.Status, logURL string)

UpdateActuationStatus is called to report the status of the actuation.

type Asset

type Asset struct {

	// ID is the unique ID of this asset matching Asset.Id.
	ID string `gae:"$id"`
	// Asset contains all details about the asset.
	Asset *modelpb.Asset

	// LastHistoryID is ID of the last committed AssetHistory entity.
	LastHistoryID int64 `gae:",noindex"`

	// HistoryEntry is data of the last committed or currently recording entry.
	//
	// If its ID matches LastHistoryID, then it was already committed and it is
	// the latest entry. Otherwise it is the currently recording one and its ID
	// is LastHistoryID+1.
	HistoryEntry *modelpb.AssetHistory

	// ConsecutiveFailures counts how many actuations failed in a row.
	//
	// It is reset when an actuation succeeds or the asset is determined to be
	// up-to-date, disabled, or locked.
	ConsecutiveFailures int64 `gae:",noindex"`
	// contains filtered or unexported fields
}

Asset represents a Cloud resource (or a bunch of resources) actuated as a single unit.

func (*Asset) IsRecordingHistoryEntry

func (a *Asset) IsRecordingHistoryEntry() bool

IsRecordingHistoryEntry is true if HistoryEntry is an uncommitted record.

type AssetHistory

type AssetHistory struct {

	// ID is monotonically increasing ID, starting with 1.
	ID int64 `gae:"$id"`
	// Parent is the key of the parent Asset entity.
	Parent *datastore.Key `gae:"$parent"`
	// Entry contains all details.
	Entry *modelpb.AssetHistory

	// Created matches Entry.Actuation.Created, exposed for indexing.
	Created time.Time
	// contains filtered or unexported fields
}

AssetHistory is an entry in an asset history log.

Jump to

Keyboard shortcuts

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