Documentation ¶
Overview ¶
Package model contains Datastore entities definition.
Index ¶
- func CleanupOldEntities(ctx context.Context) error
- func EqualStrSlice(a, b []string) bool
- func ExpireActuations(ctx context.Context) error
- func IntendedMatchesReported(intended, reported *modelpb.AssetState) bool
- func IsActuateDecision(d modelpb.ActuationDecision_Decision) bool
- func IsActuationEnabed(cfg *modelpb.AssetConfig, dep *modelpb.DeploymentConfig) bool
- func IsSameState(a, b *modelpb.AssetState) bool
- func IsUpToDate(inteded, reported, applied *modelpb.AssetState) bool
- func Txn(ctx context.Context, cb func(context.Context) error) error
- func ValidateIntendedState(assetID string, state *modelpb.AssetState) error
- func ValidateReportedState(assetID string, state *modelpb.AssetState) error
- type Actuation
- type ActuationBeginOp
- type ActuationEndOp
- func (op *ActuationEndOp) Apply(ctx context.Context) error
- func (op *ActuationEndOp) Expire(ctx context.Context)
- func (op *ActuationEndOp) HandleActuatedState(ctx context.Context, assetID string, asset *rpcpb.ActuatedAsset)
- func (op *ActuationEndOp) UpdateActuationStatus(ctx context.Context, status *statuspb.Status, logURL string)
- type Asset
- type AssetHistory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupOldEntities ¶
CleanupOldEntities deletes old entities to keep datastore tidy.
func EqualStrSlice ¶
EqualStrSlice compares two string slices.
func ExpireActuations ¶
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 ¶
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 ¶
ActuatedAssetIDs is a sorted list of asset IDs that are being actuated.
Only returns assets with ACTUATE_* 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 ¶
func (op *ActuationBeginOp) Apply(ctx context.Context) (map[string]*modelpb.ActuationDecision, error)
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 ¶
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.