Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
szimano committed Feb 28, 2012
2 parents 8957525 + f338ae4 commit d476c8d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 31 deletions.
42 changes: 40 additions & 2 deletions README.mediawiki
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
= Jozi JUG AWS sample application =

== Setup JBoss ==
Start JBoss AS 7.1+

./standalone.sh [-Dlocal] --server-config=standalone-full.xml
Fix the slf4j module, by editing ${JBOSS_HOME}/modules/org/jboss/logging/main/module.xml and add those two to the dependencies:

<module name="org.apache.log4j"/>
<module name="org.slf4j"/>
'' This might be fixed by JBoss one day, but still for JBoss AS 7.1-Final does not work properly''

== Build & Deploy the war ==

Build the project with

mvn clean install
And put '''target/jozi-aws-demo-1-SNAPSHOT.war''' in ''''${JBOSS_HOME}/standalone/deployments'''

== Run the application ==

=== JMS & Hibernate version ===

The optional '''-Dlocal''' will use JPA/JMS services instead of SDB/SQS
Run the server with

./standalone.sh -Dlocal --server-config=standalone-full.xml
Deploy JMS queue with

add-jms-queue --name=JoziJUGQueue --entries=queues/MessageQueue
This will use JPA/JMS services.

=== SQS & SDB version ===

Fill in aws.properties and sqs.conf in the resources folder (use .sample files)

Create an empty '''messages''' domain in SDB.

Run the server with

./standalone.sh
== Access the application ==

Go to [http://localhost:8080/jozi-aws-demo-1-SNAPSHOT/home/index http://localhost:8080/jozi-aws-demo-1-SNAPSHOT/home/index]
19 changes: 13 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.16</version>
</dependency>

<dependency>
<groupId>pl.softwaremill.common</groupId>
<artifactId>softwaremill-sqs</artifactId>
Expand Down Expand Up @@ -118,6 +112,19 @@

</dependencies>

<repositories>
<repository>
<id>softwaremill-snapshots</id>
<name>SoftwareMill Snapshots</name>
<url>http://tools.softwaremill.pl/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>softwaremill-releases</id>
<name>SoftwareMill Releases</name>
<url>http://tools.softwaremill.pl/nexus/content/repositories/releases</url>
</repository>
</repositories>

<profiles>
<profile>
<id>lg</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
package pl.softwaremill.jozijug.joziawsdemo.impl.sdb;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
* User: szimano
*/
public class DateFormatter {

public SimpleDateFormat getDateFormat() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat format;

static {
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
}

public String formatDate(Date date) {
return format.format(date);
}

public Date parseDate(String dateString) {
try {
return format.parse(dateString);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import com.xerox.amazonws.simpledb.SDBException;
import org.jboss.seam.solder.core.Veto;
import pl.softwaremill.jozijug.joziawsdemo.MessageMappingConstants;
import pl.softwaremill.jozijug.joziawsdemo.entity.Message;
import pl.softwaremill.jozijug.joziawsdemo.service.AWS;
Expand Down Expand Up @@ -40,9 +39,9 @@ public void addMessage(Message msg) {
attrs.put(MessageMappingConstants.ROOM, msg.getRoom());
attrs.put(MessageMappingConstants.CONTENT, msg.getContent());
attrs.put(MessageMappingConstants.DATE,
dateFormatter.getDateFormat().format(msg.getDate()));
dateFormatter.formatDate(msg.getDate()));
attrs.put(MessageMappingConstants.SAVE_DATE,
dateFormatter.getDateFormat().format(msg.getSaveDate()));
dateFormatter.formatDate(msg.getSaveDate()));

try {
String itemId = msg.getUuid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import pl.softwaremill.jozijug.joziawsdemo.service.MessagesLister;

import javax.inject.Inject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -62,17 +60,13 @@ private String escapeValue(String value) {
}

private Message convertItemToMessage(Item item) {
try {
return new Message(
UUID.fromString(item.getIdentifier()),
item.getAttribute(ROOM),
item.getAttribute(CONTENT),
dateFormatter.getDateFormat().parse(item.getAttribute(DATE)),
dateFormatter.getDateFormat().parse(item.getAttribute(SAVE_DATE))
);
} catch (ParseException e) {
throw new RuntimeException(e);
}
return new Message(
UUID.fromString(item.getIdentifier()),
item.getAttribute(ROOM),
item.getAttribute(CONTENT),
dateFormatter.parseDate(item.getAttribute(DATE)),
dateFormatter.parseDate(item.getAttribute(SAVE_DATE))
);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package pl.softwaremill.jozijug.joziawsdemo.tools;

import com.xerox.amazonws.ec2.*;
import com.xerox.amazonws.ec2.EC2Exception;
import com.xerox.amazonws.ec2.Jec2;
import com.xerox.amazonws.ec2.LaunchConfiguration;
import com.xerox.amazonws.ec2.LoadBalancing;
import com.xerox.amazonws.ec2.LoadBalancingException;
import com.xerox.amazonws.ec2.ReservationDescription;
import pl.softwaremill.jozijug.joziawsdemo.impl.sdb.AwsAccessKeys;

import java.io.IOException;
Expand Down Expand Up @@ -30,9 +35,9 @@ private Jec2 createJec2() {
}

public List<String> startInstance(Jec2 ec2) throws EC2Exception {
LaunchConfiguration launchConfiguration = new LaunchConfiguration("ami-6d477b19");
launchConfiguration.setSecurityGroup(Arrays.asList("SoftDevCon"));
launchConfiguration.setKeyName("confitura");
LaunchConfiguration launchConfiguration = new LaunchConfiguration("ami-75300901");
launchConfiguration.setSecurityGroup(Arrays.asList("quicklaunch-1"));
launchConfiguration.setKeyName("aws-jozi-jug");
launchConfiguration.setAvailabilityZone("eu-west-1c");
ReservationDescription reservationDescription = ec2.runInstances(launchConfiguration);

Expand All @@ -47,7 +52,7 @@ public List<String> startInstance(Jec2 ec2) throws EC2Exception {

public void registerWithElb(List<String> instanceIds) throws LoadBalancingException {
LoadBalancing loadBalancing = createLoadBalancing();
loadBalancing.registerInstancesWithLoadBalancer("SoftDevConLB", instanceIds);
loadBalancing.registerInstancesWithLoadBalancer("JoziLB", instanceIds);
System.out.println("Registered " + instanceIds + " with the load balancer.");
}

Expand Down

0 comments on commit d476c8d

Please sign in to comment.