Technical Blog

2 Posts authored by: Sylvain Gibier

The contract negociation went through, the SLA is signed, and as a super-keen developer, you've already downloaded and built Elastic Path within minutes ()! Your heart is racing. The adrenaline is pumping. You just can't wait to start building your ecommerce storefront. With the source code in hand, it's so tempting to start hacking the Elastic Path source code right away.

 

But then you start thinking about the next EP release version, and bug fixes... and you're wondering what you're going to do when it's time to upgrade... How will you manage your customizations while keeping in sync with the most recent stable release of Elastic Path?

 

Maven to the rescue! You can use the power of Maven dependencies and, more importantly, the WAR overlay feature to do this. Overlays are used to share common resources across multiple web applications. Basically, it's a nice and clean way to apply the Decorator pattern to any EP based web applications.

 

How It Works

Step 1. If you don't already have one, install your own Maven repository (Sonatype Nexus, for instance). I won't go into details, but have a look at this old post on TheServerSide.com: Setting Up a Maven Repository.

 

Step 2. Deploy all required libraries shipped with the EP source code in your new Maven repository and build the codebase as per the Developer Guide. When it's done, you should have all applications packaged and ready to be deployed. Depending on your chosen Maven repository, you will need to deploy your different WAR packages (cmserver, searchserver and storefront) by uploading both the WAR binary and the POM file within the project.

 

Step 3. Create a WAR Maven project to hold all the customizations that you want to make on the standard storefront source code (controller, XML configuration, etc.) and specify that you are dependent on EP's Mavenized storefront WAR as follows:

<dependency>
     <groupId>com.elasticpath</groupId>
     <artifactId>com.elasticpath.sf</artifactId>
     <version>6.1.1</version>
     <type>war</type>
</dependency>

 

In your POM project file, add   the Maven Warpath plugin. The Warpath plugin extends the existing war overlay functionality included in the Maven War plugin to turn war artifacts into fully fledged build dependencies. We need it to expose the classes built and contained within the WAR dependency.

<plugin>
     <groupId>org.appfuse</groupId>
     <artifactId>maven-warpath-plugin</artifactId>

     <extensions>true</extensions>
     <executions>
          <execution>
            <goals>
                 <goal>add-classes</goal>
            </goals>
          </execution>
     </executions>
</plugin>

 

While packaging your new extended storefront, all configuration, classes, and libs will be imported from the depending WAR archive into your new web application. The web application "overlay" will work exactly as the original and will be ready for any customization.
Now, let's say you want to override a specific configuration file like WEB-INF/web.xml to declare your extending ContextConfigListener java class. Simply copy locally to your project the WEB-INF/web.xml file and make your modifications. While packaging, the override files will replace all existing configuration files and resources from EP.

 

waroverlay.png

 

WAR overlay gives you full control and dependency management on all your EP customizations. In case of an upgrade or bug fix, all you need to do is rebuild the default EP package and update your project dependency. No more code merge nightmares! No more wondering if you missed any updated configuration files!

 

By combining the WAR overlay approach with Spring framework's plugin capability available within EP, you can override even bean implementation by simply creating your own core extension jar project, having a dependency on the standard EP core jar library, and defining a plugin.xml file within your own jar project. All this has already been proven in the field. You can implement your own storefront without modifying any EP core domain interfaces, services by injection you own implementation.

 

And voila! By leveraging Maven dependency and WAR overlay mechanisms, you have a clean, straightforward approach to implementing EP in the field that keeps the upgrade effort low.

8 Comments Permalink

Unless you've been hibernating the past few years, you're probably aware of Amazon Cloud Computing Infrastructure. Maybe you're even wondering if you could deploy your favorite ecommerce application "in the cloud" and finally reach the sky ;-)

 

The short answer is yes, you can.

 

What's really behind Amazon EC2?

 

If you've ever used a virtual machine a la VMWare or Xen, then you're already an EC2 expert. The true power of EC2 is its web service layer, which allows you to dynamically start, deploy, and run pre-configured virtual images, or so-called Amazon Machine Images (AMIs). If you don't want to deal with the web services directly, Amazon recently released a web console (see https://console.aws.amazon.com/) to perform most AMI-related activities.

 

But what about Elastic Path deployment?

 

Elastic Path deployment is pretty much the same. You need to produce some kind of infrastructure design, deciding your targeting production environment and typology (OS, number of CPUs, RAM) as well software stack (web application container, DBMS). The biggest difference is that instead of purchasing hardware, you think in terms of AMIs.

 

You can create your own AMI (http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/) or start from an existing one and tailor it to your needs by installing any required software. So as far EP deployment is concerned, all you have to do is to follow the deployment guide to set up and configure your app servers, db servers, etc. ...

 

Once you have a configured AMI, you need to bundle it (http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/). This ensures that your installed software and configuration is persisted (all changes made to a running instance are lost in the event of a crash or if you terminate it). That's one difference with VMWare images. The bundled AMI becomes your master AMI that you will use to launch new instances in response to load increases.

 

Once you've configured your AMI for your web layer, app server and db layer, all you need to do is to start your default set of AMI instances, configure your load balancer and proxy, and deploy your EP war files... and hope you're good to sell!

 

Any known limitations while deploying on Amazon EC2?

 

There is one major limitation when it comes to clustering and sticky/shared session in clustered app server farms: currently, EC2 doesn't support any broadcast mechanism. You can always store user sessions in the database so that they can be "replicated" between running app server instances. Or you can leverage Open Terracota technology for sticky session replication. Have a look at this pretty nice post for more details: http://blog.decaresystems.ie/index.php/2007/02/12/amazon-web-services-the-future-of-datacenter-computing-part-2/.

 

 

Stay tuned for a complete step by step deployment on Amazon EC2, including dynamically scalling for your traffic load. So don't forget your credit card ;-)

0 Comments Permalink