Monday, 11 April 2016

Taking IBM Bluemix OpenWhisk for a Test Drive

OpenWhisk is a new event-driven platform that lets developers quickly and easily build feature-rich apps that automatically trigger responses to events. To read more about it view the link below. In this simple example we will explore it it's use from IBM Bluemix by returning Todays date.


1. Login to Bluemix using

2. Click on "Try OpenWhisk" as shown below

3. Once logged in to the new Bluemix Console you should see a screen as follows

At this point we can only use OpenWhisk from the command line

4. Click on "Configure CLI" button to install it

5. Once installed you can verify it's installed as follows

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk/actions$ wsk --help
usage: wsk [-h] [-v] [--apihost hostname] [--apiversion version]

OpenWhisk is a distributed compute service to add event-driven logic to your

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         verbose output
  --apihost hostname    whisk API host
  --apiversion version  whisk API version

available commands:
    action              work with actions
    activation          work with activations
    namespace           work with namespaces
    package             work with packages
    rule                work with rules
    trigger             work with triggers
    sdk                 work with the SDK
    property            work with whisk properties
    list                list all triggers, actions, and rules in the registry

Learn more at fork on GitHub All trademarks are the property of their
respective owners.

6. Now lets Set your OpenWhisk Namespace and Authorization Key. They are provided when you are taken to the install CLI for OpenWhisk, I simply create a script for this as follows

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk$ cat set-namespace-key
wsk property set --auth your-rather-long-key --namespace ""

Once run you get output as follows

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk$ ./set-namespace-key
ok: whisk auth set
ok: namespace set to

7.  Now create an OpenWhisk JavaScript function as shown below


 * Todays Date as an OpenWhisk action.
function main(params) {
    var currentTime = new Date();
    return {payload:  'Todays date is, ' + currentTime + '!'};

8. Create the OpenWhisk action as shown below

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk/actions$ wsk action create todaysdate todaysdate.js
ok: created action todaysdate

9. Invoke the action as shown below

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk/actions$  wsk action invoke todaysdate --blocking --result
    "payload": "Todays date is, Mon Apr 11 2016 10:14:56 GMT+0000 (UTC)!"

10. Invoke it again this displaying the full Response Object as shown below

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk/actions$  wsk action invoke todaysdate --blocking
ok: invoked todaysdate with id dbb447b65b06433a8b511187011f5715
    "result": {
        "payload": "Todays date is, Mon Apr 11 2016 10:19:07 GMT+0000 (UTC)!"
    "status": "success",
    "success": true

11. We can view our current actions using a command as follows, you can see we have added the "todaysdate" function

pasapicella@pas-macbook-pro:~/ibm/bluemix/openwhisk/actions$ wsk list
entities in namespace:
/                            private
/                                     private

12. Now lets return to the Bluemix Web Console and click on "Inspect activity metrics and logs"
Here you can view what you have invoked

There is clearly more to OpenWhisk then just this BUT for more information the IBM Bluemix docs have some more demos to try out.

Thursday, 7 April 2016

Tomcat Runtime added to Web Console of IBM Bluemix

I almost always use the tomcat buildpack within IBM Bluemix for my Java based applications. By default IBM bluemix will use the IBM Liberty buildpack for java apps unless you specify otherwise. The buildpacks on Bluemix can be viewed using "cf buildpacks" and the tomcat buildpack is referred to as "java_buildpack"

So to use the tomcat buildpack in a manifest.yml you would target it as follows

- name: pas-javaapp
  memory: 512M
  instances: 1
  host: pas-javaapp
  path: ./passapp.war
  buildpack: java_buildpack

Now the Web Console catalog for "Runtimes" shows Tomcat for those creating an application from the Console itself. This was done for those who wish to use Tomcat on Bluemix can cleary see it's an option as per the screen shot below and don't have to start with the Liberty Buildpack if they don't wish to do so.