Search This Blog

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.

https://developer.ibm.com/open/openwhisk/

Steps

1. Login to Bluemix using http://bluemix.net

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]
           {action,activation,namespace,package,rule,trigger,sdk,property,list}
           ...

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

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,activation,namespace,package,rule,trigger,sdk,property,list}
    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 https://developer.ibm.com/openwhisk fork on GitHub
https://github.com/openwhisk. 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 "pasapi@au1.ibm.com_dev"

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 pasapi@au1.ibm.com_dev


7.  Now create an OpenWhisk JavaScript function as shown below

todaysdate.js

/**
 * 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
response:
{
    "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: pasapi@au1.ibm.com_dev
packages
actions
/pasapi@au1.ibm.com_dev/todaysdate                            private
/pasapi@au1.ibm.com_dev/hello                                     private
triggers
rules


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.

https://new-console.ng.bluemix.net/docs/openwhisk/index.html

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

applications:
- name: pas-javaapp
  memory: 512M
  instances: 1
  host: pas-javaapp
  domain: mybluemix.net
  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.