Skip to main content

Running Java EE applications on Amazon EC2: deploying to 20 m...

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Bookmark History

Saved by 5 people (1 private), first by anonymouse user on 2008-01-09


Public Sticky notes

Running JEE applications on Amazon EC2: deploying to 20 machines with no money down

posted Monday, 7 January 2008

Computer hardware has traditionally been a scarce, expensive resource. In the early days of computing developers had to share a single machine. Today each developer usually has their own machine but it’s rare for a developer to have more than one. This means that running performance tests often involves scavenging for machines.  Likewise, replicating even just part of a production environment is a major undertaking. With Amazon’s Elastic Compute Cloud (EC2), however, things are very different. A set of Linux servers is now just a web service call away. You simply pay 10 cents per CPU-hour for up to 20 machines! No more upfront costs or waiting for machines to be purchased and configured.

To make it easier for enterprise Java developers to use EC2, I have created EC2Deploy.  It’s a Groovy framework for deploying an enterprise Java application on a set of Amazon EC2 servers. EC2Deploy provides a simple, easy to use API for launching a set of EC2 instances; configuring MySQL, Apache and one or more Tomcat servers; and deploying one or more web applications. In addition, it can also run JMeter and collect performance metrics.

Here is an example script that launches some EC2 instances; configures MySQL with one slave, Tomcat and Apache; deploys a single web application on the Tomcat server; and runs a JMeter test with first one thread and then two.

class ClusterTest extends GroovyTestCase {
  void testSomething() {
    AWSProperties awsProperties = new 
        AWSProperties("/…/aws.properties")
    
    def ec2 = new EC2(awsProperties)
 
    def explodedWar = '…/projecttrack/webapp/target/ptrack'
 
    ClusterSpec clusterSpec = 
       new ClusterSpec()
            .schema("ptrack", ["ptrack": "ptrack"], 
                    ["src/test/resources/testdml1.sql", 
                     "src/test/resources/testdml2.sql"])
            .slaves(1)                  
            .tomcats(1)
            .webApp(explodedWar, "ptrack")
            .catalinaOptsBuilder({builder, databasePrivateDnsName ->
                 builder.arg("-Xmx500m")
                 builder.prop("com.sun.management.jmxremote")
                 builder.prop("com.sun.management.jmxremote.port", 8091)
                 builder.prop("com.sun.management.jmxremote.authenticate",             
                                     false)
                 builder.prop("com.sun.management.jmxremote.ssl", false)
                 builder.prop("ptrack.application.environment", "ec2")
                 builder.prop("log4j.configuration", 
                               "log4j-minimal.properties")
                 builder.prop("jdbc.db.server", databasePrivateDnsName)})
 
    SimpleCluster cluster = new SimpleCluster(ec2, clusterSpec)
 
    cluster.loadTest("…/projecttrack/functionalTests/jmeter/SimpleTest.jmx",
        [1, 2])
     
    cluster.stop()
  }
}

 

Let’s look at each of the pieces.

Highlighted by harjeet

Running JEE applications on Amazon EC2: deploying to 20 machines with no money down >

posted Monday, 7 January 2008 >

Computer hardware has traditionally been a scarce, expensive resource. In the early days of computing developers had to share a single machine. Today each developer usually has their own machine but it’s rare for a developer to have more than one. This means that running performance tests often involves scavenging for machines. >   Likewise, replicating even just part of a production environment is a major undertaking. With > Amazon’s Elastic Compute Cloud (EC2) > , however, things are very different. A set of Linux servers is now just a web service call away. You simply pay 10 cents per CPU-hour for up to 20 machines! No more upfront costs or waiting for machines to be purchased and configured. >

To make it easier for enterprise Java developers to use EC2, I have created EC2Deploy. >  It’s a Groovy framework for deploying an enterprise Java application on a set of Amazon EC2 servers. EC2Deploy provides a simple, easy to use API for launching a set of EC2 instances; configuring MySQL, Apache and one or more Tomcat servers; and deploying one or more web applications. In addition, it can also run JMeter and collect performance metrics. >

Here is an example script that launches some EC2 instances; configures MySQL with one slave, Tomcat and Apache; deploys a single web application on the Tomcat server; and runs a JMeter test with first one thread and then two. >


class ClusterTest extends GroovyTestCase {
>
  
void testSomething() {
>
    
AWSProperties awsProperties = new
> 
        
AWSProperties("/…/aws.properties")
>
    
    
def ec2 = new EC2(awsProperties)
>
 
    
def explodedWar = '…/projecttrack/webapp/target/ptrack'
>
 
    
ClusterSpec clusterSpec =
> 
       
new ClusterSpec()
>
            
.schema("ptrack", ["ptrack": "ptrack"],
> 
                    
["src/test/resources/testdml1.sql",
> 
                     
"src/test/resources/testdml2.sql"])
>
            
.slaves(1)
>                  
            
.tomcats(1)
>
            
.webApp(explodedWar, "ptrack")
>
            
.catalinaOptsBuilder({builder, databasePrivateDnsName ->
>
                 
builder.arg("-Xmx500m")
>
                 
builder.prop("com.sun.management.jmxremote")
>
                 
builder.prop("com.sun.management.jmxremote.port", 8091)
>
                 
builder.prop("com.sun.management.jmxremote.authenticate",
>             
                                     
false)
>
                 
builder.prop("com.sun.management.jmxremote.ssl", false)
>
                 
builder.prop("ptrack.application.environment", "ec2")
>
                 
builder.prop("log4j.configuration",
> 
                               
"log4j-minimal.properties")
>
                 
builder.prop("jdbc.db.server", databasePrivateDnsName)})
>
 
    
SimpleCluster cluster = new SimpleCluster(ec2, clusterSpec)
>
 
    
cluster.loadTest("…/projecttrack/functionalTests/jmeter/SimpleTest.jmx",
>
        
[1, 2])
>
     
    
cluster.stop()
>
  
}
>

}
>

 

Let’s look at each of the pieces. >

Highlighted by harjeet