Monday, November 2, 2009

how to setup clover with multi-module maven project and build with bamboo

Ok so i figured how to setup clover with maven on a mulit-module project with putting the config in a maven profile:

<profile>
<id>clover</id>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
<targetPercentage>${clover.coverage.percent}</targetPercentage>
<snapshot>/development/build-server/clover/${groupId}-${artifactId}/clover.snapshot</snapshot>
<generateHtml>true</generateHtml>
<generateXml>true</generateXml>
<baseDir>${project.basedir}</baseDir>
<licenseLocation>/development/build-server/clover/clover.license</licenseLocation>
</configuration>
<executions>
<execution>
<id>clover</id>
<goals>
<goal>setup</goal>
<goal>snapshot</goal>
</goals>
</execution>
<execution>
<phase>verify</phase>
<goals>
<goal>aggregate</goal>
<goal>clover</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</profile>


Simply drop that into your profiles section in your pom. You will need to change the paths of where you have put your clover licence and where you want the snapshots to be stored. Then when you want to run it use this command.

mvn -P clover install


Bamboo

Setup bamboo as normal but make sure you don't let bamboo clear out your build directory each time or clover won't work. So untick the option to clean out the build directory each time.

Thursday, October 15, 2009

Grails: the Iron Man suit for the Tony Stark developer

Just thought i would put a response together for this post:

Grails dark side

In my opinion the Grails sweet spot is for developers who already have years of experience of building web app with spring/hibernate/sitemesh and java.

Basically it is the "iron man suit" for an already established "Tony Stark" developer. The iron man suit is at its most powerful when it is controlled by Tony Stark. A man who has years of experience of solving problems. The suit simply enhances him :)

I have years of experience of using the spring/hibernate/sitemesh/java stack along with deploying java web apps on java app servers. So Grails is my "Iron Man Suit"

For me Grails is essentially the same core deployed in the same way. The difference is that Grails + Groovy is literally super glue for these components. Almost like comparing assembling your own Ikea furniture vs carving your own out of wood. Except the end quality is even better.

So thinking that you can get the absolute most out of Grails without knowing anything about spring or hibernate etc is ignorant. And actually being ignorant of the underline technologies often leads to assumption that a bug with the underline technology (eg hibernate) is a bug with Grails.

Wednesday, September 16, 2009

Turn off caching in Liferay (development mode)

Hi All

Long time no post. But here is a little snippit of a trick I discovered but had to do some serious google searches to find.

To turn off the liferay caching in Liferay for when you are developing all you have to do is this:

Find this file:

$LIFERAY_HOME/tomcat-6.0.18/webapps/ROOT/WEB-INF/classes/portal-developer.properties

Can copy it and rename it to:

$LIFERAY_HOME/tomcat-6.0.18/webapps/ROOT/WEB-INF/classes/portal-ext.properties

This will disable all caching in Liferay such as css, javascript and vm templates.

Hope this helps.

Tuesday, July 21, 2009

Workaround to a nasty Grails 1.1.1 bug

Hi all

Just wanted to post quickly about a workaround to a Grails bug I dropped into to my application lately. There seems to some strange problem with Grails not binding the GORM methods to the domain objects intermittently.
Eg horrible errors like this


groovy.lang.MissingPropertyException: No such property: save for class: XXXXX



I only seem to get this problem in production on a Tomcat 6.0 server. I super quick fix that seemed to solve it at the time was to restart the tomcat server after a deployment. But that was too shaky for me.

Unfortunately is happening on a really important piece of my application. When i take payment. So i end up taking payment via my provider Paypal but not saving the transaction details in my own database.


Anyway after some searching around it seems like the problem it might have been fixed in the upcoming Grails 1.1.2

But for now this seems to do the trick. Someone posted this quick fix on the forums. The problem is with the hibernate only lazily adding the GORM method and some problem with groovy not recognising them.

So the trick is to get Hibernate plugin to register them at start up. So in your bootstrap.groovy add the following:

