-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breakout Scale into UpScale/DownScale actions
* also move logic into instance_reporters
- Loading branch information
1 parent
c778add
commit 8de2953
Showing
12 changed files
with
539 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lib/cloud_controller/deployment_updater/actions/down_scaler.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'cloud_controller/deployment_updater/actions/scale_down_old_process' | ||
module VCAP::CloudController | ||
module DeploymentUpdater | ||
module Actions | ||
class DownScaler | ||
attr_reader :deployment, :logger, :app, :target_total_instance_count | ||
|
||
def initialize(deployment, logger, target_total_instance_count, routable_instance_count) | ||
@deployment = deployment | ||
@app = deployment.app | ||
@logger = logger | ||
@target_total_instance_count = target_total_instance_count | ||
@routable_instance_count = routable_instance_count | ||
end | ||
|
||
def scale_down | ||
instances_to_reduce = non_deploying_web_processes.map(&:instances).sum - desired_non_deploying_instances | ||
|
||
return if instances_to_reduce <= 0 | ||
|
||
non_deploying_web_processes.each do |process| | ||
if instances_to_reduce < process.instances | ||
ScaleDownOldProcess.new(deployment, process, process.instances - instances_to_reduce).call | ||
break | ||
end | ||
|
||
instances_to_reduce -= process.instances | ||
ScaleDownOldProcess.new(deployment, process, 0).call | ||
end | ||
end | ||
|
||
def can_downscale? | ||
non_deploying_web_processes.map(&:instances).sum > desired_non_deploying_instances | ||
end | ||
|
||
def desired_non_deploying_instances | ||
[target_total_instance_count - @routable_instance_count, 0].max | ||
end | ||
|
||
private | ||
|
||
def non_deploying_web_processes | ||
app.web_processes.reject { |process| process.guid == deployment.deploying_web_process.guid }.sort_by { |p| [p.created_at, p.id] } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lib/cloud_controller/deployment_updater/actions/up_scaler.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module VCAP::CloudController | ||
module DeploymentUpdater | ||
module Actions | ||
class UpScaler | ||
attr_reader :deployment, :logger, :app, :interim_desired_instance_count | ||
|
||
def initialize(deployment, logger, interim_desired_instance_count, instance_count_summary) | ||
@deployment = deployment | ||
@app = deployment.app | ||
@logger = logger | ||
@interim_desired_instance_count = interim_desired_instance_count | ||
@starting_instances_count = instance_count_summary.starting_instances_count | ||
@unhealthy_instances_count = instance_count_summary.unhealthy_instances_count | ||
@routable_instances_count = instance_count_summary.routable_instances_count | ||
end | ||
|
||
def scale_up | ||
return unless can_scale? | ||
|
||
deploying_web_process.update(instances: desired_new_instances) | ||
deployment.update(last_healthy_at: Time.now) | ||
end | ||
|
||
def can_scale? | ||
@starting_instances_count < deployment.max_in_flight && | ||
@unhealthy_instances_count == 0 && | ||
# if routable instances is < deploying_web_process.instances - deployment.max_in_flight | ||
# then that indicates that Diego isnt in sync with CAPI yet | ||
@routable_instances_count >= deploying_web_process.instances - deployment.max_in_flight | ||
end | ||
|
||
def finished_scaling? | ||
deploying_web_process.instances >= interim_desired_instance_count | ||
end | ||
|
||
private | ||
|
||
def desired_new_instances | ||
[@routable_instances_count + deployment.max_in_flight, interim_desired_instance_count].min | ||
end | ||
|
||
def deploying_web_process | ||
@deploying_web_process ||= deployment.deploying_web_process | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.