db

package
v0.0.0-...-81a4f0c Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostgresDriverName = "postgres"
	MysqlDriverName    = "mysql"
	PolicyDb           = "policy_db"
	BindingDb          = "binding_db"
	StoredProcedureDb  = "storedprocedure_db"
)
View Source
const (
	DESCSTR string = "DESC"
	ASCSTR  string = "ASC"
)

Variables

View Source
var ErrAlreadyExists = fmt.Errorf("already exists")
View Source
var ErrConflict = fmt.Errorf("conflicting entry exists")
View Source
var ErrDoesNotExist = fmt.Errorf("doesn't exist")

Functions

This section is empty.

Types

type AppMetricDB

type AppMetricDB interface {
	DatabaseStatus
	SaveAppMetric(appMetric *models.AppMetric) error
	SaveAppMetricsInBulk(metrics []*models.AppMetric) error
	RetrieveAppMetrics(appId string, metricType string, start int64, end int64, orderType OrderType) ([]*models.AppMetric, error)
	PruneAppMetrics(before int64) error
	Close() error
}

type BindingDB

type BindingDB interface {
	DatabaseStatus
	CreateServiceInstance(serviceInstance models.ServiceInstance) error
	GetServiceInstance(serviceInstanceId string) (*models.ServiceInstance, error)
	GetServiceInstanceByAppId(appId string) (*models.ServiceInstance, error)
	UpdateServiceInstance(serviceInstance models.ServiceInstance) error
	DeleteServiceInstance(serviceInstanceId string) error
	CreateServiceBinding(bindingId string, serviceInstanceId string, appId string) error
	DeleteServiceBinding(bindingId string) error
	DeleteServiceBindingByAppId(appId string) error
	CheckServiceBinding(appId string) bool
	GetAppIdByBindingId(bindingId string) (string, error)
	GetAppIdsByInstanceId(instanceId string) ([]string, error)
	CountServiceInstancesInOrg(orgId string) (int, error)
	GetBindingIdsByInstanceId(instanceId string) ([]string, error)
	Close() error
}

type Database

type Database struct {
	DriverName string
	DSN        string
}

func GetConnection

func GetConnection(dbUrl string) (*Database, error)

*

This function is used to generate db connection info, for example,
For mysql:
input dbUrl: 'username:password@tcp(localhost:3306)/autoscaler?tls=custom&sslrootcert=db_ca.crt'
  return:
  &Database{DriverName: "mysql", DSN:"username:password@tcp(localhost:3306)/autoscaler?parseTime=true&tls=custom"}

For postgres:

  input dbUrl: postgres://postgres:password@localhost:5432/autoscaler?sslmode=disable
  return:
  &Database{DriverName: "postgres", DSN:"postgres://postgres:password@localhost:5432/autoscaler?sslmode=disable"
*

type DatabaseConfig

type DatabaseConfig struct {
	URL                   string        `yaml:"url"`
	MaxOpenConnections    int           `yaml:"max_open_connections"`
	MaxIdleConnections    int           `yaml:"max_idle_connections"`
	ConnectionMaxLifetime time.Duration `yaml:"connection_max_lifetime"`
	ConnectionMaxIdleTime time.Duration `yaml:"connection_max_idletime"`
}

type DatabaseStatus

type DatabaseStatus interface {
	GetDBStatus() sql.DBStats
}

type InstanceMetricsDB

type InstanceMetricsDB interface {
	DatabaseStatus
	RetrieveInstanceMetrics(appid string, instanceIndex int, name string, start int64, end int64, orderType OrderType) ([]*models.AppInstanceMetric, error)
	SaveMetric(metric *models.AppInstanceMetric) error
	SaveMetricsInBulk(metrics []*models.AppInstanceMetric) error
	PruneInstanceMetrics(before int64) error
	Close() error
}

type LockDB

type LockDB interface {
	Lock(lock *models.Lock) (bool, error)
	Release(owner string) error
	Close() error
}

type MySQLConfig

type MySQLConfig struct {
	// contains filtered or unexported fields
}

type Name

type Name = string

type OrderType

type OrderType uint8
const (
	DESC OrderType = iota
	ASC
)

type PolicyDB

type PolicyDB interface {
	DatabaseStatus
	GetAppIds() (map[string]bool, error)
	GetAppPolicy(appId string) (*models.ScalingPolicy, error)
	SaveAppPolicy(appId string, policy string, policyGuid string) error
	SetOrUpdateDefaultAppPolicy(appIds []string, oldPolicyGuid string, newPolicy string, newPolicyGuid string) ([]string, error)
	DeletePoliciesByPolicyGuid(policyGuid string) ([]string, error)
	RetrievePolicies() ([]*models.PolicyJson, error)
	Close() error
	DeletePolicy(appId string) error
	SaveCredential(appId string, cred models.Credential) error
	DeleteCredential(appId string) error
	GetCredential(appId string) (*models.Credential, error)
}

type ScalingEngineDB

type ScalingEngineDB interface {
	DatabaseStatus
	SaveScalingHistory(history *models.AppScalingHistory) error
	RetrieveScalingHistories(appId string, start int64, end int64, orderType OrderType, includeAll bool) ([]*models.AppScalingHistory, error)
	PruneScalingHistories(before int64) error
	UpdateScalingCooldownExpireTime(appId string, expireAt int64) error
	CanScaleApp(appId string) (bool, int64, error)
	GetActiveSchedule(appId string) (*models.ActiveSchedule, error)
	GetActiveSchedules() (map[string]string, error)
	SetActiveSchedule(appId string, schedule *models.ActiveSchedule) error
	RemoveActiveSchedule(appId string) error
	Close() error
}

type SchedulerDB

type SchedulerDB interface {
	DatabaseStatus
	GetActiveSchedules() (map[string]*models.ActiveSchedule, error)
	Close() error
}

type StoredProcedureDB

type StoredProcedureDB interface {
	Close() error
	CreateCredentials(credOptions models.CredentialsOptions) (*models.Credential, error)
	DeleteCredentials(credOptions models.CredentialsOptions) error
	DeleteAllInstanceCredentials(instanceId string) error
	ValidateCredentials(creds models.Credential) (*models.CredentialsOptions, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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