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

Commit b4134db

Browse files
reneighborMerricdeLauneyreidmit
committed
Handle case where blobstore_key is not set on droplet
When downloading a droplet, if the blobstore key is not set, you would previously get a BlobNotFound error. This can make it hard to distinguish this case from the other cases where BlobNotFound errors are raised. We want to make it clearer when, e.g. staging does not complete and our droplet does not have a blobstore key. Co-authored-by: Renee Chu <rchu@pivotal.io> Co-authored-by: Merric De Launey <mdelauney@pivotal.io> Co-authored-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent 7b4ec25 commit b4134db

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

app/controllers/runtime/helpers/blob_dispatcher.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ def initialize(blobstore:, controller:)
66
end
77

88
def send_or_redirect(guid:)
9+
logger.error('No guid for BlobNotFound')
910
raise CloudController::Errors::BlobNotFound unless guid
1011

1112
blob = @blobstore.blob(guid)
1213

14+
logger.error('No blob object for BlobNotFound')
1315
raise CloudController::Errors::BlobNotFound unless blob
1416

1517
send_or_redirect_blob(blob)

app/controllers/v3/droplets_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ def download
161161
private
162162

163163
def send_droplet_blob(droplet)
164+
if droplet.blobstore_key.nil?
165+
resource_not_found_with_message!('Blobstore key not present on droplet. This may be due to a failed build.')
166+
end
167+
164168
droplet_blobstore = CloudController::DependencyLocator.instance.droplet_blobstore
165169
BlobDispatcher.new(blobstore: droplet_blobstore, controller: self).send_or_redirect(guid: droplet.blobstore_key)
166170
rescue CloudController::Errors::BlobNotFound

spec/request/droplets_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,21 @@
405405
end
406406
end
407407

408+
context 'when the droplet cannot be retrieved from the blobstore' do
409+
before do
410+
droplet_model.update(
411+
state: VCAP::CloudController::DropletModel::STAGED_STATE,
412+
droplet_hash: nil
413+
)
414+
end
415+
416+
it 'returns an error with a helpful message' do
417+
get "/v3/droplets/#{droplet_model.guid}/download", nil, developer_headers
418+
expect(last_response).to have_status_code(404)
419+
expect(last_response).to have_error_message('Blobstore key not present on droplet. This may be due to a failed build.')
420+
end
421+
end
422+
408423
context 'when the droplet cannot be found' do
409424
it 'returns 404 for the droplet' do
410425
get '/v3/droplets/some-bogus-guid/download', nil, developer_headers

0 commit comments

Comments
 (0)