Sunday, May 14, 2017

Real Time tweet analysis with Oracle Stream Analytics

Oracle Stream Analytics platform provides a compelling combination of an easy-to-use visual façade to rapidly create and dynamically change Real Time Event Stream Processing (Fast Data) applications.
This blog shows an example on how to Integrate Twitter with Oracle Stream Analytics for realtime tweet analysis.
Use Case
Here I have taken an usecase of sentiment analysis. We will capture realtime tweets on recently released bollywood movie “Sarkar 3” and identify sentiments based on keywords defined in datasource. Please note intent of this blog is not to provide sentiment analysis solution. As there are more complex system and analytics required for it. However this blog gives idea on using Oracle Stream Analytics, Integrating with twitter, using database as reference.
Please install Oracle Stream Analytics (OSA) 12.2.1 from following URL. http://www.oracle.com/technetwork/middleware/complex-event-processing/downloads/index.html
OSA Installation is as simple as download and execute. You can refer to installation instruction available in OSA documentation. https://docs.oracle.com/middleware/12212/osa/using-streamanalytics/toc.htm
Once installtion is complete go to domain and start server by “startwlevs.cmd” or “startwlevs.sh” and Login to Oracle Stream Analytics (OSA) browser. http:// <hostname>:<port>/sx.
I have configured OSA on port 9202. Hence my URL is http://localhost:9202/sx. provide username and password.
To create connection with Twitter account
Go to Catalog tab. And select menu “Create New Item” -> “Connection”.


Provide connection name,description, tags. Select Connection type as Twitter.



Next screen it asks for Twitter connection dteail.
As you can see it asks Key & token to communicate with Twitter. For this Go to https://apps.twitter.com/
Click on Create New App. And provide information as shown below.


Agree terms & conditions and click on “Crate your Twitter application” button.


You will get message that application has been created successfully.
Now, access the application and go to “Keys and Access Tokens” section. It has key and token information unique to the application. Copy these values and paste in OSA connection page.




You will also need to generate Access Token. Click on the button “Create my access token”


Go back to OSA console and provide all the information it asked to integrate with Twitter.
Click save and your twitter connection is ready to use.




Let’s create a Stream that will read desired tweets.


Provide stream name, tags and source type as Twitter.


Provide hashtag you want to ready. Here I am using tweets from #sarkar3 and #sarkar3review
Click next and select default twitter shape. And click on create button.
Our stream is ready to use.


Next we will create an Exploration on the stream we created recently.
Goto Catalog. Click on Menu “Create New Item”-> Exploration.




Provide Exploration name, tags. Select Source as the stream we created above “Sarkar3 Movie Review”.
Click on Create. It will take to the exploration page.
As you can see it contains Stream in sources. If you scroll down it will start capturing live tweets in “Live output stream” section. As shown below.


Now to analyze sentiments we will need to filter tweets based on keywords. We will keep these keywords in database table.
Let’s create sentiment datastore.  Goto your database and create a table as shown here.
I have created a table SENTIMENTS in my Oracle XE instance. With following columns and records.
And insert following records.
Next step is to create a datastore to access db table created above. For this login to Oracle Event processing (OEP) visualizer and create a datasource. Later we will use this datasource in stream analytics.
To open OEP visualize in your browser enter URL- localhost:9202/wlevs. You should see following screen.
Expand your OSA domain name and click on defaultserver.
Click on datasource tab. And click on Add button to create a new datasource.


Provide desired datasource name and JNDI name. Here I have used name as Demo.
Click on next tab “global transaction protocol”. Provide connection information. And save it.
You should see datasource created with successful deployment message.


Now come back to OSA console and click on Create new Item-> Connection.




Provide desired datasource name as “Sentiment data source”. And select source type as Database table.


Click Next. You should see following page. ‘demo’ datasource we created in OEP visualizer can be seen in the list. Select demo as data source name.
Click next. You should see list of tables. Select SENTIMENTS table from the list.


Click on save. Datasource is created successfully.




Now go back to Exploration and add “sentiment data source” in source section.


You will get error asking to correlate both source streams.


Click on Add a Correlation and select “lang” field from Twitter stream and “LANG” field from datasource table.


Add a filter to identify tweets matches to our key words defined in database.


You can remove columns from live output stream section. Just right click on the column and select remove.


