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

Commit 0a4ff67

Browse files
authored
Merge pull request cloudfoundry#1620 from cloudfoundry/space_summary_wrong_guid_1523
V2 endpoints should return app guid instead of process guid in various places
2 parents 0278a44 + 0ae0b8a commit 0a4ff67

4 files changed

Lines changed: 144 additions & 4 deletions

File tree

app/controllers/runtime/apps_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ def upload_droplet(guid)
196196
[HTTP::CREATED, JobPresenter.new(enqueued_job).to_json]
197197
end
198198

199+
def url_for_guid(_, process)
200+
super(process.app_guid, process)
201+
end
202+
199203
def read(guid)
200204
process = find_guid(guid)
201205
raise CloudController::Errors::ApiError.new_from_details('AppNotFound', guid) unless process.web?

app/controllers/runtime/space_summaries_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def app_summary(space)
3939
instances = instances_reporters.number_of_starting_and_running_instances_for_processes(space.apps)
4040
space.apps.reject { |process| process.app.nil? }.collect do |process|
4141
{
42-
guid: process.guid,
42+
guid: process.app_guid,
4343
urls: process.routes.map(&:uri),
4444
routes: process.routes.map(&:as_summary_json),
4545
service_count: process.service_bindings_dataset.count,

spec/unit/controllers/runtime/apps_controller_spec.rb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,127 @@ def update_app
557557
end
558558
end
559559

560+
describe 'read app' do
561+
let(:process) { ProcessModelFactory.make(instances: 1) }
562+
let(:app_model) { process.app }
563+
let(:developer) { make_developer_for_space(process.space) }
564+
let(:app_guid) { process.app_guid }
565+
566+
before do
567+
set_current_user(developer)
568+
allow_any_instance_of(V2::AppStage).to receive(:stage).and_return(nil)
569+
end
570+
571+
it 'returns the app in question' do
572+
get "/v2/apps/#{app_guid}"
573+
expect(decoded_response['metadata']).to include({
574+
'guid' => app_guid.to_s,
575+
'url' => "/v2/apps/#{app_guid}",
576+
'created_at' => anything,
577+
'updated_at' => anything
578+
})
579+
expect(decoded_response['entity']).to include({
580+
'name' => 'name-1',
581+
'production' => false,
582+
'space_guid' => process.space.guid.to_s,
583+
'stack_guid' => process.stack.guid.to_s,
584+
'buildpack' => nil,
585+
'detected_buildpack' => nil,
586+
'detected_buildpack_guid' => nil,
587+
'environment_json' => nil,
588+
'memory' => 1024,
589+
'instances' => 1,
590+
'disk_quota' => 1024,
591+
'state' => 'STOPPED',
592+
'version' => anything,
593+
'command' => nil,
594+
'console' => false,
595+
'debug' => nil,
596+
'staging_task_id' => anything,
597+
'package_state' => 'STAGED',
598+
'health_check_type' => 'port',
599+
'health_check_timeout' => nil,
600+
'health_check_http_endpoint' => nil,
601+
'staging_failed_reason' => nil,
602+
'staging_failed_description' => nil,
603+
'diego' => true,
604+
'docker_image' => nil,
605+
'docker_credentials' => {
606+
'username' => nil,
607+
'password' => nil
608+
},
609+
'package_updated_at' => anything,
610+
'detected_start_command' => '$HOME/boot.sh',
611+
'enable_ssh' => true,
612+
'ports' => [8080],
613+
'space_url' => "/v2/spaces/#{process.space.guid}",
614+
'stack_url' => "/v2/stacks/#{process.stack.guid}",
615+
'routes_url' => "/v2/apps/#{app_guid}/routes",
616+
'events_url' => "/v2/apps/#{app_guid}/events",
617+
'service_bindings_url' => "/v2/apps/#{app_guid}/service_bindings",
618+
'route_mappings_url' => "/v2/apps/#{app_guid}/route_mappings"
619+
})
620+
end
621+
622+
context 'when the app has rolled to a new web process' do
623+
before do
624+
process.destroy
625+
ProcessModelFactory.make(instances: 1, app: app_model)
626+
end
627+
628+
it 'returns the app with the appropriate app guid' do
629+
get "/v2/apps/#{app_guid}"
630+
expect(decoded_response['metadata']).to include({
631+
'guid' => app_guid.to_s,
632+
'url' => "/v2/apps/#{app_guid}",
633+
'created_at' => anything,
634+
'updated_at' => anything
635+
})
636+
expect(decoded_response['entity']).to include({
637+
'name' => 'name-1',
638+
'production' => false,
639+
'space_guid' => process.space.guid.to_s,
640+
'stack_guid' => process.stack.guid.to_s,
641+
'buildpack' => nil,
642+
'detected_buildpack' => nil,
643+
'detected_buildpack_guid' => nil,
644+
'environment_json' => nil,
645+
'memory' => 1024,
646+
'instances' => 1,
647+
'disk_quota' => 1024,
648+
'state' => 'STOPPED',
649+
'version' => anything,
650+
'command' => nil,
651+
'console' => false,
652+
'debug' => nil,
653+
'staging_task_id' => anything,
654+
'package_state' => 'STAGED',
655+
'health_check_type' => 'port',
656+
'health_check_timeout' => nil,
657+
'health_check_http_endpoint' => nil,
658+
'staging_failed_reason' => nil,
659+
'staging_failed_description' => nil,
660+
'diego' => true,
661+
'docker_image' => nil,
662+
'docker_credentials' => {
663+
'username' => nil,
664+
'password' => nil
665+
},
666+
'package_updated_at' => anything,
667+
'detected_start_command' => '$HOME/boot.sh',
668+
'enable_ssh' => true,
669+
'ports' => [8080],
670+
'space_url' => "/v2/spaces/#{process.space.guid}",
671+
'stack_url' => "/v2/stacks/#{process.stack.guid}",
672+
'routes_url' => "/v2/apps/#{app_guid}/routes",
673+
'events_url' => "/v2/apps/#{app_guid}/events",
674+
'service_bindings_url' => "/v2/apps/#{app_guid}/service_bindings",
675+
'route_mappings_url' => "/v2/apps/#{app_guid}/route_mappings"
676+
})
677+
end
678+
end
679+
end
680+
560681
describe 'update app' do
561682
let(:update_hash) { {} }
562683

spec/unit/controllers/runtime/space_summaries_controller_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ module VCAP::CloudController
44
RSpec.describe SpaceSummariesController do
55
let(:space) { Space.make }
66
let(:process) { ProcessModelFactory.make(space: space) }
7+
let(:app_model) { process.app }
78
let!(:first_route) { Route.make(space: space) }
89
let!(:second_route) { Route.make(space: space) }
910
let(:first_service) { ManagedServiceInstance.make(space: space) }
1011
let(:second_service) { ManagedServiceInstance.make(space: space) }
1112

1213
let(:instances_reporters) { double(:instances_reporters) }
13-
let(:running_instances) { { process.guid => 5 } }
14+
let(:running_instances) { { app_model.guid => 5 } }
1415

1516
before do
1617
ServiceBinding.make(app: process.app, service_instance: first_service)
@@ -37,7 +38,7 @@ module VCAP::CloudController
3738
it 'returns the space apps' do
3839
get "/v2/spaces/#{space.guid}/summary"
3940
expected_app_hash = {
40-
guid: process.guid,
41+
guid: app_model.guid,
4142
urls: [first_route.uri, second_route.uri],
4243
routes: [
4344
first_route.as_summary_json,
@@ -157,6 +158,7 @@ module VCAP::CloudController
157158

158159
context 'when an app is deleted concurrently' do
159160
let(:deleted_process) { ProcessModelFactory.make(space: space) }
161+
let!(:deleted_app_guid) { deleted_process.app.guid }
160162
before do
161163
deleted_process.app = nil
162164
allow_any_instance_of(Space).to receive(:apps).and_return([process, deleted_process])
@@ -166,7 +168,20 @@ module VCAP::CloudController
166168
get "/v2/spaces/#{space.guid}/summary"
167169
expect(last_response.status).to eq(200)
168170
expect(space.apps).to match([process, deleted_process])
169-
expect(last_response.body).not_to include(deleted_process.guid)
171+
expect(last_response.body).not_to include(deleted_app_guid)
172+
end
173+
end
174+
175+
context 'when the app has rolled to a new web process' do
176+
before do
177+
process.destroy
178+
ProcessModel.make(app: app_model, type: ProcessTypes::WEB)
179+
end
180+
181+
it 'returns the space apps with the appropriate app guid' do
182+
get "/v2/spaces/#{space.guid}/summary"
183+
184+
expect(decoded_response['apps'][0]).to include({ 'guid' => app_model.guid })
170185
end
171186
end
172187
end

0 commit comments

Comments
 (0)