class BootStrap {

def grailsApplication

def init = {servletContext ->


switch (grails.util.GrailsUtil.environment) {

case "production":
grailsApplication.domainClasses.each{
def clazz = it.clazz
println "Clazz: $clazz count: " + clazz.count();
}
break;

case "development":
// dev stuff
break;
}
}

}


This simply calls count on all domain objects and prints out the count. You don't have to print out the count it was just nice for me.

Hope this helps

Tuesday, July 7, 2009

Grails developer available: Get them while there hot

Hi Peeps

This is just quick shout out to the community. I will be available to start a Grails contract from 20th July. So if you have any new cool projects coming up and are looking for a developer then let me know.

You can get me on peter.delahunty@gmail.com

Tuesday, June 30, 2009

Deploying a Grails app on EC2 from scratch.

Hi All

Ok so i have found some time write up how to deploy a Grails app onto EC2. This is a step by step guide to setting up Apache, Tomcat, Mysql, Java on an ubuntu Ec2 Box

For those who do not know. EC2 is Amazon's (that's right the one famous for books) hosting service of its webservice suite. It allows you to run virtual server images on it amazingly scaleable infrastructure. Plus you only pay for what you use. If your server is up for 4 hours you pay for 4 hours. $0.10 per hour (about). You can build your own server as i will show you in the steps below and manange it on their infrastructure.


These are the steps i have taken and they work for me. I am sure there are hundreds of ways to skin a cat (so the cat skinners say) but this is my way. Take it or leave it :)

Pre-Requisites

1) Get Firefox i am sure you have it already if you don't get it you will need it. As of writing this i am using 3.0.11 download here

2) Install the EC2 Firefox plugin (Elasticfox) download here

3) Install the S3 firefox plugin download here


4) Open an amazon account. This is a five min job requiring a valid credit card. Signup here
Once you have an account you then need to open a EC2 account and an S3 account.


5) Then next step is for you get familiar with the tools. You can do this by following the getting started guides in this ebook.

Gettings started


IMPORTANT !!!

You need to read the getting started guide and get familiar with things before you read the rest of this blog post. Otherwise it will not make sense. I am assuming from here onwards you have read an tried out the service.


Setting up a server to run a Grails app.

By now you should have terminated any test instances you had running on EC2 and be ready start a fresh.


1) Start with a baseline Linux image

Ok i have decided to host my application on Linux basically because there was no descion to be made. I would only ever host a serious website on Linux and never windows.

The base linux version i used is Ubuntu 8.10 (intrepid) i am also using a 32bit and not 64 bit. You can find the AMI codes here

https://help.ubuntu.com/community/EC2StartersGuide

I have chosen to go with AMI ami-5059be39 because it is based in the US and is 32Bit. If you want to run your servers in Europe then go with this ami-80c0e8f4

Ok now you should have a running instance of the ubuntu basic server. Connect to the server using an SSH terminal

Create a directory called downloads in side your home directory /home/ubuntu and cd into it.

2) Next you want to install Java

You should be in the downloads directory you created above

Download java 1.6. Right that now happens to be JDK 6 update 14. To do this i goto the java download website .

Choose JDK 6 update 14
Choose linux
Then copy the download link for the NON rpm version the second link

Now on your EC2 machine run the following command

wget <THE JDK DOWNLOAD URL>


This will now download the JDK install file onto the box

NOTE you might want to rename the file:

mv <NAME OF THE FILE>  jdk-6u14-linux-i586.bin


Next copy the file to /usr/local

sudo cp jdk-6u14-linux-i586.bin /usr/local



Change the permissions


sudo chmod +x jdk-6u14-linux-i586.bin



Then run the install file


sudo ./jdk-6u14-linux-i586.bin



This should unpack the java file to this directory /usr/local/jdk1.6.0_14

Next create a symbolic link to the directory called java


sudo ln -s /usr/local/jdk1.6.0_14 /usr/local/java


That is java installed.

3) Next install MYSQL

Download mysql via the same way you downloaded java above using wget you get the download link here

Choose the Linux (x86) download

Copy the mysql tar file into /usr/local


sudo cp mysql-5.1.35-linux-i686-glibc23.tar.gz /usr/local


Delete any existing mysql directories. (this maybe optional)


