tem_mr_search 0.2.5 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +6 -7
- data/Rakefile +3 -1
- data/lib/tem_mr_search/client.rb +24 -1
- data/lib/tem_mr_search/map_reduce_executor.rb +20 -3
- data/lib/tem_mr_search/map_reduce_job.rb +24 -3
- data/lib/tem_mr_search/server.rb +8 -5
- data/tem_mr_search.gemspec +14 -8
- data/test/test_client_server.rb +18 -0
- data/test/test_map_reduce_executor.rb +1 -0
- metadata +36 -16
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
bin/tem_mr_search_server
|
2
1
|
CHANGELOG
|
2
|
+
LICENSE
|
3
|
+
Manifest
|
4
|
+
README
|
5
|
+
Rakefile
|
6
|
+
bin/tem_mr_search_server
|
7
|
+
lib/tem_mr_search.rb
|
3
8
|
lib/tem_mr_search/client.rb
|
4
9
|
lib/tem_mr_search/client_query.rb
|
5
10
|
lib/tem_mr_search/db.rb
|
@@ -9,12 +14,6 @@ lib/tem_mr_search/map_reduce_planner.rb
|
|
9
14
|
lib/tem_mr_search/query_builder.rb
|
10
15
|
lib/tem_mr_search/server.rb
|
11
16
|
lib/tem_mr_search/web_client_query_builder.rb
|
12
|
-
lib/tem_mr_search.rb
|
13
|
-
LICENSE
|
14
|
-
Manifest
|
15
|
-
Rakefile
|
16
|
-
README
|
17
|
-
tem_mr_search.gemspec
|
18
17
|
test/mr_test_case.rb
|
19
18
|
test/test_client_server.rb
|
20
19
|
test/test_db.rb
|
data/Rakefile
CHANGED
@@ -16,7 +16,9 @@ Echoe.new('tem_mr_search') do |p|
|
|
16
16
|
p.email = 'victor@costan.us'
|
17
17
|
p.summary = 'Tem Map-Reduce proof of concept: database search.'
|
18
18
|
p.url = 'http://tem.rubyforge.org'
|
19
|
-
p.dependencies = ['tem_ruby >=0.
|
19
|
+
p.dependencies = ['tem_ruby >=0.15.2', 'tem_multi_proxy >=0.2.7']
|
20
|
+
p.development_dependencies = ["echoe >=3.2",
|
21
|
+
"flexmock >=0.8.6"]
|
20
22
|
|
21
23
|
p.need_tar_gz = !Gem.win_platform?
|
22
24
|
p.need_zip = !Gem.win_platform?
|
data/lib/tem_mr_search/client.rb
CHANGED
@@ -13,6 +13,24 @@ class Client
|
|
13
13
|
OP = Zerg::Support::Protocols::ObjectProtocol
|
14
14
|
OPAdapter = Zerg::Support::Sockets::ProtocolAdapter.adapter_module OP
|
15
15
|
|
16
|
+
# Requests information for a random TEM to be used as a query's root TEM.
|
17
|
+
#
|
18
|
+
# Args:
|
19
|
+
# server_addr:: string with the address of the Map-Reduce server's RPC port.
|
20
|
+
#
|
21
|
+
# Returns a hash with the following keys:
|
22
|
+
# :id:: the TEM's ID (to be used as the :root_tem argument in search calls)
|
23
|
+
# :ecert:: the TEM's Endorsement Certificate
|
24
|
+
# :pubek:: the TEM's public Endorsement Key (from the ECert)
|
25
|
+
def self.get_tem(server_addr)
|
26
|
+
output = issue_request server_addr, :type => :get_tem
|
27
|
+
return nil unless output
|
28
|
+
|
29
|
+
ecert = OpenSSL::X509::Certificate.new output[:ecert]
|
30
|
+
pubek = Tem::Key.new_from_ssl_key ecert.public_key
|
31
|
+
{ :id => output[:id], :ecert => ecert, :pubek => pubek }
|
32
|
+
end
|
33
|
+
|
16
34
|
# Performs a private database search using a Map-Reduce.
|
17
35
|
#
|
18
36
|
# Args:
|
@@ -21,7 +39,12 @@ class Client
|
|
21
39
|
#
|
22
40
|
# Returns the result of the Map-Reduce computation.
|
23
41
|
def self.search(server_addr, client_query)
|
24
|
-
|
42
|
+
tem_info = get_tem server_addr
|
43
|
+
# TODO: check the endorsement certificate.
|
44
|
+
client_query.bind tem_info[:pubek]
|
45
|
+
|
46
|
+
output = issue_request server_addr, :type => :search,
|
47
|
+
:root_tem => tem_info[:id],
|
25
48
|
:map_reduce => client_query.to_hash
|
26
49
|
output ? client_query.unpack_output(output) : nil
|
27
50
|
end
|
@@ -30,9 +30,12 @@ class MapReduceExecutor
|
|
30
30
|
|
31
31
|
@db = db # Writable only in main thread.
|
32
32
|
@tems = tems # Writable only in main thread.
|
33
|
+
|
34
|
+
# Protected by @lock during collect_tem_ids, read-only during execute.
|
35
|
+
@tem_certs = Array.new @tems.length
|
33
36
|
|
34
37
|
# Writable only in main thread.
|
35
|
-
@planner = planner_class.new
|
38
|
+
@planner = planner_class.new job, db.length, tems.length, root_tem
|
36
39
|
|
37
40
|
# Protected by @lock
|
38
41
|
@tem_parts = { :mapper => { root_tem => job.mapper },
|
@@ -49,6 +52,8 @@ class MapReduceExecutor
|
|
49
52
|
|
50
53
|
# Executes the job.
|
51
54
|
def execute
|
55
|
+
collect_tem_ids
|
56
|
+
|
52
57
|
# Spawn TEM threads.
|
53
58
|
@tems.each_index { |i| Thread.new(i) { |i| executor_thread i } }
|
54
59
|
|
@@ -64,7 +69,18 @@ class MapReduceExecutor
|
|
64
69
|
|
65
70
|
return @outputs[@planner.output_id]
|
66
71
|
end
|
67
|
-
|
72
|
+
|
73
|
+
# Collects identification information from all the TEMs.
|
74
|
+
def collect_tem_ids
|
75
|
+
threads = (0...@tems.length).map do |tem_index|
|
76
|
+
Thread.new(tem_index, @tems[tem_index]) do |index, tem|
|
77
|
+
ecert = tem.endorsement_cert
|
78
|
+
@lock.synchronize { @tem_certs[index] = ecert }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
threads.each { |thread| thread.join }
|
82
|
+
end
|
83
|
+
|
68
84
|
# Main method for thread in charge of a TEM.
|
69
85
|
def executor_thread(tem_index)
|
70
86
|
queue = @thread_queues[tem_index]
|
@@ -83,7 +99,8 @@ class MapReduceExecutor
|
|
83
99
|
case action[:action]
|
84
100
|
when :migrate
|
85
101
|
in_part = @lock.synchronize { @tem_parts[action[:secpack]][tem_index] }
|
86
|
-
|
102
|
+
target_ecert = @tem_certs[action[:to]]
|
103
|
+
out_part = in_part.migrate target_ecert, @tems[tem_index]
|
87
104
|
@lock.synchronize do
|
88
105
|
@tem_parts[action[:secpack]][action[:to]] = out_part
|
89
106
|
end
|
@@ -47,6 +47,11 @@ class MapReduceJob
|
|
47
47
|
:map => @mapper.to_plain_object, :reduce => @reducer.to_plain_object,
|
48
48
|
:finalize => @finalizer.to_plain_object }
|
49
49
|
end
|
50
|
+
|
51
|
+
# Binds the SECpacks in this job to the given key.
|
52
|
+
def bind(tem_pubek)
|
53
|
+
[@mapper, @reducer, @finalizer].each { |part| part.bind tem_pubek }
|
54
|
+
end
|
50
55
|
|
51
56
|
# Base class for the Map-Reduce SECpack wrappers.
|
52
57
|
class JobPart
|
@@ -54,7 +59,23 @@ class MapReduceJob
|
|
54
59
|
unless secpack.nil? or secpack.kind_of? Tem::SecPack
|
55
60
|
secpack = Tem::SecPack.new_from_array secpack
|
56
61
|
end
|
57
|
-
@
|
62
|
+
@job = job
|
63
|
+
@secpack = secpack
|
64
|
+
end
|
65
|
+
|
66
|
+
# Binds the wrapped SECpack to the given key.
|
67
|
+
def bind(tem_pubek)
|
68
|
+
@secpack.bind tem_pubek, :_secret, :_plain if @secpack
|
69
|
+
end
|
70
|
+
|
71
|
+
# Creates a copy of the job part by migrating the wrapped SECpack.
|
72
|
+
#
|
73
|
+
# Args:
|
74
|
+
# target_ecert:: the Endorsement Certificate of the target TEM
|
75
|
+
# tem:: session to the TEM to be used for migration
|
76
|
+
def migrate(target_ecert, tem)
|
77
|
+
migrated_secpack = tem.migrate @secpack, target_ecert
|
78
|
+
self.class.new migrated_secpack, @job
|
58
79
|
end
|
59
80
|
|
60
81
|
def to_plain_object
|
@@ -71,7 +92,7 @@ class MapReduceJob
|
|
71
92
|
@id_attribute = job.id_attribute
|
72
93
|
end
|
73
94
|
|
74
|
-
#
|
95
|
+
# SECpack for mapping the given object data into the query.
|
75
96
|
def map_for_object(object_data)
|
76
97
|
return nil unless @secpack
|
77
98
|
object_id = object_data[@id_attribute.to_s]
|
@@ -93,7 +114,7 @@ class MapReduceJob
|
|
93
114
|
|
94
115
|
# Wrapper for the reduce SECpack.
|
95
116
|
class Reducer < JobPart
|
96
|
-
#
|
117
|
+
# SECpack for reducing two inputs coming from maps or other reduces.
|
97
118
|
def reduce_for_outputs(output1, output2)
|
98
119
|
new_secpack = Tem::SecPack.new_from_array @secpack.to_array
|
99
120
|
|
data/lib/tem_mr_search/server.rb
CHANGED
@@ -87,15 +87,18 @@ class Server
|
|
87
87
|
job = MapReduceJob.new request[:map_reduce]
|
88
88
|
root_tem = request[:root_tem]
|
89
89
|
executor = MapReduceExecutor.new job, @db, @tems, root_tem
|
90
|
-
|
90
|
+
executor.execute
|
91
91
|
when :fetch
|
92
|
-
|
92
|
+
@db.item_by_id(request[:id]) || :not_found
|
93
|
+
when :get_tem
|
94
|
+
tem_id = rand @tems.length
|
95
|
+
{ :id => tem_id, :ecert => @tems[tem_id].endorsement_cert.to_pem }
|
93
96
|
when :shutdown
|
94
|
-
|
97
|
+
:shutdown
|
95
98
|
when :db_dump
|
96
|
-
|
99
|
+
(0...@db.length).map { |i| @db.item(i) }
|
97
100
|
else
|
98
|
-
|
101
|
+
:unknown
|
99
102
|
end
|
100
103
|
end
|
101
104
|
|
data/tem_mr_search.gemspec
CHANGED
@@ -2,38 +2,44 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{tem_mr_search}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Victor Costan"]
|
9
|
-
s.date = %q{2009-11-
|
9
|
+
s.date = %q{2009-11-18}
|
10
10
|
s.default_executable = %q{tem_mr_search_server}
|
11
11
|
s.description = %q{Tem Map-Reduce proof of concept: database search.}
|
12
12
|
s.email = %q{victor@costan.us}
|
13
13
|
s.executables = ["tem_mr_search_server"]
|
14
|
-
s.extra_rdoc_files = ["bin/tem_mr_search_server", "
|
15
|
-
s.files = ["bin/tem_mr_search_server", "
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "bin/tem_mr_search_server", "lib/tem_mr_search.rb", "lib/tem_mr_search/client.rb", "lib/tem_mr_search/client_query.rb", "lib/tem_mr_search/db.rb", "lib/tem_mr_search/map_reduce_executor.rb", "lib/tem_mr_search/map_reduce_job.rb", "lib/tem_mr_search/map_reduce_planner.rb", "lib/tem_mr_search/query_builder.rb", "lib/tem_mr_search/server.rb", "lib/tem_mr_search/web_client_query_builder.rb"]
|
15
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "bin/tem_mr_search_server", "lib/tem_mr_search.rb", "lib/tem_mr_search/client.rb", "lib/tem_mr_search/client_query.rb", "lib/tem_mr_search/db.rb", "lib/tem_mr_search/map_reduce_executor.rb", "lib/tem_mr_search/map_reduce_job.rb", "lib/tem_mr_search/map_reduce_planner.rb", "lib/tem_mr_search/query_builder.rb", "lib/tem_mr_search/server.rb", "lib/tem_mr_search/web_client_query_builder.rb", "test/mr_test_case.rb", "test/test_client_server.rb", "test/test_db.rb", "test/test_map_reduce_executor.rb", "test/test_map_reduce_job.rb", "test/test_map_reduce_planner.rb", "test/test_query_builders.rb", "testdata/cluster.yml", "testdata/empty_cluster.yml", "testdata/fares.yml", "testdata/parallel_plan_431.yml", "testdata/parallel_plan_740.yml", "testdata/serial_plan_410.yml", "testdata/serial_plan_431.yml", "testdata/serial_plan_740.yml", "tem_mr_search.gemspec"]
|
16
16
|
s.homepage = %q{http://tem.rubyforge.org}
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tem_mr_search", "--main", "README"]
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.rubyforge_project = %q{tem}
|
20
20
|
s.rubygems_version = %q{1.3.5}
|
21
21
|
s.summary = %q{Tem Map-Reduce proof of concept: database search.}
|
22
|
-
s.test_files = ["test/
|
22
|
+
s.test_files = ["test/test_client_server.rb", "test/test_db.rb", "test/test_map_reduce_executor.rb", "test/test_map_reduce_job.rb", "test/test_map_reduce_planner.rb", "test/test_query_builders.rb"]
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
26
|
s.specification_version = 3
|
27
27
|
|
28
28
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
-
s.add_runtime_dependency(%q<tem_ruby>, [">= 0.
|
29
|
+
s.add_runtime_dependency(%q<tem_ruby>, [">= 0.15.2"])
|
30
30
|
s.add_runtime_dependency(%q<tem_multi_proxy>, [">= 0.2.7"])
|
31
|
+
s.add_development_dependency(%q<echoe>, [">= 3.2"])
|
32
|
+
s.add_development_dependency(%q<flexmock>, [">= 0.8.6"])
|
31
33
|
else
|
32
|
-
s.add_dependency(%q<tem_ruby>, [">= 0.
|
34
|
+
s.add_dependency(%q<tem_ruby>, [">= 0.15.2"])
|
33
35
|
s.add_dependency(%q<tem_multi_proxy>, [">= 0.2.7"])
|
36
|
+
s.add_dependency(%q<echoe>, [">= 3.2"])
|
37
|
+
s.add_dependency(%q<flexmock>, [">= 0.8.6"])
|
34
38
|
end
|
35
39
|
else
|
36
|
-
s.add_dependency(%q<tem_ruby>, [">= 0.
|
40
|
+
s.add_dependency(%q<tem_ruby>, [">= 0.15.2"])
|
37
41
|
s.add_dependency(%q<tem_multi_proxy>, [">= 0.2.7"])
|
42
|
+
s.add_dependency(%q<echoe>, [">= 3.2"])
|
43
|
+
s.add_dependency(%q<flexmock>, [">= 0.8.6"])
|
38
44
|
end
|
39
45
|
end
|
data/test/test_client_server.rb
CHANGED
@@ -37,6 +37,24 @@ class ClientServerTest < MrTestCase
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_get_tem
|
41
|
+
flexmock(Server).should_receive(:tems_from_cluster_file).
|
42
|
+
with(@empty_cluster_file).and_return do |file|
|
43
|
+
Tem.auto_conf
|
44
|
+
$tem.emit if $tem.activate
|
45
|
+
[$tem]
|
46
|
+
end
|
47
|
+
|
48
|
+
_test_request do |server_addr|
|
49
|
+
tem_info = Client.get_tem server_addr
|
50
|
+
assert_equal 0, tem_info[:id], 'Incorrect TEM id'
|
51
|
+
assert_equal $tem.endorsement_cert.to_pem, tem_info[:ecert].to_pem,
|
52
|
+
'Incorrect ECert'
|
53
|
+
assert_equal $tem.pubek.ssl_key.to_pem, tem_info[:pubek].ssl_key.to_pem,
|
54
|
+
'Incorrect PubEK'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
40
58
|
def test_dump_database
|
41
59
|
_test_request do |server_addr|
|
42
60
|
items = Client.dump_database server_addr
|
@@ -18,6 +18,7 @@ class MapReduceExecutorTest < MrTestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def _test_executor(tems, root_tem)
|
21
|
+
@client_query.bind tems[root_tem].pubek
|
21
22
|
executor = MRExecutor.new @client_query, @db, tems, root_tem
|
22
23
|
packed_output = executor.execute
|
23
24
|
result = @client_query.unpack_output packed_output
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tem_mr_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-18 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.15.2
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tem_multi_proxy
|
@@ -32,6 +32,26 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.2.7
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: echoe
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "3.2"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: flexmock
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.8.6
|
54
|
+
version:
|
35
55
|
description: "Tem Map-Reduce proof of concept: database search."
|
36
56
|
email: victor@costan.us
|
37
57
|
executables:
|
@@ -39,8 +59,11 @@ executables:
|
|
39
59
|
extensions: []
|
40
60
|
|
41
61
|
extra_rdoc_files:
|
42
|
-
- bin/tem_mr_search_server
|
43
62
|
- CHANGELOG
|
63
|
+
- LICENSE
|
64
|
+
- README
|
65
|
+
- bin/tem_mr_search_server
|
66
|
+
- lib/tem_mr_search.rb
|
44
67
|
- lib/tem_mr_search/client.rb
|
45
68
|
- lib/tem_mr_search/client_query.rb
|
46
69
|
- lib/tem_mr_search/db.rb
|
@@ -50,12 +73,14 @@ extra_rdoc_files:
|
|
50
73
|
- lib/tem_mr_search/query_builder.rb
|
51
74
|
- lib/tem_mr_search/server.rb
|
52
75
|
- lib/tem_mr_search/web_client_query_builder.rb
|
53
|
-
|
76
|
+
files:
|
77
|
+
- CHANGELOG
|
54
78
|
- LICENSE
|
79
|
+
- Manifest
|
55
80
|
- README
|
56
|
-
|
81
|
+
- Rakefile
|
57
82
|
- bin/tem_mr_search_server
|
58
|
-
-
|
83
|
+
- lib/tem_mr_search.rb
|
59
84
|
- lib/tem_mr_search/client.rb
|
60
85
|
- lib/tem_mr_search/client_query.rb
|
61
86
|
- lib/tem_mr_search/db.rb
|
@@ -65,12 +90,6 @@ files:
|
|
65
90
|
- lib/tem_mr_search/query_builder.rb
|
66
91
|
- lib/tem_mr_search/server.rb
|
67
92
|
- lib/tem_mr_search/web_client_query_builder.rb
|
68
|
-
- lib/tem_mr_search.rb
|
69
|
-
- LICENSE
|
70
|
-
- Manifest
|
71
|
-
- Rakefile
|
72
|
-
- README
|
73
|
-
- tem_mr_search.gemspec
|
74
93
|
- test/mr_test_case.rb
|
75
94
|
- test/test_client_server.rb
|
76
95
|
- test/test_db.rb
|
@@ -86,6 +105,7 @@ files:
|
|
86
105
|
- testdata/serial_plan_410.yml
|
87
106
|
- testdata/serial_plan_431.yml
|
88
107
|
- testdata/serial_plan_740.yml
|
108
|
+
- tem_mr_search.gemspec
|
89
109
|
has_rdoc: true
|
90
110
|
homepage: http://tem.rubyforge.org
|
91
111
|
licenses: []
|
@@ -120,9 +140,9 @@ signing_key:
|
|
120
140
|
specification_version: 3
|
121
141
|
summary: "Tem Map-Reduce proof of concept: database search."
|
122
142
|
test_files:
|
123
|
-
- test/test_query_builders.rb
|
124
|
-
- test/test_map_reduce_job.rb
|
125
143
|
- test/test_client_server.rb
|
126
|
-
- test/test_map_reduce_planner.rb
|
127
144
|
- test/test_db.rb
|
128
145
|
- test/test_map_reduce_executor.rb
|
146
|
+
- test/test_map_reduce_job.rb
|
147
|
+
- test/test_map_reduce_planner.rb
|
148
|
+
- test/test_query_builders.rb
|