v1models

package
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBuildNotFound          error = gorm.ErrRecordNotFound
	ErrDuplicateVersionString error = errors.New("field version_string for builds must be unique")
	// ErrBadCreateRequest is an error type used when a create servie request fails validation checks
	ErrBadCreateRequest error = errors.New("error invalid create build request")
)

ErrBuildNotFound is returned when a specific build look up fails

View Source
var ErrAllocationPoolNotFound = gorm.ErrRecordNotFound

ErrAllocationPoolNotFound is the error to represent a failed lookup of a allocationPool db record

View Source
var ErrClusterNotFound = gorm.ErrRecordNotFound

ErrClusterNotFound is the error to represent a failed lookup of a cluster db record

View Source
var (
	// ErrDeployNotFound is retunrned when unable to find a deployment db record that matches a get query
	ErrDeployNotFound = gorm.ErrRecordNotFound
)
View Source
var ErrEnvironmentNotFound = gorm.ErrRecordNotFound

ErrEnvironmentNotFound is the error to represent a failed lookup of a environment db record

View Source
var (
	// ErrServiceInstanceNotFound is a wrapper around gorms failed lookup error specifically
	// for failure to find a service instance
	ErrServiceInstanceNotFound = gorm.ErrRecordNotFound
)
View Source
var (
	ErrServiceNotFound = gorm.ErrRecordNotFound
)

ErrServiceNotFound is the error to represent a failed lookup of a service entity

Functions

func NewAllocationPoolStore

func NewAllocationPoolStore(dbconn *gorm.DB) allocationPoolStore

NewAllocationPoolStore creates a db connection via gorm

func NewBuildStore

func NewBuildStore(dbConn *gorm.DB) buildStore

func NewClusterStore

func NewClusterStore(dbconn *gorm.DB) clusterStore

creates a db connection via gorm

func NewDeployStore

func NewDeployStore(dbConn *gorm.DB) deployStore

func NewEnvironmentStore

func NewEnvironmentStore(dbconn *gorm.DB) environmentStore

func NewServiceInstanceStore

func NewServiceInstanceStore(dbConn *gorm.DB) serviceInstanceStore

func NewServiceStore

func NewServiceStore(db *gorm.DB) serviceStore

Types

type AllocationPool

type AllocationPool struct {
	ID           int    `gorm:"primaryKey;uniqueIndex"`
	Name         string `gorm:"not null;default:null"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
	Environments []Environment
}

AllocationPool is the data structure that models a persisted to a database via gorm

type AllocationPoolStore

type AllocationPoolStore interface {
	ListAll() ([]AllocationPool, error)
	CreateNew(CreateAllocationPoolRequest) (AllocationPool, error)
	GetByID(int) (AllocationPool, error)
	GetByName(string) (AllocationPool, error)
	AddEnvironmentByID(AllocationPool, int) (AllocationPool, error)
}

allocationPoolStore is the interface defining allowed db actions for AllocationPool

type Build

type Build struct {
	ID            int
	VersionString string `gorm:"not null;default:null"`
	CommitSha     string
	BuildURL      string
	BuiltAt       time.Time `gorm:"autoCreateTime"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
	ServiceID     int
	Service       Service `gorm:"foreignKey:ServiceID;references:ID"`
}

Build is the structure used to represent a build entity in sherlock's db persistence layer

func SeedBuilds

func SeedBuilds(db *gorm.DB) ([]Build, error)

SeedBuilds is a testing utility used in functional tests to populate a postgres DB with fake Build entities

type BuildStore

type BuildStore interface {
	ListAll() ([]Build, error)
	CreateNew(Build) (Build, error)
	GetByID(int) (Build, error)
	GetByVersionString(string) (Build, error)
}

type Cluster

