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

Inherits:
BaseJob show all
Includes:
LegacyDeploymentHelper, 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 LegacyDeploymentHelper

#ignore_cloud_config?

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_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username

Constructor Details

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

Returns a new instance of UpdateDeployment.



15
16
17
18
19
20
21
22
# File 'lib/bosh/director/jobs/update_deployment.rb', line 15

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

Class Method Details

.job_typeObject



11
12
13
# File 'lib/bosh/director/jobs/update_deployment.rb', line 11

def self.job_type
  :update_deployment
end

Instance Method Details

#performObject



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bosh/director/jobs/update_deployment.rb', line 24

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

  manifest_text = File.read(@manifest_file_path)
  manifest_hash = Psych.load(manifest_text)
  logger.debug("Manifest:\n#{manifest_text}")

  if Config.parse_config_values
    manifest_hash = Bosh::Director::Jobs::Helpers::ConfigParser.parse(manifest_hash)
  end

  if ignore_cloud_config?(manifest_hash)
    warning = "Ignoring cloud config. Manifest contains 'networks' section."
    logger.debug(warning)
    @event_log.warn_deprecated(warning)
    cloud_config_model = nil
  else
    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
  end

  runtime_config_model = Bosh::Director::Models::RuntimeConfig[@runtime_config_id]
  if runtime_config_model.nil?
    logger.debug("No runtime config uploaded yet.")
  else
    logger.debug("Runtime config:\n#{runtime_config_model.manifest}")
  end

  deployment_manifest = Manifest.load_from_hash(manifest_hash, cloud_config_model, runtime_config_model)

  @deployment_name = deployment_manifest.to_hash['name']

  previous_releases, previous_stemcells = get_stemcells_and_releases
  context = {}
  parent_id = add_event

  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_stage = @event_log.begin_stage('Preparing deployment', 1)
    event_log_stage.advance_and_track('Preparing deployment') do
      planner_factory = DeploymentPlan::PlannerFactory.create(logger)
      deployment_plan = planner_factory.create_from_manifest(deployment_manifest, cloud_config_model, runtime_config_model, @options)
      deployment_plan.bind_models
    end

    if deployment_plan.instance_models.any?(&:ignore)
      @event_log.warn('You have ignored instances. They will not be changed.')
    end

    next_releases, next_stemcells  = get_stemcells_and_releases
    context = event_context(next_releases, previous_releases, next_stemcells, previous_stemcells)

    render_job_templates(deployment_plan.jobs_starting_on_deploy)
    deployment_plan.compile_packages

    update_step(deployment_plan).perform

    if check_for_changes(deployment_plan)
      PostDeploymentScriptRunner.run_post_deploys_after_deployment(deployment_plan)
    end

    @notifier.send_end_event
    logger.info('Finished updating deployment')
    add_event(context, parent_id)

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