Class: Aspera::Ascp::Management

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/ascp/management.rb

Overview

processing of ascp management port events Reference: mgmtmess.c

Constant Summary collapse

ERRORS =

References: https://www.ibm.com/support/pages/error-code-reference-tables asmgmt_err.h : codes, mnemonics and messages mgmtmess.c : faspmgmt_err_name_str (additional info) and as_mgmt_err_is_retryable Note that the fact that an error is retry-able is not internally defined by protocol, it's client-side responsibility rubocop:disable-next Layout/FirstHashElementLineBreak

{
  # id   retry-able    mnemo/code                        message                                              additional info
  0  => {r: false, c: 'UNKNOWN',                     m: 'unknown',                                        a: 'unknown'},
  1  => {r: false, c: 'FASP_PROTO',                  m: 'Generic fasp(tm) protocol error',                a: 'FASP error'},
  2  => {r: false, c: 'ASCP',                        m: 'Generic SCP error',                              a: 'ASCP error'},
  3  => {r: false, c: 'AMBIGUOUS_TARGET',            m: 'Target incorrectly specified',                   a: 'Ambiguous target'},
  4  => {r: false, c: 'NO_SUCH_FILE',                m: 'No such file or directory',                      a: 'No such file or directory'},
  5  => {r: false, c: 'NO_PERMS',                    m: 'Insufficient permission to read or write',       a: 'Insufficient permissions'},
  6  => {r: false, c: 'NOT_DIR',                     m: 'Target is not a directory',                      a: 'Target must be a directory'},
  7  => {r: false, c: 'IS_DIR',                      m: 'File is a directory - expected regular file',    a: 'Expected regular file'},
  8  => {r: false, c: 'USAGE',                       m: 'Incorrect usage of scp command',                 a: 'Incorrect usage of Aspera scp command'},
  9  => {r: false, c: 'LIC_DUP',                     m: 'Duplicate license',                              a: 'Duplicate license'},
  10 => {r: false, c: 'LIC_RATE_EXCEEDED',           m: 'Rate exceeds the cap imposed by license',        a: 'Rate exceeds cap imposed by license'},
  11 => {r: false, c: 'INTERNAL_ERROR',              m: 'Internal error (unexpected error)',              a: 'Internal error'},
  12 => {r: true,  c: 'TRANSFER_ERROR',              m: 'Error establishing control connection',
                                                     a: 'Error establishing SSH connection (check SSH port and firewall)'},
  13 => {r: true,  c: 'TRANSFER_TIMEOUT',            m: 'Timeout establishing control connection',
                                                     a: 'Timeout establishing SSH connection (check SSH port and firewall)'},
  14 => {r: true,  c: 'CONNECTION_ERROR',            m: 'Error establishing data connection',
                                                     a: 'Error establishing UDP connection (check UDP port and firewall)'},
  15 => {r: true,  c: 'CONNECTION_TIMEOUT',          m: 'Timeout establishing data connection',
                                                     a: 'Timeout establishing UDP connection (check UDP port and firewall)'},
  16 => {r: true,  c: 'CONNECTION_LOST',             m: 'Connection lost',                                a: 'Connection lost'},
  17 => {r: true,  c: 'RCVR_SEND_ERROR',             m: 'Receiver fails to send feedback',                a: 'Network failure (receiver can\'t send feedback)'},
  18 => {r: true,  c: 'RCVR_RECV_ERROR',             m: 'Receiver fails to receive data packets',         a: 'Network failure (receiver can\'t receive UDP data)'},
  19 => {r: false, c: 'AUTH',                        m: 'Authentication failure',                         a: 'Authentication failure'},
  20 => {r: false, c: 'NOTHING',                     m: 'Nothing to transfer',                            a: 'Nothing to transfer'},
  21 => {r: false, c: 'NOT_REGULAR',                 m: 'Not a regular file (special file)',              a: 'Not a regular file'},
  22 => {r: false, c: 'FILE_TABLE_OVR',              m: 'File table overflow',                            a: 'File table overflow'},
  23 => {r: true,  c: 'TOO_MANY_FILES',              m: 'Too many files open',                            a: 'Too many files open'},
  24 => {r: false, c: 'FILE_TOO_BIG',                m: 'File too big for file system',                   a: 'File too big for filesystem'},
  25 => {r: false, c: 'NO_SPACE_LEFT',               m: 'No space left on disk',                          a: 'No space left on disk'},
  26 => {r: false, c: 'READ_ONLY_FS',                m: 'Read only file system',                          a: 'Read only filesystem'},
  27 => {r: false, c: 'SOME_FILE_ERRS',              m: 'Some individual files failed',                   a: 'One or more files failed'},
  28 => {r: false, c: 'USER_CANCEL',                 m: 'Cancelled by user',                              a: 'Cancelled by user'},
  29 => {r: false, c: 'LIC_NOLIC',                   m: 'License not found or unable to access',          a: 'Unable to access license info'},
  30 => {r: false, c: 'LIC_EXPIRED',                 m: 'License expired',                                a: 'License expired'},
  31 => {r: false, c: 'SOCK_SETUP',                  m: 'Unable to setup socket (create, bind, etc ...)', a: 'Unable to set up socket'},
  32 => {r: true,  c: 'OUT_OF_MEMORY',               m: 'Out of memory, unable to allocate',              a: 'Out of memory'},
  33 => {r: true,  c: 'THREAD_SPAWN',                m: 'Can\'t spawn thread',                            a: 'Unable to spawn thread'},
  34 => {r: false, c: 'UNAUTHORIZED',                m: 'Unauthorized by external auth server',           a: 'Unauthorized'},
  35 => {r: true,  c: 'DISK_READ',                   m: 'Error reading source file from disk',            a: 'Disk read error'},
  36 => {r: true,  c: 'DISK_WRITE',                  m: 'Error writing to disk',                          a: 'Disk write error'},
  37 => {r: true,  c: 'AUTHORIZATION',               m: 'Used interchangeably with ERR_UNAUTHORIZED',     a: 'Authorization failure'},
  38 => {r: false, c: 'LIC_ILLEGAL',                 m: 'Operation not permitted by license',             a: 'Operation not permitted by license'},
  39 => {r: true,  c: 'PEER_ABORTED_SESSION',        m: 'Remote peer terminated session',                 a: 'Peer aborted session'},
  40 => {r: true,  c: 'DATA_TRANSFER_TIMEOUT',       m: 'Transfer stalled, timed out',                    a: 'Data transfer stalled, timed out'},
  41 => {r: false, c: 'BAD_PATH',                    m: 'Path violates docroot containment',              a: 'File location is outside \'docroot\' hierarchy'},
  42 => {r: false, c: 'ALREADY_EXISTS',              m: 'File or directory already exists',               a: 'File or directory already exists'},
  43 => {r: false, c: 'STAT_FAILS',                  m: 'Cannot stat file',                               a: 'Cannot collect details about file or directory'},
  44 => {r: true,  c: 'PMTU_BRTT_ERROR',             m: 'UDP session initiation fatal error',             a: 'UDP session initiation fatal error'},
  45 => {r: true,  c: 'BWMEAS_ERROR',                m: 'Bandwidth measurement fatal error',              a: 'Bandwidth measurement fatal error'},
  46 => {r: false, c: 'VLINK_ERROR',                 m: 'Virtual link error',                             a: 'Virtual link error'},
  47 => {r: true,  c: 'CONNECTION_ERROR_HTTP',       m: 'Error establishing HTTP connection',
                                                     a: 'Error establishing HTTP connection (check HTTP port and firewall)'},
  48 => {r: false, c: 'FILE_ENCRYPTION_ERROR',       m: 'File encryption error, e.g. corrupt file',       a: 'File encryption/decryption error, e.g. corrupt file'},
  49 => {r: false, c: 'FILE_DECRYPTION_PASS',        m: 'File decryption bad passphrase',                 a: 'File decryption error, bad passphrase'},
  50 => {r: false, c: 'BAD_CONFIGURATION',           m: 'Aspera.conf contains invalid data and was rejected', a: 'Invalid configuration'},
  51 => {r: false, c: 'INSECURE_CONNECTION',         m: 'Remote-host key check failure',                  a: 'Remote host is not who we expected'},
  52 => {r: false, c: 'START_VALIDATION_FAILED',     m: 'File start validation failed',                   a: 'File start validation failed'},
  53 => {r: false, c: 'STOP_VALIDATION_FAILED',      m: 'File stop validation failed',                    a: 'File stop validation failed'},
  54 => {r: false, c: 'THRESHOLD_VALIDATION_FAILED', m: 'File threshold validation failed',               a: 'File threshold validation failed'},
  55 => {r: false, c: 'FILEPATH_TOO_LONG',           m: 'File path/name too long for underlying file system', a: 'File path exceeds underlying file system limit'},
  56 => {r: false, c: 'ILLEGAL_CHARS_IN_PATH',       m: 'Windows path contains illegal characters',
                                                     a: 'Path being written to Windows file system contains illegal characters'},
  57 => {r: false, c: 'CHUNK_MUST_MATCH_ALIGNMENT',  m: 'Chunk size/start must be aligned with storage',
                                                     a: 'Data size must match storage chunk size and alignment requirements'},
  58 => {r: false, c: 'VALIDATION_SESSION_ABORT',    m: 'Session aborted due to validation error(s)',     a: 'Session aborted due to validation error(s)'},
  59 => {r: false, c: 'REMOTE_STORAGE_ERROR',        m: 'Remote storage errored',                         a: 'Remote storage errored'},
  60 => {r: false, c: 'LUA_SCRIPT_ABORTED_SESSION',  m: 'Session aborted due to Lua script abort',        a: 'Session aborted'},
  61 => {r: true,  c: 'SSEAR_RETRYABLE',             m: 'Transfer failed because of a retryable Encryption at Rest error',
                                                     a: 'Server-side Encryption At Rest unavailable'},
  62 => {r: false, c: 'SSEAR_FATAL',                 m: 'Transfer failed because of a fatal Encryption at Rest error', a: 'Server-side Encryption At Rest failed'},
  63 => {r: false, c: 'LINK_LOOP',                   m: 'Path refers to a symbolic link loop',            a: 'Symbolic link loop'},
  64 => {r: false, c: 'CANNOT_RENAME_PARTIAL',       m: 'Can\'t rename a partial file',                   a: 'Cannot rename partial file'},
  65 => {r: false, c: 'CIPHER_NON_COMPAT_FIPS',      m: 'Can\'t use this cipher with FIPS mode enabled',  a: 'Cypher not supported in FIPS mode'},
  66 => {r: false, c: 'PEER_REQUIRES_FIPS',          m: 'Peer rejects cipher due to FIPS mode enabled on peer', a: 'Peer requires FIPS be enabled'},
  67 => {r: false, c: 'UPLOAD_IN_PROGRESS',          m: 'Conflict between two transfers',                 a: 'File upload already in progress'},
  68 => {r: false, c: 'MIN_VERSION_CHECK',           m: 'Minimum version check failed',                   a: 'Failed to start due to minimum version check'},
  69 => {r: true,  c: 'MAX_ASCP',                    m: 'Maximum ascp processes on a node exceeded',
                                                     a: 'Failed to start session maximum transfer sessions exceeded'}
}.freeze
PROT_VERSION =