Let’s tweet review on #sarkar3review or #sarkar3, hashtags we are monitoring.
Here are tweets with sentiments in OSA exploration.
We can further publish exploration results to a BAM dashboard or messaging queue for further analysis.



Wednesday, May 10, 2017

DevOps With Oracle DeveloperCS Ansible and Docker

This blog shows a sample DevOps cycle using combination of Oracle Developer Cloud Service & Ansible playbook.
Scenario: An organization wants to setup DevOps practice with Oracle public cloud for Dev & test. However production still remains on-premise. In such case Oracle Developer cloud service can deploy artifacts(e.g. JAR file) to JCS (Java cloud Service) or ACCS (Application container Cloud service). However to get the artifact on premise we can write extension. So that artifact is downloaded and production environment is rolled out automatically.
Note that here we are discussing a simple example to get the concept. In real implementation there will be more complex architecture. What we discuss below is just one of the possible way.
Tools/features used:
  1. Oracle Public Cloud:
  • Source code repository – GIT Repository available OOTB with Developer CS. Used to maintain source code of sample Java Spring bootstrap based application
  • Continuous Integration- Hudson build server available OOTB with Developer CS. Used to compile code, generate Jar file and perform Unit testing
  1. Internet:
  • GIT Hub  - to maintain artifacts/binaries generated by Developer CS. (Here jar generated from Developer CS is moved to GIT Hub)
  1. On Premise:
  • Docker – Docker container to run java application
  • Ansible – Ansible playbook to download artifact from GIT Hub, configure with Docker and rollout the environment.
Flow:




Implementation:
  • I am assuming that audience is familiar with Developer Cloud service, Docker concepts, Checkin code from their respective IDE to GIT repository. If you need information on Developer CS please refer to Oracle documentations (https://docs.oracle.com/en/cloud/paas/developer-cloud/index.html )
  • I have built a Spring bootstrap based J2SE project.
  • Let’s login to Developer CS. Provide your Identity domain and user credential.
  • On successful login you will see projects already configured in Developer CS. In my case I already have a Spring Medrec J2SE Project. A new project can be created from this page.
  • Click on the project and go to Project section. Copy the GIT repository path. That needs to configured with your IDE

  • Go to IDE (Netbean in my case) and check-in source code in GIT repository. Once source code is successfully pushed go to Code section. Here it shows source code checked-in to the GIT repository. It also has a pom.xml as Maven script, checked in as a part of source code.

  • Now go to build section to create a build job. Here I have created a Job named “Master Build”. Go to the configure section of Master build. And click on Source code tab. Here you need to configure repository info where code is checked-in.

  • Now click on Build steps. Add build step “Invoke Maven 3”. And define appropriate goals configured in your maven.xml
  • Go to post build section and select option to archive artifact. If you have Junit test cases select option to publish Junit test cases as well. It will show test results on Developer CS console.

  • Save changes and run the build. You will see an artifact generated as a result of successful build. Here a zip file ‘medrec-0.0.1-SNAPSHOT.zip’ can be seen. This zip contains application JAR inside.
  • Also you can see Junit test results by clicking on ‘Tests’
  • Since the artifact is generated successfully it can be deployed to Oracle ACCS. Click on ‘Deploy’ menu option configure & Deploy application in your ACCS account.

  • Go to configuration section of this job.
  • Click on build steps and select execute shell as an option. Here we will copy artifact generated by previous build and move to GIT Hub.


  • Click on build steps and select execute shell as an option. Here we will copy artifact generated by previous build and move to GIT Hub. On successful build ‘medrec-0.0.1-SNAPSHOT.zip’ file can be seen in GIT hub.
  • Next, we will use Ansible playbook to pull zip file from GIT Hub and deploy on Docker. I am using a Linux VM where docker engine & Ansible are already installed.
  • Here is the Ansible playbook (deploy.yml) created to perform following tasks in sequence:
    • Pull Artifacts (medrec-0.0.1-SNAPSHOT.zip file) on local file system
    • Unzip the archive
    • Stop and remove pre-existing docker contianer
    • Build new docker image
    • Start a new container
  • This is how deploy.yml looks like (2 screenshots) :
  • We will execute deploy.yml on localhost. However Ansible can perform same task on remote host as well.
  • Once above command is executed it will perform each task mentioned in playbook.
  • Lets check we check docker images and container.
  • Access URL to run java application on Docker’s IP address. (Here the application shows Swagger API)