Installing Datomic on OS X Mavericks using Cassandra on Docker on Vagrant

Just a quick note – I’m in the process of publishing a book, Clojure Recipes. You can see it for presale on Amazon here.

Introduction

This post shows you how to setup Datomic running on Cassandra using using Vagrant and Docker from scratch. This is non-trivial and if everything goes well, will probably take a hour.

Note that this are my notes from going through this process, so there will definitely be room for improvement, either a simpler way to do things or a better way to explain what is going on.

Assumptions

  • This has been written for a Macbook Pro Retina running MacOS X 10.9.3 (Mavericks) with 16GB of RAM. You’ll need to make a judgment as to whether your setup is similar enough for these steps to apply to your system.

Pre-requisites

  •  you need at least 9G free on your hard drive
  •  to actually do this – you need a datomic pro evaluation key – you can get this by registering on the my.datomic.com site – and then under Account click Send licence key and under Downloads – and also get the latest version of Datomic Pro.

Outline

This has the following steps:

Note that steps A-J are here.
K. Setting Up Datomic
L. Running Datomic

 

Process Steps

Note that steps 1-24 are here:

K. Setting Up Datomic:

25. Obtain a license for Datomic pro through the Datomic Website

26. Download Datomic Pro from here (ie not the free version of Datomic)

27. Expand the datomic download
$ unzip datomic-pro-0.9.4384.zip -d datomic-pro-0.9.4384
cd datomic-pro-0.9.4384

28. Copy the cassandra transactor into the config directory (mac terminal)
$ cp config/samples/cassandra-transactor-template.properties config

29. Drop in your license key for datomic pro from the email into the cassandra-transactor-template.properties file (mac terminal)
$ nano config/cassandra-transactor-template.properties
under
license-key=

Also Set the following property entries
cassandra-host=localhost

Also Ensure the following is uncommented:
cassandra-user=datomic
cassandra-password=datomic

30. Provision a keyspace and table for datomic from the datomic directory (mac terminal):

cd apache-cassandra-2.0.8/

./bin/cqlsh -f ../datomic-pro-0.9.4815/datomic-pro-0.9.4815/bin/cql/cassandra-keyspace.cql -u cassandra -p cassandra

./bin/cqlsh -f ../datomic-pro-0.9.4815/datomic-pro-0.9.4815/bin/cql/cassandra-table.cql -u cassandra -p cassandra

./bin/cqlsh -f ../datomic-pro-0.9.4815/datomic-pro-0.9.4815/bin/cql/cassandra-user.cql -u cassandra -p cassandra

Note that with the third one – if you have trouble – log in with cqlsh and run it directly – ie

./bin/cqlsh -f -u cassandra -p cassandra

CREATE USER datomic WITH PASSWORD ‘datomic’ NOSUPERUSER;

GRANT ALL ON KEYSPACE datomic TO datomic;

L. Running Datomic

31. Start the datomic transactor with  the new cassandra template properties we just created:

cd datomic-pro-0.9.4815
bin/transactor config/cassandra-template.properties

Ensure you get a result like:

System started datomic:cass://localhost:9042/datomic.datomic/?ssl=&password=datomic&user=datomic

So you know it was successful.

Note this down – this will be the URI to connect.

32. In a new command prompt in the datomic-pro-0.9.4815 directory run:

bin/shell

Ensure you get the prompt

Datomic Java Shell

33. Run through the following commands from the datomic tutorial. Create the database: http://docs.datomic.com/tutorial.html

% String uri = "datomic:cass://localhost:9042/datomic.datomic/seattle;e;e?user=datomic&password=datomic";

% Peer.createDatabase(uri);

Expect the result:
true

34. Connect to the database
% conn = Peer.connect(uri);

Expect result similar to:
<{:db-id "seattle;e;e-bdffc04f-19b0-4c5b-8ff8-97393d14b303", :index-rev 0, :basis-t 63, :next-t 1000, :unsent-updates-queue 0, :pending-txes 0}>

35. Load up the schema

schema_rdr = new FileReader("samples/seattle/seattle-schema.edn");
schema_tx = Util.readAll(schema_rdr).get(0);
txResult = conn.transact(schema_tx).get();

36. Add some seed data

data_rdr = new FileReader("samples/seattle/seattle-data0.edn");
data_tx = Util.readAll(data_rdr).get(0);
txResult = conn.transact(data_tx).get();

37. Query the database

results = Peer.q("[:find ?c :where [?c :community/name]]", conn.db());
db = conn.db();
for (Object result : results) {
entity = db.entity(result.get(0));
System.out.println(entity.get(":community/name"));
}

You should get a list of communities that looks like this:
Downtown Dispatch
Discover SLU
Discover SLU
Discover SLU
Delridge Produce Cooperative
Delridge Neighborhoods Development Association
Delridge Grassroots Leadership
Crown Hill Neighbors
Community Harvest of Southwest Seattle
...

Voila – you have a Datomic database running on Cassandra across three nodes!

References:

Leave a Reply

Your email address will not be published. Required fields are marked *