Class: Services::PccMdsPull

Inherits:
MdsPull show all
Defined in:
app/models/services/pcc_mds_pull.rb

Constant Summary

Constants inherited from MdsPull

MdsPull::ASYNC_SEND_OPTS

Instance Attribute Summary

Attributes inherited from ServiceImplementation

#service_definition

Instance Method Summary collapse

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, )
  server.download_file , 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.message}\n#{ex.backtrace.join("\n")}"
  nil # Return nil; we failed to download the specified file and 'nil' is the correct response
end

#ftp_serverObject

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()
   = (.)

  files = []
  ftp_server.connect do | server |
    files = server.file_list ., '*.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()
   = (.)
  
  cleared_files = []
  ftp_server.connect do | server |
    .available_files.deleted.each do | available_file |
      cleared_files << remove_file(server, available_file, .)
    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(, files_to_download)
   = (.)

  downloaded_files = []
  ftp_server.connect do | server |
    files_to_download.each do | available_file |
      downloaded_files << download_file(server, available_file, .)
    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, )
  server.remove_file , available_file.request_id
  available_file.id
rescue Exception => ex
  Rails.logger.error "Error removing server file: #{available_file.to_rrepr}: #{ex.message}\n#{ex.backtrace.join("\n")}"
  nil # Return nil; we failed to remove the specified file and 'nil' is the correct response
end