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) ⇒ StateApplier

Returns a new instance of StateApplier.



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

def initialize(instance_plan, agent_client, rendered_job_templates_cleaner, logger)
  @instance_plan = instance_plan
  @instance = @instance_plan.instance
  @agent_client = agent_client
  @rendered_job_templates_cleaner = rendered_job_templates_cleaner
  @logger = logger
end

Instance Method Details

#applyObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/bosh/director/instance_updater/state_applier.rb', line 11

def apply
  @instance.apply_vm_state(@instance_plan.spec)
  @instance.update_templates(@instance_plan.templates)
  @rendered_job_templates_cleaner.clean

  if @instance.state == 'started'
    @agent_client.run_script('pre-start', {})
    @agent_client.start
  end
end

#post_start(min_watch_time, max_watch_time) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bosh/director/instance_updater/state_applier.rb', line 22

def post_start(min_watch_time, max_watch_time)
  current_state = wait_until_desired_state(min_watch_time, max_watch_time)

  if @instance.state == 'started'
    if current_state['job_state'] != 'running'
      raise AgentJobNotRunning, "`#{@instance}' is not running after update"
    else
      @agent_client.run_script('post-start', {})
    end
  end

  if @instance.state == 'stopped' && current_state['job_state'] == 'running'
    raise AgentJobNotStopped, "`#{@instance}' is still running despite the stop command"
  end

  @instance.update_state
end