Skip to content

Commit c223429

Browse files
committed
Rename 'lb_algo' and 'loadbalancing-algorithm' to 'algorithm'
Fix tests
1 parent 436e963 commit c223429

File tree

16 files changed

+77
-77
lines changed

16 files changed

+77
-77
lines changed

app/messages/manifest_routes_update_message.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def contains_non_route_hash_values?(routes)
2727
validate :routes_are_uris, if: proc { |record| record.requested?(:routes) }
2828
validate :route_protocols_are_valid, if: proc { |record| record.requested?(:routes) }
2929
validate :route_options_are_valid, if: proc { |record| record.requested?(:routes) }
30-
validate :lb_algos_are_valid, if: proc { |record| record.requested?(:routes) }
30+
validate :loadbalancings_are_valid, if: proc { |record| record.requested?(:routes) }
3131
validate :no_route_is_boolean
3232
validate :default_route_is_boolean
3333
validate :random_route_is_boolean
@@ -65,16 +65,16 @@ def route_options_are_valid
6565
end
6666
end
6767

68-
def lb_algos_are_valid
68+
def loadbalancings_are_valid
6969
return if errors[:routes].present?
7070

7171
routes.each do |r|
72-
next unless r[:options] && r[:options][:'loadbalancing-algorithm']
72+
next unless r[:options] && r[:options][:'loadbalancing']
7373

