simplify processing check up

This commit is contained in:
mr 2024-08-29 09:34:10 +02:00
parent 3cb536d2e3
commit 6e732e3eac
3 changed files with 11 additions and 14 deletions

Binary file not shown.

View File

@ -7,20 +7,22 @@ package workflow_builder
import ( import (
. "oc-monitord/models" . "oc-monitord/models"
"os" "os"
"slices"
"strings" "strings"
"time" "time"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/models/resource_model" "cloud.o-forge.io/core/oc-lib/models/resource_model"
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph" "cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
w "cloud.o-forge.io/core/oc-lib/models/workflow"
"github.com/nwtgck/go-fakelish" "github.com/nwtgck/go-fakelish"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
type ArgoBuilder struct { type ArgoBuilder struct {
graph graph.Graph OriginWorkflow w.Workflow
Workflow Workflow Workflow Workflow
Timeout int Timeout int
} }
type Workflow struct { type Workflow struct {
@ -137,11 +139,11 @@ func (b *ArgoBuilder) createVolumes() {
} }
func (b *ArgoBuilder) getDependency(current_computing_id string) (dependencies []string) { func (b *ArgoBuilder) getDependency(current_computing_id string) (dependencies []string) {
for _, link := range b.graph.Links { for _, link := range b.OriginWorkflow.Graph.Links {
if !b.IsProcessing(link.Source.ID) || !b.IsProcessing(link.Destination.ID) { if !b.IsProcessing(link.Source.ID) {
continue continue
} }
source := b.graph.Items[link.Source.ID].Processing source := b.OriginWorkflow.Graph.Items[link.Source.ID].Processing
if current_computing_id == link.Destination.ID && source != nil { if current_computing_id == link.Destination.ID && source != nil {
dependency_name := getArgoName(source.GetName(), link.Source.ID) dependency_name := getArgoName(source.GetName(), link.Source.ID)
dependencies = append(dependencies, dependency_name) dependencies = append(dependencies, dependency_name)
@ -239,7 +241,7 @@ func removeImageName(user_input string) string {
// Return the graphItem containing a Processing resource, so that we have access to the ID of the graphItem in order to identify it in the links // Return the graphItem containing a Processing resource, so that we have access to the ID of the graphItem in order to identify it in the links
func (b *ArgoBuilder) getProcessings() (list_computings []graph.GraphItem) { func (b *ArgoBuilder) getProcessings() (list_computings []graph.GraphItem) {
for _, item := range b.graph.Items { for _, item := range b.OriginWorkflow.Graph.Items {
if item.Processing != nil { if item.Processing != nil {
list_computings = append(list_computings, item) list_computings = append(list_computings, item)
} }
@ -248,12 +250,7 @@ func (b *ArgoBuilder) getProcessings() (list_computings []graph.GraphItem) {
} }
func (b *ArgoBuilder) IsProcessing(id string) bool { func (b *ArgoBuilder) IsProcessing(id string) bool {
for _, item := range b.graph.Items { return slices.Contains(b.OriginWorkflow.Processings, id)
if item.Processing != nil && item.Processing.GetID() == id {
return true
}
}
return false
} }
func getStringValue(comp resource_model.AbstractResource, key string) string { func getStringValue(comp resource_model.AbstractResource, key string) string {

View File

@ -46,7 +46,7 @@ func (w *WorflowDB) ExportToArgo(timeout int) (string, error) {
return "", fmt.Errorf("can't export a graph that has not been loaded yet") return "", fmt.Errorf("can't export a graph that has not been loaded yet")
} }
argo_builder := ArgoBuilder{graph: *w.Workflow.Graph, Timeout: timeout} argo_builder := ArgoBuilder{OriginWorkflow: *w.Workflow, Timeout: timeout}
filename, err := argo_builder.CreateDAG() filename, err := argo_builder.CreateDAG()
if err != nil { if err != nil {
logger.Error().Msg("Could not create the argo file for " + w.Workflow.Name) logger.Error().Msg("Could not create the argo file for " + w.Workflow.Name)