-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
156 lines (127 loc) · 8.2 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Requirements:
So far everything has been tested only on linux (Ubuntu).
However the only platform-dependent part is the cassandra dev setup scripts (see below),
which assume bash; they may or may not work under Cygwin...
Java: JDK (not JRE). I have 1.6.0_24-b07. Java 1.5 may also work, not tested.
Maven: maven2. I have 2.2.1. Maven 3 may also work, not tested.
Install maven ubuntu / debian:
sudo apt-get install maven2
Eclipse is recommended for development.
The project files (.classpath, .project, .settings/) are set up for Eclipse Helios SR2.
You'll also want the M2Eclipse plugin:
http://m2eclipse.sonatype.org
Once you've installed M2Eclipse and restarted, you shoud be able to add this project
using File / Import..., General:Existing Projects into Workspace.
It will then spend ages downloading maven dependencies but should eventually work.
For testing, we're using TestNG rather than JUnit (because Tapestry has a bunch of support for it),
so you may want to install the "TestNG" Eclipse plugin from here, in the same way as for M2Eclipse:
http://testng.org/doc/eclipse.html
Background reading:
This project:
README-user-stories.txt - User interaction requirements / design.
README-datastructures.txt - Cassandra data structure design, vote counting algorithms etc.
Tapestry info / tutorial:
http://tapestry.apache.org/creating-the-skeleton-application.html
Cassandra info / tutorial:
http://wiki.apache.org/cassandra/FrontPage
http://wiki.apache.org/cassandra/DataModel
http://www.datastax.com/docs/0.8/index
http://maxgrinev.com/2010/07/12/do-you-really-need-sql-to-do-it-all-in-cassandra/
Hector (data access library used to interface to Cassandra):
https://github.com/rantav/hector/wiki/User-Guide
https://github.com/rantav/hector/wiki
- note some info is a little out-of-date and refers to the old Hector APIs before a recent redesign.
TestNG (Java unit / integration test library):
http://testng.org/doc/index.html
To setup cassandra (local installation in the repos, for dev, as current user):
Run this from top dir of repos:
./install-cassandra-for-dev.sh (one-off unless you use 'git clean' as below)
./start-cassandra-for-dev.sh (start or restart; this will stay open and log to console)
then from a separate console:
./initialize-cassandra-schema.sh (one-off after first startup, unless you use 'git clean' as below)
To exit cassandra, just Ctrl+C to kill it.
This setup runs a localhost (single node) cluster, keeping its data in the repos in gitignored dirs,
so you can clean everything easily, e.g. using 'git clean -d -X -f'
On linux you may also want to do this, as described here - it will still work without this though:
http://www.datastax.com/docs/0.8/install/installing#installing-jna
Edit the file /etc/security/limits.conf, adding the following entries for the user or group that runs Cassandra:
theusername soft memlock unlimited
theusername hard memlock unlimited
You can use jconsole (connect to the CassandraDaemon process) to view its JMX management stuff.
To run the cassandra cli (console querying / DDL tool): start cassandra as above, then:
./cassandra-cli-for-dev.sh
To run the webapp from the commandline:
mvn jetty:run
then it will be accessible at:
http://localhost:8080/policy-auction/
To run within Eclipse:
I can't get this to work yet! Should be possible with the "Run Jetty Run" plugin:
Install the "Run Jetty Run" plugin (http://code.google.com/p/run-jetty-run/)
in eclipse: search for "Jetty" in the Eclipse Marketplace, or use this update site:
http://run-jetty-run.googlecode.com/svn/trunk/updatesite
then use Run Configurations, select Jetty Webapp, click New, enter config
...I can get it to launch jetty, but it doesn't seem to start the Tapestry servlet context properly:
accessing http://localhost:8080/<context> only lists the directory for fileserving, doesn't run Tapestry classes.
To run the TestNG unit tests from the commandline:
./initialize-cassandra-for-tests.sh
(one-off unless you use 'git clean' as below, or unless you change conf/cassandra-schema.txt)
mvn test
To run or debug TestNG unit tests within Eclipse:
Assuming you have the TestNG plugin installed (see Requirements, above):
First, run ./initialize-cassandra-for-tests.sh in the top directory.
Then right-click the test class (e.g. HectorPolicyManagerImplTest) and choose "Run as... / TestNG Test". Or "Debug as...".
Logging:
The project uses SLF4J, backed by Log4J.
Some log messages are written to tables in Cassandra when running the webapp.
Logging and log filtering levels are configured via the file src/main/resources/log4j.properties.
Logging can be done from any java code in the webapp like this:
private static final Logger logger = LoggerFactory.getLogger(MyEnclosingClass.class);
...
logger.info("some message");
logger.error("Disaster", someException);
Intro to java project structure:
src/main/java:
Tapestry-related stuff:
net/retakethe/policyauction/pages
Each Tapestry page has one class in here (plus a ".tml" template with matching name).
This class connects together the page template and the data layer.
The getter/setter methods provide properties that can be reference in the page .tml template.
There are also handlers for events such as "onActionFrom..." and "onSuccess...".
The "@Persist" annotation means that field is kept in the session between page shows.
net/retakethe/policyauction/components
Tapestry "components" that can be shared between pages.
The "Layout" one is used for most of the current pages, set up by the 't:type="layout"' in the page .tml.
net/retakethe/policyauction/entities
Data objects acted on by Tapestry pages and passed to/from the data layer.
net/retakethe/policyauction/services
AppModule - the 'bind' call here is what makes our Cassandra implementation of the 'DAOManager'
available for injection into fields of cassandra page classes via '@Inject'.
Data layer stuff:
net/retakethe/policyauction/data/api
Abstract interfaces for the data layer.
This is what the Tapestry pages talk to.
No dependency on any specific data store implementation here.
net/retakethe/policyauction/data/impl
The implementation of the data layer which talks to Cassandra via the Hector library.
Nothing in Tapestry should need to reference this directly.
src/main/resources:
net/retakethe/policyauction/pages
<pagename>.tml - HTML template corresponding to each Tapestry page.
(Note you can make Eclipse show them with HTML syntax highlighting by adding "*.tml" to the "Text/XML"
content type in Preferences / General / Content Types.)
This has some magic markup ('t:' and 'p:' namespaces, '${<propertyname>}' and '${<prefix>:<name>}' syntax)
which Tapestry uses to do all the dynamic stuff at render time.
<pagename>.properties - values for the '${message:<name>}' placeholders on that page.
net/retakethe/policyauction/components
HTML template corresponding to each Tapestry component.
src/main/webapp:
WEB-INF/web.xml defines servlet config and sets up Tapestry as a servlet filter.
src/test/java:
Unit test classes. Not part of the packaged webapp.
_fixtures:
Support fixtures for unit tests - for starting test cassandra DB etc.
net/retakethe ... :
The actual TestNG unit tests for classes in src/main/java/net/retakethe ...
src/test/resources:
Unit test resources, config etc. Not part of the packaged webapp.
Some are auto-generated by initialize-cassandra-for-tests.sh.