dbManager

package
v0.0.0-...-33e56a9 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbParameter

type DbParameter struct {
	Db      *gorm.DB
	Metrics map[string]*prometheus.GaugeVec
	// contains filtered or unexported fields
}

DbParameter is the struct defined to group and contain all the methods that interact with the database. On it there is the following parameters: - connStr: strings with the connection information to the database - Db: a gorm.DB pointer to the db to invoke all the db methods

func New

func New(dbConn string, tables ...interface{}) *DbParameter

New is the function to create the struct DbParameter. Parameters: - dbConn: strings with the connection information to the database - tables: array of interfaces that will contains the models to migrate to the database on initialization Returns: - DbParameter: struct to interact with dbManager functionalities

func (*DbParameter) AddEvent

func (d *DbParameter) AddEvent(event models.Event) (e error)

AddEvent job is to register the new event on its corresponding resource state. Parameters: - event: a reference containing the new event in the resource. Returns: - e: error raised in case of problems

func (*DbParameter) AddToHistory

func (d *DbParameter) AddToHistory(state models.State) (e error)

AddToHistory job is to archive the provided state as a new event in the history of changes linked to the state provided. Parameters: - state: State to be archived as a new event in the history of changes of the State. Returns: - e: error raised in case of problems

func (*DbParameter) DatesWithin

func (d *DbParameter) DatesWithin(EventFrom, EventTo, TimeFrom, TimeTo int64) (inc int, diff int64)

DatesWithin job is to check whether the analized time-window overlaps or not, reporting how this happens and how much overlapping exists. Parameters: - EventFrom: int representing the start of the interval for the event. - EventTp: int representing the end of the interval for the event. - TimeFrom: int representing the start of the time-window. - TimeTo: int representing the end of the time-window. Returns: - inc: const(int) representing the state of the time-window vs the interval. - diff: int representing the region of overlapping between both time-windows.

func (*DbParameter) GetAllHistory

func (d *DbParameter) GetAllHistory(ac string, u models.Use) ([]*models.Event, error)

GetAllHistory job is to retrieve the complete history of changes in the state of the provided resource linked to the given account. Parameters: - ac: string representing the ID of the account to be processed. - u: Use reference used as the pattern to match the specific state needed. Returns: - slice of Event containing the changes in the history of the provided account. - error raised in case of problems

func (*DbParameter) GetAllStates

func (d *DbParameter) GetAllStates() ([]*models.State, error)

GetAllStates job is to retrieve a snapshot of all the states present in the system at the time of invokation- Returns: - slice of States containing all the resources state in the system - error raised in case of problems

func (*DbParameter) GetHistory

func (d *DbParameter) GetHistory(ac, ty, rg string, from, to int64) ([]*models.Event, error)

GetHistory job is to retrieve the history of changes in the state of the provided account during the given time-window, with the posibility of filter the result by the type of resource. Parameters: - ac: string representing the ID of the account to be processed. - ty: string representing the resource type to use as filter - rg: string representing the resource region to use as filter - from: int representing the start of the time-window. - to: int representing the end of the time-window. Returns: - slice of Event containing the changes in the history of the provided account. - error raised in case of problems

func (*DbParameter) GetState

func (d *DbParameter) GetState(ac string) ([]*models.State, error)

GetState job is to retrieve the actual state of every resource linked to the provided account. Parameters: - ac: string representing the ID of the account to be processed. Returns: - slice of State containing the states kept in the system of the resources linked to the provided account - error raised in case of problems

func (*DbParameter) GetSystemUsage

func (d *DbParameter) GetSystemUsage(from, to int64, ty, rg string) ([]*models.Usage, error)

GetSystemUsage job is to compute the usage accumulated in the whole system by account considering the time in the actual state and the history of changes that the account resources have had during the provided time-window, with the posibility of filtering by resource type. Parameters: - from: int representing the start of the time-window. - to: int representing the end of the time-window. - ty: string representing the resource type to use as filter - rg: string representing the resource region to use as filter Returns: - slice of Usages containing the usage per account in the system in the provided time-window. - error raised in case of problems

func (*DbParameter) GetUsage

func (d *DbParameter) GetUsage(ac, ty, rg string, from, to int64) (*models.Usage, error)

GetUsage job is to compute the usage accumulated by the provided account considering the time in the actual state and the history of changes that the account resources have had during the provided time-window, with the posibility of filtering by resource type. Parameters: - ac: string representing the ID of the account to be processed. - ty: string representing the resource type to use as filter - rg: string representing the resource region to use as filter - from: int representing the start of the time-window. - to: int representing the end of the time-window. Returns: - Usage reference containing the usage of the account in the system in the provided time-window. - error raised in case of problems

func (*DbParameter) ListState

func (d *DbParameter) ListState(metric, region string) ([]*models.MinimalState, error)

ListState job is to retrieve the list of not terminated states in the system for the requested region and resource type.. Parameters: - metric - region Returns: - slice of State containing the states kept in the system. - error raised in case of problems

func (*DbParameter) UpdateStates

func (d *DbParameter) UpdateStates(states []*models.State, pattern models.State) error

UpdateStates job is to process the provided states given a pattern, ranging through the given states, records the change in the history of the state and then updates the state with in the system according to the pattern. Parameters: - states: slice of State to be updated in the system. - pattern: a State reference containing the changes to be done previous to the update in the system. Returns: - error raised in case of problems

Jump to

Keyboard shortcuts

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