diff --git a/backend/database/mem.go b/backend/database/mem.go index 88a4447..1e36b38 100644 --- a/backend/database/mem.go +++ b/backend/database/mem.go @@ -1,11 +1,11 @@ package database import ( + "math/rand" "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 @@ -37,37 +37,121 @@ func NewSimpleDatabase(ex executor.Service) Database { } func (s *simpleDB) GetNode(hostname string) (*model.Node, error) { - panic("todo") + return &model.Node{ + Hostname: hostname, + StartTime: time.Now().Add(-1 * time.Hour), + }, nil } func (s *simpleDB) GetJob(id string) (*model.Job, error) { - panic("todo") + return &model.Job{ + Id: id, + Name: "example-job", + Status: "active", + Nodes: []string{"node-1", "node-2"}, + Resources: []string{}, + }, nil } func (s *simpleDB) AllNodes() ([]*model.Node, error) { - return maps.Values(s.nodes), nil + return []*model.Node{ + { + Hostname: "node-1", + StartTime: time.Now().Add(-1 * time.Hour), + }, + { + Hostname: "node-2", + StartTime: time.Now().Add(-1 * time.Hour), + }, + { + Hostname: "node-3", + StartTime: time.Now().Add(-1 * time.Hour), + }, + }, nil } func (s *simpleDB) AllJobs() ([]*model.Job, error) { - return maps.Values(s.jobs), nil + return []*model.Job{ + { + Id: "job-1", + Name: "example-job", + Status: "active", + Nodes: []string{"node-1", "node-2"}, + Resources: []string{}, + }, + { + Id: "job-2", + Name: "example-job", + Status: "active", + Nodes: []string{"node-1", "node-2"}, + Resources: []string{}, + }, + { + Id: "job-3", + Name: "example-job", + Status: "active", + Nodes: []string{"node-1", "node-2"}, + Resources: []string{}, + }, + { + Id: "job-4", + Name: "example-job", + Status: "active", + Nodes: []string{"node-1", "node-2"}, + Resources: []string{}, + }, + { + Id: "job-5", + Name: "example-job", + Status: "active", + Nodes: []string{"node-1", "node-2"}, + Resources: []string{}, + }, + }, nil } func (s *simpleDB) QueryTemperatureSamples(from, to time.Time) ([]model.Sample[float64], error) { - panic("todo") + return generateFakeFloat64Samples(100), nil } func (s *simpleDB) QueryMemorySamples(from, to time.Time) ([]model.Sample[int64], error) { - panic("todo") + return generateFakeInt64Samples(100), nil } func (s *simpleDB) QueryStorageSamples(from, to time.Time) ([]model.Sample[int64], error) { - panic("todo") + return generateFakeInt64Samples(100), nil } func (s *simpleDB) QueryNetworkUploadSamples(from, to time.Time) ([]model.Sample[int64], error) { - panic("todo") + return generateFakeInt64Samples(100), nil } func (s *simpleDB) QueryNetworkDownloadSamples(from, to time.Time) ([]model.Sample[int64], error) { - panic("todo") + return generateFakeInt64Samples(100), nil +} + +func generateFakeFloat64Samples(amount int) []model.Sample[float64] { + fakeSamples := make([]model.Sample[float64], amount) + + for i := range fakeSamples { + fakeSamples[i] = model.Sample[float64]{ + Timestamp: time.Now().Add(time.Duration(i-amount) * time.Second), + Value: rand.Float64(), + } + } + + return fakeSamples +} + +func generateFakeInt64Samples(amount int) []model.Sample[int64] { + fakeSamples := make([]model.Sample[int64], amount) + + for i := range fakeSamples { + fakeSamples[i] = model.Sample[int64]{ + Timestamp: time.Now().Add(time.Duration(i-amount) * time.Second), + Value: rand.Int63n(1000), + } + } + + return fakeSamples } diff --git a/frontend/index.html b/frontend/index.html index 0df5b7e..fbac936 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -25,111 +25,6 @@
- -