1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2 KiB
Go

2 years ago
package database
import (
"time"
"git.phc.dm.unipi.it/phc/cluster-dashboard/backend/executor"
"git.phc.dm.unipi.it/phc/cluster-dashboard/backend/model"
"golang.org/x/exp/maps"
2 years ago
)
// simpleDB è una implementazione di [database.Database] che tiene giusto una cache in memoria e
// quando il server viene riavviato perde tutte le statistiche che ha accumulato. Più avanti si
// potrebbe pensare di scrivere queste informazioni in un file o usare un vero database.
type simpleDB struct {
Executor executor.Service
// lastUpdate tiene traccia di quando abbiamo aggiornato l'ultima volta tutti i dati
lastUpdate *time.Time
// Nodes is a map from hostname to node info
nodes map[string]*model.Node
2 years ago
// Jobs is a map from job id to job info
jobs map[string]*model.Job
2 years ago
// The following are maps from hostname to a list of sampled temperatures, used memory, used storage space and network upload and download rate.
temperatureSamples map[string][]model.Sample[float64]
memorySamples map[string][]model.Sample[int64]
storageSamples map[string][]model.Sample[int64]
networkUploadSamples map[string][]model.Sample[int64]
networkDownloadSamples map[string][]model.Sample[int64]
}
func NewSimpleDatabase(ex executor.Service) Database {
return &simpleDB{Executor: ex}
}
func (s *simpleDB) GetNode(hostname string) (*model.Node, error) {
2 years ago
panic("todo")
}
func (s *simpleDB) GetJob(id string) (*model.Job, error) {
2 years ago
panic("todo")
}
func (s *simpleDB) AllNodes() ([]*model.Node, error) {
return maps.Values(s.nodes), nil
2 years ago
}
func (s *simpleDB) AllJobs() ([]*model.Job, error) {
return maps.Values(s.jobs), nil
2 years ago
}
func (s *simpleDB) QueryTemperatureSamples(from, to time.Time) ([]model.Sample[float64], error) {
panic("todo")
}
func (s *simpleDB) QueryMemorySamples(from, to time.Time) ([]model.Sample[int64], error) {
panic("todo")
}
func (s *simpleDB) QueryStorageSamples(from, to time.Time) ([]model.Sample[int64], error) {
panic("todo")
}
func (s *simpleDB) QueryNetworkUploadSamples(from, to time.Time) ([]model.Sample[int64], error) {
panic("todo")
}
func (s *simpleDB) QueryNetworkDownloadSamples(from, to time.Time) ([]model.Sample[int64], error) {
panic("todo")
}