cloud_controller/app/controllers/staging_controller.rb
# Handles a droplet upload from a stager
Handles a droplet upload from a stager
Handles a droplet upload from a stager
def upload_droplet
    upload = nil
    src_path = nil
    app = App.find_by_id(params[:id])
    raise CloudError.new(CloudError::APP_NOT_FOUND) unless app
    upload = self.class.lookup_upload(params[:upload_id])
    unless upload
      CloudController.logger.error("No upload set for upload_id=#{params[:upload_id]}")
      raise CloudError.new(CloudError::BAD_REQUEST)
    end
    if CloudController.use_nginx
      src_path = params[:droplet_path]
    else
      src_path = params[:upload][:droplet].path
    end
    unless src_path && File.exist?(src_path)
      CloudController.logger.error("Uploaded droplet not found at '#{src_path}'")
      raise CloudError.new(CloudError::BAD_REQUEST)
    end
    begin
      CloudController.logger.debug("Renaming staged droplet from '#{src_path}' to '#{upload.upload_path}'")
      File.rename(src_path, upload.upload_path)
    rescue => e
      CloudController.logger.error("Failed uploading staged droplet: #{e}", :tags => [:staging])
      CloudController.logger.error(e)
      FileUtils.rm_f(upload.upload_path)
      raise e
    end
    CloudController.logger.debug("Stager (#{request.remote_ip}) uploaded droplet to #{upload.upload_path}",
                                 :tags => [:staging])
    render :nothing => true, :status => 200
  ensure
    FileUtils.rm_f(src_path) if src_path
    self.class.complete_upload(upload) if upload
  end
def upload_droplet upload = nil src_path = nil app = App . find_by_id ( params [ :id ] ) raise CloudError . new ( CloudError :: APP_NOT_FOUND ) unless app upload = self . class . lookup_upload ( params [ :upload_id ] ) unless upload CloudController . logger . error ( "No upload set for upload_id=#{params[:upload_id]}" ) raise CloudError . new ( CloudError :: BAD_REQUEST ) end if CloudController . use_nginx src_path = params [ :droplet_path ] else src_path = params [ :upload ] [ :droplet ] . path end unless src_path && File . exist? ( src_path ) CloudController . logger . error ( "Uploaded droplet not found at '#{src_path}'" ) raise CloudError . new ( CloudError :: BAD_REQUEST ) end begin CloudController . logger . debug ( "Renaming staged droplet from '#{src_path}' to '#{upload.upload_path}'" ) File . rename ( src_path , upload . upload_path ) rescue => e CloudController . logger . error ( "Failed uploading staged droplet: #{e}" , :tags => [ :staging ] ) CloudController . logger . error ( e ) FileUtils . rm_f ( upload . upload_path ) raise e end CloudController . logger . debug ( "Stager (#{request.remote_ip}) uploaded droplet to #{upload.upload_path}" , :tags => [ :staging ] ) render :nothing => true , :status => 200 ensure FileUtils . rm_f ( src_path ) if src_path self . class . complete_upload ( upload ) if upload end
Handles a droplet upload from a stager
Handles a droplet upload from a stager