cassandra 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG +10 -0
  2. data/LICENSE +0 -0
  3. data/Manifest +12 -13
  4. data/README.md +344 -0
  5. data/Rakefile +52 -8
  6. data/cassandra.gemspec +5 -5
  7. data/conf/0.6/cassandra.in.sh +0 -0
  8. data/conf/0.6/log4j.properties +0 -0
  9. data/conf/0.6/schema.json +9 -0
  10. data/conf/0.6/storage-conf.xml +10 -0
  11. data/conf/0.7/cassandra.in.sh +0 -0
  12. data/conf/0.7/cassandra.yaml +0 -0
  13. data/conf/0.7/log4j-server.properties +0 -0
  14. data/conf/0.7/schema.json +9 -0
  15. data/conf/0.7/schema.txt +5 -16
  16. data/conf/0.8/cassandra.in.sh +0 -0
  17. data/conf/0.8/cassandra.yaml +1 -1
  18. data/conf/0.8/log4j-server.properties +0 -0
  19. data/conf/0.8/schema.json +19 -1
  20. data/conf/0.8/schema.txt +12 -17
  21. data/lib/cassandra.rb +3 -2
  22. data/lib/cassandra/0.6.rb +0 -0
  23. data/lib/cassandra/0.6/cassandra.rb +57 -6
  24. data/lib/cassandra/0.6/columns.rb +19 -0
  25. data/lib/cassandra/0.6/protocol.rb +2 -1
  26. data/lib/cassandra/0.7.rb +0 -0
  27. data/lib/cassandra/0.7/cassandra.rb +0 -270
  28. data/lib/cassandra/0.7/columns.rb +1 -81
  29. data/lib/cassandra/0.7/protocol.rb +0 -112
  30. data/lib/cassandra/0.8.rb +0 -0
  31. data/lib/cassandra/0.8/cassandra.rb +5 -267
  32. data/lib/cassandra/0.8/columns.rb +1 -81
  33. data/lib/cassandra/0.8/protocol.rb +9 -103
  34. data/lib/cassandra/array.rb +0 -0
  35. data/lib/cassandra/cassandra.rb +715 -92
  36. data/lib/cassandra/{0.7/column_family.rb → column_family.rb} +0 -0
  37. data/lib/cassandra/columns.rb +63 -6
  38. data/lib/cassandra/comparable.rb +0 -0
  39. data/lib/cassandra/constants.rb +0 -0
  40. data/lib/cassandra/debug.rb +0 -0
  41. data/lib/cassandra/helpers.rb +0 -0
  42. data/lib/cassandra/{0.7/keyspace.rb → keyspace.rb} +0 -0
  43. data/lib/cassandra/long.rb +0 -0
  44. data/lib/cassandra/mock.rb +45 -8
  45. data/lib/cassandra/ordered_hash.rb +0 -0
  46. data/lib/cassandra/protocol.rb +119 -0
  47. data/lib/cassandra/time.rb +0 -0
  48. data/test/cassandra_client_test.rb +0 -0
  49. data/test/cassandra_mock_test.rb +3 -0
  50. data/test/cassandra_test.rb +202 -20
  51. data/test/comparable_types_test.rb +0 -0
  52. data/test/eventmachine_test.rb +0 -0
  53. data/test/ordered_hash_test.rb +0 -0
  54. data/test/test_helper.rb +1 -1
  55. data/vendor/0.6/gen-rb/cassandra.rb +0 -0
  56. data/vendor/0.6/gen-rb/cassandra_constants.rb +0 -0
  57. data/vendor/0.6/gen-rb/cassandra_types.rb +0 -0
  58. data/vendor/0.7/gen-rb/cassandra.rb +0 -0
  59. data/vendor/0.7/gen-rb/cassandra_constants.rb +0 -0
  60. data/vendor/0.7/gen-rb/cassandra_types.rb +0 -0
  61. data/vendor/0.8/gen-rb/cassandra.rb +0 -0
  62. data/vendor/0.8/gen-rb/cassandra_constants.rb +0 -0
  63. data/vendor/0.8/gen-rb/cassandra_types.rb +0 -0
  64. metadata +27 -29
  65. data/README.rdoc +0 -99
  66. data/lib/cassandra/0.8/column_family.rb +0 -3
  67. data/lib/cassandra/0.8/keyspace.rb +0 -3
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ v0.11.1
2
+ - Add counter support for Cassandra 0.8. (Thanks Swrve team!)
3
+ - Add additional rake tasks to start and stop cassandra in the background.
4
+ - Fix issue with non-utf8 column names not being encoded/decoded properly.
5
+ - Add way to specify a default read/write consistency.
6
+ - Consolidate 0.7 and 0.8 functions, and move 0.6 specific functions into lib/cassandra/0.6/
7
+ - Use 0.8-rc1 as 0.8 install target.
8
+ - Updated get_index_slices API to allow passing an array of hashes instead of IndexClause instance. (Maintains backward compatibility.)
9
+ - Fix permissions issue.
10
+
1
11
  v0.11.0
