Module: Nucleus::Adapters::V1::CloudFoundryV2::Data
- Included in:
- Nucleus::Adapters::V1::CloudFoundryV2
- Defined in:
- lib/nucleus/adapters/v1/cloud_foundry_v2/data.rb
Instance Method Summary collapse
- #deploy(application_name_or_id, file, file_compression_format) ⇒ Object
- #download(application_name_or_id, compression_format) ⇒ Object
- #rebuild(application_name_or_id) ⇒ Object
Instance Method Details
#deploy(application_name_or_id, file, file_compression_format) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/data.rb', line 7 def deploy(application_name_or_id, file, file_compression_format) # could be made async, too # resources: [] says that no previous data shall be reused, see also: # http://apidocs.cloudfoundry.org/202/apps/uploads_the_bits_for_an_app.html app_guid = app_guid(application_name_or_id) # deploy by guid # deploy_response = put("/v2/apps/#{app_guid}/bits", body: { resources: [], application: file.read }, # headers: { 'Content-Type' => 'multipart/form-data; '\ # 'boundary=nucleus-cloud-foundry-adapter-file-upload-boundary' }) begin # convert all archives to .zip archives converted_file = ArchiveConverter.convert(file, file_compression_format, 'zip', true) unless converted_file.respond_to?(:path) && converted_file.respond_to?(:read) tmpfile = Tempfile.new(["nucleus-cf-deploy-upload-#{app_guid}", '.zip']) tmpfile.binmode tmpfile.write converted_file.read tmpfile.rewind converted_file = tmpfile end # TODO: this is only a temporary solution until excon supports multipart requests # See also: https://github.com/excon/excon/issues/353 url = "#{@endpoint_url}/v2/apps/#{app_guid}/bits" request_body = { multipart: true, application: converted_file, async: false, resources: '[]' } begin RestClient::Request.execute(method: :put, url: url, payload: request_body, headers: headers, verify_ssl: @check_certificates) rescue RestClient::BadRequest => e raise Errors::AdapterRequestError, e.http_body end ensure if tmpfile tmpfile.close tmpfile.unlink # deletes this temporary file end end end |
#download(application_name_or_id, compression_format) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/data.rb', line 48 def download(application_name_or_id, compression_format) app_guid = app_guid(application_name_or_id) # fail if there is no deployment unless deployed?(app_guid) fail Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be downloaded' end download_response = get("/v2/apps/#{app_guid}/download", follow_redirects: false, expects: [200, 302]) if download_response.status == 200 data = download_response.body else download_location = download_response.headers[:Location] # if IBM f*cked with the download URL, fix the address download_location = download_location.gsub(/objectstorage.service.networklayer.com/, 'objectstorage.softlayer.net') # omit_default_port: https://github.com/excon/excon/issues/475 data = Excon.new(download_location, omit_default_port: true).get.body end # write data to tmpfile so that it can be converted downloaded_application_archive = Tempfile.new(["nucleus-cf-deployment-download-#{app_guid}", '.zip']) downloaded_application_archive.binmode downloaded_application_archive.write StringIO.new(data).read downloaded_application_archive.rewind # convert from current format (which is always a zip archive) to the destination format ArchiveConverter.convert(downloaded_application_archive, 'zip', compression_format, false) ensure if downloaded_application_archive downloaded_application_archive.close downloaded_application_archive.unlink end end |
#rebuild(application_name_or_id) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/nucleus/adapters/v1/cloud_foundry_v2/data.rb', line 82 def rebuild(application_name_or_id) app_guid = app_guid(application_name_or_id) # fail if there is no deployment unless deployed?(app_guid) fail Errors::SemanticAdapterRequestError, 'Application must be deployed before it can be rebuild' end # rebuild by name or id rebuild_response = post("/v2/apps/#{app_guid}/restage") to_nucleus_app(rebuild_response.body) end |