Merge branch 'master' of github.ibm.com:nickm/owdbg
diff --git a/invoker/init.sh b/invoker/init.sh
old mode 100644
new mode 100755
index 4443d7d..4cb5a50
--- a/invoker/init.sh
+++ b/invoker/init.sh
@@ -1,4 +1,4 @@
#!/bin/bash
-wsk package create owdbg -p broker "https://owdb.mybluemix.net" -p action ""
+wsk package create owdbg -p broker "https://owdbg.mybluemix.net" -p action ""
wsk action create owdbg/invoker owdbg-invoker.js
diff --git a/invoker/owdbg-invoker.js b/invoker/owdbg-invoker.js
index 85c624f..920e067 100644
--- a/invoker/owdbg-invoker.js
+++ b/invoker/owdbg-invoker.js
@@ -1,7 +1,67 @@
+var request = require('request');
+
function main(params) {
- request({
- url: params.broker + "/invoke",
- json: true,
- body: params
+ return new Promise(function(resolve, reject) {
+ console.log('Invoking ' + JSON.stringify(params) + ' ' + JSON.stringify(whisk));
+
+ var opts = {
+ url: params.broker + '/invoke/begin',
+ method: 'POST',
+ headers: {
+ 'Accept': 'application/json'
+ },
+ json: true,
+ body: {
+ key: whisk.getAuthKey(),
+ action: params.action,
+ namespace: params.namespace,
+ params: params
+ }
+ };
+
+ console.log('with options ' + JSON.stringify(opts));
+
+ request(opts, function(err, response, body) {
+ if (err || response.statusCode != 200) {
+ if (err) console.log('OOPS1 ' + JSON.stringify(err));
+ else console.log('OOPS1b ' + JSON.stringify(response) + ' ' + JSON.stringify(body));
+ reject(body);
+ } else {
+ console.log('YUMMO ' + body);
+ var activationId = body.activationId;
+
+ console.log('Ok, so far so good with activationId ' + activationId);
+ var timer = setInterval(function() {
+ request({
+ url: params.broker + '/invoke/status/' + activationId,
+ method: 'GET',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json',
+ 'AuthKey': whisk.getAuthKey()
+ },
+ }, function(err, response, body) {
+ if (err || response.statusCode != 200) {
+ if (err) console.log('OOPS2 ' + JSON.stringify(err));
+ else console.log('OOPS2b ' + JSON.stringify(response));
+ reject(body);
+ } else {
+ try {
+ body = JSON.parse(body);
+ console.log("Result? " + body.result + " " + body);
+ if (body.result !== undefined) {
+ clearInterval(timer);
+ resolve(body);
+ }
+ } catch (e) {
+ console.log("Could not parse result");
+ reject(body);
+ }
+ }
+ });
+ }, 1000);
+ }
+ });
});
}
+//main({'broker':'https://owdbg.mybluemix.net','action':'foo/bar15'})
diff --git a/invoker/update.sh b/invoker/update.sh
new file mode 100755
index 0000000..47d4b6a
--- /dev/null
+++ b/invoker/update.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+wsk action update owdbg/invoker owdbg-invoker.js
diff --git a/nodejs/client/client.js b/nodejs/client/client.js
index 32f7d18..3cdcf35 100644
--- a/nodejs/client/client.js
+++ b/nodejs/client/client.js
@@ -1,22 +1,31 @@
-var WebSocket = require('ws');
+var WebSocket = require('ws'),
+ expandHomeDir = require('expand-home-dir'),
+ prompt = require('prompt');
-var host = "https://owdbg.mybluemix.net";
-var path = "/client/register";
+var host = 'https://owdbg.mybluemix.net';
+var path = '/ws/client/register';
var uri = host + path;
-console.log(uri);
var ws = new WebSocket(uri);
-var key = require('properties-parser').parse("~/.wskprops")["AUTH"];
+var key = require('properties-parser').read(expandHomeDir('~/.wskprops'))['AUTH'];
+
+console.log(uri);
+console.log(key);
ws.on('open', function open() {
- console.log("CONNECTION OPEN");
+ console.log('CONNECTION OPEN');
ws.send(JSON.stringify({
- type: "init",
+ type: 'init',
key: key
}));
});
+
+ws.on('close', function() {
+ console.log('CONNECTION CLOSED ' + JSON.stringify(arguments));
+});
ws.on('message', function(data, flags) {
+ console.log('MESSAGE ' + data + ' ||| ' + JSON.stringify(flags));
//
// flags.binary will be set if a binary data is received.
// flags.masked will be set if the data was masked.
@@ -24,13 +33,31 @@
try {
var message = JSON.parse(data);
switch (message.type) {
- case "invoke":
- console.log("INVOKE");
+ case 'invoke':
+ console.log('INVOKE');
console.log(JSON.stringify(message, undefined, 4));
- ws.send(JSON.stringify({
- type: "end",
- activationid: message.activationId
- }));
+
+ prompt.start();
+ prompt.get({
+ name: "result", description: "Return value",
+ conform: function(result) {
+ try {
+ JSON.parse(result);
+ return true;
+ } catch (e) {
+ console.log("NOPE " + result);
+ return false;
+ }
+ }
+ }, function(err, values) {
+ ws.send(JSON.stringify({
+ type: 'end',
+ key: message.key,
+ activationId: message.activationId,
+ result: values.result
+ }));
+ });
+
break;
}
} catch (e) {
diff --git a/nodejs/client/package.json b/nodejs/client/package.json
index ada7710..c169339 100644
--- a/nodejs/client/package.json
+++ b/nodejs/client/package.json
@@ -9,6 +9,8 @@
"author": "",
"license": "ISC",
"dependencies": {
+ "expand-home-dir": "0.0.3",
+ "prompt": "^1.0.0",
"properties-parser": "^0.3.1",
"ws": "^1.1.1"
}