Documentation ¶
Overview ¶
Package environments defines data structure representing a environment instance and methods for interacting with them it is left to concrete implementations in package db or others to implement these interfaces
Index ¶
- Variables
- type AllocationPoolController
- func (allocationPoolController *AllocationPoolController) AddEnvironmentByID(currentAllocationPool v1models.AllocationPool, environmentID int) (v1models.AllocationPool, error)
- func (allocationPoolController *AllocationPoolController) CreateNew(newAllocationPool v1models.CreateAllocationPoolRequest) (v1models.AllocationPool, error)
- func (allocationPoolController AllocationPoolController) DoesAllocationPoolExist(name string) (int, bool)
- func (allocationPoolController *AllocationPoolController) GetByID(id int) (v1models.AllocationPool, error)
- func (allocationPoolController *AllocationPoolController) GetByName(name string) (v1models.AllocationPool, error)
- func (allocationPoolController *AllocationPoolController) ListAll() ([]v1models.AllocationPool, error)
- type BuildController
- func (bc *BuildController) CreateNew(newBuild CreateBuildRequest) (v1models.Build, error)
- func (bc *BuildController) GetByID(id int) (v1models.Build, error)
- func (bc *BuildController) GetByVersionString(versionString string) (v1models.Build, error)
- func (bc *BuildController) ListAll() ([]v1models.Build, error)
- func (bc *BuildController) Serialize(builds ...v1models.Build) []v1serializers.BuildResponse
- type ClusterController
- func (clusterController *ClusterController) CreateNew(newCluster v1models.CreateClusterRequest) (v1models.Cluster, error)
- func (clusterController ClusterController) DoesClusterExist(name string) (id int, ok bool)
- func (clusterController *ClusterController) FindOrCreate(name string) (int, error)
- func (clusterController *ClusterController) GetByID(id int) (v1models.Cluster, error)
- func (clusterController *ClusterController) GetByName(name string) (v1models.Cluster, error)
- func (clusterController *ClusterController) ListAll() ([]v1models.Cluster, error)
- type CreateBuildRequest
- type CreateDeployRequest
- type CreateServiceInstanceRequest
- type DeployController
- func (dc *DeployController) CreateNew(newDeployRequest CreateDeployRequest) (v1models.Deploy, error)
- func (dc *DeployController) GetDeploysByEnvironmentAndService(environmentName, serviceName string) ([]v1models.Deploy, error)
- func (dc *DeployController) GetMostRecentDeploy(environmentName, serviceName string) (v1models.Deploy, error)
- func (dc *DeployController) ListServiceInstances() ([]v1models.ServiceInstance, error)
- func (dc *DeployController) Serialize(deploy ...v1models.Deploy) []v1serializers.DeployResponse
- type EnvironmentController
- func (environmentController *EnvironmentController) CreateNew(newEnvironment v1models.CreateEnvironmentRequest) (v1models.Environment, error)
- func (environmentController EnvironmentController) DoesEnvironmentExist(name string) (id int, ok bool)
- func (environmentController *EnvironmentController) FindOrCreate(name string) (int, error)
- func (environmentController *EnvironmentController) GetByID(ID int) (v1models.Environment, error)
- func (environmentController *EnvironmentController) GetByName(name string) (v1models.Environment, error)
- func (environmentController *EnvironmentController) ListAll() ([]v1models.Environment, error)
- func (environmentController *EnvironmentController) Serialize(environments ...v1models.Environment) []v1serializers.EnvironmentResponse
- type MockEnvironmentStore
- func (m *MockEnvironmentStore) CreateNew(newEnvironment v1models.CreateEnvironmentRequest) (v1models.Environment, error)
- func (m *MockEnvironmentStore) GetByID(id int) (v1models.Environment, error)
- func (m *MockEnvironmentStore) GetByName(name string) (v1models.Environment, error)
- func (m *MockEnvironmentStore) ListAll() ([]v1models.Environment, error)
- type MockServiceInstanceStore
- func (m *MockServiceInstanceStore) CreateNew(clusterID, serviceID, environmentID int) (v1models.ServiceInstance, error)
- func (m *MockServiceInstanceStore) GetByEnvironmentAndServiceID(environmentID, serviceID int) (v1models.ServiceInstance, error)
- func (m *MockServiceInstanceStore) ListAll() ([]v1models.ServiceInstance, error)
- func (m *MockServiceInstanceStore) Reload(serviceInstance v1models.ServiceInstance, reloadCluster bool, ...) (v1models.ServiceInstance, error)
- type MockServiceStore
- type Response
- type ServiceController
- func (sc *ServiceController) CreateNew(newService v1models.CreateServiceRequest) (v1models.Service, error)
- func (sc *ServiceController) DoesServiceExist(name string) (id int, ok bool)
- func (sc *ServiceController) FindOrCreate(name string) (int, error)
- func (sc *ServiceController) GetByName(name string) (v1models.Service, error)
- func (sc *ServiceController) ListAll() ([]v1models.Service, error)
- func (sc *ServiceController) Serialize(services ...v1models.Service) []v1serializers.ServiceResponse
- type ServiceInstanceController
- func (sic *ServiceInstanceController) CreateNew(newServiceInstance CreateServiceInstanceRequest) (v1models.ServiceInstance, error)
- func (sic *ServiceInstanceController) FindOrCreate(environmentName, serviceName string) (int, error)
- func (sic *ServiceInstanceController) GetByEnvironmentAndServiceName(environmentName, serviceName string) (v1models.ServiceInstance, error)
- func (sic *ServiceInstanceController) ListAll() ([]v1models.ServiceInstance, error)
- func (sic *ServiceInstanceController) Reload(serviceInstance v1models.ServiceInstance, reloadCluster bool, ...) (v1models.ServiceInstance, error)
- func (sic *ServiceInstanceController) Serialize(serviceInstances ...v1models.ServiceInstance) []v1serializers.ServiceInstanceResponse
- type TestApplication
Constants ¶
This section is empty.
Variables ¶
var ( // ErrServiceMismatch is an error returned when creating a deploy where the build and service instance // reference different service entities. ErrServiceMismatch = errors.New("service referenced by build and service instance do not match") )
Functions ¶
This section is empty.
Types ¶
type AllocationPoolController ¶
type AllocationPoolController struct {
// contains filtered or unexported fields
}
AllocationPoolController is the management layer for AllocationPools
func NewAllocationPoolController ¶
func NewAllocationPoolController(dbConn *gorm.DB) *AllocationPoolController
NewAllocationPoolController accepts a gorm DB connection and returns a new instance of the allocationPool controller
func (*AllocationPoolController) AddEnvironmentByID ¶
func (allocationPoolController *AllocationPoolController) AddEnvironmentByID(currentAllocationPool v1models.AllocationPool, environmentID int) (v1models.AllocationPool, error)
AddEnvironmentByID takes a AllocationPoolObject and associates an existing environment to it.
func (*AllocationPoolController) CreateNew ¶
func (allocationPoolController *AllocationPoolController) CreateNew(newAllocationPool v1models.CreateAllocationPoolRequest) (v1models.AllocationPool, error)
CreateNew is the public api on the allocationPoolController for persisting a new service entity to the data store
func (AllocationPoolController) DoesAllocationPoolExist ¶
func (allocationPoolController AllocationPoolController) DoesAllocationPoolExist(name string) (int, bool)
DoesAllocationPoolExist is a helper method to check if a allocationPool with the given name already exists in sherlock's data storage
func (*AllocationPoolController) GetByID ¶
func (allocationPoolController *AllocationPoolController) GetByID(id int) (v1models.AllocationPool, error)
GetByID is the public API for looking up a allocationPool from the data store by name
func (*AllocationPoolController) GetByName ¶
func (allocationPoolController *AllocationPoolController) GetByName(name string) (v1models.AllocationPool, error)
GetByName is the public API for looking up a allocationPool from the data store by name
func (*AllocationPoolController) ListAll ¶
func (allocationPoolController *AllocationPoolController) ListAll() ([]v1models.AllocationPool, error)
ListAll is the public api for listing out all AllocationPools tracked by sherlock
type BuildController ¶
type BuildController struct { Store v1models.BuildStore // this is needed so that we can automatically create a new service entity // if a build is reported for a service not tracked by sherlock Services *ServiceController }
BuildController is the management layer that processes requests to the /Builds api group
func NewBuildController ¶
func NewBuildController(dbConn *gorm.DB) *BuildController
NewBuildController returns an instance of the controller struct for interacting with build entities. It embeds a buildStore interface for operations on the build persistence layer
func (*BuildController) CreateNew ¶
func (bc *BuildController) CreateNew(newBuild CreateBuildRequest) (v1models.Build, error)
CreateNew is the Public API on the build controller for saving a new build entity to persistent storage
func (*BuildController) GetByID ¶
func (bc *BuildController) GetByID(id int) (v1models.Build, error)
GetByID is the public api on the build controller for performing a lookup of a build entity by ID
func (*BuildController) GetByVersionString ¶
func (bc *BuildController) GetByVersionString(versionString string) (v1models.Build, error)
GetByVersionString will perform a look up of a build entity using it's unique version string ie image repo + tag
func (*BuildController) ListAll ¶
func (bc *BuildController) ListAll() ([]v1models.Build, error)
ListAll is the public API on the build controller for listing out all Builds
func (*BuildController) Serialize ¶
func (bc *BuildController) Serialize(builds ...v1models.Build) []v1serializers.BuildResponse
type ClusterController ¶
type ClusterController struct {
// contains filtered or unexported fields
}
ClusterController is the management layer for Clusters
func NewClusterController ¶
func NewClusterController(dbConn *gorm.DB) *ClusterController
NewClusterController accepts a gorm DB connection and returns a new instance of the cluster controller
func (*ClusterController) CreateNew ¶
func (clusterController *ClusterController) CreateNew(newCluster v1models.CreateClusterRequest) (v1models.Cluster, error)
CreateNew is the public api on the clusterController for persisting a new service entity to the data store
func (ClusterController) DoesClusterExist ¶
func (clusterController ClusterController) DoesClusterExist(name string) (id int, ok bool)
DoesClusterExist is a helper method to check if a cluster with the given name already exists in sherlock's data storage
func (*ClusterController) FindOrCreate ¶
func (clusterController *ClusterController) FindOrCreate(name string) (int, error)
FindOrCreate will attempt to look an cluster by name and return its ID if successful if unsuccessful it will create a new cluster from the provider name and return that id
func (*ClusterController) GetByID ¶
func (clusterController *ClusterController) GetByID(id int) (v1models.Cluster, error)
GetByID is the public API for looking up a cluster from the data store by name
type CreateBuildRequest ¶
type CreateBuildRequest struct { VersionString string `json:"version_string" binding:"required"` CommitSha string `json:"commit_sha" binding:"required"` BuildURL string `json:"build_url,omitempty"` BuiltAt time.Time `json:"built_at,omitempty"` ServiceName string `json:"service_name" binding:"required"` ServiceRepo string `json:"service_repo"` }
CreateBuildRequest is the type used to validate a request for a new build
type CreateDeployRequest ¶
type CreateDeployRequest struct { EnvironmentName string ServiceName string BuildVersionString string }
CreateDeployRequest is a struct used to contain all the information that is necessary to provision a new deploy
type CreateServiceInstanceRequest ¶
type CreateServiceInstanceRequest struct { EnvironmentName string ServiceName string ClusterName string }
CreateServiceInstanceRequest is a type containing the name of an environment and service that sherlock uses to create a new association between the two.
type DeployController ¶
type DeployController struct { ServiceInstances *ServiceInstanceController Builds *BuildController // contains filtered or unexported fields }
DeployController is a type used to contain all the top level functionality for managing Deploy entities.
func NewDeployController ¶
func NewDeployController(dbConn *gorm.DB) *DeployController
NewDeployController accepts a gorm db connection and returns a controller struct used for the management of deploy entities
func (*DeployController) CreateNew ¶
func (dc *DeployController) CreateNew(newDeployRequest CreateDeployRequest) (v1models.Deploy, error)
CreateNew is used to create a new deploy based on a service name, environment name and build version string
func (*DeployController) GetDeploysByEnvironmentAndService ¶
func (dc *DeployController) GetDeploysByEnvironmentAndService(environmentName, serviceName string) ([]v1models.Deploy, error)
GetDeploysByEnvironmentAndService will retrieve the deploy history for a given service instance with the associated names
func (*DeployController) GetMostRecentDeploy ¶
func (dc *DeployController) GetMostRecentDeploy(environmentName, serviceName string) (v1models.Deploy, error)
GetMostRecentDeploy will look up the most recent ie currently active deploy for a given service instance
func (*DeployController) ListServiceInstances ¶
func (dc *DeployController) ListServiceInstances() ([]v1models.ServiceInstance, error)
func (*DeployController) Serialize ¶
func (dc *DeployController) Serialize(deploy ...v1models.Deploy) []v1serializers.DeployResponse
Serialize takes a variable number of deploy entities and serializes them into types suitable for use in client responses
type EnvironmentController ¶
type EnvironmentController struct {
// contains filtered or unexported fields
}
EnvironmentController is the management layer for environments
func NewEnvironmentController ¶
func NewEnvironmentController(dbConn *gorm.DB) *EnvironmentController
NewEnvironmentController accepts a gorm DB connection and returns a new instance of the environment controller
func NewEnvironmentMockController ¶
func NewEnvironmentMockController(mockStore *MockEnvironmentStore) *EnvironmentController
NewEnvironmentMockController returns an EnvironmentController instance with the provided mock of the storage layer for use in unit tests
func (*EnvironmentController) CreateNew ¶
func (environmentController *EnvironmentController) CreateNew(newEnvironment v1models.CreateEnvironmentRequest) (v1models.Environment, error)
CreateNew is the public api on the environmentController for persisting a new service entity to the data store
func (EnvironmentController) DoesEnvironmentExist ¶
func (environmentController EnvironmentController) DoesEnvironmentExist(name string) (id int, ok bool)
DoesEnvironmentExist is a helper method to check if a environment with the given name already exists in sherlock's data storage
func (*EnvironmentController) FindOrCreate ¶
func (environmentController *EnvironmentController) FindOrCreate(name string) (int, error)
FindOrCreate will attempt to look an environment by name and return its ID if successful if unsuccessful it will create a new environment from the provider name and return that id
func (*EnvironmentController) GetByID ¶
func (environmentController *EnvironmentController) GetByID(ID int) (v1models.Environment, error)
GetByName is the public API for looking up a environment from the data store by name
func (*EnvironmentController) GetByName ¶
func (environmentController *EnvironmentController) GetByName(name string) (v1models.Environment, error)
GetByName is the public API for looking up a environment from the data store by name
func (*EnvironmentController) ListAll ¶
func (environmentController *EnvironmentController) ListAll() ([]v1models.Environment, error)
ListAll is the public api for listing out all environments tracked by sherlock
func (*EnvironmentController) Serialize ¶
func (environmentController *EnvironmentController) Serialize(environments ...v1models.Environment) []v1serializers.EnvironmentResponse
Takes an GORM Environment object and returns a JSON for environment
type MockEnvironmentStore ¶
MockEnvironmentStore is a concrete type that implements environmentStore interface for use in unit tests
func (*MockEnvironmentStore) CreateNew ¶
func (m *MockEnvironmentStore) CreateNew(newEnvironment v1models.CreateEnvironmentRequest) (v1models.Environment, error)
func (*MockEnvironmentStore) GetByID ¶
func (m *MockEnvironmentStore) GetByID(id int) (v1models.Environment, error)
func (*MockEnvironmentStore) GetByName ¶
func (m *MockEnvironmentStore) GetByName(name string) (v1models.Environment, error)
func (*MockEnvironmentStore) ListAll ¶
func (m *MockEnvironmentStore) ListAll() ([]v1models.Environment, error)
type MockServiceInstanceStore ¶
MockServiceInstanceStore is a concrete type that implements serviceInstanceStore interface for use in unit tests
func (*MockServiceInstanceStore) CreateNew ¶
func (m *MockServiceInstanceStore) CreateNew(clusterID, serviceID, environmentID int) (v1models.ServiceInstance, error)
func (*MockServiceInstanceStore) GetByEnvironmentAndServiceID ¶
func (m *MockServiceInstanceStore) GetByEnvironmentAndServiceID(environmentID, serviceID int) (v1models.ServiceInstance, error)
func (*MockServiceInstanceStore) ListAll ¶
func (m *MockServiceInstanceStore) ListAll() ([]v1models.ServiceInstance, error)
func (*MockServiceInstanceStore) Reload ¶
func (m *MockServiceInstanceStore) Reload(serviceInstance v1models.ServiceInstance, reloadCluster bool, reloadEnvironment bool, reloadService bool) (v1models.ServiceInstance, error)
type MockServiceStore ¶
MockServiceStore is used for mocking underlying database operations for services in unit tests
func (*MockServiceStore) CreateNew ¶
func (m *MockServiceStore) CreateNew(newService v1models.CreateServiceRequest) (v1models.Service, error)
type Response ¶
type Response struct { Environments []v1serializers.EnvironmentResponse `json:"environments"` Error string `json:"error,omitempty"` }
Response is a type that allows all data returned from the /environment api group to share a consistent structure
type ServiceController ¶
type ServiceController struct {
Store v1models.ServiceStore
}
ServiceController is the management layer for CRUD operations for service entities
func NewServiceController ¶
func NewServiceController(dbConn *gorm.DB) *ServiceController
NewServiceController accepts a gorm DB connection and returns a new instance of the service controller
func NewServiceMockController ¶
func NewServiceMockController(mockStore *MockServiceStore) *ServiceController
NewServiceMockController returns a service controller that will use a customizable mock store for use in tests in other packages
func (*ServiceController) CreateNew ¶
func (sc *ServiceController) CreateNew(newService v1models.CreateServiceRequest) (v1models.Service, error)
CreateNew is the public api on the serviceController for persisting a new service entity to the data store
func (*ServiceController) DoesServiceExist ¶
func (sc *ServiceController) DoesServiceExist(name string) (id int, ok bool)
DoesServiceExist is a helper method to check if a service with the given name already exists in sherlock's data storage
func (*ServiceController) FindOrCreate ¶
func (sc *ServiceController) FindOrCreate(name string) (int, error)
FindOrCreate will attempt to look an environment by name and return its ID if successful if unsuccessful it will create a new environment from the provider name and return that id
func (*ServiceController) GetByName ¶
func (sc *ServiceController) GetByName(name string) (v1models.Service, error)
GetByName is the public API for looking up a service from the data store by name
func (*ServiceController) ListAll ¶
func (sc *ServiceController) ListAll() ([]v1models.Service, error)
ListAll is the public api for listing out all services tracked by sherlock
func (*ServiceController) Serialize ¶
func (sc *ServiceController) Serialize(services ...v1models.Service) []v1serializers.ServiceResponse
type ServiceInstanceController ¶
type ServiceInstanceController struct {
// contains filtered or unexported fields
}
ServiceInstanceController is the type used to manage logic related to working with ServiceInstance entities
func NewServiceInstanceController ¶
func NewServiceInstanceController(dbConn *gorm.DB) *ServiceInstanceController
NewServiceInstanceController expects a gorm.DB connection and will provision a new controller instance
func NewServiceInstanceMockController ¶
func NewServiceInstanceMockController(mockStore *MockServiceInstanceStore) *ServiceInstanceController
NewServiceInstanceMockController returns an EnvironmentController instance with the provided mock of the storage layer for use in unit tests
func (*ServiceInstanceController) CreateNew ¶
func (sic *ServiceInstanceController) CreateNew(newServiceInstance CreateServiceInstanceRequest) (v1models.ServiceInstance, error)
CreateNew accepts the name of an environment and a service. It will perform find or create operations for both and their create an association between them
func (*ServiceInstanceController) FindOrCreate ¶
func (sic *ServiceInstanceController) FindOrCreate(environmentName, serviceName string) (int, error)
FindOrCreate will check if a service instance with the given name and environment already exists if so it returns the id. If not it will create it and then return the id
func (*ServiceInstanceController) GetByEnvironmentAndServiceName ¶
func (sic *ServiceInstanceController) GetByEnvironmentAndServiceName(environmentName, serviceName string) (v1models.ServiceInstance, error)
GetByEnvironmentAndServiceName accepts environment and service names as strings and will return the Service_Instance entity representing the association between them if it exists
func (*ServiceInstanceController) ListAll ¶
func (sic *ServiceInstanceController) ListAll() ([]v1models.ServiceInstance, error)
ListAll retrieves all service_instance entities from the backing data store
func (*ServiceInstanceController) Reload ¶
func (sic *ServiceInstanceController) Reload(serviceInstance v1models.ServiceInstance, reloadCluster bool, reloadEnvironment bool, reloadService bool) (v1models.ServiceInstance, error)
Reload reloads a serviceInstance from the DB, optionally loading related Cluster/Environment/Service objects along with it.
func (*ServiceInstanceController) Serialize ¶
func (sic *ServiceInstanceController) Serialize(serviceInstances ...v1models.ServiceInstance) []v1serializers.ServiceInstanceResponse
Serialize takes a variable number of service instance entities and serializes them into types suitable for use in client responses
type TestApplication ¶
type TestApplication struct { AllocationPools *AllocationPoolController Builds *BuildController Clusters *ClusterController Deploys *DeployController Environments *EnvironmentController ServiceInstances *ServiceInstanceController Services *ServiceController DB *gorm.DB }
TestApplication is a simplified sherlock.Application that avoids circular dependencies or unneeded fields for testing. Fields exported for the benefit of tests coupled to the v1controllers package.