Optimize development and deployment using CloudFoundry

March 31, 2013 1 comment

In this post I will be walking though the steps needed to deploy an application on cloudFoundry and how we can achieve Contiuous Integration and Continuous Delivery using CloudFoundry(http://www.cloudfoundry.com/) and Cloudbees(http://www.cloudbees.com/). Tough CloudBees is also a PaaS(Platform as a Service) provider, but I will be limiting to use the build feature of CloudBees

For the reason why I choose CloudFoundry over other PaaS providers please refer to my previous blog

I have a Maven based Spring Web Application, with a HTML view developed in HTML5 and Bootstrap. There are also some REST endpoints. It has a MySQL backend, and it also talks to some Google API’s. The local machine used was Ubuntu 32 bit 12.04 LTS

So, we start with requesting an invitation from Cloudfoundy by clicking on the signup link on their landing page.

  • Once registered, download VMC client from command line. VMC is a command line tool to manage applications in cloudfoundry. You can manage your apps/services through VMC. Since VMC is a ruby gem, please make sure you have ruby installed(http://docs.cloudfoundry.com/tools/vmc/installing-vmc.html). You can check if vmc is installed by issuing which vmc  on command line.
sudo apt-get install ruby-full rubygems
sudo gem install vmc
  •  Set the vmc target to http://api.cloudfoundry.com.  Target defines the base location where you application will be deployed. Login to cloudfoundry using the below mentioned commands. The credentials will be the same as created above
vmc target http://api.cloudfoundry.com
vmc login
  • Once the target is being set.  Navigate to the target folder of your application. Run vmc push <appname> . This will automatically pick the .war file present in the target folder, and will try to deploy the application. If there are multiple then it will ask you for the name of the war to be deployed. Press Enter to move to next options
    • Select the instances that are needed to host your application
    • CloudFoundy automatically detects the type of application that you are trying to upload, and configures the deployment environment accordingly. Select the application type(Spring in my case)
    • Select the java Runtime.
    • Select the memory limit. For this kind of free deployment, the memory limit is 2 GB i.e. All you deployed application can have total memory of 2GB.
    • Select the domain name. This URL used to access you application over public network.
    • Create Service for a application. A service is nothing but an external dependency that you application has eg:- MySQL, Redis, RabbitMQ. You can create those service instances here and they will be automatically be linked to you application. There is no need to update the database properties files with new credentials. CloudFoundry replaces the beans at Runtime to connect to its own service. For more read refer http://bit.ly/16q3heb and http://bit.ly/YLXXPW .
    • Save the configuration.
  • VMC will now try to upload the application war file and then deploy on the tomcat instance, then the application will be started.
  • Once the application is started, you can see the status through the following commands. Also validate the application by hitting the URL.
vmc apps - Show all running applications
vmc app <appname> - Show the specified application status
vmc info - Show the target information and user details
vmc services - Shows all the running services
vmc service <servicename> - Show the service details
  • CloudFoundry uses tunnels  to connect to the  services that are currently bound to the applications. Below example connects to the MySQL service.
vmc tunnel <service-name> mysql/mysqldump
  • To access the log files for tomcat use the file command.
vmc files <app-name> <file-path> {logs/stdout.log}

CloudFoundry does provide a clean way of deploying application from our local machine, but this is tedious and also I cannot get the test results and sonar reports. It would be better if I can achieve Continuous Integration and Continous Delivery of any changes that I push to my git repository. For this we can leverage the CloudFoundry integration with CloudBees. Cloudbees provides out of the box jenkins installation, which can be used for CI.

CloudFoundy provides a clean guidline of how cloudbees can be used to provide CI and CD on CloudFoundry. It can be found on the following blog link .

On caveat here is the link mentions coding, building and deploying all under Cloudbees umbrella. Since my code is in BitBucket, it does not make any sense to move the code from BitBucket to Cloudbees.

Assuming that the Jenkins instance is hosted on the following link http://<appname&gt;.ci.cloudbees.com . Open the jenkins job and click on Configure . 

    • Cloudbees to access the git repo and perform checkout, you need to add the CloudBees public SSH Key in you git account. The public key is present in the Configure section. How to add it to git repo, follow the given link
    • In the Source Code Management provide the ssh path git repository which hosts your code. 
    • In the Post Build Section check the CloudFoundry configuration settings.

With these step we should be able to setup and configure Jenkins. Click on Build Now to start a new build. The code will be checked from your git repo. Post build the war file will be automatically deployed to CLoudFoundry.

Using the combination of CloudBees and CloudFoundry, we can automate the whole process of build and deploy. Also with jenkins in place we can use tools like Sonar and Emma to get the health of the builds and analyze different pointers.

Cheers.

Choosing the right cloud

March 31, 2013 10 comments

There is a small mobile application that I am working on. It a  mobile module as well as a server module, which stores all my data. Till now, it was inhouse development where I deploy my server on tomcat and then access from the mobile app as both are on the same wireless n/w domain. This obviously wont work, when I needed to host the sever-side module to a public network, for it to access anywhere. Alas, and I was struck by the Cloud,  the buzzword I hear too often. So I though, lets deploy it on cloud. So, I went on searching for a cloud provider that would help me deploy my application.

Below were my parameters/requirements.

  1. I have a small Spring Web application which has a HTML view and some REST service endpoints. There is a MySQL database at the back-end and the application fetches data from some Google Services.
  2. It should be free. I intend not to spend a penny right now since the app is in it’s infancy.
  3. It should not be a 30 day time trial.
  4. It should be quick. Something similar to how I deploy applications on my local dev.
  5. It should not be overly complicated. I don’t want to go through API or management console and tons of external dependencies.
  6. I hate to doze through documents and installing sample apps to figure out how this thing works.
  7. It should give me good computing power and good space, so that my application has a space to breath.I am more leaned towards Platform as a Service(PaaS) providers.

Below are some of the cloud service providers that I had evaluated, and my take on them(This is personal opinion and does not indicate that the providers are bad).

  1. Amazon – Amazon is probably the first Cloud provider that anyone can think of. Its like NASA when it comes to space stuff. The ecosystem of amazon is very wast and the options provided are immense and diversified. On the flipside, hosting an app to Amazon, involves a lot of groundwork and  effort of integrating and running  application is huge. So amazon proved to be too big for a small application like mine. They should have an express setup with limited functionality so that people can get their hand dirty before jumping onto AWS Management Console.
  2. Heroku – I did  fancied the name. They have awesomely named servers(After fictitious samurai’s), but then that does not hide the fact that heroku works on the world of his own. His own git repository, different deployment process. Dynamo’s and workers are a tad complicated. I just could not figure out how I can deploy my simple spring application on heroku without making configuration changes.
  3. OpenShift – I just could not make it work. I thought it was nice interface but I wasn’t able to deploy my application to it. It’s an opaque system, and you never know how/why your application failed to deploy. Also, no MySQL or third party integration find a mention(Or may be I could not find it 😦 ).
  4. Rackspace – I doubt if they have any free hosting
  5. Jelastic – The interface seems promising and was able to get a good management console, was even able to setup Mysql and tomcat instances to run on. But then it would not allow me to fetch the code and build it from the git repo, and it also does not have a feature to upload and deploy a war file.
  6. CloudFoundry – This is a cloud hosting provided by VMWare, and is currently in beta. It provides limited functionality and a clean process to deploy you application. It’s free (for upto 2GB of RAM space) and does not have a time trial. Deploying the application was a breeze and since it can be done from command line, it’s fun to do :).

After going through the given providers CloudFoundry seems to be a cloud provider that I could use.

  1. Has a very simple and minimal learning curve. Just understand how vmc works and you are good to go. 
  2. Deploy the application as a war file rather that cloud provider checking out the code and then building it(This is error prone,fragile and not verbose). Also only the delta changes are uploaded and not the whole war file, thereby making deployment quick.
  3. It automagically recognizes application types and configures the deployment environment as per the application.
  4. External service binding to databases like MySQL, Redis and MongoDB are very simple and easy and it doe not require you make any code changes. You can switch service providers at runtime.
  5. There is a RAM limit of 2GB, so you can host multiple applications , just that the total RAM size should not exceed 2GB. So you can start/stop apps as an when needed.

CloudFoundry currently might not be as full fledged  cloud service providers as a other player but they have a easy deployment process and also provide easy access for people to setup their dev environment for infant applications. It saves you the pain of spending a day or two setting up the system or else being scared of the time trial finishing or various thresholds being reached after which you are getting charged.

CloudFoundry currently supports Spring, Java web , Ruby, Scala,node.js etc. .AppFog is one PaaS provider that is build over CloudFoundry(https://www.appfog.com/)

http://docs.cloudfoundry.com/getting-started.html

GWT with tomcat

January 10, 2013 Leave a comment

I have been working with GWT for sometime, and I always find it annoying that GWT deployment runs on an in-build jetty server. So I tried to give a shot to using tomcat and deploying GWT application on that, and see if it makes the hot deployment easier. The problem is we cannot do Run As->Run On Server and deploy the application on tomcat.

Below are the steps how you can configure your tomcat to deploy GWT application.

  1. Create a new Apache Server (I used Apache 7.0)
  2. Create a mavenized sample for GWT app(using this link)
  3. Do a clean build, package the application to generate a war file.
  4. Open server.xml defined in Servers->Tomcat Server folder present in your workspace.
  5. Edit the <Context> tag. Edit the docBase to point to the exploded war folder present in the target folder of your application.
  6. Run mvn clean package to package your application.
  7. Run the application on Tomcat(Run As->Run On Server).
  8. Open Chrome, to see if the GWT application is correctly deployed.

This will only deploy the application. In order to make any changes being reflected in the web page, you need to redeploy the application.

To run the GWT application in codesvr mode, you need to run the application as Run As->Run As Web Application(running on an external server). On the dialog box give the path of the deployed tomcat application as External Server Root and select one of the matching items. Click OK to deploy the application in debug mode.

Installing Android x86 on VirtualBox and Eclipse development

October 21, 2012 1 comment

After spending night oils and getting frustrated with the slow speed and frequent timeouts with the android emulator, I decided to host the android-x86 image on a virtual box and then use to for my development purpose. This was done with the hope to get ease of use,quick deployment and performance improvement. Please note that I am using the x86 4.0.4 (Ice Cream sandwich) deployment. Please choose correct deployment from the Android x86 download section for your purpose

Below are the things that are needed to host the android image as a virtual device

  1. Android x86 image iso (Android x86 download section)
  2. Oracle Virtual Box (Download) . I am using ubuntu, so I can issue the sudo apt-get install virtualbox command to install virtualbox.

We start with downloading the latest iso image for Android x86  from the link above. I  initially downloaded android-x86-4.0-RC2-eeepc.iso and it had a better ethernet support( I was not able to put up an ethernet connection with the asus or the IBM iso images). But then I was able to get an ethernet connection enabled android-x86-4.0-eth0-generic_x86-20120516.iso released  by tabletx86(Thanks). The file is currently hosted at this link for download.

Steps for installing and running the image can be followed from the given blog post

  • Launch New virtual machine wizard Select Linux and Linux 2.6 after giving a proper name to your virtual machine
  • Set the base memory size to an appropriate level. I have set it to 1000 MB as I have a 8 GB machine. Set it to 512 MB. This can be changed later
  • Create a new Virtual Hard Disk. Select the  Start-up Disk option and Create a new hard disk  radio buttton
  • Select the file Type as VDI
  • Select storage details as Dynamically allocated
  • Select the size for the disk space that for the virtual machine. I stayed with the default 8GB.
  • Press Create to finalize the changes and create the Android Virtual machine.

After Creating the VM , we need to configure it to install the ISO and also configure the ethernet adapter for n/w connectivity. Open the Setting window for the newly created VM.

  • Select Display  and assign the video memory to a value say 20 MB.
  • Select Storage  to specify the android iso image. In the IDE Controller, select Empty. Now to the right of it in the Attributes section Select the path of the iso image to load by clicking the CD image.
  • Select Network  and select Enable Network Adapter  check box. Also select Bridged Adapter  from the Attached To,  and eth0 or wlan0(whichever is available) from the Name dropdown lists.Expand Advanced. and select Adapter Type  as PCnet-FAST III. 

After setting up the VM, start the VM to install the android-x86 image. Refer to the link for instructions

After installation, run the VM to bring up the Android Screen. So we have successfully installed Android image on our VM. Now we need to configure the VM so that it behaves as a networked machine, and can share the internet connection and also be connected through the adb bridge.

  • Unlock the screen and press Ctrl + F1  this would open the terminal for the VM.
  • Open the file /etc/init.sh with write access (Use su to gain root access and then vi /etc/init.sh)
  • Put the following lines at the end of the file.Save and close the file
    • netcfg eth0 up
    • netcfg eth0 dhcp
    • setprop net.dns1 8.8.8.8
  • Execute netcfg on terminal. It should should eth0 marked with the a local n/w IP address (192.168.1.2 in my case).
  • Open the browser to check if internet is working. If not, then restart the VM.

Once the internet connection is established then we can connect the VM through the adb by issuing the following command adb connect <IP address>.  Start your eclipse Open Devices View and the VM should be listed as an online device.

Changing Screen resolution for the VM

In case of simulating different screen resolutions we can configure the VM to ask for the resolution with which the VM should start with (link)

  • Start the VM and from the GRUB menu select debug mode
  • Run the following commands to update menu.lstfile
    • mount -o remount,rw /mnt
    • vi /mnt/grub/menu.lst
    • Update the kernal command to add DPI=160 and vga=ask, in both the normal boot command and the debug boot command
    • Save and exit the file
  • Un-mount and restart
    • cd /
    • unmount /mnt
    • reboot -f

Now on restart it will ask you the VGA resolution that needs to be selected.

Also we can add the resolution information directly to the .vbox file to Virtual Box by issuing the following command

VBoxManage setextradata <vm_name> <CustomVideoMode1> <1200x768x16>


Running On VMWare

Running an x86 image on a VMWare is also pretty simple

  1. Download the iso image from the link above. Create a new machine in VMWare Workstation
  2. Select the installer disc image as the one just downnloaded. Select Other as a the Operating System. Then select Free BSD   from the download below.
  3. Give the name for the VM and Disk Size in the next Screens and click finish to create the Virtual machine
  4. In the network Section of the VM option select with NAT or else Bridged Adapter.
  5. Start the VM and follow the installation steps as mentioned earlier.

Virtual Machine did have pretty good benefits as compared to the emulator and hence its suggested.

  1. Running the VM is much faster as compared to the android emulator.
  2. Also,we get keyboard control
  3. We can test the app for multiple reslutions.
  4. It lacks orientation support as of now

Hope this tutorial will help you in setting up the Android image successfully.

Spring redirection

There are two way of redirection present in Spring that I have come across . Forward and Redirect.  We have been using redirect, but have been facing a problem. Each time we redirect our model attributes get attached to the URL as query String paramaeters. This is not right as it exposes the internal handling of elements in the application. So we needed to prevent the model attributes from appearing in the URL.

After digging for solution I got to know that spring itself provides us with the option for attaching or detaching the model attributes from the queryString. We needed to check ig the view is coming in as a redirectView. If it is then set the modelAttribute parameter to false. And now the model attributes will not be visible in as query String.

As I am using URLBAsedViewResolver I had to override the createView() method to provide my custom implementation.

Below is the code for the same

if(element instanceof RedirectView)
{
    RedirectView redirectView = (RedirectView)element;
    redirectView.setExposeModelAttributes(false);
}

Configuring Locale in Spring

Locale is one of the most important thing that you need in case you want to internationalize the messages. In Spring it is really very easy to configure Locale both at runtime and at application load time.

To setup locale we need 2 things

1. SessionLocaleResolver

2. LocaleChangeInterceptor

SessionValueLocale sets the param value for the Locale. the properties files will then be suffixed with the param value supplied to look for locale specific properties.

<bean id="localeResolver">
        <property name="defaultLocale" value="en_US" />
</bean>

This would setup the Locale for the application for “en_US”. Hence we need to have something like messages_en_US.properties which will house the locale specific messages

LocaleChangeInterceptor  can help users to change the locale at runtime based on the locale parameter provided with the request.

<bean id="localeInterceptor">
         <property name="paramName" value="lo" />
</bean>

After configuring this we can pass in the locale params through URL query string, with the key being the paramName specified in the bean property

EG:- for setting a UK based locale we pass ?lo=en_UK. So the messages will be picked from messages_en_UK.properties.

We also need to added the above bean as an interceptor for handler mappings so that it wired with each request directed to the application

<bean 
class="org.springframework.web.servlet.mvc.support.
ControllerClassNameHandlerMapping" >
       <property name="interceptors">
             <list>
                  <ref bean="localeInterceptor" />
             </list>
       </property>
</bean>

Setting up JBOSS AS7 with eclipse

April 26, 2012 1 comment

I recently got a chance to try out JBOSS AS7 as application server container for the upcoming project and I must say that JBOSS is no longer the monotithic,tiring,heavy and problamatic server anymore.It took me 4 seconds to run the server, which is fascinating considering the legacy.  Parallel deployment. quick startup,lightweight, powerful feature etc are some nifty features on offer

So, as part of the initial requirement, we have to setup a maven based project and then deploy that onto JBoss AS7 through Eclipse and trust it was’nt a piece of cake and henceforth I decided to  write a post about it.

  1. Download and unzip JBoss AS7 from http://www.jboss.org/jbossas/downloads/ to a convenient location
  2. Create a basic maven project from maven quickstart archtype.
  3. This is optional step if you are planning to use JBoss external to Eclipse.
  4. Download JBoss Tool for Eclipse from the following update site. You will only need to install JBoos AS Tools for registering/creating a server.This is optional step if you are planning to use JBoss external to Eclipse.
  5. Setup a JBoss Community Server within eclipse,Server->JBoss AS7 by providing the path to JBoss folder. This will help you in displaying the logs in eclipse console.
  6. AS7 currently deploys wars that are present within standalone/deployments folder.

The problem was how to deploy the war file into JBoss automatically from eclipse.  The steps follwoed with tomcat did not work and I had to come up with some different solution. I thought against making the changes in JBoss configuration.So, I thought that maven creates a war in target folder by default.We can change the o/p directory such that the war is created within the standalone/deployments folder. This way our updated war reaches JBoss each time we build the project and since JBoss is running within it would be automatically deployed, and I can track the log messages in the console.

To achieve this I used the maven-war-plugin in pom.xml. I configured the plugin to set the OutputDirectoy to the standalone/deployment folder.And Voila, it worked, so we were able to wire our project with JBoss seamlessly and also were able to reload the context automatically without going through the pains of understanding the JBoss configurations.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <outputDirectory>/path/to/standalone/deployment</outputDirectory>
  </configuration>
 </plugin>

Also through AS7 Maven Plugin
Add the following maven plugin info in pom.xml

 <pluginRepository>
   <id>jboss-public-repository-group</id>
   <name>JBoss Public Maven Repository Group</name>
   <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
 </pluginRepository>

<plugin>
 <groupId>org.jboss.as.plugins</groupId>
 <artifactId>jboss-as-maven-plugin</artifactId>
 <version>7.1.1.Final</version>
 <configuration>
  <hostname>localhost</hostname>
  <port>9999</port>
  <filename>${project.build.finalName}.${project.packaging}</filename>
  <webModule>
   <groupId>${project.groupId}</groupId>
   <artifactId>${project.artifactId}</artifactId>
   <contextRoot>/test</contextRoot>
  </webModule>
 </configuration>
</plugin>

The execution can be configured through the following entry, which says if the maven phase is package then next linked goal should be delpoy

 

<executions>
  <execution>
   <phase>package</phase>
   <goals>
      <goal>deploy</goal>
   </goals>
  </execution>
</executions>

Behaviour Driven Development using Cucumber

April 25, 2012 Leave a comment

Behavior Driven Development(BDD) is an acceptance testing methodology coined by Dan North.This can be used for writing acceptance test cases at business/product owner. These acceptance cases are then mapped to unit test which test whether the module adheres to the requirements.I was given a task to explore how to incorporate BDD for our agile project,so I am just trying to put forward the basic setup and usage of BDD using JUnit and cucumber-jvm(successor to Cuke4Duke) also know as Cuke

Cuke believes that accpetance tests can be clubbed under different scenarios, each of which being a combination of  Given [initial context], when [event occurs], then [ensure some outcomes],and[additional outcomes]. In this post I will try to cover setting up Cuke in a maven project and writing basic BDD

We start by creating a maven project using quicktype archtype. Add the following pom entries to get cuke dependencies.

<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-java</artifactId>
   <version>RELEASE</version>
   <scope>test</scope>
 </dependency>
 <dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-html</artifactId>
   <version>RELEASE</version>
   <scope>test</scope>
 </dependency>
 <dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-junit</artifactId>
   <version>RELEASE</version>
   <scope>test</scope>
 </dependency>

We will experiment by creating a single case for addition of two numbers.Once the project is in place create the add.features files in src/test/resources folder(create if not existing). This will contain the acceptance criteria against which the test cases are to be written. Put the following content in add.feature  

Feature:Simple Addition
Scenario: Addition
     When I add 4 and 5
     Then the result is 9

Here adding two numbers is the feature that I want to add to my module.So, in the features file we first define the feaure that we are planning to test on. Then, we define the possible scenario’s. In this case it’s addition of two number.You can add multiple scenarios in a single feature like addition of floats, addition of  3 4 numbers depending on depth of the feature.Various clauses that can be used within the Scenario are Given,When,Then,And

Once the feature file is done, we move to defining the Step definition files. Each Clause is basically a step definition i.e it maps to a single function in the java file. For each feature it is recommended to create a separate step definition file. For this case the step definition file will have the following content.

public class AdditionStepdefs {
  @When("^I add (\\d+) and (\\d+)$")
  public void adding(int arg1, int arg2) {}
  @Given("^I press (.+)$")
  public void I_press(String what) {}
  @Then("^the result is (\\d+)$")
  public void the_result_is(double expected) {}
}

This is an empty step definition file. Each feature will have one. We also need a runner which will run the test cases with cucumber. So create a file AppRunnerTest.java with the following content

@RunWith(Cucumber.class)
public class AdditionTest {
}

 

This is a basic cuke setup and the basic explanation of what can be achieved through Cuke. Cuke aims at automating the acceptance process and improve code test ability and feature deep-dive.

 

 

Adding tomcat to maven

April 15, 2012 Leave a comment

There often arises case that we check out a maven project which is supposed to be deployed as a web application but it is not configured as Dyanmic Web Project, so that it can be launched directly from eclipse “Run As Server” command.Adding a DWM facet to project screws the entire project structure, leading to a lot of errors.

I had my issues in deploying a maven project onto an eclipse tomcat server, so I decided to look for a solution to this problem somewhere through maven. I wanted  that post packaging, maven should be able to run tomcat and deploy the war file onto that.

Maven provides users clean methods to integrate tomcat with maven plugin, namely tomcat:<maven goal>. This project was previously hosted with codehouse.mojo but since moved under the apache tomcat umbrella.

These are the steps I followed to get rid of this problem.

1. Download and install tomcat-apache-maven project through pom entry

<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat6-maven-plugin</artifactId>
 <version>2.0-beta-1</version>
</plugin>

The version can be 6 or 7 depending on the requirements. This would bootstrap a default tomcat container, downloaded through maven to be used for deploying and running the application.

Tomcat can then be run-in through the following goals

tomcat6/7:run,deploy,list,redeploy,sessions,undeploy,stop,exploded

deploy goal simply assembles the war and deploys it to tomcat through tomcat manager using HTTP PUT

To avoid assembling a war file at the time of deployment simply use exploded goal.

You can change the versions of the tomcat dependencies by providing custom dependencies.

   <dependencies>
 <dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>catalina</artifactId>
    <version>6.0.23</version>
   </dependency>
</dependencies>

Tomcat Configurations

Various things can be set in as per the needs by altering the configuration information within the plugin module.Things like listening port,ajp port, war directory,context file etc can be modified through this.You can refer to an existing tomcat configuration folder by setting the <configurationDir>

Also, for lazy people like me you can also set automatic context reloading by setting <contextReloadable> to true . 

More information can be found on the following apache link

http://tomcat.apache.org/maven-plugin.html

Data Collection from Flume-NG to HDFS

January 22, 2012 17 comments

I have just started using/exploring Flume-NG as a distributed data collection tool. It’s pretty similar to Scribe, but more powerful and customizable.I found it very interesting and thought of giving it a try for a prototype.Flume-NG basically enables me to collect data from different sources and then redirect them to a single point for collection or possible aggregation.The data could be logs, events or even system triggers that can arise over any machine over the distributed system. With Flume-NG, I can gather information from multiple systems and store them on single source, a File or HDFS.

This is a very initial post about how to setup Flume-NG and then connect to a HDFS system to storing the collected data.The system based requirements are as follows –

1. Install Apache Flume-NG

Apache Flume-NG 1.0 incubation version.You can get the code from the GIT, by following the step as mentioned in the link below.

     http://bit.ly/wxao5o

a. Once you download the code, run mvn package to create Flume-NG distribution.Extract the distribution to a place or your choice.

b. Create a folder /var/log/flume

c. Create a symLink flume in /usr/local/. This symLink should point to the Flume-NG distribution that you have extracted in Step a.. Also you can create a symLink in /usr/bin/  if you want to run Flume-NG from command-line directly

                sudo ln -s /usr/local/flume/bin/flume-ng flume

With this, you should be able to install Flume-NG on your machine

2. Install Apache Hadoop

Information on how to setup Hadoop can be referred from

      http://yhoo.it/y6Wxl8

This outlines the setup procedure and the commands to get yuoe started with Hadoop.I installed hadoop on my ubuntu using apt-get install hadoop .  I installed hadoop as a single node setup for experimental purposes.

a. You might need to create a user ‘hadoop‘ and grant him su access, if you want to create a seperate workspace for Hadoop. I did that.

b. Hadoop requires SSH to connect to and manage the nodes. Hence, if like me you are running hadoop on the same machine, then you need to make sure that ssh is enabled on you machine and also you need to install ssh Server to service incoming SSH request from hadoop.Install ssh,rsync and openssh-server.Change the port of ssh to something other than 22, I changes it to 2250. You can do this by modifying the /etc/ssh/sshd_config  and change Port 22 to a value of your choice.

 sudo apt-get install openssh-server

Now the problem comes that, if you chnage the ssh default port to some value then you need to change hadoop configurations as it tries to connect to default port(22). For this open {HADOOP_HOME}/conf/hadoop-env.sh. Search for “HADOOP_SSH_OPTS”  and add ‘p <Port Number>’. Save and close the file. Restart Hadoop, now if will connect to the defined post for ssh connection.

c. Also in the file  {HADOOP_HOME}/conf/hadoop-env.sh set the JAVA_HOME to the installed java path.

Try the commands as mentioned the Yahoo tutorial to get accustomed with how to use Hadoop.Will try to more on Hadoop,once I know more about it :).

Now, I guess we should have both FLume-NG and Hadoop running on a single machine. Good, now the idea is to tail a file and send the data to HDFS for storage. For this we require 2 Flume-NG agents. One which will collect data from the file and other that will put the data in HDFS.I will call them agent1 and agent2.

Now in order to start a node in Flume we need to define configuration files for the agent(This is different and a tad difficult from Flume). So we need to create standard java properties file.

In each file we need to define a source,sink and channel. Since the post is getting pretty long, I will skip the configuration properties  as of now. The properties file, can be placed in the conf folder of Flume-NG.

Issue a flume command to start agent2(Which puts data on HDFS).

              flume-ng node -c ../conf/ -f ../conf/agent2.properties -n agent2

-c define the configuration folder.

-f The Configuration filename for the Flume-NG node(Mandatory)

-n The name of the Flume-NG node(Mandatory)

This would start a node with HDFS as a sink,Apache Avro as a source and memory as a channel.

In the similar fashion start another node agent1

              flume-ng node -c ../conf/ -f ../conf/agent1.properties -n agent1

Now, I am tailing catalina.out using my agent1 for any changes and I would be pushing the same logs to HDFS using my agent2.

I simply restart my tomcat to generate logs in catalina.out and in my agent2 terminal I can see that data has started pouring as constant HDFS block, in the data directory, that I have mentioned in my core-site.xml file of Hadoop.

So with this I have successully used Flume-NG to demonstrate the process of data collection. I can define agents in N systems (Agent1), which will collect data and then pass on to a single source(Agent2), which will be writing data in Hadoop.

Next goal would be to play with Flume-NG code to see if other sinks apart from HDFS can be plugged in, or else how I can refine and filter the contents of the data, en-route HDFS.

Thanks..!!

Create your own website, free on WordPress.com.Create your own website.
Start free