inns-apds / assignments

All related assignments and related issues.
0 stars 0 forks source link

using npm openwhisk to orchestrate actions #4

Open D-Workz opened 6 years ago

D-Workz commented 6 years ago

Hey, i am using js to solve assignment 4, I had no problem creating the actions, I can too invoke them now with wsk -i action invoke --param filename in example...

There is a libary inside npm called openwhisk supposingly able to invoke actions. I did a lot of tries but I dont seem to be able to invoke any of my actions. I tried setting the api host or looking for an "insecure" invoke of the actions, but either the settings didnt help or I couldnt set them correctly. The repo I am working in is: https://github.com/D-Workz/imageManipulator

I am trying to invoke actions like: return new Promise(function (resolve, reject) { initDBsaveImage(image) .then (name => { let ow = openwhisk({ignore_certs:true}); ow.actions .invoke( {name: "watermark", result:true, param:{filename:name}} ) .then((result1) => { resolve({res:result1, hans:"hans"}); }) .catch(err =>{ reject({error:err}); }) }); })

this code can be found inside the repo: openwhisk/server/api/images.js in case there is more info needed let me know, thanks for feedback dennis

salehsedghpour commented 6 years ago

Due to an issue with the Node.js runtime in OpenWhisk, environment variables used by the constructor are not available until the invocation function handler is called. If you want to define the client instance outside this function, you will need to manually pass in the constructor options . ` var openwhisk = require('openwhisk'); // DOES NOT WORK! Environment parameters not set. var ow = openwhisk();

function action() { return ow.actions.invoke('sample') }

exports.main = action `

also this https://www.npmjs.com/package/openwhisk is useful.

D-Workz commented 6 years ago

Thanks a lot, this is the npm module I am using and inside their readme, they initialize openwhist only like: var openwhisk = require('openwhisk'); I will check.

D-Workz commented 6 years ago

Thanks a lot, this is the npm module I am using and inside their readme, they initialize openwhist only like: var openwhisk = require('openwhisk'); I will check.

I checked, it didnt work. I spoke with a collegue and he tried to, didnt work for him neither. He will upload example code soon.

Philipp-p commented 6 years ago

I'm using IBM Bluemix and try to execute two simple hello world functions in parallel my code is:

var openwhisk = require("openwhisk")

function main(params) {
    var ow = openwhisk()
    return ow.actions.invoke([
        {name: "hello-world-1", blocking: true, result: true}, 
        {name: "hello-world-2", blocking: true, result: true}
    ]).then(([result1, result2]) => { 
        return {
            "result1" : result1,
            "result2" : result2
        }});
}

This should return a JSON with the two results since this is a blocking call, but IBM Bluemix returns the activation ID instead as following:

Results:
 {
  "result1": {
    "activationId": "7aa5ccd00d2a4833a5ccd00d2ac833cf"
  },
  "result2": {
    "activationId": "6231457c732c4de0b1457c732cbde0ad"
  }
}
Logs:
 []

The version below returns the same:

function main(params) {
    var openwhisk = require("openwhisk")
    var ow = openwhisk()
    return ow.actions.invoke([
        {name: "hello-world-1", blocking: true, result: true}, 
        {name: "hello-world-2", blocking: true, result: true}
    ]).then(([result1, result2]) => { 
        return {
            "result1" : result1,
            "result2" : result2
        }});
}

So I'm wondering if I did something wrong in the invocation…

salehsedghpour commented 5 years ago

We spent many hours on this problem, but we couldn't find any solution for openwhisk library in node JS. Using openwhisk module in nodejs you can invoke functions successfully one by one and also we could not find any parallel invocation solution. Also we have found this for making async requests. Also we suggest to use java for your functions. there are too many libraries for creating async requests for Bluemix api.