type Cluster struct {
	ID            int    `gorm:"primaryKey;uniqueIndex"`
	Name          string `gorm:"not null;default:null"`
	GoogleProject string
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

Cluster is the data structure that models a persisted to a database via gorm

type ClusterStore

type ClusterStore interface {
	ListAll() ([]Cluster, error)
	CreateNew(CreateClusterRequest) (Cluster, error)
	GetByID(int) (Cluster, error)
	GetByName(string) (Cluster, error)
}

clusterStore is the interface defining allowed db actions for Cluster

type CreateAllocationPoolRequest

type CreateAllocationPoolRequest struct {
	Name         string `json:"name" binding:"required"`
	Environments []Environment
}

CreateAllocationPoolRequest struct defines the data required to create a new allocationPool in db

func (CreateAllocationPoolRequest) AllocationPoolReq

func (createAllocationPoolRequest CreateAllocationPoolRequest) AllocationPoolReq() AllocationPool

creates a allocationPool entity object to be persisted with the database from a request to create a allocationPool

type CreateClusterRequest

type CreateClusterRequest struct {
	Name string `json:"name" binding:"required"`
}

CreateClusterRequest struct defines the data required to create a new cluster in db

func (CreateClusterRequest) ClusterReq

func (createClusterRequest CreateClusterRequest) ClusterReq() Cluster

creates a cluster entity object to be persisted with the database from a request to create a cluster.

type CreateEnvironmentRequest

type CreateEnvironmentRequest struct {
	Name string `json:"name" binding:"required"`
}

CreateEnvironmentRequest struct defines the data required to create a new environment in db

func (CreateEnvironmentRequest) EnvironmentReq

func (createEnvironmentRequest CreateEnvironmentRequest) EnvironmentReq() Environment

creates a environment entity object to be persisted with the database from a request to create a environment

type CreateServiceRequest

type CreateServiceRequest struct {
	Name    string `json:"name" binding:"required"`
	RepoURL string `json:"repo_url" binding:"required"`
}

CreateServiceRequest is a type used to represent the information required to register a new service in sherlock

func (CreateServiceRequest) Service

func (cr CreateServiceRequest) Service() Service

creates a service entity object to be persisted with the database from a request to create a service

type Deploy

type Deploy struct {
	ID                int
	ServiceInstanceID int
	ServiceInstance   ServiceInstance `gorm:"foreignKey:ServiceInstanceID;references:ID"`
	BuildID           int
	Build             Build `gorm:"foreignKey:BuildID;references:ID"`
	CreatedAt         time.Time
	UpdatedAt         time.Time
}

Deploy is the type defining the database model for a deployment. It is an association between a service instance and a build

func (*Deploy) CalculateLeadTimeHours

func (deploy *Deploy) CalculateLeadTimeHours() float64

type DeployStore

type DeployStore interface {
	CreateDeploy(buildID, serviceInstanceID int) (Deploy, error)
	GetDeploysByServiceInstance(serviceInstanceID int) ([]Deploy, error)
	GetMostRecentDeployByServiceInstance(serviceInstanceID int) (Deploy, error)
}

type Environment

type Environment struct {
	ID               int    `gorm:"primaryKey"`
	Name             string `gorm:"not null;default:null"`
	IsPermanent      bool
	Requester        string
	DestroyedAt      time.Time
	CreatedAt        time.Time
	UpdatedAt        time.Time
	AllocationPoolID *int `gorm:"default:null"`
}

Environment is the data structure that models a persisted to a database via gorm

func SeedEnvironments

func SeedEnvironments(db *gorm.DB) ([]Environment, error)

SeedEnvironments takes a gorm DB connection and will seed a db with some fake environment data for use in functional testing

type EnvironmentStore

type EnvironmentStore interface {
	ListAll() ([]Environment, error)
	CreateNew(CreateEnvironmentRequest) (Environment, error)
	GetByID(int) (Environment, error)
	GetByName(string) (Environment, error)
}

environmentStore is the interface defining allowed db actions for Environment

type Service

type Service struct {
	ID        int    `gorm:"primaryKey" faker:"unique"`
	Name      string `gorm:"not null;default:null"`
	RepoURL   string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Service is the data structure that models a service entity persisted to a database via gorm

func SeedServices

func SeedServices(db *gorm.DB) ([]Service, error)

SeedServices is a test utility that will populate a database with a predetermined list of "services" to be used for running functional tests against a real database

type ServiceInstance

type ServiceInstance struct {
	ID            int
	ServiceID     int
	Service       Service `gorm:"foreignKey:ServiceID;references:ID"`
	EnvironmentID int
	Environment   Environment `gorm:"foreignKey:EnvironmentID;references:ID"`
	ClusterID     int         `gorm:"default:null"`
	Cluster       Cluster     `gorm:"foreignKey:ClusterID;references:ID"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

ServiceInstance is the model type for interacting with the database representation of service instances

func SeedServiceInstances

func SeedServiceInstances(db *gorm.DB) ([]ServiceInstance, error)

SeedServiceInstances is used to populate the database with Service Instance entities solely intended for use in testing

type ServiceInstanceStore

type ServiceInstanceStore interface {
	ListAll() ([]ServiceInstance, error)
	CreateNew(clusterID, environmentID, serviceID int) (ServiceInstance, error)
	GetByEnvironmentAndServiceID(environmentID, serviceID int) (ServiceInstance, error)
	Reload(serviceInstance ServiceInstance, reloadCluster bool, reloadEnvironment bool, reloadService bool) (ServiceInstance, error)
}

type ServiceStore

type ServiceStore interface {
	ListAll() ([]Service, error)
	CreateNew(CreateServiceRequest) (Service, error)
	GetByName(string) (Service, error)
}

serviceStore is the interface type that defines the methods required for implementing the persistence layer for services entities

Jump to

Keyboard shortcuts

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