Top Level Namespace

Defined Under Namespace

Classes: CfdpApi

Instance Method Summary collapse

Instance Method Details

#cfdp_cancel(transaction_id:, remote_entity_id: nil, timeout: 600, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cfdp.rb', line 63

def cfdp_cancel(
  transaction_id:,
  remote_entity_id: nil,
  timeout: 600,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)
  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  continuation = api.subscribe(scope: scope) if timeout
  transaction_id = api.cancel(transaction_id: transaction_id, remote_entity_id: remote_entity_id, scope: scope)
  indication = nil
  indication = cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Transaction-Finished', continuation: continuation, timeout: timeout, scope: scope) if timeout
  indication ||= cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Proxy-Put-Response', continuation: continuation, timeout: timeout, scope: scope) if remote_entity_id and timeout
  return indication
end

#cfdp_directory_listing(remote_entity_id:, directory_name:, directory_file_name:, timeout: 600, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/cfdp.rb', line 181

def cfdp_directory_listing(
  remote_entity_id:,
  directory_name:,
  directory_file_name:,
  timeout: 600,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)

  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  continuation = api.subscribe(scope: scope) if timeout
  transaction_id = api.directory_listing(remote_entity_id: remote_entity_id, directory_name: directory_name, directory_file_name: directory_file_name, scope: scope)
  indications = []
  indications << cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Transaction-Finished', continuation: continuation, timeout: timeout, scope: scope) if timeout
  indications << cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Directory-Listing-Response', continuation: continuation, timeout: timeout, scope: scope) if timeout
  return indications.compact
end

#cfdp_indications(transaction_id: nil, indication_type: nil, continuation: nil, include_continuation: true, timeout: nil, api_timeout: 5, limit: 100, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/cfdp.rb', line 162

def cfdp_indications(
  transaction_id: nil,
  indication_type: nil,
  continuation: nil,
  include_continuation: true,
  timeout: nil,
  api_timeout: 5,
  limit: 100,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)
  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  return cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: indication_type, continuation: continuation, include_continuation: include_continuation, timeout: timeout, limit: limit, scope: scope)
end

#cfdp_put(destination_entity_id:, source_file_name: nil, destination_file_name: nil, closure_requested: nil, transmission_mode: nil, filestore_requests: [], fault_handler_overrides: [], flow_label: nil, segmentation_control: "NOT_PRESERVED", messages_to_user: [], remote_entity_id: nil, timeout: 600, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



19
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cfdp.rb', line 19

def cfdp_put(
  destination_entity_id:,
  source_file_name: nil,
  destination_file_name: nil,
  closure_requested: nil,
  transmission_mode: nil,
  filestore_requests: [],
  fault_handler_overrides: [],
  flow_label: nil,
  segmentation_control: "NOT_PRESERVED",
  messages_to_user: [],
  remote_entity_id: nil, # Used to indicate proxy put
  timeout: 600,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)

  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  continuation = api.subscribe(scope: scope) if timeout
  transaction_id = api.put(
    destination_entity_id: destination_entity_id,
    source_file_name: source_file_name,
    destination_file_name: destination_file_name,
    transmission_mode: transmission_mode,
    closure_requested: closure_requested,
    filestore_requests: filestore_requests,
    fault_handler_overrides: fault_handler_overrides,
    flow_label: flow_label,
    segmentation_control: segmentation_control,
    messages_to_user: messages_to_user,
    remote_entity_id: remote_entity_id, # Used to indicate proxy put
    scope: $openc3_scope)
  return transaction_id unless timeout
  indication = nil
  indication = cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Transaction-Finished', continuation: continuation, timeout: timeout, scope: scope) if timeout
  indication ||= cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Proxy-Put-Response', continuation: continuation, timeout: timeout, scope: scope) if remote_entity_id and timeout
  return transaction_id, indication
end

#cfdp_report(transaction_id:, remote_entity_id: nil, report_file_name: nil, timeout: 600, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/cfdp.rb', line 126

