computings components connected to one another

This commit is contained in:
pb 2024-05-16 14:18:06 +02:00
parent a461f3ba1c
commit 73fd329551
2 changed files with 44 additions and 49 deletions

View File

@ -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 {
func (b *ArgoBuilder) getDependency(current_computing_id string) (dependencies []string) {
var dependencies_id []string
for i := len(branch)-1; i >= 0 ; i-- {
current_link := b.graph.Links[branch[i]]
current_computing_found := false
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 ""
}
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
}
for _, dependency := range dependencies_id {
dependency_name := getArgoName(b.graph.getComponentName(dependency),dependency)
dependencies = append(dependencies, dependency_name)
}
return false
return
}
func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string, index int) string {
// 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
// }
for i := index; i >= 0 ; i-- {
previousLink := b.graph.Links[branch[i]]
// func (b *ArgoBuilder) findPreviousComputing(computing_id string, branch []string, index int) string {
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
}
// for i := index; i >= 0 ; i-- {
// previousLink := b.graph.Links[branch[i]]
}
return ""
}
// 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 ""
// }
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
}

View File

@ -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{