Monday, 16 May 2016

IBM Bluemix Liberty Buildpack and Spring Boot Applications for "Auto-Scale" and "Monitoring" Services

Working with a customer last week we determined that Spring Boot applications using Liberty Buildpack failed to allow the "Auto-Scale" service to show up "Throughput" metrics and essentially mean we couldn't scale out or down application instances using Throughput metrics.

It turns out the Agent within the IBM Liberty buildpack isn't quite picking up application WAR files created using Spring Boot and hence "Monitoring and Analytics" and "Auto-Scale" service have limited functionality.

IBM Bluemix Services

To solve this we simply need to select the correct generated WAR file. Spring Boot along with Maven produces two WAR files as shown below when the application packaged as a WAR is packaged using "mvn package"


-rw-r--r--   1 pasapicella  staff  12341953 13 May 14:17 demo-sb-war-0.0.1-SNAPSHOT.war.original
-rw-r--r--   1 pasapicella  staff  17229369 13 May 14:17 demo-sb-war-0.0.1-SNAPSHOT.war

The WAR file "demo-sb-war-0.0.1-SNAPSHOT.war.original" is the one that is originally generated using maven and it's this file which we should push to IBM Bluemix using the IBM Liberty buildpack
If there’s a Main-Class defined in the manifest it attempts to start it up using the war file, thats the WAR file "demo-sb-war-0.0.1-SNAPSHOT.war". Once you push the version of our war without the Main-Class Manifest entry defined "demo-sb-war-0.0.1-SNAPSHOT.war.original" everything starts up correctly and is now happily recording both throughput and monitoring. If the WAR has a Main-Class app, the buildpack will only install the JDK for the app, and the app embeds Tomcat (by default for Spring Boot), so essentially the app is running on Tomcat; if it's a WAR app without Main-Class manifest entry, the buildpack installs Liberty as well and the app will run on Liberty.

Simply push the correct WAR file and your Spring Boot WAR files using Liberty Buildpack can take advantage of the Liberty Buildpack agent for extra "Monitoring" and "Auto-Scale" service support.

Screen Shots for Monitoring and Analytics service with Spring Boot WAR file

To verify this you can use the Basic Spring Boot Application at the following URL. It simply exposes one REST end point service displaying "helloworld".

Thursday, 12 May 2016

IBM Bluemix Dedicated/Local Status Page

With Bluemix Public you can view the status page which details all the runtimes and services and thier current status on all 3 PUBLIC regions. Those customers with Bluemix Dedicated or Local get a status page which includes a column on the status of thier Dedicated or Local instance.

To navigate to it perform the following steps:

1. Log into your Bluemix dedicated or local instance web console

2. Click on the Status link which is accessed through the profile icon on the top right hand corner

3. You will see a table as follows as well as status messages to indicate the current status of your own Bluemix Local or Dedicated Environment.

More Information

Tuesday, 10 May 2016

Telstra SMS API Swagger Enabled and deployable on Bluemix Sydney Public Instance

The following demo below can be used to expose the Telstra SMS Public API

You can deploy this to Bluemix by simply using the "Deploy to Bluemix" button as shown below.

Once deployed you have a Swagger UI enabled REST endpoints to consume as shown below.

Application once deployed on Bluemix

Swagger UI 

More Information

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.

Tuesday, 22 March 2016

IBM Bluemix NodeRed Demo using Twitter and Telstra SMS API

In this example I integrate Twitter Feed with Telstra SMS API to send an SMS based. It is based on the wrapper application which exposes the Telstra SMS API on Bluemix as per a previous Post.

It is assumed you have NodeRed NodeJS application running on Bluemix and are at the Editor as shown below.


1. Drag a "Social -> Twitter" node onto the editor
2. Double click on the Node and ensure you add your twitter credentials and authorize twitter to work with NodeRed itself. Also use a FOR TAG you wish to receive as part of the feed from twitter, in this demo it is "#telstrasmaapi-pas"

3. Once done it will look as follows

4. Drag a "Function -> HTTP Request" onto the editor
5. Double click on the HTTP Request item and add details as shown below.

Method = POST
URL = sent about telstra SMS API
Name = Any name of your choice

