Skip to content

Commit 1f7e419

Browse files
committed
remove calculators
1 parent e389879 commit 1f7e419

File tree

5 files changed

+54
-69
lines changed

5 files changed

+54
-69
lines changed

lib/cloud_controller/deployment_updater/actions/canary.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'cloud_controller/deployment_updater/actions/scale_down_canceled'
2-
require 'cloud_controller/deployment_updater/calculators/all_instances_routable'
32

43
module VCAP::CloudController
54
module DeploymentUpdater
@@ -16,7 +15,7 @@ def call
1615
deployment.db.transaction do
1716
deployment.lock!
1817
return unless deployment.state == DeploymentModel::PREPAUSED_STATE
19-
return unless Calculators::AllInstancesRoutable.new(deployment, logger).call
18+
return unless all_instances_routable?
2019

2120
ScaleDownCanceled.new(deployment).call
2221

@@ -29,6 +28,20 @@ def call
2928
logger.info("paused-canary-deployment-for-#{deployment.guid}")
3029
end
3130
end
31+
32+
private
33+
34+
def all_instances_routable?
35+
instances = instance_reporters.all_instances_for_app(deployment.deploying_web_process)
36+
instances.all? { |_, val| val[:state] == VCAP::CloudController::Diego::LRP_RUNNING && val[:routable] }
37+
rescue CloudController::Errors::ApiError # the instances_reporter re-raises InstancesUnavailable as ApiError
38+
logger.info("skipping-canary-update-for-#{deployment.guid}")
39+
false
40+
end
41+
42+
def instance_reporters
43+
CloudController::DependencyLocator.instance.instances_reporters
44+
end
3245
end
3346
end
3447
end

lib/cloud_controller/deployment_updater/actions/cancel.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'cloud_controller/deployment_updater/calculators/find_interim_web_process'
21
module VCAP::CloudController
32
module DeploymentUpdater
43
module Actions
@@ -19,7 +18,7 @@ def call
1918

2019
deploying_web_process.lock!
2120

22-
prior_web_process = Calculators::FindInterimWebProcess.new(deployment).call || app.oldest_web_process
21+
prior_web_process = find_interim_web_process || app.oldest_web_process
2322
prior_web_process.lock!
2423

2524
prior_web_process.update(instances: deployment.original_web_process_instance_count)
@@ -33,6 +32,31 @@ def call
3332
)
3433
end
3534
end
35+
36+
private
37+
38+
def find_interim_web_process
39+
# Find newest interim web process that (a) belongs to a SUPERSEDED (DEPLOYED) deployment and (b) has at least
40+
# one running instance.
41+
app.web_processes_dataset.
42+
qualify.
43+
join(:deployments, deploying_web_process_guid: :guid).
44+
where(deployments__state: DeploymentModel::DEPLOYED_STATE).
45+
where(deployments__status_reason: DeploymentModel::SUPERSEDED_STATUS_REASON).
46+
order(Sequel.desc(:created_at), Sequel.desc(:id)).
47+
find { |p| has_running_instance?(p) }
48+
end
49+
50+
def has_running_instance?(process)
51+
instances = instance_reporters.all_instances_for_app(process)
52+
instances.any? { |_, val| val[:state] == VCAP::CloudController::Diego::LRP_RUNNING }
53+
rescue CloudController::Errors::ApiError # the instances_reporter re-raises InstancesUnavailable as ApiError
54+
false
55+
end
56+
57+
def instance_reporters
58+
CloudController::DependencyLocator.instance.instances_reporters
59+
end
3660
end
3761
end
3862
end

lib/cloud_controller/deployment_updater/actions/scale.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'cloud_controller/deployment_updater/actions/scale_down_canceled'
22
require 'cloud_controller/deployment_updater/actions/scale_down_old_process'
33
require 'cloud_controller/deployment_updater/actions/finalize'
4-
require 'cloud_controller/deployment_updater/calculators/all_instances_routable'
54

65
module VCAP::CloudController
76
module DeploymentUpdater
@@ -18,7 +17,7 @@ def initialize(deployment, logger)
1817
def call
1918
deployment.db.transaction do
2019
return unless deployment.lock!.state == DeploymentModel::DEPLOYING_STATE
21-
return unless Calculators::AllInstancesRoutable.new(deployment, logger).call
20+
return unless all_instances_routable?
2221

2322
app.lock!
2423
oldest_web_process_with_instances.lock!
@@ -60,6 +59,18 @@ def oldest_web_process_with_instances
6059
def deploying_web_process
6160
@deploying_web_process ||= deployment.deploying_web_process
6261
end
62+
63+
def all_instances_routable?
64+
instances = instance_reporters.all_instances_for_app(deployment.deploying_web_process)
65+
instances.all? { |_, val| val[:state] == VCAP::CloudController::Diego::LRP_RUNNING && val[:routable] }
66+
rescue CloudController::Errors::ApiError # the instances_reporter re-raises InstancesUnavailable as ApiError
67+
logger.info("skipping-deployment-update-for-#{deployment.guid}")
68+
false
69+
end
70+
71+
def instance_reporters
72+
CloudController::DependencyLocator.instance.instances_reporters
73+
end
6374
end
6475
end
6576
end

lib/cloud_controller/deployment_updater/calculators/all_instances_routable.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

lib/cloud_controller/deployment_updater/calculators/find_interim_web_process.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)