Class: Kumonos::Clusters::Cluster

Inherits:
Struct
  • Object
show all
Defined in:
lib/kumonos/clusters.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#circuit_breakerObject

Returns the value of attribute circuit_breaker

Returns:

  • (Object)

    the current value of circuit_breaker



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

def circuit_breaker
  @circuit_breaker
end

#connect_timeout_msObject

Returns the value of attribute connect_timeout_ms

Returns:

  • (Object)

    the current value of connect_timeout_ms



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

def connect_timeout_ms
  @connect_timeout_ms
end

#lbObject

Returns the value of attribute lb

Returns:

  • (Object)

    the current value of lb



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

def lb
  @lb
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

#outlier_detectionObject

Returns the value of attribute outlier_detection

Returns:

  • (Object)

    the current value of outlier_detection



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

def outlier_detection
  @outlier_detection
end

#tlsObject

Returns the value of attribute tls

Returns:

  • (Object)

    the current value of tls



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

def tls
  @tls
end

#use_sdsObject

Returns the value of attribute use_sds

Returns:

  • (Object)

    the current value of use_sds



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

def use_sds
  @use_sds
end

Class Method Details

.build(h) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kumonos/clusters.rb', line 16

def build(h)
  use_sds = h.fetch('sds', false)
  lb = use_sds ? nil : h.fetch('lb')
  raise "Invalid format in `lb` value. Must be \"${host}:${port}\" format: #{lb}" if lb && lb.split(':').size != 2

  circuit_breaker =
    if h.key?('circuit_breaker')
      CircuitBreaker.build(h.fetch('circuit_breaker'))
    else
      nil
    end

  new(
    h.fetch('cluster_name'),
    h.fetch('connect_timeout_ms'),
    lb,
    h.fetch('tls'),
    circuit_breaker,
    OutlierDetection.build(h['outlier_detection']), # optional
    use_sds
  )
end

Instance Method Details

#to_hObject



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
# File 'lib/kumonos/clusters.rb', line 40

def to_h
  h = super

  h.delete(:lb)
  h.delete(:use_sds)
  if use_sds
    h[:type] = 'sds'
    h[:service_name] = name
    h[:features] = 'http2'
  else
    h[:type] = 'strict_dns'
    h[:hosts] = [{ url: "tcp://#{lb}" }]
  end

  h[:lb_type] = 'round_robin'
  h.delete(:tls)
  if tls
    h[:ssl_context] = {}
    h[:ssl_context][:sni] = lb.split(':', 2)[0] unless use_sds
  end

  h.delete(:circuit_breaker)
  h[:circuit_breakers] = { default: circuit_breaker.to_h } if circuit_breaker

  if outlier_detection
    h[:outlier_detection] = outlier_detection.to_h
  else
    h.delete(:outlier_detection)
  end

  h
end