Note: Ensure URL is changed to the mobile number you wish to use and a BODY you wish to send as part of the TEXT.

6. Connect the twitter node to the HTTP Request node as shown below.

7. Click the "Deploy" button
8. Now log into your Twitter account and send a Tweet using the TAG you identified above as shown below. You must use the TAG name you said your looking for in this case "#telstrasmaapi-pas"

9. It should then send an SMS to the identified mobile number you used (Australia Mobiles Only) as shown below.

More Information

For more information on NodeRed use the link below.

Thursday, 18 February 2016

Bluemix CLI Installation and Use on Bluemix PUBLIC

We recently announced a seperate CLI for Bluemix known as "Bluemix CLI". You can find out more about it at the following link

The Bluemix command line interface (CLI) provides a set of commands that are grouped by namespace for users to interact with Bluemix. Some Bluemix CLI commands, which are called bx commands, are wrappers of existing cf commands, and others are unique for Bluemix. The information that follows lists all commands that are supported by Bluemix CLI and includes their names, options, usage, prerequisites, descriptions, and examples.

Download it from Here

The following shows how to use it once you installed it for you operating System.

1. Target End Point

pasapicella@pas-macbook-pro:~$ bluemix api
Invoke 'cf api'...

Setting api endpoint to

API endpoint: (API version: 2.40.0)
Not logged in. Use 'bluemix login' to log in.

2. Login as shown below

pasapicella@pas-macbook-pro:~$ bluemix login -u -p ****** -o -s dev
Invoke 'cf login -u -p ****** -o -s dev'...

API endpoint:

Targeted org

Targeted space dev

API endpoint: (API version: 2.40.0)
Space:          dev

3. Test the "bluemix info" call.

pasapicella@pas-macbook-pro:~$ bluemix info
Listing Bluemix info...

build:                      221004
region:                     us-south
version:                    2
description:                IBM Bluemix
user:                       b6c020b4-e11a-4630-a6a2-3f20fcec7f90
app_ssh_oauth_client:       ssh-proxy
logging_endpoint:           wss://
doppler_logging_endpoint:   wss://
api_version:                2.40.0
name:                       Bluemix

And my favorite which is the "bluemix list" command.

pasapicella@pas-macbook-pro:~$ bluemix list
Getting CF applications in org '' / space 'dev' as
Name                        Type             State     Instances   Memory   Disk   URLs
bluemix-apples-springboot   CF Application   STARTED   1/1         512M     1G
containerbridge             CF Application   STOPPED   0/1         64M      1M
pas-bmspringboot-demo       CF Application   STARTED   1/1         512M     1G
pas-dotnet-helloworld       CF Application   STARTED   1/1         256M     1G
pas-mjalbums                CF Application   STARTED   1/1         512M     1G
pas-mobile-web              CF Application   STARTED   1/1         512M     1G
pas-mongodb-local           CF Application   STARTED   1/1         450M     1G
pas-mysql-local             CF Application   STARTED   1/1         450M     1G
pas-postgresql-local        CF Application   STARTED   1/1         450M     1G
pas-sb-elastic              CF Application   STARTED   1/1         450M     1G
pas-SpringBootJARDemo       CF Application   STARTED   1/1         512M     1G
pas-tonynode                CF Application   STARTED   1/1         512M     1G
springboot-swagger-rest     CF Application   STARTED   1/1         512M     1G

Getting services in org '' / space 'dev' as
Name                              Type               Service           Plan               Bound CF Apps                                                            Last Operation
API Management-wv                 Service Instance   API Management    APImStandardPlan
BlazeMeter-92                     Service Instance   blazemeter        free-tier
cleardb-mysql                     Service Instance   cleardb           spark              pas-SpringBootJARDemo
Cloudant-NoSQL-DB-mel-training    Service Instance   cloudantNoSQLDB   Shared
dev_elephantsql                   Service Instance   elephantsql       turtle             bluemix-apples-springboot, pas-postgresql-local, pas-SpringBootJARDemo
jhipster-postgresql               Service Instance   elephantsql       turtle
pas-mongodb                       Service Instance   mongodb           100                pas-mongodb-local
pas-mongodb-lab                   Service Instance   mongolab          sandbox
pas-mysql                         Service Instance   cleardb           spark              containerbridge, pas-mjalbums, pas-mysql-local
pas-telstrademo-cloudantNoSQLDB   Service Instance   cloudantNoSQLDB   Shared
todo-mongo-db                     Service Instance   mongolab          sandbox
Twilio-7b                         Service Instance

