Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement websocket/send action #484

Closed
wants to merge 1 commit into from

Conversation

jberstler
Copy link

@jberstler jberstler commented May 20, 2016

This creates a new package called websocket

Implementation is in Node.JS which required adding the ws package to the Node.JS runtime (see #523).
Added unit tests which confirm that a message can be sent to a running WebSocket, as well as handle various error cases.

@jberstler jberstler changed the title Implement websocket/send action WIP: Implement websocket/send action May 20, 2016
@jberstler jberstler mentioned this pull request May 20, 2016

public TestWebSocketServer(InetSocketAddress address) {
super(address);
// TODO Auto-generated constructor stub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all TODO comments ... replace with appropriate comments if needed?

@jberstler jberstler force-pushed the websocket-node branch 4 times, most recently from a658722 to e758049 Compare May 20, 2016 19:19
@@ -52,6 +52,7 @@ swagger-tools@0.8.7 \
tmp@0.0.28 \
watson-developer-cloud@1.4.1 \
when@3.7.3 \
ws@1.1.0 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will require updating reference.md and generating pr to bluemix docs @csantanapr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjustin-ibm go ahead and add the new npm package in both places

  1. docs/reference.md#runtime-environment
  2. openwhisk/openwhisk_reference.md#runtime-environment

@jberstler jberstler force-pushed the websocket-node branch 4 times, most recently from e69758f to 06a6ad3 Compare May 31, 2016 15:41
@jberstler
Copy link
Author

@rabbah The code is ready and based on the history of the catalog folder you seem like the right person to assign this to. The only question I have is whether or not this one action warrants an entirely new package.

@jberstler jberstler force-pushed the websocket-node branch 2 times, most recently from ee9e025 to d965375 Compare May 31, 2016 16:05
@jberstler jberstler changed the title WIP: Implement websocket/send action Implement websocket/send action May 31, 2016
@rabbah
Copy link
Member

rabbah commented May 31, 2016

Thanks @bjustin-ibm - now regretting using bash for installing packages ;)

var WebSocket = require('ws');
var ws = new WebSocket(uri);

ws.on('open', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this exploit a warm action? hmm...

@csantanapr
Copy link
Member

@rabbah about

Thanks @bjustin-ibm - now regretting using bash for installing packages ;)

Should we create an issue in the backlog for switching to a cross-platform scripting languages (i.e. nodejs)?

val run = wsk.action.invoke(websocketSendAction, Map("uri" -> badURI.toString.toJson, "payload" -> "This is the message to send".toJson))
withActivation(wsk.activation, run) {
activation =>
activation.fields("response").asJsObject.fields("success").toString should be("false")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the success property is invariably of type boolean hence should check against false.toJson instead (same above line 81).

@rabbah
Copy link
Member

rabbah commented May 31, 2016 via email

@jberstler jberstler changed the title Implement websocket/send action WIP: Implement websocket/send action May 31, 2016
@jberstler
Copy link
Author

IPGA 64

@rabbah I believe this is ready to merge.

@jberstler jberstler changed the title WIP: Implement websocket/send action Implement websocket/send action Jun 15, 2016
-a description "Utilities for communicating with WebSockets"

waitForAll

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@starpit please review annotations below.

Copy link
Contributor

@starpit starpit Jun 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. field-level descriptions, e.g. what does the uri or payload field mean? "description": "the uri blah..."
  2. i would guess that we should mark the uri field as bindTime? which means that the package-level metadata needs a "parameters" annotation [ { "key": "parameters": value: [{ "name": "uri", bindTime: true, required: true } }]
  3. we don't have an established schema for this yet, but the package also needs these annotations
    • service icon
    • branding text e.g. "Cloudant", unicode rather than graphical, but encodes whatever preferred capitalization the provider uses, service marks, etc.
    • branding icon (optional, e.g. if the service provider has a "Cloudant[TM]" wide-form branding icon)
    • link to service provider's home page
    • link to service instantiation broker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: separability concerns, yes. we can do 1-2, and the 3 as two separate tasks, but we have to make sure that we don't keep kicking the 3 can down the road.

@rabbah
Copy link
Member

rabbah commented Jun 15, 2016

Are the concerns under separable? That requires systematically addressing all the packages since none have these. Whereas 1-2 strike me as in scope.

@@ -0,0 +1,29 @@
#!/bin/bash
#
# use the command line interface to install Weather.com package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weather.com ? must be typo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed a copy-and-paste-o. Thanks for catching it.


createPackage websocket \
-a description "Utilities for communicating with WebSockets"
-a parameters '[ {"name":"uri", "required":true, "bindTime":true} ]'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@starpit Please verify this is what you were asking for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, @bjustin-ibm awesome, thanks!!

@jberstler
Copy link
Author

Ok @rabbah... for reals this time 😏 I think this is ready.

ws.send(payload, function(error) {
if (error) {
console.log("Error received communicating with websocket: " + error);
whisk.error(error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ws.close() on error? (i can add this as i merge if you confirm.)

This creates a new package called websocket
Implementation is in Node.JS and required added the ws package to the Node.JS runtime.
Added unit tests which confirm that a message can be sent to a WebSocket running on Bluemix, as well as handle various error cases.
@starpit
Copy link
Contributor

starpit commented Jun 20, 2016

@bjustin-ibm hiya, do the parameters have any sensitive information? e.g. does the uri contain passwords?

@jberstler
Copy link
Author

does the uri contain passwords

@starpit Like any action parameters, they contain exactly what the caller puts in them, and so it is not generally predictable whether or not they will contain sensitive information. In terms of websockets, I don't believe it is necessarily true that the URI will include authentication information, though I suppose it could.

@starpit
Copy link
Contributor

starpit commented Jun 20, 2016

ok cool, thanks for the great summary! does a websocket have any sort of lifecycle, e.g. account registration, credentialing, ...?

@jberstler
Copy link
Author

does a websocket have any sort of lifecycle, e.g. account registration, credentialing, ...?

@starpit websocket is only a communication protocol for transferring arbitrary data, and is not specific to any particular application or service. This OW action is only meant to act as a client to send data to a running websocket server, and will not act as a websocket server.

To answer your question more directly, things like account registration or credentialing could only be accomplished with how a websocket server interprets the data sent to it by clients, and is not something this OW action would actively facilitate or be responsible for.

@starpit
Copy link
Contributor

starpit commented Jun 20, 2016

ok thanks @bjustin-ibm

as much as possible, i think we'd like to avoid the "hey this is tantalizing and sounds cool, but to use it you'll need to do stuff we don't tell you about".

e.g. mobile developer wants a websocket server, see this... after all, whisk is trying to help people avoid setting up servers!

maybe we can belay this reaction by naming the package or action ... somehow?

echo Installing WebSocket package.

createPackage websocket \
-a description "Utilities for communicating with WebSockets"
Copy link
Author

@jberstler jberstler Jun 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@starpit The "websocket" package only has one action named "send". I think the description of the send action (below) makes it pretty clear that it is intended for talking to a websocket server (as opposed to acting as one). The only potentially ambiguous text I could find is the description on the line above. I intentionally left it generic to allow us to add more actions in the future, but if you have a suggestion for making this more clear, we can certainly consider that.

Apart from that, I can't see how naming the package anything but "websocket" could be an improvement, as this term accurately and succinctly describes the specific kind of communication facilitated by the package.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to make this "send" action part of some other package (which? I have no idea) and rename the action to something like "websocketSend". That being said, I believe the option of adding this to an existing package was already discussed in #393.

@rabbah
Copy link
Member

rabbah commented Jun 20, 2016

Rebased and merged as 89f2b01.

@rabbah rabbah closed this Jun 20, 2016
@jberstler jberstler deleted the websocket-node branch June 21, 2016 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants