mrutkows / openwhisk-knative-build

Knative build resources for Apache OpenWhisk Functions
Apache License 2.0
0 stars 1 forks source link

Create fake Activation record in OW object #17

Open mrutkows opened 5 years ago

mrutkows commented 5 years ago

The canonical documentation is here: https://github.com/apache/incubator-openwhisk/blob/9eb197cdb60a72f67b8c8a7f81413cadc73d54de/docs/actions.md#accessing-action-metadata-within-the-action-body

See blog for insight: https://www.raymondcamden.com/2017/08/04/working-with-action-metadata-in-openwhisk

In short, something like this: "annotations": [ { "key": "limits", "value": { "logs": 10, "memory": 256, "timeout": 60000 } }, { "key": "path", "value": "rcamden@us.ibm.com_My Space/safeToDelete/meta2" }, { "key": "causedBy", "value": "sequence" } ],

Note: this article discusses the unique "sequence" metadata, but we need to identify the complete record by examining the complete structure in the server.

mrutkows commented 5 years ago

These are (at least some of) the values we would need to provide values for:

    __OW_API_HOST
    __OW_API_KEY
    __OW_NAMESPACE
    __OW_ACTION_NAME (ding ding, we have a winner!)
    __OW_ACTIVATION_ID
    __OW_DEADLINE
mrutkows commented 5 years ago

Here is an actual result (from a while ago) that shows a dump of env. vars from Bluemix OpenWhisk from a function:

        "result": {
            "DEBIAN_FRONTEND": "noninteractive",
            "HOME": "/root",
            "HOSTNAME": "38001e3b19cb",
            "NODE_VERSION": "6.9.1",
            "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "PWD": "/nodejsAction",
            "SERVICE_IGNORE": "true",
            "__OW_ACTION_NAME": "/whisk.system/carlos_experiments/env",
            "__OW_ACTIVATION_ID": "7f4676509",
            "__OW_API_HOST": "10.155.229.130:443",
            "__OW_API_KEY": "fa59:zILraFhLbDd5yWQ",
            "__OW_DEADLINE": "1481931644784",
            "__OW_NAMESPACE": "whisk.system"
        }
mrutkows commented 5 years ago

as per: https://github.com/apache/incubator-openwhisk/blob/c9fb555c950a1fff124e1071b0db518bcbe181cd/docs/actions-new.md

Activation

The proxy is ready to execute a function once it has successfully completed initialization. The OpenWhisk platform will invoke the function by posting an HTTP request to /run with a JSON object providing a new activation context and the input parameters for the function. There may be many activations of the same function against the same proxy (viz. container). Currently, the activations are guaranteed not to overlap — that is, at any given time, there is at most one request to /run from the OpenWhisk platform.

The route must accept a JSON object and respond with a JSON object, otherwise the OpenWhisk platform will treat the activation as a failure and proceed to destroy the container. The JSON object provided by the platform follows the following schema:

{
  "value": JSON,
  "namespace": String,
  "action_name": String,
  "api_host": String,
  "api_key": String,
  "activation_id": String,
  "deadline": Number
}

The value is the function parameters. The rest of the properties become part of the activation context which is a set of environment variables constructed by capitalizing each of the property names, and prefixing the result with __OW_. Additionally, the context must define __OW_API_HOST whose value is the OpenWhisk API host. This value is currently provided as an environment variable defined at container startup time and hence already available in the context.

Successful activation: The route must respond with 200 OK if the activation is successful and the function has produced a JSON object as its result. The response body is recorded as the result of the activation.

Failed activation: Any response other than 200 OK is treated as an activation error. The response from the handler must be a JSON object with a single field called error describing the failure.

The value of the error field may be any valid JSON value. Should the proxy fail to respond with a JSON object, the OpenWhisk platform will treat the failure as an uncaught exception. These two failures modes are distinguished by the value of the response.status in the activation record which is "application error" if the proxy returned an "error" object, and "action developer error" otherwise.

Time limit: Every action in OpenWhisk has a defined time limit (e.g., 60 seconds). The activation must complete within the allowed duration. Failure to complete activation within the allowed time frame will destroy the container.