20
BlueMix Han Lab C - Building aT in BlueMix Version : 3.0 Last modification date : 05/ Owner : IBM nds-On Workshop Twitter Influencer Analyzer Ap 00 /12/2014 M Ecosystem Development pplication

BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

BlueMix HandsLab C - Building a Twitter Influencer Analyzer Applicationin BlueMix

Version : 3.00Last modification date : 05/Owner : IBM

BlueMix Hands-On Workshopa Twitter Influencer Analyzer Application

.00/12/2014

IBM Ecosystem Development

a Twitter Influencer Analyzer Application

Page 2: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version
Page 3: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Copyright IBM Corporation 2013-2014. All rights reserved. 3

Table of Contents

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix............................................................... 5

Part 1: Configuration/Setup ....................................................................................................................... 5

1. Get the Klout key............................................................................................................................... 5

2. Get the Twitter key ............................................................................................................................ 5

Part 2: Building and Deploying the Node.js version with the IBM BlueMix Eclipse tools ......................... 6

1. Starting Eclipse ................................................................................................................................. 6

2. Importing the code for this section from GitHub................................................................................ 6

3. Edit the code to add the Twitter API and Klout API keys.................................................................. 8

4. Push the application from Eclipse ..................................................................................................... 9

5. Running the application...................................................................................................................11

Part 3: Building and Deploying the Java version with the IBM BlueMix Eclipse tools............................11

1. Starting Eclipse ...............................................................................................................................11

2. Importing the code for this section from GitHub..............................................................................12

3. Edit the code to add the Twitter API and Klout API keys................................................................13

4. Push the application from Eclipse ...................................................................................................14

6. Running the application...................................................................................................................16

Part 4: Deploying the Python version with command line tools .............................................................18

1. Add the Twitter and Klout keys .......................................................................................................18

2. Deploy a the Python version with command line tools .................................................................19

3. Running the application...................................................................................................................20

Page 4: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version
Page 5: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 5

Lab C: Build a Twitter Influencer Analyzer Application inBlueMix

Lab Objectives: In this lab you'll learn how to create a Twitter analysis application that runs on IBM BlueMix and

makes use of BlueMix services such as MongoDB and SQLDB. The application also makes use of external social

data services provided by Twitter and Klout, as well as Google mapping services. Documentation is provided for

creating the application using node.js, Java, and Python – to emphasize l that BlueMix is a scalable, multi-language

(polyglot) application platform.

The Twitter Influencer Analyzer is a web application which collects data from Twitter, Klout and Google Maps to

display influence relationships between twitter users. The application uses the MongoDB and SQLDB BlueMix

services:

Three approaches are demonstrated :

i) Building and deploying the Node.js version using the IBM BlueMix tools in Eclipse

ii) Building and deploying the Java version using the IBM BlueMix tools in Eclipse

iii) Building and deploying the Python version using the IBM BlueMix command line tools

Lab Duration : 40 minutes

Part 1: Configuration/Setup

In Part 1 you'll setup the necessary API keys to use the Twitter and Klout APIs utilized in this application.If you're pressed for time, you can skip ahead to part 2 and ask the instructor to let you use his or her key

1. Get the Klout key

In this section you'll get the Klout developer key. If you already have this key skip ahead to the nextsection.

Step 1 Open you browser and go to http://developer.klout.com

Step 2 Click on the button Register to build you awesome app and follow the prompts to obtain aKlout developer key

2. Get the Twitter key

In this section you'll get the Twitter developer key. If you already have these keys skip ahead to the nextsection.

Step 1 Open you browser and go to https://github.com/ibmjstart/bluemix-python-sample-twitter-influence-app/blob/master/registerTwitter.md (hint: you can copy this URL from the fileLongCommands.txt)

Step 2 Follow the instructions in the document to register a new Twitter application and to obtain the 4keys required to use the Twitter API

Page 6: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 6

Part 2: Building and Deploying the Node.js version with the IBM BlueMixEclipse tools

In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version of the TwitterInfluencer Analyzer application that uses the Mongo DB database service .

1. Starting Eclipse

In this section you’ll start Eclipse and load the workspace that will be used for this part of the lab.

Step 1 Open Windows Explorer and launch the program \BlueMixLabs\eclipse\eclipse.exe where\BlueMixLabs is the root folder of the files provided to you by the instructor.

Step 2 Select the workspace \BlueMixLabs\workspaces\LabC when prompted and click OK

Figure 1 Select Eclipse Workspace

2. Importing the code for this section from GitHub

In this section you’ll use the built in Eclipse tools to import the code for this section from a Git repository.This is demonstrates how a typical BlueMix developer would work with version controlled code.

Step 1 Select File->Import from the Eclipse menu and select Git_>Projects from Git in the resultingdialog. Click Next.

Figure 2 Importing from Git dialog

Step 2 Select GitHub as the source and click Next

Page 7: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 7

Figure 3 Select GitHub as the source

Step 3 Enter the string bluemix-days-tia in the Search field and click Search

Figure 4 Finding GitHub Repository

Step 4 Select the ibmecod Repository shown in Figure 4 and click Next.

