light modification
This commit is contained in:
15
models/common/enum/infrastructure.go
Normal file
15
models/common/enum/infrastructure.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package enum
|
||||
|
||||
type InfrastructureType int
|
||||
|
||||
const (
|
||||
DOCKER InfrastructureType = iota
|
||||
KUBERNETES
|
||||
SLURM
|
||||
HW
|
||||
CONDOR
|
||||
)
|
||||
|
||||
func (t InfrastructureType) String() string {
|
||||
return [...]string{"DOCKER", "KUBERNETES", "SLURM", "HW", "CONDOR"}[t]
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package common
|
||||
package enum
|
||||
|
||||
type ScheduledType int
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package common
|
||||
package enum
|
||||
|
||||
type StorageSize int
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package common
|
||||
package models
|
||||
|
||||
type Container struct {
|
||||
Image string `json:"image,omitempty" bson:"image,omitempty"` // Image is the container image TEMPO
|
@@ -1,4 +1,4 @@
|
||||
package common
|
||||
package models
|
||||
|
||||
// CPU is a struct that represents a CPU
|
||||
type CPU struct {
|
||||
@@ -18,17 +18,3 @@ type GPU struct {
|
||||
MemoryGb float64 `bson:"memory,omitempty" json:"memory,omitempty" description:"Units in MB"`
|
||||
Cores map[string]int `bson:"cores,omitempty" json:"cores,omitempty"`
|
||||
}
|
||||
|
||||
type InfrastructureType int
|
||||
|
||||
const (
|
||||
DOCKER InfrastructureType = iota
|
||||
KUBERNETES
|
||||
SLURM
|
||||
HW
|
||||
CONDOR
|
||||
)
|
||||
|
||||
func (t InfrastructureType) String() string {
|
||||
return [...]string{"DOCKER", "KUBERNETES", "SLURM", "HW", "CONDOR"}[t]
|
||||
}
|
42
models/common/planner.go
Normal file
42
models/common/planner.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
func GetPlannerNearestStart(start time.Time, planned map[tools.DataType][]pricing.PricedItemITF, request *tools.APIRequest) float64 {
|
||||
near := float64(10000000000) // set a high value
|
||||
for _, items := range planned { // loop through the planned items
|
||||
for _, priced := range items { // loop through the priced items
|
||||
if priced.GetLocationStart() == nil { // if the start is nil,
|
||||
continue // skip the iteration
|
||||
}
|
||||
newS := priced.GetLocationStart() // get the start
|
||||
if newS.Sub(start).Seconds() < near { // if the difference between the start and the new start is less than the nearest start
|
||||
near = newS.Sub(start).Seconds()
|
||||
}
|
||||
}
|
||||
}
|
||||
return near
|
||||
}
|
||||
|
||||
func GetPlannerLongestTime(end *time.Time, planned map[tools.DataType][]pricing.PricedItemITF, request *tools.APIRequest) float64 {
|
||||
if end == nil {
|
||||
return -1
|
||||
}
|
||||
longestTime := float64(0)
|
||||
for _, priced := range planned[tools.PROCESSING_RESOURCE] {
|
||||
if priced.GetLocationEnd() == nil {
|
||||
continue
|
||||
}
|
||||
newS := priced.GetLocationEnd()
|
||||
if longestTime < newS.Sub(*end).Seconds() {
|
||||
longestTime = newS.Sub(*end).Seconds()
|
||||
}
|
||||
// get the nearest start from start var
|
||||
}
|
||||
return longestTime
|
||||
}
|
Reference in New Issue
Block a user