Wednesday, August 13, 2014

Mixing Twilio with IBM Bluemix

This post walks you through the steps to get started with Twilio on IBM's Bluemix. Twilio comes as a service that you can add  to your Mobile Cloud or Node.js app. Here's a quick look at Twilio. Twilio, is a cloud communications IaaS organization which  allows you use standard web languages to build voice, SMS and VOIP applications via a Web API.
Twilio provides the  ability to build VOIP applications using APIs. Twilio itself resides in the cloud and is always available. It also provides SIP integration which means that it can be integrated with Soft switches. Twilio looks really  interesting with its ability to combine the  cloud, Web and VOIP, SMS  and  the like.
This post barely scratches the surface of Twilio & Blue mix. This article provides aa hands-on experience for integration of Twilio with Bluemix and is based on this Twilio blog post. It enables you to send a SMS to your mobile phone by typing in a URL.
As in my earlier post the steps are
1) Fire-up a Node.js  Webstarter application from the  Bluemix dashboard.  In my case I have named the application websms. Once this is up and running
2) Click Add a Service and under 'Web and Application' choose Twilio.
3) Enter a  name for the Twilio service. You will also need the Account SID and Authorization token
4) For this go to http://www.twilio.com and sign up2
5) Once you have registered, go to your Dashboard for the Account SID and Auth Token. If the Auth token is encrypted, you can click the 'lock' symbol to display the Auth token in plain text.
6) Enter the Accout SID and Auth Token in the Twilio service in Bluemix
7)  To get started you can simply  fork my Twilio  websms code from devops.
8) Now clone the code into a folder you create as follows
git clone https://hub.jazz.net/git/tvganesh/websms
9) You will need to modify the following files
package.json
manifest.yml
app.js
 
10) You can create package.json by running
npm init. Make sure you enter the name of the application you created in Bluemix. In my case it is "websms' For the rest of the options you can choose the default. Here is the package.json file
"name": "websms",
"version": "0.0.0",
"description": "This README.md file is displayed on your project page. You should edit this \r file to describe your project, including instructions for building and \r running the project, pointers to the license under which you are making the \r project available, and anything else you think would be useful for others to\r know.",
"main": "app.js",
"dependencies": {
"gopher": "^0.0.7",
"express": "^3.12.0",
"twilio": "^1.6.0",
"ejs": "^1.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://hub.jazz.net/git/tvganesh/websms"
},
"author": "",
"license": "ISC"
}
11) In the manifest.yml make sure you enter the name of your application and the host
applications:
- host: websms
disk: 1024M
name: websms
command: node app.js
path: .
domain:
mem: 128M
instances: 1
12) Lastly make changes to your app.js.
// dependencies
var app = require('gopher'),
twilio = require('twilio');
var config = JSON.parse(process.env.VCAP_SERVICES);
var twilioSid, twilioToken;
config['user-provided'].forEach(function(service) {
if (service.name == 'Twilio') {
twilioSid = service.credentials.accountSID;
twilioToken = service.credentials.authToken;
}
});
// URL test
app.get('/', function(request, response) {
var client = new twilio.RestClient(twilioSid, twilioToken);
client.sendMessage({
to:'',
from:'body:'Twilio notification through Bluemix!'
}, function(err, message) {
response.send('Message sent! ID: '+message.sid);
});
});
13) After you have made the changes you will need to push the changes to Bluemix using the command line based 'cf' tool
14) Login into cf with
cf login – a http://api.ng.bluemix.net
15) Push the websms onto bluemix
16) In the folder where you websms files reside entr the following command
cf push websms -p . -m 512M
17) This should push the code to Bluemix.
Note: If you happen to get a
Server error, status code: 400, error code: 170001, message: Staging error: cannot get instances since staging failed
then you need to make sure to check the changes made to  files app.js, package.,json or the manigfest,yml.
18)  If all things went smoothly, go to your Bluemix dashboard and click the link adjacent to the Routes. You should see that an SMS has been sent as shown
3
19) Your mobile should now display the message that was sent as shown below
Screenshot_2014-06-22-13-41-44
20) Check the  analytics in your Twilio dashboard
1
Disclaimer: This article represents the author’s viewpoint only and doesn’t necessarily represent IBM’s positions, strategies or opinions
[polldaddy rating="7295683"]

Saturday, August 9, 2014

Test driving Push notification in Bluemix

