Skip to content

Commit 850d481

Browse files
authored
Merge pull request #97 from fission/workflow-env-headers
Add support for headers and query params to workflow invocations
2 parents 20dbf52 + a69e300 commit 850d481

9 files changed

Lines changed: 480 additions & 216 deletions

File tree

examples/misc/inputs.wf.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The Inputs Workflow - simply prints the inputs it received, including body, query params and headers.
2+
#
3+
# Example: curl -XPUT -H "hello: world" http://$FISSION_ROUTER/fission-function/inputs?a=b
4+
apiVersion: 1
5+
output: Printer
6+
tasks:
7+
Printer:
8+
run: compose
9+
inputs: "{$.Invocation.Inputs}"

examples/whales/metadatawhale.wf.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ tasks:
55
PrefixedFortune:
66
run: fortune
77
inputs:
8-
header_prefix: "Whale says:"
8+
headers:
9+
# If the 'prefix' header is non-empty, we use that. Otherwise we default to "whale says"
10+
prefix: "{ $.Invocation.Inputs.headers.Prefix || 'Whale says: ' }"

pkg/fnenv/fission/envproxy.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2930
type 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

pkg/fnenv/fission/httputil.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)