class Asperalm::Fasp::Node

this singleton class is used by the CLI to provide a common interface to start a transfer before using it, the use must set the `node_api` member.

Attributes

node_api[R]

use this to read the node_api end point.

Public Class Methods

new(node_api) click to toggle source
Calls superclass method Asperalm::Fasp::Manager::new
# File lib/asperalm/fasp/node.rb, line 10
def initialize(node_api)
  super()
  @node_api=node_api
  # TODO: currently only supports one transfer. This is bad shortcut. but ok for CLI.
  @transfer_id=nil
end

Public Instance Methods

node_api=(new_value) click to toggle source

use this to set the node_api end point before using the class.

# File lib/asperalm/fasp/node.rb, line 26
def node_api=(new_value)
  if !@node_api.nil? and !new_value.nil?
    Log.log.warn('overriding existing node api value')
  end
  @node_api=new_value
end
node_api_() click to toggle source

used internally to ensure node api is set before using.

# File lib/asperalm/fasp/node.rb, line 18
def node_api_
  raise StandardError,'Before using this object, set the node_api attribute to a Asperalm::Rest object' if @node_api.nil?
  return @node_api
end
start_transfer(transfer_spec,options=nil) click to toggle source

generic method

# File lib/asperalm/fasp/node.rb, line 34
def start_transfer(transfer_spec,options=nil)
  if transfer_spec['tags'].is_a?(Hash) and transfer_spec['tags']['aspera'].is_a?(Hash)
    transfer_spec['tags']['aspera']['xfer_retry']||=150
  end
  # optimisation in case of sending to the same node
  if transfer_spec['remote_host'].eql?(URI.parse(node_api_.params[:base_url]).host)
    transfer_spec['remote_host']='localhost'
  end
  resp=node_api_.create('ops/transfers',transfer_spec)[:data]
  @transfer_id=resp['id']
  Log.log.debug("tr_id=#{@transfer_id}")
  return @transfer_id
end
wait_for_transfers_completion() click to toggle source

generic method

# File lib/asperalm/fasp/node.rb, line 49
def wait_for_transfers_completion
  started=false
  spinner=nil
  # lets emulate management events to display progress bar
  loop do
    # status is empty sometimes with status 200...
    trdata=node_api_.read("ops/transfers/#{@transfer_id}")[:data] || {"status"=>"unknown"} rescue {"status"=>"waiting(read error)"}
    case trdata['status']
    when 'completed'
      notify_listeners('emulated',{Manager::LISTENER_SESSION_ID_B=>@transfer_id,'Type'=>'DONE'})
      break
    when 'waiting','partially_completed','unknown','waiting(read error)'
      if spinner.nil?
        spinner = TTY::Spinner.new("[:spinner] :title", format: :classic)
        spinner.start
      end
      spinner.update(title: trdata['status'])
      spinner.spin
      #puts trdata
    when 'running'
      #puts "running: sessions:#{trdata["sessions"].length}, #{trdata["sessions"].map{|i| i['bytes_transferred']}.join(',')}"
      if !started and trdata['precalc'].is_a?(Hash) and
      trdata['precalc']['status'].eql?('ready')
        notify_listeners('emulated',{Manager::LISTENER_SESSION_ID_B=>@transfer_id,'Type'=>'NOTIFICATION','PreTransferBytes'=>trdata['precalc']['bytes_expected']})
        started=true
      else
        notify_listeners('emulated',{Manager::LISTENER_SESSION_ID_B=>@transfer_id,'Type'=>'STATS','Bytescont'=>trdata['bytes_transferred']})
      end
    else
      Log.log.warn("trdata -> #{trdata}")
      raise Fasp::Error.new("#{trdata['status']}: #{trdata['error_desc']}")
    end
    sleep 1
  end
  #TODO get status of sessions
  return [] 
end