From 73fd3295519b103fd15ee7d5d65181c82008692c Mon Sep 17 00:00:00 2001 From: pb Date: Thu, 16 May 2024 14:18:06 +0200 Subject: [PATCH] computings components connected to one another --- argo_builder.go | 90 +++++++++++++++++++++++-------------------------- graph.go | 3 +- 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/argo_builder.go b/argo_builder.go index f828497..686aeca 100644 --- a/argo_builder.go +++ b/argo_builder.go @@ -47,7 +47,7 @@ func (b *ArgoBuilder) CreateDAG() bool { b.Workflow.ApiVersion = "argoproj.io/v1alpha1" b.Workflow.Kind = "Workflow" - b.Workflow.Metadata.GenerateName = "oc-test-" + generateName() + b.Workflow.Metadata.GenerateName = "oc-test-" + generateWfName() yamlified, err := yaml.Marshal(b.Workflow) @@ -55,7 +55,7 @@ func (b *ArgoBuilder) CreateDAG() bool { logs.Error("Could not transform object to yaml file") return false } - fmt.Println(string(yamlified)) + err = os.WriteFile("argo.yml", []byte(yamlified), 0660) if err != nil { logs.Error("Could not write the yaml file") @@ -67,8 +67,8 @@ func (b *ArgoBuilder) CreateDAG() bool { func (b *ArgoBuilder) createTemplates() { for _, comp := range b.graph.Computings{ - image_name := strings.Split(comp.Command," ")[0] - temp_container := Container{Image: image_name} // TODO : edit computing model to store the container name:version + image_name := strings.Split(comp.Command," ")[0] // TODO : decide where to store the image name, GUI or models.computing.Image + temp_container := Container{Image: image_name} // TODO : decide where to store the image name, GUI or models.computing.Image temp_container.Command = getComputingCommands(comp.Command) temp_container.Args = getComputingArgs(comp.Arguments,comp.Command) input_names := getComputingEnvironmentName(comp.Environment) @@ -101,16 +101,10 @@ func (b *ArgoBuilder) createDAGstep() { step.Arguments.Parameters = append(step.Arguments.Parameters, Parameter{Name: name, Value: value}) } - // For each branch, check if the computing has a dependency - for _, branch := range b.branches { - if b.componentInBranch(comp.ID,branch) { - // retrieves the name (computing.name-computing.ID) - dependency := b.getDependency(comp.ID,branch) - if dependency != "" && !slices.Contains(step.Dependencies,dependency) { - step.Dependencies = append(step.Dependencies,dependency) - } - } - } + + // retrieves the name (computing.name-computing.ID) + step.Dependencies = b.getDependency(comp.ID) + new_dag.Tasks = append(new_dag.Tasks, step) } @@ -129,50 +123,50 @@ func (b *ArgoBuilder) createVolumes() { b.Workflow.Spec.Volumes = append(b.Workflow.Spec.Volumes, new_volume) } -func (b *ArgoBuilder) getDependency(current_computing_id string, branch []string) string { - - for i := len(branch)-1; i >= 0 ; i-- { - current_link := b.graph.Links[branch[i]] - current_computing_found := false +func (b *ArgoBuilder) getDependency(current_computing_id string) (dependencies []string) { + var dependencies_id []string - if current_link.Source == current_computing_id || current_link.Destination == current_computing_id { - current_computing_found = true - } - if current_computing_found { - return b.findPreviousComputing(current_computing_id,branch,i-1) + for _, link := range b.graph.Links { + if current_computing_id == link.Destination && b.graph.getComponentType(link.Source) == "computing" && !slices.Contains(dependencies_id,link.Source) { + dependencies_id = append(dependencies_id, link.Source) } } - return "" + for _, dependency := range dependencies_id { + dependency_name := getArgoName(b.graph.getComponentName(dependency),dependency) + dependencies = append(dependencies, dependency_name) + } + + return } -func (b *ArgoBuilder) componentInBranch(component_id string, branch []string) bool { - for _, link := range branch { - if b.graph.Links[link].Source == component_id || b.graph.Links[link].Destination == component_id { - return true - } - } - return false -} +// func (b *ArgoBuilder) componentInBranch(component_id string, branch []string) bool { +// for _, link := range branch { +// if b.graph.Links[link].Source == component_id || b.graph.Links[link].Destination == component_id { +// return true +// } +// } +// return false +// } -func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string, index int) string { +// func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string, index int) string { - for i := index; i >= 0 ; i-- { - previousLink := b.graph.Links[branch[i]] +// for i := index; i >= 0 ; i-- { +// previousLink := b.graph.Links[branch[i]] - if previousLink.Source != computing_id && b.graph.getComponentType(previousLink.Source) == "computing"{ - name := getArgoName(b.graph.getComponentName(previousLink.Source),previousLink.Source) - return name - } - if previousLink.Destination != computing_id && b.graph.getComponentType(previousLink.Destination) == "computing"{ - name := getArgoName(b.graph.getComponentName(previousLink.Destination),previousLink.Destination) - return name - } +// if previousLink.Source != computing_id && b.graph.getComponentType(previousLink.Source) == "computing"{ +// name := getArgoName(b.graph.getComponentName(previousLink.Source),previousLink.Source) +// return name +// } +// if previousLink.Destination != computing_id && b.graph.getComponentType(previousLink.Destination) == "computing"{ +// name := getArgoName(b.graph.getComponentName(previousLink.Destination),previousLink.Destination) +// return name +// } - } - return "" -} +// } +// return "" +// } func getComputingCommands(user_input string) (list_command []string) { user_input = removeImageName(user_input) @@ -240,7 +234,7 @@ func getComputingEnvironmentName(user_input []string) (list_names []string){ return } -func generateName() (Name string){ +func generateWfName() (Name string){ Name = fakelish.GenerateFakeWord(5, 8) + "-" + fakelish.GenerateFakeWord(5, 8) return } diff --git a/graph.go b/graph.go index bb3f895..0648a58 100644 --- a/graph.go +++ b/graph.go @@ -193,6 +193,7 @@ func (g *Graph) ExportToArgo(id string) error { // Return a list containing the IDs of each link that make up a branch in the graph func (g *Graph) getListBranches(end_links map[string]models.Link, unvisited_links_list map[string]models.Link, current_branch []string) (list_branches [][]string) { + if current_branch == nil { current_branch = make([]string, 0) } @@ -296,7 +297,7 @@ func (g *Graph) getComponentName(id string) string { return "" } - +// returns either computing, data or storage func (g *Graph) getComponentType(component_id string) string { for _, comp := range g.Computings { if comp.ID == component_id{