flockdb 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +28 -0
- data/Rakefile +1 -20
- data/flockdb.gemspec +19 -75
- data/lib/flock.rb +17 -19
- data/lib/flock/client.rb +26 -18
- data/lib/flock/gen-rb/flock_d_b.rb +126 -0
- data/lib/flock/gen-rb/flockdb_types.rb +22 -0
- data/lib/flock/mixins/sizeable.rb +2 -6
- data/lib/flock/mock_service.rb +139 -74
- data/lib/flock/operations/execute_operation.rb +1 -1
- data/lib/flock/operations/execute_operations.rb +6 -1
- data/lib/flock/operations/query_term.rb +51 -7
- data/lib/flock/operations/select_operation.rb +0 -1
- data/lib/flock/operations/select_operations.rb +97 -0
- data/lib/flock/operations/simple_operation.rb +17 -2
- data/lib/flock/service.rb +1 -1
- data/lib/flock/version.rb +3 -0
- data/spec/execute_operations_spec.rb +4 -5
- data/spec/flock_spec.rb +114 -0
- data/spec/query_term_spec.rb +14 -2
- data/spec/simple_operation_spec.rb +2 -3
- data/spec/spec_helper.rb +1 -1
- metadata +68 -16
- data/VERSION +0 -1
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flockdb (0.6.1)
|
5
|
+
thrift (>= 0.5.0)
|
6
|
+
thrift_client (>= 0.6.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.1.2)
|
12
|
+
rake (0.8.7)
|
13
|
+
rr (1.0.2)
|
14
|
+
rspec (1.3.2)
|
15
|
+
thrift (0.6.0)
|
16
|
+
thrift_client (0.6.2)
|
17
|
+
thrift (~> 0.6.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler (~> 1.0.10)
|
24
|
+
diff-lcs
|
25
|
+
flockdb!
|
26
|
+
rake (= 0.8.7)
|
27
|
+
rr
|
28
|
+
rspec (~> 1.3.0)
|
data/Rakefile
CHANGED
@@ -12,23 +12,4 @@ Spec::Rake::SpecTask.new(:spec) do |t|
|
|
12
12
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
begin
|
17
|
-
require 'jeweler'
|
18
|
-
Jeweler::Tasks.new do |gemspec|
|
19
|
-
gemspec.name = "flockdb"
|
20
|
-
gemspec.summary = "Ruby Flock client"
|
21
|
-
gemspec.description = "Get your flock on in Ruby."
|
22
|
-
gemspec.email = "freels@twitter.com"
|
23
|
-
gemspec.homepage = "http://github.com/twitter/flockdb-client"
|
24
|
-
gemspec.authors = ["Matt Freels", "Rael Dornfest", "Nick Kallen"]
|
25
|
-
gemspec.add_dependency 'thrift', '>= 0.5.0'
|
26
|
-
gemspec.add_dependency 'thrift_client', '>= 0.6.0'
|
27
|
-
|
28
|
-
# development
|
29
|
-
gemspec.add_development_dependency 'rspec'
|
30
|
-
gemspec.add_development_dependency 'rr'
|
31
|
-
end
|
32
|
-
rescue LoadError
|
33
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
34
|
-
end
|
15
|
+
require 'bundler/gem_tasks'
|
data/flockdb.gemspec
CHANGED
@@ -1,87 +1,31 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
|
-
|
7
|
-
s.name = %q{flockdb}
|
8
|
-
s.version = "0.6.1"
|
3
|
+
require File.join(File.dirname(__FILE__), 'lib', 'flock', 'version')
|
9
4
|
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'flockdb'
|
7
|
+
s.version = Flock::VERSION
|
10
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
9
|
s.authors = ["Matt Freels", "Rael Dornfest", "Nick Kallen"]
|
12
|
-
s.
|
13
|
-
s.description =
|
10
|
+
s.summary = "Get your flock on in Ruby"
|
11
|
+
s.description = "Get your flock on in Ruby."
|
14
12
|
s.email = %q{freels@twitter.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
|
17
|
-
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"LICENSE",
|
22
|
-
"README.md",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"flockdb.gemspec",
|
26
|
-
"lib/flock.rb",
|
27
|
-
"lib/flock/client.rb",
|
28
|
-
"lib/flock/gen-rb/flock_d_b.rb",
|
29
|
-
"lib/flock/gen-rb/flockdb_constants.rb",
|
30
|
-
"lib/flock/gen-rb/flockdb_types.rb",
|
31
|
-
"lib/flock/mixins/sizeable.rb",
|
32
|
-
"lib/flock/mock_service.rb",
|
33
|
-
"lib/flock/operation.rb",
|
34
|
-
"lib/flock/operations/complex_operation.rb",
|
35
|
-
"lib/flock/operations/execute_operation.rb",
|
36
|
-
"lib/flock/operations/execute_operations.rb",
|
37
|
-
"lib/flock/operations/query_term.rb",
|
38
|
-
"lib/flock/operations/select_operation.rb",
|
39
|
-
"lib/flock/operations/simple_operation.rb",
|
40
|
-
"lib/flock/service.rb",
|
41
|
-
"lib/flock/thrift.rb",
|
42
|
-
"lib/flockdb.rb",
|
43
|
-
"spec/execute_operations_spec.rb",
|
44
|
-
"spec/flock_spec.rb",
|
45
|
-
"spec/mock_service_spec.rb",
|
46
|
-
"spec/query_term_spec.rb",
|
47
|
-
"spec/simple_operation_spec.rb",
|
48
|
-
"spec/spec.opts",
|
49
|
-
"spec/spec_helper.rb"
|
50
|
-
]
|
51
|
-
s.homepage = %q{http://github.com/twitter/flockdb-client}
|
13
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.homepage = %q{http://github.com/twitter/flock-client}
|
52
16
|
s.rdoc_options = ["--charset=UTF-8"]
|
53
17
|
s.require_paths = ["lib"]
|
54
18
|
s.rubygems_version = %q{1.3.7}
|
55
|
-
s.
|
56
|
-
s.
|
57
|
-
"spec/execute_operations_spec.rb",
|
58
|
-
"spec/flock_spec.rb",
|
59
|
-
"spec/mock_service_spec.rb",
|
60
|
-
"spec/query_term_spec.rb",
|
61
|
-
"spec/simple_operation_spec.rb",
|
62
|
-
"spec/spec_helper.rb"
|
63
|
-
]
|
64
|
-
|
65
|
-
if s.respond_to? :specification_version then
|
66
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
-
s.specification_version = 3
|
19
|
+
s.test_files = `git ls-files`.split("\n").select{|f| f =~ /^spec/}
|
20
|
+
s.rubyforge_project = 'flock-client'
|
68
21
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
78
|
-
s.add_dependency(%q<rr>, [">= 0"])
|
79
|
-
end
|
80
|
-
else
|
81
|
-
s.add_dependency(%q<thrift>, [">= 0.5.0"])
|
82
|
-
s.add_dependency(%q<thrift_client>, [">= 0.6.0"])
|
83
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
84
|
-
s.add_dependency(%q<rr>, [">= 0"])
|
85
|
-
end
|
22
|
+
# dependencies
|
23
|
+
s.add_dependency 'thrift', '>= 0.5.0'
|
24
|
+
s.add_dependency 'thrift_client', '>= 0.6.0'
|
25
|
+
s.add_development_dependency 'bundler', '~> 1.0.10'
|
26
|
+
s.add_development_dependency 'rake', '= 0.8.7'
|
27
|
+
s.add_development_dependency 'rspec', '~> 1.3.0'
|
28
|
+
s.add_development_dependency 'diff-lcs'
|
29
|
+
s.add_development_dependency 'rr'
|
86
30
|
end
|
87
31
|
|
data/lib/flock.rb
CHANGED
@@ -5,26 +5,24 @@ require 'thrift_client'
|
|
5
5
|
require 'flock/mixins/sizeable'
|
6
6
|
|
7
7
|
# thrift sources. load order is important.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
require 'flock/thrift'
|
15
|
-
|
16
|
-
require 'flock/operation'
|
17
|
-
require 'flock/operations/query_term'
|
18
|
-
require 'flock/operations/select_operation'
|
19
|
-
require 'flock/operations/complex_operation'
|
20
|
-
require 'flock/operations/simple_operation'
|
21
|
-
require 'flock/operations/execute_operation'
|
22
|
-
require 'flock/operations/execute_operations'
|
23
|
-
require 'flock/service'
|
24
|
-
require 'flock/client'
|
8
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'flock', 'gen-rb')
|
9
|
+
|
10
|
+
require 'flockdb_types'
|
11
|
+
require 'flockdb_constants'
|
12
|
+
require 'flock_d_b'
|
25
13
|
|
26
14
|
module Flock
|
27
|
-
autoload :MockService,
|
15
|
+
autoload :MockService, 'flock/mock_service'
|
16
|
+
autoload :Operation, 'flock/operation'
|
17
|
+
autoload :QueryTerm, 'flock/operations/query_term'
|
18
|
+
autoload :SelectOperation, 'flock/operations/select_operation'
|
19
|
+
autoload :ComplexOperation, 'flock/operations/complex_operation'
|
20
|
+
autoload :SimpleOperation, 'flock/operations/simple_operation'
|
21
|
+
autoload :ExecuteOperation, 'flock/operations/execute_operation'
|
22
|
+
autoload :ExecuteOperations, 'flock/operations/execute_operations'
|
23
|
+
autoload :SelectOperations, 'flock/operations/select_operations'
|
24
|
+
autoload :Service, 'flock/service'
|
25
|
+
autoload :Client, 'flock/client'
|
28
26
|
|
29
27
|
FlockException = Edges::FlockException
|
30
28
|
Priority = Edges::Priority
|
@@ -41,7 +39,7 @@ module Flock
|
|
41
39
|
|
42
40
|
class UnknownStateError < FlockException
|
43
41
|
def initialize(state)
|
44
|
-
super("Unable to look up id for state #{state.inspect}. Valid states are #{ Flock::
|
42
|
+
super("Unable to look up id for state #{state.inspect}. Valid states are #{ Flock::QueryTerm::STATES.keys.map{|s| s.inspect }.join(', ') }")
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
data/lib/flock/client.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
class Flock::Client
|
2
2
|
|
3
|
-
# symbol => state_id map
|
4
|
-
STATES = Flock::Edges::EdgeState::VALUE_MAP.inject({}) do |states, (id, name)|
|
5
|
-
states.update name.downcase.to_sym => id
|
6
|
-
end.freeze
|
7
|
-
|
8
3
|
attr_accessor :graphs
|
9
4
|
attr_reader :service
|
10
5
|
|
@@ -15,6 +10,7 @@ class Flock::Client
|
|
15
10
|
# takes arguments a list of servers and an options hash to pass to the default service_class,
|
16
11
|
# or a service itself
|
17
12
|
def initialize(servers = nil, options = {})
|
13
|
+
options = options.dup
|
18
14
|
if graphs = (options.delete(:graphs) || Flock.graphs)
|
19
15
|
@graphs = graphs
|
20
16
|
end
|
@@ -46,15 +42,27 @@ class Flock::Client
|
|
46
42
|
@cache = {} if @cache
|
47
43
|
end
|
48
44
|
|
49
|
-
|
50
45
|
# queries
|
51
46
|
|
47
|
+
def multi(&block)
|
48
|
+
select_operations = Flock::SelectOperations.new(self)
|
49
|
+
yield select_operations
|
50
|
+
select_operations
|
51
|
+
end
|
52
|
+
|
52
53
|
def select(*query)
|
53
|
-
|
54
|
+
query = query.first if query.size == 1 # supports deprecated API [[1, 2, 3]]
|
55
|
+
Flock::SimpleOperation.new(self, Flock::QueryTerm.new(query, graphs))
|
56
|
+
end
|
57
|
+
|
58
|
+
def get(source, graph, destination)
|
59
|
+
raise ArgumentError unless source.is_a?(Fixnum) && destination.is_a?(Fixnum)
|
60
|
+
|
61
|
+
select(source, graph, destination, [:positive, :removed, :negative, :archived]).edges.paginate(1).current_page.first
|
54
62
|
end
|
55
63
|
|
56
64
|
def contains(*query)
|
57
|
-
query =
|
65
|
+
query = Flock::QueryTerm.new(query, graphs).unapply[0, 3]
|
58
66
|
_cache :contains, query do
|
59
67
|
service.contains(*query)
|
60
68
|
end
|
@@ -70,9 +78,8 @@ class Flock::Client
|
|
70
78
|
|
71
79
|
# edge manipulation
|
72
80
|
|
73
|
-
def update(method, source_id, graph, destination_id,
|
74
|
-
execute_at =
|
75
|
-
position = options.delete(:position)
|
81
|
+
def update(method, source_id, graph, destination_id, *args)
|
82
|
+
priority, execute_at, position = process_args(args)
|
76
83
|
|
77
84
|
_cache_clear
|
78
85
|
ops = current_transaction || Flock::ExecuteOperations.new(@service, priority, execute_at)
|
@@ -87,10 +94,8 @@ class Flock::Client
|
|
87
94
|
|
88
95
|
alias unarchive add
|
89
96
|
|
90
|
-
def transaction(
|
91
|
-
execute_at =
|
92
|
-
position = options.delete(:position)
|
93
|
-
|
97
|
+
def transaction(*args, &block)
|
98
|
+
priority, execute_at, _ = process_args(args)
|
94
99
|
new_transaction = !in_transaction?
|
95
100
|
|
96
101
|
ops =
|
@@ -116,9 +121,7 @@ class Flock::Client
|
|
116
121
|
!!Thread.current[:edge_transaction]
|
117
122
|
end
|
118
123
|
|
119
|
-
|
120
|
-
# graph name lookup utility methods
|
121
|
-
|
124
|
+
private
|
122
125
|
def _lookup_graph(key)
|
123
126
|
if @graphs.nil? or key.is_a? Integer
|
124
127
|
key
|
@@ -146,4 +149,9 @@ class Flock::Client
|
|
146
149
|
return node.map {|n| n.to_i if n } if node.respond_to? :map
|
147
150
|
node.to_i if node
|
148
151
|
end
|
152
|
+
|
153
|
+
def process_args(args)
|
154
|
+
options = args.last.is_a?(Hash) ? args.pop : nil
|
155
|
+
[args.first || Flock::Priority::High, options && options[:execute_at], options && options[:position]]
|
156
|
+
end
|
149
157
|
end
|
@@ -45,6 +45,38 @@ require 'flockdb_types'
|
|
45
45
|
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'get failed: unknown result')
|
46
46
|
end
|
47
47
|
|
48
|
+
def get_metadata(source_id, graph_id)
|
49
|
+
send_get_metadata(source_id, graph_id)
|
50
|
+
return recv_get_metadata()
|
51
|
+
end
|
52
|
+
|
53
|
+
def send_get_metadata(source_id, graph_id)
|
54
|
+
send_message('get_metadata', Get_metadata_args, :source_id => source_id, :graph_id => graph_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
def recv_get_metadata()
|
58
|
+
result = receive_message(Get_metadata_result)
|
59
|
+
return result.success unless result.success.nil?
|
60
|
+
raise result.ex unless result.ex.nil?
|
61
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'get_metadata failed: unknown result')
|
62
|
+
end
|
63
|
+
|
64
|
+
def contains_metadata(source_id, graph_id)
|
65
|
+
send_contains_metadata(source_id, graph_id)
|
66
|
+
return recv_contains_metadata()
|
67
|
+
end
|
68
|
+
|
69
|
+
def send_contains_metadata(source_id, graph_id)
|
70
|
+
send_message('contains_metadata', Contains_metadata_args, :source_id => source_id, :graph_id => graph_id)
|
71
|
+
end
|
72
|
+
|
73
|
+
def recv_contains_metadata()
|
74
|
+
result = receive_message(Contains_metadata_result)
|
75
|
+
return result.success unless result.success.nil?
|
76
|
+
raise result.ex unless result.ex.nil?
|
77
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'contains_metadata failed: unknown result')
|
78
|
+
end
|
79
|
+
|
48
80
|
def select2(queries)
|
49
81
|
send_select2(queries)
|
50
82
|
return recv_select2()
|
@@ -167,6 +199,28 @@ require 'flockdb_types'
|
|
167
199
|
write_result(result, oprot, 'get', seqid)
|
168
200
|
end
|
169
201
|
|
202
|
+
def process_get_metadata(seqid, iprot, oprot)
|
203
|
+
args = read_args(iprot, Get_metadata_args)
|
204
|
+
result = Get_metadata_result.new()
|
205
|
+
begin
|
206
|
+
result.success = @handler.get_metadata(args.source_id, args.graph_id)
|
207
|
+
rescue Flock::Edges::FlockException => ex
|
208
|
+
result.ex = ex
|
209
|
+
end
|
210
|
+
write_result(result, oprot, 'get_metadata', seqid)
|
211
|
+
end
|
212
|
+
|
213
|
+
def process_contains_metadata(seqid, iprot, oprot)
|
214
|
+
args = read_args(iprot, Contains_metadata_args)
|
215
|
+
result = Contains_metadata_result.new()
|
216
|
+
begin
|
217
|
+
result.success = @handler.contains_metadata(args.source_id, args.graph_id)
|
218
|
+
rescue Flock::Edges::FlockException => ex
|
219
|
+
result.ex = ex
|
220
|
+
end
|
221
|
+
write_result(result, oprot, 'contains_metadata', seqid)
|
222
|
+
end
|
223
|
+
|
170
224
|
def process_select2(seqid, iprot, oprot)
|
171
225
|
args = read_args(iprot, Select2_args)
|
172
226
|
result = Select2_result.new()
|
@@ -313,6 +367,78 @@ require 'flockdb_types'
|
|
313
367
|
::Thrift::Struct.generate_accessors self
|
314
368
|
end
|
315
369
|
|
370
|
+
class Get_metadata_args
|
371
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
372
|
+
SOURCE_ID = 1
|
373
|
+
GRAPH_ID = 2
|
374
|
+
|
375
|
+
FIELDS = {
|
376
|
+
SOURCE_ID => {:type => ::Thrift::Types::I64, :name => 'source_id'},
|
377
|
+
GRAPH_ID => {:type => ::Thrift::Types::I32, :name => 'graph_id'}
|
378
|
+
}
|
379
|
+
|
380
|
+
def struct_fields; FIELDS; end
|
381
|
+
|
382
|
+
def validate
|
383
|
+
end
|
384
|
+
|
385
|
+
::Thrift::Struct.generate_accessors self
|
386
|
+
end
|
387
|
+
|
388
|
+
class Get_metadata_result
|
389
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
390
|
+
SUCCESS = 0
|
391
|
+
EX = 1
|
392
|
+
|
393
|
+
FIELDS = {
|
394
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => Flock::Edges::Metadata},
|
395
|
+
EX => {:type => ::Thrift::Types::STRUCT, :name => 'ex', :class => Flock::Edges::FlockException}
|
396
|
+
}
|
397
|
+
|
398
|
+
def struct_fields; FIELDS; end
|
399
|
+
|
400
|
+
def validate
|
401
|
+
end
|
402
|
+
|
403
|
+
::Thrift::Struct.generate_accessors self
|
404
|
+
end
|
405
|
+
|
406
|
+
class Contains_metadata_args
|
407
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
408
|
+
SOURCE_ID = 1
|
409
|
+
GRAPH_ID = 2
|
410
|
+
|
411
|
+
FIELDS = {
|
412
|
+
SOURCE_ID => {:type => ::Thrift::Types::I64, :name => 'source_id'},
|
413
|
+
GRAPH_ID => {:type => ::Thrift::Types::I32, :name => 'graph_id'}
|
414
|
+
}
|
415
|
+
|
416
|
+
def struct_fields; FIELDS; end
|
417
|
+
|
418
|
+
def validate
|
419
|
+
end
|
420
|
+
|
421
|
+
::Thrift::Struct.generate_accessors self
|
422
|
+
end
|
423
|
+
|
424
|
+
class Contains_metadata_result
|
425
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
426
|
+
SUCCESS = 0
|
427
|
+
EX = 1
|
428
|
+
|
429
|
+
FIELDS = {
|
430
|
+
SUCCESS => {:type => ::Thrift::Types::BOOL, :name => 'success'},
|
431
|
+
EX => {:type => ::Thrift::Types::STRUCT, :name => 'ex', :class => Flock::Edges::FlockException}
|
432
|
+
}
|
433
|
+
|
434
|
+
def struct_fields; FIELDS; end
|
435
|
+
|
436
|
+
def validate
|
437
|
+
end
|
438
|
+
|
439
|
+
::Thrift::Struct.generate_accessors self
|
440
|
+
end
|
441
|
+
|
316
442
|
class Select2_args
|
317
443
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
318
444
|
QUERIES = 1
|