Getting containers in org '' / space 'dev' as
No containers were found.

Getting container groups in org '' / space 'dev' as
Name                  Type              State             Instances   Memory   URLs
pas-etherpad1         Container Group   RESIZE_FAILED     0/1         256M
pas-sb-container      Container Group   UPDATE_COMPLETE   1/1         512M
pas-mysql-container   Container Group   CREATE_COMPLETE   1/1         512M

Getting VM groups in org '' / space 'dev' as
No VM groups were found.

Wednesday, 10 February 2016

Invoking the Billing API for Bluemix Public Organizations

The ability to view usage data from a billing perspective on IBM Bluemix Public is available as a REST based API. To use it follow the steps below.

In order to use the API you have to have the Billing Manager Role or be the Account Owner of the organization as shown below.


1. Log into the PUBLIC Bluemix region as shown below

pasapicella@Pas-MacBook-Pro:~$ cf login -u -p ***** -o -s dev
API endpoint:

Targeted org

Targeted space dev

API endpoint: (API version: 2.40.0)
Space:          dev

2. List all your Organizations as shown below

pasapicella@Pas-MacBook-Pro:~$ cf orgs
Getting orgs as

NAB Experimentation

3. Determine the GUID of the Org you wnat to get metering usage from

pasapicella@Pas-MacBook-Pro:~$ cf org --guid

4. Determine the region name for the PUBLIC instance your connected to as follows

pasapicella@Pas-MacBook-Pro:~$ curl
  "name": "Bluemix",
  "build": "221004",
  "support": "",
  "version": 2,
  "description": "IBM Bluemix",
  "authorization_endpoint": "",
  "token_endpoint": "",
  "min_cli_version": null,
  "min_recommended_cli_version": null,
  "api_version": "2.40.0",
  "app_ssh_endpoint": "",
  "app_ssh_host_key_fingerprint": null,
  "app_ssh_oauth_client": "ssh-proxy",
  "routing_endpoint": "",
  "logging_endpoint": "wss://",
  "doppler_logging_endpoint": "wss://",
  "console_endpoint": "",
  "region": "us-south"

5. Determine the OAUTH token for your connected session as follows

pasapicella@Pas-MacBook-Pro:~$ cf oauth-token
Getting OAuth token...

bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0ODAzOWM1My0yODZhLTQ5Y2YtYWIzYi0yNGVhZTY


At this point we are ready to invoke the Billing/Metering API. The format is as follows

Bluemix Endpoint:

  1. ORG_ID : Account GUID
  2. YYYY-MM: Year and month for which usage is required
Format as follows:

curl -v -X GET -H "Authorization: bearer {oauth-token}" "" | python -m json.tool
6. To invoke using curl we should do it as follows


pasapicella@Pas-MacBook-Pro:~$ curl -v -X GET -H "Authorization: bearer {oauth-token}" "" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying
* Connected to ( port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *
* Server certificate: DigiCert SHA2 Secure Server CA
* Server certificate: DigiCert Global Root CA
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0> GET /v2/metering/organizations/us-south:e270a605-978e-45fc-9507-00a50dec2469/usage/2016-02 HTTP/1.1
> Host:
> User-Agent: curl/7.43.0
> Accept: */*
> Authorization: bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0ODAzOWM1My0yODZhLTQ5Y2YtYWIzYi0yNGVhZTY4ZmFmYzIiLCJzdWIiOiJiNmMwMjBiNC1lMTFhLTQ2MzAtYTZhMi0zZjIwZmNlYzdmOTAiLCJzY29wZSI6WyJjbG91ZF9jb250cm9sbGVyLnJlYWQiLCJwYXNzd29yZC53cml0ZSIsImNsb3VkX2NvbnRyb2xsZXIud3JpdGUiLCJvcGVuaWQiXSwiY2xpZW50X2lkIjoiY2YiLCJjaWQiOiJjZiIsImF6cCI6ImNmIiwiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIiwidXNlcl9pZCI6ImI2YzAyMGI0LWUxMWEtNDYzMC1hNmEyLTNmMjBmY2VjN2Y5MCIsIm9yaWdpbiI6InVhYSIsInVzZXJfbmFtZSI6InBhc2FwaUBhdTEuaWJtLmNvbSIsImVtYWlsIjoicGFzYXBpQGF1MS5pYm0uY29tIiwicmV2X3NpZyI6IjVjOGMyODQ4IiwiaWF0IjoxNDU1MDU3NzQxLCJleHAiOjE0NTUxMDA5NDEsImlzcyI6Imh0dHBzOi8vdWFhLm5nLmJsdWVtaXgubmV0L29hdXRoL3Rva2VuIiwiemlkIjoidWFhIiwiYXVkIjpbImNsb3VkX2NvbnRyb2xsZXIiLCJwYXNzd29yZCIsImNmIiwib3BlbmlkIl19.EUEIXZ-XgxQbvTQnSgrToODHbNmKvhx0PtAp9CaiPTk
  0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0< HTTP/1.1 200 OK
< X-Backside-Transport: OK OK
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
< Date: Tue, 09 Feb 2016 22:54:44 GMT
< Etag: W/"3bcc-JgmFioUYI4v46tUXnGY1SQ"
< Vary: Accept-Encoding
< X-Cf-Requestid: 7b5cea8c-1a24-4114-44b2-a45e5d6e6f40
< X-Heap-Used: 136304240
< X-Instance-Id: 657c5e04638a49788a1053e7bb4e22ff
< X-Instance-Index: 5
< X-Node-Version: v0.10.41
< X-Powered-By: Express
< X-Process-Id: 93
< X-Response-Time: 3374.537ms
< X-Uptime: 16055
< X-Client-IP:
< X-Global-Transaction-ID: 750960253
{ [4055 bytes data]
100 15308    0 15308    0     0   3019      0 --:--:--  0:00:05 --:--:--  3967
* Connection #0 to host left intact
    "organizations": [
            "billable_usage": {
                "spaces": []
            "currency_code": "AUD",
            "id": "e270a605-978e-45fc-9507-00a50dec2469",
            "name": "",
            "non_billable_usage": {
                "spaces": [
                        "applications": [
                                "id": "121ccef0-2417-49c4-9f8f-47958b6d819d",
                                "name": "pas-bmspringboot-demo",
                                "usage": [
                                        "buildpack": "0154f971-ae72-4882-9695-bda6e31310b7",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "0154f971-ae72-4882-9695-bda6e31310b7",
                                            "name": "liberty-for-java_v2_1-20151006-0912"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "2d7dfb5f-0900-4c4a-a936-edaf3b7febb8",
                                "name": "pas-tonynode",
                                "usage": [
                                        "buildpack": "f0bff590-8b49-4c7d-bc4a-3ff24adcd411",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "f0bff590-8b49-4c7d-bc4a-3ff24adcd411",
                                            "name": "sdk-for-nodejs_v2_8-20151209-1403"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "3a962319-e7c4-456f-a2a4-b1f356a5d142",
                                "name": "pas-dotnet-helloworld",
                                "usage": [
                                        "buildpack": "0a566654-d250-463e-b413-67782482e903",
                                        "cost": 4.265998000402778,
                                        "quantity": 53.72793451388889,
                                        "runtime": {
                                            "id": "0a566654-d250-463e-b413-67782482e903",
                                            "name": "aspnet5-experimental"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "54629864-0e43-488f-bfca-3f9c9d806de6",
                                "name": "pas-mysql-local",
                                "usage": [
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 7.498824610083008,
                                        "quantity": 94.44363488769531,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "59f15702-1c42-444b-a1fb-94fbaf6cb27a",
                                "name": "pas-mobile-web",
                                "usage": [
                                        "buildpack": "0154f971-ae72-4882-9695-bda6e31310b7",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "0154f971-ae72-4882-9695-bda6e31310b7",
                                            "name": "liberty-for-java_v2_1-20151006-0912"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "926900dd-ccd7-4442-8f58-413df2bc0237",
                                "name": "pas-mongodb-local",
                                "usage": [
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 7.498824610083008,
                                        "quantity": 94.44363488769531,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "ab5a3278-a1c1-44f6-9113-713a4d800131",
                                "name": "bluemix-apples-springboot",
                                "usage": [
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "b448fd3a-5350-47d2-820d-7f739a057f22",
                                "name": "pas-SpringBootJARDemo",
                                "usage": [
                                        "buildpack": "eb0b11e9-8982-4b93-adcb-7350d0bf2ae4",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "eb0b11e9-8982-4b93-adcb-7350d0bf2ae4",
                                            "name": "liberty-for-java_v2_3-20151208-1311"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                "id": "b7d3d442-5546-41b4-b5c0-4ef737734e7b",
                                "name": "pas-sb-elastic",
                                "usage": [
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 7.498824610083008,
                                        "quantity": 94.44363488769531,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"

Wednesday, 27 January 2016

Adding community based Plugins to the CF CLI Tool

I needed a community based plugin recently and this is how you would add it to your CF CLI interface.

1. Add Community based REPO as shown below

$ cf add-plugin-repo community

2. Check available plugins from REPO added above

pasapicella@Pas-MacBook-Pro:~/ibm$ cf repo-plugins community
Getting plugins from all repositories ...

Repository: CF-Community
name                      version   description
Download Droplet          1.0.0     Download droplets to your local machine
Firehose Plugin           0.8.0     This plugin allows you to connect to the firehose (CF admins only)
doctor                    1.0.1     doctor scans your deployed applications, routes and services for anomalies and reports any issues found. (CLI v6.7.0+)
manifest-generator        1.0.0     Help you to generate a manifest from 0 (CLI v6.7.0+)
Diego-Enabler             1.0.1     Enable/Disable Diego support for an app (CLI v6.13.0+)

3. Install plugin as shown below

pasapicella@Pas-MacBook-Pro:~/ibm/$ cf install-plugin "Live Stats" -r community

**Attention: Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.**

Do you want to install the plugin Live Stats? (y or n)> y
Looking up 'Live Stats' from repository 'community'
7874156 bytes downloaded...
Installing plugin /var/folders/rj/5r89y5nd6pd4c9hwkbvdp_1w0000gn/T/cf-plugin-stats...
Plugin Live Stats v0.0.0 successfully installed.

4. View plugin commands

pasapicella@Pas-MacBook-Pro:~/ibm/$ cf plugins
Listing Installed Plugins...

Plugin Name       Version   Command Name                                           Command Help
IBM-Containers    0.8.788   ic                                                     IBM Containers plug-in

Live Stats        N/A       live-stats                                             Show browser based stats
active-deploy     0.1.22    active-deploy-service-info                             Reports version information about the CLI and Active Deploy service. It also reports the cloud back ends enabled by the Active Deploy service instance.

Monday, 25 January 2016

ServletContextAware Controller class with Spring

I rarely need to save state within the Servlet Context via an application scope, but recently I did and here is what your controller class would look like to get access to the ServletConext with Spring. I was using Spring Boot 1.3.2.RELEASE.

In short you implement the "org.springframework.web.context.ServletContextAware" interface as shown below. In this example we retrieve an application scope attribute.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.json.JsonParser;
import org.springframework.boot.json.JsonParserFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class CommentatorController implements ServletContextAware
    private static final Logger log = LoggerFactory.getLogger(CommentatorController.class);
    private static final JsonParser parser = JsonParserFactory.getJsonParser();

    private ServletContext context;

    public void setServletContext(ServletContext servletContext)
        this.context = servletContext;

    @RequestMapping(value="/", method = RequestMethod.GET)
    public String listTeams (Model model)
        String jsonString = (String) context.getAttribute("riderData");
        List<Rider> riders = new ArrayList<>();

        if (jsonString != null)
            if (jsonString.trim().length() != 0)
                Map<String, Object> jsonMap = parser.parseMap(jsonString);
                List<Object> riderList = (List<Object>) jsonMap.get("Riders");

                for (Object rider: riderList)
                    Map m = (Map) rider;
                            new Rider((String)m.get("RiderId"),

                //"Riders = " + riders.size());
                model.addAttribute("ridercount", riders.size());
            model.addAttribute("ridercount", 0);

        model.addAttribute("riders", riders);

        return "commentator";