Sha256: f7e8d4614ec951090d2810d5a5f2135770ed0e2d2c9929ee9f967abe57051243

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

#
# Services Module
#
#  Uses etcd to manage state of Service Endpoint & Members
#
module Services
  require_relative 'services/version'
  require_relative 'services/connection'
  require_relative 'services/entity'
  require_relative 'services/service'
  require_relative 'services/endpoint'
  require_relative 'services/member'

  # this will  change or be slurped up from a config/node attrib
  KEY = '/services'

  #
  # Share a connection between all classess using this module
  #
  class << self
    attr_accessor :connection, :run_context

    def get(*args)
      Chef::Log.debug "connection.get args #{args}" unless run_context.nil?
      connection.get(*args)
    end

    def set(*args)
      Chef::Log.debug "connection.set args #{args}" unless run_context.nil?
      connection.set(*args)
    end

    # return a list of all services
    def all
      services = []
      get(KEY).each do |s|
        name = File.basename s.key
        puts "loading #{name}"
        services << Services::Service.new(name)
      end
      services
    end

    # return all services a node is subscribed to
    def subscribed(f = nil)
      fail 'param and run_context can not both be nil' if f.nil? && run_context.nil?

      fqdn = f.nil? ? rteraun_context.node.fqdn : f
      services = all.map { |s| s.members.include?(fqdn) ? s : nil }
      services.compact
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jn_services-1.0.1 lib/services.rb
jn_services-1.0.0 lib/services.rb