diff --git a/docs/identified_problems.md b/docs/identified_problems.md index 36081e1..e1133a9 100644 --- a/docs/identified_problems.md +++ b/docs/identified_problems.md @@ -2,4 +2,11 @@ - [ ] In most of the components from 'models/' we have a method to add input and output to the model, however this linking of components is already done in oc-schedule when parsing the MxGraph. We need to determine if adding relations between components inside the objects themself is necessary. - When running in debug mode with a breakpoint inside the first line of computing.addLink it is only called once -- [ ] \ No newline at end of file +- [ ] + +## MxGraph + +- [ ] The ConsumeMxGraphModel is way too long, it should refactored and broken down in different sub methods + - mxcell are put inside an tag when the settings have been opened, wether values have been set or not. Maybe we could find a way to make mxgraph add these whenever we add a component to the graph. + - then identify the links only +- [ ] It is unclear what are the inputs and the ouputs. It seems like they were implemented to link two components, but it seems redundant with the identification of links \ No newline at end of file diff --git a/docs/lexicon.md b/docs/lexicon.md new file mode 100644 index 0000000..a4e1259 --- /dev/null +++ b/docs/lexicon.md @@ -0,0 +1,6 @@ +- rType : ressource type, can only be : + - rtype.DATA + - rtype.COMPUTING + - rtype.STORAGE + - rtype.DATACENTER + - rtype.INVALID if it doesn't match with any of the previous type \ No newline at end of file diff --git a/models/workflow.go b/models/workflow.go index 5a39887..b883a24 100644 --- a/models/workflow.go +++ b/models/workflow.go @@ -564,9 +564,9 @@ func FindSliceInSlice(slice1 []string, slice2 []string) (int, int, bool) { return -1, -1, false } -func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, err error, issues []error) { +func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (returned_wf *Workflow, err error, issues []error) { - ret = &Workflow{} + returned_wf = &Workflow{} // When we will iterate over the full array of cells, we first will register the resources // and after the linkage between them @@ -574,6 +574,18 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er return xmlmodel.Root.MxCell[i].RID != nil }) + // For each cell of the xml graph, + // in the case cell has a rID retrieve its rType from the value of rID of the componant in the worfklow + // retrieve the componant's type + // create an object from the rType + // update the existing workflow with the new componant + // or by defautlt : the cell represents an arrow + // if the source or the target of the arrow is a datacenter + // define which end of the arrow is the DC + // if the other other end of the arrow is a computing component + // create a computing object + // attach the DC to it + // update the workflow with the object : create the list of this type of component or update the list with the id of the component with the object for _, cell := range xmlmodel.Root.MxCell { switch { @@ -595,10 +607,11 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er nil } - resObj := ret.CreateResourceObject(rType) + resObj := returned_wf.CreateResourceObject(rType) resObj.setReference(rIDObj) - ret.UpdateObj(resObj, cell.ID) + returned_wf.UpdateObj(resObj, cell.ID) + case cell.ID == "0" || cell.ID == "1": // ID 0 and 1 are special cases of mxeditor continue @@ -606,8 +619,8 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er default: // Not root nor resource. Should be only links - sourceObj := ret.GetResource(cell.Source) - targetObj := ret.GetResource(cell.Target) + sourceObj := returned_wf.GetResource(cell.Source) + targetObj := returned_wf.GetResource(cell.Target) if sourceObj == nil || targetObj == nil { if sourceObj == nil && targetObj == nil { @@ -633,18 +646,18 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er datacenterLinked = cell.Source } - switch ret.GetResource(datacenterLinked).getRtype() { + switch returned_wf.GetResource(datacenterLinked).getRtype() { case rtype.COMPUTING: - computingObj := ret.GetResource(datacenterLinked).(*ComputingObject) + computingObj := returned_wf.GetResource(datacenterLinked).(*ComputingObject) // We should always get a ID because we already registered resources and discarded which doesn't correspond to existent models computingObj.DataCenterID = *datacenter - ret.UpdateObj(computingObj, *datacenterLinked) + returned_wf.UpdateObj(computingObj, *datacenterLinked) } } else { targetObj.addLink(INPUT, *cell.Source) - ret.UpdateObj(targetObj, *cell.Target) // save back + returned_wf.UpdateObj(targetObj, *cell.Target) // save back // If we have a relationship of: // Source ----> Target @@ -653,7 +666,7 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er // But we also must make sure that the Target will be in the OUTPUTs of the Source sourceObj.addLink(OUTPUT, *cell.Target) - ret.UpdateObj(sourceObj, *cell.Source) + returned_wf.UpdateObj(sourceObj, *cell.Source) } } @@ -663,7 +676,9 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er dataslist := make(map[string]bool) // datalist := make(map[string]bool) - for _, comp := range ret.Computing { + + // Test wether the computing componants are linked with a DC + for _, comp := range returned_wf.Computing { if comp.DataCenterID == "" { issues = append(issues, errors.New("Computing "+*comp.getName()+" without a Datacenter")) } else { @@ -673,14 +688,14 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er } for _, dcin := range comp.Inputs { - switch ret.GetResource(&dcin).getRtype() { + switch returned_wf.GetResource(&dcin).getRtype() { case rtype.DATA: dataslist[dcin] = true } } for _, dcout := range comp.Outputs { - switch ret.GetResource(&dcout).getRtype() { + switch returned_wf.GetResource(&dcout).getRtype() { case rtype.DATA: dataslist[dcout] = true } @@ -688,23 +703,23 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er } - for _, va := range ret.Storage { - if va.Inputs == nil && va.Outputs == nil { - issues = append(issues, errors.New("Storage "+*va.getName()+" without compatible inputs and outputs")) + for _, storage_component := range returned_wf.Storage { + if storage_component.Inputs == nil && storage_component.Outputs == nil { + issues = append(issues, errors.New("Storage "+*storage_component.getName()+" without compatible inputs and outputs")) } } - for dcID, va := range ret.Datacenter { + for dcID, dc_component := range returned_wf.Datacenter { // if rID doesn't exist in the list, it means that it's not used if _, ok := dcslist[dcID]; !ok { - issues = append(issues, errors.New("DC "+*va.getName()+" not atached to any Computing")) + issues = append(issues, errors.New("DC "+*dc_component.getName()+" not atached to any Computing")) } } - for dcID, va := range ret.Data { + for dcID, data_component := range returned_wf.Data { // if rID doesn't exist in the list, it means that it's not used if _, ok := dataslist[dcID]; !ok { - issues = append(issues, errors.New("Data "+*va.getName()+" not atached to any Computing")) + issues = append(issues, errors.New("Data "+*data_component.getName()+" not atached to any Computing")) } } @@ -722,7 +737,7 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er // inputs AND Comp2 inputs with Comp1 outputs, since we are // iterating over all existent Computing models in the Graph - for _, comp := range ret.Computing { + for _, comp := range returned_wf.Computing { compModel, err2 := comp.getModel() if err = err2; err != nil { @@ -744,7 +759,7 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er //TODO: We should allow heterogenous inputs? for _, objIn := range comp.Inputs { - resIn := ret.GetResource(&objIn) + resIn := returned_wf.GetResource(&objIn) resInType := resIn.getRtype() switch resInType { case rtype.DATA: @@ -781,7 +796,7 @@ func (w Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (ret *Workflow, er //TODO: We should allow heterogenous outputs? for _, objOut := range comp.Outputs { - resOut := ret.GetResource(&objOut) + resOut := returned_wf.GetResource(&objOut) resOutType := resOut.getRtype() switch resOutType { case rtype.COMPUTING: