Friday, 15 May 2015

ASP.NET 5 IBM Bluemix Demo

The following demo is using the same code IBM Bluemix created when using the Experimental ASP .NET 5 runtime. This can be done using the CF CLI where we clone the project from jazzhub git repository.


1. Clone a sample project as follows

pas@Pass-MacBook-Pro:~/bluemix-apps/DOTNET$ git clone
Cloning into 'pas-donet-demo'...
remote: Counting objects: 24, done
remote: Finding sources: 100% (24/24)
remote: Total 24 (delta 0), reused 24 (delta 0)
Unpacking objects: 100% (24/24), done.
Checking connectivity... done.

2. cd pas-donet-demo

3. Edit manifest.yml to use a unique host name

- disk_quota: 1024M
  host: pas-donet-demo
  name: pas-donet-demo
  path: .
  instances: 1
  memory: 256M

4. Deploy as follows

pas@Pass-MacBook-Pro:~/bluemix-apps/DOTNET/pas-donet-demo$ cf push -f manifest.yml
Using manifest file manifest.yml

Creating app pas-donet-demo in org / space dev as

Creating route

Binding to pas-donet-demo...

Uploading pas-donet-demo...
Uploading app files from: .
Uploading 19.9K, 15 files
Done uploading

Starting app pas-donet-demo in org / space dev as
-----> Downloaded app package (20K)

  * WARNING: This is an experimental buildpack. It is not supported.     *
  *          Do not expect it to work reliably. Please, do not           *
  *          contact support about issues with this buildpack.           *
-----> Extracting mono
Using mono mono-lucid64-3.12.1.tar.gz
-----> Adding Nowin.vNext
       Copied 3 files from /var/vcap/data/dea_next/admin_buildpacks/2b638599-b3da-44e9-86f0-6b2f513daa4f_87e6c7503171fc3d6db9055873938657ca3ea6c6/resources/Nowin.vNext to /tmp/staged/app/src


       Total time 361ms
-----> Moving files in to place
       Copied 1865 files from /app/mono to /tmp/staged/app
-----> Saving to buildpack cache
       Copied 628 files from /tmp/staged/app/.k to /tmp/cache
-----> Writing Release YML

-----> Uploading droplet (136M)

0 of 1 instances running, 1 starting
1 of 1 instances running

App started


App pas-donet-demo was started using this command `cd src/samplemvc; sleep 999999 | k cf-web`

Showing health and status for app pas-donet-demo in org / space dev as

requested state: started
instances: 1/1
usage: 256M x 1 instances
last uploaded: Fri May 15 11:38:29 UTC 2015

     state     since                    cpu    memory           disk           details
#0   running   2015-05-15 09:40:30 PM   0.1%   168.9M of 256M   369.8M of 1G

5. Finally access the application using the route as shown below.


Friday, 8 May 2015

Accessing your Cloud Integration API end point from Javascript

I previously created a Cloud Integration endpoint using a Bluemix Application Itself. The application was a Sprint Boot application exposing a single REST endpoint. The screen shots below show what has been added to the Catalog as private API's in my organization. The demo below shows how to access the API using a Javascript client in this case NodeJS from the command line.

Here is how we can access that API using a Javascript SDK which we can download from the Cloud Integration service itself.

1. Click on the "Cloud Integration" service itself
2. Select your API endpoint
3. Under "Access SDK's" select "Javascript SDK" and unzip it onto your file system

Note: We will use NodeJS to run this code

4. Install the required packages using the following command

> npm install

5. Ensure you import the API module as follows , as we are not using NPM for the API itself. The code is commented out so simply add it back in and change the reference to use "sdk"

// Alternatively, if you are not using npm, then import the API class module.
var sdk = require('./lib/SpringBootHelloWorldAPI.js');
console.log("Imported API class module ok");

6. The full code is as follows which enables us to display the function call output within the method itself. There are many ways to do this but just so we invoke it this is good enough.

// Import the SDK package.
//var sdk = require('SpringBootHelloWorldAPI');

// Alternatively, if you are not using npm, then import the API class module.
var sdk = require('./lib/SpringBootHelloWorldAPI.js');
console.log("Imported API class module ok");

// Create a new instance of the API class.
var api = new sdk.SpringBootHelloWorldAPI();

// Set the API credentials.
// TODO: replace username and password with those from the API definition.
//api.setAPICredentials('username', 'password'); // The API credentials are optional.

// Example for the HelloWorldService operation.
function example_HelloWorldService() {

 // Set up the request parameters for the HelloWorldService operation.
 var request = {};

        console.log("About to call service method");

 // Invoke the HelloWorldService operation.
 api.HelloWorldService(request, function (error, callback) {

  // Handle any errors from the HelloWorldService operation.
  if (error) {
   throw error;

                func_result = callback;




7. Edit ./lib/SpringBootHelloWorldAPI.js and change the final line of JavaScript code to be as follows

module.exports.SpringBootHelloWorldAPI = SpringBootHelloWorldAPI;

8. Finally call the API using the Javascript client as follows
pas@Pass-MacBook-Pro:~/bluemix-apps/cloud-integration/client-api/springboot-hello/javascript$ node example.js
Imported API class module ok
About to call service method
{ id: 48, content: 'Hello, World!' }