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" ) // 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 // Jobs is a map from job id to job info jobs map[string]*model.Job // 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) { panic("todo") } func (s *simpleDB) GetJob(id string) (*model.Job, error) { panic("todo") } func (s *simpleDB) AllNodes() ([]*model.Node, error) { return maps.Values(s.nodes), nil } func (s *simpleDB) AllJobs() ([]*model.Job, error) { return maps.Values(s.jobs), nil } 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") }