2
12
  - Remove direct thrift dependency. Allow thrift_client to require it.
3
13
  - Add functions for each and each_key to iterate through key ranges.
data/LICENSE CHANGED
File without changes
data/Manifest CHANGED
@@ -1,5 +1,9 @@
1
- bin/cassandra_helper
2
1
  CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README.md
5
+ Rakefile
6
+ bin/cassandra_helper
3
7
  conf/0.6/cassandra.in.sh
4
8
  conf/0.6/log4j.properties
5
9
  conf/0.6/schema.json
@@ -14,38 +18,33 @@ conf/0.8/cassandra.yaml
14
18
  conf/0.8/log4j-server.properties
15
19
  conf/0.8/schema.json
16
20
  conf/0.8/schema.txt
21
+ lib/cassandra.rb
22
+ lib/cassandra/0.6.rb
17
23
  lib/cassandra/0.6/cassandra.rb
18
24
  lib/cassandra/0.6/columns.rb
19
25
  lib/cassandra/0.6/protocol.rb
20
- lib/cassandra/0.6.rb
26
+ lib/cassandra/0.7.rb
21
27
  lib/cassandra/0.7/cassandra.rb
22
- lib/cassandra/0.7/column_family.rb
23
28
  lib/cassandra/0.7/columns.rb
24
- lib/cassandra/0.7/keyspace.rb
25
29
  lib/cassandra/0.7/protocol.rb
26
- lib/cassandra/0.7.rb
30
+ lib/cassandra/0.8.rb
27
31
  lib/cassandra/0.8/cassandra.rb
28
- lib/cassandra/0.8/column_family.rb
29
32
  lib/cassandra/0.8/columns.rb
30
- lib/cassandra/0.8/keyspace.rb
31
33
  lib/cassandra/0.8/protocol.rb
32
- lib/cassandra/0.8.rb
33
34
  lib/cassandra/array.rb
34
35
  lib/cassandra/cassandra.rb
36
+ lib/cassandra/column_family.rb
35
37
  lib/cassandra/columns.rb
36
38
  lib/cassandra/comparable.rb
37
39
  lib/cassandra/constants.rb
38
40
  lib/cassandra/debug.rb
39
41
  lib/cassandra/helpers.rb
42
+ lib/cassandra/keyspace.rb
40
43
  lib/cassandra/long.rb
41
44
  lib/cassandra/mock.rb
42
45
  lib/cassandra/ordered_hash.rb
46
+ lib/cassandra/protocol.rb
43
47
  lib/cassandra/time.rb
44
- lib/cassandra.rb
45
- LICENSE
46
- Manifest
47
- Rakefile
48
- README.rdoc
49
48
  test/cassandra_client_test.rb
50
49
  test/cassandra_mock_test.rb
51
50
  test/cassandra_test.rb
