src/main/java/, avro schemas in src/main/avro/, and data in src/main/resources/.
##Setting up HBase
For this tutorial we will be using [HBase](http://hbase.apache.org) to
store the logs. For those of you not familiar with HBase, it is a NoSQL
column store with an architecture very similar to Google's BigTable.
If you don't already have already HBase setup, you can go over the steps at
[HBase Overview](http://hbase.apache.org/book/quickstart.html)
documentation. Gora aims to support the most recent HBase versions however if you
find compatibility problems please [get in touch](../mailing_lists.html).
So download an [HBase release](http://www.apache.org/dyn/closer.cgi/hbase/).
After extracting the file, cd to the hbase-${dist} directory and start the HBase server.
$ bin/start-hbase.sh
and make sure that HBase is available by using the Hbase shell.
$ bin/hbase shell
##Configuring Gora
Gora is configured through a file in the classpath named gora.properties.
We will be using the following file gora-tutorial/conf/gora.properties
gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
gora.datastore.autocreateschema=true
This file states that the default store will be HBaseStore,
and schemas(tables) should be automatically created.
More information for configuring different settings in gora.properties
can be found [here](/current/gora-conf.html).
##Modeling the data
For this tutorial, we will be parsing and storing the logs of a web server.
Some example logs are at src/main/resources/access.log.tar.gz, which
belongs to the (now shutdown) server at http://www.buldinle.com/.
Example logs contain 10,000 lines, between dates 2009/03/10 - 2009/03/15.
The first thing, we need to do is to extract the logs.
$ tar zxvf src/main/resources/access.log.tar.gz -C src/main/resources/
You can also use your own log files, given that the log
format is [Combined Log Format](http://httpd.apache.org/docs/current/logs.html).
Some example lines from the log are:
88.254.190.73 - - [10/Mar/2009:20:40:26 +0200] "GET / HTTP/1.1" 200 43 "http://www.buldinle.com/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB5; .NET CLR 2.0.50727; InfoPath.2)
78.179.56.27 - - [11/Mar/2009:00:07:40 +0200] "GET /index.php?i=3&a=1__6x39kovbji8&k=3750105 HTTP/1.1" 200 43 "http://www.buldinle.com/index.php?i=3&a=1__6X39Kovbji8&k=3750105" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
78.163.99.14 - - [12/Mar/2009:18:18:25 +0200] "GET /index.php?a=3__x7l72c&k=4476881 HTTP/1.1" 200 43 "http://www.buldinle.com/index.php?a=3__x7l72c&k=4476881" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1)
The first fields in order are: User's ip, ignored, ignored, Date and
time, HTTP method, URL, HTTP Method, HTTP status code, Number of bytes
returned, Referrer, and User Agent.
##Defining data beans
Data beans are the main way to hold the data in memory and persist in Gora. Gora
needs to explicitly keep track of the status of the data in memory, so
we use [Apache Avro](http://avro.apache.org) for defining the beans. Using
Avro gives us the possibility to explicitly keep track of an object's persistent state
and a way to serialize an object's data.
Defining data beans is a very easy task, but for the exact syntax please
consult the [Avro Specification](http://avro.apache.org/docs/current/spec.html).
First, we need to define the bean Pageview to hold a
single URL access in the logs. Let's go over the class at src/main/avro/pageview.json
{
"type": "record",
"name": "Pageview",
"namespace": "org.apache.gora.tutorial.log.generated",
"fields" : [
{"name": "url", "type": "string"},
{"name": "timestamp", "type": "long"},
{"name": "ip", "type": "string"},
{"name": "httpMethod", "type": "string"},
{"name": "httpStatusCode", "type": "int"},
{"name": "responseSize", "type": "int"},
{"name": "referrer", "type": "string"},
{"name": "userAgent", "type": "string"}
]
}
Avro schemas are declared in JSON.
[Records](http://avro.apache.org/docs/current/spec.html#schema_record)
are defined with type "record", with a name as the name of the class, and a
namespace which is mapped to the package name in Java. The fields
are listed in the "fields" element. Each field is given with its type.
##Compiling Avro Schemas
The next step after defining the data beans is to compile the schemas
into Java classes. For that we will use the [GoraCompiler](/current/compiler.html).
Invoke the Gora compiler from the top-level Gora directory with:
$ bin/gora goracompiler
results in:
$ Usage: GoraCompiler