Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 0ca59fd

Browse files
Remove the state from service brokers API
[#172646313](https://www.pivotaltracker.com/story/show/172646313)
1 parent 9d48077 commit 0ca59fd

10 files changed

Lines changed: 33 additions & 136 deletions

File tree

app/presenters/v3/service_broker_presenter.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,11 @@ module V3
1010
class ServiceBrokerPresenter < BasePresenter
1111
include VCAP::CloudController::Presenters::Mixins::MetadataPresentationHelpers
1212

13-
STATES = {
14-
VCAP::CloudController::ServiceBrokerStateEnum::SYNCHRONIZING => 'synchronization in progress',
15-
VCAP::CloudController::ServiceBrokerStateEnum::SYNCHRONIZATION_FAILED => 'synchronization failed',
16-
VCAP::CloudController::ServiceBrokerStateEnum::AVAILABLE => 'available',
17-
VCAP::CloudController::ServiceBrokerStateEnum::DELETE_IN_PROGRESS => 'delete in progress',
18-
VCAP::CloudController::ServiceBrokerStateEnum::DELETE_FAILED => 'delete failed'
19-
}.tap { |s| s.default = 'available' }.freeze
20-
2113
def to_hash
2214
{
2315
guid: broker.guid,
2416
name: broker.name,
2517
url: broker.broker_url,
26-
status: status,
2718
created_at: broker.created_at,
2819
updated_at: broker.updated_at,
2920
relationships: build_relationships,
@@ -41,10 +32,6 @@ def broker
4132
@resource
4233
end
4334

44-
def status
45-
STATES[broker.state]
46-
end
47-
4835
def build_relationships
4936
if broker.space_guid.nil?
5037
{}

docs/v3/source/includes/experimental_resources/service_brokers/_create.md.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ Content-Type: application/json
3939
Location: https://api.example.org/v3/jobs/af5c57f6-8769-41fa-a499-2c84ed896788
4040
```
4141

42-
This endpoint creates a new service broker and a job to synchronize the service offerings and service plans with those in the broker's catalog. The `Location` header refers to the created job which syncs the broker with the catalog.
42+
This endpoint creates a new service broker and a job to synchronize the service offerings and service plans with those in the broker's catalog.
43+
The `Location` header refers to the created job which syncs the broker with the catalog. See [_Service broker jobs_](#service-broker-jobs) for more information and limitations.
44+
4345

4446
#### Definition
4547
`POST /v3/service_brokers`

docs/v3/source/includes/experimental_resources/service_brokers/_delete.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Content-Type: application/json
2020
Location: https://api.example.org/v3/jobs/af5c57f6-8769-41fa-a499-2c84ed896788
2121
```
2222

23-
This endpoint creates a job to delete an existing service broker. The `Location` header refers to the created job.
23+
This endpoint creates a job to delete an existing service broker. The `Location` header refers to the created job. See [_Service broker jobs_](#service-broker-jobs) for more information and limitations.
2424

2525
#### Definition
2626
`DELETE /v3/service_brokers/:guid`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Service Broker Jobs
2+
3+
CRUD operations for service brokers are asynchronous. `create`, `update` and `delete` endpoints return urls to `jobs` in the `Location` header of the HTTP response.
4+
5+
These jobs are the only source of information about the progress and end state of the operation. Therefore, the job must be polled to find out when the process ends and if it was successful.
6+
It's also worth noting that there is no mechanism to link a service broker with its jobs, apart from the `Location` header in the API response.
7+
8+
When a failure occurs during a create job, then the service broker won't be usable. However it will still be included in the `GET` endpoints responses, hence the importance of querying the job to find out the end status.
9+
10+
When updating a service broker, the changes will be rollbacked in the event the job fails. The service broker will remain unchanged with no indication that the update operation failed. Querying the job will provide such information.
11+

docs/v3/source/includes/experimental_resources/service_brokers/_object.md.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Name | Type | Description
1212
**guid** | _uuid_ | Unique identifier for the service broker.
1313
**name** | _string_ | Name of the service broker.
1414
**url** | _string_ | URL of the service broker.
15-
**status** | _string_ | Availability status of the service broker.
1615
**created_at** | _datetime_ | The time with zone when the object was created.
1716
**updated_at** | _datetime_ | The time with zone when the object was last updated.
1817
**relationships.space** | [_to-one relationship_](#to-one-relationships) | The space the service broker is restricted to. Omitted for globally available service brokers.

docs/v3/source/includes/experimental_resources/service_brokers/_update.md.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Content-Type: application/json
3636
Location: https://api.example.org/v3/jobs/af5c57f6-8769-41fa-a499-2c84ed896788
3737
```
3838

39-
This endpoint updates a broker and creates a job to synchronize the service offerings and service plans with those in the broker's catalog. The `Location` header refers to the created job which syncs the broker with the catalog.
39+
This endpoint updates a broker and creates a job to synchronize the service offerings and service plans with those in the broker's catalog.
40+
The `Location` header refers to the created job which syncs the broker with the catalog. See [_Service broker jobs_](#service-broker-jobs) for more information and limitations.
41+
4042
Service Brokers that are in the process of being synchronized or deleted cannot be updated.
4143

4244
#### Definition

docs/v3/source/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ includes:
312312
- experimental_resources/service_brokers/list
313313
- experimental_resources/service_brokers/update
314314
- experimental_resources/service_brokers/delete
315+
- experimental_resources/service_brokers/jobs
315316
- experimental_resources/service_offerings/header
316317
- experimental_resources/service_offerings/visibility
317318
- experimental_resources/service_offerings/object

spec/request/lifecycle/service_brokers_spec.rb

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,11 @@
4646
expect(parsed_response['state']).to eq('PROCESSING')
4747
broker = parsed_response.dig('links', 'service_brokers', 'href')
4848

49-
# Check it's in progress
50-
get broker, {}, admin_headers
51-
expect(last_response).to have_status_code(200)
52-
expect(parsed_response).to include(
53-
'name' => 'my-service-broker',
54-
'url' => 'http://example.org/my-service-broker-url',
55-
'status' => 'synchronization in progress',
56-
)
57-
5849
# Check it finishes
5950
execute_all_jobs(expected_successes: 1, expected_failures: 0)
6051
get job_url_for_create, {}, admin_headers
6152
expect(last_response).to have_status_code(200)
6253
expect(parsed_response['state']).to eq('COMPLETE')
63-
64-
# Check it's correct
65-
get broker, {}, admin_headers
66-
expect(last_response).to have_status_code(200)
67-
expect(parsed_response).to include(
68-
'name' => 'my-service-broker',
69-
'url' => 'http://example.org/my-service-broker-url',
70-
'status' => 'available',
71-
)
7254
end
7355
end
7456

@@ -90,15 +72,6 @@
9072
get job_url_for_create, {}, admin_headers
9173
expect(last_response).to have_status_code(200)
9274
expect(parsed_response['state']).to eq('FAILED')
93-
94-
# Check it's in failed state
95-
get parsed_response.dig('links', 'service_brokers', 'href'), {}, admin_headers
96-
expect(last_response).to have_status_code(200)
97-
expect(parsed_response).to include(
98-
'name' => 'my-service-broker',
99-
'url' => 'http://example.org/my-service-broker-url',
100-
'status' => 'synchronization failed',
101-
)
10275
end
10376
end
10477

@@ -189,7 +162,7 @@
189162
type: 'basic',
190163
credentials: {
191164
username: 'old-admin',
192-
password: 'not-welcome',
165+
password: 'not-welcome'
193166
}
194167
},
195168
metadata: {
@@ -207,7 +180,7 @@
207180
type: 'basic',
208181
credentials: {
209182
username: 'admin',
210-
password: 'welcome',
183+
password: 'welcome'
211184
}
212185
},
213186
metadata: {
@@ -235,7 +208,7 @@
235208
'state' => 'PROCESSING',
236209
'operation' => 'service_broker.update',
237210
'errors' => [],
238-
'warnings' => [],
211+
'warnings' => []
239212
})
240213

241214
execute_all_jobs(expected_successes: 1, expected_failures: 0)
@@ -255,8 +228,7 @@
255228
expect(last_response).to have_status_code(200)
256229
expect(parsed_response).to include({
257230
'name' => 'new-name',
258-
'url' => 'http://example.org/new-broker-url',
259-
'status' => 'available',
231+
'url' => 'http://example.org/new-broker-url'
260232
})
261233
end
262234

@@ -297,7 +269,6 @@
297269
expect(parsed_response).to include({
298270
'name' => 'old-name',
299271
'url' => 'http://example.org/old-broker-url',
300-
'status' => 'available',
301272
'metadata' => {
302273
'annotations' => {
303274
'to_delete' => 'value',

spec/request/service_brokers_spec.rb

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
url: global_service_broker_v3.broker_url,
153153
created_at: iso8601,
154154
updated_at: iso8601,
155-
status: 'available',
156155
relationships: {},
157156
links: {
158157
self: {
@@ -172,7 +171,6 @@
172171
url: global_service_broker_v2.broker_url,
173172
created_at: iso8601,
174173
updated_at: iso8601,
175-
status: 'available',
176174
relationships: {},
177175
links: {
178176
self: {
@@ -211,7 +209,6 @@
211209
url: space_scoped_service_broker.broker_url,
212210
created_at: iso8601,
213211
updated_at: iso8601,
214-
status: 'available',
215212
metadata: { labels: {}, annotations: {} },
216213
relationships: {
217214
space: { data: { guid: space.guid } }
@@ -354,7 +351,6 @@ def expect_empty_list(user_headers)
354351
url: global_service_broker_v3.broker_url,
355352
created_at: iso8601,
356353
updated_at: iso8601,
357-
status: 'available',
358354
metadata: { labels: {}, annotations: {} },
359355
relationships: {},
360356
links: {
@@ -401,7 +397,6 @@ def expect_empty_list(user_headers)
401397
url: space_scoped_service_broker.broker_url,
402398
created_at: iso8601,
403399
updated_at: iso8601,
404-
status: 'available',
405400
metadata: { labels: {}, annotations: {} },
406401
relationships: {
407402
space: { data: { guid: space.guid } }
@@ -710,7 +705,6 @@ def expect_empty_list(user_headers)
710705
url: 'http://example.org/broker-url',
711706
created_at: iso8601,
712707
updated_at: iso8601,
713-
status: 'synchronization in progress',
714708
metadata: { labels: { potato: 'yam' }, annotations: { style: 'mashed' } },
715709
relationships: {},
716710
links: {
@@ -760,7 +754,7 @@ def expect_empty_list(user_headers)
760754
expect(last_response.headers['Location']).to end_with("/v3/jobs/#{job.guid}")
761755
end
762756

763-
it 'creates the services and the plans in the database' do
757+
it 'creates the services and the plans in the database and updates broker state' do
764758
create_broker_successfully(global_broker_request_body, with: admin_headers)
765759
execute_all_jobs(expected_successes: 1, expected_failures: 0)
766760

@@ -848,7 +842,6 @@ def expect_empty_list(user_headers)
848842
url: 'http://example.org/space-broker-url',
849843
created_at: iso8601,
850844
updated_at: iso8601,
851-
status: 'synchronization in progress',
852845
metadata: { labels: {}, annotations: {} },
853846
relationships: {
854847
space: { data: { guid: space.guid } }
@@ -1015,10 +1008,8 @@ def expect_empty_list(user_headers)
10151008
let(:job) { VCAP::CloudController::PollableJobModel.last }
10161009

10171010
it 'leaves broker in a non-available failed state' do
1018-
expect_broker_status(
1019-
status: 'synchronization failed',
1020-
with: admin_headers
1021-
)
1011+
broker = VCAP::CloudController::ServiceBroker.last
1012+
expect(broker.state).to eq(VCAP::CloudController::ServiceBrokerStateEnum::SYNCHRONIZATION_FAILED)
10221013
end
10231014

10241015
it 'has failed the job with an appropriate error' do
@@ -1164,7 +1155,6 @@ def expect_created_broker(expected_broker)
11641155
expect(VCAP::CloudController::ServiceBroker.count).to eq(@count_before_creation + 1)
11651156

11661157
service_broker = VCAP::CloudController::ServiceBroker.last
1167-
11681158
expect(service_broker).to include(
11691159
'name' => expected_broker[:name],
11701160
'broker_url' => expected_broker[:url],
@@ -1176,17 +1166,6 @@ def expect_created_broker(expected_broker)
11761166
expect(service_broker.auth_password).to eq(expected_broker[:authentication][:credentials][:password])
11771167
end
11781168

1179-
def expect_broker_status(status:, with:)
1180-
expect(VCAP::CloudController::ServiceBroker.count).to eq(@count_before_creation + 1)
1181-
service_broker = VCAP::CloudController::ServiceBroker.last
1182-
1183-
get("/v3/service_brokers/#{service_broker.guid}", {}, with)
1184-
expect(last_response.status).to eq(200)
1185-
expect(parsed_response).to include(
1186-
'status' => status
1187-
)
1188-
end
1189-
11901169
def expect_no_broker_created
11911170
expect(VCAP::CloudController::ServiceBroker.count).to eq(@count_before_creation)
11921171
end
@@ -1206,11 +1185,10 @@ def assert_broker_state(broker_json)
12061185
get broker_url, {}, admin_headers
12071186
expect(last_response.status).to eq(200)
12081187

1209-
updated_service_broker_json = broker_json.tap do |broker|
1210-
broker[:status] = 'available'
1211-
end
1188+
expect(parsed_response).to match_json_response(broker_json)
12121189

1213-
expect(parsed_response).to match_json_response(updated_service_broker_json)
1190+
service_broker = VCAP::CloudController::ServiceBroker.last
1191+
expect(service_broker.state).to eq('AVAILABLE')
12141192
end
12151193
end
12161194

@@ -1299,10 +1277,8 @@ def assert_broker_state(broker_json)
12991277
end
13001278

13011279
it 'marks the broker as deleting' do
1302-
get "/v3/service_brokers/#{global_broker.guid}", {}, admin_headers
1303-
expect(parsed_response).to include({
1304-
'status' => 'delete in progress'
1305-
})
1280+
broker = VCAP::CloudController::ServiceBroker.last
1281+
expect(broker.state).to eq(VCAP::CloudController::ServiceBrokerStateEnum::DELETE_IN_PROGRESS)
13061282
end
13071283
end
13081284

@@ -1390,10 +1366,8 @@ def assert_broker_state(broker_json)
13901366
end
13911367

13921368
it 'updates the broker state' do
1393-
get "/v3/service_brokers/#{global_broker.guid}", {}, admin_headers
1394-
expect(parsed_response).to include({
1395-
'status' => 'delete failed'
1396-
})
1369+
broker = VCAP::CloudController::ServiceBroker.last
1370+
expect(broker.state).to eq(VCAP::CloudController::ServiceBrokerStateEnum::DELETE_FAILED)
13971371
end
13981372
end
13991373
end

spec/unit/presenters/v3/service_broker_presenter_spec.rb

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module Presenters::V3
1818
end
1919

2020
let(:service_broker_guid) { 'some-broker-guid' }
21-
let(:service_broker_state) { nil }
2221
let(:space_guid) { nil }
2322
let(:service_broker) do
2423
double(
@@ -28,7 +27,6 @@ module Presenters::V3
2827
auth_username: 'username',
2928
auth_password: 'welcome',
3029
space_guid: space_guid,
31-
state: service_broker_state,
3230
created_at: Time.now,
3331
updated_at: Time.now,
3432
labels: [label],
@@ -97,54 +95,6 @@ module Presenters::V3
9795
expect(result[:links][:space][:href]).to eq("#{link_prefix}/v3/spaces/#{space_guid}")
9896
end
9997
end
100-
101-
describe 'broker status' do
102-
context 'when there is no state (e.g. legacy V2 created broker)' do
103-
it 'is available' do
104-
expect(result[:status]).to eq('available')
105-
end
106-
end
107-
108-
context 'when state is available' do
109-
let(:service_broker_state) { ServiceBrokerStateEnum::AVAILABLE }
110-
111-
it 'is available' do
112-
expect(result[:status]).to eq('available')
113-
end
114-
end
115-
116-
context 'when state is synchronizing' do
117-
let(:service_broker_state) { ServiceBrokerStateEnum::SYNCHRONIZING }
118-
119-
it 'has synchronization in progress' do
120-
expect(result[:status]).to eq('synchronization in progress')
121-
end
122-
end
123-
124-
context 'when state is synchronization failed' do
125-
let(:service_broker_state) { ServiceBrokerStateEnum::SYNCHRONIZATION_FAILED }
126-
127-
it 'has synchronization failed' do
128-
expect(result[:status]).to eq('synchronization failed')
129-
end
130-
end
131-
132-
context 'when state is delete in progress' do
133-
let(:service_broker_state) { ServiceBrokerStateEnum::DELETE_IN_PROGRESS }
134-
135-
it 'has delete in progress' do
136-
expect(result[:status]).to eq('delete in progress')
137-
end
138-
end
139-
140-
context 'when state is delete failed' do
141-
let(:service_broker_state) { ServiceBrokerStateEnum::DELETE_FAILED }
142-
143-
it 'has delete failed' do
144-
expect(result[:status]).to eq('delete failed')
145-
end
146-
end
147-
end
14898
end
14999
end
150100
end

0 commit comments

Comments
 (0)