improved structure, doc and naming
This commit is contained in:
parent
b7441c7430
commit
c79b693ba3
@ -6,6 +6,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
@ -13,16 +14,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ArgoBuilder struct {
|
type ArgoBuilder struct {
|
||||||
graph Graph
|
graph Graph
|
||||||
branches [][]string
|
branches [][]string
|
||||||
steps []DagStep
|
Workflow Workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
type DagStep struct {
|
type Workflow struct {
|
||||||
Name string `yaml:"name"`
|
Templates []Template `yaml:"templates"`
|
||||||
Template string `yaml:"template"`
|
|
||||||
Arguments []string `yaml:"arguments"`
|
|
||||||
Dependencies []string `yaml:"dependencies"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -31,22 +29,32 @@ func (b *ArgoBuilder) CreateDAG() bool {
|
|||||||
fmt.Println("list of branches : ", b.branches)
|
fmt.Println("list of branches : ", b.branches)
|
||||||
|
|
||||||
b.createDAGstep()
|
b.createDAGstep()
|
||||||
yamlified, err := yaml.Marshal(b.steps)
|
yamlified, err := yaml.Marshal(b.Workflow)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("Could not produce yaml file")
|
logs.Error("Could not transform object to yaml file")
|
||||||
}
|
}
|
||||||
fmt.Println(string(yamlified))
|
fmt.Println(string(yamlified))
|
||||||
|
err = os.WriteFile("argo.yml", []byte(yamlified), 0660)
|
||||||
|
if err != nil {
|
||||||
|
logs.Error("Could not write the yaml file")
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (b *ArgoBuilder) createDAGstep() {
|
func (b *ArgoBuilder) createDAGstep() {
|
||||||
|
|
||||||
|
new_dag := Dag{}
|
||||||
|
|
||||||
for _, comp := range b.graph.Computings{
|
for _, comp := range b.graph.Computings{
|
||||||
unique_name := comp.Name + "_" + comp.ID
|
unique_name := comp.Name + "_" + comp.ID
|
||||||
step := DagStep{Name: unique_name, Template: unique_name, Arguments: comp.Arguments}
|
var comp_params []Parameter
|
||||||
|
comp_params = append(comp_params, Parameter{"toto","titi"})
|
||||||
|
step := Task{Name: unique_name, Template: unique_name}
|
||||||
|
step.Arguments.Parameters = append(step.Arguments.Parameters, comp_params...)
|
||||||
|
|
||||||
// For each branch, check if the computing has a dependency
|
// For each branch, check if the computing has a dependency
|
||||||
for _, branch := range b.branches {
|
for _, branch := range b.branches {
|
||||||
if b.componentInBranch(comp.ID,branch) {
|
if b.componentInBranch(comp.ID,branch) {
|
||||||
@ -57,8 +65,13 @@ func (b *ArgoBuilder) createDAGstep() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.steps = append(b.steps, step)
|
|
||||||
|
new_dag.Tasks = append(new_dag.Tasks, step)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.Workflow.Templates = append (b.Workflow.Templates, Template{Name: "dag", Dag: new_dag})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ArgoBuilder) getDependency (current_computing_id string, branch []string) string {
|
func (b *ArgoBuilder) getDependency (current_computing_id string, branch []string) string {
|
||||||
|
@ -25,23 +25,27 @@ group if g.Links size > 0
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
graph -> graph : get list branches (end_lists, unvisited_links, current_branch)
|
||||||
|
note left: unvisited links and current branch\n are nilfor the first entry
|
||||||
|
|
||||||
loop link in endLinks
|
loop link in endLinks
|
||||||
|
|
||||||
|
|
||||||
|
graph -> graph : create a new list representing the current branch
|
||||||
|
|
||||||
graph -> graph : copy Links id on a list
|
graph -> graph : copy Links id on a list
|
||||||
|
|
||||||
loop while hasParent
|
graph -> graph : get list previous links
|
||||||
graph -> graph : currentLink = idList[i]
|
|
||||||
|
|
||||||
group if link.dst == currentLink.Src
|
group if len(previous_links) == 0
|
||||||
graph -> graph : do something
|
graph -> graph : add current list
|
||||||
note right : TEST ALGO : edit a\n string that shows every branch
|
end
|
||||||
graph -> graph : change currentSrc with link.Src
|
|
||||||
graph -> graph : remove currentLink from idList
|
|
||||||
end
|
|
||||||
group else
|
|
||||||
graph -> graph : hasParent = false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
loop for link in previous_links
|
||||||
|
graph -> graph : add the link to the current branch
|
||||||
|
graph -> graph : remove current link from unvisited links list
|
||||||
|
graph -> graph : get list branches (end_lists, unvisited_links, current_branch)
|
||||||
|
note right: for each link we retrieve the branch that\nprecedes it recursively,\n so once we hit the end of a branch\n the entire branch is returned\n to the node where a split happened\nor that is its source
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
2
go.mod
2
go.mod
@ -9,6 +9,7 @@ require (
|
|||||||
github.com/rs/zerolog v1.32.0
|
github.com/rs/zerolog v1.32.0
|
||||||
github.com/sbabiv/xml2map v1.2.1
|
github.com/sbabiv/xml2map v1.2.1
|
||||||
github.com/tidwall/gjson v1.17.1
|
github.com/tidwall/gjson v1.17.1
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -46,5 +47,4 @@ require (
|
|||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
google.golang.org/protobuf v1.32.0 // indirect
|
google.golang.org/protobuf v1.32.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
)
|
||||||
|
29
graph.go
29
graph.go
@ -261,55 +261,48 @@ func (g *Graph) ExportToArgo(id string) error {
|
|||||||
|
|
||||||
fmt.Println(str)
|
fmt.Println(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Identified branches : ", list_branches)
|
fmt.Println("Identified branches : ", list_branches)
|
||||||
argo_builder := ArgoBuilder{*g,list_branches,nil}
|
argo_builder := ArgoBuilder{graph : *g, branches: list_branches}
|
||||||
argo_builder.CreateDAG()
|
argo_builder.CreateDAG()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, editable_link_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)
|
||||||
}
|
}
|
||||||
|
|
||||||
if editable_link_list == nil {
|
if unvisited_links_list == nil {
|
||||||
editable_link_list = make(map[string]models.Link,len(g.Links))
|
unvisited_links_list = make(map[string]models.Link,len(g.Links))
|
||||||
maps.Copy(editable_link_list,g.Links)
|
maps.Copy(unvisited_links_list,g.Links)
|
||||||
fmt.Println(editable_link_list)
|
fmt.Println(unvisited_links_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
for link_id, _ := range end_links {
|
for link_id, _ := range end_links {
|
||||||
// branch := []string{link_id}
|
|
||||||
j := link_id
|
j := link_id
|
||||||
new_branches := make([][]string,0)
|
new_branches := make([][]string,0)
|
||||||
|
|
||||||
|
previous_index := g.getPreviousLink(j, unvisited_links_list)
|
||||||
previous_index := g.hasPreviousLink(j, editable_link_list)
|
|
||||||
if len(previous_index) == 0 {
|
if len(previous_index) == 0 {
|
||||||
// new_branches = append(new_branches, []string{link_id})
|
|
||||||
// return new_branches
|
|
||||||
list_branches = append(list_branches, []string{link_id})
|
list_branches = append(list_branches, []string{link_id})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id_link := range previous_index {
|
for _, id_link := range previous_index {
|
||||||
current_branch = append([]string{link_id},current_branch...)
|
current_branch = append([]string{link_id},current_branch...)
|
||||||
delete(editable_link_list, link_id)
|
delete(unvisited_links_list, link_id)
|
||||||
// create a new branch for each previous link, appending the current path to this node to the created branch
|
// create a new branch for each previous link, appending the current path to this node to the created branch
|
||||||
new_end_link := make(map[string]models.Link,0)
|
new_end_link := make(map[string]models.Link,0)
|
||||||
new_end_link[id_link] = g.Links[id_link]
|
new_end_link[id_link] = g.Links[id_link]
|
||||||
new_branches = g.getListBranches(new_end_link,editable_link_list,current_branch)
|
new_branches = g.getListBranches(new_end_link,unvisited_links_list,current_branch)
|
||||||
|
|
||||||
for _, new_branch := range new_branches{
|
for _, new_branch := range new_branches{
|
||||||
current_branch = append(new_branch,link_id)
|
current_branch = append(new_branch,link_id)
|
||||||
list_branches = append(list_branches, current_branch)
|
list_branches = append(list_branches, current_branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -350,7 +343,7 @@ func (g *Graph) isSource(comp_id string,link_id string) bool {
|
|||||||
// with the same Destination id that the Source id in g.Links[linkIndex]
|
// with the same Destination id that the Source id in g.Links[linkIndex]
|
||||||
// or nil if not
|
// or nil if not
|
||||||
|
|
||||||
func (g *Graph) hasPreviousLink(link_id string,map_link map[string]models.Link) (previous_id []string) {
|
func (g *Graph) getPreviousLink(link_id string,map_link map[string]models.Link) (previous_id []string) {
|
||||||
for k, link := range map_link{
|
for k, link := range map_link{
|
||||||
if(k != link_id && link.Destination == g.Links[link_id].Source){
|
if(k != link_id && link.Destination == g.Links[link_id].Source){
|
||||||
previous_id = append(previous_id, k)
|
previous_id = append(previous_id, k)
|
||||||
|
2
main.go
2
main.go
@ -39,7 +39,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.LoadFrom(list["test-alpr"])
|
g.LoadFrom(list["test-alpr"])
|
||||||
g.ExportToArgo("test")
|
g.ExportToArgo("test-alpr")
|
||||||
|
|
||||||
fmt.Print("stop")
|
fmt.Print("stop")
|
||||||
|
|
||||||
|
40
template_models.go
Normal file
40
template_models.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type Parameter struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Value string `yaml:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Container struct {
|
||||||
|
Image string `yaml:"image"`
|
||||||
|
Command []string `yaml:"command,omitempty"`
|
||||||
|
Args []string `yaml:"args,omitempty"`
|
||||||
|
VolumeMounts []VolumeMount `yaml:"volumeMounts,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeMount struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
MountPath string `yaml:"mountPath"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Task struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Template string `yaml:"template"`
|
||||||
|
Dependencies []string `yaml:"dependencies,omitempty"`
|
||||||
|
Arguments struct {
|
||||||
|
Parameters []Parameter `yaml:"parameters,omitempty"`
|
||||||
|
} `yaml:"arguments,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Dag struct {
|
||||||
|
Tasks []Task `yaml:"tasks,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Template struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Inputs struct {
|
||||||
|
Parameters []Parameter `yaml:"parameters"`
|
||||||
|
} `yaml:"inputs,omitempty"`
|
||||||
|
Container Container `yaml:"container,omitempty"`
|
||||||
|
Dag Dag `yaml:"dag,omitempty"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user