Class: Bosh::Director::InstanceUpdater::StateApplier

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/instance_updater/state_applier.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance_plan, agent_client, rendered_job_templates_cleaner, logger, options) ⇒ StateApplier

Returns a new instance of StateApplier.



3
4
5
6
7
8
9
10
# File 'lib/bosh/director/instance_updater/state_applier.rb', line 3

def initialize(instance_plan, agent_client, rendered_job_templates_cleaner, logger, options)
  @instance_plan = instance_plan
  @instance = @instance_plan.instance
  @agent_client = agent_client
  @rendered_job_templates_cleaner = rendered_job_templates_cleaner
  @logger = logger
  @is_canary = options.fetch(:canary, false)
end

Instance Method Details

#apply(update_config, run_post_start = true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bosh/director/instance_updater/state_applier.rb', line 12

def apply(update_config, run_post_start = true)
  @instance.apply_vm_state(@instance_plan.spec)
  @instance.update_templates(@instance_plan.templates)
  @rendered_job_templates_cleaner.clean

  if @instance.state == 'started'
    @logger.info("Running pre-start for #{@instance}")
    @agent_client.run_script('pre-start', {})

    @logger.info("Starting instance #{@instance}")
    @agent_client.start
  end

  # for backwards compatibility with instances that don't have update config
  if update_config && run_post_start
    min_watch_time = @is_canary ? update_config.min_canary_watch_time : update_config.min_update_watch_time
    max_watch_time = @is_canary ? update_config.max_canary_watch_time : update_config.max_update_watch_time

    post_start(min_watch_time, max_watch_time)
  end
end