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.ApiVersion = "argoproj.io/v1alpha1"
b.Workflow.Kind = "Workflow" b.Workflow.Kind = "Workflow"
b.Workflow.Metadata.GenerateName = "oc-test-" + generateName() b.Workflow.Metadata.GenerateName = "oc-test-" + generateWfName()
yamlified, err := yaml.Marshal(b.Workflow) yamlified, err := yaml.Marshal(b.Workflow)
@ -55,7 +55,7 @@ func (b *ArgoBuilder) CreateDAG() bool {
logs.Error("Could not transform object to yaml file") logs.Error("Could not transform object to yaml file")
return false return false
} }
fmt.Println(string(yamlified))
err = os.WriteFile("argo.yml", []byte(yamlified), 0660) err = os.WriteFile("argo.yml", []byte(yamlified), 0660)
if err != nil { if err != nil {
logs.Error("Could not write the yaml file") logs.Error("Could not write the yaml file")
@ -67,8 +67,8 @@ func (b *ArgoBuilder) CreateDAG() bool {
func (b *ArgoBuilder) createTemplates() { func (b *ArgoBuilder) createTemplates() {
for _, comp := range b.graph.Computings{ for _, comp := range b.graph.Computings{
image_name := strings.Split(comp.Command," ")[0] 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 : edit computing model to store the container name:version 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.Command = getComputingCommands(comp.Command)
temp_container.Args = getComputingArgs(comp.Arguments,comp.Command) temp_container.Args = getComputingArgs(comp.Arguments,comp.Command)
input_names := getComputingEnvironmentName(comp.Environment) 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}) 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) // retrieves the name (computing.name-computing.ID)
dependency := b.getDependency(comp.ID,branch) step.Dependencies = b.getDependency(comp.ID)
if dependency != "" && !slices.Contains(step.Dependencies,dependency) {
step.Dependencies = append(step.Dependencies,dependency)
}
}
}
new_dag.Tasks = append(new_dag.Tasks, step) 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) 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-- { for _, link := range b.graph.Links {
current_link := b.graph.Links[branch[i]] if current_computing_id == link.Destination && b.graph.getComponentType(link.Source) == "computing" && !slices.Contains(dependencies_id,link.Source) {
current_computing_found := false dependencies_id = append(dependencies_id, link.Source)
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)
} }
} }
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 { // func (b *ArgoBuilder) componentInBranch(component_id string, branch []string) bool {
for _, link := range branch { // for _, link := range branch {
if b.graph.Links[link].Source == component_id || b.graph.Links[link].Destination == component_id { // if b.graph.Links[link].Source == component_id || b.graph.Links[link].Destination == component_id {
return true // return true
} // }
} // }
return false // 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-- { // for i := index; i >= 0 ; i-- {
previousLink := b.graph.Links[branch[i]] // previousLink := b.graph.Links[branch[i]]
if previousLink.Source != computing_id && b.graph.getComponentType(previousLink.Source) == "computing"{ // if previousLink.Source != computing_id && b.graph.getComponentType(previousLink.Source) == "computing"{
name := getArgoName(b.graph.getComponentName(previousLink.Source),previousLink.Source) // name := getArgoName(b.graph.getComponentName(previousLink.Source),previousLink.Source)
return name // return name
} // }
if previousLink.Destination != computing_id && b.graph.getComponentType(previousLink.Destination) == "computing"{ // if previousLink.Destination != computing_id && b.graph.getComponentType(previousLink.Destination) == "computing"{
name := getArgoName(b.graph.getComponentName(previousLink.Destination),previousLink.Destination) // name := getArgoName(b.graph.getComponentName(previousLink.Destination),previousLink.Destination)
return name // return name
} // }
} // }
return "" // return ""
} // }
func getComputingCommands(user_input string) (list_command []string) { func getComputingCommands(user_input string) (list_command []string) {
user_input = removeImageName(user_input) user_input = removeImageName(user_input)
@ -240,7 +234,7 @@ func getComputingEnvironmentName(user_input []string) (list_names []string){
return return
} }
func generateName() (Name string){ func generateWfName() (Name string){
Name = fakelish.GenerateFakeWord(5, 8) + "-" + fakelish.GenerateFakeWord(5, 8) Name = fakelish.GenerateFakeWord(5, 8) + "-" + fakelish.GenerateFakeWord(5, 8)
return 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 // 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) { 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 { if current_branch == nil {
current_branch = make([]string, 0) current_branch = make([]string, 0)
} }
@ -296,7 +297,7 @@ func (g *Graph) getComponentName(id string) string {
return "" return ""
} }
// returns either computing, data or storage
func (g *Graph) getComponentType(component_id string) string { func (g *Graph) getComponentType(component_id string) string {
for _, comp := range g.Computings { for _, comp := range g.Computings {
if comp.ID == component_id{ if comp.ID == component_id{