This post is a continuation of my earlier post 'Getting started with mobile cloud in Bluemix'. Here I take a test drive of the push service that Bluemix offers based on the article "Extend an Android app using the Push cloud service" from developerWorks.
This post assumes that you have already completed the changes from my earlier post for the mobile cloud. If you haven't,  you could clone the code from "mobile data" which is the official IBM version of this app and includes all the changes needed for persisting data in the cloud through their Android.
The Mobile Cloud App I created on Bluemix is "mobtvg". The main steps to have Push notification service using Bluemix are
  1. GCM services : Get Google API Project number  & GCM API Key
  2. Include the Google Play services library project
  3. Add the jar files to enable Push service
  4. Modify the server side Node.js file to send push notifications to all registered devices
  5. Make necessary code changes
  6. Run the application and test for notification
Here are more details on the above steps
a) GCM services : Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. The 1st thing to do is get the Google API Project number & GCM API key.
- Click Create Project. Enter Project name & click Create.
- Note the Project Number on top of the page.
- Click API & Auth on left panel. Click API.
- Scroll down and turn-on Google Messaging for Android
-  Click credentials and click "Create new key". Click server key. Click create
-Copy API key in the Public API access
Now go the Bluemix dashboard and click your application. Click the Push module. In the Configuration tab, scroll down to Google Cloud Messaging and  click 'Edit'
Enter the Google API Project Number & GCM API key for both the Sandbox & Production configuration and click Save.
4
b) In Eclipse click Windows->Android SDK manager. Scroll down to the bottom and under Extras select Google Play services. Click install. Once the installation is successful import the project as follows File-Import->Android->Existing Android  code into Workspace. Click Next. In the next screen Browse to the path where your ADT bundle is installed and choose the folder
\ sdk\extras\google\google_play_services
and Click Ok. Also  check 'Copy project into workspace'. This will copy.
3
Now build the Google Play Services Project. To do this the project. Click Project->Properties->Android and make sure that you select 'Is library project' and then click build.
5
Add a reference to the Google Play services in the Androidmanifest.xml
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
c) Make all the code changes given in Step 4 of "Extend an Android app using the Push cloud service.
d) In MainActivity.java make sure you change the app_name to the name of your app for e.g
public static final String CLASS_NAME = "MainActivity";
public static final String APP_NAME = "mobtvg";
Also ensure that under assets folder you have populated the Application ID in the bluemix.properties file
applicationID=<Application ID from Bluemix>
d) Add ibmcloudcode.jar, ibmpush.jar, android-support-v4.jar (from /extras/android/support/v4)
e) Now the Mobile Push project need to include this library project. To do this select your Mobile App project. Click Project->Properties->Android. Click Add and select google-play-services-lib. Note: Make sure "Is library project" is unchecked otherwise you are in for a lot of grief.
8
f) Now you need to make changes to the Node.js application to push any changes from the server to all registered devices.  The code for this is in bluelist-push-node. Note; Making changes through the GUI results in an error that "manifest.yml is not in root node". So I suggest that you take the 'cf' route as follows.
- Clone the code using Git
git clone https://hub.jazz.net/git/mobilecloud/bluelist-push
Go to bluelist-push-node folder
i) Open the app.js with your favorite editor and enter the Application ID of your Bluemix application
//Data Values
var values = {
version:"0.3.1",
//change this to the actual application id of your mobile backend starter
appID : "",
host : "https://mobile.ng.bluemix.net"
}
ii) Open manifest.yml and change host name & name to the name of your application for e.g.
host: mobtvg
disk: 1024M
name: mobtvg
command: node app.js
path: .
domain: ng.bluemix.net
mem: 128M
instances: 1
iii) Once the changes are complete, open a command propmpt and  login into Bluemix using 'cf' as follows
- cd to the directory in which Node.js & manifest.yml exist, Do
cf login - a http://api.ng.bluemix.net
cf push mobtvg -p . -m 512M
(Note the changes are pushed to the mobile cloud app on Bluemix)
This will run through and finally give the status that the app is running successfully.
f) Now that all changes are complete the Mobile Cloud with Push can be tested..
g) Click Window->Android Virtual Device Manager. Click the Device definitions. You choose Google Nexus, Nexus 7. Click Create AVD.
Note: Make sure you choose Google API Level Y and not Android x.x.x API Y.
6
Let the AVD come up and display the current items in the grocery list.
h) Login to Bluemix. Click Push and select the Notifications tab and enter a test message for e.g. "This is a notification from Bluemix" and click send.
7
This will result in a Push Notification to be sent to the AVD. You should see this popup on you AVD as shown below
1
i) Add another AVD through Windows-Android Virtual Device manager. While one AVD is running go to Run->Run Configurations->Target Device and choose the newly created AVD.
j) This will start a second AVD which will refresh with the contents of the grocery list. Now adda new item in one of AVD devices. This will result in a Push notification to the other device that the Bluelist has been updated.
2
There you have it.
1) A mobile cloud applications in which changes persist in the cloud and are refreshed each time the Android device is restarted.
2) A Push notification that is sent to all registered devices whenever there is a change to the list.
Disclaimer: This article represents the author’s viewpoint only and doesn’t necessarily represent IBM’s positions, strategies or opinions
[polldaddy rating="7295683"]

