Skip to content

Commit 622df2c

Browse files
Samzesethboyles
authored andcommitted
Add canary steps to presenter
1 parent 1066ad2 commit 622df2c

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

app/presenters/v3/deployment_presenter.rb

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ def to_hash
1010
guid: deployment.guid,
1111
created_at: deployment.created_at,
1212
updated_at: deployment.updated_at,
13-
status: {
14-
value: deployment.status_value,
15-
reason: deployment.status_reason,
16-
details: {
17-
last_successful_healthcheck: deployment.last_healthy_at,
18-
last_status_change: deployment.status_updated_at
19-
}
20-
},
13+
status: build_status(deployment),
2114
strategy: deployment.strategy,
2215
options: {
2316
max_in_flight: deployment.max_in_flight
@@ -64,6 +57,29 @@ def new_processes
6457
end
6558
end
6659

60+
def build_status(deployment)
61+
status = {
62+
value: deployment.status_value,
63+
reason: deployment.status_reason,
64+
details: {
65+
last_successful_healthcheck: deployment.last_healthy_at,
66+
last_status_change: deployment.status_updated_at
67+
}
68+
}
69+
70+
if deployment.strategy == VCAP::CloudController::DeploymentModel::CANARY_STRATEGY
71+
status[:canary] = {
72+
steps: {
73+
# TODO: delegate to model ?
74+
current: deployment.canary_current_step,
75+
total: deployment.canary_steps&.length || 1
76+
}
77+
}
78+
end
79+
80+
status
81+
end
82+
6783
def build_links
6884
{
6985
self: {

spec/unit/presenters/v3/deployment_presenter_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,53 @@ module VCAP::CloudController::Presenters::V3
128128
end
129129
end
130130
end
131+
132+
describe 'status' do
133+
context 'when the strategy is rolling' do
134+
before do
135+
deployment.strategy = VCAP::CloudController::DeploymentModel::ROLLING_STRATEGY
136+
end
137+
138+
it 'shows no canary status' do
139+
result = DeploymentPresenter.new(deployment).to_hash
140+
expect(result[:status][:canary]).to be_nil
141+
end
142+
end
143+
144+
context 'when the strategy is canary' do
145+
before do
146+
deployment.strategy = VCAP::CloudController::DeploymentModel::CANARY_STRATEGY
147+
deployment.canary_current_step = 1
148+
end
149+
150+
context 'when there are no explicit steps' do
151+
it 'presents the canary status' do
152+
result = DeploymentPresenter.new(deployment).to_hash
153+
expect(result[:status][:canary][:steps][:current]).to eq(1)
154+
expect(result[:status][:canary][:steps][:total]).to eq(1)
155+
end
156+
end
157+
158+
context 'when there are explicit steps' do
159+
before do
160+
deployment.strategy = VCAP::CloudController::DeploymentModel::CANARY_STRATEGY
161+
deployment.canary_current_step = 2
162+
deployment.canary_steps = [
163+
{ instance_weight: 1 },
164+
{ instance_weight: 2 },
165+
{ instance_weight: 3 },
166+
{ instance_weight: 4 }
167+
]
168+
end
169+
170+
it 'presents the canary status' do
171+
result = DeploymentPresenter.new(deployment).to_hash
172+
expect(result[:status][:canary][:steps][:current]).to eq(2)
173+
expect(result[:status][:canary][:steps][:total]).to eq(4)
174+
end
175+
end
176+
end
177+
end
131178
end
132179
end
133180
end

0 commit comments

Comments
 (0)