update component id with the one in the links

This commit is contained in:
pb 2024-04-09 15:03:12 +02:00
parent 6bbb2a0b40
commit a485831a01

View File

@ -168,13 +168,13 @@ func (g *Graph) GetWorkflowComponents(workflow string){
if (comp_id != "") { if (comp_id != "") {
switch component_type { switch component_type {
case "computing": case "computing":
g.AddComputingModel(comp_id, value) g.AddComputingModel(comp_id, value, id.Str)
case "data": case "data":
g.AddDataModel(comp_id, value) g.AddDataModel(comp_id, value, id.Str)
case "datacenter": case "datacenter":
g.AddDatacenterModel(comp_id, value) g.AddDatacenterModel(comp_id, value, id.Str)
case "storage": case "storage":
g.AddStorageModel(comp_id, value) g.AddStorageModel(comp_id, value, id.Str)
default : default :
logs.Critical("Component type doesn't match a know type : " + component_type) logs.Critical("Component type doesn't match a know type : " + component_type)
} }
@ -186,47 +186,7 @@ func (g *Graph) GetWorkflowComponents(workflow string){
} }
func (g *Graph) AddComponentObject(comp_type string, component interface{}){ func (g *Graph) AddDataModel(id string, user_input gjson.Result, wf_id string) error {
switch comp_type {
case "computing":
g.Computings = append(g.Computings, component.(models.ComputingModel))
case "data":
g.Datas = append(g.Datas, component.(models.DataModel))
case "datacenter":
g.Datacenters = append(g.Datacenters, component.(models.DatacenterModel))
case "storage":
g.Storages = append(g.Storages, component.(models.StorageModel))
}
}
// Construct the object corresponding to component_type from its ID, retrieved in
// the xml graph, in order to merge the user input with the base model
func (g *Graph) GetComponentById(component_type string, id string) (map[string]interface{}, error) {
// TODO : Add a verification that g.ws is initialized ?
body , err := g.ws.Get("v1/"+component_type+"/"+id)
if err != nil {
return nil, err
}
comp := make(map[string]interface{})
jsonified := gjson.ParseBytes(body)
jsonified.ForEach(func(key, value gjson.Result) bool {
comp[key.Str] = value.String()
return true // keep iterating
})
return comp, nil
}
func (g *Graph) AddDataModel(id string, user_input gjson.Result) error {
var d models.DataModel var d models.DataModel
resp, err := g.ws.Get("v1/data/" + id) resp, err := g.ws.Get("v1/data/" + id)
if err != nil { if err != nil {
@ -234,11 +194,12 @@ func (g *Graph) AddDataModel(id string, user_input gjson.Result) error {
} }
json.Unmarshal(resp, &d) json.Unmarshal(resp, &d)
json.Unmarshal([]byte(user_input.Raw),&d.DataNEWModel) json.Unmarshal([]byte(user_input.Raw),&d.DataNEWModel)
d.ID = wf_id
g.Datas = append(g.Datas, d) g.Datas = append(g.Datas, d)
return nil return nil
} }
func (g *Graph) AddDatacenterModel(id string, user_input gjson.Result) error { func (g *Graph) AddDatacenterModel(id string, user_input gjson.Result, wf_id string) error {
var d models.DatacenterModel var d models.DatacenterModel
resp, err := g.ws.Get("v1/datacenter/" + id) resp, err := g.ws.Get("v1/datacenter/" + id)
if err != nil { if err != nil {
@ -246,11 +207,12 @@ func (g *Graph) AddDatacenterModel(id string, user_input gjson.Result) error {
} }
json.Unmarshal(resp, &d) json.Unmarshal(resp, &d)
json.Unmarshal([]byte(user_input.Raw),&d.DatacenterNEWModel) json.Unmarshal([]byte(user_input.Raw),&d.DatacenterNEWModel)
d.ID = wf_id
g.Datacenters = append(g.Datacenters, d) g.Datacenters = append(g.Datacenters, d)
return nil return nil
} }
func (g *Graph) AddComputingModel(id string, user_input gjson.Result) error { func (g *Graph) AddComputingModel(id string, user_input gjson.Result, wf_id string) error {
var c models.ComputingModel var c models.ComputingModel
resp, err := g.ws.Get("v1/computing/" + id) resp, err := g.ws.Get("v1/computing/" + id)
if err != nil { if err != nil {
@ -258,11 +220,12 @@ func (g *Graph) AddComputingModel(id string, user_input gjson.Result) error {
} }
json.Unmarshal(resp, &c) json.Unmarshal(resp, &c)
json.Unmarshal([]byte(user_input.Raw),&c.ComputingNEWModel) json.Unmarshal([]byte(user_input.Raw),&c.ComputingNEWModel)
c.ID = wf_id
g.Computings = append(g.Computings, c) g.Computings = append(g.Computings, c)
return nil return nil
} }
func (g *Graph) AddStorageModel(id string, user_input gjson.Result) error { func (g *Graph) AddStorageModel(id string, user_input gjson.Result, wf_id string) error {
var s models.StorageModel var s models.StorageModel
resp, err := g.ws.Get("v1/data/" + id) resp, err := g.ws.Get("v1/data/" + id)
if err != nil { if err != nil {
@ -270,6 +233,7 @@ func (g *Graph) AddStorageModel(id string, user_input gjson.Result) error {
} }
json.Unmarshal(resp, &s) json.Unmarshal(resp, &s)
json.Unmarshal([]byte(user_input.Raw),&s.StorageNEWModel) json.Unmarshal([]byte(user_input.Raw),&s.StorageNEWModel)
s.ID = wf_id
g.Storages = append(g.Storages, s) g.Storages = append(g.Storages, s)
return nil return nil
} }