Friday, August 8, 2014

Getting started with a Mobile Cloud app with Bluemix

This post gives the key steps to get going in building a Mobile Cloud application on IBM's Bluemix. This post focuses on using the Android Platform for building the application. IBM Bluemix'es mobile cloud application includes under its hood mobile services like mobile application security, push and mobile data. A Node.js is also thrown in to provide server-side functions.
The Bluemix Mobile architecture is shown below
BuildingMobile
 
As in the previous post an existing Mobile cloud application IBM's bluelist -base is cloned to get familiarity with the steps involved. The IBM's bluelist-base app enables the user to maintain a grocery list that persists as mobile data in the cloud instance. To get started perform the following
1) Install ADT + Eclipse bundle from the aforementioned link
2) Unzip and install Eclipse and the ADT bundle
3) Make sure you have the Java JDK for Eclipse. If not install from the following site Java SE Development Kit 8 Downloads
4) Since we will be cloning an existing application and using Eclipse to make the changes we need to install EGit.
5) To do this open Eclipse and select Help-> Install New Software and type in http://download.eclipse.org/egit/updates in the Work with text field and hit enter. You should see the following
1
6) Once EGit is installed the IBM's bluelist-base App can be cloned as follows
7) In Eclipse click File->Import->Git->Import from Git and click Next
8) Choose Clone URI and Click Next
9) Enter the URI for IBM's bluelist-base. This shown below
2
10) This will download all the necessary source files and other Android related files and directories into the workspace.
11) After this perform the Steps 2 to Step 6 from the link given Build an Android app using the MobileData cloud service
12) After you make the necessary code changes you are good to go
13) Make sure you right-click and add all the necessary imports required (also Ctrl+Shift + O)
14) Build the Project and make sure that there are no errors
15) You are now ready to run the mobile cloud application. We need to run the mobile app on a Virtual simulator. This can be done as
a) In Eclipse click Window->Android Virtual Device Manager. Click the Device Definitions tab.
b) Choose Nexus 7 (Google) and Click Create AVD.
c) This will open a New Window. Set the following Skin->QVGA and Enter 100 MiB in SD Card size and click OK. This will add this as a AVD.
16) Now run the application.
17) This will bring up the AVD. This takes some time You should see the IBM bluelist showing up as one of the apps.
18) Click on IBM Bluelist. You can add grocery items. These items will persist even if you have to restart your application
3
19) The data is persisted in the IBM's cloud. This can be checked by logging into BlueMix'es dashboard
4
20) Click the Mobile Data and the data entered in the AVD device will show up in Data Classes drop down.
5
21) The Analytics tab will give a graphical output of the API calls
6
So not the mobile app that is cloud enabled is ready.
Clearly the ability to build Android Apps with the data stored at a cloud opens up numerous possibilities for apps like Evernote, Pocket across several devices.
There you have your first Mobile Cloud App.
Watch this space!
Disclaimer: This article represents the author's viewpoint only and doesn't necessarily represent IBM's positions, strategies or opinions
[polldaddy rating="7295683"]

Natural selection of database technology through the years

