Tuesday, June 18, 2013

Maven javac: invalid target release: 1.7

When I try to compile my maven project by running "mvn package", I get the following error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project onix-generator: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.7
[ERROR] Usage: javac
[ERROR] use -help for a list of possible options
1) Check your Java version:

java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode) 
2) Check javac version:

javac -version
javac 1.7.0_09
3) Check $JAVA_HOME

Make sure it points to the java bin directory.

How to create a Maven project

First install Maven - Read Install Maven 3 on Amazon EC2 Ubuntu.

Create a folder anywhere you like. cd into the directory.

Create a Maven project
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.maventest -DartifactId=maventest
The CLI will prompt for a few options:

1.) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 284:

Push Enter. We will use the default 284.
remote -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)
2.) Choose org.apache.maven.archetypes:maven-archetype-quickstart version:

Choose 1.1 (Number 6).

3.) Define value for property 'version':  1.0-SNAPSHOT: :

You can leave the version "1.0-SNAPSHOT" as the default value.

4.) Confirm properties configuration:

Push Enter.


You should see a folder created.

Monday, June 17, 2013

AWS - Elastic Map Reduce Tutorial

MapReduce has become a very common technique utilizing parallel computing.

Let's say you have a database table with username and description columns in it. You want to replace html tags in the description column with empty spaces. Let's say the database has petabytes of data. It will take forever for a single machine to do this job.

MapReduce works by distributing this job among multiple machines. Each machine executes different dataset in parallel, and then the outputs will be aggregated. Therefore, a job that may take days to compute can take only mins to finish.

In this tutorial, we will experiment with Amazon's Elastic MapReduce.

Let's get started.


Create a S3 bucket

Elastic MapReduce uses S3 to store it's input and output. We will first create a bucket.

Log into your Amazon Web S3 console. Create a bucket, say my_map_reduce_data. Amazon S3 bucket names need to be unique across all Amazon S3 buckets. It's best to prefix it with your company name.


Create input data

Let's create a text file and put some random data into it. We will create a MapReduce function to count word frequencies.

Ex.
apple apple orange orange orange
pear pear pear pear pear pear pear pineapple pineapple

Label this file input.txt.

Create a folder inside my_map_reduce_data and call it input.


Implementing the mapper function

Download the following file and save it as wordSplitter.py

https://s3.amazonaws.com/elasticmapreduce/samples/wordcount/wordSplitter.py

It's a script that reads the input file line by line and prints out the number of occurrence for each distinct word in that line.

Upload wordSplitter.py to my_map_reduce_data


Launch the Elastic MapReduce Cluster

Sign in to the Elastic MapReduce Console.

Click on Create New Job Flow.

Give the Job Flow Name WordSplitter.

Choose Amazon Distribution for the Hadoop version.

Choose Streaming as the job flow type. You write the mapper and reducer scripts in any of the following languages: Ruby, Perl, Python, PHP, R, Bash, or C++.

Click Continue.


Input, output locations

Fill in the following:
Input Location: my_map_reduce_data/input
Output Location: my_map_reduce_data/output
Mapper: my_map_reduce_data/wordSplitter.py
Reducer: aggregate

Click Continue.


Configure EC2 Instances

Leave the options as it is.

Click Continue.


Advanced Options

If you want to ssh into the master node, specify the Amazon EC2 Key Pair.

For the Amazon S3 Log Path, put my_map_reduce_data/logs

Check Yes for Enable debugging. It will create an index of the log files in Amazon SimpleDB.

Leave the other boxes as NO.


BootStrap Actions

Proceed without bootstrap actions. BootStrap allows additional software to be installed in the cluster nodes before the MapReduce process any data.


Review the information and start the job. You should see the job being started.

You can monitor the status of the nodes in the MapReduce Web console.

Check the output folder in S3 after the job is completed.

Remember to delete all buckets to avoid getting charges.

Sunday, June 16, 2013

Composer Update doesn't install files

If you ever update with composer.phar and not seem to get any files fetched, it may be a cache issue.

Remove the composer cache folder.

Ex. rm -rf /root/.composer

Make sure you delete the whole .composer folder. Not just the cache folder inside.

Symfony 2 FOSUserBundle - overriding the registration success event

I was trying the change the registration flow of FOSUserBundle the other day. The goal is to let new users to use the site without activating their accounts while an activation email can still be sent. Every time these users log in to the site, a flash message will show up and ask them to activate their accounts.

The first thing I did was creating a EmailConfirmationListener. You can copy this file from the FOSUserBundle in the vender's folder. All I did was 1) setting user isEnabled flag to true and 2) changing the route (if needed).

Note that the EmailConfirmationListener registers the following event:
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess'
When I registered a new user, I registered two activation emails were be sent.

The trace log shows that two onRegistrationSuccess events were fired. One is the one from the vendor, the other one is the one I just created.

The listener service is declared in email_confirmation.xml.

Doing a quick search on the project root folder for the term "email_confirmation.xml" reveals the following:
if ($config['confirmation']['enabled']) {
         $loader->load('email_confirmation.xml');
}
Now turn the confirmation setting to false in config.yml

fos_user:
    registration:
        confirmation:
            enabled: true

Then only one onRegistrationSuccess event would be fired.

Saturday, June 15, 2013

Symfony 2 JS Error in Production Only - Assetic Compression

If your JS files work perfectly in dev but not in production, it may be a compression issue indirectly caused by the Assetic bundle.

Make sure every single javascript file ends with a semi colon. The issue is that JS allows files to not end with semi colon, but when Assetic compresses and combines all JS files, the files are appended and causing incorrect syntax error.

Friday, June 14, 2013

Symfony 2 Composer - error occurred when generating the bootstrap file


[RuntimeException]                                  
An error occurred when generating the bootstrap file.

If you see the following error during updating Symfony vendors via Composer, do the following:


php composer update --no-scripts
php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php