def cfdp_report(
  transaction_id:,
  remote_entity_id: nil,
  report_file_name: nil,
  timeout: 600,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)
  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  continuation = api.subscribe(scope: scope) if timeout
  transaction_id = api.report(transaction_id: transaction_id, remote_entity_id: remote_entity_id, report_file_name: report_file_name, scope: scope)
  indication = nil
  indication = cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Report', continuation: continuation, timeout: timeout, scope: scope) if not remote_entity_id and timeout
  indication ||= cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Remote-Report-Response', continuation: continuation, timeout: timeout, scope: scope) if remote_entity_id and timeout
  return indication
end

#cfdp_resume(transaction_id:, remote_entity_id: nil, timeout: 600, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/cfdp.rb', line 105

def cfdp_resume(
  transaction_id:,
  remote_entity_id: nil,
  timeout: 600,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)
  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  continuation = api.subscribe(scope: scope) if timeout
  transaction_id = api.resume(transaction_id: transaction_id, remote_entity_id: remote_entity_id, scope: scope)
  indication = nil
  indication = cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Resumed', continuation: continuation, timeout: timeout, scope: scope) if not remote_entity_id and timeout
  indication ||= cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Remote-Resume-Response', continuation: continuation, timeout: timeout, scope: scope) if remote_entity_id and timeout
  return indication
end

#cfdp_subscribe(api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/cfdp.rb', line 148

def cfdp_subscribe(
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)

  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  return api.subscribe(scope: scope)
end

#cfdp_suspend(transaction_id:, remote_entity_id: nil, timeout: 600, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cfdp.rb', line 84

def cfdp_suspend(
  transaction_id:,
  remote_entity_id: nil,
  timeout: 600,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)
  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  continuation = api.subscribe(scope: scope) if timeout
  transaction_id = api.suspend(transaction_id: transaction_id, remote_entity_id: remote_entity_id, scope: scope)
  indication = nil
  indication = cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Suspended', continuation: continuation, timeout: timeout, scope: scope) if not remote_entity_id and timeout
  indication ||= cfdp_wait_for_indication(api: api, transaction_id: transaction_id, indication_type: 'Remote-Suspend-Response', continuation: continuation, timeout: timeout, scope: scope) if remote_entity_id and timeout
  return indication
end

#cfdp_transactions(active: true, api_timeout: 5, microservice_name: 'CFDP', prefix: '/cfdp', schema: 'http', hostname: nil, port: 2905, url: nil, scope: $openc3_scope) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/cfdp.rb', line 204

def cfdp_transactions(
  active: true,
  api_timeout: 5,
  microservice_name: 'CFDP',
  prefix: '/cfdp',
  schema: 'http',
  hostname: nil,
  port: 2905,
  url: nil,
  scope: $openc3_scope)

  api = CfdpApi.new(timeout: api_timeout, microservice_name: microservice_name, prefix: prefix, schema: schema, hostname: hostname, port: port, url: url, scope: scope)
  return api.transactions(active: active, scope: scope)
end

#cfdp_wait_for_indication(api:, transaction_id: nil, indication_type: nil, continuation: nil, include_continuation: false, timeout: 600, limit: 1000, scope: $openc3_scope) ⇒ Object

Helper methods



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/cfdp.rb', line 221

def cfdp_wait_for_indication(
  api:,
  transaction_id: nil,
  indication_type: nil,
  continuation: nil,
  include_continuation: false,
  timeout: 600,
  limit: 1000,
  scope: $openc3_scope)

  timeout ||= 0
  start_time = Time.now
  end_time = start_time + timeout
  continuation = '0-0' unless continuation
  done = false
  while not done
    result = api.indications(transaction_id: transaction_id, continuation: continuation, limit: limit, scope: scope)
    continuation = result['continuation']
    indications = result['indications']
    if indications and indications.length > 0
      unless indication_type
        if include_continuation
          return indications, continuation
        else
          return indications
        end
      end
      indications.each do |indication|
        if indication['indication_type'] == indication_type
          if include_continuation
            return indication, continuation
          else
            return indication
          end
        end
      end
    end
    if Time.now >= end_time
      raise "CFDP Timeout" if timeout > 0
      done = true
    end
    break if done
    if defined? wait
      wait_time = wait(1)
      break if wait_time < 1.0 # User hit go
    else
      sleep(1)
    end
  end
  if indication_type
    if include_continuation
      return nil, continuation
    else
      return nil
    end
  else
    if include_continuation
      return [], continuation
    else
      return []
    end
  end
end