voldemort-rb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/connection/connection.rb +31 -32
- metadata +38 -6
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'rexml/document'
|
2
1
|
require 'json'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
3
4
|
|
4
5
|
class Connection
|
5
|
-
include REXML
|
6
6
|
|
7
7
|
attr_accessor :hosts # The hosts from where we bootstrapped.
|
8
8
|
attr_accessor :nodes # The array of VoldemortNodes available.
|
@@ -35,18 +35,22 @@ class Connection
|
|
35
35
|
|
36
36
|
def bootstrap
|
37
37
|
cluster_response = self.get_from("metadata", "cluster.xml", false)
|
38
|
-
|
39
|
-
self.nodes = self.parse_nodes_from(
|
38
|
+
cluster_xml_doc = Nokogiri::XML(cluster_response[1][0][1])
|
39
|
+
self.nodes = self.parse_nodes_from(cluster_xml_doc)
|
40
40
|
|
41
41
|
stores_response = self.get_from("metadata", "stores.xml", false)
|
42
|
+
|
42
43
|
stores_xml = stores_response[1][0][1]
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
self.
|
47
|
-
self.
|
48
|
-
|
45
|
+
doc = Nokogiri::XML(stores_xml)
|
46
|
+
|
47
|
+
self.key_serializer_type = self.parse_schema_type(doc, 'key-serializer')
|
48
|
+
self.value_serializer_type = self.parse_schema_type(doc, 'value-serializer')
|
49
|
+
self.key_serializer_schemas = self.parse_schema_from(doc, 'key-serializer')
|
50
|
+
self.value_serializer_schemas = self.parse_schema_from(doc, 'value-serializer')
|
51
|
+
|
49
52
|
self.connect_to_random_node
|
53
|
+
|
50
54
|
rescue StandardError => e
|
51
55
|
raise("There was an error trying to bootstrap from the specified servers: #{e}")
|
52
56
|
end
|
@@ -62,39 +66,34 @@ class Connection
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
|
-
def parse_schema_type(
|
66
|
-
doc =
|
67
|
-
type_doc = XPath.first(doc, "//stores/store[name = \"#{self.db_name}\"]/#{serializer}/type")
|
68
|
-
|
69
|
+
def parse_schema_type(doc, serializer = 'value-serializer')
|
70
|
+
type_doc = doc.xpath("//stores/store[name = \"#{self.db_name}\"]/#{serializer}/type")
|
69
71
|
if(type_doc != nil)
|
70
72
|
return type_doc.text
|
71
73
|
else
|
72
74
|
return nil
|
73
75
|
end
|
74
|
-
end
|
76
|
+
end
|
75
77
|
|
76
|
-
def parse_schema_from(
|
78
|
+
def parse_schema_from(doc, serializer = 'value-serializer')
|
77
79
|
parsed_schemas = {}
|
78
|
-
doc =
|
79
|
-
|
80
|
-
XPath.each(doc, "//stores/store[name = \"#{self.db_name}\"]/#{serializer}/schema-info") do |value_serializer|
|
81
|
-
parsed_schemas[value_serializer.attributes['version']] = value_serializer.text
|
80
|
+
doc.xpath("//stores/store[name = \"#{self.db_name}\"]/#{serializer}/schema-info").each do |value_serializer|
|
81
|
+
parsed_schemas[value_serializer.attributes['version'].text] = value_serializer.text
|
82
82
|
end
|
83
|
-
|
84
83
|
return parsed_schemas
|
85
|
-
end
|
86
|
-
|
87
|
-
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def parse_nodes_from(doc)
|
88
88
|
nodes = []
|
89
|
-
doc
|
90
|
-
|
91
|
-
node =
|
92
|
-
node.
|
93
|
-
node.
|
94
|
-
node.
|
95
|
-
node.
|
96
|
-
node.
|
97
|
-
node.partitions = n.elements["partitions"].text
|
89
|
+
doc.xpath("/cluster/server").each do |n|
|
90
|
+
node = VoldemortNode.new
|
91
|
+
node.id = n.xpath("//id").text
|
92
|
+
node.host = n.xpath("//host").text
|
93
|
+
node.port = n.xpath("//socket-port").text
|
94
|
+
node.http_port = n.xpath("//http_port").text
|
95
|
+
node.admin_port = n.xpath("//admin-port").text
|
96
|
+
node.partitions = n.xpath("//partitions").text
|
98
97
|
nodes << node
|
99
98
|
end
|
100
99
|
nodes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voldemort-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alejandro Crosa
|
@@ -15,10 +15,42 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-08 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ruby_protobuf
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 21
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
- 3
|
34
|
+
version: 0.3.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 113
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 3
|
50
|
+
- 1
|
51
|
+
version: 1.4.3.1
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
22
54
|
description: voldemort-rb allows you to connect to the Voldemort descentralized key value store.
|
23
55
|
email:
|
24
56
|
- alejandrocrosa@gmail.com
|