74-
lb_algo = r[:options][:'loadbalancing-algorithm']
75-
RouteOptionsMessage::VALID_LOADBALANCING_ALGORITHMS.exclude?(lb_algo) &&
74+
loadbalancing = r[:options][:'loadbalancing']
75+
RouteOptionsMessage::VALID_LOADBALANCING_ALGORITHMS.exclude?(loadbalancing) &&
7676
errors.add(:base,
77-
message: "Route '#{r[:route]}' contains invalid load-balancing algorithm '#{lb_algo}'. \
77+
message: "Route '#{r[:route]}' contains invalid load-balancing algorithm '#{loadbalancing}'. \
7878
Valid algorithms: '#{RouteOptionsMessage::VALID_LOADBALANCING_ALGORITHMS.join(', ')}'")
7979
end
8080
end

app/messages/route_options_message.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
module VCAP::CloudController
44
class RouteOptionsMessage < BaseMessage
5-
VALID_MANIFEST_ROUTE_OPTIONS = %i[loadbalancing-algorithm].freeze
6-
VALID_ROUTE_OPTIONS = %i[lb_algo].freeze
5+
VALID_MANIFEST_ROUTE_OPTIONS = %i[loadbalancing].freeze
6+
VALID_ROUTE_OPTIONS = %i[loadbalancing].freeze
77
VALID_LOADBALANCING_ALGORITHMS = %w[round-robin least-connections].freeze
88

99
register_allowed_keys VALID_ROUTE_OPTIONS
1010
validates_with NoAdditionalKeysValidator
11-
validates :lb_algo,
12-
inclusion: { in: VALID_LOADBALANCING_ALGORITHMS, message: "'%<value>s' is not a supported load-balancing algorithm" },
11+
validates :loadbalancing,
12+
inclusion: { in: VALID_LOADBALANCING_ALGORITHMS, message: "'%<value>s' is not supported" },
1313
presence: true,
1414
allow_nil: true
1515
end

app/presenters/v3/app_manifest_presenters/route_properties_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def to_hash(route_mappings:, app:, **_)
1212

1313
if route_mapping.route.options
1414
route_hash[:options] = {}
15-
route_hash[:options][:'loadbalancing-algorithm'] = route_mapping.route.options[:lb_algo] if route_mapping.route.options[:lb_algo]
15+
route_hash[:options][:'loadbalancing'] = route_mapping.route.options[:loadbalancing] if route_mapping.route.options[:loadbalancing]
1616
end
1717

1818
route_hash

docs/v3/source/includes/api_resources/_routes.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636
],
3737
"options": {
38-
"lb_algo": "round-robin"
38+
"loadbalancing": "round-robin"
3939
},
4040
"metadata": {
4141
"labels": <%= metadata.fetch(:labels, {}).to_json(space: ' ', object_nl: ' ')%>,
@@ -128,7 +128,7 @@
128128
}
129129
],
130130
"options": {
131-
"lb_algo": "round-robin"
131+
"loadbalancing": "round-robin"
132132
},
133133
"metadata": {
134134
"labels": {},
@@ -221,6 +221,6 @@
221221

222222
<% content_for :route_options do %>
223223
{
224-
"lb_algo": "round-robin"
224+
"loadbalancing": "round-robin"
225225
}
226226
<% end %>

docs/v3/source/includes/resources/routes/_create.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ curl "https://api.example.org/v3/routes" \
2222
}
2323
},
2424
"options": {
25-
"lb_algo": "round-robin"
25+
"loadbalancing": "round-robin"
2626
}
2727
"metadata": {
2828
"labels": { "key": "value" },

docs/v3/source/includes/resources/routes/_route_options_object.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Example Route-Options object
99

1010
| Name | Type | Description |
1111
|-------------|----------|----------------------------------------------------------------------------------------------------------|
12-
| **lb_algo** | _string_ | The load balancer associated with this route. Valid algorithms are 'round-robin' and 'least-connections' |
12+
| **loadbalancing** | _string_ | The load balancer associated with this route. Valid algorithms are 'round-robin' and 'least-connections' |

docs/v3/source/includes/resources/routes/_update.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ curl "https://api.example.org/v3/routes/[guid]" \
1111
-H "Content-type: application/json" \
1212
-d '{
1313
"options": {
14-
"lb_algo": "round-robin"
14+
"loadbalancing": "round-robin"
1515
}
1616
"metadata": {
1717
"labels": {"key": "value"},

lib/cloud_controller/app_manifest/manifest_route.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def self.parse(route, options=nil)
1717

1818
attrs[:full_route] = route
1919
attrs[:options] = {}
20-
attrs[:options][:lb_algo] = options[:'loadbalancing-algorithm'] if options && options.key?(:'loadbalancing-algorithm')
20+
attrs[:options][:loadbalancing] = options[:'loadbalancing'] if options && options.key?(:'loadbalancing')
2121

2222
ManifestRoute.new(attrs)
2323
end

spec/request/space_manifests_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -647,20 +647,20 @@
647647

648648
expect(last_response).to have_status_code(422)
649649
expect(last_response).to have_error_message("For application '#{app1_model.name}': \
650-
Route 'https://#{route.host}.#{route.domain.name}' contains invalid route option 'doesnt-exist'. Valid keys: 'loadbalancing-algorithm'")
650+
Route 'https://#{route.host}.#{route.domain.name}' contains invalid route option 'doesnt-exist'. Valid keys: 'loadbalancing'")
651651
end
652652
end
653653

654654
context 'updating existing route options' do
655-
# using loadbalancing-algorithm as an example since it is the only route option currently supported
655+
# using loadbalancing as an example since it is the only route option currently supported
656656
before do
657657
yml_manifest = {
658658
'applications' => [
659659
{ 'name' => app1_model.name,
660660
'routes' => [
661661
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
662662
'options' => {
663-
'loadbalancing-algorithm' => 'round-robin'
663+
'loadbalancing' => 'round-robin'
664664
} }
665665
] }
666666
]
@@ -675,7 +675,7 @@
675675
Delayed::Worker.new.work_off
676676
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
677677
app1_model.reload
678-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
678+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'round-robin' })
679679
end
680680

681681
it 'updates the route option when a new value is provided' do
@@ -685,7 +685,7 @@
685685
'routes' => [
686686
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
687687
'options' => {
688-
'loadbalancing-algorithm' => 'least-connections'
688+
'loadbalancing' => 'least-connections'
689689
} }
690690
] }
691691
]
@@ -699,7 +699,7 @@
699699
Delayed::Worker.new.work_off
700700
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
701701
app1_model.reload
702-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'least-connections' })
702+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'least-connections' })
703703
end
704704

705705
it 'does not modify any route options when the options hash is not provided' do
@@ -721,7 +721,7 @@
721721
Delayed::Worker.new.work_off
722722
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
723723
app1_model.reload
724-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
724+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'round-robin' })
725725
end
726726

727727
it 'does not modify any route options options: nil is provided' do
@@ -744,7 +744,7 @@
744744
Delayed::Worker.new.work_off
745745
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
746746
app1_model.reload
747-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
747+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'round-robin' })
748748
end
749749

750750
it 'does not modify any route options if an empty options hash is provided' do
@@ -764,7 +764,7 @@
764764
expect(last_response.status).to eq(202)
765765

766766
app1_model.reload
767-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
767+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'round-robin' })
768768
end
769769

