Class: Bosh::Director::Jobs::RunErrand

Inherits:
BaseJob show all
Includes:
LockHelper
Defined in:
lib/bosh/director/jobs/run_errand.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_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_checkpoint, #track_and_log, #username

Constructor Details

#initialize(deployment_name, errand_name, keep_alive) ⇒ RunErrand

Returns a new instance of RunErrand.



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

def initialize(deployment_name, errand_name, keep_alive)
  @deployment_name = deployment_name
  @errand_name = errand_name
  @deployment_manager = Api::DeploymentManager.new
  @instance_manager = Api::InstanceManager.new
  @keep_alive = keep_alive
  blobstore = App.instance.blobstores.blobstore
  log_bundles_cleaner = LogBundlesCleaner.new(blobstore, 60 * 60 * 24 * 10, logger) # 10 days
  @logs_fetcher = LogsFetcher.new(@instance_manager, log_bundles_cleaner, logger)
end

Class Method Details

.job_typeObject



9
10
11
# File 'lib/bosh/director/jobs/run_errand.rb', line 9

def self.job_type
  :run_errand
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
# File 'lib/bosh/director/jobs/run_errand.rb', line 24

def perform
  deployment_model = @deployment_manager.find_by_name(@deployment_name)
  deployment_manifest = Manifest.load_from_text(deployment_model.manifest, deployment_model.cloud_config, deployment_model.runtime_config)
  deployment_name = deployment_manifest.to_hash['name']
  with_deployment_lock(deployment_name) do
    deployment = nil
    job = nil

    event_log_stage = Config.event_log.begin_stage('Preparing deployment', 1)
    event_log_stage.advance_and_track('Preparing deployment') do
      planner_factory = DeploymentPlan::PlannerFactory.create(logger)
      deployment = planner_factory.create_from_manifest(deployment_manifest, deployment_model.cloud_config, deployment_model.runtime_config, {})
      deployment.bind_models
      job = deployment.instance_group(@errand_name)

      if job.nil?
        raise JobNotFound, "Errand '#{@errand_name}' doesn't exist"
      end

      unless job.is_errand?
        raise RunErrandError,
          "Instance group '#{job.name}' is not an errand. To mark an instance group as an errand " +
            "set its lifecycle to 'errand' in the deployment manifest."
      end

      if job.instances.empty?
        raise InstanceNotFound, "Instance '#{@deployment_name}/#{@errand_name}/0' doesn't exist"
      end

      logger.info('Starting to prepare for deployment')
      job.bind_instances(deployment.ip_provider)

      JobRenderer.create.render_job_instances(job.needed_instance_plans)
    end

    deployment.compile_packages

    runner = Errand::Runner.new(job, result_file, @instance_manager, @logs_fetcher)

    cancel_blk = lambda {
      begin
        task_checkpoint
      rescue TaskCancelled => e
        runner.cancel
        raise e
      end
    }

    with_updated_instances(deployment, job) do
      logger.info('Starting to run errand')
      runner.run(&cancel_blk)
    end
  end
end

#task_cancelled?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/bosh/director/jobs/run_errand.rb', line 79

def task_cancelled?
  super unless @ignore_cancellation
end