@@ -55,46 +55,57 @@ func (f *FanOutNode) Equals(cmp types.Comparable) bool {
5555 }
5656}
5757
58- // Exec splits the output for the next parallel dags
58+ // executeFanOut splits the output for the next parallel dags
5959// Scatter mode can only be used if the value held in the map is of type slice. Subdivides each map entry to a different node
6060// Broadcast mode can always be used. Copies the entire map to each of the subsequent nodes
61- func (f * FanOutNode ) Exec ( _ * Request , params ... map [ string ] interface {} ) (map [ string ] interface {} , error ) {
61+ func (workflow * Workflow ) executeFanOut ( progress * Progress , input * PartialData , task * FanOutNode , r * Request ) (* PartialData , * Progress , bool , error ) {
6262 output := make (map [string ]interface {})
6363
6464 // TODO: avoid forcing the interface implementation, so that the signature of Exec can be adapted
65- if len (params ) != 1 {
66- return nil , fmt .Errorf ("failed to get one input for choice node: received %d inputs" , len (params ))
65+ if len (input . Data ) != 1 {
66+ return nil , progress , false , fmt .Errorf ("failed to get one input for choice node: received %d inputs" , len (input . Data ))
6767 }
6868
6969 // input -> output: map["input":1] -> map["0":map["input":1], "1":map["input":1]]
70- if f .Type == Broadcast {
71- for _ , nextNode := range f .GetNext () {
70+ if task .Type == Broadcast {
71+ for _ , nextNode := range task .GetNext () {
7272 // TODO: check if a copy of params[0] is needed
73- output [string (nextNode )] = params [ 0 ] // simply returns input, that will be copied to each subsequent node
73+ output [string (nextNode )] = input . Data // simply returns input, that will be copied to each subsequent node
7474 }
75- } else if f .Type == Scatter { // scatter only accepts an array with exactly fanOutDegree elements. However, multiple input values are allowed
76- inputName := maps .Keys (params [ 0 ] )[0 ]
77- inputToScatter := params [ 0 ] [inputName ]
75+ } else if task .Type == Scatter { // scatter only accepts an array with exactly fanOutDegree elements. However, multiple input values are allowed
76+ inputName := maps .Keys (input . Data )[0 ]
77+ inputToScatter := input . Data [inputName ]
7878 inputArrayToScatter , errNotSlice := utils .ConvertToSlice (inputToScatter )
7979 if errNotSlice != nil {
80- return nil , fmt .Errorf ("cannot convert input %v to slice" , inputToScatter )
80+ return nil , progress , false , fmt .Errorf ("cannot convert input %v to slice" , inputToScatter )
8181 }
8282
83- if len (inputArrayToScatter ) != f .FanOutDegree {
84- return nil , fmt .Errorf ("input array size (%d) must be equal to fanOutDegree (%d). Check the previous node output" ,
85- len (inputArrayToScatter ), f .FanOutDegree )
83+ if len (inputArrayToScatter ) != task .FanOutDegree {
84+ return nil , progress , false , fmt .Errorf ("input array size (%d) must be equal to fanOutDegree (%d). Check the previous node output" ,
85+ len (inputArrayToScatter ), task .FanOutDegree )
8686 }
8787
88- for i , nextNode := range f .GetNext () {
88+ for i , nextNode := range task .GetNext () {
8989 iOutput := make (map [string ]interface {})
9090 iOutput [inputName ] = inputArrayToScatter [i ]
9191 output [string (nextNode )] = iOutput
9292 }
9393 } else {
94- return nil , fmt .Errorf ("invalid fanout mode: %d" , f .Type )
94+ return nil , progress , false , fmt .Errorf ("invalid fanout mode: %d" , task .Type )
9595 }
9696
97- return output , nil
97+ /* using forNode = "" in order to create a special input to handle fanout
98+ * case with Data field which contains a map[string]interface{} with the key set
99+ * to nodeId and the value which is also a map[string]interface{} containing the
100+ * effective input for the nth-parallel node */
101+ outputData := NewPartialData (ReqId (r .Id ), "" , task .GetId (), output )
102+ //newOutputDataMap := make(map[string]interface{}) // TODO: consider using a map of PartialData rather than a single PartialData object
103+
104+ err := progress .CompleteNode (task .GetId ())
105+ if err != nil {
106+ return nil , progress , false , err
107+ }
108+ return outputData , progress , true , nil
98109}
99110
100111func (f * FanOutNode ) AddOutput (workflow * Workflow , taskId TaskId ) error {
0 commit comments