Module: Mcrain

Defined in:
lib/mcrain/riak.rb,
lib/mcrain.rb,
lib/mcrain/base.rb,
lib/mcrain/redis.rb,
lib/mcrain/version.rb,
lib/mcrain/rabbitmq.rb,
lib/mcrain/boot2docker.rb

Overview

don’t require ‘rabbitmq/http/client’ here in order to use mcrain without ‘rabbitmq_http_api_client’ gem require ‘rabbitmq/http/client’

Defined Under Namespace

Modules: Boot2docker Classes: Base, Rabbitmq, Redis, Riak

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



57
58
59
# File 'lib/mcrain.rb', line 57

def logger
  @logger ||= Logger.new($stderr)
end

Class Method Details

.[](name) ⇒ Object



14
15
16
# File 'lib/mcrain.rb', line 14

def [](name)
  lookup(name)
end

.class_for(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/mcrain.rb', line 29

def class_for(name)
  if class_name = class_names[name]
    class_name.constantize
  else
    if klass = Mcrain::Base.descendants.detect{|c| c.server_name == name}
      class_names[name] = klass.name
    end
    klass
  end
end

.class_namesObject



25
26
27
# File 'lib/mcrain.rb', line 25

def class_names
  @class_names ||= {}
end

.instancesObject



44
45
46
# File 'lib/mcrain.rb', line 44

def instances
  @instances ||= {}
end

.lookup(name, options = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/mcrain.rb', line 18

def lookup(name, options = {})
  klass = class_for(name.to_sym)
  r = instances[name] ||= klass.new
  options.each{|k,v| r.send("#{k}=", v)}
  r
end

.pull_imagesObject



48
49
50
51
52
53
54
# File 'lib/mcrain.rb', line 48

def pull_images
  Mcrain::Base.descendants.each do |klass|
    Timeout.timeout(10.minutes) do
      LoggerPipe.run(logger, "docker pull #{klass.container_image}")
    end
  end
end

.register(name, class_name) ⇒ Object



40
41
42
# File 'lib/mcrain.rb', line 40

def register(name, class_name)
  class_names[name] = class_name
end

.wait_port_opened(host, port, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mcrain.rb', line 61

def wait_port_opened(host, port, options = {})
  logger.debug("wait_port_opened(#{host.inspect}, #{port.inspect}, #{options.inspect})")
  interval = options[:interval] || 10 # second
  Timeout.timeout(options[:timeout] || 60) do
    begin
      s = TCPSocket.open(host, port)
      s.close
      return true
    rescue Errno::ECONNREFUSED
      sleep(interval)
      retry
    end
  end
end