Class: Services::PccMdsPull
- Inherits:
-
MdsPull
- Object
- ServiceImplementation
- MdsPull
- Services::PccMdsPull
- Defined in:
- app/models/services/pcc_mds_pull.rb
Constant Summary
Constants inherited from MdsPull
Instance Attribute Summary
Attributes inherited from ServiceImplementation
Instance Method Summary collapse
- #download_file(server, available_file, account_directory) ⇒ Object
-
#ftp_server ⇒ Object
Factory method to return one and only one instance of the ftp server class for an instance of the PccMdsPull class.
-
#list_available_files(configured_account) ⇒ Object
Overridden from MdsPull.
-
#perform_cleanup_on_remote_server(configured_account) ⇒ Object
Overridden from MdsPull.
-
#perform_file_downloads(configured_account, files_to_download) ⇒ Object
Overridden from MdsPull.
- #remove_file(server, available_file, account_directory) ⇒ Object
Methods inherited from MdsPull
#identify_providers, #invoke, #request_assessments, #request_baseline
Methods inherited from ServiceImplementation
#account_map, #initialize, #server_credentials
Constructor Details
This class inherits a constructor from Services::ServiceImplementation
Instance Method Details
#download_file(server, available_file, account_directory) ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/models/services/pcc_mds_pull.rb', line 60 def download_file(server, available_file, account_directory) server.download_file account_directory, available_file.request_id, available_file.download_path available_file.id rescue Exception => ex Rails.logger.error "Error downloading file: #{available_file.to_rrepr}: #{ex.}\n#{ex.backtrace.join("\n")}" nil # Return nil; we failed to download the specified file and 'nil' is the correct response end |
#ftp_server ⇒ Object
Factory method to return one and only one instance of the ftp server class for an instance of the PccMdsPull class.
9 10 11 12 13 14 15 |
# File 'app/models/services/pcc_mds_pull.rb', line 9 def ftp_server # Create a new FtpServer instance only if necessary @ftp_server ||= FtpServer.new(service_definition.hostname, service_definition.username, server_credentials.password, service_definition.base_uri) end |
#list_available_files(configured_account) ⇒ Object
Overridden from MdsPull.
20 21 22 23 24 25 26 27 28 |
# File 'app/models/services/pcc_mds_pull.rb', line 20 def list_available_files(configured_account) mapped_account = account_map(configured_account.account_id) files = [] ftp_server.connect do | server | files = server.file_list mapped_account.account_code, '*.zip' end files.map { | fn | [ fn, fn ] } end |
#perform_cleanup_on_remote_server(configured_account) ⇒ Object
Overridden from MdsPull
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/services/pcc_mds_pull.rb', line 48 def perform_cleanup_on_remote_server(configured_account) mapped_account = account_map(configured_account.account_id) cleared_files = [] ftp_server.connect do | server | configured_account.available_files.deleted.each do | available_file | cleared_files << remove_file(server, available_file, mapped_account.account_code) end end cleared_files.compact end |
#perform_file_downloads(configured_account, files_to_download) ⇒ Object
Overridden from MdsPull.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/services/pcc_mds_pull.rb', line 33 def perform_file_downloads(configured_account, files_to_download) mapped_account = account_map(configured_account.account_id) downloaded_files = [] ftp_server.connect do | server | files_to_download.each do | available_file | downloaded_files << download_file(server, available_file, mapped_account.account_code) end end downloaded_files.compact # The compact is here because there could be nil's in the list end |
#remove_file(server, available_file, account_directory) ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/models/services/pcc_mds_pull.rb', line 68 def remove_file(server, available_file, account_directory) server.remove_file account_directory, available_file.request_id available_file.id rescue Exception => ex Rails.logger.error "Error removing server file: #{available_file.to_rrepr}: #{ex.}\n#{ex.backtrace.join("\n")}" nil # Return nil; we failed to remove the specified file and 'nil' is the correct response end |