Management port start message

'2'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Management

Returns a new instance of Management.



389
390
391
392
393
394
# File 'lib/aspera/ascp/management.rb', line 389

def initialize
  # current event being parsed line by line
  @event_build = nil
  # last fully built event
  @last_event = nil
end

Instance Attribute Details

#last_event ⇒ Object (readonly)

Returns the value of attribute last_event.



395
396
397
# File 'lib/aspera/ascp/management.rb', line 395

def last_event
  @last_event
end

Class Method Details

.command_to_stream(data) ⇒ String

Build command to send on management port Frame: header, one line per field, empty line (last empty element adds the final line break)

Parameters:

  • data (Hash) —

    keys are snake case: e.g. 'type'=>'START','source'=>_path_,'destination'=>_path_

Returns:

  • (String) —

    frame to send on management port



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/aspera/ascp/management.rb', line 371

def command_to_stream(data)
  data
    .map do |key, value|
      name = field_snake_to_native(key)
      value = value.to_s
      if PATH_FIELDS.include?(name)
        value = escape_path(value)
      else
        Aspera.assert(!value.match?(/[\r\n]/)) { "mgt port: line break in value of #{name}" }
      end
      "#{name}: #{value}"
    end
    .unshift(MGT_HEADER)
    .push(MGT_FRAME_SEPARATOR, '')
    .join("\n")
