Documentation ¶
Overview ¶
Package storage contains an implementation of interface between Go code and (almost any) SQL database like PostgreSQL, SQLite, or MariaDB. An implementation named DBStorage is constructed via New function and it is mandatory to call Close for any opened connection to database.
Index ¶
- Variables
- func ColNames(cols ...ClusterCol) []string
- type Cluster
- type ClusterCol
- type ClusterConfiguration
- type ClusterConfigurationID
- type ClusterID
- type ClusterName
- type ClusterQuery
- type ClusterQueryBuilder
- type Cols
- type Column
- type ConfigurationID
- type ConfigurationProfile
- type ID
- type ItemNotFoundError
- type Name
- type SearchClusterRequest
- type Storage
- func (storage Storage) AckTrigger(clusterName string, triggerID int64) error
- func (storage Storage) ChangeConfigurationProfile(id int, username, description, configuration string) ([]ConfigurationProfile, error)
- func (storage Storage) ChangeStateOfTriggerByID(id int64, active int) error
- func (storage Storage) Close()
- func (storage Storage) Connections() *sql.DB
- func (storage Storage) CreateClusterConfiguration(cluster, username, reason, description, configuration string) ([]ClusterConfiguration, error)
- func (storage Storage) CreateNewCluster(id int64, name string) error
- func (storage Storage) DeactivatePreviousConfigurations(tx *sql.Tx, clusterID ClusterID) error
- func (storage Storage) DeleteCluster(id int64) error
- func (storage Storage) DeleteClusterByName(name string) error
- func (storage Storage) DeleteClusterConfigurationByID(id int64) error
- func (storage Storage) DeleteConfigurationProfile(id int) ([]ConfigurationProfile, error)
- func (storage Storage) DeleteTriggerByID(id int64) error
- func (storage Storage) DisableClusterConfiguration(cluster, username, reason string) ([]ClusterConfiguration, error)
- func (storage Storage) EnableClusterConfiguration(cluster, username, reason string) ([]ClusterConfiguration, error)
- func (storage Storage) EnableOrDisableClusterConfigurationByID(id int64, active string) error
- func (storage Storage) GetCluster(id int) (Cluster, error)
- func (storage Storage) GetClusterActiveConfiguration(cluster string) (string, error)
- func (storage Storage) GetClusterByName(name string) (Cluster, error)
- func (storage Storage) GetClusterConfigurationByID(id int64) (string, error)
- func (storage Storage) GetConfigurationIDForCluster(cluster string) (int, error)
- func (storage Storage) GetConfigurationProfile(id int) (ConfigurationProfile, error)
- func (storage Storage) GetTriggerByID(id int64) (Trigger, error)
- func (storage Storage) GetTriggerID(triggerType string) (int, error)
- func (storage Storage) InsertNewConfigurationProfile(tx *sql.Tx, configuration, username, description string) bool
- func (storage Storage) InsertNewOperatorConfiguration(tx *sql.Tx, clusterID ClusterID, configurationID int, username, reason string) error
- func (storage Storage) ListActiveClusterTriggers(clusterName string) ([]Trigger, error)
- func (storage Storage) ListAllClusterConfigurations() ([]ClusterConfiguration, error)
- func (storage Storage) ListAllTriggers() ([]Trigger, error)
- func (storage Storage) ListClusterConfiguration(cluster string) ([]ClusterConfiguration, error)
- func (storage Storage) ListClusterTriggers(clusterName string) ([]Trigger, error)
- func (storage Storage) ListConfigurationProfiles() ([]ConfigurationProfile, error)
- func (storage Storage) ListOfClusters() ([]Cluster, error)
- func (storage Storage) Map(cols []Column, mapper func(Column, interface{}) (interface{}, error), ...) ([]interface{}, error)
- func (storage Storage) NewTrigger(clusterName, triggerType, userName, reason, link string) error
- func (storage Storage) NewTriggerType(ttype, description string) error
- func (storage Storage) Ping() error
- func (storage Storage) Placeholder() sq.PlaceholderFormat
- func (storage Storage) QueryOne(ctx context.Context, selectCols []Column, selectBuilder sq.SelectBuilder, ...) error
- func (storage Storage) RegisterNewCluster(name string) error
- func (storage Storage) SelectConfigurationProfileID(tx *sql.Tx) (int, error)
- func (storage Storage) StoreConfigurationProfile(username, description, configuration string) ([]ConfigurationProfile, error)
- type Storager
- type Trigger
- type TriggerID
Constants ¶
This section is empty.
Variables ¶
var ErrNoSuchObj = fmt.Errorf("no such object")
ErrNoSuchObj is indicating no result returned from db
var ErrUnknown = fmt.Errorf("unknown error during querying db")
ErrUnknown indicates db query failed without details (QueryRow returning Row wasn't populated)
Functions ¶
func ColNames ¶
func ColNames(cols ...ClusterCol) []string
ColNames Creates a list fo string column names from list of typed ClusterCols
Types ¶
type Cluster ¶
type Cluster struct { ID ClusterID `json:"id"` Name ClusterName `json:"name"` }
Cluster represents cluster record in the controller service.
ID: unique key Name: cluster GUID in the following format: c8590f31-e97e-4b85-b506-c45ce1911a12
type ClusterConfiguration ¶
type ClusterConfiguration struct { ID ClusterConfigurationID `json:"id"` Cluster string `json:"cluster"` Configuration string `json:"configuration"` ChangedAt string `json:"changed_at"` ChangedBy string `json:"changed_by"` Active string `json:"active"` Reason string `json:"reason"` }
ClusterConfiguration represents cluster configuration record in the controller service.
ID: unique key Cluster: cluster ID (not name) Configuration: a JSON structure stored in a string ChangeAt: timestamp of the last configuration change ChangeBy: username of admin that created or updated the configuration Active: flag indicating whether the configuration is active or not Reason: a string with any comment(s) about the cluster configuration
type ClusterConfigurationID ¶
type ClusterConfigurationID ID
ClusterConfigurationID represents unique key of cluster configuration stored in database.
type ClusterName ¶
type ClusterName Name
ClusterName represents name of cluster in format c8590f31-e97e-4b85-b506-c45ce1911a12
type ClusterQuery ¶
ClusterQuery is Sql query model for Cluster
func NewClusterQuery ¶
func NewClusterQuery(s Storager) *ClusterQuery
NewClusterQuery creates new ClusterQuery Sql model
func (*ClusterQuery) Map ¶
func (c *ClusterQuery) Map(cols []ClusterCol, r *Cluster) ([]interface{}, error)
Map creates a list of destination struct fields using columns to select
func (*ClusterQuery) Query ¶
func (c *ClusterQuery) Query() ClusterQueryBuilder
Query exposes typed Cluster queryBuilder
func (*ClusterQuery) QueryOne ¶
func (c *ClusterQuery) QueryOne(ctx context.Context, req SearchClusterRequest) (*Cluster, error)
QueryOne will query DB with generated command and return one row as Cluster
type ClusterQueryBuilder ¶
type ClusterQueryBuilder struct {
// contains filtered or unexported fields
}
ClusterQueryBuilder is just a typed wrapped to build queries more conviniently using only exposed methods
func (ClusterQueryBuilder) Equals ¶
func (b ClusterQueryBuilder) Equals(col ClusterCol, v interface{}) ClusterQueryBuilder
Equals add a SQL Where Predicate using AND (if any exists) using Equals (=) operand. Ignores Zero values in values For example: WHERE col = 3
func (ClusterQueryBuilder) WithPaging ¶
func (b ClusterQueryBuilder) WithPaging(limit, offset int) ClusterQueryBuilder
WithPaging is setting how many recors (limit) and from which record (offset) This can be used for paging. It skips Zero values
type Cols ¶
type Cols struct { ID ClusterCol Name ClusterCol }
Cols defines which columns exist in Clusters table, just for tyoe safe operations with them
type Column ¶
type Column string
Column is typed reference to a sql column, which is further used by particular storage objects
type ConfigurationID ¶
type ConfigurationID ID
ConfigurationID represents unique key of configuration stored in database.
type ConfigurationProfile ¶
type ConfigurationProfile struct { ID ConfigurationID `json:"id"` Configuration string `json:"configuration"` ChangedAt string `json:"changed_at"` ChangedBy string `json:"changed_by"` Description string `json:"description"` }
ConfigurationProfile represents configuration profile record in the controller service.
ID: unique key Configuration: a JSON structure stored in a string ChangeAt: username of admin that created or updated the configuration ChangeBy: timestamp of the last configuration change Description: a string with any comment(s) about the configuration
type ItemNotFoundError ¶
type ItemNotFoundError struct {
ItemID interface{}
}
ItemNotFoundError shows that item with provided ItemID wasn't found in storage
func (*ItemNotFoundError) Error ¶
func (e *ItemNotFoundError) Error() string
type SearchClusterRequest ¶
type SearchClusterRequest struct { utils.Pagination ID int `schema:"id"` Name string `schema:"name"` }
SearchClusterRequest defines type safe SearchCluster request, it is reused and defines request validation tags
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage represents an interface to any relational database based on SQL language
func NewFromConnection ¶
NewFromConnection function creates and initializes a new instance of Storage interface from prepared connection
func (Storage) AckTrigger ¶
AckTrigger sets a timestamp to the selected trigger + updates the 'active' flag. and returns error if trigger wasn't found
func (Storage) ChangeConfigurationProfile ¶
func (storage Storage) ChangeConfigurationProfile(id int, username, description, configuration string) ([]ConfigurationProfile, error)
ChangeConfigurationProfile updates the existing configuration profile specified by its ID.
func (Storage) ChangeStateOfTriggerByID ¶
ChangeStateOfTriggerByID change the state ('active', 'inactive') of trigger specified by its ID. returns ItemNotFoundError if there weren't rows with such id
func (Storage) Close ¶
func (storage Storage) Close()
Close method closes the connection to database. Needs to be called at the end of application lifecycle.
func (Storage) Connections ¶
Connections is sql.DB connection
func (Storage) CreateClusterConfiguration ¶
func (storage Storage) CreateClusterConfiguration(cluster, username, reason, description, configuration string) ([]ClusterConfiguration, error)
CreateClusterConfiguration creates new configuration for specified cluster.
func (Storage) CreateNewCluster ¶
CreateNewCluster creates a new cluster with specified ID and name. It differs from RegisterNewCluster, because ID is specified explicitly here.
func (Storage) DeactivatePreviousConfigurations ¶
DeactivatePreviousConfigurations deactivate all previous configurations for the specified trigger. To be called inside transaction.
func (Storage) DeleteCluster ¶
DeleteCluster deletes cluster with specified ID from the database.
func (Storage) DeleteClusterByName ¶
DeleteClusterByName deletes cluster with specified name from the database.
func (Storage) DeleteClusterConfigurationByID ¶
DeleteClusterConfigurationByID deletes cluster configuration specified by its ID. TODO: copy & paste, needs to be refactored later
func (Storage) DeleteConfigurationProfile ¶
func (storage Storage) DeleteConfigurationProfile(id int) ([]ConfigurationProfile, error)
DeleteConfigurationProfile deletes a configuration profile specified by its name.
func (Storage) DeleteTriggerByID ¶
DeleteTriggerByID deletes trigger specified by its ID returns ItemNotFoundError if trigger didn't exist
func (Storage) DisableClusterConfiguration ¶
func (storage Storage) DisableClusterConfiguration(cluster, username, reason string) ([]ClusterConfiguration, error)
DisableClusterConfiguration disables the specified cluster configuration (reset the 'active' flag). TODO: copy & paste, needs to be refactored later
func (Storage) EnableClusterConfiguration ¶
func (storage Storage) EnableClusterConfiguration(cluster, username, reason string) ([]ClusterConfiguration, error)
EnableClusterConfiguration enables the specified cluster configuration (set the 'active' flag).
func (Storage) EnableOrDisableClusterConfigurationByID ¶
EnableOrDisableClusterConfigurationByID enables or disables the specified cluster configuration (set or reset the 'active' flag). Please see also EnableClusterConfiguration and DisableClusterConfiguration
func (Storage) GetCluster ¶
GetCluster method selects the specified cluster from database. Also see GetClusterByName.
func (Storage) GetClusterActiveConfiguration ¶
GetClusterActiveConfiguration reads one active configuration for the selected cluster.
func (Storage) GetClusterByName ¶
GetClusterByName selects a cluster specified by its name. Also see GetCluster.
func (Storage) GetClusterConfigurationByID ¶
GetClusterConfigurationByID reads cluster configuration for the specified configuration ID.
func (Storage) GetConfigurationIDForCluster ¶
GetConfigurationIDForCluster reads the ID for the specified cluster name.
func (Storage) GetConfigurationProfile ¶
func (storage Storage) GetConfigurationProfile(id int) (ConfigurationProfile, error)
GetConfigurationProfile selects one configuration profile identified by its ID.
func (Storage) GetTriggerByID ¶
GetTriggerByID selects all informations about the trigger specified by its ID.
func (Storage) GetTriggerID ¶
GetTriggerID select ID for specified trigger type (name).
func (Storage) InsertNewConfigurationProfile ¶
func (storage Storage) InsertNewConfigurationProfile(tx *sql.Tx, configuration, username, description string) bool
InsertNewConfigurationProfile inserts new configuration profile into a database (in transaction).
func (Storage) InsertNewOperatorConfiguration ¶
func (storage Storage) InsertNewOperatorConfiguration(tx *sql.Tx, clusterID ClusterID, configurationID int, username, reason string) error
InsertNewOperatorConfiguration inserts the new configuration for selected operator/cluster. To be called inside transaction.
func (Storage) ListActiveClusterTriggers ¶
ListActiveClusterTriggers selects all active triggers assigned to the specified cluster.
func (Storage) ListAllClusterConfigurations ¶
func (storage Storage) ListAllClusterConfigurations() ([]ClusterConfiguration, error)
ListAllClusterConfigurations selects all cluster configurations from the database.
func (Storage) ListAllTriggers ¶
ListAllTriggers selects all triggers from the database.
func (Storage) ListClusterConfiguration ¶
func (storage Storage) ListClusterConfiguration(cluster string) ([]ClusterConfiguration, error)
ListClusterConfiguration selects cluster configuration from the database for the specified cluster.
func (Storage) ListClusterTriggers ¶
ListClusterTriggers selects all triggers assigned to the specified cluster.
func (Storage) ListConfigurationProfiles ¶
func (storage Storage) ListConfigurationProfiles() ([]ConfigurationProfile, error)
ListConfigurationProfiles selects list of all configuration profiles from database.
func (Storage) ListOfClusters ¶
ListOfClusters method selects all clusters from database.
func (Storage) Map ¶
func (storage Storage) Map(cols []Column, mapper func(Column, interface{}) (interface{}, error), r interface{}) ([]interface{}, error)
Map creates a list of destination struct fields using columns to select
func (Storage) NewTrigger ¶
NewTrigger constructs new trigger in a database.
func (Storage) NewTriggerType ¶
NewTriggerType inserts a trigger_type object in the database
func (Storage) Placeholder ¶
func (storage Storage) Placeholder() sq.PlaceholderFormat
Placeholder returns current query argument placeholder (?, or $).It depends on driver used. In squirrel format
func (Storage) QueryOne ¶
func (storage Storage) QueryOne(ctx context.Context, selectCols []Column, selectBuilder sq.SelectBuilder, mapper func(Column, interface{}) (interface{}, error), res interface{}) error
QueryOne is generating Sql query using squirell sql builder, querying it with db store and mapping result to destination object with provided mapper
func (Storage) RegisterNewCluster ¶
RegisterNewCluster inserts information about new cluster into the database. It differs from CreateNewCluster, because ID is not specified explicitly here.
func (Storage) SelectConfigurationProfileID ¶
SelectConfigurationProfileID selects the ID of lately inserted/created configuration profile. To be used in transaction.
func (Storage) StoreConfigurationProfile ¶
func (storage Storage) StoreConfigurationProfile(username, description, configuration string) ([]ConfigurationProfile, error)
StoreConfigurationProfile stores a given configuration profile (string ATM) into the database.
type Storager ¶
type Storager interface { Connections() *sql.DB Placeholder() sq.PlaceholderFormat QueryOne(context.Context, []Column, sq.SelectBuilder, func(Column, interface{}) (interface{}, error), interface{}) error }
Storager exposes interface for testing
type Trigger ¶
type Trigger struct { ID TriggerID `json:"id"` Type string `json:"type"` Cluster string `json:"cluster"` Reason string `json:"reason"` Link string `json:"link"` TriggeredAt string `json:"triggered_at"` TriggeredBy string `json:"triggered_by"` AckedAt string `json:"acked_at"` Parameters string `json:"parameters"` Active int `json:"active"` }
Trigger represents trigger record in the controller service
ID: unique key Type: ID of trigger type Cluster: cluster ID (not name) Reason: a string with any comment(s) about the trigger Link: link to any document with customer ACK with the trigger TriggeredAt: timestamp of the last configuration change TriggeredBy: username of admin that created or updated the trigger AckedAt: timestamp where the insights operator acked the trigger Parameters: parameters that needs to be pass to trigger code Active: flag indicating whether the trigger is still active or not