apache / openwhisk-client-js Goto Github PK
View Code? Open in Web Editor NEWJavaScript client library for the Apache OpenWhisk platform
Home Page: https://openwhisk.apache.org/
License: Apache License 2.0
JavaScript client library for the Apache OpenWhisk platform
Home Page: https://openwhisk.apache.org/
License: Apache License 2.0
Is there an option similar to the -r
in the wsk
cli that returns only the result of the invocation (used together with -b
or blocking = true
)? I'd use it all the time :)
On a related note, I don't think I understand how this example in the readme works:
const blocking = true
const params = {msg: 'this is some words to reverse'}
ow.actions.invoke({actionName, blocking, params}).then(result => {
console.log('here's the reversed string', result.reversed)
}).catch(err => {
console.error(failed to invoke actions', err)
})
IIUC the result of the invocation will contain not only the "result", but all the other meta data (e.g., duration, name, annotations, etc.) and I would expect result.reversed
to be undefined. New to js, what am I missing?
try calling ow.packges.get({name:"foo", junk: "SOME VERY LARGE PAYLOAD"})
if the payload is too big (in my case, 330k), you will get back an odd SSL error:
Error encountered calling OpenWhisk: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line"
action.js does not allow to set {"parameters"}
wsk -v action create --kind nodejs:6 -p param pval helloAction7 helloAction.js
...
Body sent:
{"parameters": [{"value": "pval", "key": "param"}], "exec": {"kind": "nodejs:6", "code": "function main() {\n return {payload: 'Hello world'};\n}\n"}}
Use environment variable to turn on help debugging by dumping more information about API requests to the console.
Minor release, rather than patch, as #99 is a new feature.
npm version minor
to bump package.json
to 3.13.0Need to write up these instructions in the repository.
The README is light on examples of using the library for common tasks, focusing more the API documentation.
We should re-work the file to add more of these common usecases to help developers.
People have recently been asking about retrieving package details, including credentials, invoking actions and triggers amongst others.
currently nodejs is hardcoded
return { exec: { kind: 'nodejs', code: options.action } }
https://github.com/openwhisk/openwhisk-client-js/blob/master/lib/actions.js#L79
Patch release to resolve bug in 3.13.0
action.get
API (#105)npm version patch
to bump package.json
to 3.13.1TypeScript definitions at @types/openwhisk would be helpful.
A local deployment of openwhisk generally uses a self signed certificate. The base request
operations should permit an additional configuration parameter to disable rejecting unauthorized TLS. This is particularly helpful for integration testing against a local deployment.
wsk
cli allows setting new default parameters without updating the action body. This library treats the action
parameter as mandatory for update operations.
Need to update the actions.update
method to support this.
Hi I'm trying the sample code:
create trigger feed from alarm package
// for example...
const params = {cron: '*/8 * * * * *', trigger_payload: {name: 'James'}}
const name = '/whisk.system/alarms/alarm'
const trigger = 'alarmTrigger'
ow.feeds.create({name, trigger, params}).then(package => {
console.log('alarm trigger feed created')
}).catch(err => {
console.error('failed to create alarm trigger', err)
})
This is giving me a failure:
failed to create alarm trigger { BaseOperationError: Action invocation failed, API returned error code. Check syntax errors? Missing error message.
at Client.handle_errors (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/openwhisk/lib/client.js:102:13)
at rp.catch.err (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/openwhisk/lib/client.js:43:38)
at tryCatcher (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/promise.js:510:31)
at Promise._settlePromiseAt (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/promise.js:584:18)
at Promise._settlePromises (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/promise.js:700:14)
at Async._drainQueue (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/async.js:15:14)
at runCallback (timers.js:666:20)
at tryOnImmediate (timers.js:639:5)
at processImmediate [as _immediateCallback] (timers.js:611:5)
name: 'BaseOperationError',
message: 'Action invocation failed, API returned error code. Check syntax errors? Missing error message.',
error:
{ duration: 109,
name: 'alarm',
subject: 'whisk.system',
activationId: '20ae80ca53c24fa3886fb9a23e2ba16c',
publish: false,
annotations: [ [Object], [Object] ],
version: '0.0.5',
response: { result: [Object], success: false, status: 'application error' },
end: 1492115313980,
logs: [],
start: 1492115313871,
namespace: 'whisk.system' } }
Can you let me know why this is not working? I am able to use the sample snippets to create an action without any problems but I'm not able to do it for an alarm
When running test code for openwhisk actions it is often necessary to ignore certificates since it is running openwhisk in travis. It looks like the other constructor parameters are already handled this way.
right now, i find that my code is littered with things like:
Promise.all(triggers.map(trigger => ow.triggers.invoke({ triggerName: trigger.name })))
it seems preferable to me to write:
Promise.all(triggers.map(ow.triggers.invoke))
but i can't, because the get
and invoke
operations require triggerName
, or actionName
or packageName
or ruleName
rather than just name
.
on top of this, having an invokeAll
or getAll
command would be nice, so that i could write
ow.packages.get('foo').then(package=>package.actions).then(ow.actions.getAll)
and having a simple projection mechanism would then simplify this to:
ow.packages.getActions('foo').then(ow.actions.getAll)
compare this to what we have now:
ow.packages.get('foo').then(package=>package.actions)
.then(Promise.all(triggers.map(trigger=>ow.triggers.invoke({triggerName:trigger.name})))
request-promise depends on request, which is very slow to load: request/request#2261
that issue aligns with my experience. namely, that request-promise, due to request, can take anywhere from 120-250ms to require
on mac and linux.
on windows 10, apparently due to windows defender, it can take 10 times as long! sometimes multiple seconds!
an alternative is needle: https://www.npmjs.com/package/needle
quick experiments show that needle indeed loads in about 1/4th the time. these numbers from macos 10.12.6, node 8.5.0: fairly stably needle loads in 30-32ms, and request-promise in 110-120ms.
in more realistic scenarios, i've seen request-promise routinely take close to 300ms on macos, and 1-3 seconds on windows 10. the fall creators update of windows 10 seems to have made this much worse.
the patch for this is straightforward, as needle mostly obeys the same schema as rp.
rather than init the api like this:
var ow = openwhisk({api: 'https://openwhisk.ng.bluemix.net/api/v1/', api_key: '...', namespace: 'default_namespace'});
I'd like to suggest a little bit of convenience:
var ow = openwhisk({apihost: 'openwhisk.ng.bluemix.net', api_key: '...', namespace: 'default_namespace'});
where apihost
allows one to just provide either the host
or host:port
.
this can be split to determine protocol as in
var edgeHostParts = apihost.split(':');
var protocol = (edgeHostParts.length >= 2 && edgeHostParts[1] == '443') ? 'https' : 'http';
api = protocol + '://' + apihost + '/api/v1/';
If the platform returns an API error, the library parses any error text and wraps it in a generic error response.
Here's an example of creating an action for an invalid namespace.
{
"error": {
"name": "BaseOperationError",
"message": "OpenWhisk authentication failed, check API key? The supplied authentication is not authorized to access this resource.",
"error": {
"error": "The supplied authentication is not authorized to access this resource.",
"code": 5170570
}
}
}
This does not give the developer much help to understand where the error occurred and why.
Ideas for improving this from @starpit
BaseOperationError
.In order for a dev to run the integration tests, one has to create seed artifacts manually. Further, if a test fails, its transient artifacts are not reclaimed. The integration tests should perform all required setup and cleanup on termination.
In the test for invoking an action using a JSON string (actions.test.js
, line 413 ff) the JSON string is defined in a payload
field, rather than in the params
field. Furthermore, it is an empty object, which is equal to the default when no params are provided - so the test will always succeed.
ShortDesc
represents both request response type as well as request body, which does not have name
field.
I was getting errors trying actions.invoke but not getting any error stack back (using .then().catch(err)). actions.list works fine which means my base setup of API key etc was fine. I added a line of instrumentation into base_operation.js handle_errors() which showed that OW was returning a 405 method not allowed.
In-package actions have a slash in their namespace. The action.get code is not using encodeURIComponent, thus resulting in erroneous 404s.
Using 'openwhisk' in context of a React app (created with create-react-app
) is causing react-scripts build
to fail due to ES5 incompatibility.
$ npm run build
> [email protected] build /Users/guest/Downloads/my-app
> react-scripts build
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/openwhisk/lib/names.js:6
Read more here: http://bit.ly/2tRViJ9
API endpoint is being removed as per the discussion in:
apache/openwhisk#3153
This should be replicated in the client library and published as a new major version.
Add support for routes.create({swagger:...})
Hi folks!
I deploy OpenWhisk locally on minikube and it's my action:
const openwhisk = require('openwhisk');
function main(params){
return new Promise((resolve, reject) => {
ow.actions.list().then(resolve);
});
}
Result of invoke it is error:
Unhandled rejection Error: Error encountered calling OpenWhisk: Error: getaddrinfo ENOTFOUND nginx.openwhisk nginx.openwhisk:443
Maybe someone experienced similar issue and can help?
Cheers ๐ฅ
on error, the HTTP statusCode is swallowed up into strings. it is helpful to have direct access to the statusCode integer
When creating an action it would be great to be able to provide default parameters.
Once the following PRs have merged, the next release can drafted and made available on this repo. npmbot should automatically publish to NPM.
routes()
methods. API name parameter and swagger route definition now supported. Route retrieval method included. (#69, #70, #71)^^ @csantanapr
the leading slash in a fully qualified name is optional but appears to break the library here if it's not specified.
for reference, see: apache/openwhisk#2328
Whisk's CLI returns parameters bound to an action when using "wsk action get" (in an array called "parameters" that has objects storing each parameter's name and value).
But the parameter information is gone in the nodeJS library when using actions.get - the parameters array is always empty (or only has an "_actions" object for a sequence action).
Hi, I'm invoking many actions from inside a parent action over a long (3-5 mins) period of time. We're running against an on-premises OpenWhisk cluster. The code invoking the actions is along the lines of:
const invokeAction = (openwhisk, v) => {
return openwhisk.actions.invoke({
name: "my-action",
params: { param: "val" },
insecure: true,
blocking: true //different error depending on whether true or false
});
};
const ow = openwhisk({ ignore_certs: true });
rxObservableEmittingMySqlData
.bufferCount(1000) //buffer to accomodate 1MB max message size
.zip(Observable.timer(0, 800) x => x) //this will add a .8s delay before each action invocation - without this, I get "too many actions for namespace"
.flatMap(v => Observable.fromPromise(invokeAction(ow, v)), 30) //where 30 is maximum concurrent in-flight requests - these problems occur regardless of this value
.subscribe(console.log, reject, resolve);
Error If blocking = true:
"response": {
"status": "application error",
"statusCode": 0,
"success": false,
"result": {
"error": {
"error": {
"code": "EPIPE",
"errno": "EPIPE",
"syscall": "write"
},
"message": "Unknown Error From API: Error: write EPIPE",
"name": "OpenWhiskError"
}
}
}
Error If blocking = false:
{"fatal":true, "code": "PROTOCOL_CONNECTION_LOST"}
Even though more OW instances were added to our cluster, it also doesn't seem like the actions aren't completing quickly enough (even when I remove/reduce my throttling), and even if not for these errors I'd be hitting the 5 minute timeout.
Is this the wrong approach for handling millions of MySQL records with OpenWhisk? Is OW even the right tool for the job?
we inherit needle's default connection-open timeout of 10 seconds. this seems to result in socket hangup errors. i'm not sure what the right solution is here, but wanted to raise awareness of it.
this seems to happen often enough to be of note, when talking to ibm cloud functions
Greetings
I am looking into the JS api and have a question.
var options = {apihost: 'openwhisk.ng.bluemix.net', api_key: '...'};
var ow = openwhisk(options);
Is it possible to have multiple 'ow' objects , with different API key/Namespace combos in the same Node.js application?
Does the library have any global/singleton properties that preclude that kind of usage?
Thanks
pj
action being invoked:
function main(args) {
return new Promise((resolve, reject) => { reject({ statusCode: 404 }) };
}
The invocation of this action through the REST API produces this response:
{
"error": {
"statusCode": 404
}
}
However OpenWhisk Client expect the statusCode to be at the top-level, and I think we should change this behavior to also support OpenWhisk error response.
count=true|false is a valid query parameters for entity (actions, triggers, rules, activations) listing
specially handy for counting activations and combining with since for a specific action:
ow.activations.list({
name: actionName,
count: true,
since: since
}
Ref: https://gist.github.com/csantanapr/ce5856f9ad9bb5a18a1882969569048d
recently, the openwhisk backend introduced a (non-semver!) breaking change to the rule creation API. now, the action and trigger fields must be fully qualified, as in they must include a namespace.
suggestion: if the action or trigger do not have a slash in them, then prepend '/_/'
?
at some point a change was made that breaks code that relies on the global namespace
field, i.e. the one provided with the openwhisk constructor.
now, the namespace is either the per-request options.namespace
or names.default_namespace()
, the latter of which does not pay attention to the global option:
const default_namespace = () => {
return process.env['__OW_NAMESPACE'] || '_'
}
this breaks our code. luckily we are still pre-production, or this would've been a nightmare.
perhaps this: 9269e96
Travis is currently failing for this repo due to a trigger test failure.
Test output:
โ triggers โบ fire a trigger
t.true(update_result.hasOwnProperty('activationId'))
|
false
1. triggers โบ fire a trigger
AssertionError: false === true
triggers.test.js:112:7
process._tickCallback (internal/process/next_tick.js:109:7)
Minor release, rather than patch, as #88 is a new feature.
npm version minor
to bump package.json
to 3.11.0Need to write up these instructions in the repository.
Is it possible that the current test suite has no coverage of error handling? Because
earlier versions of PR #78 didn't do proper error handling, but all of the integration and functional tests passed
with proper error handling, the PR still fails, because the codecov tool complains that the lines having to do with error handling (in my update) are not covered by tests!
This client library currents copies the the CLI tool in interacting with the API GW service through web action proxies, rather than interfacing with the APIGW API.
Migrating the implementation to talk directly to the APIGW is a better option. This will provide greater flexibility for the client library and stops using undocumented web actions.
The CLI and OW web UIs add an annotation to triggers to associate them with feeds when creating new trigger feeds.
This means that when that trigger is deleted, the feed can be notified.
The SDK does not implement this behaviour. This means that if someone creates a new trigger feed, deletes it and tries to re-create it, it may fail based on the implementation of the feed provider.
The behaviour of the SDK should mirror the other OW tools. It should be possible to disable this behaviour using a parameter option, although it defaults to on.
Setup a Travis build to periodically run integration test against an openwhisk deployment (or the publicly hosted service).
OpenWhisk's API Gateway service has moved from "experimental" to "release". The API path has changed between the versions.
The library has been updated to support both API endpoints recently, using a configuration parameter to control which one to use.
We need to remove the old API from the library. This will be a breaking change and need to be a major release.
npm version patch
to bump package.json
to 3.14.0A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.