end

.error_by_mnemonic(mnemonic) ⇒ Hash?

Returns error of management port (see ERRORS), nil if unknown.

Parameters:

  • mnemonic (String) —

    mnemonic of error, e.g. CONNECTION_LOST

Returns:

  • (Hash, nil) —

    error of management port (see ERRORS), nil if unknown



319
320
321
# File 'lib/aspera/ascp/management.rb', line 319

def error_by_mnemonic(mnemonic)
  ERRORS_BY_MNEMONIC[mnemonic]
end

.escape_path(value) ⇒ String

Escape path value for management port: line breaks and escape char

Parameters:

Returns:



356
357
358
# File 'lib/aspera/ascp/management.rb', line 356

def escape_path(value)
  value.gsub(/[\n\r\e]/) { |char| "#{PATH_ESCAPE}#{PATH_ESCAPES[char]}" }
end

.event_native_to_snake(event) ⇒ Object

Translates mgt port event into (enhanced) typed event



342
343
344
345
346
347
348
349
350
351
# File 'lib/aspera/ascp/management.rb', line 342

def event_native_to_snake(event)
  event.each_with_object({}) do |(key, value), h|
    h[field_native_to_snake(key)] =
      if INTEGER_FIELDS.include?(key) && INTEGER_VALUE.match?(value) then value.to_i
      elsif BOOLEAN_FIELDS.include?(key) then value.eql?(BOOLEAN_TRUE)
      else
        value
      end
  end