sudo rm -rf /etc/mysql



Next follow these commands to install it. IMPORTANT: Don't follow any of the step that are listed by the mysql_install_db script they will be covered later.


sudo groupadd mysql
sudo useradd -g mysql mysql
sudo cp mysql-5.1.35-linux-i686-glibc23.tar.gz /usr/local
sudo cd /usr/local
sudo gunzip mysql-5.1.35-linux-i686-glibc23.tar.gz
sudo tar -xvf mysql-5.1.35-linux-i686-glibc23.tar
sudo mv /usr/local/mysql-5.1.35-linux-i686-glibc23 /usr/local/mysql
sudo cd mysql
sudo mkdir logs
sudo chown -R mysql .
sudo chgrp -R mysql .
sudo scripts/mysql_install_db --user=mysql
sudo chown -R root .
sudo chown -R mysql data
sudo bin/mysqld_safe --user=mysql &


Right now you should have running mysql instance

Copy the standard startup script into the linux startup area


sudo cp /usr/local/mysql/support_files/mysql.server /etc/init.d/mysql


Setup mysql to run at all levels


sudo update-rc.d mysql defaults


Set a root password


sudo /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
sudo /usr/local/mysql/bin/mysqladmin -u root -h 'localhost' password 'new-password'


Ok now you have a running mysql instance

4) Next you want to move the Mysql installation on to an amazon EBS.

You should already know about an EBS from reading the EC2 getting start guide above.

Create a new EBS using Elastic fox and attach it to your EC2 instance. You will be asked to enter a device when you are attaching the EBS to your running EC2 instance. Enter the following:


/dev/sdh


Once you have done that you want to mount and format that diskspace. I am simply following the instructions found here but have modified it bit as my paths are different

Install XFS. This is a secure file system.


sudo apt-get install -y xfsprogs


Setup the mount and fomat the disk


sudo modprobe xfs
sudo mkfs.xfs /dev/sdh

echo "/dev/sdh /vol xfs noatime 0 0" | sudo tee -a /etc/fstab
sudo mkdir /vol
sudo mount /vol


You should now have a new filesystem under /vol

Stop mysql if running


sudo /etc/init.d/mysql stop


Move all the mysql files


sudo mkdir -p /vol/usr/local/mysql

sudo mv /usr/local/mysql /vol/usr/local


Remount the mysql directory to the volume


sudo mkdir /usr/local/mysql

echo "/vol/usr/local/mysql /usr/local/mysql none bind" | sudo tee -a /etc/fstab
sudo mount /usr/local/mysql



Restart mysql

Stop mysql if running


sudo /etc/init.d/mysql start


You now have mysql running from an EBS


Setup mysql database user and backup script


/usr/local/mysql/bin/mysql -p -u root


create database


CREATE DATABASE demodb CHARACTER SET utf8 COLLATE utf8_general_ci;


create app user and backup user and give access:


CREATE USER 'demouser'@'localhost' IDENTIFIED BY 'demouser123';
GRANT ALL PRIVILEGES ON demodb.* TO 'demouser'@'localhost' WITH GRANT OPTION;

CREATE USER 'backup'@'localhost' IDENTIFIED BY 'backup123';
GRANT LOCK TABLES, SELECT ON demodb.* TO 'backup'@'localhost';


Setup db backup:

Download the mysql backup script:


http://sourceforge.net/projects/automysqlbackup/


For putting files in s3 use this


http://s3tools.org/s3cmd

apt-get install s3cmd






6) Install Tomcat

This is easy to install
Download tomcat 6 into your /home/ubuntu/downloads using wget
Copy the jar file it to /usr/local

Use the java jar command to unpack tomcat zip


sudo /usr/local/java/bin/jar -xvf /usr/local/tomcatXXX.zip



Create a symbolic link to Tomcat


sudo ln -s /usr/local/tomcatXXXX /usr/local/tomcat



Next create tomcat user to run tomcat


sudo groupadd tomcat
sudo useradd -m -s /bin/bash -g tomcat tomcat



Change to tomcat user and edit the .profile to add java in the PATH


