Skip to content

Commit eed3d7b

Browse files
authored
Better error message and support logs for /v3/service_offerings and plans (#4213)
* Better error message and support logs for /v3/service_offerings and plans
1 parent cfd3d29 commit eed3d7b

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

app/controllers/v3/service_instances_controller.rb

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ def create_user_provided(message)
254254

255255
def create_managed(message, space:)
256256
service_plan = ServicePlan.first(guid: message.service_plan_guid)
257-
unprocessable_service_plan! unless service_plan_valid?(service_plan, space)
257+
unprocessable_service_plan! unless service_plan_valid?(service_plan)
258+
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
259+
service_plan_not_visible_in_space!(service_plan, space) unless service_plan_exists_in_space?(service_plan, space)
258260

259261
action = V3::ServiceInstanceCreateManaged.new(user_audit_info, message.audit_hash)
260262
VCAP::CloudController::ManagedServiceInstance.db.transaction do
@@ -394,17 +396,26 @@ def admin?
394396
permission_queryer.can_write_globally?
395397
end
396398

397-
def service_plan_valid?(service_plan, space)
399+
def service_plan_valid?(service_plan)
398400
service_plan &&
399-
visible_to_current_user?(plan: service_plan) &&
400-
service_plan.visible_in_space?(space)
401+
visible_to_current_user?(plan: service_plan)
402+
end
403+
404+
def service_plan_active?(service_plan)
405+
service_plan.active?
406+
end
407+
408+
def service_plan_exists_in_space?(service_plan, space)
409+
service_plan.visible_in_space?(space)
401410
end
402411

403412
def raise_if_invalid_service_plan!(service_instance, message)
404413
return unless message.service_plan_guid
405414

406415
service_plan = ServicePlan.first(guid: message.service_plan_guid)
407-
unprocessable_service_plan! unless service_plan_valid?(service_plan, service_instance.space)
416+
unprocessable_service_plan! unless service_plan_valid?(service_plan)
417+
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
418+
service_plan_not_visible_in_space!(service_plan, service_instance.space) unless service_plan_exists_in_space?(service_plan, service_instance.space)
408419
invalid_service_plan_relation! unless service_plan.service == service_instance.service
409420
end
410421

@@ -424,6 +435,18 @@ def unprocessable_service_plan!
424435
unprocessable!('Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.')
425436
end
426437

438+
def unavailable_service_plan!(service_plan)
439+
unprocessable!("Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' has been removed from the service broker's catalog. " \
440+
'It is not possible to create new service instances using this plan.')
441+
end
442+
443+
def service_plan_not_visible_in_space!(service_plan, space)
444+
unprocessable!('Invalid service plan. This could be due to a space-scoped broker which is offering the service plan ' \
445+
"'#{service_plan.name}' with guid '#{service_plan.guid}' in another space or that the plan " \
446+
'is not enabled in this organization. Ensure that the service plan is visible in your current space ' \
447+
"'#{space.name}' with guid '#{space.guid}'.")
448+
end
449+
427450
def invalid_service_plan_relation!
428451
raise CloudController::Errors::ApiError.new_from_details('InvalidRelation', 'service plan relates to a different service offering')
429452
end

spec/request/service_instances_spec.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,10 @@ def check_filtered_instances(*instances)
12601260
expect(last_response).to have_status_code(422)
12611261
expect(parsed_response['errors']).to include(
12621262
include({
1263-
'detail' => 'Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.',
1263+
'detail' => 'Invalid service plan. This could be due to a space-scoped broker which is offering the service plan ' \
1264+
"'#{service_plan.name}' with guid '#{service_plan.guid}' in another space or that the plan " \
1265+
'is not enabled in this organization. Ensure that the service plan is visible in your current space ' \
1266+
"'#{space.name}' with guid '#{space.guid}'.",
12641267
'title' => 'CF-UnprocessableEntity',
12651268
'code' => 10_008
12661269
})
@@ -1276,7 +1279,9 @@ def check_filtered_instances(*instances)
12761279
expect(last_response).to have_status_code(422)
12771280
expect(parsed_response['errors']).to include(
12781281
include({
1279-
'detail' => 'Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.',
1282+
'detail' => "Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' " \
1283+
"has been removed from the service broker's catalog. " \
1284+
'It is not possible to create new service instances using this plan.',
12801285
'title' => 'CF-UnprocessableEntity',
12811286
'code' => 10_008
12821287
})
@@ -2404,6 +2409,26 @@ def check_filtered_instances(*instances)
24042409
end
24052410
end
24062411

2412+
context 'not enabled in that org' do
2413+
let(:service_plan) { VCAP::CloudController::ServicePlan.make(public: false, active: true) }
2414+
let(:service_plan_guid) { service_plan.guid }
2415+
2416+
it 'fails saying the plan is invalid' do
2417+
api_call.call(admin_headers)
2418+
expect(last_response).to have_status_code(422)
2419+
expect(parsed_response['errors']).to include(
2420+
include({
2421+
'detail' => 'Invalid service plan. This could be due to a space-scoped broker which is offering the service plan ' \
2422+
"'#{service_plan.name}' with guid '#{service_plan.guid}' in another space or that the plan " \
2423+
'is not enabled in this organization. Ensure that the service plan is visible in your current space ' \
2424+
"'#{space.name}' with guid '#{space.guid}'.",
2425+
'title' => 'CF-UnprocessableEntity',
2426+
'code' => 10_008
2427+
})
2428+
)
2429+
end
2430+
end
2431+
24072432
context 'not available' do
24082433
let(:service_plan) { VCAP::CloudController::ServicePlan.make(public: true, active: false) }
24092434
let(:service_plan_guid) { service_plan.guid }
@@ -2413,7 +2438,9 @@ def check_filtered_instances(*instances)
24132438
expect(last_response).to have_status_code(422)
24142439
expect(parsed_response['errors']).to include(
24152440
include({
2416-
'detail' => 'Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.',
2441+
'detail' => "Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' " \
2442+
"has been removed from the service broker's catalog. " \
2443+
'It is not possible to create new service instances using this plan.',
24172444
'title' => 'CF-UnprocessableEntity',
24182445
'code' => 10_008
24192446
})

0 commit comments

Comments
 (0)