mcrain 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1a06ee8da82a778eea1700f2366af6a025a6456
4
- data.tar.gz: 77b113a4873c5acd9d2f6ed093e56092c6648929
3
+ metadata.gz: 2eab1ae91f7d9e73884273cedd2b581a54d53a80
4
+ data.tar.gz: 9e853f3952c4d2b718c0d49d42c60cf628199999
5
5
  SHA512:
6
- metadata.gz: 8af73c32ed5d7e65b217be6cd30c35c72b1e9778812344b04b03b1e0e96957b08dbc0146a23694c62c7d7c34711ee6969b6664ad66732005d438779c5069f1db
7
- data.tar.gz: 2895f8d1a5df7e7020045e798badc8290f3d112e3191256b5e4f112ecbd751fe96feae65cda8f8bbdd0e8e32475e2d4ebef1a166ea5ee16c7e19057c41259d8b
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
- s = LoggerPipe.run(logger, build_docker_command, timeout: 10)
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
- # $stderr.puts "[#{e.class}] #{e.message}"
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
- raise NotImplementedError
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 client_script
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
@@ -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 client_script
49
- client
50
- "RabbitMQ::HTTP::Client.new(*#{build_client_args.inspect})"
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 client_script
27
- client
28
- "Redis.new(#{build_client_options.inspect})"
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 client
24
- unless @client
25
- require client_require
26
- build_uris
27
- @client = ::Riak::Client.new(build_client_options)
28
- end
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 build_client_options
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
- r = c.ping
86
- raise "Ping failure with #{c.inspect}" unless r
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 initialize
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(45) # Please wait approximately 30 seconds for the cluster to stabilize
140
+ sleep(5)
138
141
  return
139
142
  rescue
140
143
  sleep(0.5)
@@ -1,3 +1,3 @@
1
1
  module Mcrain
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-07 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger_pipe