Class: Bosh::Director::DeploymentPlan::UpdateConfig

Inherits:
Object
  • Object
show all
Includes:
ValidationHelper
Defined in:
lib/bosh/director/deployment_plan/update_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValidationHelper

#safe_property

Constructor Details

#initialize(update_config, default_update_config = nil) ⇒ UpdateConfig

Returns a new instance of UpdateConfig.

Parameters:

  • update_config (Hash)

    Raw update config from deployment manifest

  • default_update_config (optional, Hash) (defaults to: nil)

    Default update config



19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 19

def initialize(update_config, default_update_config = nil)
  optional = !default_update_config.nil?

  @canaries = safe_property(update_config, "canaries",
                            :class => Integer, :optional => optional)

  @max_in_flight = safe_property(update_config, "max_in_flight",
                                 :class => Integer, :optional => optional,
                                 :min => 1)

  canary_watch_times = safe_property(update_config, "canary_watch_time",
                                     :class => String,
                                     :optional => optional)
  update_watch_times = safe_property(update_config, "update_watch_time",
                                     :class => String,
                                     :optional => optional)

  if canary_watch_times
    @min_canary_watch_time, @max_canary_watch_time =
      parse_watch_times(canary_watch_times)
  end

  if update_watch_times
    @min_update_watch_time, @max_update_watch_time =
      parse_watch_times(update_watch_times)
  end

  @serial = safe_property(update_config, "serial", {
    class: :boolean,
    optional: true,
    default: default_update_config ? default_update_config.serial? : true,
  })

  if optional
    @canaries ||= default_update_config.canaries

    @min_canary_watch_time ||= default_update_config.min_canary_watch_time
    @max_canary_watch_time ||= default_update_config.max_canary_watch_time

    @min_update_watch_time ||= default_update_config.min_update_watch_time
    @max_update_watch_time ||= default_update_config.max_update_watch_time

    @max_in_flight ||= default_update_config.max_in_flight
  end
end

Instance Attribute Details

#canariesObject

Returns the value of attribute canaries.



8
9
10
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 8

def canaries
  @canaries
end

#max_canary_watch_timeObject

Returns the value of attribute max_canary_watch_time.



12
13
14
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 12

def max_canary_watch_time
  @max_canary_watch_time
end

#max_in_flightObject

Returns the value of attribute max_in_flight.



9
10
11
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 9

def max_in_flight
  @max_in_flight
end

#max_update_watch_timeObject

Returns the value of attribute max_update_watch_time.



15
16
17
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 15

def max_update_watch_time
  @max_update_watch_time
end

#min_canary_watch_timeObject

Returns the value of attribute min_canary_watch_time.



11
12
13
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 11

def min_canary_watch_time
  @min_canary_watch_time
end

#min_update_watch_timeObject

Returns the value of attribute min_update_watch_time.



14
15
16
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 14

def min_update_watch_time
  @min_update_watch_time
end

Instance Method Details

#parse_watch_times(value) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 75

def parse_watch_times(value)
  value = value.to_s

  if value =~ /^\s*(\d+)\s*\-\s*(\d+)\s*$/
    result = [$1.to_i, $2.to_i]
  elsif value =~ /^\s*(\d+)\s*$/
    result = [$1.to_i, $1.to_i]
  else
    raise UpdateConfigInvalidWatchTime,
          "Watch time should be an integer or a range of two integers"
  end

  if result[0] > result[1]
    raise UpdateConfigInvalidWatchTime,
          "Min watch time cannot be greater than max watch time"
  end

  result
end

#serial?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 95

def serial?
  !!@serial
end

#to_hashObject



65
66
67
68
69
70
71
72
73
# File 'lib/bosh/director/deployment_plan/update_config.rb', line 65

def to_hash
  {
    'canaries' => @canaries,
    'max_in_flight' => @max_in_flight,
    'canary_watch_time' => "#{@min_canary_watch_time}-#{@max_canary_watch_time}",
    'update_watch_time' => "#{@min_update_watch_time}-#{@max_update_watch_time}",
    'serial' => serial?
  }
end