end

.field_native_to_snake(name) ⇒ Object

Translate native event name to snake case



324
325
326
327
328
329
330
# File 'lib/aspera/ascp/management.rb', line 324

def field_native_to_snake(name)
  case name
  when 'Elapsedusec' then 'elapsed_usec'
  when 'Bytescont' then 'bytes_cont'
  else name.capital_to_snake
  end
end

.field_snake_to_native(name) ⇒ Object

Translate snake case event name to native

Parameters:

  • name (String) —

    Field name



334
335
336
337
338
339
# File 'lib/aspera/ascp/management.rb', line 334

def field_snake_to_native(name)
  field = name.to_s.delete('_')
  result = PARAMETERS.find { |w| w.casecmp?(field) }
  Aspera.assert(!result.nil?) { "No such field: #{name}" }
  result
end

.unescape_path(value) ⇒ String

Reverse of escape_path

Parameters:

  • value (String) —

    Escaped path

Returns:



363
364
365
# File 'lib/aspera/ascp/management.rb', line 363

def unescape_path(value)
  value.gsub(/\e([nr\e])/) { PATH_ESCAPES.key(Regexp.last_match(1)) }
end

Instance Method Details

#process_line(line) ⇒ Hash

Process line of mgt port event

Parameters:

  • line (String) —

    line of mgt port event

Returns:

  • (Hash) —

    event hash or nil if event is not yet complete



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/aspera/ascp/management.rb', line 400

def process_line(line)
  case line
  when MGT_HEADER
    # begin event
    Log.log.warn { "mgt port: incomplete event discarded: #{@event_build}" } unless @event_build.nil?
    @event_build = {}
  when MGT_FRAME_SEPARATOR
    Aspera.assert_type(@event_build, Hash) { 'mgt port: unexpected line: end frame without header' }
    @last_event = @event_build
    @event_build = nil
    return @last_event
  else
    # event field: name up to first colon, optional single space (as `as_mgmt_buffered_read_msg`)
    name, value = line.split(':', 2)
    Aspera.error_unexpected_value(line) { 'mgt port' } if value.nil?
    Aspera.assert_type(@event_build, Hash) { 'mgt port: unexpected line: data without header' }
    value = value.delete_prefix(' ')
    value = self.class.unescape_path(value) if PATH_FIELDS.include?(name)
    @event_build[name] = value
  end
  return
end