mcrain 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mcrain/base.rb +25 -5
- data/lib/mcrain/rabbitmq.rb +6 -12
- data/lib/mcrain/redis.rb +6 -12
- data/lib/mcrain/riak.rb +21 -18
- data/lib/mcrain/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eab1ae91f7d9e73884273cedd2b581a54d53a80
|
4
|
+
data.tar.gz: 9e853f3952c4d2b718c0d49d42c60cf628199999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3edb11335ff2b994b90b77134e527dd92584e13f52981f1b2877dfd8d4bbeea38ef2dc0811c170e59f46654cd2e9a93cc8e95e67006026f583708ea540e16b
|
7
|
+
data.tar.gz: 9979c2da2473d65bb7ff9cf2ce9ad325f6392b8262629f176b1f41291d4e651ebd0e99299b05d50481b0bf475cb35e595be462038056c780d74e54a2f18091dc
|
data/lib/mcrain/base.rb
CHANGED
@@ -17,6 +17,11 @@ module Mcrain
|
|
17
17
|
|
18
18
|
attr_accessor :container_image, :port
|
19
19
|
end
|
20
|
+
def reset
|
21
|
+
instance_variables.each do |var|
|
22
|
+
instance_variable_set(var, nil)
|
23
|
+
end
|
24
|
+
end
|
20
25
|
|
21
26
|
def container_image
|
22
27
|
self.class.container_image or raise "No container_image for #{self.class.name}"
|
@@ -47,6 +52,7 @@ module Mcrain
|
|
47
52
|
end
|
48
53
|
|
49
54
|
def start
|
55
|
+
reset
|
50
56
|
clear_old_container
|
51
57
|
run_container
|
52
58
|
if block_given?
|
@@ -69,8 +75,7 @@ module Mcrain
|
|
69
75
|
end
|
70
76
|
|
71
77
|
def run_container
|
72
|
-
|
73
|
-
|
78
|
+
LoggerPipe.run(logger, build_docker_command, timeout: 10)
|
74
79
|
end
|
75
80
|
|
76
81
|
def build_docker_command
|
@@ -98,7 +103,7 @@ module Mcrain
|
|
98
103
|
begin
|
99
104
|
wait_for_ready
|
100
105
|
rescue => e
|
101
|
-
|
106
|
+
$stderr.puts "[#{e.class}] #{e.message}"
|
102
107
|
sleep(1)
|
103
108
|
retry
|
104
109
|
end
|
@@ -110,17 +115,32 @@ module Mcrain
|
|
110
115
|
end
|
111
116
|
|
112
117
|
def client
|
113
|
-
|
118
|
+
@client ||= build_client
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_client
|
122
|
+
require client_require
|
123
|
+
yield if block_given?
|
124
|
+
client_class.new(*client_init_args)
|
114
125
|
end
|
115
126
|
|
116
127
|
def client_require
|
117
128
|
raise NotImplementedError
|
118
129
|
end
|
119
130
|
|
120
|
-
def
|
131
|
+
def client_class
|
121
132
|
raise NotImplementedError
|
122
133
|
end
|
123
134
|
|
135
|
+
def client_init_args
|
136
|
+
raise NotImplementedError
|
137
|
+
end
|
138
|
+
|
139
|
+
def client_script
|
140
|
+
client
|
141
|
+
"#{client_class.name}.new(*#{client_init_args.inspect})"
|
142
|
+
end
|
143
|
+
|
124
144
|
def stop
|
125
145
|
LoggerPipe.run(logger, "docker kill #{container_name}", timeout: 10)
|
126
146
|
end
|
data/lib/mcrain/rabbitmq.rb
CHANGED
@@ -32,22 +32,16 @@ module Mcrain
|
|
32
32
|
"guest"
|
33
33
|
end
|
34
34
|
|
35
|
-
def client
|
36
|
-
require client_require
|
37
|
-
@client ||= RabbitMQ::HTTP::Client.new(*build_client_args)
|
38
|
-
end
|
39
|
-
|
40
|
-
def build_client_args
|
41
|
-
["http://#{host}:#{port}", {username: username, password: password}]
|
42
|
-
end
|
43
|
-
|
44
35
|
def client_require
|
45
36
|
'rabbitmq/http/client'
|
46
37
|
end
|
47
38
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
39
|
+
def client_class
|
40
|
+
RabbitMQ::HTTP::Client
|
41
|
+
end
|
42
|
+
|
43
|
+
def client_init_args
|
44
|
+
["http://#{host}:#{port}", {username: username, password: password}]
|
51
45
|
end
|
52
46
|
|
53
47
|
def wait_for_ready
|
data/lib/mcrain/redis.rb
CHANGED
@@ -10,22 +10,16 @@ module Mcrain
|
|
10
10
|
self.container_image = "redis:2.8.19"
|
11
11
|
self.port = 6379
|
12
12
|
|
13
|
-
def client
|
14
|
-
require client_require
|
15
|
-
@client ||= ::Redis.new(build_client_options)
|
16
|
-
end
|
17
|
-
|
18
|
-
def build_client_options
|
19
|
-
{host: host, port: port}
|
20
|
-
end
|
21
|
-
|
22
13
|
def client_require
|
23
14
|
'redis'
|
24
15
|
end
|
25
16
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
17
|
+
def client_class
|
18
|
+
::Redis
|
19
|
+
end
|
20
|
+
|
21
|
+
def client_init_args
|
22
|
+
[{host: host, port: port}]
|
29
23
|
end
|
30
24
|
|
31
25
|
def wait_for_ready
|
data/lib/mcrain/riak.rb
CHANGED
@@ -20,16 +20,15 @@ module Mcrain
|
|
20
20
|
super
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@client
|
23
|
+
def build_client
|
24
|
+
super{ build_uris }
|
25
|
+
end
|
26
|
+
|
27
|
+
def client_class
|
28
|
+
::Riak::Client
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
31
|
+
def client_init_args
|
33
32
|
options = {
|
34
33
|
nodes: uris.map{|uri| {host: uri.host, pb_port: uri.port} }
|
35
34
|
}
|
@@ -38,18 +37,13 @@ module Mcrain
|
|
38
37
|
options[:authentication] = {user: uri.user, password: uri.password}
|
39
38
|
end
|
40
39
|
end
|
41
|
-
options
|
40
|
+
[options]
|
42
41
|
end
|
43
42
|
|
44
43
|
def client_require
|
45
44
|
'riak'
|
46
45
|
end
|
47
46
|
|
48
|
-
def client_script
|
49
|
-
client
|
50
|
-
"Riak::Client.new(#{build_client_options.inspect})"
|
51
|
-
end
|
52
|
-
|
53
47
|
def build_uris
|
54
48
|
# https://github.com/hectcastro/docker-riak/blob/develop/bin/test-cluster.sh#L9
|
55
49
|
|
@@ -82,8 +76,13 @@ module Mcrain
|
|
82
76
|
def wait_for_ready
|
83
77
|
c = client
|
84
78
|
logger.debug("sending a ping")
|
85
|
-
|
86
|
-
|
79
|
+
begin
|
80
|
+
r = c.ping
|
81
|
+
raise "Ping failure with #{c.inspect}" unless r
|
82
|
+
rescue => e
|
83
|
+
logger.debug("[#{e.class.name}] #{e.message} by #{c.inspect}")
|
84
|
+
raise e
|
85
|
+
end
|
87
86
|
20.times do |i|
|
88
87
|
begin
|
89
88
|
logger.debug("get and store ##{i}")
|
@@ -112,7 +111,8 @@ module Mcrain
|
|
112
111
|
attr_reader :host, :cids, :pb_ports, :uris, :admin_uris
|
113
112
|
attr_accessor :automatic_clustering, :cluster_size
|
114
113
|
|
115
|
-
def
|
114
|
+
def reset
|
115
|
+
super
|
116
116
|
w = @work_dir = Mcrain::Riak.docker_riak_path
|
117
117
|
raise "#{self.class.name}.docker_riak_path is blank. You have to set it to use the class" if w.blank?
|
118
118
|
raise "#{w}/Makefile not found" unless File.readable?(File.join(w, "Makefile"))
|
@@ -129,12 +129,15 @@ module Mcrain
|
|
129
129
|
logger.debug("cd #{@work_dir.inspect}")
|
130
130
|
Dir.chdir(@work_dir) do
|
131
131
|
# http://basho.co.jp/riak-quick-start-with-docker/
|
132
|
+
#
|
133
|
+
# "Please wait approximately 30 seconds for the cluster to stabilize"
|
134
|
+
# from https://gist.github.com/agutow/11133143#file-docker3-sh-L12
|
132
135
|
LoggerPipe.run(logger, "#{@prepare_cmd} #{build_command}")
|
133
136
|
sleep(1)
|
134
137
|
20.times do
|
135
138
|
begin
|
136
139
|
LoggerPipe.run(logger, "#{@prepare_cmd} make test-cluster")
|
137
|
-
sleep(
|
140
|
+
sleep(5)
|
138
141
|
return
|
139
142
|
rescue
|
140
143
|
sleep(0.5)
|
data/lib/mcrain/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcrain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger_pipe
|