sudo su - tomcat
vi /home/tomcat/.profile


Edit the file using vi to contain


export JAVA_HOME=/usr/local/java
PATH=$JAVA_HOME/bin:$PATH


configure the server.xml to use an AJP connector to work with apache.

save your old /usr/local/tomcat/conf/server.xml to server.xml.orig


cp /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.orig


edit a new server.xml


vi /usr/local/tomcat/conf/server.xml


copy this config in there:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<Service name="Catalina">

<!--
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->

<Connector port="8009"
protocol="AJP/1.3"
redirectPort="8443"
connectionTimeout="300000"
maxThreads="200"
backlog="50"
enableLookups="true"
emptySessionPath="true"

/>

<Engine name="Catalina" defaultHost="localhost">

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

</Host>
</Engine>
</Service>
</Server>



That is tomcat setup. You can run it if you like to see it working.

Now just run tomcat


sudo su - tomcat
/usr/local/tomcat/bin/startup.sh



6) Install Apache

This is easy


sudo apt-get install apache2


Enable AJP mod


sudo a2enmod proxy_ajp


Create a new site to configure AJP with tomcat. You can change the to whatever you want.



sudo vi /etc/apache2/sites-available/webapp


add the following config to link apache to tomcat


<ifmodule>
ProxyRequests On
ProxyVia On

<location>
Order allow,deny
Allow from all
ProxyPass ajp://localhost:8009/
ProxyPassReverse ajp://localhost:8009/
</location>

</ifmodule>

Enable your site


sudo a2ensite webapp


disable the default apache config


sudo a2dissite default


start or restart apache


sudo /etc/init.d/apache2 restart



That is basic apache installed

To secure apache with basic authenication:



sudo mkdir /etc/apache2/passwd
cd /etc/apache2/passwd
sudo htpasswd -c site-access



add these lines to the webapp config to secure:

<Location />
Order allow,deny
Allow from all

AuthType Basic
AuthName "Restricted area"
AuthUserFile /etc/apache2/passwd/site-access
Require valid-user

ProxyPass ajp://localhost:8009/
ProxyPassReverse ajp://localhost:8009/
</Location>





To enable SSL on the apache instance:

Enable ssl mod


sudo a2enmod ssl


generate your .key and .crt files. The company who you bought your SSL certs from should tell you how to do this.

make a new director to put the .key and .crt file in:


sudo mkdir /etc/apache2/ssl


copy the .key and .crt files into that directory. eg:


/etc/apache2/ssl/www.mydomain.com.crt
/etc/apache2/ssl/www.mydomain.com.key



Create a new site to configure ssl.


sudo vi /etc/apache2/sites-available/ssl


copy this config

<VirtualHost *:443>
DocumentRoot /var/www/

<IfModule mod_proxy_ajp.c>

ProxyRequests On
ProxyVia On

<Location />
Order allow,deny
Allow from all
#AuthType Basic
#AuthName "Restricted area"
#AuthUserFile /etc/apache2/passwd/site-access
#Require valid-user
ProxyPass ajp://localhost:8009/
ProxyPassReverse ajp://localhost:8009/
</Location>


</IfModule>

<IfModule mod_ssl.c>

SSLEngine On
SSLCertificateFile /etc/apache2/ssl/www.mydomain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/www.mydomain.com.key

</IfModule>
</VirtualHost>


Just change the paths at the bottom to point to your .crt and .key files.

Ok few that was long ish for me to write...

By now you should have Tomcat running with Apache and Mysql.



UPDATE:

Extra steps i take for Grails:

Going live with grails

Hope this helps someone....

Monday, June 29, 2009

Paypal Pro Plugin documentation done

Hi

I have release the Paypal Pro plugin. Basically this is NOT a replacement for the existing Grails paypal plugin. It allows you to directly interface with a Paypal Webpayment Pro account. This is a service provided by Paypal that you have to pay for each month but it allows you to take payments on your website via forms on your website without the customer ever getting redirected to Paypal.

The plugin is all working and i have been using it on www.ebookstamper.com for the last few weeks.

Check it out here:

http://grails.org/plugin/paypal-pro


Peace