@@ -0,0 +1,344 @@
1
+ # cassandra
2
+ A Ruby client for the Cassandra distributed database.
3
+
4
+ * [Getting Started](#getting-started)
5
+ * [License](#license)
6
+ * [Cassandra Version](#cassandra-version)
7
+ * [Read/Write API Method Reference](#read-write-api-method-reference)
8
+
9
+ ## Getting Started
10
+
11
+ Here is a quick sample of the general use (more details in Read/Write
12
+ API below):
13
+
14
+ require 'cassandra'
15
+ client = Cassandra.new('Twitter', '127.0.0.1:9160')
16
+ client.insert(:Users, "5", {'screen_name' => "buttonscat"})
17
+
18
+ ## License
19
+
20
+ Copyright 2009, 2010 Twitter, Inc. See included LICENSE file. Portions copyright 2004-2009 David Heinemeier Hansson, and used with permission.
21
+
22
+ ## Cassandra Version
23
+
24
+ The Cassandra project is under very active development, and as such
25
+ there are a few different versions that you may need to use this gem
26
+ with. We have set up an easy sure fire mechanism for selecting the
27
+ specific version that you are connecting to while requiring the gem.
28
+
29
+ #### Require Method
30
+ The default version is the currently stable release of cassandra. (0.7
31
+ at this time, but 0.8 is looming in the near future.)
32
+
33
+ To use the default version simply use a normal require:
34
+ require 'cassandra'
35
+
36
+ To use a specific version (0.7 in this example) you would use a
37
+ slightly differently formatted require:
38
+ require 'cassandra/0.7'
39
+
40
+ #### Environment Variable Method
41
+ These mechanisms work well when you are using the cassandra gem in your
42
+ own projects or irb, but if you would rather not hard code your app to a
43
+ specific version you can always specify an environment variable with the
44
+ version you are using:
45
+ export CASSANDRA_VERSION=0.7
46
+
47
+ Then you would use the default require as listed above:
48
+ require 'cassandra'
49
+
50
+ ## Read/Write API Method Reference
51
+
52
+ ### insert
53
+
54
+ * column\_family - The column\_family that you are inserting into.
55
+ * key - The row key to insert.
56
+ * hash - The columns or super columns to insert.
57
+ * options - Valid options are:
58
+ * :timestamp - Uses the current time if none specified.
59
+ * :consistency - Uses the default write consistency if none specified.
60
+ * :ttl - If specified this is the number of seconds after the insert that this value will be available.
61
+
62
+ This is the main method used to insert rows into cassandra. If the
63
+ column\_family that you are inserting into is a SuperColumnFamily then
64
+ the hash passed in should be a nested hash, otherwise it should be a
65
+ flat hash.
66
+
67
+ This method can also be called while in batch mode. If in batch mode
68
+ then we queue up the mutations (an insert in this case) and pass them to
69
+ cassandra in a single batch at the end of the block.
70
+
71
+ Example:
72
+
73
+ @client.insert(:Statuses, key, {'body' => 'v', 'user' => 'v'})
74
+
75
+ columns = {@uuids[1] => 'v1', @uuids[2] => 'v2'}
76
+ @client.insert(:StatusRelationships, key, {'user_timelines' => columns})
77
+
78
+
79
+ ### remove
80
+
81
+ * column\_family - The column\_family that you are inserting into.
82
+ * key - The row key to insert.
83
+ * columns - Either a single super_column or a list of columns.
84
+ * sub_columns - The list of sub\_columns to select.
85
+ * options - Valid options are:
86
+ * :timestamp - Uses the current time if none specified.
87
+ * :consistency - Uses the default write consistency if none specified.
88
+
89
+ This method is used to delete (actually marking them as deleted with a
90
+ tombstone) columns or super columns.
91
+
92
+ Example:
93
+ @client.insert(:Statuses, key, {'body' => 'v', 'subject' => 'v'})
94
+
95
+ @client.remove(:Statuses, key, 'body') # removes the 'body' column
96
+ @client.remove(:Statuses, key) # removes the row
97
+
98
+ ### count\_columns
99
+
100
+ Count the columns for the provided parameters.
101
+
102
+ * column\_family - The column\_family that you are inserting into.
103
+ * key - The row key to insert.
104
+ * columns - Either a single super_column or a list of columns.
105
+ * sub_columns - The list of sub\_columns to select.
106
+ * options - Valid options are:
107
+ * :consistency - Uses the default read consistency if none specified.
108
+
109
+ Example:
110
+ @client.insert(:Statuses, key, {'body' => 'v1', 'user' => 'v2'})
111
+ @client.count_columns(:Statuses, key) # returns 2
112
+
113
+ ### get
114
+
115
+ Return a hash (actually, a Cassandra::OrderedHash) or a single value
116
+ representing the element at the column_family:key:[column]:[sub_column]
117
+ path you request.
118
+
119
+ * column\_family - The column\_family that you are inserting into.
120
+ * key - The row key to insert.
121
+ * columns - Either a single super\_column or a list of columns.
122
+ * sub\_columns - The list of sub\_columns to select.
123
+ * options - Valid options are:
124
+ * :count - The number of columns requested to be returned.
125
+ * :start - The starting value for selecting a range of columns.
126
+ * :finish - The final value for selecting a range of columns.
127
+ * :reversed - If set to true the results will be returned in
128
+ reverse order.
129
+ * :consistency - Uses the default read consistency if none specified.
130
+
131
+ Example:
132
+ @client.insert(:Users, key, {'body' => 'v', 'user' => 'v'})
133
+ @client.get(:Users, key)) # returns {'body' => 'v', 'user' => 'v'}
134
+
135
+ ### multi\_get
136
+
137
+ Multi-key version of Cassandra#get.
138
+
139
+ This method allows you to select multiple rows with a single query.
140
+ If a key that is passed in doesn't exist an empty hash will be
141
+ returned.
142
+
143
+ Supports the same parameters as Cassandra#get.
144
+
145
+ * column_family - The column_family that you are inserting into.
146
+ * key - An array of keys to.
147
+ * columns - Either a single super_column or a list of columns.
148
+ * sub_columns - The list of sub\_columns to select.
149
+ * options - Valid options are:
150
+ * :count - The number of columns requested to be returned.
151
+ * :start - The starting value for selecting a range of columns.
152
+ * :finish - The final value for selecting a range of columns.
153
+ * :reversed - If set to true the results will be returned in reverse order.
154
+ * :consistency - Uses the default read consistency if none specified.
155
+
156
+ Example:
157
+
158
+ @client.insert(:Users, '1', {'body' => 'v1', 'user' => 'v1'})
159
+ @client.insert(:Users, '2', {'body' => 'v2', 'user' => 'v2'})
160
+
161
+ expected = OrderedHash[
162
+ '1', {'body' => 'v1', 'user' => 'v1'},
163
+ '2', {'body' => 'v2', 'user' => 'v2'},
164
+ 'bogus', {}
165
+ ]
166
+ result = @client.multi_get(:Users, ['1', '2', 'bogus'])
167
+
168
+ ### exists?
169
+
170
+ Return true if the column\_family:key:[column]:[sub\_column] path you
171
+ request exists.
172
+
173
+ If passed in only a row key it will query for any columns (limiting
174
+ to 1) for that row key. If a column is passed in it will query for
175
+ that specific column/super column.
176
+
177
+ This method will return true or false.
178
+
179
+ * column\_family - The column\_family that you are inserting into.
180
+ * key - The row key to insert.
181
+ * columns - Either a single super\_column or a list of columns.
182
+ * sub\_columns - The list of sub\_columns to select.
183
+ * options - Valid options are:
184
+ * :consistency - Uses the default read consistency if none specified.
185
+
186
+ Example:
187
+
188
+ @client.insert(:Statuses, 'key', {'body' => 'v'})
189
+ @client.exists?(:Statuses, 'key') # returns true
190
+ @client.exists?(:Statuses, 'bogus') # returns false
191
+ @client.exists?(:Statuses, 'key', 'body') # returns true
192
+ @client.exists?(:Statuses, 'key', 'bogus') # returns false
193
+
194
+ ### get\_range
195
+ Return an Cassandra::OrderedHash containing the columns specified for the given
196
+ range of keys in the column\_family you request.
197
+
198
+ This method is just a convenience wrapper around Cassandra#get_range_single
199
+ and Cassandra#get\_range\_batch. If :key\_size, :batch\_size, or a block
200
+ is passed in Cassandra#get\_range\_batch will be called. Otherwise
201
+ Cassandra#get\_range\_single will be used.
202
+
203
+ The start\_key and finish\_key parameters are only useful for iterating of all records
204
+ as is done in the Cassandra#each and Cassandra#each\_key methods if you are using the
205
+ RandomPartitioner.
206
+
207
+ If the table is partitioned with OrderPreservingPartitioner you may
208
+ use the start\_key and finish\_key params to select all records with
209
+ the same prefix value.
210
+
211
+ If a block is passed in we will yield the row key and columns for
212
+ each record returned.
213
+
214
+ Please note that Cassandra returns a row for each row that has existed in the
215
+ system since gc\_grace\_seconds. This is because deleted row keys are marked as
216
+ deleted, but left in the system until the cluster has had resonable time to replicate the deletion.
217
+ This function attempts to suppress deleted rows (actually any row returned without
218
+ columns is suppressed).
219
+
220
+ * column\_family - The column\_family that you are inserting into.
221
+ * key - The row key to insert.
222
+ * columns - Either a single super\_column or a list of columns.
223
+ * sub\_columns - The list of sub\_columns to select.
224
+ * options - Valid options are:
225
+ * :start\_key - The starting value for selecting a range of keys (only useful with OPP).
226
+ * :finish\_key - The final value for selecting a range of keys (only useful with OPP).
227
+ * :key\_count - The total number of keys to return from the query. (see note regarding deleted records)
228
+ * :batch\_size - The maximum number of keys to return per query. If specified will loop until :key\_count is obtained or all records have been returned.
229
+ * :count - The number of columns requested to be returned.
230
+ * :start - The starting value for selecting a range of columns.
231
+ * :finish - The final value for selecting a range of columns.
232
+ * :reversed - If set to true the results will be returned in reverse order.
233
+ * :consistency - Uses the default read consistency if none specified.
234
+
235
+ Example:
236
+
237
+ 10.times do |i|
238
+ @client.insert(:Statuses, i.to_s, {'body' => '1'})
239
+ end
240
+
241
+ @client.get_range_keys(:Statuses, :key_count => 4)
242
+
243
+ # returns:
244
+ #{
245
+ # '0' => {'body' => '1'},
246
+ # '1' => {'body' => '1'},
247
+ # '2' => {'body' => '1'},
248
+ # '3' => {'body' => '1'}
249
+ #}
250
+
251
+ ### count\_range
252
+
253
+ Return an Array containing all of the keys within a given range.
254
+
255
+ This method just calls Cassandra#get\_range and returns the
256
+ row keys for the records returned.
257
+
258
+ See [Cassandra#get\_range](#get-range) for options.
259
+
260
+ ### get\_range\_keys
261
+
262
+ Return an Array containing all of the keys within a given range.
263
+
264
+ This method just calls Cassandra#get\_range and returns the
265
+ row keys for the records returned.
266
+
267
+ See [Cassandra#get\_range](#get-range) for options.
268
+
269
+ ### each\_key
270
+ Iterate through each key within the given range parameters. This function can be
271
+ used to iterate over each key in the given column family.
272
+
273
+ This method just calls Cassandra#get\_range and yields each row key.
274
+
275
+ See [Cassandra#get\_range](#get-range) for options.
276
+
277
+ Example:
278
+ 10.times do |i|
279
+ @client.insert(:Statuses, k + i.to_s, {"body-#{i.to_s}" => 'v'})
280
+ end
281
+
282
+ @client.each_key(:Statuses) do |key|
283
+ print key
284
+ end
285
+
286
+ # returns 0123456789
287
+
288
+ ### each
289
+ Iterate through each row within the given column\_family.
290
+
291
+ This method just calls Cassandra#get\_range and yields the key and
292
+ columns.
293
+
294
+ See [Cassandra#get\_range](#get-range) for options.
295
+
296
+ ### get\_index\_slices
297
+ This method is used to query a secondary index with a set of
298
+ provided search parameters
299
+
300
+ Please note that you can either specify a
301
+ CassandraThrift::IndexClause or an array of hashes with the
302
+ format as below.
303
+
304
+ * column\_family - The Column Family this operation will be run on.
305
+ * index\_clause - This can either be a CassandraThrift::IndexClause or an array of hashes with the following keys:
306
+ * :column\_name - Column to be compared
307
+ * :value - Value to compare against
308
+ * :comparison - Type of comparison to do.
309
+ * options
310
+ * :key\_count - Set maximum number of rows to return. (Only works if CassandraThrift::IndexClause is not passed in.)
311
+ * :key\_start - Set starting row key for search. (Only works if CassandraThrift::IndexClause is not passed in.)
312
+ * :consistency
313
+
314
+ Example:
315
+ @client.create_index('Twitter', 'Statuses', 'x', 'LongType')
316
+
317
+ @client.insert(:Statuses, 'row1', { 'x' => [0,10].pack("NN") })
318
+
319
+ (2..10).to_a.each do |i|
320
+ @twitter.insert(:Statuses, 'row' + i.to_s, { 'x' => [0,20].pack("NN"), 'non_indexed' => [i].pack('N*') })
321
+ end
322
+
323
+ @client.insert(:Statuses, 'row11', { 'x' => [0,30].pack("NN") })
324
+
325
+ expressions = [{:column_name => 'x', :value => [0,20].pack("NN"), :comparison => "=="}]
326
+
327
+ # verify multiples will be returned
328
+ @client.get_indexed_slices(:Statuses, expressions).length # returns 9
329
+
330
+ # verify that GT and LT queries perform properly
331
+ expressions = [
332
+ { :column_name => 'x',
333
+ :value => [0,20].pack("NN"),
334
+ :comparison => "=="},
335
+ { :column_name => 'non_indexed',
336
+ :value => [5].pack("N*"),
337
+ :comparison => ">"}
338
+ ]
339
+
340
+ @client.get_indexed_slices(:Statuses, expressions).length # returns 5
341
+
342
+ ## Reporting Problems
343
+
344
+ The Github issue tracker is [here](http://github.com/fauna/cassandra/issues). If you have problems with this library or Cassandra itself, please use the [cassandra-user mailing list](http://mail-archives.apache.org/mod_mbox/incubator-cassandra-user/).
data/Rakefile CHANGED
@@ -10,19 +10,21 @@ unless ENV['FROM_BIN_CASSANDRA_HELPER']
10
10
  p.summary = "A Ruby client for the Cassandra distributed database."
11
11
  p.rubygems_version = ">= 0.8"
12
12
  p.dependencies = ['thrift_client >=0.6.0', 'json', 'rake', 'simple_uuid >=0.1.0']
13
- p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift)/
13
+ p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift|.*\.rbc)/
14
14
  p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
15
+ p.retain_gemspec = true
15
16
  end
16
17
  end
17
18
 
18
19
  CassandraBinaries = {
19
20
  '0.6' => 'http://www.apache.org/dist/cassandra/0.6.13/apache-cassandra-0.6.13-bin.tar.gz',
20
21
  '0.7' => 'http://www.apache.org/dist/cassandra/0.7.5/apache-cassandra-0.7.5-bin.tar.gz',
21
- '0.8' => 'http://www.apache.org/dist/cassandra/0.8.0/apache-cassandra-0.8.0-beta1-bin.tar.gz'
22
+ '0.8' => 'http://www.apache.org/dist/cassandra/0.8.0/apache-cassandra-0.8.0-rc1-bin.tar.gz'
22
23
  }
23
24
 
24
25
  CASSANDRA_HOME = ENV['CASSANDRA_HOME'] || "#{ENV['HOME']}/cassandra"
25
26
  CASSANDRA_VERSION = ENV['CASSANDRA_VERSION'] || '0.7'
27
+ CASSANDRA_PIDFILE = ENV['CASSANDRA_PIDFILE'] || "#{CASSANDRA_HOME}/cassandra.pid"
26
28
 
27
29
  def setup_cassandra_version(version = CASSANDRA_VERSION)
28
30
  FileUtils.mkdir_p CASSANDRA_HOME
@@ -57,14 +59,50 @@ def setup_environment
57
59
  env
58
60
  end
59
61
 
60
- desc "Start Cassandra"
61
- task :cassandra => :java do
62
- setup_cassandra_version
62
+ def running?(pid_file = nil)
63
+ pid_file ||= CASSANDRA_PIDFILE
63
64
 
64
- env = setup_environment
65
+ if File.exists?(pid_file)
66
+ pid = File.new(pid_file).read.to_i
67
+ begin
68
+ Process.kill(0, pid)
69
+ return true
70
+ rescue
71
+ File.delete(pid_file)
72
+ end
73
+ end
65
74
 
66
- Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
67
- sh("env #{env} bin/cassandra -f")
75
+ false
76
+ end
77
+
78
+ namespace :cassandra do
79
+ desc "Start Cassandra"
80
+ task :start, :daemonize, :needs => :java do |t, args|
81
+ args.with_defaults(:daemonize => true)
82
+
83
+ setup_cassandra_version
84
+
85
+ env = setup_environment
86
+
87
+ Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
88
+ sh("env #{env} bin/cassandra #{'-f' unless args.daemonize} -p #{CASSANDRA_PIDFILE}")
89
+ end
90
+ end
91
+
92
+ desc "Stop Cassandra"
93
+ task :stop => :java do
94
+ setup_cassandra_version
95
+ env = setup_environment
96
+ sh("kill $(cat #{CASSANDRA_PIDFILE})")
97
+ end
98
+ end
99
+
100
+ desc "Start Cassandra"
101
+ task :cassandra => :java do
102
+ begin
103
+ Rake::Task["cassandra:start"].invoke(false)
104
+ rescue RuntimeError => e
105
+ raise e unless e.message =~ /Command failed with status \(130\)/ # handle keyboard interupt errors
68
106
  end
69
107
  end
70
108
 
@@ -120,3 +158,9 @@ task :thrift do
120
158
  rm -rf gen-rb &&
121
159
  thrift -gen rb #{CASSANDRA_HOME}/interface/cassandra.thrift")
122
160
  end
161
+
162
+ task :fix_perms do
163
+ chmod_R 0755, './'
164
+ end
165
+
166
+ task :pkg => [:fix_perms]