setup
This commit is contained in:
parent
ec7a7e4746
commit
29bc21735d
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -15,6 +16,10 @@ import (
|
||||
*/
|
||||
type Booking struct {
|
||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||
|
||||
ResumeMetrics map[string]map[string]models.MetricResume `json:"resume_metrics,omitempty" bson:"resume_metrics,omitempty"`
|
||||
ExecutionMetrics map[string][]models.MetricsSnapshot `json:"metrics,omitempty" bson:"metrics,omitempty"`
|
||||
|
||||
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty" validate:"required"` // ExecutionsID is the ID of the executions
|
||||
DestPeerID string `json:"dest_peer_id,omitempty"` // DestPeerID is the ID of the destination peer
|
||||
WorkflowID string `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
|
||||
@ -30,6 +35,33 @@ type Booking struct {
|
||||
ResourceID string `json:"resource_id,omitempty" bson:"resource_id,omitempty" validate:"required"` // could be a Compute or a Storage
|
||||
}
|
||||
|
||||
func (b *Booking) CalcDeltaOfExecution() map[string]map[string]models.MetricResume {
|
||||
m := map[string]map[string]models.MetricResume{}
|
||||
for instance, snapshot := range b.ExecutionMetrics {
|
||||
m[instance] = map[string]models.MetricResume{}
|
||||
for _, metric := range snapshot {
|
||||
for _, mm := range metric.Metrics {
|
||||
if resume, ok := m[instance][mm.Name]; !ok {
|
||||
m[instance][mm.Name] = models.MetricResume{
|
||||
Delta: 0,
|
||||
LastValue: mm.Value,
|
||||
}
|
||||
} else {
|
||||
delta := resume.LastValue - mm.Value
|
||||
if delta == 0 {
|
||||
resume.Delta = delta
|
||||
} else {
|
||||
resume.Delta = (resume.Delta + delta) / 2
|
||||
}
|
||||
resume.LastValue = mm.Value
|
||||
m[instance][mm.Name] = resume
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CheckBooking checks if a booking is possible on a specific compute resource
|
||||
func (wfa *Booking) Check(id string, start time.Time, end *time.Time, parrallelAllowed int) (bool, error) {
|
||||
// check if
|
||||
|
17
models/common/models/metric.go
Normal file
17
models/common/models/metric.go
Normal file
@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
type MetricsSnapshot struct {
|
||||
From string `json:"origin"`
|
||||
Metrics []Metric `json:"metrics"`
|
||||
}
|
||||
|
||||
type Metric struct {
|
||||
Name string `json:"name"`
|
||||
Value float64 `json:"value"`
|
||||
Error error `json:"error"`
|
||||
}
|
||||
|
||||
type MetricResume struct {
|
||||
Delta float64 `json:"delta"`
|
||||
LastValue float64 `json:"last_value"`
|
||||
}
|
0
models/common/planner.go
Normal file → Executable file
0
models/common/planner.go
Normal file → Executable file
Loading…
Reference in New Issue
Block a user