etcd-rb 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ class ClusterController
5
5
  end
6
6
 
7
7
  def self.kill_node(node_name)
8
- node_pid = `ps -ef|grep #{node_name}|grep -v grep`.split[1]
8
+ node_pid = `ps -ef|grep etcd|grep #{node_name}|grep -v grep`.split[1]
9
9
  `kill -9 #{node_pid}`
10
10
  end
11
11
 
@@ -16,4 +16,4 @@ class ClusterController
16
16
  def self.stop_cluster
17
17
  `#{sh_path}/cluster stop`
18
18
  end
19
- end
19
+ end
@@ -1,4 +1,8 @@
1
1
  module ClientHelper
2
+ # Sample V2 API request/response for keys
3
+ # $ curl -L http://127.0.0.1:4001/v2/keys
4
+ # {"action":"get","node":{"dir":true,"nodes":[{"key":"/foo","value":"bar","modifiedIndex":22,"createdIndex":22}]}}
5
+
2
6
  def default_client(uri = "http://127.0.0.1:4001")
3
7
  client = Etcd::Client.new(:uris => uri)
4
8
  client.cluster = healthy_cluster(uri)
@@ -12,8 +16,8 @@ module ClientHelper
12
16
  nodes = Etcd::Cluster.nodes_from_attributes(data)
13
17
  cluster = Etcd::Cluster.new(uri)
14
18
  cluster.nodes = nodes
15
- nodes.map{|x| x.status = :running}
19
+ nodes.map{|node| node.status = :running}
16
20
  nodes.first.is_leader = true
17
21
  cluster
18
22
  end
19
- end
23
+ end
@@ -1,45 +1,42 @@
1
1
  module ClusterHelper
2
+
3
+ # Sample V2 API request/response for cluster members
4
+ # $ curl -L http://127.0.0.1:4001/v2/members
5
+ # {"members":[{"id":"d2356cd527a56a4","name":"node2","peerURLs":["http://127.0.0.1:7002"],"clientURLs":["http://127.0.0.1:4002"]},{"id":"108d26d18c38bf0e","name":"node0","peerURLs":["http://127.0.0.1:7000"],"clientURLs":["http://127.0.0.1:4000"]},{"id":"14306b09b8d69fc4","name":"node1","peerURLs":["http://127.0.0.1:7001"],"clientURLs":["http://127.0.0.1:4001"]}]}
6
+
2
7
  def status_data
3
- [
4
- {"action"=>"GET",
5
- "key"=>"/_etcd/machines/node1",
6
- "value"=>
7
- "raft=http://127.0.0.1:7001&etcd=http://127.0.0.1:4001&raftVersion=v0.1.1",
8
- "index"=>360},
9
- {"action"=>"GET",
10
- "key"=>"/_etcd/machines/node2",
11
- "value"=>
12
- "raft=http://127.0.0.1:7002&etcd=http://127.0.0.1:4002&raftVersion=v0.1.1",
13
- "index"=>360},
14
- {"action"=>"GET",
15
- "key"=>"/_etcd/machines/node3",
16
- "value"=>
17
- "raft=http://127.0.0.1:7003&etcd=http://127.0.0.1:4003&raftVersion=v0.1.1",
18
- "index"=>360}
19
- ]
8
+ {"members" =>
9
+ [
10
+ {"id" => "14306b09b8d69fc4","name" => "node1","peerURLs"=> ["http://127.0.0.1:7001"],"clientURLs" => ["http://127.0.0.1:4001"]},
11
+ {"id" => "d2356cd527a56a4","name" => "node2","peerURLs" => ["http://127.0.0.1:7002"],"clientURLs" => ["http://127.0.0.1:4002"]},
12
+ {"id" => "108d26d18c38bf0e","name" => "node3","peerURLs" => ["http://127.0.0.1:7003"],"clientURLs" => ["http://127.0.0.1:4003"]}
13
+ ]
14
+ }
20
15
  end
21
16
 
17
+ # cluster config hashes below map member client URLs to the leader client URL
18
+
22
19
  def healthy_cluster_config
23
20
  {
24
- 'http://127.0.0.1:4001' => 'http://127.0.0.1:7001',
25
- 'http://127.0.0.1:4002' => 'http://127.0.0.1:7001',
26
- 'http://127.0.0.1:4003' => 'http://127.0.0.1:7001'
21
+ 'http://127.0.0.1:4001' => 'http://127.0.0.1:4001',
22
+ 'http://127.0.0.1:4002' => 'http://127.0.0.1:4001',
23
+ 'http://127.0.0.1:4003' => 'http://127.0.0.1:4001'
27
24
  }
28
25
  end
29
26
 
30
27
  def one_down_cluster_config
31
28
  {
32
- 'http://127.0.0.1:4001' => 'http://127.0.0.1:7001',
33
- 'http://127.0.0.1:4002' => 'http://127.0.0.1:7001',
29
+ 'http://127.0.0.1:4001' => 'http://127.0.0.1:4001',
30
+ 'http://127.0.0.1:4002' => 'http://127.0.0.1:4001',
34
31
  'http://127.0.0.1:4003' => :down
35
32
  }
36
33
  end
37
34
 
38
35
  def healthy_cluster_changed_leader_config
39
36
  {
40
- 'http://127.0.0.1:4001' => 'http://127.0.0.1:7002',
41
- 'http://127.0.0.1:4002' => 'http://127.0.0.1:7002',
42
- 'http://127.0.0.1:4003' => 'http://127.0.0.1:7002'
37
+ 'http://127.0.0.1:4001' => 'http://127.0.0.1:4002',
38
+ 'http://127.0.0.1:4002' => 'http://127.0.0.1:4002',
39
+ 'http://127.0.0.1:4003' => 'http://127.0.0.1:4002'
43
40
  }
44
41
  end
45
42
 
@@ -52,19 +49,20 @@ module ClusterHelper
52
49
 
53
50
 
54
51
  def leader_uri(uri)
55
- "#{uri}/v1/leader"
52
+ "#{uri}/v2/members/leader"
56
53
  end
57
54
 
58
55
  def stub_leader_uri(uri, opts = {})
59
- leader = (opts[:leader] ||"http://127.0.0.1:7001")
56
+ leader = (opts[:leader] || "http://127.0.0.1:4001")
60
57
  if leader == :down
61
58
  stub_request(:get, leader_uri(uri)).to_timeout
62
59
  else
63
- stub_request(:get, leader_uri(uri)).to_return(body: leader)
60
+ leader_info = status_data["members"].select{|node| node["clientURLs"].first == leader }.first
61
+ stub_request(:get, leader_uri(uri)).to_return(body: MultiJson.dump(leader_info) )
64
62
  end
65
63
  end
66
64
 
67
- # [{etcd_url => leader_string},{etcd_url => leader_string}]
65
+ # [{node_client_url => leader_client_url},{node_client_url => leader_client_url}]
68
66
  def with_stubbed_leaders(cluster_config)
69
67
  cluster_config.each do |url, leader_uri|
70
68
  stub_leader_uri(url, :leader => leader_uri)
@@ -72,4 +70,4 @@ module ClusterHelper
72
70
  yield if block_given?
73
71
  #urls.each { |url| WebMock.should have_requested(:get, leader_uri(url))}
74
72
  end
75
- end
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcd-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-27 00:00:00.000000000 Z
12
+ date: 2016-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.2.2
93
+ rubygems_version: 2.4.8
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: ''