1Charles Darwin in his landmark book “The Origin of Species' discusses how flora and fauna evolved through the centuries. The different features of each individual species would undergo a process of natural selection by which modification of attributes would naturally occur that would enable the species to adapt and propagate through time. Those modifications that failed to adapt would naturally become extinct.
In this post I discuss how database (DB) technology has evolved over the years. As new requirements arose database technology has had to adapt and newer paradigms have evolved. However, unlike species which became extinct the older versions still exist as they continue o address the earlier problems that remain today.
Here is a short & brief history of evolution of databases
Relational databases: Relational databases had their genesis when E.F Codd of IBM came up with a relational model of organizing data. In this model all data is organized as tables with several rows. In a relational model each row has several columns and one of the columns contains a unique value for each row called primary key. Relational databases have ruled the enterprise domain for more than 3 decades. An enterprise's data is organized as a set of related tables. Users can query the database using Structured Query Language or SQL.
I remember in the late 1980's when I started to work in the industry, programming jobs were much sought after by all of us engineering graduates. In those days database jobs were 'uncool' and system programming jobs dealing with writing assemblers, compilers were the really cool jobs. I was also susceptible to this prevailing opinion and stayed away from databases. As fate would have it I eventually moved into telecom and telecom protocol work in which I worked for more than 2 decades and have largely maintained my distance from DB.
However it recent times I did want to look brush up whatever little I knew of DB. Recently I was listening to the Coursera course “Introduction to Data Science' by Bill Howe. In one of the lectures the professor uttered something that really caught my fancy. He mentions that SQL is probably the closest to natural language. How true! Once the DB schema and tables have been set up, querying the DB for all sorts of data can be done in SQL which is close to natural language. For e.g.
SELECT a,b,c from TABLE S,T where condition X1 AND/OR condition X2
The power of DBs comes from the fact that all the data is organized as tables and enables one to retrieve any sort of data from it. Trying to accomplish this with any other high level programming language would take several hundreds of lines of code and we would have to write functions for each in individual query.
NoSQL databases: However the utility of relational databases decreases as we scale to hundreds of Gbs of data. In this age of the internet and the worldwide web data is easily of the order of several terabytes to a few petabytes. For e.g. Weather modelling, Social networks like FB,Twitter or LinkedIn all need to operate on millions of status updates or tweets per day. Traditional relational databases cannot handle such large sets of data. This is where the concept of NoSQL DB came into existence. NoSQL databases typically store data as key, value pairs. The singular advantage of NoSQL is that the database can scale horizontally or in other words the performance does not degrade with large increases in data size. In NoSQL databases data is hashed and uniformly distributed across commodity servers through a technique known as 'consistent hashing'. Also data in NoSQL databases is replicated across servers. This architecture of NoSQL databases is based on common, commodity servers which are expected to crash. However this would not affect the NoSQL DB to function correctly. The strength of NoSQL databases comes from the fact that servers can join or leave the NoSQL DB without affecting the functioning of the DB. Some of the more popular examples of NoSQL DB are CouchDB, MongoDB, Riak, Voldemort, Dynamo etc.Do take a look at my post "When NoSQL makes better sense that MySQL"
NewSQL: This variation of DB came into existence as there was a need for extremely fast performance for computing tasks like analytics etc. These DBs exist completely in memory and so the access is blazingly fast. The most famous of DBs of this paradigm is SAP's HANA.
Graph Databases: Graph databases are the recent entrants into database technology. This strain of databases came into existence to handle associative data more efficiently. In a graph database data is represented as a graph. Nodes in the graph can be entities and edges can be relationships. A search on a graph database will result in a traversal from a specified start node to a specified terminating node. “Friends' in Facebook, 'followers/following' in Twitter and 'connections' in LinkedIn all use Graph Database to map association and enable easy search. Graph Databases is what allows these databases to make recommendations like 'You may know'. E.g. of Graph Database Google's Graph DB, Neo4j
As we move ahead database technology will continue to evolve into newer architectures to handle
[polldaddy rating="7295683"]

Wednesday, August 6, 2014

Get your feet wet with IBM Bluemix

