IDEA is now open source! The free community edition at http://www.jetbrains.org is all you need for Cassandra development. (You don't need J2EE or Web tools.)

Setup Cassandra as a project

Preconditions: JDK6 and Ant (http://ant.apache.org/)

IDEA will generally set the project up properly for you (you'll need to run some ant targets and add a couple of folders as "content roots").

Open IDEA and Select "Check out from Version Control" under "Quick Start" and select 'Git' or 'Subversion' (this tutorial will use Git). (The URL to the Apache Cassandra svn is https://svn.apache.org/repos/asf/cassandra/trunk, the 'Git Repository URL' is git://git.apache.org/cassandra.git)

CheckOutFromVersionControl-1.png

Parent directory is where IDEA will place the Cassandra checkout/clone. Press Clone to engage the checkout/clone (be patient, will take some time). Answer 'Yes' to "Would you like to create an IntelliJ IDEA project for the sources you have checked out to /Users/schildmeijer/workspace/cassandra?"

CloneRepository-2.png

Choose "Create Java project from existing sources".

CreateProjectFromExistingSources-3.png

Pick an appropriate name for the new project (e.g cassandra) 'Project files location' is where on the file system IDEA will create your Java project.

NewProject-4.png

Add the following Java source files to your module.

NewProjectChooseModules-5.png

Press 'Next' followed by 'Finish' after you have reviewed the suggested module structure. I recommend to only have one module (Cassandra).

NewProjectReviewLibrariesFound-6.png NewProjectReviewModuleStructure-7.png

Your project will be now imported into the IDEA project workspace. Wait until the project indexing is done. (This might take some time depending on your computer)

Your IDEA project workspace should now look something like this:

InitialProjectWorkspace-8.png

Whats left now is to generate the Command Line Interface (CLI) grammar by ANTLR, add the "conf" folder to your sources, so that log4j properties can be found, generate the avro code and finally add these folders as "content roots".

First we will generate some code (CLI grammar, avro bindings, thrift bindings). This is where ant enters the building.

Press the 'Ant Build' tab (far to the right), then 'Add' (the plus sign) and locate the build.xml in your cassandra project folder. Run the ant 'build' target by double clicking on it (this should hopefully generate all the code necessary to run cassandra in IDEA). (Press no if IDEA asks you to add some project specific files to git/svn version control).

Ant-9.png

Next step is to add the "conf" folder. Choose 'View as: Packages" and right click on your cassandra project and pick 'Module Settings'. Go to dependencies and press 'Add' then 'Single-Entry Module Library...' Now locate the conf folder and press 'Ok'.

Single-EntryModuleDependency-10.png

Now it's time to add avro and thrift generated java files as 'content roots'. Once again, right click on the cassandra project in the 'View as: Packages" perspective and choose 'Module Settings' This time you press 'Add Content Root' and locate "interface/avro/gen-java", do the same for "interface/thrift/gen-java"

ContentRootAvro-11.png ContentRootThrift-12.png

One final thing needs to be done in this view; choose the cassandra/src content root, right click on "gen-java" and click 'Sources'.

ContentRootSrc-13.png

Update If you still see some errors popping up, right click on the cassandra project in the 'View as: Packages" perspective and choose 'Module Settings'. Go to Libraries(on the left), click "Attach Jar Directories.." and add build/lib/jars directory. Now when you rebuild your project, all errors should go away.

Create a Cassandra application's RUN configuration

Create a new application called cassandra (e.g Run -> Edit Configurations -> Add new configuration (insert) -> Application)

 org.apache.cassandra.thrift.CassandraDaemon

 -Dcassandra-foreground -Dstorage-config=@@@ -ea -Xmx1G

Replace @@@ above with the path to your conf folder, eg mine is "/Users/schildmeijer/workspace/cassandra/conf". The flags above are taken from the cassandra shell script.

* VM Parameters for Cassandra 7.0

-Dcassandra-foreground -Dcassandra.config=@@@ -ea -Xmx1G

Replace @@@ above with the path to your cassandra.yaml as a URI, eg mine is "file:///home/edward/idea/conf/cassandra.yaml".

eg mine is "/Users/schildmeijer/workspace/cassandra"

EditConfigurations-14.png

Review and Modify storage-conf.xml and log4j.properties accordingly, as in certain cases directory creation of /var/cassandra fails due to ACLs of execution context

storage-conf.xml

    Directories: Specify where Cassandra should store different data on disk
         Keep the data disks and the CommitLog disks separate for best performance
    
    <CommitLogDirectory>/var/cassandra/commitlog</CommitLogDirectory>
    <DataFileDirectories>
        <DataFileDirectory>/var/cassandra/data</DataFileDirectory>
    </DataFileDirectories>
    <CalloutLocation>/var/cassandra/callouts</CalloutLocation>
    <BootstrapFileDirectory>/var/cassandra/bootstrap</BootstrapFileDirectory>
    <StagingFileDirectory>/var/cassandra/staging</StagingFileDirectory>

appender in log4j.properties

log4j.appender.R.File=/var/cassandra/logs/system.log

Verify that it runs from IDEA

When you start the app it should look similar to cmd line start, eg mine looks like this:

Listening for transport dt_socket at address: 8888
DEBUG 18:49:27,959 Loading settings from /Users/schildmeijer/Documents/workspace/cassandra/conf/storage-conf.xml
DEBUG 18:49:28,141 Syncing log with a period of 10000
 INFO 18:49:28,146 Auto DiskAccessMode determined to be mmap
DEBUG 18:49:28,268 setting autoBootstrap to false
DEBUG 18:49:28,446 Starting CFS Schema
DEBUG 18:49:28,464 Starting CFS Migrations
DEBUG 18:49:28,495 opening keyspace system
DEBUG 18:49:28,496 Starting CFS LocationInfo
DEBUG 18:49:28,497 key cache capacity for LocationInfo is 1
DEBUG 18:49:28,499 Starting CFS HintsColumnFamily
DEBUG 18:49:28,499 key cache capacity for HintsColumnFamily is 1
DEBUG 18:49:28,500 opening keyspace definitions
DEBUG 18:49:28,533 Estimating compactions for LocationInfo
DEBUG 18:49:28,543 Estimating compactions for HintsColumnFamily
DEBUG 18:49:28,543 Estimating compactions for Migrations
DEBUG 18:49:28,549 Estimating compactions for Schema
DEBUG 18:49:28,572 Checking to see if compaction of LocationInfo would be useful
DEBUG 18:49:28,573 Checking to see if compaction of HintsColumnFamily would be useful
DEBUG 18:49:28,573 Checking to see if compaction of Migrations would be useful
DEBUG 18:49:28,574 Checking to see if compaction of Schema would be useful
 INFO 18:49:28,578 Saved Token not found. Using 1816769162446994796948805497871322369
 INFO 18:49:28,579 Saved ClusterName not found. Using Test Cluster
 INFO 18:49:28,610 Creating new commitlog segment /var/lib/cassandra/commitlog/CommitLog-1270745368610.log
 INFO 18:49:28,650 Starting up server gossip
DEBUG 18:49:28,737 attempting to connect to /127.0.0.1
 INFO 18:49:28,800 Binding thrift service to localhost/127.0.0.1:9160

Try running the cassandra-cli as per CassandraCli, and you should be able to connect to localhost/9160.

Project code style

An unofficial project code style which should make it easier to conform to the project's CodeStyle is here: projectCodeStyle.xml

RunningCassandraInIDEA (last edited 2011-04-06 17:22:30 by AmulyaBhatia)