Class: Imperium::Service

Inherits:
APIObject show all
Defined in:
lib/imperium/service.rb

Overview

Service is a container for data being received from and sent to the agent services APIs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from APIObject

#==, #attribute_map, #ruby_attribute_names, #to_h

Constructor Details

#initialize(*args) ⇒ Service

Returns a new instance of Service.



46
47
48
49
50
51
# File 'lib/imperium/service.rb', line 46

def initialize(*args)
  # So we can << onto these w/o having to nil check everywhere first
  @tags ||= []
  @checks ||= []
  super
end

Instance Attribute Details

#addressString

Returns The network address to find the service at for DNS requests, defaults to the running agent’s IP if left blank.

Returns:

  • (String)

    The network address to find the service at for DNS requests, defaults to the running agent’s IP if left blank.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#checksArray<ServiceCheck>

Returns Specifies a list of checks to use for monitoring the service’s health.

Returns:

  • (Array<ServiceCheck>)

    Specifies a list of checks to use for monitoring the service’s health.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#create_indexInteger (readonly)

Returns:

  • (Integer)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#enable_tag_overrideBoolean

Returns Specifies to disable the anti-entropy feature for this service’s tags. If EnableTagOverride is set to true then external agents can update this service in the catalog and modify the tags.

Returns:

  • (Boolean)

    Specifies to disable the anti-entropy feature for this service’s tags. If EnableTagOverride is set to true then external agents can update this service in the catalog and modify the tags.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#idString

Returns The service’s id, when creating a new service this will be automatically assigned if not supplied, must be unique.

Returns:

  • (String)

    The service’s id, when creating a new service this will be automatically assigned if not supplied, must be unique.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#modify_indexInteger (readonly)

Returns:

  • (Integer)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#nameString

Returns The service’s name in the consul UI, required for creation, not required to be unique.

Returns:

  • (String)

    The service’s name in the consul UI, required for creation, not required to be unique.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#portInteger

Returns The port the service is bound to for network services.

Returns:

  • (Integer)

    The port the service is bound to for network services.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#tagsArary<String>

Returns List of tags to be used for the service, can be used after creation for filtering in the API.

Returns:

  • (Arary<String>)

    List of tags to be used for the service, can be used after creation for filtering in the API.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

Instance Method Details

#add_check(val) ⇒ Object Also known as: check=



53
54
55
# File 'lib/imperium/service.rb', line 53

def add_check(val)
  @checks <<  maybe_convert_service_check(val) unless val.nil?
end

#registration_dataHash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]

Generate a hash containing the data necessary for registering this service.

If both Check and Checks are present in the object they’re coalesced into a single Checks key.

Returns:

  • (Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>])

    Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]



73
74
75
76
77
78
79
# File 'lib/imperium/service.rb', line 73

def registration_data
  to_h.tap do |h|
    h.delete('CreateIndex')
    h.delete('ModifyIndex')
    h.delete('Checks') if checks.empty?
  end
end