Class: Bosh::Director::Jobs::UpdateDeployment

Inherits:
BaseJob show all
Includes:
LockHelper
Defined in:
lib/bosh/director/jobs/update_deployment.rb

Instance Attribute Summary

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LockHelper

#with_compile_lock, #with_deployment_lock, #with_release_lock, #with_release_locks, #with_stemcell_lock

Methods inherited from BaseJob

#begin_stage, #dns_manager, #event_log, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log

Constructor Details

#initialize(manifest_file_path, cloud_config_id, options = {}) ⇒ UpdateDeployment

Returns a new instance of UpdateDeployment.



12
13
14
15
16
17
# File 'lib/bosh/director/jobs/update_deployment.rb', line 12

def initialize(manifest_file_path, cloud_config_id, options = {})
  @blobstore = App.instance.blobstores.blobstore
  @manifest_file_path = manifest_file_path
  @options = options
  @cloud_config_id = cloud_config_id
end

Class Method Details

.job_typeObject



8
9
10
# File 'lib/bosh/director/jobs/update_deployment.rb', line 8

def self.job_type
  :update_deployment
end

Instance Method Details

#performObject



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
64
65
# File 'lib/bosh/director/jobs/update_deployment.rb', line 19

def perform
  logger.info('Reading deployment manifest')

  manifest_text = File.read(@manifest_file_path)
  logger.debug("Manifest:\n#{manifest_text}")
  cloud_config_model = Bosh::Director::Models::CloudConfig[@cloud_config_id]
  if cloud_config_model.nil?
    logger.debug("No cloud config uploaded yet.")
  else
    logger.debug("Cloud config:\n#{cloud_config_model.manifest}")
  end

  deployment_manifest = Manifest.load_from_text(manifest_text, cloud_config_model)
  deployment_name = deployment_manifest.to_hash['name']
  with_deployment_lock(deployment_name) do
    @notifier = DeploymentPlan::Notifier.new(deployment_name, Config.nats_rpc, logger)
    @notifier.send_start_event

    deployment_plan = nil

    event_log.begin_stage('Preparing deployment', 1)
    event_log.track('Preparing deployment') do
      planner_factory = DeploymentPlan::PlannerFactory.create(logger)
      deployment_plan = planner_factory.create_from_manifest(deployment_manifest, cloud_config_model, @options)
      deployment_plan.bind_models
    end

    deployment_plan.compile_packages

    render_job_templates(deployment_plan.jobs_starting_on_deploy)
    update_step(deployment_plan).perform
    @notifier.send_end_event
    logger.info('Finished updating deployment')

    "/deployments/#{deployment_plan.name}"
  end
rescue Exception => e
  begin
    @notifier.send_error_event e
  rescue Exception => e2
    # log the second error
  ensure
    raise e
  end
ensure
  FileUtils.rm_rf(@manifest_file_path)
end