db

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLabelData Data is of invalid type.
	ErrInvalidLabelData = errors.New("label data is invalid")
	// ErrEmptyValue Value is empty.
	ErrEmptyValue = errors.New("value is empty")
	// ErrSeverityValueOutOfRange Severity value is out of range.
	ErrSeverityValueOutOfRange = errors.New("severity value out of range")
	// ErrMaintenanceNeedsEnd ...
	ErrMaintenanceNeedsEnd = errors.New("maintenance event needs a end")
	// ErrEndsBeforeStart An incident ends before it has started.
	ErrEndsBeforeStart = errors.New("incidents end before it starts")
)

Functions

func AffectsFromImpactComponentList

func AffectsFromImpactComponentList(componentImpacts *apiServerDefinition.ImpactComponentList) (*[]Impact, error)

AffectsFromImpactComponentList parses a apiServerDefinition.ImpactComponentList to an Impact list.

func GetCurrentPhaseGeneration

func GetCurrentPhaseGeneration(dbCon *gorm.DB) (int, error)

GetCurrentPhaseGeneration retrieves the currently highest generation.

func GetHighestIncidentUpdateOrder

func GetHighestIncidentUpdateOrder(dbCon *gorm.DB, incidentID uuid.UUID) (int, error)

GetHighestIncidentUpdateOrder retrieves the currently highest order for an incident.

Types

type Component

type Component struct {
	DisplayName        *apiServerDefinition.DisplayName `yaml:"displayname"`
	Labels             *Labels                          `gorm:"type:jsonb"             yaml:"labels"`
	ActivelyAffectedBy *[]Impact                        `gorm:"foreignKey:ComponentID"`
	Model              `gorm:"embedded"`
}

Component represents a single component that could be affected by many Incident.

func ComponentFromAPI

func ComponentFromAPI(componentRequest *apiServerDefinition.Component) (*Component, error)

ComponentFromAPI creates a Component from an API request.

func (*Component) GetImpactIncidentList

func (c *Component) GetImpactIncidentList() *apiServerDefinition.ImpactIncidentList

GetImpactIncidentList converts the impact list.

func (*Component) ToAPIResponse

ToAPIResponse converts to API response.

type ID

type ID = uuid.UUID

ID is the generally used identifier type. String type for UUIDs.

type Impact

type Impact struct {
	Incident   *Incident   `gorm:"foreignKey:IncidentID"`
	Component  *Component  `gorm:"foreignKey:ComponentID"`
	ImpactType *ImpactType `gorm:"foreignKey:ImpactTypeID"`

	IncidentID   *ID `gorm:"primaryKey"`
	ComponentID  *ID `gorm:"primaryKey"`
	ImpactTypeID *ID `gorm:"primaryKey"`

	Severity *apiServerDefinition.SeverityValue `gorm:"type:smallint"`
}

Impact connect a Incident with a Component and ImpactType.

type ImpactType

type ImpactType struct {
	DisplayName *apiServerDefinition.DisplayName `gorm:"not null"    yaml:"displayname"`
	Description *apiServerDefinition.Description `yaml:"description"`
	Model       `gorm:"embedded"`
}

ImpactType represents the type of impact.

func ImpactTypeFromAPI

func ImpactTypeFromAPI(impactTypeRequest *apiServerDefinition.ImpactType) (*ImpactType, error)

ImpactTypeFromAPI creates an ImpactType from an API request.

func (*ImpactType) ToAPIResponse

ToAPIResponse converts to API response.

type Incident

type Incident struct {
	DisplayName     *apiServerDefinition.DisplayName
	Description     *apiServerDefinition.Description
	Affects         *[]Impact `gorm:"foreignKey:IncidentID;constraint:OnDelete:CASCADE"`
	BeganAt         *apiServerDefinition.Date
	EndedAt         *apiServerDefinition.Date
	PhaseGeneration *apiServerDefinition.Incremental
	PhaseOrder      *apiServerDefinition.Incremental
	Phase           *Phase            `gorm:"foreignKey:PhaseGeneration,PhaseOrder;References:Generation,Order"`
	Updates         *[]IncidentUpdate `gorm:"foreignKey:IncidentID;constraint:OnDelete:CASCADE"`
	Model           `gorm:"embedded"`
}

