cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Cassandra Wiki] Update of "RunningCassandraInIDEA" by LyubenTodorov
Date Fri, 25 Oct 2013 00:40:56 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.

The "RunningCassandraInIDEA" page has been changed by LyubenTodorov:
https://wiki.apache.org/cassandra/RunningCassandraInIDEA?action=diff&rev1=23&rev2=24

  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.)
  
- You can create an IntelliJ project in just two steps:
+ To quickly import Cassandra into IntelliJ and start coding simply:
  
   1. Run "ant generate-eclipse-files"
-  1. File -> Import Project
+  2. File -> Import Project
  
- If you want to get up close and personal with setting it up manually instead of "cheating"
like that, read on...
+ If you want IDEA to handle more of the environment for you, keep reading.
  
  <<TableOfContents>>
  
- = Setup Cassandra as a project =
+ = 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").
+ ''' Prerequisites: ''' JDK6 (Cassandra 1.2) or JDK7 (Cassandra 2.0+), Apache Ant (http://ant.apache.org/)
and Git (http://git-scm.com/)  are required to get Cassandra running in IDEA. 
  
- 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)
+  1. Clone Cassandra from apache's Git repository. <<BR>><<BR>>
+  for trunk branch (JDK7 required)
+  {{{ 
+  git clone git://git.apache.org/cassandra.git
+  }}}
+  for cassandra-1.2 branch
+  {{{
+  git clone –b cassandra-1.2 git://git.apache.org/cassandra.git 
+  }}}
+  2. Once git has finished cloning the repository, generate the eclipse files using ant.
+  {{{
+  ant generate-eclipse-files
+  }}} 
+  3. Start IDEA
+  4. Click '''Import Project'''.
+  5. Navigate to the newly cloned cassandra directory and click '''OK'''.
  
- {{attachment:CheckOutFromVersionControl-1.png}}
+  {{attachment:1_Import Casandra.png}}
+  <<BR>><<BR>>
+  6. Select '''Import project from external model''', pick '''Eclipse''' then click '''OK'''.
  
- 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?"
+  {{attachment:2_Import as Eclipse project.png}}
+  <<BR>><<BR>>
+  7. Select '''Next'''
  
- {{attachment:CloneRepository-2.png}}
+  {{attachment:3_Select Project Directory.png}}
+  <<BR>><<BR>>
+  8. Select '''cassandra''' and click '''Finish'''. You now have a successfully imported
Cassandra project.
  
- Choose "Create Java project from existing sources".
+  {{attachment:5_Import Completed.png}}
+  <<BR>><<BR>>
  
- {{attachment:CreateProjectFromExistingSources-3.png}}
+ = Building & Testing Cassandra via Ant =
  
- 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.
+ To build Cassandra we need to import ant's build file, aka '''build.xml'''. 
  
- {{attachment:NewProject-4.png}}
  
- Add the following Java source files to your module.
+  1. Select the '''Ant Build''' tab from IDEA (right hand side in the screen shot below).
+  2. Select the '''+''' (Add).
+  3. Navigate to Cassandra's root directory (based on the tutorial this would be ~/workspace/cassandra/)
and select '''build.xml'''.
+  4. Click '''OK'''.
  
-  * interface/thrift/gen-java
-  * src/java
-  * test/unit
+  The different ant targets will now be available for execution. 
+  {{attachment:Adding Ant Config.png}}
+  <<BR>><<BR>>
  
- {{attachment:NewProjectChooseModules-5.png}}
+  '''Building / Testing Cassandra via Ant''' <<BR>>
+  Once the ant build file is added to IDEA you can compile cassandra via the '''build'''
target. The unit tests are located under the '''test''' target.<<BR>>
+  To run a target '''select''' it and then click {{attachment:idea_run.png}}.
  
- Press 'Next' followed by 'Finish' after you have reviewed the suggested module structure.
I recommend to only have one module (Cassandra).
+  {{attachment:10_Successful Build.png}}
  
- {{attachment:NewProjectReviewLibrariesFound-6.png}} {{attachment:NewProjectReviewModuleStructure-7.png}}
+ = Create a RUN configuration =
  
- 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)
+  1. Select '''Run''' > '''Edit Configurations...''' and click the '''+''' (Add New Configuration).<<BR>>
+  2. Populate the config with the following:<<BR>>
  
- Your IDEA project workspace should now look something like this:
+  {{{
+  Main class: org.apache.cassandra.service.CassandraDaemon
+  VM options: -Dcassandra-foreground=yes -Dcassandra.config=@@@ -ea -Xmx1G
  
- {{attachment:InitialProjectWorkspace-8.png}}
+  Note -Dcassandra.config you want to replace @@@ with the full path to your cassandra.yaml
config file (located in <cassandra_dir>/conf/cassandra.yaml)
+  eg: file:////Users/user/workspace/cassandra/conf/cassandra.yaml
+  }}}
  
- 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".
+  3. Click '''OK'''.
  
- First we will generate some code (CLI grammar, avro bindings, thrift bindings). This is
where ant enters the building.
+  {{attachment:Run Configuration.png}}
+  <<BR>><<BR>>  
  
- 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).
+ = Verify Cassandra is running via IDEA =
  
- {{attachment:Ant-9.png}}
+  If everything is configured correctly, when you run Cassandra (via {{attachment:idea_run.png}}
or '''Run > Run...''') logs should appear in the IDEA console.
  
- 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'.
+  {{attachment:Cassandra Logs via IDEA.png}}
+  <<BR>><<BR>>
  
- {{attachment:Single-EntryModuleDependency-10.png}}
+  Once cassandra is started, you can also check it's up and running by connecting to it via
[[http://www.datastax.com/docs/1.0/dml/using_cql#starting-the-cql-command-line-program-cqlsh|cqlsh]]
  
- 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"
+  {{{
+  $ ./cqlsh 
+  Connected to Test Cluster at localhost:9160.
+  [cqlsh 3.1.8 | Cassandra 1.2.11-SNAPSHOT | CQL spec 3.0.0 | Thrift protocol 19.36.1]
+  Use HELP for help.
+  cqlsh> 
+  }}}
  
- {{attachment:ContentRootAvro-11.png}} {{attachment:ContentRootThrift-12.png}}
+ = Notes =
  
- One final thing needs to be done in this view; choose the cassandra/src content root, right
click on "gen-java" and click 'Sources'.
+ Dont forget to update IntelliJ to use JDK7 or later for Cassandra versions greater than
Cassandra 1.2
  
- {{attachment:ContentRootSrc-13.png}}
+  {{attachment:7_JDK and Language Level Change.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)
- 
-  * Main class
- 
- {{{
-  org.apache.cassandra.thrift.CassandraDaemon
- }}}
-  * VM Parameters for Cassandra up to 6.0
- 
- {{{
-  -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".
- 
-  * Working Directory
- 
- eg mine is "/Users/schildmeijer/workspace/cassandra"
- 
- {{attachment: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: [[attachment:projectCodeStyle.xml]]
- 

Mime
View raw message