Class: Aspera::NodeSimulator

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

Instance Method Summary collapse

Constructor Details

#initialize ⇒ NodeSimulator

Returns a new instance of NodeSimulator.



13
14
15
16
# File 'lib/aspera/node_simulator.rb', line 13

def initialize
  @agent = Agent::Direct.new(management_cb: ->(event) { process_event(event) })
  @sessions = {}
end

Instance Method Details

#all_sessions ⇒ Object



22
23
24
# File 'lib/aspera/node_simulator.rb', line 22

def all_sessions
  @agent.sessions.map { |session| session[:job_id] }.uniq.each.map { |job_id| job_to_transfer(job_id) }
end

#job_to_transfer(job_id) ⇒ Object

status: ('waiting', 'partially_completed', 'unknown', 'waiting(read error)',] 'running', 'completed', 'failed'



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/aspera/node_simulator.rb', line 27

def job_to_transfer(job_id)
  jobs = @agent.sessions_by_job(job_id)
  ts = nil
  sessions = jobs.map do |j|
    ts ||= j[:ts]
    {
      id:                    j[:id],
      client_node_id:        '',
      server_node_id:        '2bbdcc39-f789-4d47-8163-6767fc14f421',
      client_ip_address:     '192.168.0.100',
      server_ip_address:     '5.10.114.4',
      status:                'running',
      retry_timeout:         3600,
      retry_count:           0,
      start_time_usec:       1701094040000000,
      end_time_usec:         nil,
      elapsed_usec:          405312,
      bytes_transferred:     26,
      bytes_written:         26,
      bytes_lost:            0,
      files_completed:       1,
      directories_completed: 0,
      target_rate_kbps:      500000,
      min_rate_kbps:         0,
      calc_rate_kbps:        9900,
      network_delay_usec:    40000,
      avg_rate_kbps:         0.51,
      error_code:            0,
      error_desc:            '',
      source_statistics:     {
        args_scan_attempted:  1,
        args_scan_completed:  1,
        paths_scan_attempted: 1,
        paths_scan_failed:    0,
        paths_scan_skipped:   0,
        paths_scan_excluded:  0,
        dirs_scan_completed:  0,
        files_scan_completed: 1,
        dirs_xfer_attempted:  0,
        dirs_xfer_fail:       0,
        files_xfer_attempted: 1,
        files_xfer_fail:      0,
        files_xfer_noxfer:    0
      },
      precalc:               {
        enabled:              true,
        status:               'ready',
        bytes_expected:       0,
        directories_expected: 0,
        files_expected:       0,
        files_excluded:       0,
        files_special:        0,
        files_failed:         1
      }
    }
  end
  ts ||= {}
  result = {
    id:                    job_id,
    status:                'running',
    start_spec:            ts,
    sessions:              sessions,
    bytes_transferred:     26,
    bytes_written:         26,
    bytes_lost:            0,
    avg_rate_kbps:         0.51,
    files_completed:       1,
    files_skipped:         0,
    directories_completed: 0,
    start_time_usec:       1701094040000000,
    end_time_usec:         1701094040405312,
    elapsed_usec:          405312,
    error_code:            0,
    error_desc:            '',
    precalc:               {
      status:               'ready',
      bytes_expected:       0,
      files_expected:       0,
      directories_expected: 0,
      files_special:        0,
      files_failed:         1
    },
    files:                 [{
      id:              'd1b5c112-82b75425-860745fc-93851671-64541bdd',
      path:            '/workspaces/45071/packages/bYA_ilq73g.asp-package/contents/data_file.bin',
      start_time_usec: 1701094040000000,
      elapsed_usec:    105616,
      end_time_usec:   1701094040001355,
      status:          'completed',
      error_code:      0,
      error_desc:      '',
      size:            26,
      type:            'file',
      checksum_type:   'none',
      checksum:        nil,
      start_byte:      0,
      bytes_written:   26,
      session_id:      'bafc72b8-366c-4501-8095-47208183d6b8'
    }]
  }
  Log.dump(:job, result, level: :trace2)
  return result
end

#process_event(event) ⇒ Object

Process event from management port



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/aspera/node_simulator.rb', line 132

def process_event(event)
  # Code duplicated on purpose, as implementation goes, blocks will be replaced
  case event['Type']
  when 'NOP' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  # rubocop:disable Lint/DuplicateBranch
  when 'START' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'QUERY' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'QUERYRSP' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'STATS' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'STOP' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'ERROR' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'CANCEL' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'DONE' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'RATE' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'FILEERROR' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'SESSION' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'NOTIFICATION' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'INIT' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'VLINK' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'PUT' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'WRITE' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'CLOSE' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'SKIP' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  when 'ARGSTOP' then Aspera.Log.debug { "event not managed: #{event['Type']}" }
  # rubocop:enable Lint/DuplicateBranch
  else Aspera.error_unreachable_line
  end
end

#start(ts) ⇒ Object



18
19
20
# File 'lib/aspera/node_simulator.rb', line 18

def start(ts)
  @agent.start_transfer(ts)
end