bigrecord-driver 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -11
- data/VERSION +1 -1
- data/bin/bigrecord-driver +206 -0
- data/bin/hbase-driver +30 -2
- data/conf/log4j.properties +1 -1
- data/lib/big_record_driver/version.rb +3 -0
- data/lib/big_record_driver.rb +1 -0
- data/lib/bigrecord_driver.rb +1 -1
- metadata +6 -14
- data/MIT-LICENSE +0 -22
- data/bin/cassandra-driver +0 -5
- data/bin/launcher +0 -155
- data/lib/big_record_driver/cassandra_driver/server.rb +0 -135
- data/test/test_client_cassandra.rb +0 -63
- data/vendor/java/cassandra/cassandra-0.3.0-dev.jar +0 -0
- data/vendor/java/cassandra/libthrift.jar +0 -0
- data/vendor/java/cassandra/log4j-1.2.15.jar +0 -0
data/README.rdoc
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
-
=
|
1
|
+
= Bigrecord Driver
|
2
2
|
|
3
|
-
Bigrecord
|
3
|
+
Bigrecord Driver uses JRuby to interact with Java databases through their native Java APIs, and connect with other Ruby (regular Ruby or JRuby) based applications through DRb.
|
4
|
+
|
5
|
+
Currently supported databases are:
|
6
|
+
* HBase
|
7
|
+
|
8
|
+
The system that's running Bigrecord Driver will of course require JRuby and Java, however any other systems looking to access the databases require only Ruby and network access to the Bigrecord Driver server.
|
4
9
|
|
5
10
|
== Requirements
|
6
11
|
|
7
|
-
* HBase 0.20.
|
12
|
+
* HBase 0.20.2 (packaged by default)
|
13
|
+
* Any HBase version that conforms to the 0.20.2 API will work, see the "Database lib path" section for more information
|
8
14
|
* JRuby 1.3.0+
|
9
15
|
|
10
16
|
== Installation
|
11
17
|
|
12
|
-
(1) Install the latest Java Runtime for your operating system. There are many resources online for this.
|
18
|
+
(1) Install the latest Java Runtime for your operating system (or any version that's supported by JRuby. There are many resources online for this.
|
13
19
|
|
14
20
|
(2) Go to: http://jruby.org/getting-started and follow the instructions for installing the latest JRuby.
|
15
21
|
|
@@ -17,9 +23,11 @@ Bigrecord drivers that use JRuby DRb servers to connect with databases through t
|
|
17
23
|
|
18
24
|
export JRUBY_HOME=/path/to/jruby
|
19
25
|
|
20
|
-
and then add $JRUBY_HOME/bin to your system PATH
|
26
|
+
and then add $JRUBY_HOME/bin to your system PATH:
|
21
27
|
|
22
|
-
|
28
|
+
export PATH=$PATH:$JRUBY_HOME/bin
|
29
|
+
|
30
|
+
(4) Check that JRuby is installed correctly by typing in the following commands, and verifying that you get similar output:
|
23
31
|
|
24
32
|
> echo $JRUBY_HOME
|
25
33
|
/path/to/jruby
|
@@ -32,15 +40,37 @@ and then add $JRUBY_HOME/bin to your system PATH.
|
|
32
40
|
|
33
41
|
== Usage
|
34
42
|
|
35
|
-
|
43
|
+
=== Starting the service
|
44
|
+
|
45
|
+
Once you have everything installed, you can start up a Bigrecord Driver DRb server for HBase with:
|
46
|
+
|
47
|
+
hbase-driver start -p [port]
|
48
|
+
|
49
|
+
Port will default to 40000 if none is specified. Remember this port, because it will be used in the bigrecord.yml configuration file.
|
50
|
+
|
51
|
+
=== Stopping the service
|
52
|
+
|
53
|
+
When you want to stop the server, simply run the command:
|
54
|
+
|
55
|
+
hbase-driver stop -p [port]
|
56
|
+
|
57
|
+
=== More options
|
58
|
+
|
59
|
+
Check out more usage options with:
|
60
|
+
|
61
|
+
hbase-driver
|
62
|
+
|
63
|
+
=== Database lib path
|
64
|
+
|
65
|
+
Bigrecord Driver comes packaged with the latest set of lib files needed to interact with the specified database. Since it might be necessary to include the lib files of a different version than the latest, specify the database install location using the -l argument.
|
66
|
+
|
67
|
+
hbase-driver start -p [port] -l [/path/to/hbase/install]
|
36
68
|
|
37
|
-
|
38
|
-
|
39
|
-
Remember this port, because it will be used in the bigrecord.yml configuration file.
|
69
|
+
Bigrecord Driver will then use the /path/to/hbase/install folder and include the jar files needed to run so long as lib files weren't rearranged from the default configuration.
|
40
70
|
|
41
71
|
== Debugging
|
42
72
|
|
43
|
-
* If any errors are encountered during the usage of Bigrecord Driver, you can check the /tmp/
|
73
|
+
* If any errors are encountered during the usage of Bigrecord Driver, you can check the /tmp/bigrecord-driver/<database>/log/[port].log files for any errors that might've occurred.
|
44
74
|
|
45
75
|
== License
|
46
76
|
|
@@ -49,5 +79,6 @@ Big Record is released under the MIT license.
|
|
49
79
|
== Links
|
50
80
|
|
51
81
|
* Contact Us
|
82
|
+
* Google Group - http://groups.google.com/group/bigrecord
|
52
83
|
* Website - http://www.bigrecord.org
|
53
84
|
* IRC Channel - <tt>#bigrecord</tt> on irc.freenode.net
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
@@ -0,0 +1,206 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
print_usage()
|
4
|
+
{
|
5
|
+
cat << EOF
|
6
|
+
Bigrecord Driver
|
7
|
+
================
|
8
|
+
Usage: $DRIVERNAME-driver {start|stop|restart|status|start_debug} OPTIONS
|
9
|
+
|
10
|
+
OPTIONS:
|
11
|
+
-h Show this message
|
12
|
+
-p Define a port number (defaults to 40000)
|
13
|
+
-l Path to your $DRIVERNAME install (used to include lib files)
|
14
|
+
-c Custom class path (overwrites -l option)
|
15
|
+
EOF
|
16
|
+
}
|
17
|
+
|
18
|
+
# Getting the action
|
19
|
+
if [ "$1" != "" ]; then
|
20
|
+
if [ "$1" != "-h" -a "$1" != "-d" ]; then
|
21
|
+
ACTION=$1
|
22
|
+
shift
|
23
|
+
fi
|
24
|
+
fi
|
25
|
+
|
26
|
+
# Getting the other options
|
27
|
+
while getopts "ht:d:p:c:" optname
|
28
|
+
do
|
29
|
+
case "$optname" in
|
30
|
+
"h")
|
31
|
+
print_usage
|
32
|
+
exit 1
|
33
|
+
;;
|
34
|
+
"d")
|
35
|
+
DRIVERNAME=$OPTARG
|
36
|
+
;;
|
37
|
+
"p")
|
38
|
+
PORT=$OPTARG
|
39
|
+
;;
|
40
|
+
"c")
|
41
|
+
CLASS_PATH=$OPTARG
|
42
|
+
;;
|
43
|
+
"?")
|
44
|
+
echo "Invalid option $OPTARG"
|
45
|
+
;;
|
46
|
+
":")
|
47
|
+
echo "No argument given for option $OPTARG"
|
48
|
+
;;
|
49
|
+
*)
|
50
|
+
echo "Unknown error while processing options"
|
51
|
+
;;
|
52
|
+
esac
|
53
|
+
done
|
54
|
+
|
55
|
+
# Default parameters
|
56
|
+
if [ "$PORT" = "" ] ; then PORT=40000 ; fi
|
57
|
+
|
58
|
+
# Fix for Amazon EC2 instances
|
59
|
+
unset RUBYLIB
|
60
|
+
|
61
|
+
# Check that the DRIVERNAME given is valid
|
62
|
+
if [ "$DRIVERNAME" == "" ]; then
|
63
|
+
echo "Driver type was not specified"
|
64
|
+
exit 1
|
65
|
+
elif [ "$DRIVERNAME" != "hbase" -a "$DRIVERNAME" != "cassandra" ]; then
|
66
|
+
echo "Driver type \"$DRIVERNAME\" is invalid"
|
67
|
+
exit 1
|
68
|
+
fi
|
69
|
+
|
70
|
+
# Needs the $JRUBY_HOME environment variable to be set
|
71
|
+
if [ "$JRUBY_HOME" == "" ]; then
|
72
|
+
echo "\$JRUBY_HOME is not set. Please set it in your ~/.bashrc file."
|
73
|
+
exit 1
|
74
|
+
fi
|
75
|
+
|
76
|
+
CURRENT_DIR=`dirname "$0"`
|
77
|
+
|
78
|
+
VENDOR_DIR=`cd "$CURRENT_DIR/../vendor"; pwd`
|
79
|
+
CONF_DIR=`cd "$CURRENT_DIR/../conf"; pwd`
|
80
|
+
|
81
|
+
# Ruby file that contains the DRb server
|
82
|
+
DRIVER=$CURRENT_DIR/../lib/big_record_driver/"$DRIVERNAME"_driver/server.rb
|
83
|
+
|
84
|
+
# Location where the pids are stored
|
85
|
+
PIDS_DIR=/tmp/bigrecord-driver/$DRIVERNAME/pids
|
86
|
+
mkdir -p $PIDS_DIR
|
87
|
+
|
88
|
+
# Startup delay
|
89
|
+
STARTUP_TIMEOUT=30
|
90
|
+
|
91
|
+
# Location where the log files are stored
|
92
|
+
LOGS_DIR=/tmp/bigrecord-driver/$DRIVERNAME/log
|
93
|
+
mkdir -p $LOGS_DIR
|
94
|
+
|
95
|
+
# Set the environment to use jruby by default
|
96
|
+
PATH=$JRUBY_HOME/bin:$PATH
|
97
|
+
|
98
|
+
if [ "$CLASS_PATH" == "" ]; then
|
99
|
+
for f in $VENDOR_DIR/java/$DRIVERNAME/*.jar; do
|
100
|
+
if [ -f $f ]; then
|
101
|
+
CLASSPATH=${CLASSPATH}:$f;
|
102
|
+
fi
|
103
|
+
done
|
104
|
+
else
|
105
|
+
CLASSPATH=${CLASSPATH}:$CLASS_PATH;
|
106
|
+
fi
|
107
|
+
|
108
|
+
export PATH CLASSPATH
|
109
|
+
|
110
|
+
# TODO: find a way to use the return value of this function instead of
|
111
|
+
# manipulating the global variable
|
112
|
+
PIDS=""
|
113
|
+
|
114
|
+
|
115
|
+
refresh_pids() {
|
116
|
+
if [ -f $PIDS_DIR/$PORT.pid ]; then
|
117
|
+
PID=`cat $PIDS_DIR/$PORT.pid`
|
118
|
+
else
|
119
|
+
PID=""
|
120
|
+
fi
|
121
|
+
}
|
122
|
+
|
123
|
+
start() {
|
124
|
+
echo -n "Starting $DRIVERNAME-driver on port $PORT."
|
125
|
+
|
126
|
+
refresh_pids
|
127
|
+
|
128
|
+
if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
|
129
|
+
echo -e "\nAlready running (pid="$PID")."
|
130
|
+
exit 1
|
131
|
+
else
|
132
|
+
rm -f $LOGS_DIR/$PORT.log
|
133
|
+
nohup jruby $DRIVER $PORT >> $LOGS_DIR/$PORT.log 2>&1 < /dev/null &
|
134
|
+
PID=$!
|
135
|
+
if [ "$PID" != "" ] ; then
|
136
|
+
# monitor the log file for the message saying that the server is started
|
137
|
+
for ((i=0; i<$STARTUP_TIMEOUT; i+=1)); do
|
138
|
+
sleep 1
|
139
|
+
echo -n "."
|
140
|
+
if [ "$(cat $LOGS_DIR/$PORT.log | grep 'Started drb server')" != "" ] ; then
|
141
|
+
break
|
142
|
+
fi
|
143
|
+
done
|
144
|
+
|
145
|
+
if [ "$i" == $STARTUP_TIMEOUT ] ; then
|
146
|
+
echo -e "\nStartup timeout: couldn't start the DRb server."
|
147
|
+
else
|
148
|
+
echo $PID > $PIDS_DIR/$PORT.pid
|
149
|
+
fi
|
150
|
+
echo ""
|
151
|
+
else
|
152
|
+
echo -e "\nAn error occured while starting the DRb server."
|
153
|
+
fi
|
154
|
+
fi
|
155
|
+
}
|
156
|
+
|
157
|
+
stop() {
|
158
|
+
echo "Stopping $DRIVERNAME-driver on port $PORT"
|
159
|
+
|
160
|
+
refresh_pids
|
161
|
+
|
162
|
+
if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
|
163
|
+
echo "Stopping driver (pid = $PID)." >> $LOGS_DIR/$PORT.log
|
164
|
+
kill $PID
|
165
|
+
rm $PIDS_DIR/$PORT.pid
|
166
|
+
else
|
167
|
+
echo "No $DRIVERNAME driver to kill."
|
168
|
+
fi
|
169
|
+
}
|
170
|
+
|
171
|
+
status() {
|
172
|
+
refresh_pids
|
173
|
+
|
174
|
+
if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
|
175
|
+
echo "$DRIVERNAME-driver is RUNNING on port $PORT"
|
176
|
+
else
|
177
|
+
echo "$DRIVERNAME-driver is STOPPED on port $PORT"
|
178
|
+
fi
|
179
|
+
}
|
180
|
+
|
181
|
+
start_debug() {
|
182
|
+
jruby $DRIVER $PORT
|
183
|
+
}
|
184
|
+
|
185
|
+
case "$ACTION" in
|
186
|
+
start)
|
187
|
+
start
|
188
|
+
;;
|
189
|
+
stop)
|
190
|
+
stop
|
191
|
+
;;
|
192
|
+
restart)
|
193
|
+
stop
|
194
|
+
start
|
195
|
+
;;
|
196
|
+
status)
|
197
|
+
status
|
198
|
+
;;
|
199
|
+
start_debug)
|
200
|
+
start_debug
|
201
|
+
;;
|
202
|
+
*)
|
203
|
+
print_usage
|
204
|
+
exit 1
|
205
|
+
esac
|
206
|
+
exit 0
|
data/bin/hbase-driver
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
launcher = File.join(File.dirname(__FILE__), '
|
4
|
-
|
3
|
+
launcher = File.join(File.dirname(__FILE__), 'bigrecord-driver')
|
4
|
+
|
5
|
+
args = ARGV + ["-d", "hbase"]
|
6
|
+
|
7
|
+
# Check if we received a lib argument defining the hbase path
|
8
|
+
if ARGV.include?("-l")
|
9
|
+
switch_index = ARGV.index("-l")
|
10
|
+
hbase_path = ARGV[switch_index+1]
|
11
|
+
|
12
|
+
# Make sure that the folder exists
|
13
|
+
if File.exists?(hbase_path)
|
14
|
+
# We're only going to include the jar files we need.
|
15
|
+
required_jars = Dir[hbase_path+"/*.jar",
|
16
|
+
hbase_path+"/lib/commons-logging*.jar",
|
17
|
+
hbase_path+"/lib/zookeeper*.jar",
|
18
|
+
hbase_path+"/lib/log4j*.jar",
|
19
|
+
hbase_path+"/lib/hadoop*.jar"]
|
20
|
+
classpath = required_jars.join(":")
|
21
|
+
|
22
|
+
args.delete_at(switch_index)
|
23
|
+
args.delete_at(switch_index)
|
24
|
+
args = args + ["-c", '"'+classpath+'"']
|
25
|
+
|
26
|
+
# Otherwise we'll warn the user and quit
|
27
|
+
else
|
28
|
+
puts "Folder #{hbase_path} does not exist"
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
5
33
|
exec "bash", launcher, *args
|
data/conf/log4j.properties
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Define some default values that can be overridden by system properties
|
2
2
|
bigrecord.root.logger=INFO,DRFA
|
3
|
-
bigrecord.log.dir=/tmp/
|
3
|
+
bigrecord.log.dir=/tmp/bigrecord-driver/log
|
4
4
|
bigrecord.log.file=hbase.log
|
5
5
|
|
6
6
|
# Define the root logger to the system property "hbase.root.logger".
|
data/lib/big_record_driver.rb
CHANGED
data/lib/bigrecord_driver.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'big_record_driver'
|
1
|
+
require File.join(File.dirname(__FILE__), 'big_record_driver')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigrecord-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- openplaces.org
|
@@ -9,45 +9,37 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-04 00:00:00 -05:00
|
13
13
|
default_executable: hbase-driver
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Bigrecord drivers that use JRuby DRb servers to connect with databases through their native Java APIs. Currently supported
|
16
|
+
description: Bigrecord drivers that use JRuby DRb servers to connect with databases through their native Java APIs. Currently supported database is HBase.
|
17
17
|
email: bigrecord@openplaces.org
|
18
18
|
executables:
|
19
19
|
- hbase-driver
|
20
|
-
-
|
21
|
-
- launcher
|
20
|
+
- bigrecord-driver
|
22
21
|
extensions: []
|
23
22
|
|
24
23
|
extra_rdoc_files:
|
25
|
-
- MIT-LICENSE
|
26
24
|
- README.rdoc
|
27
25
|
files:
|
28
|
-
- MIT-LICENSE
|
29
26
|
- README.rdoc
|
30
27
|
- VERSION
|
31
|
-
- bin/
|
28
|
+
- bin/bigrecord-driver
|
32
29
|
- bin/hbase-driver
|
33
|
-
- bin/launcher
|
34
30
|
- conf/log4j.properties
|
35
31
|
- lib/big_record_driver.rb
|
36
32
|
- lib/big_record_driver/bigrecord_server.rb
|
37
|
-
- lib/big_record_driver/cassandra_driver/server.rb
|
38
33
|
- lib/big_record_driver/client.rb
|
39
34
|
- lib/big_record_driver/column_descriptor.rb
|
40
35
|
- lib/big_record_driver/driver_manager.rb
|
41
36
|
- lib/big_record_driver/exceptions.rb
|
42
37
|
- lib/big_record_driver/hbase_driver/server.rb
|
38
|
+
- lib/big_record_driver/version.rb
|
43
39
|
- lib/bigrecord_driver.rb
|
44
40
|
- test/abstract_test_client.rb
|
45
|
-
- test/test_client_cassandra.rb
|
46
41
|
- test/test_client_hbase.rb
|
47
42
|
- test/test_driver_manager.rb
|
48
|
-
- vendor/java/cassandra/cassandra-0.3.0-dev.jar
|
49
|
-
- vendor/java/cassandra/libthrift.jar
|
50
|
-
- vendor/java/cassandra/log4j-1.2.15.jar
|
51
43
|
- vendor/java/hbase/commons-logging-1.0.4.jar
|
52
44
|
- vendor/java/hbase/commons-logging-api-1.0.4.jar
|
53
45
|
- vendor/java/hbase/hadoop-0.20.1-hdfs127-core.jar
|
data/MIT-LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 openplaces.org
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
4
|
-
obtaining a copy of this software and associated documentation
|
5
|
-
files (the "Software"), to deal in the Software without
|
6
|
-
restriction, including without limitation the rights to use,
|
7
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
copies of the Software, and to permit persons to whom the
|
9
|
-
Software is furnished to do so, subject to the following
|
10
|
-
conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/cassandra-driver
DELETED
data/bin/launcher
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
#! /bin/bash
|
2
|
-
DRIVERNAME=$1
|
3
|
-
# Fix for Amazon EC2 instances
|
4
|
-
unset RUBYLIB
|
5
|
-
|
6
|
-
# Needs the $JRUBY_HOME environment variable to be set
|
7
|
-
if [ "$JRUBY_HOME" == "" ]; then
|
8
|
-
echo "\$JRUBY_HOME is not set. Please set it in your ~/.bashrc file."
|
9
|
-
exit 1
|
10
|
-
fi
|
11
|
-
|
12
|
-
VENDOR_DIR=`dirname "$0"`
|
13
|
-
VENDOR_DIR=`cd "$VENDOR_DIR/../vendor"; pwd`
|
14
|
-
|
15
|
-
CONF_DIR=`dirname "$0"`
|
16
|
-
CONF_DIR=`cd "$CONF_DIR/../conf"; pwd`
|
17
|
-
|
18
|
-
# Ruby file that contains the drb server
|
19
|
-
DRIVER=$VENDOR_DIR/../lib/big_record_driver/"$DRIVERNAME"_driver/server.rb
|
20
|
-
|
21
|
-
# location where the pids are stored
|
22
|
-
PIDS_DIR=/tmp/$DRIVERNAME-driver/run
|
23
|
-
mkdir -p $PIDS_DIR
|
24
|
-
|
25
|
-
# startup delay
|
26
|
-
STARTUP_TIMEOUT=60
|
27
|
-
|
28
|
-
# location where the log files are stored
|
29
|
-
LOGS_DIR=/tmp/$DRIVERNAME-driver/log
|
30
|
-
mkdir -p $LOGS_DIR
|
31
|
-
|
32
|
-
# set the environment to use jruby by default
|
33
|
-
PATH=$JRUBY_HOME/bin:$PATH
|
34
|
-
for f in $VENDOR_DIR/java/$DRIVERNAME/*.jar; do
|
35
|
-
if [ -f $f ]; then
|
36
|
-
CLASSPATH=${CLASSPATH}:$f;
|
37
|
-
fi
|
38
|
-
done
|
39
|
-
#CLASSPATH=$CLASSPATH:$VENDOR_DIR/java/hadoop-0.19.1-core.jar:$VENDOR_DIR/java/hbase-0.19.1.jar:$VENDOR_DIR/java/commons-logging-1.0.4.jar:$VENDOR_DIR/java/commons-logging-api-1.0.4.jar:$VENDOR_DIR/java/log4j-1.2.13.jar:$CONF_DIR/log4j.properties
|
40
|
-
|
41
|
-
export PATH CLASSPATH
|
42
|
-
|
43
|
-
# TODO: find a way to use the return value of this function instead of
|
44
|
-
# manipulating the global variable
|
45
|
-
PIDS=""
|
46
|
-
|
47
|
-
refresh_pids() {
|
48
|
-
if [ -f $PIDS_DIR/$PORT.pid ]; then
|
49
|
-
PID=`cat $PIDS_DIR/$PORT.pid`
|
50
|
-
else
|
51
|
-
PID=""
|
52
|
-
fi
|
53
|
-
}
|
54
|
-
|
55
|
-
start() {
|
56
|
-
echo -n "Starting $DRIVERNAME driver on port $PORT."
|
57
|
-
|
58
|
-
refresh_pids
|
59
|
-
|
60
|
-
if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
|
61
|
-
echo -e "\nAlready running (pid="$PID")."
|
62
|
-
exit 1
|
63
|
-
else
|
64
|
-
rm -f $LOGS_DIR/$PORT.log
|
65
|
-
nohup jruby $DRIVER $PORT >> $LOGS_DIR/$PORT.log 2>&1 < /dev/null &
|
66
|
-
PID=$!
|
67
|
-
if [ "$PID" != "" ] ; then
|
68
|
-
# monitor the log file for the message saying that the server is started
|
69
|
-
for ((i=0; i<$STARTUP_TIMEOUT; i+=1)); do
|
70
|
-
sleep 1
|
71
|
-
echo -n "."
|
72
|
-
if [ "$(cat $LOGS_DIR/$PORT.log | grep 'Started drb server')" != "" ] ; then
|
73
|
-
break
|
74
|
-
fi
|
75
|
-
done
|
76
|
-
|
77
|
-
if [ "$i" == $STARTUP_TIMEOUT ] ; then
|
78
|
-
echo -e "\nStartup timeout: couldn't start the DRb server."
|
79
|
-
else
|
80
|
-
echo $PID > $PIDS_DIR/$PORT.pid
|
81
|
-
fi
|
82
|
-
echo ""
|
83
|
-
else
|
84
|
-
echo -e "\nAn error occured while starting the DRb server."
|
85
|
-
fi
|
86
|
-
fi
|
87
|
-
}
|
88
|
-
|
89
|
-
stop() {
|
90
|
-
echo "Stopping $DRIVERNAME driver on port $PORT."
|
91
|
-
|
92
|
-
refresh_pids
|
93
|
-
|
94
|
-
if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
|
95
|
-
echo "Stopping driver (pid = $PID)." >> $LOGS_DIR/$PORT.log
|
96
|
-
kill $PID
|
97
|
-
rm $PIDS_DIR/$PORT.pid
|
98
|
-
else
|
99
|
-
echo "No $DRIVERNAME driver to kill."
|
100
|
-
fi
|
101
|
-
}
|
102
|
-
|
103
|
-
status() {
|
104
|
-
refresh_pids
|
105
|
-
|
106
|
-
if [ -f "$PIDS_DIR/$PORT.pid" -a "$PID" != "" ] ; then
|
107
|
-
echo "Running."
|
108
|
-
else
|
109
|
-
echo "Stopped."
|
110
|
-
fi
|
111
|
-
}
|
112
|
-
|
113
|
-
start_debug() {
|
114
|
-
jruby $DRIVER $PORT
|
115
|
-
}
|
116
|
-
|
117
|
-
print_usage() {
|
118
|
-
echo "Usage: $DRIVERNAME-driver {start|stop|restart|status|start_debug} [-p <port>]"
|
119
|
-
}
|
120
|
-
|
121
|
-
set_port() {
|
122
|
-
if [ "$3" == "-p" -a "$4" != "" ]; then
|
123
|
-
PORT="$4"
|
124
|
-
else
|
125
|
-
PORT=40000
|
126
|
-
fi
|
127
|
-
}
|
128
|
-
|
129
|
-
case "$2" in
|
130
|
-
start)
|
131
|
-
set_port $@
|
132
|
-
start
|
133
|
-
;;
|
134
|
-
stop)
|
135
|
-
set_port $@
|
136
|
-
stop
|
137
|
-
;;
|
138
|
-
restart)
|
139
|
-
set_port $@
|
140
|
-
stop
|
141
|
-
start
|
142
|
-
;;
|
143
|
-
status)
|
144
|
-
set_port $@
|
145
|
-
status
|
146
|
-
;;
|
147
|
-
start_debug)
|
148
|
-
set_port $@
|
149
|
-
start_debug
|
150
|
-
;;
|
151
|
-
*)
|
152
|
-
print_usage
|
153
|
-
exit 1
|
154
|
-
esac
|
155
|
-
exit 0
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../column_descriptor'
|
2
|
-
require File.dirname(__FILE__) + '/../exceptions'
|
3
|
-
require File.dirname(__FILE__) + '/../bigrecord_server'
|
4
|
-
|
5
|
-
module BigRecordDriver
|
6
|
-
class CassandraServer < BigRecordServer
|
7
|
-
include_class "org.apache.cassandra.service.Cassandra"
|
8
|
-
include_class "org.apache.cassandra.service.InvalidRequestException"
|
9
|
-
include_class "org.apache.cassandra.service.NotFoundException"
|
10
|
-
include_class "org.apache.cassandra.service.UnavailableException"
|
11
|
-
include_class "org.apache.cassandra.service.column_t"
|
12
|
-
include_class "org.apache.thrift.TException"
|
13
|
-
include_class "org.apache.thrift.protocol.TBinaryProtocol"
|
14
|
-
include_class "org.apache.thrift.transport.TSocket"
|
15
|
-
include_class "org.apache.thrift.transport.TTransport"
|
16
|
-
|
17
|
-
def configure(config = {})
|
18
|
-
config[:adr] ||= 'localhost'
|
19
|
-
config[:port] ||= 9160
|
20
|
-
@config = config
|
21
|
-
init_connection
|
22
|
-
end
|
23
|
-
|
24
|
-
def update(table_name, row, values, timestamp=nil)
|
25
|
-
safe_exec do
|
26
|
-
return nil unless row
|
27
|
-
timestamp = 0 unless timestamp
|
28
|
-
values.each do |column, value|
|
29
|
-
@cassandraClient.insert(table_name.to_s, row, column, value.to_bytes, timestamp, true)
|
30
|
-
end
|
31
|
-
row
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def get(table_name, row, column, options={})
|
36
|
-
safe_exec do
|
37
|
-
return nil unless row
|
38
|
-
# Retreive only the last version by default
|
39
|
-
options[:num_versions] ||= 1
|
40
|
-
|
41
|
-
# validate the arguments
|
42
|
-
raise ArgumentError, "num_versions must be >= 1" unless options[:num_versions] >= 1
|
43
|
-
begin
|
44
|
-
if options[:timestamp]
|
45
|
-
raw_data = @cassandraClient.get_columns_since(table_name.to_s, row, column, options[:timestamp])
|
46
|
-
else
|
47
|
-
raw_data = @cassandraClient.get_column(table_name.to_s, row, column)
|
48
|
-
end
|
49
|
-
rescue NotFoundException => e2
|
50
|
-
puts e2.message
|
51
|
-
puts e2.class
|
52
|
-
end
|
53
|
-
# Return either a single value or an array, depending on the number of version that have been requested
|
54
|
-
if options[:timestamp]
|
55
|
-
return [] unless raw_data
|
56
|
-
max_index = raw_data.length > options[:num_versions] || raw_data.length
|
57
|
-
0..max_index.each do |i|
|
58
|
-
arr[i] = Java::String.new(raw_data[i].value).to_s
|
59
|
-
end
|
60
|
-
arr
|
61
|
-
else
|
62
|
-
return nil unless raw_data
|
63
|
-
Java::String.new(raw_data.value).to_s
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def get_columns(table_name, row, columns, options={})
|
69
|
-
safe_exec do
|
70
|
-
return nil unless row
|
71
|
-
raise ArgumentError, "timestamp on get_columns is not currently supported with cassandra" if options[:timestamp]
|
72
|
-
arr = []
|
73
|
-
columns.each_with_index do |col, i|
|
74
|
-
begin
|
75
|
-
if col[-1,1] == ':'
|
76
|
-
arr + @cassandraClient.get_slice(table_name.to_s, row, col, -1, -1).to_a
|
77
|
-
else
|
78
|
-
arr + @cassandraClient.get_column(table_name.to_s, row, col)
|
79
|
-
end
|
80
|
-
rescue NotFoundException => e2
|
81
|
-
puts e2.message
|
82
|
-
puts e2.class
|
83
|
-
end
|
84
|
-
end
|
85
|
-
unless !result or result.isEmpty
|
86
|
-
values = {}
|
87
|
-
arr.each do |column_t|
|
88
|
-
values[column_t.getColumnName.to_s] = Java::String.new(column_t.value).to_s
|
89
|
-
end
|
90
|
-
values["attribute:id"] = row
|
91
|
-
values
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
## It's currently impossible to have compliant delete with cassandra,
|
98
|
-
## you would have to do it famiyl by family
|
99
|
-
# def delete(table_name, row)
|
100
|
-
# safe_exec do
|
101
|
-
# table.remove(table_name, row, ??, ??, true)
|
102
|
-
# end
|
103
|
-
# end
|
104
|
-
|
105
|
-
def ping
|
106
|
-
safe_exec do
|
107
|
-
@socket.isOpen
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def table_names
|
112
|
-
safe_exec do
|
113
|
-
@cassandraClient.getStringListProperty("tables") #.collect{|td| Java::String.new(td.getName).to_s}
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def table_exists?(table_name)
|
118
|
-
!@cassandraClient.describeTable(table_name.to_s).include?("not found.")
|
119
|
-
end
|
120
|
-
|
121
|
-
private
|
122
|
-
def init_connection
|
123
|
-
@socket = TSocket.new(@config[:adr], @config[:port]);
|
124
|
-
binary_protocol = TBinaryProtocol.new(@socket, false, false);
|
125
|
-
@cassandraClient = Cassandra::Client.new(binary_protocol);
|
126
|
-
@socket.open;
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
port = ARGV[0]
|
132
|
-
port ||= 45000
|
133
|
-
DRb.start_service("druby://:#{port}", BigRecordDriver::CassandraServer.new)
|
134
|
-
puts "Started drb server on port #{port}."
|
135
|
-
DRb.thread.join
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_test_client'
|
2
|
-
|
3
|
-
class TestCassandraClient < Test::Unit::TestCase
|
4
|
-
include AbstractTestClient
|
5
|
-
|
6
|
-
def setup
|
7
|
-
unless @big_db
|
8
|
-
BigRecordDriver::DriverManager.set_cmd('cassandra')
|
9
|
-
unless BigRecordDriver::DriverManager.running?(40005)
|
10
|
-
BigRecordDriver::DriverManager.restart(40005)
|
11
|
-
end
|
12
|
-
#TODO: don't use hard coded values for the config
|
13
|
-
@big_db = BigRecordDriver::Client.new(:drb_port => 40005)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_update_without_timestamps
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_update_with_timestamps_in_chronological_order
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_update_with_timestamps_in_reverse_chronological_order
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_get_and_get_columns
|
28
|
-
t1 = Time.now.to_i
|
29
|
-
t2 = t1 + 1000
|
30
|
-
t3 = t2 + 1000
|
31
|
-
# Temporary copy-paste until all tests passes
|
32
|
-
@big_db.update(TABLE_NAME,
|
33
|
-
'dog-key',
|
34
|
-
{'columnfamily1:name' => 'Dog',
|
35
|
-
'columnfamily1:size' => 'medium',
|
36
|
-
'columnfamily2:toto' => 'some value1'},
|
37
|
-
t1)
|
38
|
-
|
39
|
-
@big_db.update(TABLE_NAME,
|
40
|
-
'dog-key',
|
41
|
-
{'columnfamily1:size' => 'small',
|
42
|
-
'columnfamily2:toto' => 'some value2'},
|
43
|
-
t2)
|
44
|
-
|
45
|
-
@big_db.update(TABLE_NAME,
|
46
|
-
'dog-key',
|
47
|
-
{'columnfamily1:size' => 'big'},
|
48
|
-
t3)
|
49
|
-
|
50
|
-
# normal calls
|
51
|
-
assert_equal 'big', @big_db.get(TABLE_NAME, 'dog-key', 'columnfamily1:size'), "Didn't retrieved the last version of the cell"
|
52
|
-
assert_nil @big_db.get(TABLE_NAME, 'dog-key-that-does-not-exist', 'columnfamily1:size'), "Got a value for a cell that doesn't even exist"
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_get_consecutive_rows
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_delete
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_invalid_column_family
|
62
|
-
end
|
63
|
-
end
|
Binary file
|
Binary file
|
Binary file
|