@@ -25,7 +25,8 @@ import (
2525 "strings"
2626)
2727
28- // Proxy between Fission and Workflow to ensure that workflowInvocations comply with Fission function interface
28+ // Proxy between Fission and Workflow to ensure that workflowInvocations comply with Fission function interface. This
29+ // ensures that workflows can be executed exactly like Fission functions are executed.
2930type Proxy struct {
3031 invocationServer apiserver.WorkflowInvocationAPIServer
3132 workflowServer apiserver.WorkflowAPIServer
@@ -77,57 +78,57 @@ func (fp *Proxy) handleRequest(w http.ResponseWriter, r *http.Request) {
7778 fp .fissionIds [fnId ] = true
7879 }
7980
80- // Map Inputs to function parameters
81+ // Map request to workflow inputs
8182 inputs := map [string ]* types.TypedValue {}
82- err := ParseRequest (r , inputs )
83+ err := parseRequest (r , inputs )
8384 if err != nil {
8485 logrus .Errorf ("Failed to parse inputs: %v" , err )
8586 http .Error (w , "Failed to parse inputs" , 400 )
8687 return
8788 }
8889
90+ wfSpec := & types.WorkflowInvocationSpec {
91+ WorkflowId : fnId ,
92+ Inputs : inputs ,
93+ }
94+
8995 // Temporary: in case of query header 'X-Async' being present, make request async
9096 if len (r .Header .Get ("X-Async" )) > 0 {
91- invocatinId , err := fp .invocationServer .Invoke (ctx , & types.WorkflowInvocationSpec {
92- WorkflowId : fnId ,
93- Inputs : inputs ,
94- })
97+ invocationId , err := fp .invocationServer .Invoke (ctx , wfSpec )
9598 if err != nil {
9699 logrus .Errorf ("Failed to invoke: %v" , err )
97100 http .Error (w , err .Error (), 500 )
98101 return
99102 }
100103 w .WriteHeader (200 )
101- w .Write ([]byte (invocatinId .Id ))
104+ w .Write ([]byte (invocationId .Id ))
102105 return
103106 }
104107
105108 // Otherwise, the request synchronous like other Fission functions
106- invocation , err := fp .invocationServer .InvokeSync (ctx , & types.WorkflowInvocationSpec {
107- WorkflowId : fnId ,
108- Inputs : inputs ,
109- })
109+ invocation , err := fp .invocationServer .InvokeSync (ctx , wfSpec )
110110 if err != nil {
111111 logrus .Errorf ("Failed to invoke: %v" , err )
112- http .Error (w , err .Error (), 500 )
112+ http .Error (w , err .Error (), http . StatusInternalServerError )
113113 return
114114 }
115115
116+ // In case of an error, create an error response corresponding to Fission function errors
116117 if ! invocation .Status .Status .Successful () {
117118 logrus .Errorf ("Invocation not successful, was '%v'" , invocation .Status .Status .String ())
118119 http .Error (w , invocation .Status .Status .String (), 500 )
119120 return
120121 }
121122
122- // TODO determine header based on the output value
123+ // Otherwise, create a response corresponding to Fission function responses.
123124 var resp []byte
124125 if invocation .Status .Output != nil {
125126 resp = invocation .Status .Output .Value
126127 w .Header ().Add ("Content-Type" , inferContentType (invocation .Status .Output , defaultContentType ))
127128 } else {
128129 logrus .Infof ("Invocation '%v' has no output." , fnId )
129130 }
130- w .WriteHeader (200 )
131+ w .WriteHeader (http . StatusOK )
131132 w .Write (resp )
132133}
133134
0 commit comments