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/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
"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/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
@ -14,14 +15,18 @@ import (
|
|||||||
* Booking is a struct that represents a booking
|
* Booking is a struct that represents a booking
|
||||||
*/
|
*/
|
||||||
type Booking struct {
|
type Booking struct {
|
||||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||||
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
|
ResumeMetrics map[string]map[string]models.MetricResume `json:"resume_metrics,omitempty" bson:"resume_metrics,omitempty"`
|
||||||
WorkflowID string `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
|
ExecutionMetrics map[string][]models.MetricsSnapshot `json:"metrics,omitempty" bson:"metrics,omitempty"`
|
||||||
ExecutionID string `json:"execution_id,omitempty" bson:"execution_id,omitempty" validate:"required"`
|
|
||||||
State enum.BookingStatus `json:"state,omitempty" bson:"state,omitempty" validate:"required"` // State is the state of the booking
|
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty" validate:"required"` // ExecutionsID is the ID of the executions
|
||||||
ExpectedStartDate time.Time `json:"expected_start_date,omitempty" bson:"expected_start_date,omitempty" validate:"required"` // ExpectedStartDate is the expected start date of the booking
|
DestPeerID string `json:"dest_peer_id,omitempty"` // DestPeerID is the ID of the destination peer
|
||||||
ExpectedEndDate *time.Time `json:"expected_end_date,omitempty" bson:"expected_end_date,omitempty" validate:"required"` // ExpectedEndDate is the expected end date of the booking
|
WorkflowID string `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
|
||||||
|
ExecutionID string `json:"execution_id,omitempty" bson:"execution_id,omitempty" validate:"required"`
|
||||||
|
State enum.BookingStatus `json:"state,omitempty" bson:"state,omitempty" validate:"required"` // State is the state of the booking
|
||||||
|
ExpectedStartDate time.Time `json:"expected_start_date,omitempty" bson:"expected_start_date,omitempty" validate:"required"` // ExpectedStartDate is the expected start date of the booking
|
||||||
|
ExpectedEndDate *time.Time `json:"expected_end_date,omitempty" bson:"expected_end_date,omitempty" validate:"required"` // ExpectedEndDate is the expected end date of the booking
|
||||||
|
|
||||||
RealStartDate *time.Time `json:"real_start_date,omitempty" bson:"real_start_date,omitempty"` // RealStartDate is the real start date of the booking
|
RealStartDate *time.Time `json:"real_start_date,omitempty" bson:"real_start_date,omitempty"` // RealStartDate is the real start date of the booking
|
||||||
RealEndDate *time.Time `json:"real_end_date,omitempty" bson:"real_end_date,omitempty"` // RealEndDate is the real end date of the booking
|
RealEndDate *time.Time `json:"real_end_date,omitempty" bson:"real_end_date,omitempty"` // RealEndDate is the real end date of the booking
|
||||||
@ -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
|
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
|
// 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) {
|
func (wfa *Booking) Check(id string, start time.Time, end *time.Time, parrallelAllowed int) (bool, error) {
|
||||||
// check if
|
// 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