model

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 10 Imported by: 0

README

About this model

Within the model package, the top level definitions, contain the structural definitions of each entity. This is to support Gorm persistence functionality.

A package at level-two, is the behaviors and implementation of each entity in the model. This was done to keep things clean via decorator pattern implementation, for example.w

Documentation

Index

Constants

View Source
const DefaultNumberOfRetries = 3

Variables

This section is empty.

Functions

func ParseAzureDeploymentName

func ParseAzureDeploymentName(azureDeploymentName string) (*int, error)

Parses the azure deployment name and returns OUR deployment id

Types

type AttributeKey

type AttributeKey string
const (
	AttributeKeyCorrelationId       AttributeKey = "correlationId"
	AttributeKeyAzureDeploymentName AttributeKey = "azureDeploymentName"
	AttributeKeyResumeToken         AttributeKey = "resumeToken"
	AttributeKeyArmTemplate         AttributeKey = "armTemplate"
)

type BaseWithGuidPrimaryKey

type BaseWithGuidPrimaryKey struct {
	ID        uuid.UUID `gorm:"type:uuid;primaryKey;"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
}

Base contains common columns for all tables.

func (*BaseWithGuidPrimaryKey) BeforeCreate

func (base *BaseWithGuidPrimaryKey) BeforeCreate(tx *gorm.DB) error

BeforeCreate will set a UUID rather than numeric ID.

type Deployment

type Deployment struct {
	gorm.Model
	Name     string         `json:"name"`
	Template map[string]any `json:"template" gorm:"json"`
	Stages   []Stage        `json:"stages" gorm:"foreignKey:DeploymentID"`

	// azure properties
	SubscriptionId string `json:"subscriptionId"`
	ResourceGroup  string `json:"resourceGroup"`
	Location       string `json:"location"`
}

func (*Deployment) GetAzureDeploymentName

func (d *Deployment) GetAzureDeploymentName() string

Gets the azure deployment name suitable for azure deployment format - modm.<deploymentId>.<deploymentName>

func (*Deployment) ParseAzureDeploymentName

func (d *Deployment) ParseAzureDeploymentName(azureDeploymentName string) (*int, error)

type EventHook

type EventHook struct {
	BaseWithGuidPrimaryKey
	Callback string `json:"callback"`
	Name     string `json:"name" gorm:"unique"`
	ApiKey   string `json:"authKey"`
}

event hook subscriptions are stored with this

func FromCreateEventHook

func FromCreateEventHook(from *sdk.CreateEventHookRequest) *EventHook

Maps a command to create an event subscription to the hook data model

type EventHookAuditEntry added in v1.3.0

type EventHookAuditEntry struct {
	gorm.Model
	Hash    string `json:"hash"`
	Message any    `json:"message" gorm:"json"`
}

record for all event hook messages sent

type InvokedOperation

type InvokedOperation struct {
	BaseWithGuidPrimaryKey
	ParentID     *uuid.UUID                       `json:"parentId" gorm:"type:uuid"`
	Name         string                           `json:"name"`
	DeploymentId uint                             `json:"deploymentId"`
	Attributes   []InvokedOperationAttribute      `json:"attributes"`
	Retries      uint                             `json:"retries"`
	Attempts     uint                             `json:"attempts"`
	Parameters   map[string]any                   `json:"parameters" gorm:"json"`
	Results      map[uint]*InvokedOperationResult `json:"results" gorm:"json"`
	Status       string                           `json:"status"` // the current or final status of the operation
	Completed    bool                             `json:"completed"`
}

InvokedOperation is a record of an operation that was invoked by the operator

remarks:
	attributes - specify information about or that control the operation's use and behavior

func (*InvokedOperation) AttemptsExceeded

func (o *InvokedOperation) AttemptsExceeded() bool

func (*InvokedOperation) Attribute

func (o *InvokedOperation) Attribute(key AttributeKey, v any)

func (*InvokedOperation) AttributeValue

func (o *InvokedOperation) AttributeValue(key AttributeKey) (any, bool)

func (*InvokedOperation) Complete added in v1.3.0

func (o *InvokedOperation) Complete()

func (*InvokedOperation) CompletedAt added in v1.3.0

func (o *InvokedOperation) CompletedAt() (*time.Time, error)

func (*InvokedOperation) CorrelationId added in v1.3.1

func (o *InvokedOperation) CorrelationId() (*uuid.UUID, error)

func (*InvokedOperation) Error

func (o *InvokedOperation) Error(err error)

func (*InvokedOperation) Failed

func (o *InvokedOperation) Failed() error

sets the status to failed for the operation and the latest attempt's result

func (*InvokedOperation) FirstResult added in v1.3.2

func (o *InvokedOperation) FirstResult() *InvokedOperationResult

func (*InvokedOperation) HasAttribute

func (o *InvokedOperation) HasAttribute(key AttributeKey) bool

does the InvokedOperation have an attribute with the specified key?

func (*InvokedOperation) IsCompleted added in v1.3.0

func (o *InvokedOperation) IsCompleted() bool

func (*InvokedOperation) IsContinuation added in v1.3.4

func (o *InvokedOperation) IsContinuation() bool

whether the operation execution is being picked up where it last left off if interrupted

func (*InvokedOperation) IsExecutable

func (o *InvokedOperation) IsExecutable() ([]string, bool)

can the operation be executed? if not, then reasons are returned

func (*InvokedOperation) IsFirstAttempt added in v1.3.1

func (o *InvokedOperation) IsFirstAttempt() bool

func (*InvokedOperation) IsPending added in v1.3.5

func (o *InvokedOperation) IsPending() bool

func (*InvokedOperation) IsRetry

func (o *InvokedOperation) IsRetry() bool

func (*InvokedOperation) IsRetrying added in v1.3.0

func (o *InvokedOperation) IsRetrying() bool

func (*InvokedOperation) IsRunning

func (o *InvokedOperation) IsRunning() bool

func (*InvokedOperation) IsScheduled added in v1.3.0

func (o *InvokedOperation) IsScheduled() bool

func (*InvokedOperation) LatestResult

func (o *InvokedOperation) LatestResult() *InvokedOperationResult

func (*InvokedOperation) ParameterValue added in v1.3.4

func (o *InvokedOperation) ParameterValue(key ParameterKey) (any, bool)

func (*InvokedOperation) Pending added in v1.3.5

func (o *InvokedOperation) Pending()

increment the number of attempts and set the status to running if it's in a state where it can be run. return: returns true if status changed to running

func (*InvokedOperation) Running

func (o *InvokedOperation) Running()

increment the number of attempts and set the status to running if it's in a state where it can be run. return: returns true if status changed to running

func (*InvokedOperation) Schedule

func (o *InvokedOperation) Schedule() error

func (*InvokedOperation) Success

func (o *InvokedOperation) Success() error

sets the status to success for the operation and the latest attempt's result

func (*InvokedOperation) Value

func (o *InvokedOperation) Value(v any)

type InvokedOperationAttribute

type InvokedOperationAttribute struct {
	gorm.Model
	Key                string    `json:"key" gorm:"uniqueIndex:composite_index;index;not null"`
	Value              any       `json:"value" gorm:"json"`
	InvokedOperationID uuid.UUID `json:"invokedOperationId" gorm:"type:uuid;uniqueIndex:composite_index;index;not null"`
}

func NewAttribute

func NewAttribute(key AttributeKey, v any) InvokedOperationAttribute

func (InvokedOperationAttribute) Set

type InvokedOperationResult

type InvokedOperationResult struct {
	Attempt     uint      `json:"attempt"`
	Error       string    `json:"error"`
	Value       any       `json:"value" gorm:"json"`
	Status      string    `json:"status"`
	StartedAt   time.Time `json:"startedAt"`
	CompletedAt time.Time `json:"completedAt"`
}

type ParameterKey

type ParameterKey string
const (
	ParameterKeyStageId            ParameterKey = "stageId"
	ParameterKeyNestedTemplateName ParameterKey = "nestedTemplateName"
)

type Stage

type Stage struct {
	BaseWithGuidPrimaryKey
	DeploymentID        uint              `json:"deploymentId" gorm:"primaryKey"`
	Name                string            `json:"name"`
	AzureDeploymentName string            `json:"azureDeploymentName"`
	Attributes          map[string]string `json:"attributes" gorm:"json"`
	// the default number of retries
	Retries uint `json:"retries"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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