Class: Bosh::Director::DeploymentPlan::InstancePlanner

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/instance_planner.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance_plan_factory, logger) ⇒ InstancePlanner

Returns a new instance of InstancePlanner.



5
6
7
8
# File 'lib/bosh/director/deployment_plan/instance_planner.rb', line 5

def initialize(instance_plan_factory, logger)
  @instance_plan_factory = instance_plan_factory
  @logger = logger
end

Instance Method Details

#plan_job_instances(job, desired_instances, existing_instance_models) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bosh/director/deployment_plan/instance_planner.rb', line 10

def plan_job_instances(job, desired_instances, existing_instance_models)
  if existing_instance_models.count(&:ignore) > 0
    fail_if_specifically_changing_state_of_ignored_vms(job, existing_instance_models)
  end

  network_planner = NetworkPlanner::Planner.new(@logger)
  placement_plan = PlacementPlanner::Plan.new(@instance_plan_factory, network_planner, @logger)
  vip_networks, non_vip_networks = job.networks.to_a.partition(&:vip?)
  instance_plans = placement_plan.create_instance_plans(desired_instances, existing_instance_models, non_vip_networks, job.availability_zones, job.name)

  log_outcome(instance_plans)

  desired_instance_plans = instance_plans.reject(&:obsolete?)
  vip_static_ips_planner = NetworkPlanner::VipStaticIpsPlanner.new(network_planner, @logger)
  vip_static_ips_planner.add_vip_network_plans(desired_instance_plans, vip_networks)
  reconcile_network_plans(desired_instance_plans)

  elect_bootstrap_instance(desired_instance_plans)

  instance_plans
end

#plan_obsolete_jobs(desired_jobs, existing_instances) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bosh/director/deployment_plan/instance_planner.rb', line 32

def plan_obsolete_jobs(desired_jobs, existing_instances)
  desired_job_names = Set.new(desired_jobs.map(&:name))
  migrating_job_names = Set.new(desired_jobs.map(&:migrated_from).flatten.map(&:name))
  obsolete_existing_instances = existing_instances.reject do |existing_instance_model|
    desired_job_names.include?(existing_instance_model.job) ||
      migrating_job_names.include?(existing_instance_model.job)
  end

  obsolete_existing_instances.each do |instance_model|
    if instance_model.ignore
      raise DeploymentIgnoredInstancesDeletion, "You are trying to delete instance group '#{instance_model.job}', which " +
          'contains ignored instance(s). Operation not allowed.'
    end
  end

  obsolete_existing_instances.map do |obsolete_existing_instance|
    @instance_plan_factory.obsolete_instance_plan(obsolete_existing_instance)
  end
end