zerovm/zerocloud — pull request #108 by pkit (2014-07-27 12:52:18+00:00)
Title:  implement simple job chaining

this patch adds another middleware `ChainMiddleware`
the middleware allows rescheduling of response from previous job as a new job
for the chain to work the following statements should be true:
- response should contain `X-Zerovm-Execute: 1.0` header
- response should contain `Content-Type: application/json` header, and effectively be a json job description

you can see that the application that tries to chain something should be able to set a _response header_
which means that application MUST use `message/cgi` or `message/http` as its output channel content type
ChainMiddleware MUST be placed anywhere before ProxyQueryMiddleware in the proxy-server pipeline

example job description that can output a chained job is:

[
{
'name': 'http',
'exec': {'path': 'swift://a/c/chainer'},
'devices': [
{
'name': 'stdout',
'content_type': 'message/http'
}
]
}
]

as you can see, stdout has no path - will be sent to user, and its content_type is `message/http`

Protection from infinite loops:
`ChainMiddleware` has a config file setting `chain_timeout` (in seconds), by default `chain_timeout = 20`.
If chain is executing more than `chain_timeout` the chain will stop and the resulting job description file will be returned to user.