Class: Aspera::Agent::Desktop
Overview
Client: Aspera for Desktop
Instance Method Summary collapse
- #aspera_client_api_url ⇒ Object
-
#initialize(**base_options) ⇒ Desktop
constructor
A new instance of Desktop.
- #start_transfer(transfer_spec, token_regenerator: nil) ⇒ Object
- #wait_for_transfers_completion ⇒ Object
Methods inherited from Base
agent_list, factory_create, #wait_for_completion
Constructor Details
#initialize(**base_options) ⇒ Desktop
Returns a new instance of Desktop.
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/aspera/agent/desktop.rb', line 20 def initialize(**) @application_id = SecureRandom.uuid @xfer_id = nil super raise 'Using client requires a graphical environment' if !Environment.default_gui_mode.eql?(:graphical) method_index = 0 begin # curl 'http://127.0.0.1:33024/' -X POST -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","params":[],"id":999999,"method":"rpc.discover"}' # https://playground.open-rpc.org/?schemaUrl=http://127.0.0.1:33024 @client_app_api = Aspera::JsonRpcClient.new(Aspera::Rest.new(base_url: aspera_client_api_url)) client_info = @client_app_api.get_info Log.log.debug{Log.dump(:client_version, client_info)} Log.log.info('Client was reached') if method_index > 0 rescue Errno::ECONNREFUSED => e start_url = START_URIS[method_index] method_index += 1 raise StandardError, "Unable to start #{Products::Desktop::APP_NAME} #{method_index} times" if start_url.nil? Log.log.warn{"#{Products::Desktop::APP_NAME} is not started (#{e}). Trying to start it ##{method_index}..."} if !Environment.open_uri_graphical(start_url) Environment.open_uri_graphical('https://www.ibm.com/aspera/connect/') raise StandardError, "#{Products::Desktop::APP_NAME} is not installed" end sleep(SLEEP_SEC_BETWEEN_RETRY) retry end end |
Instance Method Details
#aspera_client_api_url ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aspera/agent/desktop.rb', line 47 def aspera_client_api_url log_file = Products::Desktop.log_file url = 'http://127.0.0.1:33024' File.open(log_file, 'r') do |file| file.each_line do |line| line = line.chomp if (m = line.match(/JSON-RPC server listening on (.*)/)) url = "http://#{m[1]}" end end end # raise StandardError, "Unable to find the JSON-RPC server URL in #{log_file}" if url.nil? return url end |
#start_transfer(transfer_spec, token_regenerator: nil) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/aspera/agent/desktop.rb', line 62 def start_transfer(transfer_spec, token_regenerator: nil) @request_id = SecureRandom.uuid # if there is a token, we ask the client app to use well known ssh private keys # instead of asking password transfer_spec['authentication'] = 'token' if transfer_spec.key?('token') result = @client_app_api.start_transfer(app_id: @application_id, desktop_spec: {}, transfer_spec: transfer_spec) @xfer_id = result['uuid'] end |
#wait_for_transfers_completion ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/aspera/agent/desktop.rb', line 71 def wait_for_transfers_completion started = false pre_calc = false begin loop do transfer = @client_app_api.get_transfer(app_id: @application_id, transfer_id: @xfer_id) case transfer['status'] when 'initiating', 'queued' notify_progress(:pre_start, session_id: nil, info: transfer['status']) when 'running' if !started notify_progress(:session_start, session_id: @xfer_id) started = true end if !pre_calc && (transfer['bytes_expected'] != 0) notify_progress(:session_size, session_id: @xfer_id, info: transfer['bytes_expected']) pre_calc = true else notify_progress(:transfer, session_id: @xfer_id, info: transfer['bytes_written']) end when 'completed' notify_progress(:end, session_id: @xfer_id) break when 'failed' notify_progress(:end, session_id: @xfer_id) raise Transfer::Error, transfer['error_desc'] when 'cancelled' notify_progress(:end, session_id: @xfer_id) raise Transfer::Error, 'Transfer cancelled by user' else notify_progress(:end, session_id: @xfer_id) raise Transfer::Error, "unknown status: #{transfer['status']}: #{transfer['error_desc']}" end sleep(1) end rescue StandardError => e return [e] end return [:success] end |