From 76d83878ebd335237788a657dd10ff0979d9afd4 Mon Sep 17 00:00:00 2001 From: pb Date: Wed, 30 Jul 2025 18:01:23 +0200 Subject: [PATCH] added a method to workflow which allows to retrieve items by resource type and resource id --- models/workflow/workflow.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/models/workflow/workflow.go b/models/workflow/workflow.go index 71f0a1f..b9f456b 100644 --- a/models/workflow/workflow.go +++ b/models/workflow/workflow.go @@ -227,6 +227,27 @@ func (wf *Workflow) Planify(start time.Time, end *time.Time, request *tools.APIR return longest, priceds, wf, nil } +func (w *Workflow) GetItemsByResources() (res map[tools.DataType]map[string][]string) { + dtMethodMap := map[tools.DataType]func() []graph.GraphItem{ + tools.STORAGE_RESOURCE: func() []graph.GraphItem { return w.GetGraphItems(w.Graph.IsStorage) }, + tools.DATA_RESOURCE: func() []graph.GraphItem { return w.GetGraphItems(w.Graph.IsData) }, + tools.COMPUTE_RESOURCE: func() []graph.GraphItem { return w.GetGraphItems(w.Graph.IsCompute) }, + tools.PROCESSING_RESOURCE: func() []graph.GraphItem { return w.GetGraphItems(w.Graph.IsProcessing) }, + tools.WORKFLOW_RESOURCE: func() []graph.GraphItem { return w.GetGraphItems(w.Graph.IsWorkflow) }, + } + + for dt, meth := range dtMethodMap { + items := meth() + for _, i := range items { + _, r := i.GetResource() + rId := r.GetID() + res[dt][rId] = append(res[dt][rId],i.ID) + } + } + + return +} + func plan[T resources.ResourceInterface]( dt tools.DataType, wf *Workflow, priceds map[tools.DataType]map[string]pricing.PricedItemITF, request *tools.APIRequest, f func(graph.GraphItem) bool, start func(resources.ResourceInterface, pricing.PricedItemITF) (time.Time, float64), end func(time.Time, float64) *time.Time) ([]T, map[tools.DataType]map[string]pricing.PricedItemITF, error) {