This post provides the initial steps to get started on IBM’s Bluemix (currently in beta). Bluemix is open-standard, cloud based Platform-as-a-Service (PaaS) from IBM. Bluemix allows one to quickly put together mobile, web, Big Data, IoT applications. Bluemix is an implementation of IBM’s Open Cloud Architecture, Cloud Foundry which enables developers to rapidly build, deploy, and manage their cloud applications. The developers can tap into a growing ecosystem of available services and runtime frameworks.
Bluemix uses the Softlayer infrastructure to host the user applications. Clients/developers interact with Bluemix either with HTTP or REST as shown below
8
Here are the steps to get going on Bluemix
First things first
I would suggest that you get all the registrations and installations right away.
Bluemix dashboard- Get started by creating an account on Bluemix. This will provide you access to the Bluemix’s dashboard from which you can quickly create applications (mobile, Web, IoT, BigData) etc
Devops: Register for an account with Devops. Devops allows you to easily develop, deploy and track your code online. Devops also allows you to collaborate with others by forking code from their Git repositories
Cf Interface : Install the Command line interface ‘cf” to Bluemix. The ‘cf’ command interface is built with Google’s Go programming language. With ‘cf ‘you can login to Bluemix, create an application, add services and manage your application. You can also do this from the Bluemix’es dashboard.
Install Git: There are multiple ways to develop code for Bluemix. Git command line happens to be one of them, So it makes sense to have this installed. You can install this from this link https://hub.jazz.net/tutorials/clients#installing_git
Install Node.js:The application that this post discusses is based on a Node.js based application so it will help to have it installed. Node.js is a platform that enables building of fast, scalable network applications and created by Ryan Dahl.
Kicking off Bluemix : A good first application to get moving on in Bluemix is the already available Sentiment Analysis of Twitter. This application uses the Node.js ‘sentiment’ module to perform some basic sentiment analysis.
The quickest and most painless way to get started on Bluemix is to ‘fork’ the code for Sentiment Analysis from Devops.
1) Login to your Devops account. Click the following Sentiments link from Devops, in which I have created a slight modification to the sentiment analysis application
2) Click the Edit Code button at the top. This will open the files and directories in this project (see picture below)
3) Next click the “Fork’ button on the panel on the left side. This will create a copy of the above code in your own repository (see picture below )
1
4) The Twitter sentiment analysis code is in app.js written in Node.js. You can make changes to the code as needed. I have made a few modifications to the code that I had forked. I added changes which adds a textual output of the Twitter sentiment
;
How to make code changes with Web IDE
5) To make code changes double click the app.js file. This will open up the code window. You can use the GUI based IDE to make the code changes and merge with the master branch, The steps are
a) Make the necessary changes and click the symbol shown
2
3. This will open a new window as shown below
3
4) Click the ‘Stage to change’ button.
5) This will move the changes to Staged. Click the ‘Commit’ button and enter the reason for the change and click the “Submit’
4
6) This will move the changes from ‘Staged’ to ‘Commits for master branch’
7) Now click ‘Push all’ and click ‘Ok’ in the Git Push popup window. This will merge the changes into the master branch.
8) Once this done click ‘Build & Deploy’ button
9) Your changes will transition from ‘Pending’ to ‘OK’. Now click the ‘Manage’ button. This will deploy the application with the latest changes on to Bluemix.
10) Do the following to populate the details for the parameters below  with a Twitter app that you create for your application
var tweeter = new twitter({
consumer_key:  API key
>,
consumer_secret: API secret>,
access_token_key:,
access_token_secret:
});
11) To do this log into http://dev.twitter.com
12) Click My applications where your picture is displayed and then click Create application.
13) Enter the details for Name,Description & Website (can be any valid website) and then click Create Twitter application.. This will create the Twitter application.
1
14) Click the API tab. Scroll down to the bottom and click “Create my access token”.
15) This will generate the Access token & Access token secret. Enter all the details (API Key, API secret, Access Token, Access Token secret into app.js and push to the master branch before deploying on Bluemix

Code changes with Git command line
11) Incidentally the changes to code can also be made through the Git command shell as follows
b) Modify the code using any editor and save the changes
c) Go the directory containing the files and do
git add *
d) git commit -m “Cosmetic” app.js
e) git push
This will push the changes to the git repository in the master branch
8) Click the ‘Build & deploy’ in the top right corner. You should see this
5
9) Click the ‘Manage’ button which will push the application onto the BlueMix
10) To test this application click the link next to ‘Routes’ . Enter a phrase that you would like to search and hit ‘Go’
6
You should see the application checking Twitter periodically for the tweets.
7
Thats it! You have built your first Bluemix application.
The ability to integrate Node.js into your cloud application allows one to easily create powerful applications.
Hasta la vista! I’ll be back!
Disclaimer: This article represents the author’s viewpoint only and doesn’t necessarily represent IBM’s positions, strategies or opinions