cassandra-cql 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +203 -0
- data/README.rdoc +78 -0
- data/Rakefile +150 -0
- data/cassandra-cql.gemspec +29 -0
- data/lib/cassandra-cql.rb +39 -0
- data/lib/cassandra-cql/database.rb +107 -0
- data/lib/cassandra-cql/result.rb +133 -0
- data/lib/cassandra-cql/row.rb +59 -0
- data/lib/cassandra-cql/schema.rb +108 -0
- data/lib/cassandra-cql/statement.rb +111 -0
- data/lib/cassandra-cql/types/abstract_type.rb +47 -0
- data/lib/cassandra-cql/types/ascii_type.rb +25 -0
- data/lib/cassandra-cql/types/boolean_type.rb +25 -0
- data/lib/cassandra-cql/types/bytes_type.rb +21 -0
- data/lib/cassandra-cql/types/decimal_type.rb +25 -0
- data/lib/cassandra-cql/types/double_type.rb +25 -0
- data/lib/cassandra-cql/types/float_type.rb +25 -0
- data/lib/cassandra-cql/types/integer_type.rb +27 -0
- data/lib/cassandra-cql/types/long_type.rb +27 -0
- data/lib/cassandra-cql/types/utf8_type.rb +25 -0
- data/lib/cassandra-cql/types/uuid_type.rb +27 -0
- data/lib/cassandra-cql/utility.rb +37 -0
- data/lib/cassandra-cql/uuid.rb +21 -0
- data/lib/cassandra-cql/version.rb +19 -0
- data/spec/column_family_spec.rb +105 -0
- data/spec/comparator_spec.rb +225 -0
- data/spec/conf/0.8/cassandra.in.sh +41 -0
- data/spec/conf/0.8/cassandra.yaml +61 -0
- data/spec/conf/0.8/log4j-server.properties +40 -0
- data/spec/conf/0.8/schema.txt +10 -0
- data/spec/conf/1.0/cassandra.in.sh +41 -0
- data/spec/conf/1.0/cassandra.yaml +416 -0
- data/spec/conf/1.0/log4j-server.properties +40 -0
- data/spec/conf/1.0/schema.txt +10 -0
- data/spec/result_spec.rb +173 -0
- data/spec/row_spec.rb +55 -0
- data/spec/rowkey_spec.rb +223 -0
- data/spec/schema_spec.rb +51 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/statement_spec.rb +224 -0
- data/spec/utility_spec.rb +26 -0
- data/spec/uuid_spec.rb +26 -0
- data/spec/validation_spec.rb +250 -0
- data/vendor/gen-rb/cassandra.rb +2212 -0
- data/vendor/gen-rb/cassandra_constants.rb +10 -0
- data/vendor/gen-rb/cassandra_types.rb +854 -0
- metadata +171 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
203
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
=Cassandra
|
2
|
+
The Apache Cassandra Project (http://cassandra.apache.org) develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.
|
3
|
+
|
4
|
+
=CQL
|
5
|
+
Cassandra originally went with a Thrift RPC-based API as a way to provide a common denominator that more idiomatic clients could build upon independently.
|
6
|
+
However, this worked poorly in practice: raw Thrift is too low-level to use productively, and keeping pace with new API methods to support (for example) indexes in 0.7 or distributed counters in 0.8 is too much for many maintainers.
|
7
|
+
|
8
|
+
CQL, the Cassandra Query Language, addresses this by pushing all implementation details to the server; all the client has to know for any operation is how to interpret "resultset" objects.
|
9
|
+
So adding a feature like counters just requires teaching the CQL parser to understand "column + N" notation; no client-side changes are necessary.
|
10
|
+
|
11
|
+
(CQL Specification: https://github.com/apache/cassandra/blob/trunk/doc/cql/CQL.textile)
|
12
|
+
|
13
|
+
=Quick Start
|
14
|
+
|
15
|
+
==Establishing a connection
|
16
|
+
|
17
|
+
# Defaults to the system keyspace
|
18
|
+
db = CassandraCQL::Database.new('127.0.0.1:9160')
|
19
|
+
|
20
|
+
# Specifying a keyspace
|
21
|
+
db = CassandraCQL::Database.new('127.0.0.1:9160', {:keyspace => 'keyspace1'})
|
22
|
+
|
23
|
+
# Specifying more than one seed node
|
24
|
+
db = CassandraCQL::Database.new(['127.0.0.1:9160','127.0.0.2:9160'])
|
25
|
+
|
26
|
+
==Creating a Keyspace
|
27
|
+
|
28
|
+
# Creating a simple keyspace with replication factor 1
|
29
|
+
db.execute("CREATE KEYSPACE keyspace1 WITH strategy_class='org.apache.cassandra.locator.SimpleStrategy' AND strategy_options:replication_factor=1")
|
30
|
+
db.execute("USE keyspace1")
|
31
|
+
|
32
|
+
==Creating a Column Family
|
33
|
+
|
34
|
+
# Creating a column family with a single validated column
|
35
|
+
db.execute("CREATE COLUMNFAMILY users (id varchar PRIMARY KEY, email varchar)")
|
36
|
+
|
37
|
+
# Create an index on the name
|
38
|
+
db.execute("CREATE INDEX users_email_idx ON users (email)")
|
39
|
+
|
40
|
+
==Inserting into a Column Family
|
41
|
+
|
42
|
+
# Insert without bound variables
|
43
|
+
db.execute("INSERT INTO users (id, email) VALUES ('kreynolds', 'kelley@insidesystems.net')")
|
44
|
+
|
45
|
+
# Insert with bound variables
|
46
|
+
db.execute("INSERT INTO users (id, email) VALUES (?, ?)", 'kway', 'kevin@insidesystems.net')
|
47
|
+
|
48
|
+
==Updating a Column Family
|
49
|
+
|
50
|
+
# Update
|
51
|
+
db.execute("UPDATE users SET email=? WHERE id=?", 'kreynolds@insidesystems.net', 'kreynolds')
|
52
|
+
|
53
|
+
==Selecting from a Column Family
|
54
|
+
|
55
|
+
# Select all
|
56
|
+
db.execute("SELECT * FROM users").fetch { |row| puts row.to_hash.inspect }
|
57
|
+
{"id"=>"kway", "email"=>"kevin@insidesystems.net"}
|
58
|
+
{"id"=>"kreynolds", "email"=>"kreynolds@insidesystems.net"}
|
59
|
+
|
60
|
+
# Select just one user by id
|
61
|
+
db.execute("SELECT * FROM users WHERE id=?", 'kreynolds').fetch { |row| puts row.to_hash.inspect }
|
62
|
+
{"id"=>"kreynolds", "email"=>"kreynolds@insidesystems.net"}
|
63
|
+
|
64
|
+
# Select just one user by indexed column
|
65
|
+
db.execute("SELECT * FROM users WHERE email=?", 'kreynolds@insidesystems.net').fetch { |row| puts row.to_hash.inspect }
|
66
|
+
{"id"=>"kreynolds", "email"=>"kreynolds@insidesystems.net"}
|
67
|
+
|
68
|
+
==Deleting from a Column Family
|
69
|
+
|
70
|
+
# Delete the swarthy bastard Kevin
|
71
|
+
db.execute("DELETE FROM users WHERE id=?", 'kway')
|
72
|
+
|
73
|
+
=TODO
|
74
|
+
|
75
|
+
1. Make bind_var usage friendlier
|
76
|
+
2. Determine if returning Time objects for TimeUUID is appropriate in all cases and if not, add an option
|
77
|
+
3. Add yardoc
|
78
|
+
4. Add spec for database
|
data/Rakefile
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'rspec/core'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
CassandraBinaries = {
|
9
|
+
'0.8' => 'http://archive.apache.org/dist/cassandra/0.8.4/apache-cassandra-0.8.4-bin.tar.gz',
|
10
|
+
'1.0' => 'http://archive.apache.org/dist/cassandra/1.0.1/apache-cassandra-1.0.1-bin.tar.gz',
|
11
|
+
}
|
12
|
+
|
13
|
+
CASSANDRA_VERSION = ENV['CASSANDRA_VERSION'] || '1.0'
|
14
|
+
CASSANDRA_HOME = File.dirname(__FILE__) + '/tmp'
|
15
|
+
CASSANDRA_PIDFILE = ENV['CASSANDRA_PIDFILE'] || "#{CASSANDRA_HOME}/cassandra.pid"
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
18
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
22
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
23
|
+
spec.rcov = true
|
24
|
+
spec.rcov_opts = "--exclude 'spec/*'"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Download Cassandra and run specs against it"
|
28
|
+
task :spec_with_server do
|
29
|
+
Rake::Task["cassandra:clean"].invoke
|
30
|
+
Rake::Task["cassandra:start"].invoke
|
31
|
+
error = nil
|
32
|
+
begin
|
33
|
+
Rake::Task["spec"].invoke
|
34
|
+
rescue
|
35
|
+
error = $!
|
36
|
+
end
|
37
|
+
Rake::Task["cassandra:stop"].invoke
|
38
|
+
raise $! if $!
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
def setup_cassandra_version(version = CASSANDRA_VERSION)
|
44
|
+
FileUtils.mkdir_p CASSANDRA_HOME
|
45
|
+
|
46
|
+
destination_directory = File.join(CASSANDRA_HOME, 'cassandra-' + CASSANDRA_VERSION)
|
47
|
+
|
48
|
+
unless File.exists?(File.join(destination_directory, 'bin','cassandra'))
|
49
|
+
download_source = CassandraBinaries[CASSANDRA_VERSION]
|
50
|
+
download_destination = File.join(CASSANDRA_HOME, File.basename(download_source))
|
51
|
+
untar_directory = File.join(CASSANDRA_HOME, File.basename(download_source,'-bin.tar.gz'))
|
52
|
+
|
53
|
+
puts "downloading cassandra"
|
54
|
+
sh "curl -L -o #{download_destination} #{download_source}"
|
55
|
+
|
56
|
+
sh "tar xzf #{download_destination} -C #{CASSANDRA_HOME}"
|
57
|
+
sh "mv #{untar_directory} #{destination_directory}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_environment
|
62
|
+
env = ""
|
63
|
+
if !ENV["CASSANDRA_INCLUDE"]
|
64
|
+
env << "CASSANDRA_INCLUDE=#{File.expand_path(Dir.pwd)}/spec/conf/#{CASSANDRA_VERSION}/cassandra.in.sh "
|
65
|
+
env << "CASSANDRA_HOME=#{CASSANDRA_HOME}/cassandra-#{CASSANDRA_VERSION} "
|
66
|
+
env << "CASSANDRA_CONF=#{File.expand_path(Dir.pwd)}/spec/conf/#{CASSANDRA_VERSION}"
|
67
|
+
else
|
68
|
+
env << "CASSANDRA_INCLUDE=#{ENV['CASSANDRA_INCLUDE']} "
|
69
|
+
env << "CASSANDRA_HOME=#{ENV['CASSANDRA_HOME']} "
|
70
|
+
env << "CASSANDRA_CONF=#{ENV['CASSANDRA_CONF']}"
|
71
|
+
end
|
72
|
+
|
73
|
+
env
|
74
|
+
end
|
75
|
+
|
76
|
+
def running?(pid_file = nil)
|
77
|
+
pid_file ||= CASSANDRA_PIDFILE
|
78
|
+
|
79
|
+
if File.exists?(pid_file)
|
80
|
+
pid = File.new(pid_file).read.to_i
|
81
|
+
begin
|
82
|
+
Process.kill(0, pid)
|
83
|
+
return true
|
84
|
+
rescue
|
85
|
+
File.delete(pid_file)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
namespace :cassandra do
|
93
|
+
desc "Start Cassandra"
|
94
|
+
task :start, [:daemonize] => :java do |t, args|
|
95
|
+
args.with_defaults(:daemonize => true)
|
96
|
+
|
97
|
+
setup_cassandra_version
|
98
|
+
|
99
|
+
env = setup_environment
|
100
|
+
|
101
|
+
Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
|
102
|
+
sh("env #{env} bin/cassandra #{'-f' unless args.daemonize} -p #{CASSANDRA_PIDFILE}")
|
103
|
+
end
|
104
|
+
$stdout.puts "Sleeping for 8 seconds to wait for Cassandra to start ..."
|
105
|
+
sleep(8)
|
106
|
+
end
|
107
|
+
|
108
|
+
desc "Stop Cassandra"
|
109
|
+
task :stop => :java do
|
110
|
+
setup_cassandra_version
|
111
|
+
env = setup_environment
|
112
|
+
sh("kill $(cat #{CASSANDRA_PIDFILE})")
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "Delete all data files in #{CASSANDRA_HOME}"
|
116
|
+
task :clean do
|
117
|
+
sh("rm -rf #{File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}", 'data')}")
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
desc "Start Cassandra"
|
123
|
+
task :cassandra => :java do
|
124
|
+
begin
|
125
|
+
Rake::Task["cassandra:start"].invoke(false)
|
126
|
+
rescue RuntimeError => e
|
127
|
+
raise e unless e.message =~ /Command failed with status \(130\)/ # handle keyboard interupt errors
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
desc "Run the Cassandra CLI"
|
132
|
+
task :cli do
|
133
|
+
Dir.chdir(File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")) do
|
134
|
+
sh("bin/cassandra-cli -host localhost -port 9160")
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
desc "Check Java version"
|
139
|
+
task :java do
|
140
|
+
unless `java -version 2>&1`.split("\n").first =~ /java version "1.6/ #"
|
141
|
+
puts "You need to configure your environment for Java 1.6."
|
142
|
+
puts "If you're on OS X, just export the following environment variables:"
|
143
|
+
puts ' JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"'
|
144
|
+
puts ' PATH="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin:$PATH"'
|
145
|
+
exit(1)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
require 'yard'
|
150
|
+
YARD::Rake::YardocTask.new
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/cassandra-cql/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "cassandra-cql"
|
6
|
+
s.version = CassandraCQL::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Kelley Reynolds"]
|
9
|
+
s.email = ["kelley@insidesystems.net"]
|
10
|
+
s.homepage = "http://code.google.com/a/apache-extras.org/p/cassandra-ruby/"
|
11
|
+
s.summary = "CQL Interface to Cassandra"
|
12
|
+
s.description = "CQL Interface to Cassandra"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "cassandra-cql"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "rcov", ">= 0.9.9"
|
19
|
+
s.add_development_dependency "rspec", ">= 2.6.0"
|
20
|
+
s.add_development_dependency "rake", ">= 0.9.2"
|
21
|
+
s.add_development_dependency "yard", ">= 0.7.2"
|
22
|
+
s.add_dependency "simple_uuid", ">= 0.2.0"
|
23
|
+
s.add_dependency "thrift_client", ">= 0.7.1"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
28
|
+
s.require_path = 'lib'
|
29
|
+
end
|