770770
it 'does not modify any option when options: { key: nil } is provided' do
@@ -774,7 +774,7 @@
774774
'routes' => [
775775
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
776776
'options' => {
777-
'loadbalancing-algorithm' => nil
777+
'loadbalancing' => nil
778778
} }
779779
] }
780780
]
@@ -786,12 +786,12 @@
786786
expect(last_response.status).to eq(202)
787787

788788
app1_model.reload
789-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
789+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'round-robin' })
790790
end
791791
end
792792

793-
context 'route-option: loadbalancing-algorithm' do
794-
context 'when the loadbalancing-algorithm is not supported' do
793+
context 'route-option: loadbalancing' do
794+
context 'when the loadbalancing is not supported' do
795795
let(:yml_manifest) do
796796
{
797797
'applications' => [
@@ -800,7 +800,7 @@
800800
'routes' => [
801801
{ 'route' => "https://#{route.host}.#{route.domain.name}",
802802
'options' => {
803-
'loadbalancing-algorithm' => 'unsupported-lb-algorithm'
803+
'loadbalancing' => 'unsupported-lb-algorithm'
804804
} }
805805
]
806806
}
@@ -817,22 +817,22 @@
817817
end
818818
end
819819

820-
context 'when the loadbalancing-algorithm is supported' do
820+
context 'when the loadbalancing is supported' do
821821
let(:yml_manifest) do
822822
{
823823
'applications' => [
824824
{ 'name' => app1_model.name,
825825
'routes' => [
826826
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
827827
'options' => {
828-
'loadbalancing-algorithm' => 'round-robin'
828+
'loadbalancing' => 'round-robin'
829829
} }
830830
] }
831831
]
832832
}.to_yaml
833833
end
834834

835-
it 'adds the loadbalancing-algorithm' do
835+
it 'adds the loadbalancing' do
836836
post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header)
837837

838838
expect(last_response.status).to eq(202)
@@ -842,7 +842,7 @@
842842
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
843843

844844
app1_model.reload
845-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
845+
expect(app1_model.routes.first.options).to eq({ 'loadbalancing' => 'round-robin' })
846846
end
847847
end
848848
end

spec/unit/actions/route_update_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module VCAP::CloudController
1717
}
1818
end
1919
let(:old_options) do
20-
'{"lb_algo": "round-robin"}'
20+
'{"loadbalancing": "round-robin"}'
2121
end
2222
let(:new_labels) do
2323
{
@@ -153,7 +153,7 @@ module VCAP::CloudController
153153
let(:body) do
154154
{
155155
options: {
156-
lb_algo: 'round-robin'
156+
loadbalancing: 'round-robin'
157157
}
158158
}
159159
end
@@ -163,14 +163,14 @@ module VCAP::CloudController
163163
subject.update(route:, message:)
164164

165165
route.reload
166-
expect(route[:options]).to eq('{"lb_algo":"round-robin"}')
166+
expect(route[:options]).to eq('{"loadbalancing":"round-robin"}')
167167
end
168168
end
169169
end
170170

171171
context 'when the route has existing options' do
172172
before do
173-
route[:options] = '{"lb_algo": "round-robin"}'
173+
route[:options] = '{"loadbalancing": "round-robin"}'
174174
end
175175

176176
context 'when no options are specified' do
@@ -182,15 +182,15 @@ module VCAP::CloudController
182182
expect(message).to be_valid
183183
subject.update(route:, message:)
184184
route.reload
185-
expect(route.options).to include({ 'lb_algo' => 'round-robin' })
185+
expect(route.options).to include({ 'loadbalancing' => 'round-robin' })
186186
end
187187
end
188188

189189
context 'when an option is specified' do
190190
let(:body) do
191191
{
192192
options: {
193-
lb_algo: 'least-connections'
193+
loadbalancing: 'least-connections'
194194
}
195195
}
196196
end
@@ -200,15 +200,15 @@ module VCAP::CloudController
200200
subject.update(route:, message:)
201201
route.reload
202202

203-
expect(route.options).to include({ 'lb_algo' => 'least-connections' })
203+
expect(route.options).to include({ 'loadbalancing' => 'least-connections' })
204204
end
205205
end
206206

207207
context 'when the option value is set to null' do
208208
let(:body) do
209209
{
210210
options: {
211-
lb_algo: nil
211+
loadbalancing: nil
212212
}
213213
}
214214
end

0 commit comments

Comments
 (0)