This is an automated email from the ASF dual-hosted git repository.
pdesai pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-devtools.git
The following commit(s) were added to refs/heads/master by this push:
new f6856d1 Enable knative stem runtime for separate init and activation
data invocations (#238)
f6856d1 is described below
commit f6856d1c61c15ec730cc3197e68706c7ad908de8
Author: Matt Rutkowski <[email protected]>
AuthorDate: Tue Apr 2 17:17:49 2019 -0500
Enable knative stem runtime for separate init and activation data
invocations (#238)
---
.../runtimes/javascript/platform/knative.js | 67 +++++++++++++++++-----
1 file changed, 52 insertions(+), 15 deletions(-)
diff --git a/knative-build/runtimes/javascript/platform/knative.js
b/knative-build/runtimes/javascript/platform/knative.js
index f1a69db..2582401 100644
--- a/knative-build/runtimes/javascript/platform/knative.js
+++ b/knative-build/runtimes/javascript/platform/knative.js
@@ -404,32 +404,69 @@ function PlatformKnativeImpl(platformFactory) {
try {
DEBUG.dumpObject(service.initialized(),"service.initialized()");
- // Process request and process env. variables to provide them in
the manner
- // an OpenWhisk Action expects them, as well as enable additional
Http features.
- preProcessRequest(req);
-
// Do not process requests with init. data if this is not a "stem"
cell
if (hasInitData(req) && !isStemCell(process.env))
throw ("Cannot initialize a runtime with a dedicated
function.");
- service.initCode(req).then(function () {
+ if(hasInitData(req) && hasActivationData(req)){
+
+ // Process request and process env. variables to provide them
in the manner
+ // an OpenWhisk Action expects them, as well as enable
additional Http features.
+ preProcessRequest(req);
+
+ service.initCode(req).then(function () {
+ service.runCode(req).then(function (result) {
+ postProcessResponse(req, result, res)
+ });
+ }).catch(function (error) {
+ console.error(error);
+ if (typeof error.code === "number" && typeof
error.response !== "undefined") {
+ res.status(error.code).json(error.response);
+ } else {
+ console.error("[wrapEndpoint]", "invalid errored
promise", JSON.stringify(error));
+ res.status(500).json({ error: "Internal error during
function execution." });
+ }
+ });
+ } else if(hasInitData(req)){
+
+ // Process request and process env. variables to provide them
in the manner
+ // an OpenWhisk Action expects them, as well as enable
additional Http features.
+ preProcessRequest(req);
+
+ service.initCode(req).then(function () {
+ }).catch(function (error) {
+ console.error(error);
+ if (typeof error.code === "number" && typeof
error.response !== "undefined") {
+ res.status(error.code).json(error.response);
+ } else {
+ console.error("[wrapEndpoint]", "invalid errored
promise", JSON.stringify(error));
+ res.status(500).json({ error: "Internal error during
function execution." });
+ }
+ });
+ } else if(hasActivationData(req)){
+ // Process request and process env. variables to provide them
in the manner
+ // an OpenWhisk Action expects them, as well as enable
additional Http features.
+ preProcessRequest(req);
+
service.runCode(req).then(function (result) {
postProcessResponse(req, result, res)
+ }).catch(function (error) {
+ console.error(error);
+ if (typeof error.code === "number" && typeof
error.response !== "undefined") {
+ res.status(error.code).json(error.response);
+ } else {
+ console.error("[wrapEndpoint]", "invalid errored
promise", JSON.stringify(error));
+ res.status(500).json({ error: "Internal error during
function execution." });
+ }
});
- }).catch(function (error) {
- console.error(error);
- if (typeof error.code === "number" && typeof error.response
!== "undefined") {
- res.status(error.code).json(error.response);
- } else {
- console.error("[wrapEndpoint]", "invalid errored promise",
JSON.stringify(error));
- res.status(500).json({ error: "Internal error during
function execution." });
- }
- });
+ }
+
} catch (e) {
res.status(500).json({error: "internal error during function
initialization."})
}
};
+ // TODO: the 'httpMethods' var should not alternatively store string and
string[] types
this.registerHandlers = function(app, platform) {
var httpMethods = process.env.__OW_HTTP_METHODS;
// default to "[post]" HTTP method if not defined
@@ -440,7 +477,7 @@ function PlatformKnativeImpl(platformFactory) {
if (httpMethods.startsWith('[') && httpMethods.endsWith(']')) {
httpMethods = httpMethods.substr(1, httpMethods.length);
httpMethods = httpMethods.substr(0, httpMethods.length -1);
- httpMethods = httpMethods.split(',')
+ httpMethods = httpMethods.split(',');
}
}
// default to "[post]" HTTP method if specified methods are not valid