Skip to content

Commit

Permalink
Merge pull request #91 from fission/fission-headers-query-support
Browse files Browse the repository at this point in the history
Add support for inputs specifying task metadata
  • Loading branch information
erwinvaneyk authored Nov 29, 2017
2 parents 79fa490 + 9656c8b commit 9a4813d
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 57 deletions.
55 changes: 45 additions & 10 deletions examples/whales/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
# Simple Examples
This directory contains two simple example workflows (and two whales!), along with the required functions.
This directory contains multiple simple example workflows (and whales!), along with the required functions.
The intention of each workflow is to show-off and explain a concept in Fission Workflows

## Setup
- Make sure that you have a running Fission Cluster with the workflow engine, see the [readme](../../README.md) for details.
- Deploy both the functions, using the [deploy.sh](./deploy.sh) script, or run the commands listed there manually.

### Example: Echowhale
The 'echowhale' workflow is a minimal workflow, consisting of whale echoing the input.
## Examples


### Echowhale
The `echowhale` workflow is a minimal workflow, consisting of whale echoing the input.
The main feature it shows is that a workflow from the user's view the same as a Fission function.

To invoke:
Run:
```bash
curl -XPOST -d 'Whale you echo?' $FISSION_ROUTER/fission-function/echowhale
curl -XPOST -d 'Whale you echo?' ${FISSION_ROUTER}/fission-function/echowhale
```

### Example: Fortunewhale
The fortunewhale workflow consists of multiple steps, generating a 'fortune' and passing it through the whalesay function that was used in the first workflow.
### Fortunewhale
The `fortunewhale` workflow consists of multiple steps, generating a 'fortune' and passing it through the whalesay function that was used in the first workflow.
The features introduced in this example:
- Dependencies between tasks
- Mapping a task's output to another task's input
- The 'noop' internal function, which is a function executed within the engine itself.

To invoke:
Run:
```bash
curl -XPOST $FISSION_ROUTER/fission-function/fortunewhale
curl -XPOST ${FISSION_ROUTER}/fission-function/fortunewhale
```

### Maybewhale
The `maybewhale` workflow consists of a simple if-else condition.
Depending on the length of the input, the workflow transforms the input.
If the input is smaller than 20 characters, the workflow will run the `whalesay` task.
If not, it will simply propagate the user input.

Run:
```bash
# This will wrap the input in a whale, because the input is < 20
curl -XPOST -d 'Whale you echo?' ${FISSION_ROUTER}/fission-function/maybewhale

# This will simply echo the input, because the input is >= 20.
curl -XPOST -d 'Whale you echo this way too long message?' ${FISSION_ROUTER}/fission-function/maybewhale
```

### Example:
### Metadatawhale
The `metadatawhale` workflow shows how to add metadata (headers, query values) to tasks.

Run:
```bash
curl -XPOST ${FISSION_ROUTER}/fission-function/metadatawhale
```

### Nestedwhale
The `nestedwhale` workflow is surprisingly... empty.
The principle that 'workflows are fission functions', allows workflows to call other workflows just like you would call regular Fission Functions.
In this workflow, we generate a fortune and pass it to the dedicated whale echoing workflow: `echowhale`.

Run
```bash
curl -XPOST ${FISSION_ROUTER}/fission-function/nestedwhale
```
5 changes: 4 additions & 1 deletion examples/whales/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/sh

# deploy.sh - deploys all functions and workflows in this directory

set -x

# Deploy functions
fission env create --name binary --image fission/binary-env:0.3.0
fission env create --name binary --image fission/binary-env
fission fn create --name whalesay --env binary --deploy ./whalesay.sh
fission fn create --name fortune --env binary --deploy ./fortune.sh

Expand All @@ -12,3 +14,4 @@ fission fn create --name fortunewhale --env workflow --src ./fortunewhale.wf.yam
fission fn create --name echowhale --env workflow --src ./echowhale.wf.yaml
fission fn create --name maybewhale --env workflow --src ./maybewhale.wf.yaml
fission fn create --name nestedwhale --env workflow --src ./nestedwhale.wf.yaml
fission fn create --name metadatawhale --env workflow --src ./metadatawhale.wf.yaml
1 change: 1 addition & 0 deletions examples/whales/echowhale.wf.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This whale shows how to access and reference with workflow parameters
apiVersion: 1
output: echowhale
tasks:
Expand Down
12 changes: 12 additions & 0 deletions examples/whales/fortune.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#!/bin/sh

# fortune - generate wise words
#
# Output: string (plain text)

# TODO move this to the build step once the binary environment is a v2 environment
if ! hash fortune 2>/dev/null; then
apk add fortune > /dev/null
fi

# Pretty useless, but used to show headers
prefix=${HTTP_PREFIX}

if [ ! -z "${prefix}" ] ; then
printf "${prefix}"
fi

fortune -s
1 change: 1 addition & 0 deletions examples/whales/fortunewhale.wf.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This whale shows of a basic workflow that combines both Fission Functions (fortune, whalesay) and internal functions (noop)
apiVersion: 1
output: WhaleWithFortune
tasks:
Expand Down
1 change: 1 addition & 0 deletions examples/whales/maybewhale.wf.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# A whale that shows off how a if-condition works in a workflow
apiVersion: 1
output: PassAlong
tasks:
Expand Down
8 changes: 8 additions & 0 deletions examples/whales/metadatawhale.wf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# A whale that shows off how to add metadata (e.g. headers, query) to your fission function
apiVersion: 1
output: PrefixedFortune
tasks:
PrefixedFortune:
run: fortune
inputs:
header_prefix: "Whale says:"
1 change: 1 addition & 0 deletions examples/whales/nestedwhale.wf.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This whale shows of how to call other workflows from a workflow (surprise! There is no difference with regular functions)
apiVersion: 1
output: WhaleIt
tasks:
Expand Down
6 changes: 6 additions & 0 deletions examples/whales/whalesay.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/sh

# whalesay - let a friendly whale say your message instead
#
# input: string (plain text)
# output: string (plain text)

# TODO move this to the build step once the binary environment is a v2 environment
if ! hash cowsay 2> /dev/null; then
apk update > /dev/null
apk add curl perl > /dev/null
Expand Down
2 changes: 1 addition & 1 deletion pkg/fnenv/fission/envproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (fp *Proxy) handleRequest(w http.ResponseWriter, r *http.Request) {
var resp []byte
if invocation.Status.Output != nil {
resp = invocation.Status.Output.Value
w.Header().Add("Content-Type", ToContentType(invocation.Status.Output))
w.Header().Add("Content-Type", inferContentType(invocation.Status.Output, defaultContentType))
} else {
logrus.Infof("Invocation '%v' has no output.", fnId)
}
Expand Down
Loading

0 comments on commit 9a4813d

Please sign in to comment.