Workout Time Scheduling
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPlannerNearestStart(start time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF, request *tools.APIRequest) float64 {
|
func GetPlannerNearestStart(start time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF) float64 {
|
||||||
near := float64(-1) // unset sentinel
|
near := float64(-1) // unset sentinel
|
||||||
for _, items := range planned { // loop through the planned items
|
for _, items := range planned { // loop through the planned items
|
||||||
for _, priced := range items { // loop through the priced items
|
for _, priced := range items { // loop through the priced items
|
||||||
@@ -27,7 +27,7 @@ func GetPlannerNearestStart(start time.Time, planned map[tools.DataType]map[stri
|
|||||||
return near
|
return near
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPlannerLongestTime(end *time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF, request *tools.APIRequest) float64 {
|
func GetPlannerLongestTime(end *time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF) float64 {
|
||||||
if end == nil {
|
if end == nil {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ func (abs *PricedResource[T]) GetLocationEnd() *time.Time {
|
|||||||
|
|
||||||
func (abs *PricedResource[T]) GetLocationStart() *time.Time {
|
func (abs *PricedResource[T]) GetLocationStart() *time.Time {
|
||||||
if abs.BookingConfiguration == nil {
|
if abs.BookingConfiguration == nil {
|
||||||
now := time.Now().Add(2 * time.Minute)
|
return nil
|
||||||
return &now
|
|
||||||
}
|
}
|
||||||
return abs.BookingConfiguration.UsageStart
|
return abs.BookingConfiguration.UsageStart
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
@@ -67,46 +65,32 @@ func (wf *Graph) IsWorkflow(item GraphItem) bool {
|
|||||||
return item.Workflow != nil
|
return item.Workflow != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graph) GetAverageTimeRelatedToProcessingActivity(start time.Time, processings []*resources.ProcessingResource, resource resources.ResourceInterface,
|
func (g *Graph) GetAverageTimeRelatedToProcessingActivity(processings []*resources.ProcessingResource, resource resources.ResourceInterface,
|
||||||
f func(GraphItem) resources.ResourceInterface, instance int, partnership int, buying int, strategy int, bookingMode int, request *tools.APIRequest) (float64, float64, error) {
|
f func(GraphItem) resources.ResourceInterface, instance int, partnership int, buying int, strategy int, bookingMode int, request *tools.APIRequest) (float64, float64, error) {
|
||||||
nearestStart := float64(10000000000)
|
|
||||||
oneIsInfinite := false
|
oneIsInfinite := false
|
||||||
longestDuration := float64(0)
|
longestDuration := float64(0)
|
||||||
for _, link := range g.Links {
|
for _, link := range g.Links {
|
||||||
for _, processing := range processings {
|
for _, processing := range processings {
|
||||||
var source string // source is the source of the link
|
if !(link.Destination.ID == processing.GetID() && f(g.Items[link.Source.ID]) != nil && f(g.Items[link.Source.ID]).GetID() == resource.GetID()) &&
|
||||||
if link.Destination.ID == processing.GetID() && f(g.Items[link.Source.ID]) != nil && f(g.Items[link.Source.ID]).GetID() == resource.GetID() { // if the destination is the processing and the source is not a compute
|
!(link.Source.ID == processing.GetID() && f(g.Items[link.Source.ID]) != nil && f(g.Items[link.Source.ID]).GetID() == resource.GetID()) {
|
||||||
source = link.Source.ID
|
continue
|
||||||
} else if link.Source.ID == processing.GetID() && f(g.Items[link.Source.ID]) != nil && f(g.Items[link.Source.ID]).GetID() == resource.GetID() { // if the source is the processing and the destination is not a compute
|
|
||||||
source = link.Destination.ID
|
|
||||||
}
|
}
|
||||||
priced, err := processing.ConvertToPricedResource(tools.PROCESSING_RESOURCE, &instance, &partnership, &buying, &strategy, &bookingMode, request)
|
priced, err := processing.ConvertToPricedResource(tools.PROCESSING_RESOURCE, &instance, &partnership, &buying, &strategy, &bookingMode, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
if source != "" {
|
duration := priced.GetExplicitDurationInS()
|
||||||
if priced.GetLocationStart() != nil {
|
if duration < 0 {
|
||||||
near := float64(priced.GetLocationStart().Sub(start).Seconds())
|
|
||||||
if near < nearestStart {
|
|
||||||
nearestStart = near
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if priced.GetLocationEnd() != nil {
|
|
||||||
duration := float64(priced.GetLocationEnd().Sub(*priced.GetLocationStart()).Seconds())
|
|
||||||
if longestDuration < duration {
|
|
||||||
longestDuration = duration
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
oneIsInfinite = true
|
oneIsInfinite = true
|
||||||
}
|
} else if longestDuration < duration {
|
||||||
|
longestDuration = duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if oneIsInfinite {
|
if oneIsInfinite {
|
||||||
return nearestStart, -1, nil
|
return 0, -1, nil
|
||||||
}
|
}
|
||||||
return nearestStart, longestDuration, nil
|
return 0, longestDuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -155,7 +139,7 @@ func (g *Graph) GetAverageTimeProcessingBeforeStart(average float64, processingI
|
|||||||
|
|
||||||
func (g *Graph) GetResource(id string) (tools.DataType, resources.ResourceInterface) {
|
func (g *Graph) GetResource(id string) (tools.DataType, resources.ResourceInterface) {
|
||||||
if item, ok := g.Items[id]; ok {
|
if item, ok := g.Items[id]; ok {
|
||||||
if item.Data != nil {
|
if item.NativeTool != nil {
|
||||||
return tools.NATIVE_TOOL, item.NativeTool
|
return tools.NATIVE_TOOL, item.NativeTool
|
||||||
} else if item.Data != nil {
|
} else if item.Data != nil {
|
||||||
return tools.DATA_RESOURCE, item.Data
|
return tools.DATA_RESOURCE, item.Data
|
||||||
|
|||||||
@@ -632,7 +632,7 @@ func (wf *Workflow) Planify(start time.Time, end *time.Time, instances ConfigIte
|
|||||||
tools.COMPUTE_RESOURCE: wf.Graph.IsCompute} {
|
tools.COMPUTE_RESOURCE: wf.Graph.IsCompute} {
|
||||||
if _, priceds, err = plan[resources.ResourceInterface](k, instances, partnerships, buyings, strategies, bookingMode, wf, priceds, request,
|
if _, priceds, err = plan[resources.ResourceInterface](k, instances, partnerships, buyings, strategies, bookingMode, wf, priceds, request,
|
||||||
f, func(res resources.ResourceInterface, priced pricing.PricedItemITF) (time.Time, float64, error) {
|
f, func(res resources.ResourceInterface, priced pricing.PricedItemITF) (time.Time, float64, error) {
|
||||||
nearestStart, longestDuration, err := wf.Graph.GetAverageTimeRelatedToProcessingActivity(start, ps, res, func(i graph.GraphItem) (r resources.ResourceInterface) {
|
nearestStart, longestDuration, err := wf.Graph.GetAverageTimeRelatedToProcessingActivity(ps, res, func(i graph.GraphItem) (r resources.ResourceInterface) {
|
||||||
if f(i) {
|
if f(i) {
|
||||||
_, r = i.GetResource()
|
_, r = i.GetResource()
|
||||||
}
|
}
|
||||||
@@ -650,11 +650,11 @@ func (wf *Workflow) Planify(start time.Time, end *time.Time, instances ConfigIte
|
|||||||
return false, 0, priceds, nil, err
|
return false, 0, priceds, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
longest := common.GetPlannerLongestTime(end, priceds, request)
|
longest := common.GetPlannerLongestTime(end, priceds)
|
||||||
if _, priceds, err = plan[resources.ResourceInterface](tools.WORKFLOW_RESOURCE, instances, partnerships, buyings, strategies,
|
if _, priceds, err = plan[resources.ResourceInterface](tools.WORKFLOW_RESOURCE, instances, partnerships, buyings, strategies,
|
||||||
bookingMode, wf, priceds, request, wf.Graph.IsWorkflow,
|
bookingMode, wf, priceds, request, wf.Graph.IsWorkflow,
|
||||||
func(res resources.ResourceInterface, priced pricing.PricedItemITF) (time.Time, float64, error) {
|
func(res resources.ResourceInterface, priced pricing.PricedItemITF) (time.Time, float64, error) {
|
||||||
start := start.Add(time.Duration(common.GetPlannerNearestStart(start, priceds, request)) * time.Second)
|
start := start.Add(time.Duration(common.GetPlannerNearestStart(start, priceds)) * time.Second)
|
||||||
longest := float64(-1)
|
longest := float64(-1)
|
||||||
r, code, err := res.GetAccessor(request).LoadOne(res.GetID())
|
r, code, err := res.GetAccessor(request).LoadOne(res.GetID())
|
||||||
if code != 200 || err != nil {
|
if code != 200 || err != nil {
|
||||||
@@ -678,7 +678,7 @@ func (wf *Workflow) Planify(start time.Time, end *time.Time, instances ConfigIte
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return start.Add(time.Duration(common.GetPlannerNearestStart(start, priceds, request)) * time.Second), longest, nil
|
return start.Add(time.Duration(common.GetPlannerNearestStart(start, priceds)) * time.Second), longest, nil
|
||||||
}, func(start time.Time, longest float64) (*time.Time, error) {
|
}, func(start time.Time, longest float64) (*time.Time, error) {
|
||||||
s := start.Add(time.Duration(longest) * time.Second)
|
s := start.Add(time.Duration(longest) * time.Second)
|
||||||
return &s, nil
|
return &s, nil
|
||||||
@@ -756,9 +756,6 @@ func plan[T resources.ResourceInterface](
|
|||||||
priced.SetLocationEnd(*e)
|
priced.SetLocationEnd(*e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e, err := end(started, priced.GetExplicitDurationInS()); err != nil && e != nil {
|
|
||||||
priced.SetLocationEnd(*e)
|
|
||||||
}
|
|
||||||
resources = append(resources, realItem.(T))
|
resources = append(resources, realItem.(T))
|
||||||
if priceds[dt][item.ID] != nil {
|
if priceds[dt][item.ID] != nil {
|
||||||
priced.AddQuantity(priceds[dt][item.ID].GetQuantity())
|
priced.AddQuantity(priceds[dt][item.ID].GetQuantity())
|
||||||
|
|||||||
Reference in New Issue
Block a user