Step 5 Repeat clicking Next to accept the defaults until the Finish button becomes active .

Step 6 Click Finish to complete the importing of the code.

Step 7 Wait until the project is built by monitoring the build status at the bottom right of the Eclipse UIuntil there is no activity reported

Figure 5 Build status

Step 8 Verify that there are no errors (ie red X's) in the Project Explorer pane following the build.

Page 8: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 8

Figure 6 Project Explorer following import

3. Edit the code to add the Twitter API and Klout API keys

In this section you'll add the Twitter and Klout API keys so that you can run the app successfully,

Step 1 In the Project Explorer expand the bluemix-days-tia-node project to see the file config.json.

Figure 7 Files to edit

Step 2 Double click to open the file

Step 3 Add your Klout developer key and twitter API keys to the file as shown in Figure 8

Page 9: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 9

Figure 8 Add Klout and Twitter keys

Step 4 Save config.json

4. Push the application from Eclipse

In this section you'll push, create services and start your app all from within the same UI in Eclipse .

Step 1 Go back to Eclipse and from the Servers tab select your server, right click and select Add andRemove from the context menu

Figure 9 Add project to server

Step 2 Select the bluemix-days-tia-node application and click Add .

Figure 10 Add project to BlueMix

Step 3 Click Finish. Click Next in the resulting dialog

Step 4 Append a unique string to the Subdomain (eg your first initial + last name ) since this has to beunique systemwide. See Figure 16 for an example. Click Next

Page 10: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 10

Figure 11 Specify unique Subdomain for app

Step 5 Click the icon to add a new service

Figure 12 Add new service

Step 6 Name the service mongoDBTIA and select mongodb as the Type. Click Finish

Figure 13 Name and type of service

Step 7 Click Finish to push and start your application.

Step 8 Messages should start appearing on the console. Wait for the message that says Buildingruntime environment

Page 11: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 11

Figure 14 Console messages

5. Running the application

Now that the application has been deployed and started, you can run it from the BlueMix portal

Step 1 Start your browser and go to the url https://ace.ng.bluemix.net and login if necessary

Step 2 Go to to Dashboard tab and click on the link to start the Twitter Influencer Analyzer applicationyou just pushed from Eclipse.

Step 3 Enter a known twitter handle and click on Analyze

Step 4 Verify that you see detailed information about that Twitter user.

Figure 15 Output of application

Part 3: Building and Deploying the Java version with the IBM BlueMix Eclipsetools

In Part 3 you'll work with the IBM BlueMix Eclipse tools to deploy the Java version of the TwitterInfluencer Analyzer application that uses the SQLDB database service .

1. Starting Eclipse

In this section you’ll start Eclipse and load the workspace that will be used for this part of the lab.

Step 3 If Eclipse is still open from Part 2 skip this section else open Windows Explorer and launchthe program \BlueMixLabs\eclipse\eclipse.exe where \BlueMixLabs is the root folder of thefiles provided to you by the instructor.

Step 4 Select the workspace \BlueMixLabs\workspaces\LabC when prompted and click OK

Page 12: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 12

Figure 16 Select Eclipse Workspace

2. Importing the code for this section from GitHub

In this section you’ll use the built in Eclipse tools to import the code for this section from a Git repository.This is demonstrates how a typical BlueMix developer would work with version controlled code.

Step 9 Select File->Import from the Eclipse menu and select Git_>Projects from Git in the resultingdialog. Click Next.

Figure 17 Importing from Git dialog

Step 10 Select GitHub as the source and click Next

Figure 18 Select GitHub as the source

Step 11 Enter the string bluemix-java-sample-tia in the Search field and click Search

Page 13: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 13

Figure 19 Finding GitHub Repository

Step 12 Select the ibmecod Repository shown in Figure 4 and click Next.

Step 13 Repeat clicking Next to accept the defaults until the Finish button becomes active .

Step 14 Click Finish to complete the importing of the code.

Step 15 Wait until the project is built by monitoring the build status at the bottom right of the Eclipse UIuntil there is no activity reported

Figure 20 Build status

Step 16 Verify that there are no errors (ie red X's) in the Project Explorer pane following the build.

Figure 21 Project Explorer following import

3. Edit the code to add the Twitter API and Klout API keys

In this section you'll add the Twitter and Klout API keys so that you can run the app successfully

Step 5 In the Project Explorer expand the twitter-influencer-analyzer-dao project and the expand JavaResources and src to see the file klout.properties.

Page 14: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 14

Figure 22 Files to edit

Step 6 Double click to open the file

Step 7 Add your Klout developer key to the file as shown in Figure 8

Figure 23 Add Klout key

Step 8 Save klout.properties

Step 9 Next open twiitter4j.properties and add the API key and API secret (the access token andaccess token secret are not needed)

Figure 24 Add Twitter keys

Step 10 Save twitter4j.properties

4. Push the application from Eclipse

In this section you'll push, create services and start your app all from within the same UI in Eclipse .

Step 1 Go back to Eclipse and from the Servers tab select your server, right click and select Add andRemove from the context menu

Page 15: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 15

Figure 25 Add project to server

Step 2 Select the twitter_infuencer_analyzer_dao application and click Add .

Figure 26 Add project to BlueMix

Step 3 Click Finish. Click Next in the resulting dialog

Step 4 Append a unique string to the Subdomain (eg your first initial + last name ) since this has to beunique systemwide. See Figure 16 for an example. Click Next

Figure 27 Specify unique Subdomain for app

Step 5 Click the icon to add a new service

Page 16: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 16

Figure 28 Add new service

Step 6 Name the service SQLDBTIA and select SQLDB as the Type. Click Finish

Figure 29 Name and type of service

Step 7 Click Finish to push and start your application.

Step 8 Messages should start appearing on the console. Wait for the message that says The serverdefaultServer is ready to run a smarter planet.

Figure 30 Console messages

6. Running the application

Now that the application has been deployed and started, you can run it from inside Eclipse

Step 1 From the Eclipse menu select Window>Web Browser and then select one of your installedWeb browsers (eg Firefox)

Page 17: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 17

Figure 31 Select an external browser

Step 2 In the Project Explorer select your project, right click and then select Run As->Run onServer from the context menu.

Figure 32 Launch application

Step 3 Click on Finish in the resulting dialog. .The browser you selected in Step 1 should launch withthe application

Step 4 Enter a known twitter handle and click on Analyze

Step 5 Verify that you see detailed information about that Twitter user.

Page 18: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 18

Figure 33 Output of application

Part 4: Deploying the Python version with command line tools

In Part 4 you'll work with the Cloud Foundry command line tools to deploy teh Python version of theTwitter Influencer Analyzer app that uses the Mongo DB service from your local machine

1. Add the Twitter and Klout keys

In this section you'll modify the code to add your Twitter and Klout keys

Step 1 Launch a Windows Explorer and navigate to the folder containing the app\BlueMixLabs\LabC\bluemix-python-tia\app where \BlueMixLabs is the root folder of thefiles provided to you by the instructor.

Step 2 Open the file wsgy.py with your favorite editor and add your Twitter API keys and your Kloutkey (note the Twitter Access Token and Access Token Secret are not needed).

Figure 34 Add Twitter and Klout keys

Step 3 Save the file

Page 19: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 19

2. Deploy a the Python version with command line tools

In this section you'll deploy the Python version using the Cloud Foundry Command Line tools.

Step 4 Launch a Command Prompt (cmd.exe) and navigate to the folder containing the app\BlueMixLabs\LabC\bluemix-python-tia\app where \BlueMixLabs is the root folder of thefiles provided to you by the instructor

Step 5 You'll now be in the folder containing the Python source code for the application. Execute thedir command and verify that have the files shown in Figure 35.

Figure 35 Python Source Files

Step 6 From the same command prompt login to BlueMix by issuing the following command (note; youcan copy the command from the file \BlueMixLabs\LongCommands.txt)

cf login -a https://api.ng.bluemix.net

Step 7 Provide your BlueMix credentials when prompted.

Step 8 Create an instance of the Mongo DB service used by the app selecting a Service Plan level,and giving it a unique name in the last argument by issuing the following command (note: youcan copy the command from the file \BlueMixLabs\LongCommands.txt)

cf create-service mongodb 100 mongoDBPyTIA

Step 9 Next you'll push the app to BlueMix . The following command pushes the app but doesn't startit. You need to substitute yourappname with a system wide unique name because by defaultthe app's URL starts with the app's name. (note: you can edit and then copy the commandfrom the file \BlueMixLabs\LongCommands.txt)

cf push yourappname --no-manifest --no-start -c "python wsgi.py"-b https://github.com/joshuamckenty/heroku-buildpack-python

Step 10 Bind the Service you created in Step 8 to the app that your just pushed (Note substituteyourappname with the app name you used in Step 6 - you can edit and then copy thecommand from the file \BlueMixLabs\LongCommands.txt) ).

cf bind-service yourappname mongoDBPyTIA

Step 11 Start your app. (Note substitute yourappname with the app name you used in Step 6 - you canedit and then copy the command from the file \BlueMixLabs\LongCommands.txt)

cf start yourappname

Page 20: BlueMix Hands-On Workshopfiles.meetup.com/14755122/IBM BlueMix Workshop... · Eclipse tools In Part 2 you'll work with the IBM BlueMix Eclipse tools to deploy the Node.js version

Lab C: Build a Twitter Influencer Analyzer Application in BlueMix

Copyright IBM Corporation 2013-2014. All rights reserved. 20

3. Running the application

Now that the application has been deployed and started, you can examine it in the BlueMix Web Portaland run it

Step 1 In your browser go to the BlueMix URL https://ace.ng.bluemex.net and login if necessary

Step 2 Make sure you're in the Dashboard section (if not click on the Dashboard link at the top of thepage to take you there) .

Step 3 Click on the link to bring up the Python Twitter Influencer Analyzer .

Congratulations! You’ve successfully completed Lab C where you've deployed teh same app written in 3different programming languages and runtime environments and deployed them all successfully.