Class: Bosh::Director::DeploymentPlan::InstancePlanSorter
- Defined in:
- lib/bosh/director/deployment_plan/instance_plan_sorter.rb
Instance Method Summary collapse
-
#initialize(logger) ⇒ InstancePlanSorter
constructor
A new instance of InstancePlanSorter.
- #sort(instance_plans) ⇒ Object
Constructor Details
#initialize(logger) ⇒ InstancePlanSorter
Returns a new instance of InstancePlanSorter.
3 4 5 |
# File 'lib/bosh/director/deployment_plan/instance_plan_sorter.rb', line 3 def initialize(logger) @logger = logger end |
Instance Method Details
#sort(instance_plans) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bosh/director/deployment_plan/instance_plan_sorter.rb', line 7 def sort(instance_plans) return [] if instance_plans.empty? @logger.debug('Sorting instance plan to update them always in the same order') @sorted_instance_plans = [] bootstrap_instance_plan = instance_plans.find { |instance_plan| instance_plan.instance.bootstrap? } @sorted_instance_plans << bootstrap_instance_plan bootstrap_az = bootstrap_instance_plan.instance.availability_zone_name remaining_instance_plans = instance_plans - [bootstrap_instance_plan] sorted_instance_plans_for_bootstrap_az = sorted_instance_plans_in_special_az(bootstrap_az, remaining_instance_plans) remaining_instance_plans = remaining_instance_plans - sorted_instance_plans_for_bootstrap_az sorted_instance_plans_for_no_az = sorted_instance_plans_in_special_az(nil, remaining_instance_plans) remaining_instance_plans = remaining_instance_plans - sorted_instance_plans_for_no_az instance_plans_sorted_by_az = remaining_instance_plans.sort do |plan1, plan2| plan1.instance.availability_zone_name <=> plan2.instance.availability_zone_name end current_az = instance_plans_sorted_by_az.first.instance.availability_zone_name if instance_plans_sorted_by_az.any? instance_plans_in_current_az = [] instance_plans_sorted_by_az.each do |instance_plan| if instance_plan.instance.availability_zone_name == current_az instance_plans_in_current_az << instance_plan else @sorted_instance_plans << sort_in_az(instance_plans_in_current_az) current_az = instance_plan.instance.availability_zone_name instance_plans_in_current_az = [instance_plan] end end @sorted_instance_plans << sort_in_az(instance_plans_in_current_az) @sorted_instance_plans.flatten end |