Incident represents an incident happening to one or more Component.

func IncidentFromAPI

func IncidentFromAPI(incidentRequest *apiServerDefinition.Incident) (*Incident, error)

IncidentFromAPI creates an Incident from an API request.

func (*Incident) GetImpactComponentList

func (i *Incident) GetImpactComponentList() *apiServerDefinition.ImpactComponentList

GetImpactComponentList converts the Affects list to an apiServerDefinition.ImpactComponentList.

func (*Incident) GetIncidentUpdates

func (i *Incident) GetIncidentUpdates() *apiServerDefinition.IncrementalList

GetIncidentUpdates converts the Updates list to an apiServerDefinition.IncrementalList.

func (*Incident) ToAPIResponse

ToAPIResponse converts to API response.

type IncidentUpdate

type IncidentUpdate struct {
	IncidentID  *ID                              `gorm:"primaryKey"`
	Order       *apiServerDefinition.Incremental `gorm:"primaryKey"`
	DisplayName *apiServerDefinition.DisplayName
	Description *apiServerDefinition.Description
	CreatedAt   *apiServerDefinition.Date
}

IncidentUpdate describes a action that changes the incident.

func IncidentUpdateFromAPI

func IncidentUpdateFromAPI(
	incidentUpdateRequest *apiServerDefinition.IncidentUpdate,
	incidentID uuid.UUID,
	order int,
) (*IncidentUpdate, error)

IncidentUpdateFromAPI creates an IncidentUpdate from an API request.

func (*IncidentUpdate) ToAPIResponse

ToAPIResponse converts to API response.

type Labels

Labels are metadata for components.

func (*Labels) Scan

func (l *Labels) Scan(value interface{}) error

Scan implements the database/sql.Scanner interface to correctly read data.

type Model

type Model struct {
	ID ID `gorm:"primaryKey;type:uuid;"`
}

Model sets the basic Data for all true database resources.

func (*Model) BeforeCreate

func (m *Model) BeforeCreate(_ *gorm.DB) error

BeforeCreate is a gorm hook to fill the ID field with a new UUID, before an insert statement is send to the database.

type Phase

type Phase struct {
	Name       *apiServerDefinition.Phase       `gorm:"not null"   yaml:"name"`
	Generation *apiServerDefinition.Incremental `gorm:"primaryKey"`
	Order      *apiServerDefinition.Incremental `gorm:"primaryKey"`
}

Phase represents a state of an incident on a moving scale to resolution of the incident.

func PhaseReferenceFromAPI

func PhaseReferenceFromAPI(phase *apiServerDefinition.PhaseReference) (*Phase, error)

PhaseReferenceFromAPI creates a Phase from an API request.

type Severity

type Severity struct {
	DisplayName *apiServerDefinition.DisplayName   `yaml:"name"`
	Value       *apiServerDefinition.SeverityValue `gorm:"type:smallint;unique" yaml:"value"`
}

Severity represents a severity of a incident affecting a component.

func NewSeverity

func NewSeverity(
	displayName apiServerDefinition.DisplayName,
	value apiServerDefinition.SeverityValue,
) (*Severity, error)

NewSeverity checks the value and creates a new severity.

func SeverityFromAPI

func SeverityFromAPI(severityRequest *apiServerDefinition.SeverityRequest) (*Severity, error)

SeverityFromAPI creates a Severity from an API request.

func (*Severity) ToAPIResponse

func (s *Severity) ToAPIResponse() apiServerDefinition.Severity

ToAPIResponse converts to API response.

Jump to

Keyboard shortcuts

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