While Web Projects are a convenient way to get started using Mortar, Mortar Projects make it much easier to develop a large Hadoop project with a team. Mortar Projects give you:
Pig and Hadoop on Your Computer: When you create a Mortar Project, you get a local installation of Pig and Hadoop ready to use, without needing to install anything yourself. That means faster development, and better testing.
Version Control and Code Sharing: Mortar Projects are backed by source control, either through Mortar or your own system, so you can collaborate with team members on a project.
1-Button Deployment: When you're ready to run your project on a Hadoop cluster, a single command is all that's needed to deploy and run in the cloud.
First, install the Mortar Development Framework to your local computer and login.
Mortar has an example project that contains sample code for different styles of analysis. Clone this example project using git.
git clone firstname.lastname@example.org:mortardata/mortar-examples.git cd mortar-examples
In order to take a quick look at how to run Mortar Projects, let's use the
mortar-examples project in your favorite dev environment and look at the
coffee_tweets.pig script. This script calculates the
percentage of tweets in each state that indicate "coffee snobbery."
The best way to understand what this script is doing is to run an illustrate on it. This will let us see the data flowing through every alias to figure out what is changing at each step.
Rather than send our code out to the cloud and wait for the response to come back, we can get a much faster result by using Mortar's local mode. This uses Pig and Hadoop installed locally to perform an illustrate, and thus can run very quickly.
Run a local illustrate.
# Uses read-only example AWS keys - use your own keys for your data export AWS_ACCESS_KEY="AKIAJ54D5RAJFAYAEFZQ" export AWS_SECRET_KEY="frNw2FM1UqE1VmTRe8TZ7AloIpLeugdRCBW74pJX" mortar local:illustrate pigscripts/coffee_tweets.pig
The first time you run a local command, Mortar will download and install dependencies. Once that's done for a project, you should see very fast illustrate results. Run the command again to see a speedy illustrate.
Sometimes when developing, illustrate doesn't give you enough feedback about how your script is working. In these cases you can try running your code against a small subset of your data to see how it works. To avoid the time and cost of running your job on a remote Hadoop cluster you can use Mortar's local mode.
mortar local:run pigscripts/coffee_tweets.pig
Now that the example code exists locally, you can register it as a project with Mortar. This will allow you to run the code using Mortar, and also make the project accessible to other users in your Mortar account.
In order to register a project with the Mortar service you'll need a Mortar account with a plan that supports creating Mortar Projects. Once logged into your account you can go to the Plans Page to view your current plan or upgrade to a new plan.
Mortar project names share one global namespace so you'll need to pick a unique name. For this tutorial you can prepend your Mortar handle to "mortar-examples" in order to generate a unique name.
Register a project.
mortar projects:register <your-handle>-mortar-examples
Once we are happy with our script, we can deploy it to run on a cluster. All we need to do this is to use the
mortar jobs:run pigscripts/coffee_tweets.pig
If we specify no parameters, this will by default launch a 2-node cluster to run the script on. As output of this command,
you should be given a
jobs:status command to run to see the job progress.
mortar jobs:status YOUR_JOB_ID_HERE --poll
You can also check on your job status by logging into the Mortar website and viewing the Jobs Page.
Once your job is done, you can visit the Job Details page to download a list of the states with the most coffee snobs per tweet-capita.
AT THIS POINT, YOU SHOULD BE ABLE TO:
Next, let's see how to start a Mortar Project from scratch with Developing a Mortar Project.