class Asperalm::Fasp::Parameters

translate transfer specification to ascp parameter list

Constants

FILE_LIST_AGE_MAX_SEC

assume no transfer last longer than this (garbage collect file list which were not deleted after transfer)

PARAM_DEFINITION
SEC_IN_DAY

Public Class Methods

file_list_folder() click to toggle source
# File lib/asperalm/fasp/parameters.rb, line 206
def self.file_list_folder; @@file_list_folder;end
file_list_folder=(v) click to toggle source

temp file list files are created here

# File lib/asperalm/fasp/parameters.rb, line 189
def self.file_list_folder=(v)
  @@file_list_folder=v
  unless @@file_list_folder.nil?
    FileUtils.mkdir_p(@@file_list_folder)
    # garbage collect undeleted files
    Dir.entries(@@file_list_folder).each do |name|
      file_path=File.join(@@file_list_folder,name)
      age_sec=(Time.now - File.stat(file_path).mtime).to_i
      # check age of file, delete too old
      if File.file?(file_path) and age_sec > FILE_LIST_AGE_MAX_SEC
        Log.log.debug("garbage collecting #{name}")
        File.delete(file_path)
      end
    end
  end
end
new(job_spec) click to toggle source
# File lib/asperalm/fasp/parameters.rb, line 103
def initialize(job_spec)
  @job_spec=job_spec
  @builder=Asperalm::CommandLineBuilder.new(@job_spec,PARAM_DEFINITION)
end
ts_to_env_args(transfer_spec) click to toggle source
# File lib/asperalm/fasp/parameters.rb, line 208
def self.ts_to_env_args(transfer_spec)
  return Parameters.new(transfer_spec).compute_args
end

Public Instance Methods

compute_args() click to toggle source

translate transfer spec to env vars and command line arguments for ascp NOTE: parameters starting with “EX_” (extended) are not standard

# File lib/asperalm/fasp/parameters.rb, line 112
def compute_args
  env_args={
    :args=>[],
    :env=>{},
    :ascp_version=>:ascp
  }
  # some ssh credentials are required to avoid interactive password input
  if !@job_spec.has_key?('remote_password') and
  !@job_spec.has_key?('ssh_private_key') and
  !@job_spec.has_key?('EX_ssh_key_paths') then
    raise Fasp::Error.new('required: password or ssh key (value or path)')
  end

  # special cases
  @job_spec.delete('source_root') if @job_spec.has_key?('source_root') and @job_spec['source_root'].empty?

  # process parameters as specified in table
  @builder.process_params

  # symbol must be index of Installation.paths
  if @builder.process_param('use_ascp4',:get_value)
    env_args[:ascp_version] = :ascp4
  else
    env_args[:ascp_version] = :ascp
    # destination will be base64 encoded, put before path arguments
    @builder.add_command_line_options(['--dest64'])
  end
  PARAM_DEFINITION['paths'][:mandatory]=!@job_spec.has_key?('keepalive')
  paths_array=@builder.process_param('paths',:get_value)
  unless paths_array.nil?
    # use file list if there is storage defined for it.
    if @@file_list_folder.nil?
      # not safe for special characters ? (maybe not, depends on OS)
      Log.log.debug("placing source file list on command line (no file list file)")
      @builder.add_command_line_options(paths_array.map{|i|i['source']})
    else
      file_list_file=@builder.process_param('EX_file_list',:get_value)
      if !file_list_file.nil?
        option='--file-list'
      else
        file_list_file=@builder.process_param('EX_file_pair_list',:get_value)
        if !file_list_file.nil?
          option='--file-pair-list'
        else
          # safer option: file list
          # if there is destination in paths, then use filepairlist
          # TODO: well, we test only the first one, but anyway it shall be consistent
          if paths_array.first.has_key?('destination')
            option='--file-pair-list'
            lines=paths_array.inject([]){|m,e|m.push(e['source'],e['destination']);m}
          else
            option='--file-list'
            lines=paths_array.map{|i|i['source']}
          end
          file_list_file=Asperalm::TempFileManager.instance.new_file_path_in_folder(@@file_list_folder)
          File.open(file_list_file, 'w+'){|f|f.puts(lines)}
          Log.log.debug("#{option}=\n#{File.read(file_list_file)}".red)
        end
      end
      @builder.add_command_line_options(["#{option}=#{file_list_file}"])
    end
  end
  # optional args, at the end to override previous ones (to allow override)
  @builder.add_command_line_options(@builder.process_param('EX_ascp_args',:get_value))
  # process destination folder
  destination_folder = @builder.process_param('destination_root',:get_value) || '/'
  # ascp4 does not support base64 encoding of destination
  destination_folder = Base64.strict_encode64(destination_folder) unless env_args[:ascp_version].eql?(:ascp4)
  # destination MUST be last command line argument to ascp
  @builder.add_command_line_options([destination_folder])

  @builder.add_env_args(env_args[:env],env_args[:args])

  return env_args
end